📄 webspheredeploymenttool.java
字号:
} log("Calling websphere.ejbdeploy for " + sourceJar.toString(), Project.MSG_VERBOSE); javaTask.execute(); } } 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); } } /** {@inheritDoc}. */ protected void writeJar(String baseName, File jarFile, Hashtable files, String publicId) throws BuildException { if (ejbdeploy) { // create the -generic.jar, if required File genericJarFile = super.getVendorOutputJarFile(baseName); super.writeJar(baseName, genericJarFile, files, publicId); // create the output .jar, if required if (alwaysRebuild || isRebuildRequired(genericJarFile, jarFile)) { buildWebsphereJar(genericJarFile, jarFile); } if (!keepGeneric) { log("deleting generic jar " + genericJarFile.toString(), Project.MSG_VERBOSE); genericJarFile.delete(); } } else { // create the "undeployed" output .jar, if required super.writeJar(baseName, jarFile, files, publicId); } } /** * Called to validate that the tool parameters have been configured. * @throws BuildException if there is an error. */ 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'"); } 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" * classes are the only thing that needs to be updated and either updates * the Jar with the Bean classfile or returns true, saying that the whole * websphere jar needs to be regened with ejbdeploy. This allows faster * build times for working developers. <p> * * The way websphere ejbdeploy works is it creates wrappers for the * publicly defined methods as they are exposed in the remote interface. * If the actual bean changes without changing the the method signatures * then only the bean classfile needs to be updated and the rest of the * websphere jar file can remain the same. If the Interfaces, ie. the * method signatures change or if the xml deployment descriptors changed, * the whole jar needs to be rebuilt with ejbdeploy. This is not strictly * true for the xml files. If the JNDI name changes then the jar doesnt * have to be rebuild, but if the resources references change then it * does. At this point the websphere jar gets rebuilt if the xml files * change at all. * * @param genericJarFile java.io.File The generic jar file. * @param websphereJarFile java.io.File The websphere jar file to check to * see if it needs to be rebuilt. * @return true if a rebuild is required. */ // CheckStyle:MethodLength OFF - this will no be fixed protected boolean isRebuildRequired(File genericJarFile, File websphereJarFile) { boolean rebuild = false; JarFile genericJar = null; JarFile wasJar = null; File newwasJarFile = null; JarOutputStream newJarStream = null; try { log("Checking if websphere Jar needs to be rebuilt for jar " + websphereJarFile.getName(), Project.MSG_VERBOSE); // Only go forward if the generic and the websphere file both exist if (genericJarFile.exists() && genericJarFile.isFile() && websphereJarFile.exists() && websphereJarFile.isFile()) { //open jar files genericJar = new JarFile(genericJarFile); wasJar = new JarFile(websphereJarFile); Hashtable genericEntries = new Hashtable(); Hashtable wasEntries = new Hashtable(); Hashtable replaceEntries = new Hashtable(); //get the list of generic jar entries for (Enumeration e = genericJar.entries(); e.hasMoreElements();) { JarEntry je = (JarEntry) 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(); wasEntries.put(je.getName(), je); } //Cycle Through generic and make sure its in websphere ClassLoader genericLoader = getClassLoaderFromJar(genericJarFile); for (Enumeration e = genericEntries.keys(); e.hasMoreElements();) { String filepath = (String) 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); if ((genericEntry.getCrc() != wasEntry.getCrc()) || (genericEntry.getSize() != wasEntry.getSize())) { if (genericEntry.getName().endsWith(".class")) { //File are different see if its an object or an interface String classname = genericEntry.getName().replace(File.separatorChar, '.'); classname = classname.substring(0, classname.lastIndexOf(".class")); Class genclass = genericLoader.loadClass(classname); if (genclass.isInterface()) { //Interface changed rebuild jar. log("Interface " + genclass.getName() + " 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; } } } else { // a file doesn't exist rebuild log("File " + filepath + " not present in websphere jar", Project.MSG_VERBOSE); rebuild = true; break; } } if (!rebuild) { log("No rebuild needed - updating jar", Project.MSG_VERBOSE); newwasJarFile = new File(websphereJarFile.getAbsolutePath() + ".temp"); if (newwasJarFile.exists()) { newwasJarFile.delete(); } newJarStream = new JarOutputStream(new FileOutputStream(newwasJarFile)); 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(); if (je.getCompressedSize() == -1 || je.getCompressedSize() == je.getSize()) { newJarStream.setLevel(0); } else { newJarStream.setLevel(JAR_COMPRESS_LEVEL); } // 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()); is = genericJar.getInputStream(je); } else { //use fle from original websphere jar is = wasJar.getInputStream(je); } newJarStream.putNextEntry(new JarEntry(je.getName())); while ((bytesRead = is.read(buffer)) != -1) { newJarStream.write(buffer, 0, bytesRead); } is.close(); } } else { log("websphere Jar rebuild needed due to changed " + "interface or XML", Project.MSG_VERBOSE); } } else { rebuild = true; } } catch (ClassNotFoundException cnfe) { String cnfmsg = "ClassNotFoundException while processing ejb-jar file" + ". Details: " + cnfe.getMessage(); throw new BuildException(cnfmsg, cnfe); } catch (IOException ioe) { String msg = "IOException while processing ejb-jar file " + ". Details: " + ioe.getMessage(); throw new BuildException(msg, ioe); } finally { // need to close files and perhaps rename output if (genericJar != null) { try { genericJar.close(); } catch (IOException closeException) { // Ignore } } if (wasJar != null) { try { wasJar.close(); } catch (IOException closeException) { // Ignore } } if (newJarStream != null) { try { newJarStream.close(); } catch (IOException closeException) { // Ignore } try { FILE_UTILS.rename(newwasJarFile, websphereJarFile); } catch (IOException renameException) { log(renameException.getMessage(), Project.MSG_WARN); rebuild = true; } } } return rebuild; } /** * Helper method invoked by isRebuildRequired to get a ClassLoader for a * Jar File passed to it. * * @param classjar java.io.File representing jar file to get classes from. * @return a classloader for the jar file. * @throws IOException if there is an error. */ protected ClassLoader getClassLoaderFromJar(File classjar) throws IOException { Path lookupPath = new Path(getTask().getProject()); lookupPath.setLocation(classjar); Path classpath = getCombinedClasspath(); if (classpath != null) { lookupPath.append(classpath); } return getTask().getProject().createClassLoader(lookupPath); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -