private void createClasspathJarFile(File lib) throws Exception {
   getLog().info("[WarSync] Create warsync-classpath.jar in " + lib.getAbsolutePath());
   List<String> jarFiles = new ArrayList<String>();
   if (artifacts != null && !artifacts.isEmpty()) {
     for (Artifact artifact : artifacts) {
       if (getLog().isDebugEnabled()) {
         getLog().debug("[WarSync] Found dependency: " + artifact.getId());
       }
       if (isLib(artifact)) {
         if (getLog().isDebugEnabled()) {
           getLog()
               .debug(
                   "[WarSync] Add "
                       + artifact.getFile().toURI().getPath()
                       + " to Class-Path entry of MANIFEST.MF");
         }
         jarFiles.add(artifact.getFile().toURI().getPath());
       }
     }
   }
   JarArchiver jar = new JarArchiver();
   jar.setDestFile(new File(lib, "warsync-classpath.jar"));
   Manifest manifest = Manifest.getDefaultManifest();
   manifest.addConfiguredAttribute(new Manifest.Attribute("Created-By", "maven-warsync-plugin"));
   manifest.addConfiguredAttribute(
       new Manifest.Attribute("Built-By", System.getProperty("user.name")));
   manifest.addConfiguredAttribute(
       new Manifest.Attribute("Build-Jdk", System.getProperty("java.version")));
   if (!jarFiles.isEmpty()) {
     manifest.addConfiguredAttribute(
         new Manifest.Attribute("Class-Path", StringUtils.join(jarFiles.iterator(), " ")));
   }
   jar.addConfiguredManifest(manifest);
   jar.createArchive();
 }
示例#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);
    }
  }
  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);
    //    	}

  }
示例#4
0
  private void runForked(Set<URI> classPath, Class<?> cls, String[] args)
      throws MojoExecutionException {
    getLog().info("Running wsdl2java in fork mode...");

    Commandline cmd = new Commandline();
    cmd.getShell().setQuotedArgumentsEnabled(true); // for JVM args
    cmd.setWorkingDirectory(project.getBuild().getDirectory());
    try {
      cmd.setExecutable(getJavaExecutable().getAbsolutePath());
    } catch (IOException e) {
      getLog().debug(e);
      throw new MojoExecutionException(e.getMessage(), e);
    }

    cmd.createArg().setLine(additionalJvmArgs);

    File file = null;
    try {
      // file = new File("/tmp/test.jar");
      file = FileUtils.createTempFile("cxf-codegen", ".jar");

      JarArchiver jar = new JarArchiver();
      jar.setDestFile(file.getAbsoluteFile());

      Manifest manifest = new Manifest();
      Attribute attr = new Attribute();
      attr.setName("Class-Path");
      StringBuilder b = new StringBuilder(8000);
      for (URI cp : classPath) {
        b.append(cp.toURL().toExternalForm()).append(' ');
      }
      attr.setValue(b.toString());
      manifest.getMainSection().addConfiguredAttribute(attr);

      attr = new Attribute();
      attr.setName("Main-Class");
      attr.setValue(cls.getName());
      manifest.getMainSection().addConfiguredAttribute(attr);

      jar.addConfiguredManifest(manifest);
      jar.createArchive();

      cmd.createArg().setValue("-jar");
      cmd.createArg().setValue(file.getAbsolutePath());

    } catch (Exception e1) {
      throw new MojoExecutionException("Could not create runtime jar", e1);
    }
    cmd.addArguments(args);

    CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
    CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();

    int exitCode;
    try {
      exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
    } catch (CommandLineException e) {
      getLog().debug(e);
      throw new MojoExecutionException(e.getMessage(), e);
    }

    String output = StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim();

    String cmdLine = CommandLineUtils.toString(cmd.getCommandline());

    if (exitCode != 0) {
      if (StringUtils.isNotEmpty(output)) {
        getLog().info(output);
      }

      StringBuffer msg = new StringBuffer("\nExit code: ");
      msg.append(exitCode);
      if (StringUtils.isNotEmpty(err.getOutput())) {
        msg.append(" - ").append(err.getOutput());
      }
      msg.append('\n');
      msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');

      throw new MojoExecutionException(msg.toString());
    }

    if (file != null) {
      file.delete();
    }
    if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("WSDL2Java Error")) {
      StringBuffer msg = new StringBuffer();
      msg.append(err.getOutput());
      msg.append('\n');
      msg.append("Command line was: ").append(cmdLine).append('\n').append('\n');
      throw new MojoExecutionException(msg.toString());
    }
  }