MSHARED-304 - Create a API for java tool
Simplify API ( move JavaToolResult contract to a simple Pojo )
git-svn-id: https://svn.apache.org/repos/asf/maven/shared/trunk@1551722 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
index 9577a88..8fb50f5 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaTool.java
@@ -38,9 +38,9 @@
* @author Tony Chemit <chemit@codelutin.com>
* @since 0.5
*/
-public abstract class AbstractJavaTool<Request extends JavaToolRequest, Result extends JavaToolResult>
+public abstract class AbstractJavaTool<Request extends JavaToolRequest>
extends AbstractLogEnabled
- implements JavaTool<Request, Result>
+ implements JavaTool<Request>
{
/**
@@ -74,8 +74,6 @@
protected abstract Commandline createCommandLine( Request request, String javaToolFile )
throws JavaToolException;
- protected abstract Result createResult();
-
/**
* {@inheritDoc}
*/
@@ -95,7 +93,7 @@
/**
* {@inheritDoc}
*/
- public Result execute( Request request )
+ public JavaToolResult execute( Request request )
throws JavaToolException
{
@@ -118,7 +116,7 @@
Commandline cli = createCommandLine( request, javaToolFile );
// execute it
- Result result = executeCommandLine( cli, request );
+ JavaToolResult result = executeCommandLine( cli, request );
// return result
return result;
@@ -141,14 +139,14 @@
return systemIn;
}
- protected Result executeCommandLine( Commandline cli, Request request )
+ protected JavaToolResult executeCommandLine( Commandline cli, Request request )
{
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Executing: " + cli );
}
- Result result = createResult();
+ JavaToolResult result = createResult();
result.setCommandline( cli );
@@ -218,6 +216,11 @@
return systemOut;
}
+ protected JavaToolResult createResult()
+ {
+ return new JavaToolResult();
+ }
+
protected String findJavaToolExecutable()
{
String command = javaToolName + ( Os.isFamily( Os.FAMILY_WINDOWS ) ? ".exe" : "" );
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaToolResult.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaToolResult.java
deleted file mode 100644
index 745b718..0000000
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/AbstractJavaToolResult.java
+++ /dev/null
@@ -1,97 +0,0 @@
-package org.apache.maven.shared.utils.cli.javatool;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.Commandline;
-
-/**
- * Abstract implementation of a {@link JavaToolResult}.
- *
- * @author Tony Chemit <chemit@codelutin.com>
- * @since 0.5
- */
-public abstract class AbstractJavaToolResult
- implements JavaToolResult
-{
- /**
- * The exception that prevented to execute the command line, will be <code>null</code> if jarSigner could be
- * successfully started.
- */
- private CommandLineException executionException;
-
- /**
- * The exit code reported by the Maven invocation.
- */
- private int exitCode = Integer.MIN_VALUE;
-
- /**
- * The command line used to obtain this result.
- */
- private Commandline commandline;
-
- /**
- * {@inheritDoc}
- */
- public int getExitCode()
- {
- return exitCode;
- }
-
- /**
- * {@inheritDoc}
- */
- public Commandline getCommandline()
- {
- return commandline;
- }
-
- /**
- * {@inheritDoc}
- */
- public CommandLineException getExecutionException()
- {
- return executionException;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setExitCode( int exitCode )
- {
- this.exitCode = exitCode;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setExecutionException( CommandLineException executionException )
- {
- this.executionException = executionException;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setCommandline( Commandline commandline )
- {
- this.commandline = commandline;
- }
-}
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
index 1027ee9..3870071 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaTool.java
@@ -33,14 +33,14 @@
* @author Tony Chemit <chemit@codelutin.com>
* @since 0.5
*/
-public interface JavaTool<Request extends JavaToolRequest, Result extends JavaToolResult>
+public interface JavaTool<Request extends JavaToolRequest>
{
/**
* Return the name of the java tool. This is exactly the name (without his extension) of the executable to
* find in the {@code jdk/bin} directory.
* <p/>
- * For example: {@code jarsigner, keytoll, javadoc, ...}
+ * For example: {@code jarsigner, keytool, javadoc, ...}
*
* @return the name of the java tool.
*/
@@ -58,13 +58,13 @@
* <p/>
* If could not create the java tool invocation, a {@link JavaToolException} will be thrown.
* <p/>
- * If execution fails, then the result will have a none-zero {@link Result#getExitCode()} and his
- * {@link Result#getExecutionException()} will be filled with the error, otherwise the exist code will be zero.
+ * If execution fails, then the result will have a none-zero {@link JavaToolResult#getExitCode()} and his
+ * {@link JavaToolResult#getExecutionException()} will be filled with the error, otherwise the exist code will be zero.
*
* @param request the request to perform
* @return the result of the tool execution
* @throws JavaToolException if could not create the java tool invocation
*/
- Result execute( Request request )
+ JavaToolResult execute( Request request )
throws JavaToolException;
}
diff --git a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolResult.java b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolResult.java
index 0b7855a..f3a6a77 100644
--- a/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolResult.java
+++ b/src/main/java/org/apache/maven/shared/utils/cli/javatool/JavaToolResult.java
@@ -28,22 +28,23 @@
* @author Tony Chemit <chemit@codelutin.com>
* @since 0.5
*/
-public interface JavaToolResult
+public class JavaToolResult
{
/**
- * Gets the command line used.
- *
- * @return The command line used
+ * The exception that prevented to execute the command line, will be <code>null</code> if jarSigner could be
+ * successfully started.
*/
- Commandline getCommandline();
+ private CommandLineException executionException;
/**
- * Gets the exception that possibly occurred during the execution of the command line.
- *
- * @return The exception that prevented to invoke tool or <code>null</code> if the command line was successfully
- * processed by the operating system.
+ * The exit code reported by the Maven invocation.
*/
- CommandLineException getExecutionException();
+ private int exitCode = Integer.MIN_VALUE;
+
+ /**
+ * The command line used to obtain this result.
+ */
+ private Commandline commandline;
/**
* Gets the exit code from the tool invocation. A non-zero value indicates a build failure. <strong>Note:</strong>
@@ -51,26 +52,59 @@
*
* @return The exit code from the tool invocation.
*/
- int getExitCode();
+ public int getExitCode()
+ {
+ return exitCode;
+ }
+
+ /**
+ * Gets the command line used.
+ *
+ * @return The command line used
+ */
+ public Commandline getCommandline()
+ {
+ return commandline;
+ }
+
+ /**
+ * Gets the exception that possibly occurred during the execution of the command line.
+ *
+ * @return The exception that prevented to invoke tool or <code>null</code> if the command line was successfully
+ * processed by the operating system.
+ */
+ public CommandLineException getExecutionException()
+ {
+ return executionException;
+ }
/**
* Sets the exit code reported by the tool invocation.
*
* @param exitCode The exit code reported by the tool invocation.
*/
- void setExitCode( int exitCode );
+ public void setExitCode( int exitCode )
+ {
+ this.exitCode = exitCode;
+ }
/**
* Sets the exception that prevented to execute the command line.
*
* @param executionException The exception that prevented to execute the command line, may be <code>null</code>.
*/
- void setExecutionException( CommandLineException executionException );
+ public void setExecutionException( CommandLineException executionException )
+ {
+ this.executionException = executionException;
+ }
/**
* Set the commandline used to obtain this result.
*
* @param commandline the commandline used to obtain this result
*/
- void setCommandline( Commandline commandline );
+ public void setCommandline( Commandline commandline )
+ {
+ this.commandline = commandline;
+ }
}