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

📄 bundle.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      referencedPackages.removeAll(privatePackages);      for (Iterator iterator = referencedPackages.iterator(); iterator.hasNext();) {        String packageName = (String) iterator.next();        if (!isStandardPackage(packageName) &&            !importPackage.containsKey(packageName)) {          if (packageAnalysis == PACKAGE_ANALYSIS_AUTO) {            if (exportPackage.containsKey(packageName)) {              importPackage.put(packageName, exportPackage.get(packageName)); // TODO: do we want to import with version?            } else {              importPackage.put(packageName, null);            }          } else if (packageAnalysis == PACKAGE_ANALYSIS_WARN) {            log("Referenced package not found in bundle or imports: " + packageName, Project.MSG_WARN);          }        }      }    }  }  private void addZipGroups() {    for (int i = 0; i < zipgroups.size(); i++) {      FileSet fileset = (FileSet) zipgroups.get(i);      FileScanner fs = fileset.getDirectoryScanner(getProject());      String[] files = fs.getIncludedFiles();      File basedir = fs.getBasedir();      for (int j = 0; j < files.length; j++) {        ZipFileSet zipfileset = new ZipFileSet();        zipfileset.setSrc(new File(basedir, files[j]));        srcFilesets.add(zipfileset);      }    }  }  private void addImplicitFileset() {    if (baseDir != null) {      FileSet fileset = (FileSet) getImplicitFileSet().clone();      fileset.setDir(baseDir);      srcFilesets.add(fileset);    }  }  private File getZipFile(FileSet fileset) {    if (fileset instanceof ZipFileSet) {      ZipFileSet zipFileset = (ZipFileSet) fileset;      return zipFileset.getSrc(getProject());    } else {      return null;    }  }  private void analyzeClass(ClassParser parser) throws IOException {    JavaClass javaClass = parser.parse();    availablePackages.add(javaClass.getPackageName());    String[] interfaces = javaClass.getInterfaceNames();    for (int i = 0; i < interfaces.length; i++) {      if("org.osgi.framework.BundleActivator".equals(interfaces[i])) {        activatorClasses.add(javaClass.getClassName());        break;      }    }    ConstantPool constantPool = javaClass.getConstantPool();    Constant[] constants = constantPool.getConstantPool();    for (int i = 0; i < constants.length; i++) {      Constant constant = constants[i];      if (constant instanceof ConstantClass) {        ConstantClass constantClass = (ConstantClass) constant;        String referencedClass = constantClass.getBytes(constantPool);        if (referencedClass.charAt(0) == '[') {          referencedClass = Utility.signatureToString(referencedClass, false);        } else {          referencedClass = Utility.compactClassName(referencedClass, false);        }        int lastDotIndex = referencedClass.lastIndexOf('.');        if (lastDotIndex >= 0) {          String packageName = referencedClass.substring(0, lastDotIndex);          referencedPackages.add(packageName);        }      }    }  }  private boolean isStandardPackage(String packageName) {    for (Iterator i = standardPackagePrefixes.iterator(); i.hasNext();) {      String prefix = (String) i.next();      if (packageName.startsWith(prefix)) {        return true;      }    }    return false;  }  private void handleActivator() throws ManifestException {    if (activator == ACTIVATOR_NONE) {      log("No BundleActivator set", Project.MSG_DEBUG);    } else if (activator == ACTIVATOR_AUTO) {      switch (activatorClasses.size()) {        case 0: {          log("No class implementing BundleActivator found", Project.MSG_INFO);          break;        }        case 1: {          activator = (String) activatorClasses.iterator().next();          break;        }        default: {          log("More than one class implementing BundleActivator found:", Project.MSG_WARN);          for (Iterator i = activatorClasses.iterator(); i.hasNext();) {            String activator = (String) i.next();            log("  " + activator, Project.MSG_WARN);          }          break;        }      }    }    if (activator != ACTIVATOR_NONE && activator != ACTIVATOR_AUTO) {      log("Bundle-Activator: " + activator, Project.MSG_INFO);      generatedManifest.addConfiguredAttribute(createAttribute(BUNDLE_ACTIVATOR_KEY, activator));    }  }  private void handleClassPath() throws ManifestException {    StringBuffer value = new StringBuffer();    boolean rootIncluded = false;    if (baseDir != null || classes.size() == 0) {      value.append(".,");      rootIncluded = true;    }    Iterator i = classes.iterator();    while (i.hasNext()) {      ZipFileSet zipFileSet = (ZipFileSet) i.next();      String prefix = zipFileSet.getPrefix(getProject());      if (prefix.length() > 0) {        value.append(prefix);        value.append(',');      } else if (!rootIncluded) {        value.append(".,");        rootIncluded = true;      }    }    i = libs.iterator();    while (i.hasNext()) {      ZipFileSet fileset = (ZipFileSet) i.next();      if (fileset.getSrc(getProject()) == null) {        DirectoryScanner ds = fileset.getDirectoryScanner(getProject());        String[] files = ds.getIncludedFiles();        if (files.length != 0) {          zipgroups.add(fileset);          String prefix = fixPrefix(fileset.getPrefix(getProject()));          for (int j = 0; j < files.length; j++) {            value.append(prefix.replace('\\', '/'));            value.append(files[j].replace('\\', '/'));            value.append(',');          }        }      }    }    if (value.length() > 2) {      generatedManifest.addConfiguredAttribute(createAttribute(BUNDLE_CLASS_PATH_KEY, value.substring(0, value.length() - 1)));    }  }  private static String fixPrefix(String prefix) {    if (prefix.length() > 0) {      char c = prefix.charAt(prefix.length() - 1);      if (c != '/' && c != '\\') {        prefix = prefix + "/";      }    }    return prefix;  }  private void addPackageHeader(String headerName, Map packageMap) throws ManifestException {    Iterator i = packageMap.entrySet().iterator();    if (i.hasNext()) {      StringBuffer valueBuffer = new StringBuffer();      while (i.hasNext()) {        Map.Entry entry = (Map.Entry) i.next();        String name = (String) entry.getKey();        String version = (String) entry.getValue();        valueBuffer.append(name);        if (version != null) {          valueBuffer.append(";specification-version=");          valueBuffer.append(version);        }        valueBuffer.append(',');      }      valueBuffer.setLength(valueBuffer.length() - 1);      String value = valueBuffer.toString();      generatedManifest.addConfiguredAttribute(createAttribute(headerName, value));      log(headerName + ": " + value, Project.MSG_INFO);    }  }  private static Manifest.Attribute createAttribute(String name, String value) {    Manifest.Attribute attribute = new Manifest.Attribute();    attribute.setName(name);    attribute.setValue(value);    return attribute;  }  // public methods  public void setActivator(String activator) {    if (ACTIVATOR_NONE.equalsIgnoreCase(activator)) {      this.activator = ACTIVATOR_NONE;    } else if (ACTIVATOR_AUTO.equalsIgnoreCase(activator)) {      this.activator = ACTIVATOR_AUTO;    } else {      this.activator = activator;    }  }  public void setPackageAnalysis(String packageAnalysis) {    packageAnalysis = packageAnalysis.trim().toLowerCase();    if (PACKAGE_ANALYSIS_NONE.equals(packageAnalysis)) {      this.packageAnalysis = PACKAGE_ANALYSIS_NONE;    } else if (PACKAGE_ANALYSIS_WARN.equals(packageAnalysis)) {      this.packageAnalysis = PACKAGE_ANALYSIS_WARN;    } else if (PACKAGE_ANALYSIS_AUTO.equals(packageAnalysis)) {      this.packageAnalysis = PACKAGE_ANALYSIS_AUTO;    } else {      throw new BuildException("Illegal value: " + packageAnalysis);    }  }  public void addConfiguredStandardPackage(OSGiPackage osgiPackage) {    String name = osgiPackage.getName();    String prefix = osgiPackage.getPrefix();    if (name != null && prefix == null) {      availablePackages.add(name);    } else if (prefix != null && name == null) {      standardPackagePrefixes.add(prefix);    } else {      throw new BuildException("StandardPackage must have exactly one of the name and prefix attributes defined");    }  }  public void addConfiguredImportPackage(OSGiPackage osgiPackage) {    String name = osgiPackage.getName();    if (name == null) {      throw new BuildException("ImportPackage must have a name");    } else if (osgiPackage.getPrefix() != null) {      throw new BuildException("ImportPackage must not have a prefix attribute");    } else {      importPackage.put(name, osgiPackage.getVersion());    }  }  public void addConfiguredExportPackage(OSGiPackage osgiPackage) {    String name = osgiPackage.getName();    if (name == null) {      throw new BuildException("ExportPackage must have a name");    } else if (osgiPackage.getPrefix() != null) {      throw new BuildException("ExportPackage must not have a prefix attribute");    } else {      exportPackage.put(name, osgiPackage.getVersion());    }  }  public void addConfiguredLib(ZipFileSet fileset) {    // TODO: handle refid    if (fileset.getSrc(getProject()) == null) {      addFileset(fileset);      libs.add(fileset);    } else {      addClasses(fileset);    }  }  public void addClasses(ZipFileSet fileset) {    super.addZipfileset(fileset);    srcFilesets.add(fileset);    classes.add(fileset);  }  // extends Jar  public void execute() {    try {      handleClassPath();      analyze();      handleActivator();      addPackageHeader(IMPORT_PACKAGE_KEY, importPackage);      addPackageHeader(EXPORT_PACKAGE_KEY, exportPackage);      // TODO: better merge may be needed, currently overwrites pre-existing headers      addConfiguredManifest(generatedManifest);    } catch (ManifestException me) {      throw new BuildException("Error merging manifest headers", me);    }    super.execute();  }  public void setBasedir(File baseDir) {    super.setBasedir(baseDir);    this.baseDir = baseDir;  }  public void addZipGroupFileset(FileSet fileset) {    super.addZipGroupFileset(fileset);    zipgroups.add(fileset);  }  public void addZipfileset(ZipFileSet fileset) {    super.addZipfileset(fileset);  }} // Bundle

⌨️ 快捷键说明

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