private void packageBundle() throws Exception {
    File jar = null;
    File outputDirectory = new File(project.getBuild().getOutputDirectory());
    if (projectJar != null && outputDirectory.exists()) {
      JarArchiver jarer = (JarArchiver) plexus.lookup(JarArchiver.ROLE, "jar");
      jar = new File(project.getBasedir(), jars + "/" + projectJar);
      jarer.setDestFile(jar);
      jarer.addDirectory(outputDirectory);
      jarer.createArchive();
    }

    // what is the right way of doing this?
    File file;
    //		if (PACKAGING_DIRECTORY_PLUGIN.equals(project.getPackaging())) {
    file = new File(buildTarget, project.getBuild().getFinalName() + ".jar");
    //		} else {
    //			file = new File(buildTarget, project.getArtifact().getArtifactId() + "-" +
    // project.getArtifact().getVersion());
    //		}

    JarArchiver archiver = (JarArchiver) plexus.lookup(JarArchiver.ROLE, "jar");
    archiver.setDestFile(file);

    File mfile = expandVersion(new File(project.getBasedir(), "META-INF/MANIFEST.MF"));

    archiver.setManifest(mfile);
    if (jar != null) {
      archiver.addFile(jar, jars + "/" + jar.getName());
    }
    for (Iterator i = getIncludedArtifacts().iterator(); i.hasNext(); ) {
      Artifact d = (Artifact) i.next();
      archiver.addFile(d.getFile(), jars + "/" + d.getFile().getName());
    }
    if (bundleClasspath != null) {
      for (int i = 0; i < bundleClasspath.length; i++) {
        archiver.addFile(new File(project.getBasedir(), bundleClasspath[i]), bundleClasspath[i]);
      }
    }
    archiver.createArchive();

    //    	if (PACKAGING_DIRECTORY_PLUGIN.equals(project.getArtifact().getType())) {
    project.getArtifact().setFile(file);
    //    	} else {
    //    		projectHelper.attachArtifact(project, TYPE_DIRECTORY_PLUGIN,
    // CLASSIFIER_DIRECTORY_PLUGIN, file);
    //    	}

  }
示例#2
0
  public void execute() throws MojoExecutionException {
    try {

      Library library = new Library(name);
      if (platform == null || platform.trim().length() == 0) {
        platform = library.getPlatform();
      }

      String packageName = project.getArtifactId() + "-" + project.getVersion() + "-" + platform;
      JarArchiver archiver = (JarArchiver) archiverManager.getArchiver("jar");

      File packageFile =
          new File(new File(project.getBuild().getDirectory()), packageName + ".jar");
      archiver.setDestFile(packageFile);
      archiver.setIncludeEmptyDirs(true);
      archiver.addDirectory(libDirectory);

      Manifest manifest = new Manifest();
      manifest.addConfiguredAttribute(
          new Attribute("Bundle-SymbolicName", project.getArtifactId() + "-" + platform));
      manifest.addConfiguredAttribute(new Attribute("Bundle-Name", name + " for " + platform));
      manifest.addConfiguredAttribute(
          new Attribute("Bundle-NativeCode", getNativeCodeValue(library)));
      manifest.addConfiguredAttribute(new Attribute("Bundle-Version", project.getVersion()));
      manifest.addConfiguredAttribute(new Attribute("Bundle-ManifestVersion", "2"));
      manifest.addConfiguredAttribute(
          new Attribute("Bundle-Description", project.getDescription()));
      archiver.addConfiguredManifest(manifest);

      archiver.createArchive();

      projectHelper.attachArtifact(project, "jar", platform, packageFile);

    } catch (Exception e) {
      throw new MojoExecutionException("packageing failed: " + e, e);
    }
  }