Пример #1
0
  protected void assertFileEquals(File location1, File location2) {
    String str1 = FileUtils.getStringFromFile(location1);
    String str2 = FileUtils.getStringFromFile(location2);

    StringTokenizer st1 = new StringTokenizer(str1, " \t\n\r\f(),");
    StringTokenizer st2 = new StringTokenizer(str2, " \t\n\r\f(),");

    // namespace declarations and wsdl message parts can be ordered
    // differently in the generated wsdl between the ibm and sun jdks.
    // So, when we encounter a mismatch, put the unmatched token in a
    // list and check this list when matching subsequent tokens.
    // It would be much better to do a proper xml comparison.
    List<String> unmatched = new ArrayList<String>();
    while (st1.hasMoreTokens()) {
      String tok1 = st1.nextToken();
      String tok2 = null;
      if (unmatched.contains(tok1)) {
        unmatched.remove(tok1);
        continue;
      }
      while (st2.hasMoreTokens()) {
        tok2 = st2.nextToken();

        if (tok1.equals(tok2)) {
          break;
        } else {
          unmatched.add(tok2);
        }
      }
      assertEquals(
          "Compare failed " + location1.getAbsolutePath() + " != " + location2.getAbsolutePath(),
          tok1,
          tok2);
    }

    assertTrue(!st1.hasMoreTokens());
    assertTrue(!st2.hasMoreTokens());
    assertTrue("Files did not match: " + unmatched, unmatched.isEmpty());
  }
Пример #2
0
 private String[] createForkOnceArgs(List<List<String>> wargs) throws MojoExecutionException {
   try {
     File f = FileUtils.createTempFile("cxf-w2j", "args");
     PrintWriter fw = new PrintWriter(new FileWriter(f));
     for (List<String> args : wargs) {
       fw.println(Integer.toString(args.size()));
       for (String s : args) {
         fw.println(s);
       }
     }
     fw.println("-1");
     fw.close();
     return new String[] {f.getAbsolutePath()};
   } catch (IOException ex) {
     throw new MojoExecutionException("Could not create argument file", ex);
   }
 }
Пример #3
0
  public String getStringFromFile(File location) {
    InputStream is = null;
    String result = null;

    try {
      is = new FileInputStream(location);
      result = FileUtils.normalizeCRLF(is);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (Exception e) {
          // do nothing
        }
      }
    }

    return result;
  }
Пример #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());
    }
  }