Revision: 19637 http://sourceforge.net/p/gate/code/19637 Author: markagreenwood Date: 2016-10-05 17:39:07 +0000 (Wed, 05 Oct 2016) Log Message: ----------- fixed a few bugs and possible performance issues highlighted by findbugs
Modified Paths: -------------- gate/branches/sawdust2/gate-core/pom.xml gate/branches/sawdust2/gate-core/src/main/java/gate/Factory.java gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java Modified: gate/branches/sawdust2/gate-core/pom.xml =================================================================== --- gate/branches/sawdust2/gate-core/pom.xml 2016-10-05 13:52:15 UTC (rev 19636) +++ gate/branches/sawdust2/gate-core/pom.xml 2016-10-05 17:39:07 UTC (rev 19637) @@ -464,7 +464,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.11</version> + <version>4.12</version> <scope>test</scope> </dependency> @@ -560,6 +560,8 @@ <artifactId>findbugs-maven-plugin</artifactId> <version>3.0.3</version> <configuration> + <findbugsXmlOutput>true</findbugsXmlOutput> + <findbugsXmlWithMessages>true</findbugsXmlWithMessages> <xmlOutput>true</xmlOutput> <effort>Max</effort> <threshold>Low</threshold> Modified: gate/branches/sawdust2/gate-core/src/main/java/gate/Factory.java =================================================================== --- gate/branches/sawdust2/gate-core/src/main/java/gate/Factory.java 2016-10-05 13:52:15 UTC (rev 19636) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/Factory.java 2016-10-05 17:39:07 UTC (rev 19637) @@ -310,6 +310,7 @@ if(DEBUG) Out.prln(resClass.getName() + " is a VR"); } else if(Controller.class.isAssignableFrom(resClass)) { // type specific stuff for Controllers + if(DEBUG) Out.prln(resClass.getName() + " is a Controller"); } // set the parameterValues of the resource @@ -368,7 +369,7 @@ if(sourceUrl != null) { URI sourceURI = sourceUrl.toURI(); resourceName = sourceURI.getPath().trim(); - if(resourceName == null || resourceName.length() == 0 + if(resourceName.length() == 0 || resourceName.equals("/")) { // this URI has no path -> use the whole string resourceName = sourceURI.toString(); @@ -400,7 +401,7 @@ Map<String, EventListener> listeners = new HashMap<String, EventListener>(gate.Gate.getListeners()); // set the listeners if any - if(listeners != null && !listeners.isEmpty()) { + if(!listeners.isEmpty()) { try { if(DEBUG) Out.prln("Setting the listeners for " + res.toString()); AbstractResource.setResourceListeners(res, listeners); @@ -425,7 +426,7 @@ res = res.init(); // remove the listeners if any - if(listeners != null && !listeners.isEmpty()) { + if(!listeners.isEmpty()) { try { if(DEBUG) Out.prln("Removing the listeners for " + res.toString()); AbstractResource.removeResourceListeners(res, listeners); @@ -848,7 +849,7 @@ throw new PersistenceException("Couldn't create DS class: " + e); } - godfreyTheDataStore.setStorageUrl(storageUrl.toString()); + godfreyTheDataStore.setStorageUrl(storageUrl); return godfreyTheDataStore; } // instantiateDS(dataStoreClassName, storageURL) 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-05 13:52:15 UTC (rev 19636) +++ gate/branches/sawdust2/gate-core/src/main/java/gate/Plugin.java 2016-10-05 17:39:07 UTC (rev 19637) @@ -101,7 +101,7 @@ * This is the URL against which all relative URLs in the CREOLE * metadata are resolved */ - protected transient URL baseURL; + protected transient URI baseURL; protected transient String name; @@ -153,7 +153,13 @@ } public URL getBaseURL() { - return baseURL; + try { + return baseURL.toURL(); + } catch(MalformedURLException e) { + // this should be impossible because of the way we have got hold of the + // URI + throw new RuntimeException(e); + } } public boolean isValid() { @@ -262,7 +268,7 @@ // now process the jar files with SCAN="true", looking for any extra // CreoleResource annotated classes. for(String jarFile : jarsToScan) { - URL jarUrl = new URL(baseURL, jarFile); + URL jarUrl = new URL(getBaseURL(), jarFile); scanJar(jarUrl, resInfos); } @@ -340,7 +346,7 @@ // way and read their CreoleResource annotations (if any). URL[] jarUrls = new URL[allJars.size()]; for(int i = 0; i < jarUrls.length; i++) { - jarUrls[i] = new URL(baseURL, allJars.get(i)); + jarUrls[i] = new URL(getBaseURL(), allJars.get(i)); } // TODO shouldn't we use a proper temp gate class loader which we @@ -366,13 +372,18 @@ public static class Directory extends Plugin { public Directory(URL directoryURL) { - baseURL = Gate.normaliseCreoleUrl(directoryURL); + try { + baseURL = Gate.normaliseCreoleUrl(directoryURL).toURI(); + } catch(URISyntaxException e) { + //this should never happen but.... + throw new RuntimeException(e); + } } @Override public Document getCreoleXML() throws Exception { SAXBuilder builder = new SAXBuilder(false); - URL creoleFileURL = new URL(baseURL, "creole.xml"); + URL creoleFileURL = new URL(getBaseURL(), "creole.xml"); return builder.build(creoleFileURL); } @@ -430,7 +441,9 @@ @Override public boolean equals(Object obj) { + if(this == obj) return true; + if (obj == null) return false; if(getClass() != obj.getClass()) return false; Maven other = (Maven)obj; @@ -454,7 +467,7 @@ "this plugin doesn't have any resources you can copy as you would know had you called hasResources first :P"); try (FileSystem zipFs = - FileSystems.newFileSystem(baseURL.toURI(), new HashMap<>());) { + FileSystems.newFileSystem(baseURL, new HashMap<>());) { Path target = Paths.get(dir.toURI()); Path pathInZip = zipFs.getPath("/resources"); @@ -475,19 +488,16 @@ return FileVisitResult.CONTINUE; } }); - } catch(URISyntaxException e) { - // this shouldn't be possible because of where the URI is coming from - throw new IOException(e); } } @Override public boolean hasResources() { - try (FileSystem zipFs = FileSystems.newFileSystem(baseURL.toURI(), new HashMap<>());) { + try (FileSystem zipFs = FileSystems.newFileSystem(baseURL, new HashMap<>());) { Path pathInZip = zipFs.getPath("/resources"); return Files.isDirectory(pathInZip); } - catch (IOException | URISyntaxException e) { + catch (IOException e) { return false; } } @@ -531,12 +541,12 @@ artifactRequest); baseURL = - new URL("jar:" + new URI("jar:" + artifactResult.getArtifact().getFile().toURI().toURL() + "!/"); // check it has a creole.xml at the root - URL directoryXmlFileUrl = new URL(baseURL, "creole.xml"); + URL directoryXmlFileUrl = new URL(getBaseURL(), "creole.xml"); InputStream creoleStream = null; @@ -701,7 +711,12 @@ public Component(Class<? extends Resource> resourceClass) throws MalformedURLException { this.resourceClass = resourceClass; - baseURL = new URL(resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class"), "."); + try { + baseURL = (new URL(resourceClass.getResource("/gate/creole/CreoleRegisterImpl.class"), ".")).toURI(); + } catch(URISyntaxException e) { + //this should never happen + throw new RuntimeException(e); + } } @Override 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