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

📄 bundleinfotask.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003, KNOPFLERFISH project * All rights reserved. * * Redistribution and use in source and binary forms, with or without  * modification, are permitted provided that the following conditions are met: *  * - Redistributions of source code must retain the above copyright notice,  *   this list of conditions and the following disclaimer.  *  * - Redistributions in binary form must reproduce the above copyright notice,  *   this list of conditions and the following disclaimer in the documentation  *   and/or other materials provided with the distribution.  *  * - Neither the name of the KNOPFLERFISH project nor the names of its  *   contributors may be used to endorse or promote products derived  *   from this software without specific prior written permission.  *  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. */package org.knopflerfish.ant.taskdefs.bundle;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.util.Iterator;import java.util.Set;import java.util.TreeSet;import java.util.Vector;import org.apache.bcel.classfile.ClassParser;import org.apache.bcel.classfile.Constant;import org.apache.bcel.classfile.ConstantClass;import org.apache.bcel.classfile.ConstantPool;import org.apache.bcel.classfile.JavaClass;import org.apache.bcel.classfile.Utility;import org.apache.bcel.generic.BasicType;import org.apache.bcel.generic.Type;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.DirectoryScanner;import org.apache.tools.ant.Project;import org.apache.tools.ant.Task;import org.apache.tools.ant.types.FileSet;import org.apache.tools.ant.util.FileUtils;import org.apache.tools.ant.util.StringUtils;/** * Task that analyzes a set of java sources or class files, and lists all * imported and defined packages. Also tries to find any class implementing * <tt>org.osgi.framework.BundleActivator</tt>. * * <ul> * <li><b>Class files</b> * <p> * Java class files are analyzed using the BCEL lib available from * <a href="http://jakarta.apache.org/bcel">http://jakarta.apache.org/bcel</a>. * <br> * <b>Note</b>: Scanning <i>only</i> applies * to the listed files - a complete closure of all referenced classes is * not done. * </p> * * <li><b>Source code</b> * <p> * Java source code is analyzed using very simple line-based scanning of  * files. <br> * <b>Note</b>: Source code analysis does not attempt to find any * <tt>BundleActivator</tt> * </p> *  * <li><b>Jar files</b> * <p> * Jar file analysis is not yet implemented * </p> * * </ul> * * <h3>Parameters</h3> * * <table border=> *  <tr> *   <td valign=top><b>Attribute</b></td> *   <td valign=top><b>Description</b></td> *   <td valign=top><b>Required</b></td> *  </tr> *  <tr> *   <td valign=top>imports</td> *   <td valign=top>Name of property that will receive a comma-separated list  *       of all used packages.  *       <p> *       If set to empty string, no property will be set. *       </p> *       <p> *       <b>Note</b>: Some default packages are always added. These  *       defaults can be set using the <tt>defaultimports</tt> parameter. *       </p> *   </td> *   <td valign=top>No.<br> Default value is ""</td> *  </tr> *  <tr> *   <td valign=top>exports</td> *   <td valign=top>Name of property that will receive a comma-separated  *       list of all defined packages.  *       <p> *       If set to empty string, no property will be set. *       </p> *   </td> *   <td valign=top>No.<br> Default value is ""</td> *  </tr> *   <td valign=top>activator</td> *   <td valign=top> *       Name of property that will receive name of class which implements  *       <tt>org.osgi.framework.BundleActivator</tt> *       <p> *       If set to empty string, no property will be set. *       </p> *       <p> *       If set to non-empty, and multiple activators are found, or *       an activator not equal to any previous content in the named property *       is found - a warning will be logged. *       </p> *  </td> *   <td valign=top>No.<br> Default value is ""</td> *  </tr> *  <tr> *   <td valign=top>stdimports</td> *   <td valign=top> *       Comma-separated list of all prefixes to standard packages that  *       should be ignored in exports list. *   </td> *   <td valign=top> *     No.<br> *     Default value is "java." *   </td> *  </tr> * *  <tr> *   <td valign=top>defaultimports</td> *   <td valign=top> *       Comma-separated list of all default imported packages.  *       <p> *       <b>Note</b>: Do not set <tt>defaultimports</tt> to the empty  *       string, since that might  *       cause an later illegal bundle manifest file if <i>no</i> imported  *       packages are found. *       </p> *   </td> *   <td valign=top> *     No.<br>  *     Default value is "org.osgi.framework" *   </td> *  </tr> * *  <tr> *   <td valign=top>checkFoundationEE</td> *   <td valign=top> *       Flag for testing for the Foundation Execution Environment *       <p> *       If set to "true", the task will check if all used classes *       is in the set of the OSGi Foundation Execution Environment. *       </p> *   </td> *   <td valign=top> *     No.<br>  *     Default value is "false" *   </td> *  </tr> * * <h3>Parameters specified as nested elements</h3> * <h4>fileset</h4> * * (required)<br> * <p> * All files must be specified as a fileset. Unsupported file types  * are ignored.  * </p> * * <h3>Examples</h3> * * <h4>Check all imports and activator in implementation classes</h4> * * <p> * This example assumes all implemention classes are in the package * <tt>test.impl.*</tt> * </p> * * <pre> *  &lt;bundleinfo  activator = "bundle.activator"  *               imports   = "impl.import.package"&gt; *   &lt;fileset dir="classes" includes="test/impl/&#042;"/&gt; *  &lt;/bundleinfo&gt; *  &lt;echo message="imports   = ${impl.import.package}"/&gt; *  &lt;echo message="activator = ${bundle.activator}"/&gt; * </pre>  * * * <h4>Check all imports and exports in API classes</h4> * * <p> * This example assumes all API classes are in the package * <tt>test.*</tt> * </p> * * <pre> *  &lt;bundleinfo  exports  = "api.export.package"  *               imports  = "api.import.package"&gt; *   &lt;fileset dir="classes" includes="test/&#042;"/&gt; *  &lt;/bundleinfo&gt; *  &lt;echo message="imports  = ${api.import.package}"/&gt; *  &lt;echo message="exports  = ${api.export.package}"/&gt; * </pre>  *  */public class BundleInfoTask extends Task {    private Vector    filesets = new Vector();  private FileUtils fileUtils;    private String importsProperty   = "";  private String exportsProperty   = "";  private String activatorProperty = "";  private String mainProperty      = "";    private Set     stdImports       = new TreeSet();  private boolean bDebug           = false;  private boolean bPrintClasses      = false;  private boolean bCheckFoundationEE = false;  private boolean bCheckMinimumEE    = false;  private boolean bCheckSMFEE        = false;  private Set importSet            = new TreeSet();  private Set exportSet            = new TreeSet();  private Set activatorSet         = new TreeSet();  private Set classSet             = new TreeSet();  private Set ownClasses           = new TreeSet();    public BundleInfoTask() {    fileUtils = FileUtils.newFileUtils();    setDefaultImports("org.osgi.framework");    setStdImports("java.");  }    /**   * Set property receiving list of imported packages.   */  public void setImports(String s) {    this.importsProperty  = s;  }  public void setPrintClasses(String s) {    this.bPrintClasses = "true".equals(s);  }  public void setCheckFoundationEE(String s) {    this.bCheckFoundationEE = "true".equals(s);  }  public void setCheckMinimumEE(String s) {    this.bCheckMinimumEE = "true".equals(s);  }  public void setCheckSMFEE(String s) {    this.bCheckSMFEE = "true".equals(s);  }  /**   * Set default import set.   *   * @param packageList Comma-separated list of package names.   */  public void setDefaultImports(String packageList) {    Vector v = StringUtils.split(packageList.trim(),',');      importSet.clear();    importSet.addAll(v);  }  /**   * Set property receiving list of exported packages.   */  public void setExports(String propName) {    this.exportsProperty = propName;  }  /**   * Set property receiving any BundleActivator class.   */  public void setActivator(String propName) {    this.activatorProperty = propName;  }  /**   * Set property receiving any Main class.   * <p>   * Not yet implemented.   * </p>   */  public void setMain(String propName) {    this.mainProperty = propName;  }  /**   * Set set of packages always imported.   *   * @param packageList Comma-separated list of package names.   */  public void setStdImports(String packageList) {    stdImports.clear();    stdImports.addAll(StringUtils.split(packageList.trim(),','));  }    public void addFileset(FileSet set) {    filesets.addElement(set);  }    // Implements Task  //   // Scan all files in fileset and delegate to analyze()  // then write back values to properties.  public void execute() throws BuildException {    if (filesets.size() == 0) {      throw new BuildException("No fileset specified");    }        for (int i = 0; i < filesets.size(); i++) {      FileSet fs = (FileSet) filesets.elementAt(i);      DirectoryScanner ds = fs.getDirectoryScanner(project);      File fromDir = fs.getDir(project);            String[] srcFiles = ds.getIncludedFiles();      String[] srcDirs = ds.getIncludedDirectories();            for (int j = 0; j < srcFiles.length ; j++) {	analyze(new File(fromDir, srcFiles[j]));      }            for (int j = 0; j < srcDirs.length ; j++) {	analyze(new File(fromDir, srcDirs[j]));      }    }    // Scan done - write back properties    Project proj = getProject();    importSet.removeAll(exportSet);

⌨️ 快捷键说明

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