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

📄 genericdeploymenttool.java

📁 Use the links below to download a source distribution of Ant from one of our mirrors. It is good pra
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *  Licensed to the Apache Software Foundation (ASF) under one or more *  contributor license agreements.  See the NOTICE file distributed with *  this work for additional information regarding copyright ownership. *  The ASF licenses this file to You under the Apache License, Version 2.0 *  (the "License"); you may not use this file except in compliance with *  the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * *  Unless required by applicable law or agreed to in writing, software *  distributed under the License is distributed on an "AS IS" BASIS, *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *  See the License for the specific language governing permissions and *  limitations under the License. * */package org.apache.tools.ant.taskdefs.optional.ejb;import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;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;import java.util.zip.ZipEntry;import javax.xml.parsers.SAXParser;import org.apache.tools.ant.BuildException;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.types.FileSet;import org.apache.tools.ant.types.Path;import org.apache.tools.ant.util.depend.DependencyAnalyzer;import org.xml.sax.InputSource;import org.xml.sax.SAXException;/** * A deployment tool which creates generic EJB jars. Generic jars contains * only those classes and META-INF entries specified in the EJB 1.1 standard * * This class is also used as a framework for the creation of vendor specific * deployment tools. A number of template methods are provided through which the * vendor specific tool can hook into the EJB creation process. * */public class GenericDeploymentTool implements EJBDeploymentTool {    /** The default buffer byte size to use for IO */    public static final int DEFAULT_BUFFER_SIZE = 1024;    /** The level to use for compression */    public static final int JAR_COMPRESS_LEVEL  = 9;    /** The standard META-INF directory in jar files */    protected static final String META_DIR  = "META-INF/";    /** The standard MANIFEST file */    protected static final String MANIFEST  = META_DIR + "MANIFEST.MF";    /** Name for EJB Deployment descriptor within EJB jars */    protected static final String EJB_DD    = "ejb-jar.xml";    /** A dependency analyzer name to find ancestor classes */    public static final String ANALYZER_SUPER = "super";    /** A dependency analyzer name to find all related classes */    public static final String ANALYZER_FULL = "full";    /** A dependency analyzer name for no analyzer */    public static final String ANALYZER_NONE = "none";    /** The default analyzer */    public static final String DEFAULT_ANALYZER = ANALYZER_SUPER;    /** The analyzer class for the super analyzer */    public static final String ANALYZER_CLASS_SUPER        = "org.apache.tools.ant.util.depend.bcel.AncestorAnalyzer";    /** The analyzer class for the super analyzer */    public static final String ANALYZER_CLASS_FULL        = "org.apache.tools.ant.util.depend.bcel.FullAnalyzer";    /**     * The configuration from the containing task. This config combined     * with the settings of the individual attributes here constitues the     * complete config for this deployment tool.     */    private EjbJar.Config config;    /** Stores a handle to the directory to put the Jar files in */    private File destDir;    /** The classpath to use with this deployment tool. This is appended to        any paths from the ejbjar task itself.*/    private Path classpath;    /** Instance variable that stores the suffix for the generated jarfile. */    private String genericJarSuffix = "-generic.jar";    /**     * The task to which this tool belongs. This is used to access services     * provided by the ant core, such as logging.     */    private Task task;    /**     * The classloader generated from the given classpath to load     * the super classes and super interfaces.     */    private ClassLoader classpathLoader = null;     /**     * Set of files have been loaded into the EJB jar     */    private Set addedfiles;    /**     * Handler used to parse the EJB XML descriptor     */    private DescriptorHandler handler;    /**     * Dependency analyzer used to collect class dependencies     */    private DependencyAnalyzer dependencyAnalyzer;    /** No arg constructor */    public GenericDeploymentTool() {    }    /**     * Set the destination directory; required.     * @param inDir the destination directory.     */    public void setDestdir(File inDir) {        this.destDir = inDir;    }    /**     * Get the destination directory.     *     * @return the destination directory into which EJB jars are to be written     */    protected File getDestDir() {        return destDir;    }    /**     * Set the task which owns this tool     *     * @param task the Task to which this deployment tool is associated.     */    public void setTask(Task task) {        this.task = task;    }    /**     * Get the task for this tool.     *     * @return the Task instance this tool is associated with.     */    protected Task getTask() {        return task;    }    /**     * Get the basename terminator.     *     * @return an ejbjar task configuration     */    protected EjbJar.Config getConfig() {        return config;    }    /**     * Indicate if this build is using the base jar name.     *     * @return true if the name of the generated jar is coming from the     *              basejarname attribute     */    protected boolean usingBaseJarName() {        return config.baseJarName != null;    }    /**     * Set the suffix for the generated jar file.     * @param inString the string to use as the suffix.     */    public void setGenericJarSuffix(String inString) {        this.genericJarSuffix = inString;    }    /**     * Add the classpath for the user classes     *     * @return a Path instance to be configured by Ant.     */    public Path createClasspath() {        if (classpath == null) {            classpath = new Path(task.getProject());        }        return classpath.createPath();    }    /**     * Set the classpath to be used for this compilation.     *     * @param classpath the classpath to be used for this build.     */    public void setClasspath(Path classpath) {        this.classpath = classpath;    }    /**     * Get the classpath by combining the one from the surrounding task, if any     * and the one from this tool.     *     * @return the combined classpath     */    protected Path getCombinedClasspath() {        Path combinedPath = classpath;        if (config.classpath != null) {            if (combinedPath == null) {                combinedPath = config.classpath;            } else {                combinedPath.append(config.classpath);            }        }        return combinedPath;    }    /**     * Log a message to the Ant output.     *     * @param message the message to be logged.     * @param level the severity of this message.     */    protected void log(String message, int level) {        getTask().log(message, level);    }    /**     * Get the build file location associated with this element's task.     *     * @return the task's location instance.     */    protected Location getLocation() {        return getTask().getLocation();    }    private void createAnalyzer() {        String analyzer = config.analyzer;        if (analyzer == null) {            analyzer = DEFAULT_ANALYZER;        }        if (analyzer.equals(ANALYZER_NONE)) {            return;        }        String analyzerClassName = null;        if (analyzer.equals(ANALYZER_SUPER)) {            analyzerClassName = ANALYZER_CLASS_SUPER;        } else if (analyzer.equals(ANALYZER_FULL)) {            analyzerClassName = ANALYZER_CLASS_FULL;        } else {            analyzerClassName = analyzer;        }        try {            Class analyzerClass = Class.forName(analyzerClassName);            dependencyAnalyzer                = (DependencyAnalyzer) analyzerClass.newInstance();            dependencyAnalyzer.addClassPath(new Path(task.getProject(),                config.srcDir.getPath()));            dependencyAnalyzer.addClassPath(config.classpath);        } catch (NoClassDefFoundError e) {            dependencyAnalyzer = null;            task.log("Unable to load dependency analyzer: " + analyzerClassName                + " - dependent class not found: " + e.getMessage(),                Project.MSG_WARN);        } catch (Exception e) {            dependencyAnalyzer = null;            task.log("Unable to load dependency analyzer: " + analyzerClassName                     + " - exception: " + e.getMessage(),                Project.MSG_WARN);        }    }    /**     * Configure this tool for use in the ejbjar task.     *     * @param config the configuration from the surrounding ejbjar task.     */    public void configure(EjbJar.Config config) {        this.config = config;        createAnalyzer();        classpathLoader = null;    }    /**     * Utility method that encapsulates the logic of adding a file entry to     * a .jar file.  Used by execute() to add entries to the jar file as it is     * constructed.     * @param jStream A JarOutputStream into which to write the     *        jar entry.     * @param inputFile A File from which to read the

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -