Ejemplo n.º 1
0
  /** {@inheritDoc} */
  protected ScmResult executeEditCommand(ScmProviderRepository repo, ScmFileSet files)
      throws ScmException {
    Commandline cl =
        createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), files);
    PerforceEditConsumer consumer = new PerforceEditConsumer();
    try {
      if (getLogger().isDebugEnabled()) {
        getLogger().debug(PerforceScmProvider.clean("Executing " + cl.toString()));
      }

      CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
      int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);

      if (exitCode != 0) {
        String cmdLine = CommandLineUtils.toString(cl.getCommandline());

        StringBuffer msg = new StringBuffer("Exit code: " + exitCode + " - " + err.getOutput());
        msg.append('\n');
        msg.append("Command line was:" + cmdLine);

        throw new CommandLineException(msg.toString());
      }
    } catch (CommandLineException e) {
      if (getLogger().isErrorEnabled()) {
        getLogger().error("CommandLineException " + e.getMessage(), e);
      }
    }

    if (consumer.isSuccess()) {
      return new EditScmResult(cl.toString(), consumer.getEdits());
    }

    return new EditScmResult(
        cl.toString(), "Unable to edit file(s)", consumer.getErrorMessage(), false);
  }
Ejemplo n.º 2
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());
    }
  }