http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java index e92d9879..b27eaa3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/InnerClassFilenameFilter.java @@ -44,11 +44,9 @@ public class InnerClassFilenameFilter implements FilenameFilter { * @param filename the filename to filter on. * @return true if the filename is an inner class of the base class. */ + @Override public boolean accept(File dir, String filename) { - if ((filename.lastIndexOf(".") != filename.lastIndexOf(".class")) - || (filename.indexOf(baseClassName + "$") != 0)) { - return false; - } - return true; + return filename.lastIndexOf('.') == filename.lastIndexOf(".class") + && filename.indexOf(baseClassName + "$") == 0; } }
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java index 79f4574..c3a48ec 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JbossDeploymentTool.java @@ -53,14 +53,14 @@ public class JbossDeploymentTool extends GenericDeploymentTool { * @param ejbFiles the hashtable of files to populate. * @param ddPrefix the prefix to use. */ - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + @Override + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { File jbossDD = new File(getConfig().descriptorDir, ddPrefix + JBOSS_DD); if (jbossDD.exists()) { ejbFiles.put(META_DIR + JBOSS_DD, jbossDD); } else { - log("Unable to locate jboss deployment descriptor. " - + "It was expected to be in " + jbossDD.getPath(), - Project.MSG_WARN); + log("Unable to locate jboss deployment descriptor. It was expected to be in " + + jbossDD.getPath(), Project.MSG_WARN); return; } String descriptorFileName = JBOSS_CMP10D; @@ -73,8 +73,7 @@ public class JbossDeploymentTool extends GenericDeploymentTool { if (jbossCMPD.exists()) { ejbFiles.put(META_DIR + descriptorFileName, jbossCMPD); } else { - log("Unable to locate jboss cmp descriptor. " - + "It was expected to be in " + log("Unable to locate jboss cmp descriptor. It was expected to be in " + jbossCMPD.getPath(), Project.MSG_VERBOSE); return; } @@ -84,15 +83,15 @@ public class JbossDeploymentTool extends GenericDeploymentTool { * Get the vendor specific name of the Jar that will be output. The modification date * of this jar will be checked against the dependent bean classes. */ + @Override File getVendorOutputJarFile(String baseName) { if (getDestDir() == null && getParent().getDestdir() == null) { throw new BuildException("DestDir not specified"); } if (getDestDir() == null) { return new File(getParent().getDestdir(), baseName + jarSuffix); - } else { - return new File(getDestDir(), baseName + jarSuffix); } + return new File(getDestDir(), baseName + jarSuffix); } /** @@ -102,6 +101,7 @@ public class JbossDeploymentTool extends GenericDeploymentTool { * valid * @since ant 1.6 */ + @Override public void validateConfigured() throws BuildException { } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java index 0d9bd13..71c0860 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/JonasDeploymentTool.java @@ -20,9 +20,9 @@ package org.apache.tools.ant.taskdefs.optional.ejb; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.Enumeration; +import java.util.Arrays; import java.util.Hashtable; - +import java.util.List; import javax.xml.parsers.SAXParser; import org.apache.tools.ant.AntClassLoader; @@ -330,6 +330,7 @@ public class JonasDeploymentTool extends GenericDeploymentTool { /* ------------- */ /** {@inheritDoc}. */ + @Override public void processDescriptor(String aDescriptorName, SAXParser saxParser) { descriptorName = aDescriptorName; @@ -347,7 +348,8 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** {@inheritDoc}. */ - protected void writeJar(String baseName, File jarfile, Hashtable ejbFiles, String publicId) + @Override + protected void writeJar(String baseName, File jarfile, Hashtable<String, File> ejbFiles, String publicId) throws BuildException { // create the generic jar first @@ -367,10 +369,11 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** {@inheritDoc}. */ - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + @Override + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { - // JOnAS-specific descriptor deployment - jonasDescriptorName = getJonasDescriptorName(); + // JOnAS-specific descriptor deployment + jonasDescriptorName = getJonasDescriptorName(); File jonasDD = new File(getConfig().descriptorDir, jonasDescriptorName); if (jonasDD.exists()) { @@ -382,6 +385,7 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** {@inheritDoc}. */ + @Override protected File getVendorOutputJarFile(String baseName) { return new File(getDestDir(), baseName + suffix); } @@ -459,6 +463,7 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** {@inheritDoc}. */ + @Override protected String getJarBaseName(String descriptorFileName) { String baseName = null; @@ -500,6 +505,7 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** {@inheritDoc}. */ + @Override protected void registerKnownDTDs(DescriptorHandler handler) { handler.registerDTD(EJB_JAR_1_1_PUBLIC_ID, jonasroot + File.separator + "xml" + File.separator + EJB_JAR_1_1_DTD); @@ -519,15 +525,12 @@ public class JonasDeploymentTool extends GenericDeploymentTool { * @param ejbFiles the hashtable. */ private void addGenICGeneratedFiles( - File genericJarFile, Hashtable ejbFiles) { - Java genicTask = null; // GenIC task - String genicClass = null; // GenIC class (3 are supported for various - // versions + File genericJarFile, Hashtable<String, File> ejbFiles) { if (nogenic) { return; } - genicTask = new Java(getTask()); + Java genicTask = new Java(getTask()); // GenIC task genicTask.setTaskName("genic"); genicTask.setFork(true); @@ -554,13 +557,8 @@ public class JonasDeploymentTool extends GenericDeploymentTool { genicTask.createArg().setValue("-d"); genicTask.createArg().setFile(outputdir); - // work around a bug of GenIC 2.5 - String key; - File f; - Enumeration keys = ejbFiles.keys(); - while (keys.hasMoreElements()) { - key = (String) keys.nextElement(); - f = new File(outputdir + File.separator + key); + for (String key : ejbFiles.keySet()) { + File f = new File(outputdir + File.separator + key); f.getParentFile().mkdirs(); } log("Worked around a bug of GenIC 2.5.", Project.MSG_VERBOSE); @@ -582,15 +580,18 @@ public class JonasDeploymentTool extends GenericDeploymentTool { log("Using classpath: " + classpath.toString(), Project.MSG_VERBOSE); genicTask.setClasspath(classpath); + String genicClass; // GenIC class (3 are supported for various + // versions + // work around a bug of GenIC 2.5 + // class name (search in the classpath provided for the ejbjar element) genicClass = getGenicClassName(classpath); if (genicClass == null) { log("Cannot find GenIC class in classpath.", Project.MSG_ERR); throw new BuildException("GenIC class not found, please check the classpath."); - } else { - log("Using '" + genicClass + "' GenIC class." , Project.MSG_VERBOSE); - genicTask.setClassname(genicClass); - } + } + log("Using '" + genicClass + "' GenIC class." , Project.MSG_VERBOSE); + genicTask.setClassname(genicClass); // keepgenerated if (keepgenerated) { @@ -731,33 +732,38 @@ public class JonasDeploymentTool extends GenericDeploymentTool { * @param saxParser not used. * @throws BuildException if there is an error. */ + @Override protected void checkConfiguration(String descriptorFileName, SAXParser saxParser) throws BuildException { // jonasroot if (jonasroot == null) { - throw new BuildException("The jonasroot attribut is not set."); - } else if (!jonasroot.isDirectory()) { - throw new BuildException("The jonasroot attribut '" + jonasroot - + "' is not a valid directory."); + throw new BuildException("The jonasroot attribute is not set."); + } + if (!jonasroot.isDirectory()) { + throw new BuildException( + "The jonasroot attribute '%s' is not a valid directory.", + jonasroot); } // orb - if (orb != null && !orb.equals(RMI_ORB) && !orb.equals(JEREMIE_ORB) - && !orb.equals(DAVID_ORB)) { - throw new BuildException("The orb attribut '" + orb - + "' is not valid (must be either " - + RMI_ORB + ", " + JEREMIE_ORB + " or " + DAVID_ORB + ")."); + final List<String> validOrbs = + Arrays.asList(RMI_ORB, JEREMIE_ORB, DAVID_ORB); + + if (orb != null && !validOrbs.contains(orb)) { + throw new BuildException( + "The orb attribute '%s' is not valid (must be one of %s.", orb, + validOrbs); } // additionalargs - if (additionalargs != null && additionalargs.equals("")) { - throw new BuildException("Empty additionalargs attribut."); + if (additionalargs != null && additionalargs.isEmpty()) { + throw new BuildException("Empty additionalargs attribute."); } // javac - if (javac != null && javac.equals("")) { - throw new BuildException("Empty javac attribut."); + if (javac != null && javac.isEmpty()) { + throw new BuildException("Empty javac attribute."); } } @@ -776,17 +782,15 @@ public class JonasDeploymentTool extends GenericDeploymentTool { } /** - * Delete a file. If the file is a directory, delete recursivly all the + * Delete a file. If the file is a directory, delete recursively all the * files inside. * * @param aFile file to delete. */ private void deleteAllFiles(File aFile) { if (aFile.isDirectory()) { - File[] someFiles = aFile.listFiles(); - - for (int i = 0; i < someFiles.length; i++) { - deleteAllFiles(someFiles[i]); + for (File child : aFile.listFiles()) { + deleteAllFiles(child); } } aFile.delete(); @@ -800,22 +804,19 @@ public class JonasDeploymentTool extends GenericDeploymentTool { * @param rootDir the current sub-directory to scan. * @param hashtable the hashtable where to add the files. */ - private void addAllFiles(File file, String rootDir, Hashtable hashtable) { - + private void addAllFiles(File file, String rootDir, Hashtable<String, File> hashtable) { if (!file.exists()) { throw new IllegalArgumentException(); } - String newRootDir; if (file.isDirectory()) { - File[] files = file.listFiles(); - for (int i = 0; i < files.length; i++) { - if (rootDir.length() > 0) { - newRootDir = rootDir + File.separator + files[i].getName(); + for (File child : file.listFiles()) { + if (rootDir.isEmpty()) { + newRootDir = child.getName(); } else { - newRootDir = files[i].getName(); + newRootDir = rootDir + File.separator + child.getName(); } - addAllFiles(files[i], newRootDir, hashtable); + addAllFiles(child, newRootDir, hashtable); } } else { hashtable.put(rootDir, file); http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java index cc1bd90..4b0116d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicDeploymentTool.java @@ -23,7 +23,7 @@ import java.io.InputStream; import java.nio.file.Files; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; +import java.util.List; import java.util.Vector; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -36,7 +36,9 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation; import org.apache.tools.ant.types.Environment; +import org.apache.tools.ant.types.Environment.Variable; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.FileUtils; import org.xml.sax.InputSource; @@ -140,7 +142,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { private Path wlClasspath = null; /** System properties for the JVM. */ - private Vector sysprops = new Vector(); + private List<Variable> sysprops = new Vector<>(); /** * The weblogic.StdoutSeverityLevel to use when running the JVM that @@ -159,7 +161,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { sysprops.add(sysp); } - /** * Get the classpath to the weblogic classpaths. * @return the classpath to configure. @@ -181,7 +182,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.outputDir = outputDir; } - /** * Optional classpath to WL6.0. * Weblogic 6.0 will give a warning if the home and remote interfaces @@ -196,7 +196,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.wlClasspath = wlClasspath; } - /** * The compiler (switch <code>-compiler</code>) to use; optional. * This allows for the selection of a different compiler @@ -213,7 +212,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.compiler = compiler; } - /** * Set the rebuild flag to false to only update changes in the jar rather * than rerunning ejbc; optional, default true. @@ -229,7 +227,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.alwaysRebuild = rebuild; } - /** * Sets the weblogic.StdoutSeverityLevel to use when running the JVM that * executes ejbc; optional. Set to 16 to avoid the warnings about EJB Home and @@ -240,7 +237,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.jvmDebugLevel = jvmDebugLevel; } - /** * Get the debug level. * @return the jvm debug level (may be null). @@ -249,8 +245,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { return jvmDebugLevel; } - - /** * Setter used to store the suffix for the generated weblogic jar file. * @@ -260,7 +254,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.jarSuffix = inString; } - /** * controls whether the generic file used as input to * ejbc is retained; defaults to false @@ -271,7 +264,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.keepGeneric = inValue; } - /** * Controls whether weblogic will keep the generated Java * files used to build the class files added to the @@ -280,10 +272,9 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { * @param inValue either 'true' or 'false' */ public void setKeepgenerated(String inValue) { - this.keepgenerated = Boolean.valueOf(inValue).booleanValue(); + this.keepgenerated = Boolean.parseBoolean(inValue); } - /** * Any optional extra arguments pass to the weblogic.ejbc * tool. @@ -293,7 +284,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.additionalArgs = args; } - /** * Set any additional arguments to pass to the weblogic JVM; optional. * @param args the arguments to be passed to the JVM @@ -315,7 +305,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.ejbcClass = ejbcClass; } - /** * Get the ejbc compiler class. * @return the name of the ejbc compiler class. @@ -324,7 +313,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { return ejbcClass; } - /** * <b>Deprecated</b>. Defines the location of the ejb-jar DTD in * the weblogic class hierarchy. Should not be needed, and the @@ -336,7 +324,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { setEJBdtd(inString); } - /** * <b>Deprecated</b>. Defines the location of weblogic DTD in * the weblogic class hierarchy. Should not be needed, and the @@ -348,7 +335,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.weblogicDTD = inString; } - /** * <b>Deprecated</b>. Defines the location of Sun's EJB DTD in * the weblogic class hierarchy. Should not be needed, and the @@ -360,7 +346,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.ejb11DTD = inString; } - /** * Set the value of the oldCMP scheme. This is an antonym for newCMP * @ant.attribute ignore="true' @@ -370,7 +355,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.newCMP = !oldCMP; } - /** * If this is set to true, the new method for locating * CMP descriptors will be used; optional, default false. @@ -387,7 +371,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.newCMP = newCMP; } - /** * Do not EJBC the jar after it has been put together; * optional, default false @@ -397,11 +380,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { this.noEJBC = noEJBC; } - /** * Register the DTDs. * @param handler the handler to use. */ + @Override protected void registerKnownDTDs(DescriptorHandler handler) { // register all the known DTDs handler.registerDTD(PUBLICID_EJB11, DEFAULT_WL51_EJB11_DTD_LOCATION); @@ -410,7 +393,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { handler.registerDTD(PUBLICID_EJB20, DEFAULT_WL60_EJB20_DTD_LOCATION); } - /** * Get the weblogic descriptor handler. * @param srcDir the source directory. @@ -419,8 +401,9 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { protected DescriptorHandler getWeblogicDescriptorHandler(final File srcDir) { DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) { + @Override protected void processElement() { - if (currentElement.equals("type-storage")) { + if ("type-storage".equals(currentElement)) { // Get the filename of vendor specific descriptor String fileNameWithMETA = currentText; //trim the META_INF\ off of the file name @@ -441,44 +424,39 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { handler.registerDTD(PUBLICID_WEBLOGIC_EJB510, weblogicDTD); handler.registerDTD(PUBLICID_WEBLOGIC_EJB600, weblogicDTD); - for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) { - EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next(); - + for (DTDLocation dtdLocation : getConfig().dtdLocations) { handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation()); } return handler; } - /** * Add any vendor specific files which should be included in the EJB Jar. * @param ejbFiles the hash table to be populated. * @param ddPrefix the prefix to use. */ - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + @Override + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { File weblogicDD = new File(getConfig().descriptorDir, ddPrefix + WL_DD); if (weblogicDD.exists()) { ejbFiles.put(META_DIR + WL_DD, weblogicDD); } else { - log("Unable to locate weblogic deployment descriptor. " - + "It was expected to be in " + log("Unable to locate weblogic deployment descriptor. It was expected to be in " + weblogicDD.getPath(), Project.MSG_WARN); return; } if (!newCMP) { log("The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE); - log("Please adjust your weblogic descriptor and set " - + "newCMP=\"true\" to use the new CMP descriptor " - + "inclusion mechanism. ", Project.MSG_VERBOSE); + log("Please adjust your weblogic descriptor and set newCMP=\"true\" to use the new CMP descriptor inclusion mechanism. ", + Project.MSG_VERBOSE); // The the weblogic cmp deployment descriptor File weblogicCMPDD = new File(getConfig().descriptorDir, ddPrefix + WL_CMP_DD); if (weblogicCMPDD.exists()) { - ejbFiles.put(META_DIR + WL_CMP_DD, - weblogicCMPDD); + ejbFiles.put(META_DIR + WL_CMP_DD, weblogicCMPDD); } } else { // now that we have the weblogic descriptor, we parse the file @@ -486,7 +464,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { // this could be the weblogic-cmp-rdbms.xml or any other O/R // mapping tool descriptors. try { - File ejbDescriptor = (File) ejbFiles.get(META_DIR + EJB_DD); + File ejbDescriptor = ejbFiles.get(META_DIR + EJB_DD); SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); @@ -495,36 +473,29 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { DescriptorHandler handler = getWeblogicDescriptorHandler(ejbDescriptor.getParentFile()); - saxParser.parse(new InputSource(Files.newInputStream(weblogicDD.toPath())), - handler); - - Hashtable ht = handler.getFiles(); - Enumeration e = ht.keys(); - - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - - ejbFiles.put(key, ht.get(key)); + try (InputStream in = Files.newInputStream(weblogicDD.toPath())) { + saxParser.parse(new InputSource(in), handler); } + handler.getFiles().forEach(ejbFiles::put); } catch (Exception e) { - String msg = "Exception while adding Vendor specific files: " + e.toString(); - - throw new BuildException(msg, e); + throw new BuildException( + "Exception while adding Vendor specific files: " + + e.toString(), + e); } } } - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent * bean classes. */ + @Override File getVendorOutputJarFile(String baseName) { return new File(getDestDir(), baseName + jarSuffix); } - /** * Helper method invoked by execute() for each WebLogic jar to be built. * Encapsulates the logic of constructing a java task for calling @@ -535,7 +506,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { * jarfile. */ private void buildWeblogicJar(File sourceJar, File destJar, String publicId) { - Java javaTask = null; if (noEJBC) { try { @@ -552,17 +522,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { String ejbcClassName = ejbcClass; try { - javaTask = new Java(getTask()); + Java javaTask = new Java(getTask()); javaTask.setTaskName("ejbc"); javaTask.createJvmarg().setLine(additionalJvmArgs); - if (!(sysprops.isEmpty())) { - for (Enumeration en = sysprops.elements(); en.hasMoreElements();) { - Environment.Variable entry - = (Environment.Variable) en.nextElement(); - javaTask.addSysproperty(entry); - } - } + sysprops.forEach(javaTask::addSysproperty); if (getJvmDebugLevel() != null) { javaTask.createJvmarg().setLine(" -Dweblogic.StdoutSeverityLevel=" + jvmDebugLevel); @@ -592,20 +556,18 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { String buildCompiler = getTask().getProject().getProperty("build.compiler"); - if (buildCompiler != null && buildCompiler.equals("jikes")) { + if ("jikes".equals(buildCompiler)) { javaTask.createArg().setValue("-compiler"); javaTask.createArg().setValue("jikes"); } - } else { - if (!compiler.equals(DEFAULT_COMPILER)) { - javaTask.createArg().setValue("-compiler"); - javaTask.createArg().setLine(compiler); - } + } else if (!DEFAULT_COMPILER.equals(compiler)) { + javaTask.createArg().setValue("-compiler"); + javaTask.createArg().setLine(compiler); } Path combinedClasspath = getCombinedClasspath(); - if (wlClasspath != null && combinedClasspath != null - && combinedClasspath.toString().trim().length() > 0) { + if (!(wlClasspath == null || combinedClasspath == null + || combinedClasspath.toString().trim().isEmpty())) { javaTask.createArg().setValue("-classpath"); javaTask.createArg().setPath(combinedClasspath); } @@ -636,14 +598,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } } catch (Exception e) { // Have to catch this because of the semantics of calling main() - String msg = "Exception while calling " + ejbcClassName - + ". Details: " + e.toString(); - - throw new BuildException(msg, e); + throw new BuildException("Exception while calling " + ejbcClassName + + ". Details: " + e.toString(), e); } } - /** * Method used to encapsulate the writing of the JAR file. Iterates over * the filenames/java.io.Files in the Hashtable stored on the instance @@ -654,7 +613,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { * @param publicId the id to use. * @throws BuildException if there is a problem. */ - protected void writeJar(String baseName, File jarFile, Hashtable files, + @Override + protected void writeJar(String baseName, File jarFile, Hashtable<String, File> files, String publicId) throws BuildException { // need to create a generic jar first. File genericJarFile = super.getVendorOutputJarFile(baseName); @@ -671,16 +631,15 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } } - /** * Called to validate that the tool parameters have been configured. * @throws BuildException if there is an error. */ + @Override public void validateConfigured() throws BuildException { super.validateConfigured(); } - /** * Helper method to check to see if a weblogic EBJ1.1 jar needs to be * rebuilt using ejbc. Called from writeJar it sees if the "Bean" classes @@ -726,35 +685,33 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { genericJar = new JarFile(genericJarFile); wlJar = new JarFile(weblogicJarFile); - Hashtable genericEntries = new Hashtable(); - Hashtable wlEntries = new Hashtable(); - Hashtable replaceEntries = new Hashtable(); + Hashtable<String, JarEntry> genericEntries = new Hashtable<>(); + Hashtable<String, JarEntry> wlEntries = new Hashtable<>(); + Hashtable<String, JarEntry> replaceEntries = new Hashtable<>(); //get the list of generic jar entries - for (Enumeration e = genericJar.entries(); e.hasMoreElements();) { - JarEntry je = (JarEntry) e.nextElement(); - + for (Enumeration<JarEntry> e = genericJar.entries(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); genericEntries.put(je.getName().replace('\\', '/'), je); } //get the list of weblogic jar entries - for (Enumeration e = wlJar.entries(); e.hasMoreElements();) { - JarEntry je = (JarEntry) e.nextElement(); - + for (Enumeration<JarEntry> e = wlJar.entries(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); wlEntries.put(je.getName(), je); } //Cycle Through generic and make sure its in weblogic genericLoader = getClassLoaderFromJar(genericJarFile); - for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) { - String filepath = (String) e.nextElement(); + for (Enumeration<String> e = genericEntries.keys(); e.hasMoreElements();) { + String filepath = e.nextElement(); if (wlEntries.containsKey(filepath)) { // File name/path match // Check files see if same - JarEntry genericEntry = (JarEntry) genericEntries.get(filepath); - JarEntry wlEntry = (JarEntry) wlEntries.get(filepath); + JarEntry genericEntry = genericEntries.get(filepath); + JarEntry wlEntry = wlEntries.get(filepath); if ((genericEntry.getCrc() != wlEntry.getCrc()) || (genericEntry.getSize() != wlEntry.getSize())) { @@ -768,7 +725,7 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { classname = classname.substring(0, classname.lastIndexOf(".class")); - Class genclass = genericLoader.loadClass(classname); + Class<?> genclass = genericLoader.loadClass(classname); if (genclass.isInterface()) { //Interface changed rebuild jar. @@ -776,19 +733,17 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { + " has changed", Project.MSG_VERBOSE); rebuild = true; break; - } else { - //Object class Changed update it. - replaceEntries.put(filepath, genericEntry); - } - } else { - // is it the manifest. If so ignore it - if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) { - //File other then class changed rebuild - log("Non class file " + genericEntry.getName() - + " has changed", Project.MSG_VERBOSE); - rebuild = true; - break; } + //Object class Changed update it. + replaceEntries.put(filepath, genericEntry); + } else if (!genericEntry.getName() + .equals("META-INF/MANIFEST.MF")) { + // it is the manifest, so ignore it + //File other then class changed rebuild + log("Non class file " + genericEntry.getName() + + " has changed", Project.MSG_VERBOSE); + rebuild = true; + break; } } } else { @@ -812,11 +767,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { newJarStream.setLevel(0); //Copy files from old weblogic jar - for (Enumeration e = wlEntries.elements(); e.hasMoreElements();) { - byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; - int bytesRead; - InputStream is; - JarEntry je = (JarEntry) e.nextElement(); + for (Enumeration<JarEntry> e = wlEntries.elements(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); if (je.getCompressedSize() == -1 || je.getCompressedSize() == je.getSize()) { @@ -825,12 +777,13 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { newJarStream.setLevel(JAR_COMPRESS_LEVEL); } + InputStream is; // Update with changed Bean class if (replaceEntries.containsKey(je.getName())) { log("Updating Bean class from generic Jar " + je.getName(), Project.MSG_VERBOSE); // Use the entry from the generic jar - je = (JarEntry) replaceEntries.get(je.getName()); + je = replaceEntries.get(je.getName()); is = genericJar.getInputStream(je); } else { //use fle from original weblogic jar @@ -839,6 +792,8 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } newJarStream.putNextEntry(new JarEntry(je.getName())); + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { newJarStream.write(buffer, 0, bytesRead); } @@ -878,11 +833,11 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { } if (genericLoader != null && genericLoader instanceof AntClassLoader) { + @SuppressWarnings("resource") AntClassLoader loader = (AntClassLoader) genericLoader; loader.cleanup(); } } - return rebuild; } @@ -905,7 +860,6 @@ public class WeblogicDeploymentTool extends GenericDeploymentTool { if (classpath != null) { lookupPath.append(classpath); } - return getTask().getProject().createClassLoader(lookupPath); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java index 0752bbe..15edf46 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WeblogicTOPLinkDeploymentTool.java @@ -62,14 +62,17 @@ public class WeblogicTOPLinkDeploymentTool extends WeblogicDeploymentTool { * @param srcDir the source file. * @return the descriptor handler. */ + @Override protected DescriptorHandler getDescriptorHandler(File srcDir) { DescriptorHandler handler = super.getDescriptorHandler(srcDir); if (toplinkDTD != null) { - handler.registerDTD("-//The Object People, Inc.//" - + "DTD TOPLink for WebLogic CMP 2.5.1//EN", toplinkDTD); + handler.registerDTD( + "-//The Object People, Inc.//DTD TOPLink for WebLogic CMP 2.5.1//EN", + toplinkDTD); } else { - handler.registerDTD("-//The Object People, Inc.//" - + "DTD TOPLink for WebLogic CMP 2.5.1//EN", TL_DTD_LOC); + handler.registerDTD( + "-//The Object People, Inc.//DTD TOPLink for WebLogic CMP 2.5.1//EN", + TL_DTD_LOC); } return handler; } @@ -80,21 +83,20 @@ public class WeblogicTOPLinkDeploymentTool extends WeblogicDeploymentTool { * @param ejbFiles the hashtable to add files to. * @param ddPrefix the prefix to use. */ - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + @Override + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { super.addVendorFiles(ejbFiles, ddPrefix); // Then the toplink deployment descriptor // Setup a naming standard here?. - File toplinkDD = new File(getConfig().descriptorDir, ddPrefix + toplinkDescriptor); if (toplinkDD.exists()) { ejbFiles.put(META_DIR + toplinkDescriptor, toplinkDD); } else { - log("Unable to locate toplink deployment descriptor. " - + "It was expected to be in " + log("Unable to locate toplink deployment descriptor. It was expected to be in " + toplinkDD.getPath(), Project.MSG_WARN); } } @@ -103,11 +105,12 @@ public class WeblogicTOPLinkDeploymentTool extends WeblogicDeploymentTool { * Called to validate that the tool parameters have been configured. * @throws BuildException if there is an error. */ + @Override public void validateConfigured() throws BuildException { super.validateConfigured(); if (toplinkDescriptor == null) { - throw new BuildException("The toplinkdescriptor attribute must " - + "be specified"); + throw new BuildException( + "The toplinkdescriptor attribute must be specified"); } } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java index 63caf50..6acdc47 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java @@ -23,7 +23,6 @@ import java.io.InputStream; import java.nio.file.Files; import java.util.Enumeration; import java.util.Hashtable; -import java.util.Iterator; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.jar.JarOutputStream; @@ -32,6 +31,7 @@ import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.Java; +import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation; import org.apache.tools.ant.types.Environment; import org.apache.tools.ant.types.Path; import org.apache.tools.ant.util.FileUtils; @@ -148,7 +148,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { return wasClasspath.createPath(); } - /** * Set the websphere classpath. * @param wasClasspath the websphere classpath. @@ -157,7 +156,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.wasClasspath = wasClasspath; } - /** Sets the DB Vendor for the Entity Bean mapping ; optional. * <p> * Valid options can be obtained by running the following command: @@ -177,7 +175,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.dbVendor = dbvendor; } - /** * Sets the name of the Database to create; optional. * @@ -187,7 +184,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.dbName = dbName; } - /** * Sets the name of the schema to create; optional. * @@ -197,7 +193,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.dbSchema = dbSchema; } - /** * Flag, default false, to only generate the deployment * code, do not run RMIC or Javac @@ -208,7 +203,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.codegen = codegen; } - /** * Flag, default true, to only output error messages. * @@ -218,7 +212,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.quiet = quiet; } - /** * Flag to disable the validation steps; optional, default false. * @@ -228,7 +221,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.novalidate = novalidate; } - /** * Flag to disable warning and informational messages; optional, default false. * @@ -238,7 +230,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.nowarn = nowarn; } - /** * Flag to disable informational messages; optional, default false. * @@ -248,7 +239,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.noinform = noinform; } - /** * Flag to enable internal tracing when set, optional, default false. * @@ -276,7 +266,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { use35MappingRules = attr; } - /** * Set the rebuild flag to false to only update changes in the jar rather * than rerunning ejbdeploy; optional, default true. @@ -286,7 +275,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.alwaysRebuild = rebuild; } - /** * String value appended to the basename of the deployment * descriptor to create the filename of the WebLogic EJB @@ -297,7 +285,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.jarSuffix = inString; } - /** * This controls whether the generic file used as input to * ejbdeploy is retained; optional, default false. @@ -307,7 +294,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.keepGeneric = inValue; } - /** * Decide, whether ejbdeploy should be called or not; * optional, default true. @@ -318,7 +304,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.ejbdeploy = ejbdeploy; } - /** * Setter used to store the location of the Sun's Generic EJB DTD. This * can be a file on the system or a resource on the classpath. @@ -329,7 +314,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.ejb11DTD = inString; } - /** * Set the value of the oldCMP scheme. This is an antonym for newCMP * @ant.attribute ignore="true" @@ -339,7 +323,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.newCMP = !oldCMP; } - /** * Set the value of the newCMP scheme. The old CMP scheme locates the * websphere CMP descriptor based on the naming convention where the @@ -353,7 +336,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.newCMP = newCMP; } - /** * The directory, where ejbdeploy will write temporary files; * optional, defaults to '_ejbdeploy_temp'. @@ -363,24 +345,20 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { this.tempdir = tempdir; } - /** {@inheritDoc}. */ + @Override protected DescriptorHandler getDescriptorHandler(File srcDir) { DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir); // register all the DTDs, both the ones that are known and // any supplied by the user handler.registerDTD(PUBLICID_EJB11, ejb11DTD); - for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) { - EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next(); - + for (DTDLocation dtdLocation : getConfig().dtdLocations) { handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation()); } - return handler; } - /** * Get a description handler. * @param srcDir the source directory. @@ -389,13 +367,12 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { protected DescriptorHandler getWebsphereDescriptorHandler(final File srcDir) { DescriptorHandler handler = new DescriptorHandler(getTask(), srcDir) { + @Override protected void processElement() { } }; - for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) { - EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next(); - + for (DTDLocation dtdLocation : getConfig().dtdLocations) { handler.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation()); } return handler; @@ -407,9 +384,10 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { * @param ejbFiles a hashtable entryname -> file. * @param baseName a prefix to use. */ - protected void addVendorFiles(Hashtable ejbFiles, String baseName) { + @Override + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String baseName) { - String ddPrefix = (usingBaseJarName() ? "" : baseName); + String ddPrefix = usingBaseJarName() ? "" : baseName; String dbPrefix = (dbVendor == null) ? "" : dbVendor + "-"; // Get the Extensions document @@ -419,8 +397,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { ejbFiles.put(META_DIR + WAS_EXT, websphereEXT); } else { - log("Unable to locate websphere extensions. " - + "It was expected to be in " + log("Unable to locate websphere extensions. It was expected to be in " + websphereEXT.getPath(), Project.MSG_VERBOSE); } @@ -430,17 +407,15 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { ejbFiles.put(META_DIR + WAS_BND, websphereBND); } else { - log("Unable to locate websphere bindings. " - + "It was expected to be in " + log("Unable to locate websphere bindings. It was expected to be in " + websphereBND.getPath(), Project.MSG_VERBOSE); } if (!newCMP) { log("The old method for locating CMP files has been DEPRECATED.", Project.MSG_VERBOSE); - log("Please adjust your websphere descriptor and set " - + "newCMP=\"true\" to use the new CMP descriptor " - + "inclusion mechanism. ", Project.MSG_VERBOSE); + log("Please adjust your websphere descriptor and set newCMP=\"true\" to use the new CMP descriptor inclusion mechanism. ", + Project.MSG_VERBOSE); } else { // We attempt to put in the MAP and Schema files of CMP beans try { @@ -468,25 +443,24 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { } // Theres nothing else to see here...keep moving sonny } catch (Exception e) { - String msg = "Exception while adding Vendor specific files: " - + e.toString(); - - throw new BuildException(msg, e); + throw new BuildException( + "Exception while adding Vendor specific files: " + + e.toString(), + e); } } } - /** * Get the vendor specific name of the Jar that will be output. The * modification date of this jar will be checked against the dependent * bean classes. */ + @Override File getVendorOutputJarFile(String baseName) { return new File(getDestDir(), baseName + jarSuffix); } - /** * Gets the options for the EJB Deploy operation * @@ -494,7 +468,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { */ protected String getOptions() { // Set the options - StringBuffer options = new StringBuffer(); + StringBuilder options = new StringBuilder(); if (dbVendor != null) { options.append(" -dbvendor ").append(dbVendor); @@ -542,7 +516,6 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { return options.toString(); } - /** * Helper method invoked by execute() for each websphere jar to be built. * Encapsulates the logic of constructing a java task for calling @@ -603,15 +576,16 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { } } catch (Exception e) { // Have to catch this because of the semantics of calling main() - String msg = "Exception while calling ejbdeploy. Details: " + e.toString(); - - throw new BuildException(msg, e); + throw new BuildException( + "Exception while calling ejbdeploy. Details: " + e.toString(), + e); } } /** {@inheritDoc}. */ - protected void writeJar(String baseName, File jarFile, Hashtable files, String publicId) - throws BuildException { + @Override + protected void writeJar(String baseName, File jarFile, + Hashtable<String, File> files, String publicId) throws BuildException { if (ejbdeploy) { // create the -generic.jar, if required File genericJarFile = super.getVendorOutputJarFile(baseName); @@ -633,24 +607,23 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { } } - /** * Called to validate that the tool parameters have been configured. * @throws BuildException if there is an error. */ + @Override public void validateConfigured() throws BuildException { super.validateConfigured(); if (ejbdeploy) { String home = getTask().getProject().getProperty("websphere.home"); if (home == null) { - throw new BuildException("The 'websphere.home' property must " - + "be set when 'ejbdeploy=true'"); + throw new BuildException( + "The 'websphere.home' property must be set when 'ejbdeploy=true'"); } websphereHome = getTask().getProject().resolveFile(home); } } - /** * Helper method to check to see if a websphere EBJ1.1 jar needs to be * rebuilt using ejbdeploy. Called from writeJar it sees if the "Bean" @@ -696,34 +669,32 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { genericJar = new JarFile(genericJarFile); wasJar = new JarFile(websphereJarFile); - Hashtable genericEntries = new Hashtable(); - Hashtable wasEntries = new Hashtable(); - Hashtable replaceEntries = new Hashtable(); + Hashtable<String, JarEntry> genericEntries = new Hashtable<>(); + Hashtable<String, JarEntry> wasEntries = new Hashtable<>(); + Hashtable<String, JarEntry> replaceEntries = new Hashtable<>(); //get the list of generic jar entries - for (Enumeration e = genericJar.entries(); e.hasMoreElements();) { - JarEntry je = (JarEntry) e.nextElement(); - + for (Enumeration<JarEntry> e = genericJar.entries(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); genericEntries.put(je.getName().replace('\\', '/'), je); } //get the list of websphere jar entries - for (Enumeration e = wasJar.entries(); e.hasMoreElements();) { - JarEntry je = (JarEntry) e.nextElement(); - + for (Enumeration<JarEntry> e = wasJar.entries(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); wasEntries.put(je.getName(), je); } //Cycle Through generic and make sure its in websphere genericLoader = getClassLoaderFromJar(genericJarFile); - for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) { - String filepath = (String) e.nextElement(); + for (Enumeration<String> e = genericEntries.keys(); e.hasMoreElements();) { + String filepath = e.nextElement(); if (wasEntries.containsKey(filepath)) { // File name/path match // Check files see if same - JarEntry genericEntry = (JarEntry) genericEntries.get(filepath); - JarEntry wasEntry = (JarEntry) wasEntries.get(filepath); + JarEntry genericEntry = genericEntries.get(filepath); + JarEntry wasEntry = wasEntries.get(filepath); if ((genericEntry.getCrc() != wasEntry.getCrc()) || (genericEntry.getSize() != wasEntry.getSize())) { @@ -735,7 +706,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { classname = classname.substring(0, classname.lastIndexOf(".class")); - Class genclass = genericLoader.loadClass(classname); + Class<?> genclass = genericLoader.loadClass(classname); if (genclass.isInterface()) { //Interface changed rebuild jar. @@ -743,14 +714,13 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { + " has changed", Project.MSG_VERBOSE); rebuild = true; break; - } else { - //Object class Changed update it. - replaceEntries.put(filepath, genericEntry); } + //Object class Changed update it. + replaceEntries.put(filepath, genericEntry); } else { // is it the manifest. If so ignore it if (!genericEntry.getName().equals("META-INF/MANIFEST.MF")) { - //File other then class changed rebuild + //File other then class changed rebuild log("Non class file " + genericEntry.getName() + " has changed", Project.MSG_VERBOSE); rebuild = true; @@ -779,11 +749,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { newJarStream.setLevel(0); //Copy files from old websphere jar - for (Enumeration e = wasEntries.elements(); e.hasMoreElements();) { - byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; - int bytesRead; - InputStream is; - JarEntry je = (JarEntry) e.nextElement(); + for (Enumeration<JarEntry> e = wasEntries.elements(); e.hasMoreElements();) { + JarEntry je = e.nextElement(); if (je.getCompressedSize() == -1 || je.getCompressedSize() == je.getSize()) { @@ -792,12 +759,13 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { newJarStream.setLevel(JAR_COMPRESS_LEVEL); } + InputStream is; // Update with changed Bean class if (replaceEntries.containsKey(je.getName())) { log("Updating Bean class from generic Jar " + je.getName(), Project.MSG_VERBOSE); // Use the entry from the generic jar - je = (JarEntry) replaceEntries.get(je.getName()); + je = replaceEntries.get(je.getName()); is = genericJar.getInputStream(je); } else { //use fle from original websphere jar @@ -806,6 +774,8 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { } newJarStream.putNextEntry(new JarEntry(je.getName())); + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { newJarStream.write(buffer, 0, bytesRead); } @@ -819,17 +789,15 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { rebuild = true; } } catch (ClassNotFoundException cnfe) { - String cnfmsg = "ClassNotFoundException while processing ejb-jar file" - + ". Details: " - + cnfe.getMessage(); - - throw new BuildException(cnfmsg, cnfe); + throw new BuildException( + "ClassNotFoundException while processing ejb-jar file. Details: " + + cnfe.getMessage(), + cnfe); } catch (IOException ioe) { - String msg = "IOException while processing ejb-jar file " - + ". Details: " - + ioe.getMessage(); - - throw new BuildException(msg, ioe); + throw new BuildException( + "IOException while processing ejb-jar file . Details: " + + ioe.getMessage(), + ioe); } finally { // need to close files and perhaps rename output FileUtils.close(genericJar); @@ -846,15 +814,14 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool { } if (genericLoader != null && genericLoader instanceof AntClassLoader) { + @SuppressWarnings("resource") AntClassLoader loader = (AntClassLoader) genericLoader; loader.cleanup(); } } - return rebuild; } - /** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatability.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatability.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatability.java index 2c06daf..1d748e4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatability.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatability.java @@ -51,6 +51,7 @@ public final class Compatability { * * @return the name of compatibility level */ + @Override public String toString() { return name; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatibility.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatibility.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatibility.java index bb28cd6..5c3240d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatibility.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Compatibility.java @@ -51,6 +51,7 @@ public final class Compatibility { * * @return the name of compatibility level */ + @Override public String toString() { return name; } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java index d13d2f4..a0c7e9d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/Extension.java @@ -18,11 +18,12 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.util.ArrayList; -import java.util.Iterator; -import java.util.Map; +import java.util.List; +import java.util.Objects; import java.util.StringTokenizer; import java.util.jar.Attributes; import java.util.jar.Manifest; +import java.util.stream.Stream; import org.apache.tools.ant.util.DeweyDecimal; import org.apache.tools.ant.util.StringUtils; @@ -187,31 +188,13 @@ public final class Extension { */ public static Extension[] getAvailable(final Manifest manifest) { if (null == manifest) { - return new Extension[ 0 ]; + return new Extension[0]; } - - final ArrayList results = new ArrayList(); - - final Attributes mainAttributes = manifest.getMainAttributes(); - if (null != mainAttributes) { - final Extension extension = getExtension("", mainAttributes); - if (null != extension) { - results.add(extension); - } - } - - final Map entries = manifest.getEntries(); - final Iterator keys = entries.keySet().iterator(); - while (keys.hasNext()) { - final String key = (String) keys.next(); - final Attributes attributes = (Attributes) entries.get(key); - final Extension extension = getExtension("", attributes); - if (null != extension) { - results.add(extension); - } - } - - return (Extension[]) results.toArray(new Extension[results.size()]); + return Stream + .concat(Stream.of(manifest.getMainAttributes()), + manifest.getEntries().values().stream()) + .map(attrs -> getExtension("", attrs)).filter(Objects::nonNull) + .toArray(Extension[]::new); } /** @@ -491,10 +474,11 @@ public final class Extension { * * @return string representation of object. */ + @Override public String toString() { final String brace = ": "; - final StringBuffer sb = new StringBuffer(EXTENSION_NAME.toString()); + final StringBuilder sb = new StringBuilder(EXTENSION_NAME.toString()); sb.append(brace); sb.append(extensionName); sb.append(StringUtils.LINE_SEP); @@ -567,22 +551,17 @@ public final class Extension { */ private static Extension[] getListed(final Manifest manifest, final Attributes.Name listKey) { - final ArrayList results = new ArrayList(); + final List<Extension> results = new ArrayList<>(); final Attributes mainAttributes = manifest.getMainAttributes(); if (null != mainAttributes) { getExtension(mainAttributes, results, listKey); } - final Map entries = manifest.getEntries(); - final Iterator keys = entries.keySet().iterator(); - while (keys.hasNext()) { - final String key = (String) keys.next(); - final Attributes attributes = (Attributes) entries.get(key); - getExtension(attributes, results, listKey); - } + manifest.getEntries().values() + .forEach(attributes -> getExtension(attributes, results, listKey)); - return (Extension[]) results.toArray(new Extension[results.size()]); + return results.toArray(new Extension[results.size()]); } /** @@ -595,18 +574,14 @@ public final class Extension { * or OPTIONAL_EXTENSION_LIST */ private static void getExtension(final Attributes attributes, - final ArrayList required, + final List<Extension> required, final Attributes.Name listKey) { final String names = attributes.getValue(listKey); if (null == names) { return; } - - final String[] extensions = split(names, " "); - for (int i = 0; i < extensions.length; i++) { - final String prefix = extensions[ i ] + "-"; - final Extension extension = getExtension(prefix, attributes); - + for (final String prefix : split(names, " ")) { + final Extension extension = getExtension(prefix + "-", attributes); if (null != extension) { required.add(extension); } @@ -623,10 +598,10 @@ public final class Extension { private static String[] split(final String string, final String onToken) { final StringTokenizer tokenizer = new StringTokenizer(string, onToken); - final String[] result = new String[ tokenizer.countTokens() ]; + final String[] result = new String[tokenizer.countTokens()]; for (int i = 0; i < result.length; i++) { - result[ i ] = tokenizer.nextToken(); + result[i] = tokenizer.nextToken(); } return result; http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java index b3cfddc..4747821 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java @@ -150,6 +150,7 @@ public class ExtensionAdapter extends DataType { * @param reference the reference to which this instance is associated * @exception BuildException if this instance already has been configured. */ + @Override public void setRefid(final Reference reference) throws BuildException { if (null != extensionName @@ -183,8 +184,7 @@ public class ExtensionAdapter extends DataType { } dieOnCircularReference(); if (null == extensionName) { - final String message = "Extension is missing name."; - throw new BuildException(message); + throw new BuildException("Extension is missing name."); } String specificationVersionString = null; @@ -209,7 +209,8 @@ public class ExtensionAdapter extends DataType { * @return the extension in a string. * @see java.lang.Object#toString() */ + @Override public String toString() { - return "{" + toExtension().toString() + "}"; + return "{" + toExtension() + "}"; } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java index 5aba37c..2868027 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionSet.java @@ -19,7 +19,7 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.util.ArrayList; import java.util.Arrays; -import java.util.Iterator; +import java.util.List; import java.util.Stack; import org.apache.tools.ant.BuildException; @@ -39,12 +39,12 @@ public class ExtensionSet /** * ExtensionAdapter objects representing extensions. */ - private final ArrayList extensions = new ArrayList(); + private final List<ExtensionAdapter> extensions = new ArrayList<>(); /** * Filesets specifying all the extensions wanted. */ - private final ArrayList extensionsFilesets = new ArrayList(); + private final List<FileSet> extensionsFilesets = new ArrayList<>(); /** * Adds an extension that this library requires. @@ -98,9 +98,9 @@ public class ExtensionSet return ((ExtensionSet) getCheckedRef()).toExtensions(proj); } dieOnCircularReference(); - final ArrayList extensionsList = ExtensionUtil.toExtensions(extensions); + final List<Extension> extensionsList = ExtensionUtil.toExtensions(extensions); ExtensionUtil.extractExtensions(proj, extensionsList, extensionsFilesets); - return (Extension[]) extensionsList.toArray(new Extension[extensionsList.size()]); + return extensionsList.toArray(new Extension[extensionsList.size()]); } /** @@ -123,7 +123,7 @@ public class ExtensionSet } @Override - protected synchronized void dieOnCircularReference(Stack stk, Project p) + protected synchronized void dieOnCircularReference(Stack<Object> stk, Project p) throws BuildException { if (isChecked()) { return; @@ -131,12 +131,11 @@ public class ExtensionSet if (isReference()) { super.dieOnCircularReference(stk, p); } else { - for (Iterator i = extensions.iterator(); i.hasNext();) { - pushAndInvokeCircularReferenceCheck((ExtensionAdapter) i.next(), - stk, p); + for (ExtensionAdapter extensionAdapter : extensions) { + pushAndInvokeCircularReferenceCheck(extensionAdapter, stk, p); } - for (Iterator i = extensionsFilesets.iterator(); i.hasNext();) { - pushAndInvokeCircularReferenceCheck((FileSet) i.next(), stk, p); + for (FileSet fileSet : extensionsFilesets) { + pushAndInvokeCircularReferenceCheck(fileSet, stk, p); } setChecked(true); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java index 00d4599..7f951d9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionUtil.java @@ -20,16 +20,15 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.io.File; import java.io.IOException; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.jar.JarFile; import java.util.jar.Manifest; +import java.util.stream.Collectors; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.types.FileSet; -import org.apache.tools.ant.util.FileUtils; /** * A set of useful methods relating to extensions. @@ -49,19 +48,10 @@ public final class ExtensionUtil { * @param adapters the list of ExtensionAdapterss to add to convert * @throws BuildException if an error occurs */ - static ArrayList toExtensions(final List adapters) + static ArrayList<Extension> toExtensions(final List<? extends ExtensionAdapter> adapters) throws BuildException { - final ArrayList results = new ArrayList(); - - final int size = adapters.size(); - for (int i = 0; i < size; i++) { - final ExtensionAdapter adapter = - (ExtensionAdapter) adapters.get(i); - final Extension extension = adapter.toExtension(); - results.add(extension); - } - - return results; + return adapters.stream().map(ExtensionAdapter::toExtension) + .collect(Collectors.toCollection(ArrayList::new)); } /** @@ -72,14 +62,12 @@ public final class ExtensionUtil { * @throws BuildException if an error occurs */ static void extractExtensions(final Project project, - final List libraries, - final List fileset) + final List<Extension> libraries, + final List<FileSet> fileset) throws BuildException { if (!fileset.isEmpty()) { - final Extension[] extensions = getExtensions(project, - fileset); - for (int i = 0; i < extensions.length; i++) { - libraries.add(extensions[ i ]); + for (Extension extension : getExtensions(project, fileset)) { + libraries.add(extension); } } } @@ -92,13 +80,11 @@ public final class ExtensionUtil { * @throws BuildException if failing to scan libraries */ private static Extension[] getExtensions(final Project project, - final List libraries) + final List<FileSet> libraries) throws BuildException { - final ArrayList extensions = new ArrayList(); - final Iterator iterator = libraries.iterator(); - while (iterator.hasNext()) { - final FileSet fileSet = (FileSet) iterator.next(); - + final List<Extension> extensions = new ArrayList<>(); + + for (FileSet fileSet : libraries) { boolean includeImpl = true; boolean includeURL = true; @@ -116,7 +102,7 @@ public final class ExtensionUtil { loadExtensions(file, extensions, includeImpl, includeURL); } } - return (Extension[]) extensions.toArray(new Extension[extensions.size()]); + return extensions.toArray(new Extension[extensions.size()]); } /** @@ -127,23 +113,17 @@ public final class ExtensionUtil { * @throws BuildException if there is an error */ private static void loadExtensions(final File file, - final List extensionList, + final List<Extension> extensionList, final boolean includeImpl, final boolean includeURL) throws BuildException { - JarFile jarFile = null; - try { - jarFile = new JarFile(file); - final Extension[] extensions = - Extension.getAvailable(jarFile.getManifest()); - for (int i = 0; i < extensions.length; i++) { - final Extension extension = extensions[ i ]; + try (JarFile jarFile = new JarFile(file)) { + for (Extension extension : Extension + .getAvailable(jarFile.getManifest())) { addExtension(extensionList, extension, includeImpl, includeURL); } } catch (final Exception e) { throw new BuildException(e.getMessage(), e); - } finally { - FileUtils.close(jarFile); } } @@ -158,7 +138,7 @@ public final class ExtensionUtil { * @param includeImpl false to exclude implementation details * @param includeURL false to exclude implementation URL */ - private static void addExtension(final List extensionList, + private static void addExtension(final List<Extension> extensionList, final Extension originalExtension, final boolean includeImpl, final boolean includeURL) { @@ -205,18 +185,14 @@ public final class ExtensionUtil { */ static Manifest getManifest(final File file) throws BuildException { - JarFile jarFile = null; - try { - jarFile = new JarFile(file); + try (JarFile jarFile = new JarFile(file)) { Manifest m = jarFile.getManifest(); if (m == null) { - throw new BuildException(file + " doesn't have a MANIFEST"); + throw new BuildException("%s doesn't have a MANIFEST", file); } return m; } catch (final IOException ioe) { throw new BuildException(ioe.getMessage(), ioe); - } finally { - FileUtils.close(jarFile); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtraAttribute.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtraAttribute.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtraAttribute.java index d52bec4..21d1144 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtraAttribute.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtraAttribute.java @@ -73,11 +73,11 @@ public class ExtraAttribute { */ public void validate() throws BuildException { if (null == name) { - final String message = "Missing name from parameter."; - throw new BuildException(message); - } else if (null == value) { - final String message = "Missing value from parameter " + name + "."; - throw new BuildException(message); + throw new BuildException("Missing name from parameter."); + } + if (null == value) { + throw new BuildException( + "Missing value from parameter " + name + "."); } } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibAvailableTask.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibAvailableTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibAvailableTask.java index cebcf0d..84ba74a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibAvailableTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibAvailableTask.java @@ -18,11 +18,12 @@ package org.apache.tools.ant.taskdefs.optional.extension; import java.io.File; -import java.util.Iterator; +import java.util.List; import java.util.Vector; -import java.util.jar.Manifest; +import java.util.stream.Stream; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; /** @@ -40,7 +41,7 @@ public class JarLibAvailableTask extends Task { * Filesets specifying all the librarys * to display information about. */ - private final Vector extensionFileSets = new Vector(); + private final List<ExtensionSet> extensionFileSets = new Vector<>(); /** * The name of the property to set if extension is available. @@ -77,9 +78,8 @@ public class JarLibAvailableTask extends Task { */ public void addConfiguredExtension(final ExtensionAdapter extension) { if (null != requiredExtension) { - final String message = "Can not specify extension to " - + "search for multiple times."; - throw new BuildException(message); + throw new BuildException( + "Can not specify extension to search for multiple times."); } requiredExtension = extension; } @@ -90,7 +90,7 @@ public class JarLibAvailableTask extends Task { * @param extensionSet a set of extensions to search in. */ public void addConfiguredExtensionSet(final ExtensionSet extensionSet) { - extensionFileSets.addElement(extensionSet); + extensionFileSets.add(extensionSet); } /** @@ -98,35 +98,24 @@ public class JarLibAvailableTask extends Task { * * @throws BuildException if something goes wrong. */ + @Override public void execute() throws BuildException { validate(); - final Extension test = requiredExtension.toExtension(); + final Project prj = getProject(); + final Stream<Extension> extensions; // Check if list of files to check has been specified if (!extensionFileSets.isEmpty()) { - final Iterator iterator = extensionFileSets.iterator(); - while (iterator.hasNext()) { - final ExtensionSet extensionSet - = (ExtensionSet) iterator.next(); - final Extension[] extensions = - extensionSet.toExtensions(getProject()); - for (int i = 0; i < extensions.length; i++) { - final Extension extension = extensions[ i ]; - if (extension.isCompatibleWith(test)) { - getProject().setNewProperty(propertyName, "true"); - } - } - } + extensions = extensionFileSets.stream() + .map(xset -> xset.toExtensions(prj)).flatMap(Stream::of); } else { - final Manifest manifest = ExtensionUtil.getManifest(libraryFile); - final Extension[] extensions = Extension.getAvailable(manifest); - for (int i = 0; i < extensions.length; i++) { - final Extension extension = extensions[ i ]; - if (extension.isCompatibleWith(test)) { - getProject().setNewProperty(propertyName, "true"); - } - } + extensions = Stream.of( + Extension.getAvailable(ExtensionUtil.getManifest(libraryFile))); + } + final Extension test = requiredExtension.toExtension(); + if (extensions.anyMatch(x -> x.isCompatibleWith(test))) { + prj.setNewProperty(propertyName, "true"); } } @@ -137,21 +126,16 @@ public class JarLibAvailableTask extends Task { */ private void validate() throws BuildException { if (null == requiredExtension) { - final String message = "Extension element must be specified."; - throw new BuildException(message); + throw new BuildException("Extension element must be specified."); } - - if (null == libraryFile && extensionFileSets.isEmpty()) { - final String message = "File attribute not specified."; - throw new BuildException(message); - } - if (null != libraryFile && !libraryFile.exists()) { - final String message = "File '" + libraryFile + "' does not exist."; - throw new BuildException(message); - } - if (null != libraryFile && !libraryFile.isFile()) { - final String message = "\'" + libraryFile + "\' is not a file."; - throw new BuildException(message); + if (null == libraryFile) { + if (extensionFileSets.isEmpty()) { + throw new BuildException("File attribute not specified."); + } + } else if (!libraryFile.exists()) { + throw new BuildException("File '%s' does not exist.", libraryFile); + } else if (!libraryFile.isFile()) { + throw new BuildException("'%s' is not a file.", libraryFile); } } }
