⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weblogicdeploymenttool.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (classpath == null) {                classpath = getCombinedClasspath();            }            javaTask.setFork(true);            if (classpath != null) {                javaTask.setClasspath(classpath);            }            log("Calling " + ejbcClassName + " for " + sourceJar.toString(),                Project.MSG_VERBOSE);            if (javaTask.executeJava() != 0) {                throw new BuildException("Ejbc reported an error");            }        } 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);        }    }    /**     * 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.     * @param jarFile the jar file to populate.     * @param files   the hash table of files to write.     * @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 {        // need to create a generic jar first.        File genericJarFile = super.getVendorOutputJarFile(baseName);        super.writeJar(baseName, genericJarFile, files, publicId);        if (alwaysRebuild || isRebuildRequired(genericJarFile, jarFile)) {            buildWeblogicJar(genericJarFile, jarFile, publicId);        }        if (!keepGeneric) {            log("deleting generic jar " + genericJarFile.toString(),                Project.MSG_VERBOSE);            genericJarFile.delete();        }    }    /**     * Called to validate that the tool parameters have been configured.     * @throws BuildException if there is an error.     */    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     * 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 weblogic     * jar needs to be regened with ejbc. This allows faster build times for     * working developers. <p>     *     * The way weblogic ejbc 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     * weblogic 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 ejbc. 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 weblogic jar gets rebuilt if the xml files change at     * all.     *     * @param genericJarFile java.io.File The generic jar file.     * @param weblogicJarFile java.io.File The weblogic jar file to check to     *      see if it needs to be rebuilt.     * @return true if the jar needs to be rebuilt.     */    // CheckStyle:MethodLength OFF - this will no be fixed    protected boolean isRebuildRequired(File genericJarFile, File weblogicJarFile) {        boolean rebuild = false;        JarFile genericJar = null;        JarFile wlJar = null;        File newWLJarFile = null;        JarOutputStream newJarStream = null;        ClassLoader genericLoader = null;        try {            log("Checking if weblogic Jar needs to be rebuilt for jar " + weblogicJarFile.getName(),                Project.MSG_VERBOSE);            // Only go forward if the generic and the weblogic file both exist            if (genericJarFile.exists() && genericJarFile.isFile()                 && weblogicJarFile.exists() && weblogicJarFile.isFile()) {                //open jar files                genericJar = new JarFile(genericJarFile);                wlJar = new JarFile(weblogicJarFile);                Hashtable genericEntries = new Hashtable();                Hashtable wlEntries = 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 weblogic jar entries                for (Enumeration e = wlJar.entries(); e.hasMoreElements();) {                    JarEntry je = (JarEntry) 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();                    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);                        if ((genericEntry.getCrc() != wlEntry.getCrc())                            || (genericEntry.getSize() != wlEntry.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 doesnt exist rebuild                        log("File " + filepath + " not present in weblogic jar",                            Project.MSG_VERBOSE);                        rebuild = true;                        break;                    }                }                if (!rebuild) {                    log("No rebuild needed - updating jar", Project.MSG_VERBOSE);                    newWLJarFile = new File(weblogicJarFile.getAbsolutePath() + ".temp");                    if (newWLJarFile.exists()) {                        newWLJarFile.delete();                    }                    newJarStream = new JarOutputStream(new FileOutputStream(newWLJarFile));                    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();                        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 weblogic jar                            is = wlJar.getInputStream(je);                        }                        newJarStream.putNextEntry(new JarEntry(je.getName()));                        while ((bytesRead = is.read(buffer)) != -1) {                            newJarStream.write(buffer, 0, bytesRead);                        }                        is.close();                    }                } else {                    log("Weblogic 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) {                    // empty                }            }            if (wlJar != null) {                try {                    wlJar.close();                } catch (IOException closeException) {                    // empty                }            }            if (newJarStream != null) {                try {                    newJarStream.close();                } catch (IOException closeException) {                    // empty                }                try {                    FILE_UTILS.rename(newWLJarFile, weblogicJarFile);                } catch (IOException renameException) {                    log(renameException.getMessage(), Project.MSG_WARN);                    rebuild = true;                }            }            if (genericLoader != null                && genericLoader instanceof AntClassLoader) {                AntClassLoader loader = (AntClassLoader) genericLoader;                loader.cleanup();            }        }        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 the classloader for the jarfile.     * @throws IOException if there is a problem.     */    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 + -