@Override
  public ContainerBundleAnalyzer analyze(File bundle) {
    packageExports = null;
    Analyzer analyzer = new Analyzer();
    Jar jar = null;
    try {
      jar = new Jar(bundle);
      Manifest manifest = jar.getManifest();
      String exportHeader = manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
      if (exportHeader != null) {
        Map<String, Map<String, String>> exported = analyzer.parseHeader(exportHeader);

        packageExports = exported.keySet();
      } else {
        packageExports = new HashSet<>();
      }
    } catch (Exception e) {
      throw new SmartSpacesException(
          String.format("Could not analyze bundle %s", bundle.getAbsolutePath()), e);
    } finally {
      fileSupport.close(analyzer, false);
      fileSupport.close(jar, false);
    }

    return this;
  }
Exemple #2
0
  public Manifest getManifest(
      MavenProject project, Map instructions, Properties properties, Jar[] classpath)
      throws IOException, MojoFailureException, MojoExecutionException, Exception {
    Analyzer analyzer = getAnalyzer(project, instructions, properties, classpath);
    boolean hasErrors = reportErrors("Manifest " + project.getArtifact(), analyzer);
    if (hasErrors) {
      String failok = analyzer.getProperty("-failok");
      if (null == failok || "false".equalsIgnoreCase(failok)) {
        throw new MojoFailureException("Error(s) found in manifest configuration");
      }
    }

    Jar jar = analyzer.getJar();

    if (unpackBundle) {
      File outputFile = getOutputDirectory();
      for (Entry<String, Resource> entry : jar.getResources().entrySet()) {
        File entryFile = new File(outputFile, entry.getKey());
        if (!entryFile.exists() || entry.getValue().lastModified() == 0) {
          entryFile.getParentFile().mkdirs();
          OutputStream os = new FileOutputStream(entryFile);
          entry.getValue().write(os);
          os.close();
        }
      }
    }

    Manifest manifest = jar.getManifest();

    // cleanup...
    analyzer.close();

    return manifest;
  }