use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.
the class JavadocUtil method getJavadocVersion.
/**
* Call the Javadoc tool and parse its output to find its version, i.e.:
* <pre>
* javadoc.exe(or .sh) -J-version
* </pre>
*
* @param javadocExe not null file
* @return the javadoc version as float
* @throws IOException if javadocExe is null, doesn't exist or is not a file
* @throws CommandLineException if any
* @throws IllegalArgumentException if no output was found in the command line
* @throws PatternSyntaxException if the output contains a syntax error in the regular-expression pattern.
* @see #parseJavadocVersion(String)
*/
protected static float getJavadocVersion(File javadocExe) throws IOException, CommandLineException, IllegalArgumentException {
if ((javadocExe == null) || (!javadocExe.exists()) || (!javadocExe.isFile())) {
throw new IOException("The javadoc executable '" + javadocExe + "' doesn't exist or is not a file. ");
}
Commandline cmd = new Commandline();
cmd.setExecutable(javadocExe.getAbsolutePath());
cmd.setWorkingDirectory(javadocExe.getParentFile());
cmd.createArg().setValue("-J-version");
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
if (exitCode != 0) {
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + CommandLineUtils.toString(cmd.getCommandline()));
throw new CommandLineException(msg.toString());
}
if (StringUtils.isNotEmpty(err.getOutput())) {
return parseJavadocVersion(err.getOutput());
} else if (StringUtils.isNotEmpty(out.getOutput())) {
return parseJavadocVersion(out.getOutput());
}
throw new IllegalArgumentException("No output found from the command line 'javadoc -J-version'");
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-plugins by apache.
the class AbstractJavadocMojo method executeJavadocCommandLine.
/**
* Execute the Javadoc command line
*
* @param cmd not null
* @param javadocOutputDirectory not null
* @throws MavenReportException if any errors occur
*/
private void executeJavadocCommandLine(Commandline cmd, File javadocOutputDirectory) throws MavenReportException {
if (getLog().isDebugEnabled()) {
// no quoted arguments
getLog().debug(CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", ""));
}
String cmdLine = null;
if (debug) {
cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
}
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer out = new CommandLineUtils.StringStreamConsumer();
try {
int exitCode = CommandLineUtils.executeCommandLine(cmd, out, err);
String output = (StringUtils.isEmpty(out.getOutput()) ? null : '\n' + out.getOutput().trim());
if (exitCode != 0) {
if (cmdLine == null) {
cmdLine = CommandLineUtils.toString(cmd.getCommandline()).replaceAll("'", "");
cmdLine = JavadocUtil.hideProxyPassword(cmdLine, settings);
}
writeDebugJavadocScript(cmdLine, javadocOutputDirectory);
if (StringUtils.isNotEmpty(output) && StringUtils.isEmpty(err.getOutput()) && isJavadocVMInitError(output)) {
throw new MavenReportException(output + '\n' + '\n' + JavadocUtil.ERROR_INIT_VM + '\n' + "Or, try to reduce the Java heap size for the Javadoc goal using " + "-Dminmemory=<size> and -Dmaxmemory=<size>." + '\n' + '\n' + "Command line was: " + cmdLine + '\n' + '\n' + "Refer to the generated Javadoc files in '" + javadocOutputDirectory + "' dir.\n");
}
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').append('\n');
msg.append("Refer to the generated Javadoc files in '").append(javadocOutputDirectory).append("' dir.\n");
throw new MavenReportException(msg.toString());
}
if (StringUtils.isNotEmpty(output)) {
getLog().info(output);
}
} catch (CommandLineException e) {
throw new MavenReportException("Unable to execute javadoc command: " + e.getMessage(), e);
}
if (StringUtils.isNotEmpty(err.getOutput()) && getLog().isWarnEnabled()) {
getLog().warn("Javadoc Warnings");
StringTokenizer token = new StringTokenizer(err.getOutput(), "\n");
while (token.hasMoreTokens()) {
String current = token.nextToken().trim();
getLog().warn(current);
}
}
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class CvsCommandUtils method isCvsNT.
public static boolean isCvsNT() throws ScmException {
Commandline cl = new Commandline();
cl.setExecutable("cvs");
cl.createArg().setValue("-v");
CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
try {
CommandLineUtils.executeCommandLine(cl, stdout, stderr);
} catch (CommandLineException e) {
throw new ScmException("Error while executing command.", e);
}
return stdout.getOutput().indexOf("CVSNT") >= 0;
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class TfsBlameCommand method executeBlameCommand.
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
Commandline cl = createCommandLine(workingDirectory.getBasedir(), filename);
TfsBlameConsumer consumer = new TfsBlameConsumer(getLogger());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new BlameScmResult(cl.toString(), "The tfs command failed.", stderr.getOutput(), false);
}
return new BlameScmResult(cl.toString(), consumer.getLines());
}
use of org.codehaus.plexus.util.cli.CommandLineException in project maven-scm by apache.
the class CvsExeAddCommand method executeCvsCommand.
/**
* {@inheritDoc}
*/
protected AddScmResult executeCvsCommand(Commandline cl, List<ScmFile> addedFiles) throws ScmException {
CommandLineUtils.StringStreamConsumer consumer = new CommandLineUtils.StringStreamConsumer();
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
int exitCode;
try {
exitCode = CommandLineUtils.executeCommandLine(cl, consumer, stderr);
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
// TODO: actually it may have partially succeeded - should we cvs update the files and parse "A " responses?
if (exitCode != 0) {
return new AddScmResult(cl.toString(), "The cvs command failed.", stderr.getOutput(), false);
}
return new AddScmResult(cl.toString(), addedFiles);
}
Aggregations