http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java index dd46269..87925e4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/BorlandGenerateClient.java @@ -133,7 +133,6 @@ public class BorlandGenerateClient extends Task { createClasspath().setRefid(r); } - /** * Do the work. * @@ -141,6 +140,7 @@ public class BorlandGenerateClient extends Task { * * @exception BuildException if something goes wrong with the build */ + @Override public void execute() throws BuildException { if (ejbjarfile == null || ejbjarfile.isDirectory()) { throw new BuildException("invalid ejb jar file."); @@ -162,13 +162,12 @@ public class BorlandGenerateClient extends Task { if (!(version == BorlandDeploymentTool.BES || version == BorlandDeploymentTool.BAS)) { - throw new BuildException("version " + version - + " is not supported"); + throw new BuildException("version %d is not supported", version); } log("client jar file is " + clientjarfile); - if (mode.equalsIgnoreCase(FORK_MODE)) { + if (FORK_MODE.equalsIgnoreCase(mode)) { executeFork(); } else { executeJava(); @@ -182,15 +181,14 @@ public class BorlandGenerateClient extends Task { protected void executeJava() throws BuildException { try { if (version == BorlandDeploymentTool.BES) { - throw new BuildException("java mode is supported only for " - + "previous version <=" + BorlandDeploymentTool.BAS); + throw new BuildException( + "java mode is supported only for previous version <= %d", + BorlandDeploymentTool.BAS); } log("mode : java"); - Java execTask = null; - execTask = new Java(this); - + Java execTask = new Java(this); execTask.setDir(new File(".")); execTask.setClassname("com.inprise.server.commandline.EJBUtilities"); //classpath @@ -218,8 +216,7 @@ public class BorlandGenerateClient extends Task { } catch (Exception e) { // Have to catch this because of the semantics of calling main() - String msg = "Exception while calling generateclient Details: " + e.toString(); - throw new BuildException(msg, e); + throw new BuildException("Exception while calling generateclient", e); } } @@ -227,7 +224,7 @@ public class BorlandGenerateClient extends Task { * launch the generate client using system api. * @throws BuildException if there is an error. */ - protected void executeFork() throws BuildException { + protected void executeFork() throws BuildException { if (version == BorlandDeploymentTool.BAS) { executeForkV4(); } @@ -240,13 +237,11 @@ public class BorlandGenerateClient extends Task { * launch the generate client using system api. * @throws BuildException if there is an error. */ - protected void executeForkV4() throws BuildException { + protected void executeForkV4() throws BuildException { try { - log("mode : fork " + BorlandDeploymentTool.BAS, Project.MSG_DEBUG); ExecTask execTask = new ExecTask(this); - execTask.setDir(new File(".")); execTask.setExecutable("iastool"); execTask.createArg().setValue("generateclient"); @@ -267,24 +262,19 @@ public class BorlandGenerateClient extends Task { execTask.execute(); } catch (Exception e) { // Have to catch this because of the semantics of calling main() - String msg = "Exception while calling generateclient Details: " - + e.toString(); - throw new BuildException(msg, e); + throw new BuildException("Exception while calling generateclient", e); } - } /** * launch the generate client using system api. * @throws BuildException if there is an error. */ - protected void executeForkV5() throws BuildException { + protected void executeForkV5() throws BuildException { try { log("mode : fork " + BorlandDeploymentTool.BES, Project.MSG_DEBUG); ExecTask execTask = new ExecTask(this); - execTask.setDir(new File(".")); - execTask.setExecutable("iastool"); if (debug) { execTask.createArg().setValue("-debug"); @@ -303,11 +293,8 @@ public class BorlandGenerateClient extends Task { execTask.execute(); } catch (Exception e) { // Have to catch this because of the semantics of calling main() - String msg = "Exception while calling generateclient Details: " - + e.toString(); - throw new BuildException(msg, e); + throw new BuildException("Exception while calling generateclient", e); } - } }
http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java index a987b92..4e75eef 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/DescriptorHandler.java @@ -24,6 +24,7 @@ import java.io.InputStream; import java.net.URL; import java.nio.file.Files; import java.util.Hashtable; +import java.util.Map; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; @@ -94,20 +95,20 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * put into the jar file, mapped to File objects Accessed by the SAX * parser call-back method characters(). */ - protected Hashtable ejbFiles = null; + protected Hashtable<String, File> ejbFiles = null; /** * Instance variable that stores the value found in the <ejb-name> element */ protected String ejbName = null; - private Hashtable fileDTDs = new Hashtable(); + private Map<String, File> fileDTDs = new Hashtable<>(); - private Hashtable resourceDTDs = new Hashtable(); + private Map<String, String> resourceDTDs = new Hashtable<>(); private boolean inEJBRef = false; - private Hashtable urlDTDs = new Hashtable(); + private Map<String, URL> urlDTDs = new Hashtable<>(); // CheckStyle:VisibilityModifier OFF - bc /** @@ -174,7 +175,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { /** * Resolve the entity. - * @see org.xml.sax.EntityResolver#resolveEntity(String, String). + * @see org.xml.sax.EntityResolver#resolveEntity(String, String) * @param publicId The public identifier, or <code>null</code> * if none is available. * @param systemId The system identifier provided in the XML @@ -182,11 +183,12 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * @return an inputsource for this identifier * @throws SAXException if there is a problem. */ + @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException { this.publicId = publicId; - File dtdFile = (File) fileDTDs.get(publicId); + File dtdFile = fileDTDs.get(publicId); if (dtdFile != null) { try { owningTask.log("Resolved " + publicId + " to local file " @@ -197,7 +199,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { } } - String dtdResourceName = (String) resourceDTDs.get(publicId); + String dtdResourceName = resourceDTDs.get(publicId); if (dtdResourceName != null) { InputStream is = this.getClass().getResourceAsStream(dtdResourceName); if (is != null) { @@ -207,7 +209,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { } } - URL dtdUrl = (URL) urlDTDs.get(publicId); + URL dtdUrl = urlDTDs.get(publicId); if (dtdUrl != null) { try { InputStream is = dtdUrl.openStream(); @@ -229,8 +231,8 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * Getter method that returns the set of files to include in the EJB jar. * @return the map of files */ - public Hashtable getFiles() { - return (ejbFiles == null) ? new Hashtable() : ejbFiles; + public Hashtable<String, File> getFiles() { + return ejbFiles == null ? new Hashtable<>() : ejbFiles; } /** @@ -254,13 +256,13 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * instance variables to ensure safe operation. * @throws SAXException on error */ + @Override public void startDocument() throws SAXException { - this.ejbFiles = new Hashtable(DEFAULT_HASH_TABLE_SIZE, 1); + this.ejbFiles = new Hashtable<>(DEFAULT_HASH_TABLE_SIZE, 1); this.currentElement = null; inEJBRef = false; } - /** * SAX parser call-back method that is invoked when a new element is entered * into. Used to store the context (attribute name) in the currentAttribute @@ -269,26 +271,26 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * @param attrs Attributes associated to the element. * @throws SAXException on error */ + @Override public void startElement(String name, AttributeList attrs) throws SAXException { this.currentElement = name; currentText = ""; - if (name.equals(EJB_REF) || name.equals(EJB_LOCAL_REF)) { + if (EJB_REF.equals(name) || EJB_LOCAL_REF.equals(name)) { inEJBRef = true; - } else if (parseState == STATE_LOOKING_EJBJAR && name.equals(EJB_JAR)) { + } else if (parseState == STATE_LOOKING_EJBJAR && EJB_JAR.equals(name)) { parseState = STATE_IN_EJBJAR; - } else if (parseState == STATE_IN_EJBJAR && name.equals(ENTERPRISE_BEANS)) { + } else if (parseState == STATE_IN_EJBJAR && ENTERPRISE_BEANS.equals(name)) { parseState = STATE_IN_BEANS; - } else if (parseState == STATE_IN_BEANS && name.equals(SESSION_BEAN)) { + } else if (parseState == STATE_IN_BEANS && SESSION_BEAN.equals(name)) { parseState = STATE_IN_SESSION; - } else if (parseState == STATE_IN_BEANS && name.equals(ENTITY_BEAN)) { + } else if (parseState == STATE_IN_BEANS && ENTITY_BEAN.equals(name)) { parseState = STATE_IN_ENTITY; - } else if (parseState == STATE_IN_BEANS && name.equals(MESSAGE_BEAN)) { + } else if (parseState == STATE_IN_BEANS && MESSAGE_BEAN.equals(name)) { parseState = STATE_IN_MESSAGE; } } - /** * SAX parser call-back method that is invoked when an element is exited. * Used to blank out (set to the empty string, not nullify) the name of @@ -299,6 +301,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * in this implementation. * @throws SAXException on error */ + @Override public void endElement(String name) throws SAXException { processElement(); currentText = ""; @@ -334,13 +337,12 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { * char array where the current data terminates. * @throws SAXException on error */ + @Override public void characters(char[] ch, int start, int length) throws SAXException { - currentText += new String(ch, start, length); } - /** * Called when an endelement is seen. * This may be overridden in derived classes. @@ -355,15 +357,14 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { return; } - if (currentElement.equals(HOME_INTERFACE) - || currentElement.equals(REMOTE_INTERFACE) - || currentElement.equals(LOCAL_INTERFACE) - || currentElement.equals(LOCAL_HOME_INTERFACE) - || currentElement.equals(BEAN_CLASS) - || currentElement.equals(PK_CLASS)) { + if (HOME_INTERFACE.equals(currentElement) + || REMOTE_INTERFACE.equals(currentElement) + || LOCAL_INTERFACE.equals(currentElement) + || LOCAL_HOME_INTERFACE.equals(currentElement) + || BEAN_CLASS.equals(currentElement) + || PK_CLASS.equals(currentElement)) { // Get the filename into a String object - File classFile = null; String className = currentText.trim(); // If it's a primitive wrapper then we shouldn't try and put @@ -374,8 +375,7 @@ public class DescriptorHandler extends org.xml.sax.HandlerBase { // name, create the File object and add it to the Hashtable. className = className.replace('.', File.separatorChar); className += ".class"; - classFile = new File(srcDir, className); - ejbFiles.put(className, classFile); + ejbFiles.put(className, new File(srcDir, className)); } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java index 6ed8e34..2a1d70d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EJBDeploymentTool.java @@ -18,14 +18,11 @@ package org.apache.tools.ant.taskdefs.optional.ejb; - - import javax.xml.parsers.SAXParser; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Task; - /** * The interface to implement for deployment tools. */ http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java index e9b7ed4..f582091 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/EjbJar.java @@ -21,7 +21,6 @@ package org.apache.tools.ant.taskdefs.optional.ejb; // Standard java imports import java.io.File; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.xml.parsers.ParserConfigurationException; @@ -103,12 +102,12 @@ public class EjbJar extends MatchingTask { /** * A Fileset of support classes */ - public List supportFileSets = new ArrayList(); + public List<FileSet> supportFileSets = new ArrayList<>(); /** * The list of configured DTD locations */ - public ArrayList dtdLocations = new ArrayList(); + public ArrayList<DTDLocation> dtdLocations = new ArrayList<>(); /** * The naming scheme used to determine the generated jar name @@ -162,8 +161,10 @@ public class EjbJar extends MatchingTask { * * @return an array of the values of this attribute class. */ + @Override public String[] getValues() { - return new String[] {EJB_NAME, DIRECTORY, DESCRIPTOR, BASEJARNAME}; + return new String[] { EJB_NAME, DIRECTORY, DESCRIPTOR, + BASEJARNAME }; } } @@ -178,20 +179,21 @@ public class EjbJar extends MatchingTask { /** 2.0 value */ public static final String CMP2_0 = "2.0"; /** {@inheritDoc}. */ + @Override public String[] getValues() { - return new String[]{ + return new String[] { CMP1_0, CMP2_0, }; } } + /** * The config which is built by this task and used by the various deployment * tools to access the configuration of the ejbjar task */ private Config config = new Config(); - /** * Stores a handle to the directory to put the Jar files in. This is * only used by the generic deployment descriptor tool which is created @@ -207,7 +209,7 @@ public class EjbJar extends MatchingTask { private String cmpVersion = CMPVersion.CMP1_0; /** The list of deployment tools we are going to run. */ - private ArrayList deploymentTools = new ArrayList(); + private List<EJBDeploymentTool> deploymentTools = new ArrayList<>(); /** * Add a deployment tool to the list of deployment tools that will be @@ -348,7 +350,6 @@ public class EjbJar extends MatchingTask { return supportFileSet; } - /** * Set the Manifest file to use when jarring. As of EJB 1.1, manifest * files are no longer used to configure the EJB. However, they still @@ -409,10 +410,10 @@ public class EjbJar extends MatchingTask { if (config.namingScheme == null) { config.namingScheme = new NamingScheme(); config.namingScheme.setValue(NamingScheme.BASEJARNAME); - } else if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME)) { - throw new BuildException("The basejarname attribute is not " - + "compatible with the " - + config.namingScheme.getValue() + " naming scheme"); + } else if (!NamingScheme.BASEJARNAME.equals(config.namingScheme.getValue())) { + throw new BuildException( + "The basejarname attribute is not compatible with the %s naming scheme", + config.namingScheme.getValue()); } } @@ -424,11 +425,11 @@ public class EjbJar extends MatchingTask { */ public void setNaming(NamingScheme namingScheme) { config.namingScheme = namingScheme; - if (!config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) + if (!NamingScheme.BASEJARNAME.equals(config.namingScheme.getValue()) && config.baseJarName != null) { - throw new BuildException("The basejarname attribute is not " - + "compatible with the " - + config.namingScheme.getValue() + " naming scheme"); + throw new BuildException( + "The basejarname attribute is not compatible with the %s naming scheme", + config.namingScheme.getValue()); } } @@ -546,10 +547,10 @@ public class EjbJar extends MatchingTask { if (config.namingScheme == null) { config.namingScheme = new NamingScheme(); config.namingScheme.setValue(NamingScheme.DESCRIPTOR); - } else if (config.namingScheme.getValue().equals(NamingScheme.BASEJARNAME) + } else if (NamingScheme.BASEJARNAME.equals(config.namingScheme.getValue()) && config.baseJarName == null) { - throw new BuildException("The basejarname attribute must " - + "be specified with the basejarname naming scheme"); + throw new BuildException( + "The basejarname attribute must be specified with the basejarname naming scheme"); } } @@ -568,10 +569,11 @@ public class EjbJar extends MatchingTask { * encountered that cannot be recovered from, to signal to ant * that a major problem occurred within this task. */ + @Override public void execute() throws BuildException { validateConfig(); - if (deploymentTools.size() == 0) { + if (deploymentTools.isEmpty()) { GenericDeploymentTool genericTool = new GenericDeploymentTool(); genericTool.setTask(this); genericTool.setDestdir(destDir); @@ -579,8 +581,7 @@ public class EjbJar extends MatchingTask { deploymentTools.add(genericTool); } - for (Iterator i = deploymentTools.iterator(); i.hasNext();) { - EJBDeploymentTool tool = (EJBDeploymentTool) i.next(); + for (EJBDeploymentTool tool : deploymentTools) { tool.configure(config); tool.validateConfigured(); } @@ -591,7 +592,6 @@ public class EjbJar extends MatchingTask { saxParserFactory.setValidating(true); SAXParser saxParser = saxParserFactory.newSAXParser(); - DirectoryScanner ds = getDirectoryScanner(config.descriptorDir); ds.scan(); String[] files = ds.getIncludedFiles(); @@ -601,30 +601,18 @@ public class EjbJar extends MatchingTask { // Loop through the files. Each file represents one deployment // descriptor, and hence one bean in our model. - for (int index = 0; index < files.length; ++index) { + for (String file : files) { // process the deployment descriptor in each tool - for (Iterator i = deploymentTools.iterator(); i.hasNext();) { - EJBDeploymentTool tool = (EJBDeploymentTool) i.next(); - tool.processDescriptor(files[index], saxParser); + for (EJBDeploymentTool tool : deploymentTools) { + tool.processDescriptor(file, saxParser); } } } catch (SAXException se) { - String msg = "SAXException while creating parser." - + " Details: " - + se.getMessage(); - throw new BuildException(msg, se); + throw new BuildException("SAXException while creating parser.", se); } catch (ParserConfigurationException pce) { - String msg = "ParserConfigurationException while creating parser. " - + "Details: " + pce.getMessage(); - throw new BuildException(msg, pce); + throw new BuildException( + "ParserConfigurationException while creating parser. ", pce); } } // end of execute() } - - - - - - - http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java index 7de0ba3..16bde5d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/GenericDeploymentTool.java @@ -24,7 +24,6 @@ import java.nio.file.Files; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; -import java.util.Iterator; import java.util.Set; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; @@ -37,9 +36,9 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Location; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Path; -import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.depend.DependencyAnalyzer; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -118,7 +117,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { /** * Set of files have been loaded into the EJB jar */ - private Set addedfiles; + private Set<String> addedfiles; /** * Handler used to parse the EJB XML descriptor @@ -130,11 +129,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { */ private DependencyAnalyzer dependencyAnalyzer; - /** No arg constructor */ - public GenericDeploymentTool() { - } - - /** * Set the destination directory; required. * @param inDir the destination directory. @@ -152,12 +146,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool { return destDir; } - /** * Set the task which owns this tool * * @param task the Task to which this deployment tool is associated. */ + @Override public void setTask(Task task) { this.task = task; } @@ -234,7 +228,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { combinedPath.append(config.classpath); } } - return combinedPath; } @@ -277,9 +270,10 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } try { - Class analyzerClass = Class.forName(analyzerClassName); - dependencyAnalyzer - = (DependencyAnalyzer) analyzerClass.newInstance(); + Class<? extends DependencyAnalyzer> analyzerClass = + Class.forName(analyzerClassName) + .asSubclass(DependencyAnalyzer.class); + dependencyAnalyzer = analyzerClass.newInstance(); dependencyAnalyzer.addClassPath(new Path(task.getProject(), config.srcDir.getPath())); dependencyAnalyzer.addClassPath(config.classpath); @@ -296,12 +290,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } } - /** * Configure this tool for use in the ejbjar task. * * @param config the configuration from the surrounding ejbjar task. */ + @Override public void configure(EjbJar.Config config) { this.config = config; @@ -326,12 +320,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool { File inputFile, String logicalFilename) throws BuildException { - InputStream iStream = null; - try { - if (!addedfiles.contains(logicalFilename)) { - iStream = Files.newInputStream(inputFile.toPath()); + if (!addedfiles.contains(logicalFilename)) { + try (InputStream iStream = Files.newInputStream(inputFile.toPath())) { // Create the zip entry and add it to the jar file - ZipEntry zipEntry = new ZipEntry(logicalFilename.replace('\\', '/')); + ZipEntry zipEntry = + new ZipEntry(logicalFilename.replace('\\', '/')); jStream.putNextEntry(zipEntry); // Create the file input stream, and buffer everything over @@ -345,15 +338,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool { //add it to list of files in jar addedfiles.add(logicalFilename); - } - } catch (IOException ioe) { - log("WARNING: IOException while adding entry " - + logicalFilename + " to jarfile from " - + inputFile.getPath() + " " + ioe.getClass().getName() - + "-" + ioe.getMessage(), Project.MSG_WARN); - } finally { - // Close up the file input stream for the class file - FileUtils.close(iStream); + } catch (IOException ioe) { + log("WARNING: IOException while adding entry " + logicalFilename + + " to jarfile from " + inputFile.getPath() + " " + + ioe.getClass().getName() + "-" + ioe.getMessage(), + Project.MSG_WARN); + } } } @@ -368,8 +358,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { registerKnownDTDs(h); // register any DTDs supplied by the user - for (Iterator i = getConfig().dtdLocations.iterator(); i.hasNext();) { - EjbJar.DTDLocation dtdLocation = (EjbJar.DTDLocation) i.next(); + for (DTDLocation dtdLocation : getConfig().dtdLocations) { h.registerDTD(dtdLocation.getPublicId(), dtdLocation.getLocation()); } return h; @@ -387,6 +376,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } /** {@inheritDoc}. */ + @Override public void processDescriptor(String descriptorFileName, SAXParser saxParser) { checkConfiguration(descriptorFileName, saxParser); @@ -395,7 +385,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { handler = getDescriptorHandler(config.srcDir); // Retrive the files to be added to JAR from EJB descriptor - Hashtable ejbFiles = parseEjbFiles(descriptorFileName, saxParser); + Hashtable<String, File> ejbFiles = parseEjbFiles(descriptorFileName, saxParser); // Add any support classes specified in the build file addSupportClasses(ejbFiles); @@ -410,8 +400,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { ejbFiles.put(MANIFEST, manifestFile); } - - // First the regular deployment descriptor ejbFiles.put(META_DIR + EJB_DD, new File(config.descriptorDir, descriptorFileName)); @@ -436,7 +424,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { File jarFile = getVendorOutputJarFile(baseName); - // Check to see if we need a build and start doing the work! if (needToRebuild(ejbFiles, jarFile)) { // Log that we are going to build... @@ -450,27 +437,23 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // Use helper method to write the jarfile String publicId = getPublicId(); writeJar(baseName, jarFile, ejbFiles, publicId); - } else { // Log that the file is up to date... log(jarFile.toString() + " is up to date.", Project.MSG_VERBOSE); } - } catch (SAXException se) { - String msg = "SAXException while parsing '" - + descriptorFileName - + "'. This probably indicates badly-formed XML." - + " Details: " - + se.getMessage(); - throw new BuildException(msg, se); + throw new BuildException( + "SAXException while parsing '" + descriptorFileName + + "'. This probably indicates badly-formed XML." + + " Details: " + se.getMessage(), + se); } catch (IOException ioe) { - String msg = "IOException while parsing'" - + descriptorFileName - + "'. This probably indicates that the descriptor" - + " doesn't exist. Details: " - + ioe.getMessage(); - throw new BuildException(msg, ioe); + throw new BuildException( + "IOException while parsing'" + descriptorFileName + + "'. This probably indicates that the descriptor" + + " doesn't exist. Details: " + ioe.getMessage(), + ioe); } } @@ -488,7 +471,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { */ protected void checkConfiguration(String descriptorFileName, SAXParser saxParser) throws BuildException { - /* * For the GenericDeploymentTool, do nothing. Vendor specific * subclasses should throw a BuildException if the configuration is @@ -511,28 +493,17 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @throws IOException An IOException from the parser, possibly from a * the byte stream or character stream */ - protected Hashtable parseEjbFiles(String descriptorFileName, SAXParser saxParser) + protected Hashtable<String, File> parseEjbFiles(String descriptorFileName, SAXParser saxParser) throws IOException, SAXException { - InputStream descriptorStream = null; - Hashtable ejbFiles = null; - - try { - - /* Parse the ejb deployment descriptor. While it may not - * look like much, we use a SAXParser and an inner class to - * get hold of all the classfile names for the descriptor. - */ - descriptorStream - = Files.newInputStream(new File(config.descriptorDir, descriptorFileName).toPath()); + /* Parse the ejb deployment descriptor. While it may not + * look like much, we use a SAXParser and an inner class to + * get hold of all the classfile names for the descriptor. + */ + try (InputStream descriptorStream = Files.newInputStream( + new File(config.descriptorDir, descriptorFileName).toPath())) { saxParser.parse(new InputSource(descriptorStream), handler); - - ejbFiles = handler.getFiles(); - - } finally { - FileUtils.close(descriptorStream); + return handler.getFiles(); } - - return ejbFiles; } /** @@ -542,22 +513,18 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @param ejbFiles Hashtable of EJB classes (and other) files that will be * added to the completed JAR file */ - protected void addSupportClasses(Hashtable ejbFiles) { + protected void addSupportClasses(Hashtable<String, File> ejbFiles) { // add in support classes if any Project project = task.getProject(); - for (Iterator i = config.supportFileSets.iterator(); i.hasNext();) { - FileSet supportFileSet = (FileSet) i.next(); + for (FileSet supportFileSet : config.supportFileSets) { File supportBaseDir = supportFileSet.getDir(project); DirectoryScanner supportScanner = supportFileSet.getDirectoryScanner(project); - supportScanner.scan(); - String[] supportFiles = supportScanner.getIncludedFiles(); - for (int j = 0; j < supportFiles.length; ++j) { - ejbFiles.put(supportFiles[j], new File(supportBaseDir, supportFiles[j])); + for (String supportFile : supportScanner.getIncludedFiles()) { + ejbFiles.put(supportFile, new File(supportBaseDir, supportFile)); } } } - /** * Using the EJB descriptor file name passed from the <code>ejbjar</code> * task, this method returns the "basename" which will be used to name the @@ -573,14 +540,14 @@ public class GenericDeploymentTool implements EJBDeploymentTool { String baseName = ""; // Work out what the base name is - if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME)) { + if (EjbJar.NamingScheme.BASEJARNAME.equals(config.namingScheme.getValue())) { String canonicalDescriptor = descriptorFileName.replace('\\', '/'); int index = canonicalDescriptor.lastIndexOf('/'); if (index != -1) { baseName = descriptorFileName.substring(0, index + 1); } baseName += config.baseJarName; - } else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) { + } else if (EjbJar.NamingScheme.DESCRIPTOR.equals(config.namingScheme.getValue())) { int lastSeparatorIndex = descriptorFileName.lastIndexOf(File.separator); int endBaseName = -1; if (lastSeparatorIndex != -1) { @@ -593,10 +560,11 @@ public class GenericDeploymentTool implements EJBDeploymentTool { if (endBaseName != -1) { baseName = descriptorFileName.substring(0, endBaseName); } else { - throw new BuildException("Unable to determine jar name " - + "from descriptor \"" + descriptorFileName + "\""); + throw new BuildException( + "Unable to determine jar name from descriptor \"%s\"", + descriptorFileName); } - } else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) { + } else if (EjbJar.NamingScheme.DIRECTORY.equals(config.namingScheme.getValue())) { File descriptorFile = new File(config.descriptorDir, descriptorFileName); String path = descriptorFile.getAbsolutePath(); int lastSeparatorIndex @@ -609,9 +577,8 @@ public class GenericDeploymentTool implements EJBDeploymentTool { if (dirSeparatorIndex != -1) { dirName = dirName.substring(dirSeparatorIndex + 1); } - baseName = dirName; - } else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME)) { + } else if (EjbJar.NamingScheme.EJB_NAME.equals(config.namingScheme.getValue())) { baseName = handler.getEjbName(); } return baseName; @@ -651,11 +618,10 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @param ejbFiles a hashtable entryname -> file. * @param ddPrefix a prefix to use. */ - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { // nothing to add for generic tool. } - /** * 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. @@ -680,16 +646,13 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @return boolean indicating whether or not the <code>jarFile</code> * is up to date */ - protected boolean needToRebuild(Hashtable ejbFiles, File jarFile) { + protected boolean needToRebuild(Hashtable<String, File> ejbFiles, File jarFile) { if (jarFile.exists()) { long lastBuild = jarFile.lastModified(); - Iterator fileIter = ejbFiles.values().iterator(); - // Loop through the files seeing if any has been touched // more recently than the destination jar. - while (fileIter.hasNext()) { - File currentFile = (File) fileIter.next(); + for (File currentFile : ejbFiles.values()) { if (lastBuild < currentFile.lastModified()) { log("Build needed because " + currentFile.getPath() + " is out of date", Project.MSG_VERBOSE); @@ -698,7 +661,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } return false; } - return true; } @@ -730,7 +692,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { if (manifestFile.exists()) { return manifestFile; } - if (config.manifest != null) { return config.manifest; } @@ -747,17 +708,15 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @param publicId the id to use. * @throws BuildException if there is a problem. */ - protected void writeJar(String baseName, File jarfile, Hashtable files, + protected void writeJar(String baseName, File jarfile, Hashtable<String, File> files, String publicId) throws BuildException { - - JarOutputStream jarStream = null; + // clean the addedfiles set + if (addedfiles == null) { + addedfiles = new HashSet<>(); + } else { + addedfiles.clear(); + } try { - // clean the addedfiles set - if (addedfiles == null) { - addedfiles = new HashSet(); - } else { - addedfiles.clear(); - } /* If the jarfile already exists then whack it and recreate it. * Should probably think of a more elegant way to handle this @@ -773,18 +732,18 @@ public class GenericDeploymentTool implements EJBDeploymentTool { InputStream in = null; Manifest manifest = null; try { - File manifestFile = (File) files.get(MANIFEST); + File manifestFile = files.get(MANIFEST); if (manifestFile != null && manifestFile.exists()) { in = Files.newInputStream(manifestFile.toPath()); } else { String defaultManifest = "/org/apache/tools/ant/defaultManifest.mf"; in = this.getClass().getResourceAsStream(defaultManifest); if (in == null) { - throw new BuildException("Could not find " - + "default manifest: " + defaultManifest); + throw new BuildException( + "Could not find default manifest: %s", + defaultManifest); } } - manifest = new Manifest(in); } catch (IOException e) { throw new BuildException ("Unable to read manifest", e, getLocation()); @@ -796,46 +755,43 @@ public class GenericDeploymentTool implements EJBDeploymentTool { // Create the streams necessary to write the jarfile - jarStream = new JarOutputStream(Files.newOutputStream(jarfile.toPath()), manifest); - jarStream.setMethod(JarOutputStream.DEFLATED); + try (JarOutputStream jarStream = new JarOutputStream( + Files.newOutputStream(jarfile.toPath()), manifest)) { + jarStream.setMethod(JarOutputStream.DEFLATED); - // Loop through all the class files found and add them to the jar - for (Iterator entryIterator = files.keySet().iterator(); entryIterator.hasNext();) { - String entryName = (String) entryIterator.next(); - if (entryName.equals(MANIFEST)) { - continue; - } - - File entryFile = (File) files.get(entryName); - - log("adding file '" + entryName + "'", - Project.MSG_VERBOSE); - - addFileToJar(jarStream, entryFile, entryName); - - // See if there are any inner classes for this class and add them in if there are - InnerClassFilenameFilter flt = new InnerClassFilenameFilter(entryFile.getName()); - File entryDir = entryFile.getParentFile(); - String[] innerfiles = entryDir.list(flt); - if (innerfiles != null) { - for (int i = 0, n = innerfiles.length; i < n; i++) { - - //get and clean up innerclass name - int entryIndex = entryName.lastIndexOf(entryFile.getName()) - 1; - if (entryIndex < 0) { - entryName = innerfiles[i]; - } else { - entryName = entryName.substring(0, entryIndex) - + File.separatorChar + innerfiles[i]; - } - // link the file - entryFile = new File(config.srcDir, entryName); - - log("adding innerclass file '" + entryName + "'", + // Loop through all the class files found and add them to the jar + for (String entryName : files.keySet()) { + if (entryName.equals(MANIFEST)) { + continue; + } + File entryFile = files.get(entryName); + log("adding file '" + entryName + "'", Project.MSG_VERBOSE); + addFileToJar(jarStream, entryFile, entryName); + + // See if there are any inner classes for this class and add them in if there are + InnerClassFilenameFilter flt = + new InnerClassFilenameFilter(entryFile.getName()); + File entryDir = entryFile.getParentFile(); + String[] innerfiles = entryDir.list(flt); + if (innerfiles != null) { + for (String innerfile : innerfiles) { + //get and clean up innerclass name + int entryIndex = + entryName.lastIndexOf(entryFile.getName()) - 1; + if (entryIndex < 0) { + entryName = innerfile; + } else { + entryName = entryName.substring(0, entryIndex) + + File.separatorChar + innerfile; + } + // link the file + entryFile = new File(config.srcDir, entryName); + + log("adding innerclass file '" + entryName + "'", Project.MSG_VERBOSE); - addFileToJar(jarStream, entryFile, entryName); - + addFileToJar(jarStream, entryFile, entryName); + } } } } @@ -845,8 +801,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { + "'. Details: " + ioe.getMessage(); throw new BuildException(msg, ioe); - } finally { - FileUtils.close(jarStream); } } // end of writeJar @@ -856,7 +810,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @param checkEntries files, that are extracted from the deployment descriptor * @throws BuildException if there is a problem. */ - protected void checkAndAddDependants(Hashtable checkEntries) + protected void checkAndAddDependants(Hashtable<String, File> checkEntries) throws BuildException { if (dependencyAnalyzer == null) { @@ -865,9 +819,7 @@ public class GenericDeploymentTool implements EJBDeploymentTool { dependencyAnalyzer.reset(); - Iterator i = checkEntries.keySet().iterator(); - while (i.hasNext()) { - String entryName = (String) i.next(); + for (String entryName : checkEntries.keySet()) { if (entryName.endsWith(".class")) { String className = entryName.substring(0, entryName.length() - ".class".length()); @@ -878,10 +830,10 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } } - Enumeration e = dependencyAnalyzer.getClassDependencies(); + Enumeration<String> e = dependencyAnalyzer.getClassDependencies(); while (e.hasMoreElements()) { - String classname = (String) e.nextElement(); + String classname = e.nextElement(); String location = classname.replace('.', File.separatorChar) + ".class"; File classFile = new File(config.srcDir, location); @@ -893,7 +845,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { } } - /** * Returns a Classloader object which parses the passed in generic EjbJar classpath. * The loader is used to dynamically load classes from javax.ejb.* and the classes @@ -904,7 +855,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { if (classpathLoader != null) { return classpathLoader; } - Path combinedClasspath = getCombinedClasspath(); // only generate a new ClassLoader if we have a classpath @@ -915,7 +865,6 @@ public class GenericDeploymentTool implements EJBDeploymentTool { classpathLoader = getTask().getProject().createClassLoader(combinedClasspath); } - return classpathLoader; } @@ -925,11 +874,12 @@ public class GenericDeploymentTool implements EJBDeploymentTool { * @throws BuildException If the Deployment Tool's configuration isn't * valid */ + @Override public void validateConfigured() throws BuildException { if ((destDir == null) || (!destDir.isDirectory())) { - String msg = "A valid destination directory must be specified " - + "using the \"destdir\" attribute."; - throw new BuildException(msg, getLocation()); + throw new BuildException( + "A valid destination directory must be specified using the \"destdir\" attribute.", + getLocation()); } } } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java index cbc8526..181720f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetDeploymentTool.java @@ -21,12 +21,12 @@ package org.apache.tools.ant.taskdefs.optional.ejb; import java.io.File; import java.io.IOException; import java.util.Hashtable; -import java.util.Iterator; import javax.xml.parsers.SAXParser; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.optional.ejb.EjbJar.DTDLocation; import org.xml.sax.SAXException; /** @@ -107,7 +107,7 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { * we may determine the name of the EJB JAR file using this display-name, * but this has not be implemented yet. */ - private String displayName; + private String displayName; /* * Regardless of the name of the iAS-specific EJB descriptor file, it will @@ -202,25 +202,26 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { int startOfName = descriptorFileName.lastIndexOf(File.separatorChar) + 1; String stdXml = descriptorFileName.substring(startOfName); if (stdXml.equals(EJB_DD) && (getConfig().baseJarName == null)) { - String msg = "No name specified for the completed JAR file. The EJB" - + " descriptor should be prepended with the JAR " - + "name or it should be specified using the " - + "attribute \"basejarname\" in the \"ejbjar\" task."; - throw new BuildException(msg, getLocation()); + throw new BuildException( + "No name specified for the completed JAR file. The EJB" + + " descriptor should be prepended with the JAR " + + "name or it should be specified using the " + + "attribute \"basejarname\" in the \"ejbjar\" task.", + getLocation()); } File iasDescriptor = new File(getConfig().descriptorDir, getIasDescriptorName()); if ((!iasDescriptor.exists()) || (!iasDescriptor.isFile())) { - String msg = "The iAS-specific EJB descriptor (" - + iasDescriptor + ") was not found."; - throw new BuildException(msg, getLocation()); + throw new BuildException("The iAS-specific EJB descriptor (" + + iasDescriptor + ") was not found.", getLocation()); } if ((iashome != null) && (!iashome.isDirectory())) { - String msg = "If \"iashome\" is specified, it must be a valid " - + "directory (it was set to " + iashome + ")."; - throw new BuildException(msg, getLocation()); + throw new BuildException( + "If \"iashome\" is specified, it must be a valid directory (it was set to " + + iashome + ").", + getLocation()); } } @@ -240,10 +241,10 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { * exception */ @Override - protected Hashtable parseEjbFiles(String descriptorFileName, + protected Hashtable<String, File> parseEjbFiles(String descriptorFileName, SAXParser saxParser) throws IOException, SAXException { - Hashtable files; + Hashtable<String, File> files; /* Build and populate an instance of the ejbc utility */ IPlanetEjbc ejbc = new IPlanetEjbc( @@ -260,12 +261,9 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { ejbc.setIasHomeDir(iashome); } if (getConfig().dtdLocations != null) { - for (Iterator i = getConfig().dtdLocations.iterator(); - i.hasNext();) { - EjbJar.DTDLocation dtdLocation = - (EjbJar.DTDLocation) i.next(); + for (DTDLocation dtdLocation : getConfig().dtdLocations) { ejbc.registerDTD(dtdLocation.getPublicId(), - dtdLocation.getLocation()); + dtdLocation.getLocation()); } } @@ -292,7 +290,7 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { int endOfCmp = cmpDescriptors[i].lastIndexOf('/'); String cmpDescriptor = cmpDescriptors[i].substring(endOfCmp + 1); - File cmpFile = new File(baseDir, relativePath + cmpDescriptor); + File cmpFile = new File(baseDir, relativePath + cmpDescriptor); if (!cmpFile.exists()) { throw new BuildException("The CMP descriptor file (" + cmpFile + ") could not be found.", getLocation()); @@ -300,7 +298,6 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { files.put(cmpDescriptors[i], cmpFile); } } - return files; } @@ -313,7 +310,7 @@ public class IPlanetDeploymentTool extends GenericDeploymentTool { * @param ddPrefix not used */ @Override - protected void addVendorFiles(Hashtable ejbFiles, String ddPrefix) { + protected void addVendorFiles(Hashtable<String, File> ejbFiles, String ddPrefix) { ejbFiles.put(META_DIR + IAS_DD, new File(getConfig().descriptorDir, getIasDescriptorName())); } http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java index 5a6656f..c15a07a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbc.java @@ -23,10 +23,12 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.time.Instant; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.Date; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; @@ -34,6 +36,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; +import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -42,8 +46,6 @@ import org.xml.sax.AttributeList; import org.xml.sax.HandlerBase; import org.xml.sax.InputSource; import org.xml.sax.SAXException; - -import org.apache.tools.ant.util.FileUtils; import org.apache.tools.ant.util.StringUtils; /** @@ -114,7 +116,7 @@ public class IPlanetEjbc { * (relative to the destination directory). The value for the Hashtable is * a File object which reference the actual class file. */ - private Hashtable ejbFiles = new Hashtable(); + private Hashtable<String, File> ejbFiles = new Hashtable<>(); /* Value of the display-name element read from the standard EJB descriptor */ private String displayName; @@ -150,15 +152,11 @@ public class IPlanetEjbc { * Parse the classpath into it's individual elements and store the * results in the "classpathElements" instance variable. */ - List elements = new ArrayList(); if (classpath != null) { StringTokenizer st = new StringTokenizer(classpath, File.pathSeparator); - while (st.hasMoreTokens()) { - elements.add(st.nextToken()); - } - classpathElements - = (String[]) elements.toArray(new String[elements.size()]); + final int count = st.countTokens(); + classpathElements = Collections.list(st).toArray(new String[count]); } } @@ -217,7 +215,7 @@ public class IPlanetEjbc { * * @return The list of EJB files processed by the ejbc utility. */ - public Hashtable getEjbFiles() { + public Hashtable<String, File> getEjbFiles() { return ejbFiles; } @@ -236,16 +234,8 @@ public class IPlanetEjbc { * @return An array of CMP descriptors. */ public String[] getCmpDescriptors() { - List returnList = new ArrayList(); - - EjbInfo[] ejbs = handler.getEjbs(); - - for (int i = 0; i < ejbs.length; i++) { - List descriptors = (List) ejbs[i].getCmpDescriptors(); - returnList.addAll(descriptors); - } - - return (String[]) returnList.toArray(new String[returnList.size()]); + return Stream.of(handler.getEjbs()).map(EjbInfo::getCmpDescriptors) + .flatMap(Collection::stream).toArray(String[]::new); } /** @@ -274,13 +264,13 @@ public class IPlanetEjbc { iasDescriptor = new File(args[args.length - 1]); for (int i = 0; i < args.length - 2; i++) { - if (args[i].equals("-classpath")) { + if ("-classpath".equals(args[i])) { classpath = args[++i]; - } else if (args[i].equals("-d")) { + } else if ("-d".equals(args[i])) { destDirectory = new File(args[++i]); - } else if (args[i].equals("-debug")) { + } else if ("-debug".equals(args[i])) { debug = true; - } else if (args[i].equals("-keepsource")) { + } else if ("-keepsource".equals(args[i])) { retainSource = true; } else { usage(); @@ -383,22 +373,17 @@ public class IPlanetEjbc { EjbInfo[] ejbs = getEjbs(); // Returns list of EJBs for processing - for (int i = 0; i < ejbs.length; i++) { + for (EjbInfo ejb : ejbs) { log("EJBInfo..."); - log(ejbs[i].toString()); + log(ejb.toString()); } - for (int i = 0; i < ejbs.length; i++) { - EjbInfo ejb = ejbs[i]; - + for (EjbInfo ejb : ejbs) { ejb.checkConfiguration(destDirectory); // Throws EjbcException if (ejb.mustBeRecompiled(destDirectory)) { log(ejb.getName() + " must be recompiled using ejbc."); - - String[] arguments = buildArgumentList(ejb); - callEjbc(arguments); - + callEjbc(buildArgumentList(ejb)); } else { log(ejb.getName() + " is up to date."); } @@ -412,11 +397,6 @@ public class IPlanetEjbc { */ private void callEjbc(String[] arguments) { - /* Concatenate all of the command line arguments into a single String */ - StringBuffer args = new StringBuffer(); - for (int i = 0; i < arguments.length; i++) { - args.append(arguments[i]).append(" "); - } /* If an iAS home directory is specified, prepend it to the commmand */ String command; @@ -428,6 +408,9 @@ public class IPlanetEjbc { } command += "ejbc "; + /* Concatenate all of the command line arguments into a single String */ + String args = Stream.of(arguments).collect(Collectors.joining(" ")); + log(command + args); /* @@ -498,18 +481,14 @@ public class IPlanetEjbc { * XML descriptor (it may wrap another exception) */ private EjbInfo[] getEjbs() throws IOException, SAXException { - EjbInfo[] ejbs = null; /* * The EJB information is gathered from the standard XML EJB descriptor * and the iAS-specific XML EJB descriptor using a SAX parser. */ - parser.parse(stdDescriptor, handler); parser.parse(iasDescriptor, handler); - ejbs = handler.getEjbs(); - - return ejbs; + return handler.getEjbs(); } /** @@ -522,7 +501,7 @@ public class IPlanetEjbc { */ private String[] buildArgumentList(EjbInfo ejb) { - List arguments = new ArrayList(); + List<String> arguments = new ArrayList<>(); /* OPTIONAL COMMAND LINE PARAMETERS */ @@ -566,7 +545,7 @@ public class IPlanetEjbc { arguments.add(ejb.getImplementation().getQualifiedClassName()); /* Convert the List into an Array and return it */ - return (String[]) arguments.toArray(new String[arguments.size()]); + return arguments.toArray(new String[arguments.size()]); } /** @@ -591,6 +570,7 @@ public class IPlanetEjbc { * */ public class EjbcException extends Exception { + private static final long serialVersionUID = 1L; /** * Constructs an exception with the given descriptive message. @@ -631,10 +611,10 @@ public class IPlanetEjbc { * remote copies of these DTDs cannot be accessed. The key for the Map * is the DTDs public ID and the value is the local location for the DTD */ - private Map resourceDtds = new HashMap(); - private Map fileDtds = new HashMap(); + private Map<String, String> resourceDtds = new HashMap<>(); + private Map<String, String> fileDtds = new HashMap<>(); - private Map ejbs = new HashMap(); // List of EJBs found in XML + private Map<String, EjbInfo> ejbs = new HashMap<>(); // List of EJBs found in XML private EjbInfo currentEjb; // One item within the Map private boolean iasDescriptor = false; // Is doc iAS or EJB descriptor @@ -660,7 +640,7 @@ public class IPlanetEjbc { * parsing. */ public EjbInfo[] getEjbs() { - return (EjbInfo[]) ejbs.values().toArray(new EjbInfo[ejbs.size()]); + return ejbs.values().toArray(new EjbInfo[ejbs.size()]); } /** @@ -713,35 +693,30 @@ public class IPlanetEjbc { * @param publicId The DTD's public identifier. * @param systemId The location of the DTD, as found in the XML document. */ + @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException { InputStream inputStream = null; - try { - /* Search the resource Map and (if not found) file Map */ - - String location = (String) resourceDtds.get(publicId); + String location = resourceDtds.get(publicId); if (location != null) { inputStream = ClassLoader.getSystemResource(location).openStream(); } else { - location = (String) fileDtds.get(publicId); + location = fileDtds.get(publicId); if (location != null) { // closed when the InputSource is closed inputStream = Files.newInputStream(Paths.get(location)); //NOSONAR } } } catch (IOException e) { - return super.resolveEntity(publicId, systemId); } - if (inputStream == null) { return super.resolveEntity(publicId, systemId); - } else { - return new InputSource(inputStream); } + return new InputSource(inputStream); } /** @@ -752,6 +727,7 @@ public class IPlanetEjbc { * (if any). * @throws SAXException If the parser cannot process the document. */ + @Override public void startElement(String name, AttributeList atts) throws SAXException { @@ -764,13 +740,13 @@ public class IPlanetEjbc { /* A new element has started, so reset the text being captured */ currentText = ""; - if (currentLoc.equals("\\ejb-jar")) { + if ("\\ejb-jar".equals(currentLoc)) { iasDescriptor = false; - } else if (currentLoc.equals("\\ias-ejb-jar")) { + } else if ("\\ias-ejb-jar".equals(currentLoc)) { iasDescriptor = true; } - if ((name.equals("session")) || (name.equals("entity"))) { + if (("session".equals(name)) || ("entity".equals(name))) { ejbType = name; } } @@ -784,9 +760,9 @@ public class IPlanetEjbc { * @param len The number of characters found in the document. * @throws SAXException If the parser cannot process the document. */ + @Override public void characters(char[] ch, int start, int len) throws SAXException { - currentText += new String(ch).substring(start, start + len); } @@ -796,6 +772,7 @@ public class IPlanetEjbc { * @param name String name of the element. * @throws SAXException If the parser cannot process the document. */ + @Override public void endElement(String name) throws SAXException { /* @@ -831,30 +808,30 @@ public class IPlanetEjbc { */ private void stdCharacters(String value) { - if (currentLoc.equals("\\ejb-jar\\display-name")) { + if ("\\ejb-jar\\display-name".equals(currentLoc)) { displayName = value; return; } String base = "\\ejb-jar\\enterprise-beans\\" + ejbType; - if (currentLoc.equals(base + "\\ejb-name")) { - currentEjb = (EjbInfo) ejbs.get(value); + if ((base + "\\ejb-name").equals(currentLoc)) { + currentEjb = ejbs.get(value); if (currentEjb == null) { currentEjb = new EjbInfo(value); ejbs.put(value, currentEjb); } - } else if (currentLoc.equals(base + "\\home")) { + } else if ((base + "\\home").equals(currentLoc)) { currentEjb.setHome(value); - } else if (currentLoc.equals(base + "\\remote")) { + } else if ((base + "\\remote").equals(currentLoc)) { currentEjb.setRemote(value); - } else if (currentLoc.equals(base + "\\ejb-class")) { + } else if ((base + "\\ejb-class").equals(currentLoc)) { currentEjb.setImplementation(value); - } else if (currentLoc.equals(base + "\\prim-key-class")) { + } else if ((base + "\\prim-key-class").equals(currentLoc)) { currentEjb.setPrimaryKey(value); - } else if (currentLoc.equals(base + "\\session-type")) { + } else if ((base + "\\session-type").equals(currentLoc)) { currentEjb.setBeantype(value); - } else if (currentLoc.equals(base + "\\persistence-type")) { + } else if ((base + "\\persistence-type").equals(currentLoc)) { currentEjb.setCmp(value); } } @@ -872,18 +849,19 @@ public class IPlanetEjbc { private void iasCharacters(String value) { String base = "\\ias-ejb-jar\\enterprise-beans\\" + ejbType; - if (currentLoc.equals(base + "\\ejb-name")) { - currentEjb = (EjbInfo) ejbs.get(value); + if ((base + "\\ejb-name").equals(currentLoc)) { + currentEjb = ejbs.get(value); if (currentEjb == null) { currentEjb = new EjbInfo(value); ejbs.put(value, currentEjb); } - } else if (currentLoc.equals(base + "\\iiop")) { + } else if ((base + "\\iiop").equals(currentLoc)) { currentEjb.setIiop(value); - } else if (currentLoc.equals(base + "\\failover-required")) { + } else if ((base + "\\failover-required").equals(currentLoc)) { currentEjb.setHasession(value); - } else if (currentLoc.equals(base + "\\persistence-manager" - + "\\properties-file-location")) { + } else if ((base + + "\\persistence-manager\\properties-file-location") + .equals(currentLoc)) { currentEjb.addCmpDescriptor(value); } } @@ -904,7 +882,7 @@ public class IPlanetEjbc { private boolean cmp = false; // Does this EJB support CMP? private boolean iiop = false; // Does this EJB support IIOP? private boolean hasession = false; // Does this EJB require failover? - private List cmpDescriptors = new ArrayList(); // CMP descriptor list + private List<String> cmpDescriptors = new ArrayList<>(); // CMP descriptor list /** * Construct a new EJBInfo object with the given name. @@ -926,9 +904,8 @@ public class IPlanetEjbc { if (name == null) { if (implementation == null) { return "[unnamed]"; - } else { - return implementation.getClassName(); } + return implementation.getClassName(); } return name; } @@ -1002,7 +979,7 @@ public class IPlanetEjbc { } public void setCmp(String cmp) { - setCmp(cmp.equals("Container")); + setCmp("Container".equals(cmp)); } public boolean getCmp() { @@ -1014,7 +991,7 @@ public class IPlanetEjbc { } public void setIiop(String iiop) { - setIiop(iiop.equals("true")); + setIiop(Boolean.parseBoolean(iiop)); } public boolean getIiop() { @@ -1026,7 +1003,7 @@ public class IPlanetEjbc { } public void setHasession(String hasession) { - setHasession(hasession.equals("true")); + setHasession(Boolean.parseBoolean(hasession)); } public boolean getHasession() { @@ -1037,7 +1014,7 @@ public class IPlanetEjbc { cmpDescriptors.add(descriptor); } - public List getCmpDescriptors() { + public List<String> getCmpDescriptors() { return cmpDescriptors; } @@ -1054,53 +1031,52 @@ public class IPlanetEjbc { /* Check that the specified instance variables are valid */ if (home == null) { - throw new EjbcException("A home interface was not found " - + "for the " + name + " EJB."); + throw new EjbcException( + "A home interface was not found for the " + name + " EJB."); } if (remote == null) { - throw new EjbcException("A remote interface was not found " - + "for the " + name + " EJB."); + throw new EjbcException( + "A remote interface was not found for the " + name + + " EJB."); } if (implementation == null) { - throw new EjbcException("An EJB implementation class was not " - + "found for the " + name + " EJB."); + throw new EjbcException( + "An EJB implementation class was not found for the " + name + + " EJB."); } if ((!beantype.equals(ENTITY_BEAN)) - && (!beantype.equals(STATELESS_SESSION)) - && (!beantype.equals(STATEFUL_SESSION))) { - throw new EjbcException("The beantype found (" + beantype + ") " - + "isn't valid in the " + name + " EJB."); + && (!beantype.equals(STATELESS_SESSION)) + && (!beantype.equals(STATEFUL_SESSION))) { + throw new EjbcException("The beantype found (" + beantype + + ") isn't valid in the " + name + " EJB."); } if (cmp && (!beantype.equals(ENTITY_BEAN))) { - System.out.println("CMP stubs and skeletons may not be generated" - + " for a Session Bean -- the \"cmp\" attribute will be" - + " ignoredfor the " + name + " EJB."); + System.out.println( + "CMP stubs and skeletons may not be generated for a Session Bean -- the \"cmp\" attribute will be ignoredfor the " + + name + " EJB."); } if (hasession && (!beantype.equals(STATEFUL_SESSION))) { - System.out.println("Highly available stubs and skeletons may " - + "only be generated for a Stateful Session Bean -- the " - + "\"hasession\" attribute will be ignored for the " - + name + " EJB."); + System.out.println( + "Highly available stubs and skeletons may only be generated for a Stateful Session Bean -- the \"hasession\" attribute will be ignored for the " + + name + " EJB."); } /* Check that the EJB "source" classes all exist */ if (!remote.getClassFile(buildDir).exists()) { throw new EjbcException("The remote interface " - + remote.getQualifiedClassName() + " could not be " - + "found."); + + remote.getQualifiedClassName() + " could not be found."); } if (!home.getClassFile(buildDir).exists()) { throw new EjbcException("The home interface " - + home.getQualifiedClassName() + " could not be " - + "found."); + + home.getQualifiedClassName() + " could not be found."); } if (!implementation.getClassFile(buildDir).exists()) { throw new EjbcException("The EJB implementation class " - + implementation.getQualifiedClassName() + " could " - + "not be found."); + + implementation.getQualifiedClassName() + + " could not be found."); } } @@ -1149,9 +1125,8 @@ public class IPlanetEjbc { remoteFile = remote.getClassFile(buildDir); modified = remoteFile.lastModified(); if (modified == -1) { - System.out.println("The class " - + remote.getQualifiedClassName() + " couldn't " - + "be found on the classpath"); + System.out.println("The class " + remote.getQualifiedClassName() + + " couldn't be found on the classpath"); return -1; } latestModified = modified; @@ -1160,9 +1135,8 @@ public class IPlanetEjbc { homeFile = home.getClassFile(buildDir); modified = homeFile.lastModified(); if (modified == -1) { - System.out.println("The class " - + home.getQualifiedClassName() + " couldn't be " - + "found on the classpath"); + System.out.println("The class " + home.getQualifiedClassName() + + " couldn't be found on the classpath"); return -1; } latestModified = Math.max(latestModified, modified); @@ -1172,9 +1146,9 @@ public class IPlanetEjbc { pkFile = primaryKey.getClassFile(buildDir); modified = pkFile.lastModified(); if (modified == -1) { - System.out.println("The class " - + primaryKey.getQualifiedClassName() + "couldn't be " - + "found on the classpath"); + System.out.println( + "The class " + primaryKey.getQualifiedClassName() + + "couldn't be found on the classpath"); return -1; } latestModified = Math.max(latestModified, modified); @@ -1237,7 +1211,7 @@ public class IPlanetEjbc { */ private long destClassesModified(File destDir) { String[] classnames = classesToGenerate(); // List of all stubs & skels - long destClassesModified = new Date().getTime(); // Earliest mod time + long destClassesModified = Instant.now().toEpochMilli(); // Earliest mod time boolean allClassesFound = true; // Has each been found? /* @@ -1245,7 +1219,6 @@ public class IPlanetEjbc { * determine (if all exist) which file has the most recent timestamp */ for (int i = 0; i < classnames.length; i++) { - String pathToClass = classnames[i].replace('.', File.separatorChar) + ".class"; File classFile = new File(destDir, pathToClass); @@ -1266,7 +1239,7 @@ public class IPlanetEjbc { } } - return (allClassesFound) ? destClassesModified : -1; + return allClassesFound ? destClassesModified : -1; } /** @@ -1330,6 +1303,7 @@ public class IPlanetEjbc { * * @return A String representing the EjbInfo instance. */ + @Override public String toString() { String s = "EJB name: " + name + "\n\r home: " + home @@ -1341,7 +1315,7 @@ public class IPlanetEjbc { + "\n\r iiop: " + iiop + "\n\r hasession: " + hasession; - Iterator i = cmpDescriptors.iterator(); + Iterator<String> i = cmpDescriptors.iterator(); while (i.hasNext()) { s += "\n\r CMP Descriptor: " + i.next(); } @@ -1446,6 +1420,7 @@ public class IPlanetEjbc { * * @return String representing the fully qualified class name. */ + @Override public String toString() { return getQualifiedClassName(); } @@ -1477,18 +1452,16 @@ public class IPlanetEjbc { * Reads text from the input stream and redirects it to standard output * using a separate thread. */ + @Override public void run() { - BufferedReader reader = new BufferedReader( - new InputStreamReader(stream)); - String text; - try { + try (BufferedReader reader = + new BufferedReader(new InputStreamReader(stream))) { + String text; while ((text = reader.readLine()) != null) { System.out.println(text); } } catch (IOException e) { e.printStackTrace(); //NOSONAR - } finally { - FileUtils.close(reader); } } } // End of RedirectOutput inner class http://git-wip-us.apache.org/repos/asf/ant/blob/b7d1e9bd/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java index ee5dc85..147e5d5 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/IPlanetEjbcTask.java @@ -188,6 +188,7 @@ public class IPlanetEjbcTask extends Task { * Does the work. * @throws BuildException if there is a problem. */ + @Override public void execute() throws BuildException { checkConfiguration(); @@ -202,41 +203,42 @@ public class IPlanetEjbcTask extends Task { private void checkConfiguration() throws BuildException { if (ejbdescriptor == null) { - String msg = "The standard EJB descriptor must be specified using " - + "the \"ejbdescriptor\" attribute."; + String msg = + "The standard EJB descriptor must be specified using the \"ejbdescriptor\" attribute."; throw new BuildException(msg, getLocation()); } if ((!ejbdescriptor.exists()) || (!ejbdescriptor.isFile())) { String msg = "The standard EJB descriptor (" + ejbdescriptor - + ") was not found or isn't a file."; + + ") was not found or isn't a file."; throw new BuildException(msg, getLocation()); } if (iasdescriptor == null) { - String msg = "The iAS-speific XML descriptor must be specified using" - + " the \"iasdescriptor\" attribute."; + String msg = + "The iAS-speific XML descriptor must be specified using the \"iasdescriptor\" attribute."; throw new BuildException(msg, getLocation()); } if ((!iasdescriptor.exists()) || (!iasdescriptor.isFile())) { String msg = "The iAS-specific XML descriptor (" + iasdescriptor - + ") was not found or isn't a file."; + + ") was not found or isn't a file."; throw new BuildException(msg, getLocation()); } if (dest == null) { - String msg = "The destination directory must be specified using " - + "the \"dest\" attribute."; + String msg = + "The destination directory must be specified using the \"dest\" attribute."; throw new BuildException(msg, getLocation()); } if ((!dest.exists()) || (!dest.isDirectory())) { - String msg = "The destination directory (" + dest + ") was not " - + "found or isn't a directory."; + String msg = "The destination directory (" + dest + + ") was not found or isn't a directory."; throw new BuildException(msg, getLocation()); } if ((iashome != null) && (!iashome.isDirectory())) { - String msg = "If \"iashome\" is specified, it must be a valid " - + "directory (it was set to " + iashome + ")."; + String msg = + "If \"iashome\" is specified, it must be a valid directory (it was set to " + + iashome + ")."; throw new BuildException(msg, getLocation()); } } @@ -248,21 +250,13 @@ public class IPlanetEjbcTask extends Task { * @throws BuildException If the parser cannot be created or configured. */ private SAXParser getParser() throws BuildException { - - SAXParser saxParser = null; try { SAXParserFactory saxParserFactory = SAXParserFactory.newInstance(); saxParserFactory.setValidating(true); - saxParser = saxParserFactory.newSAXParser(); - } catch (SAXException e) { - String msg = "Unable to create a SAXParser: " + e.getMessage(); - throw new BuildException(msg, e, getLocation()); - } catch (ParserConfigurationException e) { - String msg = "Unable to create a SAXParser: " + e.getMessage(); - throw new BuildException(msg, e, getLocation()); + return saxParserFactory.newSAXParser(); + } catch (SAXException | ParserConfigurationException e) { + throw new BuildException("Unable to create a SAXParser: " + e.getMessage(), e, getLocation()); } - - return saxParser; } /** @@ -284,21 +278,23 @@ public class IPlanetEjbcTask extends Task { if (iashome != null) { ejbc.setIasHomeDir(iashome); } - try { ejbc.execute(); } catch (IOException e) { - String msg = "An IOException occurred while trying to read the XML " - + "descriptor file: " + e.getMessage(); - throw new BuildException(msg, e, getLocation()); + throw new BuildException( + "An IOException occurred while trying to read the XML descriptor file: " + + e.getMessage(), + e, getLocation()); } catch (SAXException e) { - String msg = "A SAXException occurred while trying to read the XML " - + "descriptor file: " + e.getMessage(); - throw new BuildException(msg, e, getLocation()); + throw new BuildException( + "A SAXException occurred while trying to read the XML descriptor file: " + + e.getMessage(), + e, getLocation()); } catch (IPlanetEjbc.EjbcException e) { - String msg = "An exception occurred while trying to run the ejbc " - + "utility: " + e.getMessage(); - throw new BuildException(msg, e, getLocation()); + throw new BuildException( + "An exception occurred while trying to run the ejbc utility: " + + e.getMessage(), + e, getLocation()); } } @@ -309,13 +305,9 @@ public class IPlanetEjbcTask extends Task { * @return Path The classpath to be used for EJBc. */ private Path getClasspath() { - Path cp = null; if (classpath == null) { - cp = (new Path(getProject())).concatSystemClasspath("last"); - } else { - cp = classpath.concatSystemClasspath("ignore"); - } - - return cp; + return new Path(getProject()).concatSystemClasspath("last"); + } + return classpath.concatSystemClasspath("ignore"); } }
