private void processJavaClass()

in maven-plugins/java2ws-plugin/src/main/java/org/apache/cxf/maven_plugin/Java2WSMojo.java [421:539]


    private void processJavaClass(List<String> args, String cp) throws MojoExecutionException {
        if (!fork) {
            try {
                CommandInterfaceUtils.commandCommonMain();
                JavaToWS j2w = new JavaToWS(args.toArray(new String[0]));
                j2w.run();
            } catch (OutOfMemoryError e) {
                getLog().debug(e);

                StringBuilder msg = new StringBuilder(128);
                msg.append(e.getMessage()).append('\n');
                msg.append("Try to run this goal using the <fork>true</fork> and "
                        + "<additionalJvmArgs>-Xms128m -Xmx128m</additionalJvmArgs> parameters.");
                throw new MojoExecutionException(msg.toString(), e);
            } catch (Throwable e) {
                getLog().debug(e);
                throw new MojoExecutionException(e.getMessage(), e);
            }
        } else {
            getLog().info("Running java2ws 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.addArguments(args.toArray(new String[0]));
            if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
                cmd.addEnvironment("CLASSPATH", cp);
            }

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

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

            int exitCode;
            try {
                exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
            } catch (CommandLineException e) {
                getLog().debug(e);
                StringBuilder msg = new StringBuilder(e.getMessage());
                if (!(fork && classpathAsEnvVar)) {
                    msg.append('\n');
                    msg.append("Try to run this goal using <fork>true</fork> and "
                            + "<classpathAsEnvVar>true</classpathAsEnvVar>.");
                }
                msg.append('\n');
                msg.append("Command line was: ").append(cmdLine).append('\n');
                if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
                    msg.append("   CLASSPATH env: ").append(cp).append('\n');
                }
                msg.append('\n');
                throw new MojoExecutionException(msg.toString(), e);
            }

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

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

                StringBuilder msg = new StringBuilder("\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');
                if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
                    msg.append("   CLASSPATH env: ").append(cp).append('\n');
                }
                msg.append('\n');

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

            if (StringUtils.isNotEmpty(err.getOutput()) && err.getOutput().contains("JavaToWS Error")) {
                StringBuilder msg = new StringBuilder();
                msg.append(err.getOutput());
                msg.append('\n');
                msg.append("Command line was: ").append(cmdLine).append('\n');
                if (classpathAsEnvVar && !StringUtils.isEmpty(cp)) {
                    msg.append("   CLASSPATH env: ").append(cp).append('\n');
                }
                msg.append('\n');
                throw new MojoExecutionException(msg.toString());
            }
        }

        // Attach the generated wsdl file to the artifacts that get deployed
        // with the enclosing project
        if (attachWsdl && outputFile != null) {
            File wsdlFile = new File(outputFile);
            if (wsdlFile.exists()) {
                
                
                boolean hasWsdlAttached = false;
                for (Artifact a : project.getAttachedArtifacts()) {
                    if ("wsdl".equals(a.getType()) && classifier != null && classifier.equals(a.getClassifier())) {
                        hasWsdlAttached = true;
                    }
                }
                if (!hasWsdlAttached) {
                    if (classifier != null) {
                        projectHelper.attachArtifact(project, wsdlFile.getName(), classifier, wsdlFile);
                    } else {
                        projectHelper.attachArtifact(project, wsdlFile.getName(), wsdlFile);
                    }
                }
            }
        }
    }