Revision: 19616 http://sourceforge.net/p/gate/code/19616 Author: markagreenwood Date: 2016-10-03 07:26:21 +0000 (Mon, 03 Oct 2016) Log Message: ----------- some restructuring of the maven stuff to make it easier to follow
Modified Paths: -------------- gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java gate/branches/sawdust2/gate-core/src/main/java/gate/gui/creole/manager/PluginUpdateManager.java gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java Added Paths: ----------- gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/ gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java 2016-10-03 01:22:54 UTC (rev 19615) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -45,6 +45,12 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.apache.maven.model.License; +import org.apache.maven.model.Model; +import org.apache.maven.model.building.DefaultModelBuilderFactory; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelBuilder; +import org.apache.maven.model.building.ModelBuildingRequest; import org.apache.maven.repository.internal.MavenRepositorySystemUtils; import org.apache.maven.settings.Profile; import org.apache.maven.settings.Repository; @@ -75,6 +81,7 @@ import org.eclipse.aether.spi.connector.transport.TransporterFactory; import org.eclipse.aether.transport.file.FileTransporterFactory; import org.eclipse.aether.transport.http.HttpTransporterFactory; +import org.eclipse.aether.util.artifact.SubArtifact; import org.jdom.Attribute; import org.jdom.Document; import org.jdom.Element; @@ -89,6 +96,7 @@ import gate.util.asm.Opcodes; import gate.util.asm.Type; import gate.util.asm.commons.EmptyVisitor; +import gate.util.maven.SimpleModelResolver; public abstract class Plugin { @@ -428,12 +436,15 @@ "conf/settings.xml"); private String group, artifact, version; + + private String name; public Maven(String group, String artifact, String version) { this.group = group; this.artifact = artifact; this.version = version; + name = group+":"+artifact+":"+version; //TODO move calculation of baseURL into here } @@ -530,20 +541,22 @@ catch (IOException | URISyntaxException e) { return false; } - } + } @Override public Document getCreoleXML() throws Exception { Artifact artifactObj = new DefaultArtifact(group, artifact, "jar", version); - Dependency dependency = new Dependency(artifactObj, "all"); + Dependency dependency = new Dependency(artifactObj, "runtime"); RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://repo1.maven.org/maven2/").build(); ArtifactRequest artifactRequest = new ArtifactRequest(); artifactRequest.setArtifact(artifactObj); + + //is this needed now we load the settings file? artifactRequest.addRepository(central); // Add all repos from settings.xml @@ -564,16 +577,14 @@ ArtifactResult artifactResult = getRepositorySystem().resolveArtifact(getRepositorySession(), artifactRequest); - + baseURL = new URL("jar:" + artifactResult.getArtifact().getFile().toURI().toURL() + "!/"); - //System.out.println(baseURL); // check it has a creole.xml at the root URL directoryXmlFileUrl = new URL(baseURL, "creole.xml"); - //System.out.println(directoryXmlFileUrl); InputStream creoleStream = null; @@ -608,19 +619,54 @@ Element creoleRoot = jdomDoc.getRootElement(); for(ArtifactResult ar : result.getArtifactResults()) { + + Element jarElement = new Element("JAR"); jarElement.setText(ar.getArtifact().getFile().toURI().toURL() .toExternalForm()); if(ar.getArtifact().equals(artifactResult.getArtifact())) { + System.out.println("scanning"); jarElement.setAttribute("SCAN", "true"); } creoleRoot.addContent(jarElement); } + + artifactObj = + new SubArtifact(artifactObj,"", "pom"); + + artifactRequest.setArtifact(artifactObj); + artifactResult = + getRepositorySystem().resolveArtifact(getRepositorySession(), + artifactRequest); + + ModelBuildingRequest req = new DefaultModelBuildingRequest(); + req.setProcessPlugins(false); + req.setPomFile(artifactResult.getArtifact().getFile()); + req.setModelResolver(new SimpleModelResolver(getRepositorySystem(), + getRepositorySession(), new ArrayList<RemoteRepository>())); + req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); + + ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance(); + Model model = modelBuilder.build(req).getEffectiveModel(); + + + if (model.getName() != null && !model.getName().trim().equals("")) name = model.getName(); + + System.out.println(model.getOrganization().getName()); + for (org.apache.maven.model.Repository r : model.getRepositories()) { + System.out.println(r.getName()); + } + for (License l : model.getLicenses()) { + System.out.println(l.getName()); + } + return jdomDoc; } + + private static RepositorySystem repoSystem = null; @@ -664,15 +710,16 @@ repoSystemSession.setLocalRepositoryManager(getRepositorySystem() .newLocalRepositoryManager(repoSystemSession, localRepo)); - repoSystemSession.setLocalRepositoryManager(getRepositorySystem() - .newLocalRepositoryManager(repoSystemSession, localRepo)); + //repoSystemSession.setWorkspaceReader(new SimpleMavenCache(new File("repo"))); + return repoSystemSession; } @Override public String getName() { - return group+":"+artifact+":"+version; + return name; + //return group+":"+artifact+":"+version; } } @@ -775,9 +822,8 @@ } } - - /*public static void main(String args[]) throws Exception { + public static void main(String args[]) throws Exception { Gate.runInSandbox(true); Gate.init(); @@ -788,9 +834,11 @@ Gate.getCreoleRegister().registerPlugin(annieMaven); + System.out.println(annieMaven.getName()); + File r = new File("testResources"); System.out.println(annieMaven.hasResources()); annieMaven.copyResources(r); - }*/ + } } Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java 2016-10-03 01:22:54 UTC (rev 19615) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/creole/CreoleRegisterImpl.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -1,17 +1,17 @@ /* - * CreoleRegisterImpl.java + * CreoleRegisterImpl.java * - * Copyright (c) 1995-2013, The University of Sheffield. See the file - * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt + * Copyright (c) 1995-2013, The University of Sheffield. See the file + * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt * - * This file is part of GATE (see http://gate.ac.uk/), and is free - * software, licenced under the GNU Library General Public License, - * Version 2, June 1991 (in the distribution as file licence.html, - * and also available at http://gate.ac.uk/gate/licence.html). + * This file is part of GATE (see http://gate.ac.uk/), and is free software, + * licenced under the GNU Library General Public License, Version 2, June 1991 + * (in the distribution as file licence.html, and also available at + * http://gate.ac.uk/gate/licence.html). * - * Hamish Cunningham, 1/Sept/2000 + * Hamish Cunningham, 1/Sept/2000 * - * $Id$ + * $Id$ */ package gate.creole; @@ -78,15 +78,15 @@ */ @SuppressWarnings("serial") public class CreoleRegisterImpl extends HashMap<String, ResourceData> - implements - CreoleRegister { + implements CreoleRegister { /** A logger to use instead of sending messages to Out or Err **/ - protected static final Logger log = Logger.getLogger(CreoleRegisterImpl.class); + protected static final Logger log = + Logger.getLogger(CreoleRegisterImpl.class); /** Debug flag */ protected static final boolean DEBUG = false; - + protected Set<Plugin> plugins; /** The parser for the CREOLE directory files */ @@ -109,13 +109,13 @@ public CreoleRegisterImpl() throws GateException { // initialise the various maps - + lrTypes = new HashSet<String>(); prTypes = new HashSet<String>(); vrTypes = new LinkedList<String>(); toolTypes = new HashSet<String>(); applicationTypes = new HashSet<String>(); - + plugins = new LinkedHashSet<Plugin>(); // construct a SAX parser for parsing the CREOLE directory files @@ -128,8 +128,8 @@ } // default constructor /** - * reads plugins-mapping.xml file which is used for mapping old plugin - * names to new plugin names + * reads plugins-mapping.xml file which is used for mapping old plugin names + * to new plugin names */ private void readPluginNamesMappings() { // should load it only once @@ -144,7 +144,7 @@ try { URL creoleDirURL = Gate.getBuiltinCreoleDir(); URL pluginMappingsFileURL = - new URL(creoleDirURL, PLUGIN_NAMES_MAPPING_FILE); + new URL(creoleDirURL, PLUGIN_NAMES_MAPPING_FILE); Document document = builder.build(pluginMappingsFileURL); @SuppressWarnings("unchecked") List<Element> plugins = document.getRootElement().getChildren("Plugin"); @@ -159,63 +159,62 @@ // indicates a well-formedness error catch(JDOMException e) { log.warn(PLUGIN_NAMES_MAPPING_FILE + " is not well-formed.", e); + } catch(IOException e) { + log.warn("Could not check " + PLUGIN_NAMES_MAPPING_FILE, e); } - catch(IOException e) { - log.warn("Could not check " + PLUGIN_NAMES_MAPPING_FILE,e); - } } /** Get the list of CREOLE directory URLs. */ @Override public Set<URL> getDirectories() { - //TODO make this work again - //return Collections.unmodifiableSet(directories); + // just so that any old code that calls this doesn't throw an exception will + // be removed at some point when we remove all the deprecated methods return Collections.unmodifiableSet(new HashSet<URL>()); } - + @Override public void registerPlugin(Plugin plugin) throws GateException { registerPlugin(plugin, true); } - + @Override - public void registerPlugin(Plugin plugin, boolean loadDependencies) throws GateException { - - if (!plugins.contains(plugin)) { - + public void registerPlugin(Plugin plugin, boolean loadDependencies) + throws GateException { + + if(!plugins.contains(plugin)) { + Gate.addKnownPlugin(plugin); - + try { - - if (loadDependencies) { - for (Plugin required : plugin.getRequiredPlugins()) { + + if(loadDependencies) { + for(Plugin required : plugin.getRequiredPlugins()) { registerPlugin(required, true); } } - + parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(), - new URL(plugin.getBaseURL(),"creole.xml")); + new URL(plugin.getBaseURL(), "creole.xml")); log.info("CREOLE plugin loaded: " + plugin.getName()); - } - catch(Throwable e) { + } catch(Throwable e) { // it failed: - throw (new GateException("couldn't open creole.xml",e)); + throw (new GateException("couldn't open creole.xml", e)); } - + plugins.add(plugin); - + firePluginLoaded(plugin); } } @Override - public void registerComponent(Class<? extends Resource> resourceClass) throws GateException { + public void registerComponent(Class<? extends Resource> resourceClass) + throws GateException { try { registerPlugin(new Plugin.Component(resourceClass)); + } catch(MalformedURLException mue) { + throw new GateException("Unable to register component", mue); } - catch (MalformedURLException mue) { - throw new GateException("Unable to register component",mue); - } } /** @@ -231,58 +230,59 @@ @Override public void registerDirectories(URL directoryUrl, boolean loadDependencies) throws GateException { - //TODO we need to add support for the loadDependencies option to registerPlugin + // TODO we need to add support for the loadDependencies option to + // registerPlugin try { Plugin plugin = new Plugin.Directory(directoryUrl); - + registerPlugin(plugin); + } catch(Exception e) { + throw new GateException("Faailed to load plugin", e); } - catch (Exception e) { - throw new GateException("Faailed to load plugin",e); - } } - - /** Register a single CREOLE directory. The <CODE>creole.xml</CODE> - * file at the URL is parsed, and <CODE>CreoleData</CODE> objects added - * to the register. If the directory URL has not yet been added it - * is now added. If any other plugins that nees top be loaded for this - * plugin to load (specified by <CODE>REQUIRES</Code> elements in - * <code>creole.xml</code>) will also be loaded. + + /** + * Register a single CREOLE directory. The <CODE>creole.xml</CODE> file at the + * URL is parsed, and <CODE>CreoleData</CODE> objects added to the register. + * If the directory URL has not yet been added it is now added. If any other + * plugins that nees top be loaded for this plugin to load (specified by + * <CODE>REQUIRES</Code> elements in <code>creole.xml</code>) will also be + * loaded. */ @Override public void registerDirectories(URL directoryUrl) throws GateException { - registerDirectories(directoryUrl, true); + registerDirectories(directoryUrl, true); } - + /** * Parse a directory file (represented as an open stream), adding resource * data objects to the CREOLE register as they occur. If the resource is from * a URL then that location is passed (otherwise null). */ - protected void parseDirectory(Plugin plugin, Document jdomDoc, URL directoryUrl, - URL creoleFileUrl) throws GateException { + protected void parseDirectory(Plugin plugin, Document jdomDoc, + URL directoryUrl, URL creoleFileUrl) throws GateException { // create a handler for the directory file and parse it; // this will create ResourceData entries in the register try { - + CreoleAnnotationHandler annotationHandler = - new CreoleAnnotationHandler(plugin); - - GateClassLoader gcl = Gate.getClassLoader().getDisposableClassLoader(creoleFileUrl.toExternalForm()); + new CreoleAnnotationHandler(plugin); + GateClassLoader gcl = Gate.getClassLoader() + .getDisposableClassLoader(creoleFileUrl.toExternalForm()); + // Add any JARs from the creole.xml to the GATE ClassLoader - annotationHandler.addJarsToClassLoader(gcl,jdomDoc); + annotationHandler.addJarsToClassLoader(gcl, jdomDoc); // Make sure there is a RESOURCE element for every resource type the // directory defines annotationHandler.createResourceElementsForDirInfo(jdomDoc); - processFullCreoleXmlTree(directoryUrl, creoleFileUrl, jdomDoc, annotationHandler); - } - catch(IOException e) { + processFullCreoleXmlTree(directoryUrl, creoleFileUrl, jdomDoc, + annotationHandler); + } catch(IOException e) { throw (new GateException(e)); - } - catch(JDOMException je) { + } catch(JDOMException je) { if(DEBUG) je.printStackTrace(Err.getPrintWriter()); throw (new GateException(je)); } @@ -290,8 +290,8 @@ } // parseDirectory private void processFullCreoleXmlTree(URL directoryUrl, URL creoleFileUrl, - Document jdomDoc, CreoleAnnotationHandler annotationHandler) - throws GateException, IOException, JDOMException { + Document jdomDoc, CreoleAnnotationHandler annotationHandler) + throws GateException, IOException, JDOMException { // now we can process any annotations on the new classes // and augment the XML definition annotationHandler.processAnnotations(jdomDoc); @@ -304,13 +304,13 @@ // finally, parse the augmented definition with the normal parser DefaultHandler handler = - new CreoleXmlHandler(this, directoryUrl, creoleFileUrl); + new CreoleXmlHandler(this, directoryUrl, creoleFileUrl); SAXOutputter outputter = - new SAXOutputter(handler, handler, handler, handler); + new SAXOutputter(handler, handler, handler, handler); outputter.output(jdomDoc); if(DEBUG) { Out.prln("done parsing " - + ((directoryUrl == null) ? "null" : directoryUrl.toString())); + + ((directoryUrl == null) ? "null" : directoryUrl.toString())); } } @@ -324,17 +324,17 @@ try { URL creoleDirURL = Gate.getBuiltinCreoleDir(); - //URL creoleFileURL = new URL(creoleDirURL, "creole.xml"); + // URL creoleFileURL = new URL(creoleDirURL, "creole.xml"); // URL creoleFileURL = Files.getGateResource("/creole/creole.xml"); - //parseDirectory(creoleFileURL.openStream(), creoleDirURL, creoleFileURL,true);*/ + // parseDirectory(creoleFileURL.openStream(), creoleDirURL, + // creoleFileURL,true);*/ Plugin plugin = new Plugin.Directory(creoleDirURL); - - parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(), - new URL(plugin.getBaseURL(),"creole.xml")); - log.info("CREOLE plugin loaded: " + plugin.getName()); - - } - catch(Exception e) { + + parseDirectory(plugin, plugin.getCreoleXML(), plugin.getBaseURL(), + new URL(plugin.getBaseURL(), "creole.xml")); + log.info("CREOLE plugin loaded: " + plugin.getName()); + + } catch(Exception e) { if(DEBUG) log.debug(e); throw (new GateException(e)); } @@ -348,24 +348,24 @@ @Override public ResourceData put(String key, ResourceData rd) { - if(super.containsKey(key)) { + if(super.containsKey(key)) { ResourceData rData = super.get(key); rData.increaseReferenceCount(); if(DEBUG) - Out.println(key + " is already defined, new reference will be ignored."); + Out.println( + key + " is already defined, new reference will be ignored."); // TODO not sure what we should actually return here return rData; } - + // get the resource implementation class Class<? extends Resource> resClass = null; try { resClass = rd.getResourceClass(); - } - catch(ClassNotFoundException e) { + } catch(ClassNotFoundException e) { throw new GateRuntimeException( - "Couldn't get resource class from the resource data:" + e); + "Couldn't get resource class from the resource data:" + e); } // add class names to the type lists @@ -398,9 +398,9 @@ // deserialisation controllerTypes.add(rd.getClassName()); } - if (PackagedController.class.isAssignableFrom(resClass)) { + if(PackagedController.class.isAssignableFrom(resClass)) { if(DEBUG) Out.prln("Application: " + resClass); - if (applicationTypes == null) applicationTypes = new HashSet<String>(); + if(applicationTypes == null) applicationTypes = new HashSet<String>(); applicationTypes.add(rd.getClassName()); } @@ -416,46 +416,48 @@ @Override public void unregisterPlugin(Plugin plugin) { - if (plugins.remove(plugin)) { + if(plugins.remove(plugin)) { int prCount = 0; - - for(ResourceInfo rInfo : plugin.getResourceInfoList()) { - ResourceData rData = get(rInfo.getResourceClassName()); - if (rData != null && rData.getReferenceCount() == 1) { - // we only need to remove resources if we are actually going to - // remove the plugin - try { - List<Resource> loaded = - getAllInstances(rInfo.getResourceClassName(),true); - prCount += loaded.size(); - for(Resource r : loaded) { - //System.out.println(r); - Factory.deleteResource(r); - } - } catch(GateException e) { - // not much we can do here other than dump the exception - e.printStackTrace(); + + for(ResourceInfo rInfo : plugin.getResourceInfoList()) { + ResourceData rData = get(rInfo.getResourceClassName()); + if(rData != null && rData.getReferenceCount() == 1) { + // we only need to remove resources if we are actually going to + // remove the plugin + try { + List<Resource> loaded = + getAllInstances(rInfo.getResourceClassName(), true); + prCount += loaded.size(); + for(Resource r : loaded) { + // System.out.println(r); + Factory.deleteResource(r); } + } catch(GateException e) { + // not much we can do here other than dump the exception + e.printStackTrace(); } - - remove(rInfo.getResourceClassName()); } - + + remove(rInfo.getResourceClassName()); + } + try { - Gate.getClassLoader().forgetClassLoader(new URL(plugin.getBaseURL(),"creole.xml").toExternalForm(), plugin); - } - catch (Exception e) { + Gate.getClassLoader().forgetClassLoader( + new URL(plugin.getBaseURL(), "creole.xml").toExternalForm(), + plugin); + } catch(Exception e) { e.printStackTrace(); } log.info("CREOLE plugin unloaded: " + plugin.getName()); - if (prCount > 0) - log.warn(prCount+" resources were deleted as they relied on the " + plugin.getName() +" plugin"); - + if(prCount > 0) + log.warn(prCount + " resources were deleted as they relied on the " + + plugin.getName() + " plugin"); + firePluginUnloaded(plugin); - } + } } - + /** * Removes a CREOLE directory from the set of loaded directories. * @@ -463,11 +465,11 @@ */ @Override public void removeDirectory(URL directory) { - - if (directory == null) return; - - for (Plugin plugin : plugins) { - if (directory.equals(plugin.getBaseURL())) { + + if(directory == null) return; + + for(Plugin plugin : plugins) { + if(directory.equals(plugin.getBaseURL())) { unregisterPlugin(plugin); break; } @@ -482,40 +484,37 @@ public ResourceData remove(Object key) { ResourceData rd = get(key); if(rd == null) return null; - + // TODO not sure what we should actually return here if(rd.reduceReferenceCount() > 0) { if(DEBUG) - Out.println(key - + " is still defined by another plugin so won't be unloaded"); + Out.println( + key + " is still defined by another plugin so won't be unloaded"); return rd; } - + if(DEBUG) { Out.prln(key); Out.prln(rd); } - + try { if(LanguageResource.class.isAssignableFrom(rd.getResourceClass())) { lrTypes.remove(rd.getClassName()); - } - else if(ProcessingResource.class.isAssignableFrom(rd.getResourceClass())) { + } else if(ProcessingResource.class + .isAssignableFrom(rd.getResourceClass())) { prTypes.remove(rd.getClassName()); - } - else if(VisualResource.class.isAssignableFrom(rd.getResourceClass())) { + } else if(VisualResource.class.isAssignableFrom(rd.getResourceClass())) { vrTypes.remove(rd.getClassName()); - } - else if(Controller.class.isAssignableFrom(rd.getResourceClass())) { + } else if(Controller.class.isAssignableFrom(rd.getResourceClass())) { controllerTypes.remove(rd.getClassName()); - } - else if (PackagedController.class.isAssignableFrom(rd.getResourceClass())) { + } else if(PackagedController.class + .isAssignableFrom(rd.getResourceClass())) { applicationTypes.remove(rd.getClassName()); } - } - catch(ClassNotFoundException cnfe) { + } catch(ClassNotFoundException cnfe) { throw new GateRuntimeException( - "Could not load class specified in CREOLE data.", cnfe); + "Could not load class specified in CREOLE data.", cnfe); } // maintain tool types list if(rd.isTool()) toolTypes.remove(rd.getClassName()); @@ -568,9 +567,11 @@ return Collections.unmodifiableSet(toolTypes); } - /** Get the list of types of packaged application resources in the register. */ + /** + * Get the list of types of packaged application resources in the register. + */ @Override - public Set<String>getApplicationTypes() { + public Set<String> getApplicationTypes() { return Collections.unmodifiableSet(applicationTypes); } @@ -584,7 +585,7 @@ while(iter.hasNext()) { String type = iter.next(); instances.addAll(getLrInstances(type)); - }// End while + } // End while return Collections.unmodifiableList(instances); } // getLrInstances() @@ -598,7 +599,7 @@ while(iter.hasNext()) { String type = iter.next(); instances.addAll(getPrInstances(type)); - }// End while + } // End while return Collections.unmodifiableList(instances); } // getPrInstances() @@ -613,7 +614,7 @@ while(iter.hasNext()) { String type = iter.next(); instances.addAll(getVrInstances(type)); - }// End while + } // End while return Collections.unmodifiableList(instances); } // getVrInstances() @@ -624,7 +625,7 @@ if(resData == null) return Collections.emptyList(); return new TypedResourceList<LanguageResource>(resData.getInstantiations(), - LanguageResource.class); + LanguageResource.class); } // getLrInstances @Override @@ -632,8 +633,8 @@ ResourceData resData = get(resourceTypeName); if(resData == null) return Collections.emptyList(); - return new TypedResourceList<ProcessingResource>(resData - .getInstantiations(), ProcessingResource.class); + return new TypedResourceList<ProcessingResource>( + resData.getInstantiations(), ProcessingResource.class); } // getPrInstances @Override @@ -642,7 +643,7 @@ if(resData == null) return Collections.emptyList(); return new TypedResourceList<VisualResource>(resData.getInstantiations(), - VisualResource.class); + VisualResource.class); } // getVrInstances /** Get a list of all non-private instantiations of LR in the register. */ @@ -692,19 +693,18 @@ return getAllInstances(type, false); } + public List<Resource> getAllInstances(String type, boolean includeHidden) + throws GateException { - public List<Resource> getAllInstances(String type, boolean includeHidden) throws GateException { - List<Resource> res = new ArrayList<Resource>(); Class<? extends Resource> targetClass; try { targetClass = - Gate.getClassLoader().loadClass(type).asSubclass(Resource.class); - } - catch(ClassNotFoundException cnfe) { + Gate.getClassLoader().loadClass(type).asSubclass(Resource.class); + } catch(ClassNotFoundException cnfe) { throw new GateException("Invalid type " + type); } - for(Map.Entry<String,ResourceData> entry : entrySet()) { + for(Map.Entry<String, ResourceData> entry : entrySet()) { String aType = entry.getKey(); Class<?> aClass; try { @@ -712,21 +712,21 @@ if(targetClass.isAssignableFrom(aClass)) { // filter out hidden instances Iterator<? extends Resource> newInstancesIter = - get(aType).getInstantiations().iterator(); + get(aType).getInstantiations().iterator(); while(newInstancesIter.hasNext()) { Resource instance = newInstancesIter.next(); - if(includeHidden || !Gate.getHiddenAttribute(instance.getFeatures())) { + if(includeHidden + || !Gate.getHiddenAttribute(instance.getFeatures())) { res.add(instance); } } } - } - catch(ClassNotFoundException cnfe) { + } catch(ClassNotFoundException cnfe) { throw new LuckyException( - "A type registered in the creole register does not exist in the VM!"); + "A type registered in the creole register does not exist in the VM!"); } - }// while(typesIter.hasNext()) + } // while(typesIter.hasNext()) return res; } @@ -779,7 +779,8 @@ * @return a list with Strings representing the large VRs for the * resourceClassName */ - private List<String> getVRsForResource(String resourceClassName, int guiType) { + private List<String> getVRsForResource(String resourceClassName, + int guiType) { // If resurceClassName is null return a simply list if(resourceClassName == null) return Collections.unmodifiableList(new ArrayList<String>()); @@ -788,11 +789,10 @@ GateClassLoader classLoader = Gate.getClassLoader(); try { resourceClass = classLoader.loadClass(resourceClassName); - } - catch(ClassNotFoundException ex) { + } catch(ClassNotFoundException ex) { throw new GateRuntimeException( - "Couldn't get resource class from the resource name:" + ex); - }// End try + "Couldn't get resource class from the resource name:" + ex); + } // End try LinkedList<String> responseList = new LinkedList<String>(); String defaultVR = null; // Take all VRs and for each large one, test if @@ -803,32 +803,31 @@ ResourceData vrResourceData = this.get(vrClassName); if(vrResourceData == null) throw new GateRuntimeException( - "Couldn't get resource data for VR called " + vrClassName); + "Couldn't get resource data for VR called " + vrClassName); if(vrResourceData.getGuiType() == guiType) { String resourceDisplayed = vrResourceData.getResourceDisplayed(); if(resourceDisplayed != null) { Class<?> resourceDisplayedClass = null; try { resourceDisplayedClass = classLoader.loadClass(resourceDisplayed); - } - catch(ClassNotFoundException ex) { + } catch(ClassNotFoundException ex) { throw new GateRuntimeException( - "Couldn't get resource class from the resource name :" - + resourceDisplayed + " " + ex); - }// End try + "Couldn't get resource class from the resource name :" + + resourceDisplayed + " " + ex); + } // End try if(resourceDisplayedClass.isAssignableFrom(resourceClass)) { responseList.add(vrClassName); if(vrResourceData.isMainView()) { defaultVR = vrClassName; - }// End if - }// End if - }// End if - }// End if - }// End while + } // End if + } // End if + } // End if + } // End if + } // End while if(defaultVR != null) { responseList.remove(defaultVR); responseList.addFirst(defaultVR); - }// End if + } // End if return Collections.unmodifiableList(responseList); }// getVRsForResource() @@ -849,30 +848,29 @@ ResourceData vrResourceData = this.get(vrClassName); if(vrResourceData == null) throw new GateRuntimeException( - "Couldn't get resource data for VR called " + vrClassName); + "Couldn't get resource data for VR called " + vrClassName); Class<?> vrResourceClass = null; try { vrResourceClass = vrResourceData.getResourceClass(); - } - catch(ClassNotFoundException ex) { + } catch(ClassNotFoundException ex) { throw new GateRuntimeException( - "Couldn't create a class object for VR called " + vrClassName); - }// End try - // Test if VR can display all types of annotations + "Couldn't create a class object for VR called " + vrClassName); + } // End try + // Test if VR can display all types of annotations if(vrResourceData.getGuiType() == ResourceData.NULL_GUI - && vrResourceData.getAnnotationTypeDisplayed() == null - && vrResourceData.getResourceDisplayed() == null - && gate.creole.AnnotationVisualResource.class - .isAssignableFrom(vrResourceClass)) { + && vrResourceData.getAnnotationTypeDisplayed() == null + && vrResourceData.getResourceDisplayed() == null + && gate.creole.AnnotationVisualResource.class + .isAssignableFrom(vrResourceClass)) { responseList.add(vrClassName); if(vrResourceData.isMainView()) defaultVR = vrClassName; - }// End if - }// End while + } // End if + } // End while if(defaultVR != null) { responseList.remove(defaultVR); responseList.addFirst(defaultVR); - }// End if + } // End if return Collections.unmodifiableList(responseList); }// getAnnotationVRs() @@ -893,33 +891,32 @@ ResourceData vrResourceData = this.get(vrClassName); if(vrResourceData == null) throw new GateRuntimeException( - "Couldn't get resource data for VR called " + vrClassName); + "Couldn't get resource data for VR called " + vrClassName); Class<?> vrResourceClass = null; try { vrResourceClass = vrResourceData.getResourceClass(); - } - catch(ClassNotFoundException ex) { + } catch(ClassNotFoundException ex) { throw new GateRuntimeException( - "Couldn't create a class object for VR called " + vrClassName); - }// End try - // Test if VR can display all types of annotations + "Couldn't create a class object for VR called " + vrClassName); + } // End try + // Test if VR can display all types of annotations if(vrResourceData.getGuiType() == ResourceData.NULL_GUI - && vrResourceData.getAnnotationTypeDisplayed() != null - && gate.creole.AnnotationVisualResource.class - .isAssignableFrom(vrResourceClass)) { + && vrResourceData.getAnnotationTypeDisplayed() != null + && gate.creole.AnnotationVisualResource.class + .isAssignableFrom(vrResourceClass)) { String annotationTypeDisplayed = - vrResourceData.getAnnotationTypeDisplayed(); + vrResourceData.getAnnotationTypeDisplayed(); if(annotationTypeDisplayed.equals(annotationType)) { responseList.add(vrClassName); if(vrResourceData.isMainView()) defaultVR = vrClassName; - }// End if - }// End if - }// End while + } // End if + } // End if + } // End while if(defaultVR != null) { responseList.remove(defaultVR); responseList.addFirst(defaultVR); - }// End if + } // End if return Collections.unmodifiableList(responseList); }// getAnnotationVRs() @@ -946,16 +943,16 @@ ResourceData vrResourceData = this.get(vrClassName); if(vrResourceData == null) throw new GateRuntimeException( - "Couldn't get resource data for VR called " + vrClassName); + "Couldn't get resource data for VR called " + vrClassName); // Test if VR can display all types of annotations if(vrResourceData.getGuiType() == ResourceData.NULL_GUI - && vrResourceData.getAnnotationTypeDisplayed() != null) { + && vrResourceData.getAnnotationTypeDisplayed() != null) { String annotationTypeDisplayed = - vrResourceData.getAnnotationTypeDisplayed(); + vrResourceData.getAnnotationTypeDisplayed(); responseList.add(annotationTypeDisplayed); - }// End if - }// End while + } // End if + } // End while return Collections.unmodifiableList(responseList); }// getVREnabledAnnotationTypes() @@ -991,7 +988,8 @@ public synchronized void removeCreoleListener(CreoleListener l) { if(creoleListeners != null && creoleListeners.contains(l)) { @SuppressWarnings("unchecked") - Vector<CreoleListener> v = (Vector<CreoleListener>)creoleListeners.clone(); + Vector<CreoleListener> v = + (Vector<CreoleListener>)creoleListeners.clone(); v.removeElement(l); creoleListeners = v; } @@ -1000,8 +998,9 @@ @Override public synchronized void addCreoleListener(CreoleListener l) { @SuppressWarnings("unchecked") - Vector<CreoleListener> v = - creoleListeners == null ? new Vector<CreoleListener>(2) : (Vector<CreoleListener>)creoleListeners.clone(); + Vector<CreoleListener> v = creoleListeners == null + ? new Vector<CreoleListener>(2) + : (Vector<CreoleListener>)creoleListeners.clone(); if(!v.contains(l)) { v.addElement(l); creoleListeners = v; @@ -1028,6 +1027,7 @@ * Notifies all listeners that a {@link gate.Resource} has been unloaded from * the system */ + // fireResourceUnloaded /** A list of the types of LR in the register. */ protected Set<String> lrTypes; @@ -1048,25 +1048,26 @@ protected Set<String> applicationTypes; private transient Vector<CreoleListener> creoleListeners; - - private transient List<PluginListener> pluginListeners = new CopyOnWriteArrayList<PluginListener>(); - + + private transient List<PluginListener> pluginListeners = + new CopyOnWriteArrayList<PluginListener>(); + protected void firePluginLoaded(Plugin plugin) { - for (PluginListener listener : pluginListeners) { + for(PluginListener listener : pluginListeners) { listener.pluginLoaded(plugin.getBaseURL()); } } - + protected void firePluginUnloaded(Plugin plugin) { - for (PluginListener listener : pluginListeners) { + for(PluginListener listener : pluginListeners) { listener.pluginUnloaded(plugin.getBaseURL()); } } - + public void addPluginListener(PluginListener listener) { pluginListeners.add(listener); } - + public void removePluginListener(PluginListener listener) { pluginListeners.remove(listener); } @@ -1092,13 +1093,12 @@ } protected void fireResourceRenamed(Resource res, String oldName, - String newName) { + String newName) { if(creoleListeners != null) { Vector<CreoleListener> listeners = creoleListeners; int count = listeners.size(); for(int i = 0; i < count; i++) { - listeners.elementAt(i).resourceRenamed(res, oldName, - newName); + listeners.elementAt(i).resourceRenamed(res, oldName, newName); } } } @@ -1144,7 +1144,8 @@ } @Override - public void resourceRenamed(Resource resource, String oldName, String newName) { + public void resourceRenamed(Resource resource, String oldName, + String newName) { fireResourceRenamed(resource, oldName, newName); } @@ -1169,8 +1170,7 @@ * Type-safe read-only list used by getLrInstances, getPrInstances, etc. */ private static class TypedResourceList<T extends Resource> - extends - AbstractList<T> { + extends AbstractList<T> { private List<Resource> backingList; private Class<T> realType; Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/gui/creole/manager/PluginUpdateManager.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/gui/creole/manager/PluginUpdateManager.java 2016-10-03 01:22:54 UTC (rev 19615) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/gui/creole/manager/PluginUpdateManager.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -202,7 +202,6 @@ @Override public void run() { - // TODO Auto-generated method stub tabs.setEnabledAt(1, false); tabs.setEnabledAt(2, false); showProgressPanel(false); Added: gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java (rev 0) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleMavenCache.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -0,0 +1,97 @@ +package gate.util.maven; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.FileUtils; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.repository.WorkspaceReader; +import org.eclipse.aether.repository.WorkspaceRepository; + +public class SimpleMavenCache implements WorkspaceReader { + + private File root; + + private WorkspaceRepository repo; + + public SimpleMavenCache(File root) { + this.root = root; + repo = new WorkspaceRepository(); + } + + private File getArtifactFile(Artifact artifact) { + File file = root; + + for(String part : artifact.getGroupId().split("\\.")) { + file = new File(file, part); + } + + file = new File(file, artifact.getArtifactId()); + + file = new File(file, artifact.getVersion()); + + file = new File(file, artifact.getArtifactId() + "-" + artifact.getVersion() + + "." + artifact.getExtension()); + + return file; + } + + @Override + public File findArtifact(Artifact artifact) { + + File file = getArtifactFile(artifact); + + if (!file.exists()) return null; + + return file; + } + + @Override + public List<String> findVersions(Artifact artifact) { + List<String> versions = new ArrayList<String>(); + + File file = getArtifactFile(artifact).getParentFile().getParentFile(); + + if(!file.exists() || !file.isDirectory()) return versions; + + for(File version : file.listFiles()) { + if(version.isDirectory()) versions.add(version.getName()); + } + + return versions; + } + + public void cacheArtifact(Artifact artifact) throws IOException { + + File file = getArtifactFile(artifact); + + + //file.getParentFile().mkdirs(); + System.out.println(artifact.getFile()); + + FileUtils.copyFile(artifact.getFile(), file); + } + + @Override + public WorkspaceRepository getRepository() { + return repo; + } + + public static void main(String args[]) throws Exception { + Artifact artifactObj = new DefaultArtifact("uk.ac.gate.plugins", "annie", + "jar", "9.0-SNAPSHOT"); + artifactObj = artifactObj.setFile(new File("/home/mark/.m2/repository/uk/ac/gate/plugins/annie/9.0-SNAPSHOT/annie-9.0-SNAPSHOT.jar")); + + SimpleMavenCache reader = new SimpleMavenCache(new File("repo")); + System.out.println(reader.findArtifact(artifactObj)); + System.out.println(reader.findVersions(artifactObj)); + reader.cacheArtifact(artifactObj); + System.out.println(reader.findArtifact(artifactObj)); + System.out.println(reader.findVersions(artifactObj)); + + } + +} Added: gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java (rev 0) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/maven/SimpleModelResolver.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -0,0 +1,105 @@ +package gate.util.maven; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.model.Parent; +import org.apache.maven.model.building.FileModelSource; +import org.apache.maven.model.building.ModelSource; +import org.apache.maven.model.resolution.InvalidRepositoryException; +import org.apache.maven.model.resolution.ModelResolver; +import org.apache.maven.model.resolution.UnresolvableModelException; +import org.apache.maven.repository.internal.ArtifactDescriptorUtils; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.repository.RemoteRepository; +import org.eclipse.aether.resolution.ArtifactRequest; + +public class SimpleModelResolver implements ModelResolver { + + private final RepositorySystem system; + private final RepositorySystemSession session; + private final Set<String> repositoryIds; + private List<RemoteRepository> repositories; + + /** + * Creates a model resolver to assist building of dependency POMs. + * + * @param system a {@link RepositorySystem} + * @param session a {@link RepositorySystemSession} + * @param remoteRepositories remote repositories to use for resolution. + */ + public SimpleModelResolver(RepositorySystem system, RepositorySystemSession session, + List<RemoteRepository> remoteRepositories) { + this.system = system; + this.session = session; + this.repositories = new ArrayList<RemoteRepository>(remoteRepositories); + this.repositoryIds = new HashSet<String>( + remoteRepositories.size() < 3 ? 3 : remoteRepositories.size()); + + for(RemoteRepository repository : remoteRepositories) { + repositoryIds.add(repository.getId()); + } + } + + /** + * Clone Constructor. + * + * @param original a SimpleModelResolver. + */ + private SimpleModelResolver(SimpleModelResolver original) { + this.session = original.session; + this.system = original.system; + this.repositoryIds = new HashSet<String>(original.repositoryIds); + } + + @Override + public void addRepository(org.apache.maven.model.Repository repository) throws InvalidRepositoryException { + if (!repositoryIds.add(repository.getId())) { + return; + } + + this.repositories.add(ArtifactDescriptorUtils.toRemoteRepository(repository)); + } + + @Override + public ModelResolver newCopy() { + return new SimpleModelResolver(this); + } + + @Override + public ModelSource resolveModel(String groupId, String artifactId, String version) + throws UnresolvableModelException { + Artifact pomArtifact = new DefaultArtifact(groupId, artifactId, "", "pom", version); + + try { + ArtifactRequest request = new ArtifactRequest(pomArtifact, repositories, null); + pomArtifact = system.resolveArtifact(session, request).getArtifact(); + } catch (org.eclipse.aether.resolution.ArtifactResolutionException ex) { + throw new UnresolvableModelException(ex.getMessage(), groupId, artifactId, version, ex); + } + + File pomFile = pomArtifact.getFile(); + + return new FileModelSource(pomFile); + } + + @Override + public ModelSource resolveModel(Parent parent) + throws UnresolvableModelException { + return resolveModel(parent.getGroupId(), parent.getArtifactId(), parent.getVersion()); + + } + + @Override + public void addRepository(org.apache.maven.model.Repository repository, + boolean replace) throws InvalidRepositoryException { + // TODO Auto-generated method stub + + } +} Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java 2016-10-03 01:22:54 UTC (rev 19615) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/util/persistence/PersistenceManager.java 2016-10-03 07:26:21 UTC (rev 19616) @@ -1003,30 +1003,6 @@ else { oos = new ObjectOutputStream(new FileOutputStream(file)); } - - // always write the list of creole URLs first - List<URL> urlList = new ArrayList<URL>(Gate.getCreoleRegister().getDirectories()); - // go through all the URLs in the urlList and make sure that there are no duplicate - // file: entries - Set<String> realPaths = new HashSet<String>(); - List<URL> cleanedList = new ArrayList<URL>(); - for(URL url : urlList) { - if(url.getProtocol().equals("file:")) { - File dir = Files.fileFromURL(url); - try { - dir = dir.getCanonicalFile(); - } catch(Exception ex) { - // ignore - } - if(!realPaths.contains(dir.getPath())) { - realPaths.add(dir.getPath()); - cleanedList.add(url); // add the original URL, we just wanted dir to check if we already had it! - } - } else { - cleanedList.add(url); - } - } - //Object persistentList = getPersistentRepresentation(cleanedList); Object persistentList = getPersistentRepresentation(Gate.getCreoleRegister().getPlugins()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot _______________________________________________ GATE-cvs mailing list GATE-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/gate-cvs