📄 genericdeploymenttool.java
字号:
* @param baseName the base name to use. * @param descriptorFileName the file name to use. * @return the prefix. */ public String getVendorDDPrefix(String baseName, String descriptorFileName) { String ddPrefix = null; if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.DESCRIPTOR)) { ddPrefix = baseName + config.baseNameTerminator; } else if (config.namingScheme.getValue().equals(EjbJar.NamingScheme.BASEJARNAME) || config.namingScheme.getValue().equals(EjbJar.NamingScheme.EJB_NAME) || config.namingScheme.getValue().equals(EjbJar.NamingScheme.DIRECTORY)) { String canonicalDescriptor = descriptorFileName.replace('\\', '/'); int index = canonicalDescriptor.lastIndexOf('/'); if (index == -1) { ddPrefix = ""; } else { ddPrefix = descriptorFileName.substring(0, index + 1); } } return ddPrefix; } /** * Add any vendor specific files which should be included in the * EJB Jar. * @param ejbFiles a hashtable entryname -> file. * @param ddPrefix a prefix to use. */ protected void addVendorFiles(Hashtable 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. * @param baseName the basename to use. */ File getVendorOutputJarFile(String baseName) { return new File(destDir, baseName + genericJarSuffix); } /** * This method checks the timestamp on each file listed in the <code> * ejbFiles</code> and compares them to the timestamp on the <code>jarFile * </code>. If the <code>jarFile</code>'s timestamp is more recent than * each EJB file, <code>true</code> is returned. Otherwise, <code>false * </code> is returned. * TODO: find a way to check the manifest-file, that is found by naming convention * * @param ejbFiles Hashtable of EJB classes (and other) files that will be * added to the completed JAR file * @param jarFile JAR file which will contain all of the EJB classes (and * other) files * @return boolean indicating whether or not the <code>jarFile</code> * is up to date */ protected boolean needToRebuild(Hashtable 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(); if (lastBuild < currentFile.lastModified()) { log("Build needed because " + currentFile.getPath() + " is out of date", Project.MSG_VERBOSE); return true; } } return false; } return true; } /** * Returns the Public ID of the DTD specified in the EJB descriptor. Not * every vendor-specific <code>DeploymentTool</code> will need to reference * this value or may want to determine this value in a vendor-specific way. * * @return Public ID of the DTD specified in the EJB descriptor. */ protected String getPublicId() { return handler.getPublicId(); } /** * Get the manifets file to use for building the generic jar. * * If the file does not exist the global manifest from the config is used * otherwise the default Ant manifest will be used. * * @param prefix the prefix where to llook for the manifest file based on * the naming convention. * * @return the manifest file or null if the manifest file does not exist */ protected File getManifestFile(String prefix) { File manifestFile = new File(getConfig().descriptorDir, prefix + "manifest.mf"); if (manifestFile.exists()) { return manifestFile; } if (config.manifest != null) { return config.manifest; } return null; } /** * Method used to encapsulate the writing of the JAR file. Iterates over the * filenames/java.io.Files in the Hashtable stored on the instance variable * ejbFiles. * @param baseName the base name to use. * @param jarfile the jar file to write to. * @param files the files to write to the jar. * @param publicId the id to use. * @throws BuildException if there is a problem. */ protected void writeJar(String baseName, File jarfile, Hashtable files, String publicId) throws BuildException { JarOutputStream jarStream = null; 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 * so that in case of errors we don't leave people worse off * than when we started =) */ if (jarfile.exists()) { jarfile.delete(); } jarfile.getParentFile().mkdirs(); jarfile.createNewFile(); InputStream in = null; Manifest manifest = null; try { File manifestFile = (File) files.get(MANIFEST); if (manifestFile != null && manifestFile.exists()) { in = new FileInputStream(manifestFile); } 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); } } manifest = new Manifest(in); } catch (IOException e) { throw new BuildException ("Unable to read manifest", e, getLocation()); } finally { if (in != null) { in.close(); } } // Create the streams necessary to write the jarfile jarStream = new JarOutputStream(new FileOutputStream(jarfile), 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 + "'", Project.MSG_VERBOSE); addFileToJar(jarStream, entryFile, entryName); } } } } catch (IOException ioe) { String msg = "IOException while processing ejb-jar file '" + jarfile.toString() + "'. Details: " + ioe.getMessage(); throw new BuildException(msg, ioe); } finally { if (jarStream != null) { try { jarStream.close(); } catch (IOException closeException) { // ignore } } } } // end of writeJar /** * Add all available classes, that depend on Remote, Home, Bean, PK * @param checkEntries files, that are extracted from the deployment descriptor * @throws BuildException if there is a problem. */ protected void checkAndAddDependants(Hashtable checkEntries) throws BuildException { if (dependencyAnalyzer == null) { return; } dependencyAnalyzer.reset(); Iterator i = checkEntries.keySet().iterator(); while (i.hasNext()) { String entryName = (String) i.next(); if (entryName.endsWith(".class")) { String className = entryName.substring(0, entryName.length() - ".class".length()); className = className.replace(File.separatorChar, '/'); className = className.replace('/', '.'); dependencyAnalyzer.addRootClass(className); } } Enumeration e = dependencyAnalyzer.getClassDependencies(); while (e.hasMoreElements()) { String classname = (String) e.nextElement(); String location = classname.replace('.', File.separatorChar) + ".class"; File classFile = new File(config.srcDir, location); if (classFile.exists()) { checkEntries.put(location, classFile); log("dependent class: " + classname + " - " + classFile, Project.MSG_VERBOSE); } } } /** * 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 * being added to the jar. * @return a classloader. */ protected ClassLoader getClassLoaderForBuild() { if (classpathLoader != null) { return classpathLoader; } Path combinedClasspath = getCombinedClasspath(); // only generate a new ClassLoader if we have a classpath if (combinedClasspath == null) { classpathLoader = getClass().getClassLoader(); } else { classpathLoader = getTask().getProject().createClassLoader(combinedClasspath); } return classpathLoader; } /** * Called to validate that the tool parameters have been configured. * * @throws BuildException If the Deployment Tool's configuration isn't * valid */ 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()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -