You are viewing a plain text version of this content. The canonical link for it is here.
Posted to npanday-commits@incubator.apache.org by lc...@apache.org on 2012/01/04 21:12:09 UTC
svn commit: r1227326 [1/2] - in /incubator/npanday/trunk: ./
components/dotnet-core/src/main/java/npanday/
components/dotnet-executable/src/main/java/npanday/executable/
components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/
compo...
Author: lcorneliussen
Date: Wed Jan 4 21:12:08 2012
New Revision: 1227326
URL: http://svn.apache.org/viewvc?rev=1227326&view=rev
Log:
[NPANDAY-509] CommandExecutor is confused with MSDeploy-style commandline switches starting with "-" and containing both ":" and "="
o implemented a better generic approach to quote-handling (supports /:, -:, /= and /:)
o configurable from compiler-plugins and executable-plugins (configured alternative -x:y="a b c" for MSDeploy)
o old classes are yet to be removed, after this is finalized
Added:
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ArgumentQuotingStrategy.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/UnifiedShellCommandExecutor.java
- copied, changed from r1226854, incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/PlexusUtilsCommandExecutor.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/CustomSwitchAwareQuotingStrategy.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/PlexusNativeQuotingStrategy.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedBourneShell.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCmdShell.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCommandShell.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ShellUtils.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/Switch.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/SwitchFormat.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultNetExecutable.java
- copied, changed from r1226709, incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CommonsExecNetExecutable.java
incubator/npanday/trunk/components/dotnet-executable/src/test/groovy/npanday/executable/execution/switches/
incubator/npanday/trunk/components/dotnet-executable/src/test/groovy/npanday/executable/execution/switches/SwitchFormatTest.groovy
Removed:
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CommonsExecNetExecutable.java
Modified:
incubator/npanday/trunk/components/dotnet-core/src/main/java/npanday/PathUtil.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/MutableExecutableCapability.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/NetExecutable.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/AspxCompiler.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/BaseCompiler.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/CSharpCompilerForProfile.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/DefaultCompiler.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerContextImpl.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerPluginsRepository.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutableContextImpl.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutablePluginsRepository.java
incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/RepositoryExecutableContextImpl.java
incubator/npanday/trunk/components/dotnet-executable/src/test/groovy/npanday/executable/execution/CommandExecutorTest.groovy
incubator/npanday/trunk/components/dotnet-model/compiler-plugins/compiler-plugins.mdo
incubator/npanday/trunk/components/dotnet-model/compiler-plugins/src/test/groovy/npanday/model/compiler/plugins/io/CompilerPluginXpp3ReaderTest.groovy
incubator/npanday/trunk/components/dotnet-model/compiler-plugins/src/test/resources/sample-compiler-plugins.xml
incubator/npanday/trunk/components/dotnet-model/executable-plugins/executable-plugins.mdo
incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/groovy/npanday/model/compiler/plugins/io/ExecutablePluginXpp3ReaderTest.groovy
incubator/npanday/trunk/components/dotnet-model/executable-plugins/src/test/resources/sample-executable-plugins.xml
incubator/npanday/trunk/components/dotnet-registry/src/main/java/npanday/registry/impl/WindowsRegistryValueSource.java
incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/java/npanday/plugin/azure/CreateCloudServicePackageMojo.java
incubator/npanday/trunk/plugins/azure-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
incubator/npanday/trunk/plugins/maven-test-plugin/src/main/java/npanday/plugin/test/TesterMojo.java
incubator/npanday/trunk/plugins/msdeploy-maven-plugin/src/main/java/npanday/plugin/msdeploy/MsDeployUnpackDependenciesMojo.java
incubator/npanday/trunk/plugins/msdeploy-maven-plugin/src/main/resources/META-INF/npanday/executable-plugins.xml
incubator/npanday/trunk/pom.xml
Modified: incubator/npanday/trunk/components/dotnet-core/src/main/java/npanday/PathUtil.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-core/src/main/java/npanday/PathUtil.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-core/src/main/java/npanday/PathUtil.java (original)
+++ incubator/npanday/trunk/components/dotnet-core/src/main/java/npanday/PathUtil.java Wed Jan 4 21:12:08 2012
@@ -26,6 +26,7 @@ import org.codehaus.plexus.util.FileUtil
import java.io.File;
import java.io.IOException;
+import java.util.Collection;
import java.util.logging.Logger;
/**
@@ -198,6 +199,28 @@ public final class PathUtil
return targetFile;
}
+ public static String getExecutable( String executable, Collection<String> executablePaths,
+ org.codehaus.plexus.logging.Logger logger )
+ {
+ if ( executablePaths != null && executablePaths.size() > 0 )
+ {
+ for ( String executablePath : executablePaths )
+ {
+ File executableFile = PathUtil.getExecutable( new File(executablePath), executable );
+ if ( executableFile != null )
+ {
+ logger.info(
+ "NPANDAY-126-001: Found executable file for " + executable + ": \"" + executableFile + "\""
+ );
+
+ return executableFile.getAbsolutePath();
+ }
+ }
+ }
+ logger.warn( "NPANDAY-126-002: Did not find path for " + executable + " in " + executablePaths );
+
+ return executable;
+ }
public static boolean containsExecutable(String executablePath, String executable) {
return (getExecutable(new File(executablePath), executable) != null);
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/CommandExecutor.java Wed Jan 4 21:12:08 2012
@@ -19,12 +19,18 @@ package npanday.executable;
* under the License.
*/
-import npanday.executable.execution.PlexusUtilsCommandExecutor;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Lists;
+import npanday.executable.execution.UnifiedShellCommandExecutor;
+import npanday.executable.execution.quoting.CustomSwitchAwareQuotingStrategy;
+import npanday.executable.execution.switches.SwitchFormat;
import org.codehaus.plexus.logging.Logger;
import java.io.File;
import java.util.List;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
/**
* Provides services for executing commands (executables or compilers). A <code>NetExecutable</code> or
@@ -118,13 +124,26 @@ public interface CommandExecutor
* Returns a default instance of the command executor
*
* @return a default instance of the command executor
+ * @param switchformats
*/
- public static CommandExecutor createDefaultCommmandExecutor()
+ public static CommandExecutor createDefaultCommmandExecutor( String switchformats )
{
- // TODO: at some point we should switch this one to CommonsExecCommandExecutor
- return new PlexusUtilsCommandExecutor();
+ if (isNullOrEmpty(switchformats))
+ return new UnifiedShellCommandExecutor( new CustomSwitchAwareQuotingStrategy() );
+ else
+ return new UnifiedShellCommandExecutor( new CustomSwitchAwareQuotingStrategy( parseSwitchFormats(switchformats)) );
}
+ static Splitter SPLIT_ON_PIPE = Splitter.on('|').trimResults().omitEmptyStrings();
+
+ private static SwitchFormat[] parseSwitchFormats( String switchformats )
+ {
+ List<SwitchFormat> list = Lists.newArrayList();
+ for(String format : SPLIT_ON_PIPE.split( switchformats )){
+ list.add( SwitchFormat.fromStringDefinition( format ) );
+ }
+ return list.toArray(new SwitchFormat[0]);
+ }
}
}
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/ExecutableCapability.java Wed Jan 4 21:12:08 2012
@@ -41,7 +41,8 @@ public interface ExecutableCapability
/**
* Returns the command options that the executable is capable of supporting.
*
- * @return the command capability that the executable is capable of supporting. This capability is used to determine
+ * @return the command capability that the executable is capable of supporting. This capability is used to
+ * determine
* the command line parameters that the executable supports.
*/
CommandCapability getCommandCapability();
@@ -109,6 +110,13 @@ public interface ExecutableCapability
String getPluginClassName();
/**
+ * The user-defined configuration for this plugin.
+ *
+ * @return
+ */
+ java.util.Properties getPluginConfiguration();
+
+ /**
* Returns the net dependency id (within the net-dependencies.xml file).
*
* @return the net dependency id
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/MutableExecutableCapability.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/MutableExecutableCapability.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/MutableExecutableCapability.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/MutableExecutableCapability.java Wed Jan 4 21:12:08 2012
@@ -27,6 +27,7 @@ import javax.annotation.Nullable;
import java.io.File;
import java.util.Collections;
import java.util.List;
+import java.util.Properties;
import static com.google.common.base.Preconditions.checkNotNull;
@@ -47,6 +48,8 @@ public class MutableExecutableCapability
protected String pluginClassName;
+ protected Properties pluginConfiguration;
+
private String executable;
private String executableVersion;
@@ -153,6 +156,16 @@ public class MutableExecutableCapability
this.pluginClassName = pluginClassName;
}
+ public Properties getPluginConfiguration()
+ {
+ return pluginConfiguration;
+ }
+
+ public void setPluginConfiguration( Properties pluginConfiguration )
+ {
+ this.pluginConfiguration = pluginConfiguration;
+ }
+
public CommandCapability getCommandCapability()
{
return commandCapability;
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/NetExecutable.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/NetExecutable.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/NetExecutable.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/NetExecutable.java Wed Jan 4 21:12:08 2012
@@ -24,6 +24,7 @@ import npanday.PlatformUnsupportedExcept
import npanday.vendor.Vendor;
import java.util.List;
+import java.util.Properties;
/**
* Provides services for executing programs.
@@ -58,8 +59,9 @@ public interface NetExecutable
* Initialize this executable.
*
* @param npandayContext
+ * @param properties
*/
- void init( NPandayContext npandayContext );
+ void init( NPandayContext npandayContext, Properties properties );
/**
* Returns vendor framework used to run executable.
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/AspxCompiler.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/AspxCompiler.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/AspxCompiler.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/AspxCompiler.java Wed Jan 4 21:12:08 2012
@@ -66,9 +66,11 @@ public class AspxCompiler
+ compilerContext.getVendor() + ", Language = "
+ compilerContext.getArtifact().getAbsolutePath() );
- CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor();
+ CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor(
+ (String)configuration.get( "switchformats" )
+ );
commandExecutor.setLogger( logger );
- commandExecutor.executeCommand( getExecutable(), getCommands(), getExecutionPath(), failOnErrorOutput() );
+ commandExecutor.executeCommand( getExecutable(), getCommands(), null, failOnErrorOutput() );
}
}
\ No newline at end of file
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/BaseCompiler.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/BaseCompiler.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/BaseCompiler.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/BaseCompiler.java Wed Jan 4 21:12:08 2012
@@ -32,6 +32,7 @@ import org.codehaus.plexus.logging.Logge
import java.io.File;
import java.util.Collection;
+import java.util.Properties;
/**
* Provides an implementation of the compiler executable.
@@ -39,7 +40,8 @@ import java.util.Collection;
* @author Shane Isbell
*/
//TODO: Describe how this class should be extended
-abstract class BaseCompiler implements CompilerExecutable
+abstract class BaseCompiler
+ implements CompilerExecutable
{
/**
* The context that the compiler implementation can use to obtain information to customize the compile.
@@ -51,11 +53,14 @@ abstract class BaseCompiler implements C
*/
protected Logger logger;
+ protected Properties configuration;
+
/**
* This method may be overridden if the developer needs to create a profile of one of the other compilers.
*/
- public void init( NPandayContext npandayContext )
+ public void init( NPandayContext npandayContext, Properties properties )
{
+ configuration = properties;
this.compilerContext = (CompilerContext) npandayContext;
this.logger = npandayContext.getLogger();
}
@@ -79,17 +84,12 @@ abstract class BaseCompiler implements C
/**
* @see npanday.executable.compiler.CompilerExecutable#getCompiledArtifact()
*/
- public File getCompiledArtifact()
- throws InvalidArtifactException
+ public File getCompiledArtifact() throws InvalidArtifactException
{
return compilerContext.getArtifact();
}
- /**
- * @see npanday.executable.compiler.CompilerExecutable#getExecutable()
- */
- public String getExecutable()
- throws ExecutionException
+ public String getExecutable() throws ExecutionException
{
if ( compilerContext == null )
{
@@ -99,57 +99,34 @@ abstract class BaseCompiler implements C
}
/**
- * @see npanday.executable.compiler.CompilerExecutable#getExecutionPath()
- */
- public File getExecutionPath()
- {
- String executable;
- try
- {
- executable = getExecutable();
- }
- catch ( ExecutionException e )
- {
- return null;
- }
- Collection<String> executablePaths = compilerContext.getProbingPaths();
- if ( executablePaths != null )
- {
- for ( String executablePath : executablePaths )
- {
- if ( PathUtil.containsExecutable(executablePath, executable) )
- {
- logger.info("NPANDAY-068-005: Found executable path for " + executable + ": " + executablePath);
- return new File(executablePath);
- }
- }
- }
- logger.warn("NPANDAY-068-006: Did not find path for " + executable + " in " + executablePaths);
- return null;
- }
-
- /**
* @see npanday.executable.compiler.CompilerExecutable#execute()
*/
public void execute() throws ExecutionException, PlatformUnsupportedException
{
- if (compilerContext.getIncludeSources() ==null && !( new File( compilerContext.getSourceDirectoryName() ).exists() ) )
+ if ( compilerContext.getIncludeSources() == null && !(
+ new File(
+ compilerContext.getSourceDirectoryName()
+ ).exists()
+ ) )
{
logger.info( "NPANDAY-068-002: No source files to compile." );
return;
}
- logger.info( "NPANDAY-068-003: Compiling Artifact: Vendor = " +
- compilerContext.getVendor() + ", Language = " +
- compilerContext.getVendor() + ", Assembly Name = " +
- compilerContext.getArtifact().getAbsolutePath() );
-
- // commands are executed relative to working directory in Windows, but not all platforms
- File executionPath = getExecutionPath();
- String executable = new File(executionPath, getExecutable()).toString();
+ logger.info(
+ "NPANDAY-068-003: Compiling Artifact: Vendor = " + compilerContext.getVendor() + ", Language = "
+ + compilerContext.getVendor() + ", Assembly Name = " + compilerContext.getArtifact().getAbsolutePath()
+ );
+
+ String executable = getExecutable();
+ Collection<String> executablePaths = compilerContext.getProbingPaths();
- CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor();
+ CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor(
+ (String)configuration.get( "switchformats" )
+ );
commandExecutor.setLogger( logger );
- commandExecutor.executeCommand( executable, getCommands(), executionPath, failOnErrorOutput() );
+ commandExecutor.executeCommand(
+ PathUtil.getExecutable( executable, executablePaths, logger ), getCommands(), null, failOnErrorOutput()
+ );
}
public Vendor getVendor()
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/CSharpCompilerForProfile.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/CSharpCompilerForProfile.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/CSharpCompilerForProfile.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/CSharpCompilerForProfile.java Wed Jan 4 21:12:08 2012
@@ -19,14 +19,15 @@ package npanday.executable.compiler.impl
* under the License.
*/
+import npanday.NPandayContext;
import npanday.PlatformUnsupportedException;
-import npanday.executable.compiler.CompilerExecutable;
import npanday.executable.ExecutionException;
-import npanday.NPandayContext;
import npanday.executable.compiler.CompilerContext;
+import npanday.executable.compiler.CompilerExecutable;
-import java.util.List;
import java.io.File;
+import java.util.List;
+import java.util.Properties;
/**
* A compiler to be used for compiling with .NET Profiles.
@@ -44,10 +45,10 @@ public final class CSharpCompilerForProf
netCompiler = new DefaultCompiler();
}
- public void init( NPandayContext npandayContext )
+ public void init( NPandayContext npandayContext, Properties properties )
{
- super.init( npandayContext);
- netCompiler.init( npandayContext );
+ super.init( npandayContext, properties );
+ netCompiler.init( npandayContext, properties );
this.compilerContext = (CompilerContext) npandayContext;
}
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/DefaultCompiler.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/DefaultCompiler.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/DefaultCompiler.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/compiler/impl/DefaultCompiler.java Wed Jan 4 21:12:08 2012
@@ -22,6 +22,7 @@ package npanday.executable.compiler.impl
import npanday.PlatformUnsupportedException;
import npanday.executable.CommandFilter;
import npanday.executable.ExecutionException;
+import npanday.executable.execution.quoting.CustomSwitchAwareQuotingStrategy;
import npanday.vendor.Vendor;
import org.apache.maven.artifact.Artifact;
import org.codehaus.plexus.util.FileUtils;
@@ -41,6 +42,14 @@ import java.util.List;
public final class DefaultCompiler
extends BaseCompiler
{
+ CustomSwitchAwareQuotingStrategy strategy;
+
+ public DefaultCompiler(){
+ // TODO: move this to xml-configuration??
+ strategy = new CustomSwitchAwareQuotingStrategy();
+ strategy.addQuoteNormally("resource");
+ }
+
public boolean failOnErrorOutput()
{
//MONO writes warnings to standard error: this turns off failing builds on warnings for MONO
@@ -78,9 +87,9 @@ public final class DefaultCompiler
{
artifactFilePath = artifactFilePath.substring(0, artifactFilePath.length() - 3) + "dll";
}
-
+
commands.add( "/out:" + artifactFilePath);
-
+
commands.add( "/target:" + targetArtifactType );
if(compilerContext.getIncludeSources() == null || compilerContext.getIncludeSources().isEmpty() )
@@ -104,11 +113,11 @@ public final class DefaultCompiler
}
if ( !references.isEmpty() )
{
-
+
for ( Artifact artifact : references )
{
String path = artifact.getFile().getAbsolutePath();
-
+
if( !path.contains( ".jar" ) )
{
commands.add( "/reference:" + path );
@@ -117,11 +126,11 @@ public final class DefaultCompiler
}
for ( String arg : compilerContext.getEmbeddedResourceArgs() )
{
- if (logger.isDebugEnabled())
+ if (logger.isDebugEnabled())
{
logger.debug( "NPANDAY-168-001 add resource: " + arg );
}
-
+
commands.add( "/resource:" + arg );
}
for ( File file : compilerContext.getLinkedResources() )
@@ -181,9 +190,9 @@ public final class DefaultCompiler
{
String frameworkPath = System.getenv( "SystemRoot" ) + "\\Microsoft.NET\\Framework\\v4.0.30319\\";
//TODO: This is a hard-coded path: Don't have a registry value either.
- List<String> libraryNames = Arrays.asList("Microsoft.Build.Tasks.v4.0.dll",
+ List<String> libraryNames = Arrays.asList("Microsoft.Build.Tasks.v4.0.dll",
"Microsoft.Data.Entity.Build.Tasks.dll", "Microsoft.VisualC.STLCLR.dll");
- for (String libraryName : libraryNames)
+ for (String libraryName : libraryNames)
{
String libraryFullName = frameworkPath + libraryName;
if (new File( libraryFullName ).exists())
@@ -191,7 +200,7 @@ public final class DefaultCompiler
commands.add( "/reference:" + libraryFullName );
}
}
- }
+ }
if ( compilerContext.getKeyInfo().getKeyFileUri() != null )
{
commands.add( "/keyfile:" + compilerContext.getKeyInfo().getKeyFileUri() );
@@ -228,26 +237,27 @@ public final class DefaultCompiler
}
if ( !compilerContext.isTestCompile() )
{
+ // TODO: choose a better name for comments-xml and attach as artifact
commands.add(
"/doc:" + new File( compilerContext.getTargetDirectory(), "comments.xml" ).getAbsolutePath() );
}
CommandFilter filter = compilerContext.getCommandFilter();
-
+
List<String> filteredCommands = filter.filter( commands );
//Include Sources code is being copied to temporary folder for the recurse option
-
+
String fileExt = "";
String frameWorkVer = ""+compilerContext.getFrameworkVersion();
String TempDir = "";
String targetDir = ""+compilerContext.getTargetDirectory();
-
+
Date date = new Date();
String Now =""+date.getDate()+date.getHours()+date.getMinutes()+date.getSeconds();
// TODO: Why can't the tmp dir just be a static one?
TempDir = targetDir+File.separator+Now;
-
+
try
{
FileUtils.deleteDirectory( TempDir );
@@ -256,8 +266,8 @@ public final class DefaultCompiler
{
//Does Precautionary delete for tempDir
}
-
- FileUtils.mkdir(TempDir);
+
+ FileUtils.mkdir(TempDir);
// TODO: move includeSources expansion to the compiler context (handle excludes there)
if(compilerContext.getIncludeSources() != null && !compilerContext.getIncludeSources().isEmpty() )
@@ -265,28 +275,28 @@ public final class DefaultCompiler
int folderCtr=0;
for(String includeSource : compilerContext.getIncludeSources())
{
-
+
String[] sourceTokens = includeSource.replace('\\', '/').split("/");
-
+
String lastToken = sourceTokens[sourceTokens.length-1];
-
+
if(fileExt=="")
{
-
+
String[] extToken = lastToken.split( "\\." );
fileExt = "."+extToken[extToken.length-1];
}
-
+
try
{
String fileToCheck = TempDir+File.separator+lastToken;
if(FileUtils.fileExists( fileToCheck ))
{
- String subTempDir = TempDir+File.separator+folderCtr+File.separator;
+ String subTempDir = TempDir+File.separator+folderCtr+File.separator;
FileUtils.mkdir( subTempDir );
FileUtils.copyFileToDirectory( includeSource, subTempDir);
folderCtr++;
-
+
}
else
{
@@ -302,7 +312,7 @@ public final class DefaultCompiler
}
String recurseCmd = "/recurse:" + TempDir+File.separator + "*" + fileExt + "";
filteredCommands.add(recurseCmd);
-
+
}
if ( logger.isDebugEnabled() )
{
@@ -320,13 +330,9 @@ public final class DefaultCompiler
}
filteredCommands.clear();
responseFilePath = "@" + responseFilePath;
- if ( responseFilePath.indexOf( " " ) > 0)
- {
- responseFilePath = "\"" + responseFilePath + "\"";
- }
filteredCommands.add( responseFilePath );
-
+
return filteredCommands;
}
@@ -334,28 +340,7 @@ public final class DefaultCompiler
// Eg. /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Windows\",PLATFORM=\"AnyCPU\""
private String escapeCmdParams(String param)
{
- if(param == null)
- return null;
-
- String str = param;
- if((param.startsWith("/") || param.startsWith("@")) && param.indexOf(":") > 0)
- {
- int delem = param.indexOf(":") + 1;
- String command = param.substring(0, delem);
- String value = param.substring(delem);
-
- if(value.indexOf(" ") > 0 || value.indexOf("\"") > 0)
- {
- value = "\"" + value.replaceAll("\"", "\\\\\"") + "\"";
- }
-
- str = command + value;
- }
- else if(param.indexOf(" ") > 0)
- {
- str = "\"" + param + "\"";
- }
-
- return str;
+ // /resource:"path","more" doesn't work
+ return strategy.quoteAndEscape( param, '\"', new char[]{'\"'}, new char[]{' '}, '\\', false);
}
}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ArgumentQuotingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ArgumentQuotingStrategy.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ArgumentQuotingStrategy.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/ArgumentQuotingStrategy.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution;
+
+/**
+ * Interface for the various implementations of commandline argument quoting.
+ * <i>Workaround for https://jira.codehaus.org/browse/PLXUTILS-147</i>
+ *
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public interface ArgumentQuotingStrategy
+{
+ /**
+ * Possibility to intercept the quoting mechanisms.
+ *
+ * @param source the unescaped/unquoted argument
+ * @return the escaped and quoted argument
+ */
+ String quoteAndEscape(
+ String source, char quoteChar, final char[] escapedChars, final char[] quotingTriggers, char escapeChar,
+ boolean force );
+}
Copied: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/UnifiedShellCommandExecutor.java (from r1226854, incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/PlexusUtilsCommandExecutor.java)
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/UnifiedShellCommandExecutor.java?p2=incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/UnifiedShellCommandExecutor.java&p1=incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/PlexusUtilsCommandExecutor.java&r1=1226854&r2=1227326&rev=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/PlexusUtilsCommandExecutor.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/UnifiedShellCommandExecutor.java Wed Jan 4 21:12:08 2012
@@ -1,5 +1,3 @@
-package npanday.executable.execution;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -19,24 +17,61 @@ package npanday.executable.execution;
* under the License.
*/
-import npanday.PathUtil;
+package npanday.executable.execution;
+
import npanday.executable.ExecutionException;
+import npanday.executable.execution.shells.ExtendedBourneShell;
+import npanday.executable.execution.shells.ExtendedCmdShell;
+import npanday.executable.execution.shells.ExtendedCommandShell;
+import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.StreamConsumer;
+import org.codehaus.plexus.util.cli.shell.Shell;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
- * @author Shane Isbell
+ * A new unified approach to shell execution introduced in NPanday 1.5.0.
+ *
+ * <h2>Design considerations</h2>
+ * <ul>
+ * <li>In previous versions (< 1.5.0) the working directory was misused as the place
+ * where the executable live. That lead to various problems.<br/>
+ * Now, if we can locate the executable, it will be referenced to in an absolute way.
+ * The working directory can then be used for what it should be.</li>
+ * <li><b>Escaping strategies:</b> We need understand the commandline in order to choose the
+ * correct quoting/quoting.</li>
+ * </ul>
+ *
+ * <h2>Considered Issues</h2>
+ * <ul>
+ * <li><a href="https://issues.apache.org/jira/browse/NPANDAY-409">NPANDAY-409: Executable path ignored during
+ * command execution while building NPanday on Linux</a></li>
+ * <li><a href="https://issues.apache.org/jira/browse/NPANDAY-509">NPANDAY-509: CommandExecutor is confused with
+ * MSDeploy-style commandline switches starting with "-" and containing both ":" and "="</a></li>
+ * <li><a href="https://issues.apache.org/jira/browse/NPANDAY-341">NPANDAY-341: command execution fails if paths with
+ * space</a></li>
+ * <li><a href="https://issues.apache.org/jira/browse/NPANDAY-500">NPANDAY-500: potential compilation failures if
+ * path contains a space</a></li>
+ * <li><a href="https://issues.apache.org/jira/browse/NPANDAY-341">NPANDAY-341: command execution fails if paths with
+ * space </a></li>
+ * </ul>
+ *
* @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
*/
-public class PlexusUtilsCommandExecutor
+public class UnifiedShellCommandExecutor
extends CommandExecutorSkeleton
{
+ private ArgumentQuotingStrategy quotingStrategy;
+
+ public UnifiedShellCommandExecutor(ArgumentQuotingStrategy quotingStrategy){
+
+ this.quotingStrategy = quotingStrategy;
+ }
/**
* Standard Out
@@ -55,8 +90,8 @@ public class PlexusUtilsCommandExecutor
@Override
public void executeCommand(
- String executable, List<String> commands, File workingDirectory, boolean failsOnErrorOutput ) throws
- ExecutionException
+ String executable, List<String> commands, File workingDirectory, boolean failsOnErrorOutput )
+ throws ExecutionException
{
if ( commands == null )
{
@@ -65,41 +100,21 @@ public class PlexusUtilsCommandExecutor
stdOut = new StandardStreamConsumer( getLogger() );
stdErr = new ErrorStreamConsumer( getLogger() );
- Commandline commandline = new CustomPlexusUtilsCommandline();
-
- // NPANDAY-409
- // On non-Windows platforms, such as Linux, "gmcs" not resolved
- // to gmcs.exe in working directory due to /usr/bin/gmcs
- // but "./gmcs.exe" resolved as desired in working directory
- String osName = System.getProperty( "os.name" );
- if ( !osName.toLowerCase().contains( "win" ) )
- {
- File executableFile = PathUtil.getExecutable( workingDirectory, executable );
- // do not prefix for internal commands, such as mkdir
- if ( executableFile != null && workingDirectory.equals( executableFile.getParentFile() ) )
- {
- executable = new File( "./", executableFile.getName() ).toString();
- }
- }
+ Commandline commandline = new Commandline( getExtendedShell());
commandline.setExecutable( executable );
commandline.addArguments( commands.toArray( new String[commands.size()] ) );
- if ( workingDirectory != null && workingDirectory.exists() )
+ if ( workingDirectory != null )
{
- // TODO: Wrong use of working directory! $(basedir) should be the working dir,
- // and the executable paths should be absolute
commandline.setWorkingDirectory( workingDirectory.getAbsolutePath() );
}
- else if ( workingDirectory != null && !workingDirectory.exists() )
- {
- getLogger().info(
- "NPANDAY-040-006: Did not find executable path for " + executable + ", " + "will try system path"
- );
- }
+ boolean done = false;
try
{
+ getLogger().info( " +--[ RUNNING: " + commandline.toString() + "]");
+
result = CommandLineUtils.executeCommandLine( commandline, stdOut, stdErr );
getLogger().debug(
"NPANDAY-040-005: Executed command: Commandline = " + commandline + ", Result = " + result
@@ -111,6 +126,9 @@ public class PlexusUtilsCommandExecutor
"NPANDAY-040-001: Could not execute: Command = " + commandline.toString() + ", Result = " + result
);
}
+
+ getLogger().info( " +--[ DONE ]");
+ done = true;
}
catch ( CommandLineException e )
{
@@ -118,6 +136,33 @@ public class PlexusUtilsCommandExecutor
"NPANDAY-040-002: Could not execute: Command = " + commandline.toString(), e
);
}
+ finally {
+ if(!done){
+ getLogger().info( " +--[ FAILED! ]");
+ }
+ }
+ }
+
+ private Shell getExtendedShell()
+ {
+ // Workaround for https://jira.codehaus.org/browse/PLXUTILS-147
+
+ //If this is windows set the shell to command.com or cmd.exe with correct arguments.
+ if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+ {
+ if ( Os.isFamily( Os.FAMILY_WIN9X ) )
+ {
+ return new ExtendedCommandShell(quotingStrategy);
+ }
+ else
+ {
+ return new ExtendedCmdShell(quotingStrategy);
+ }
+ }
+ else
+ {
+ return new ExtendedBourneShell(quotingStrategy);
+ }
}
public int getResult()
@@ -134,5 +179,4 @@ public class PlexusUtilsCommandExecutor
{
return stdErr.toString();
}
-
}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/CustomSwitchAwareQuotingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/CustomSwitchAwareQuotingStrategy.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/CustomSwitchAwareQuotingStrategy.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/CustomSwitchAwareQuotingStrategy.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,148 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.quoting;
+
+import com.google.common.collect.Lists;
+import npanday.executable.execution.ArgumentQuotingStrategy;
+import npanday.executable.execution.switches.Switch;
+import npanday.executable.execution.switches.SwitchFormat;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class CustomSwitchAwareQuotingStrategy
+ implements ArgumentQuotingStrategy
+{
+ /**
+ * Switches that shouldn't be escaped at all
+ */
+ List<String> ignores = Lists.newArrayList();
+
+ /**
+ * Switches that should be quoted normally (as if it wasn't a switch)
+ */
+ List<String> quoteNormally = Lists.newArrayList();
+
+ SwitchFormat[] supportedSwitchFormats = {
+ new SwitchFormat( '/', '=' ), new SwitchFormat( '-', '=' ), new SwitchFormat( '/', ':' ),
+ new SwitchFormat( '-', ':' )
+ };
+
+ public CustomSwitchAwareQuotingStrategy( )
+ {
+
+ }
+
+ public CustomSwitchAwareQuotingStrategy( SwitchFormat[] switchFormats )
+ {
+ supportedSwitchFormats = switchFormats;
+ }
+
+ public String quoteAndEscape(
+ String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force )
+ {
+ for ( SwitchFormat format : supportedSwitchFormats )
+ {
+ if ( format.isMatchingSwitch( source ) )
+ {
+ Switch parsed = format.parse( source );
+
+ if (ignores.contains( parsed.getName() )){
+ return source;
+ }
+
+ if (quoteNormally.contains( parsed.getName() )){
+ return innerQuoteAndEscape( source, quoteChar, escapedChars, quotingTriggers, escapeChar, force );
+ }
+
+ return format.generate(
+ parsed.getName(),
+ innerQuoteAndEscape(
+ parsed.getValue(), quoteChar, escapedChars, quotingTriggers, escapeChar, force
+ )
+ );
+ }
+ }
+
+ return innerQuoteAndEscape( source, quoteChar, escapedChars, quotingTriggers, escapeChar, force );
+ }
+
+
+ private String innerQuoteAndEscape( String source,
+ char quoteChar,
+ final char[] escapedChars,
+ final char[] quotingTriggers,
+ char escapeChar,
+ boolean force )
+ {
+ // based on org.codehaus.plexus.util.StringUtils.quoteAndEscape()
+ // but does also escape quotes, if they are leading + trailing
+ // hence, "a" becomes "\"a\""
+
+ if ( source == null )
+ {
+ return null;
+ }
+
+ String escaped = StringUtils.escape( source, escapedChars, escapeChar );
+
+ boolean quote = false;
+ if ( force )
+ {
+ quote = true;
+ }
+ else if ( !escaped.equals( source ) )
+ {
+ quote = true;
+ }
+ else
+ {
+ for ( int i = 0; i < quotingTriggers.length; i++ )
+ {
+ if ( escaped.indexOf( quotingTriggers[i] ) > -1 )
+ {
+ quote = true;
+ break;
+ }
+ }
+ }
+
+ if ( quote )
+ {
+ return quoteChar + escaped + quoteChar;
+ }
+
+ return escaped;
+ }
+
+ public void addIgnore( String switchName )
+ {
+ ignores.add( switchName );
+ }
+
+ public void addQuoteNormally( String switchName )
+ {
+ quoteNormally.add( switchName );
+ }
+}
+
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/PlexusNativeQuotingStrategy.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/PlexusNativeQuotingStrategy.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/PlexusNativeQuotingStrategy.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/quoting/PlexusNativeQuotingStrategy.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.quoting;
+
+import npanday.executable.execution.ArgumentQuotingStrategy;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class PlexusNativeQuotingStrategy
+ implements ArgumentQuotingStrategy
+{
+ public String quoteAndEscape(
+ String source, char quoteChar, char[] escapedChars, char[] quotingTriggers, char escapeChar, boolean force )
+ {
+ return StringUtils.quoteAndEscape( source, quoteChar, escapedChars, quotingTriggers, escapeChar, force );
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedBourneShell.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedBourneShell.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedBourneShell.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedBourneShell.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.shells;
+
+import npanday.executable.execution.ArgumentQuotingStrategy;
+import org.codehaus.plexus.util.cli.shell.BourneShell;
+
+import java.util.List;
+
+/**
+ * <i>Workaround for https://jira.codehaus.org/browse/PLXUTILS-147</i>
+ *
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class ExtendedBourneShell
+ extends BourneShell
+{
+ private ArgumentQuotingStrategy quotingStrategy;
+
+ public ExtendedBourneShell( ArgumentQuotingStrategy quotingStrategy )
+ {
+ this.quotingStrategy = quotingStrategy;
+ }
+
+ @Override
+ protected List getRawCommandLine( String executable, String[] arguments )
+ {
+ char[] executableEscapeChars = getEscapeChars(
+ isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped()
+ );
+
+ char[] argumentEscapeChars = getEscapeChars(
+ isSingleQuotedArgumentEscaped(), isDoubleQuotedArgumentEscaped()
+ );
+
+ return ShellUtils.buildCommandLine(
+ quotingStrategy, executable, arguments,
+ /* executable modification */
+ getExecutionPreamble(), isQuotedExecutableEnabled(), executableEscapeChars, getExecutableQuoteDelimiter(),
+ /* arguments modification */
+ isQuotedArgumentsEnabled(), argumentEscapeChars, getArgumentQuoteDelimiter(), getQuotingTriggerChars()
+ );
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCmdShell.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCmdShell.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCmdShell.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCmdShell.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.shells;
+
+import npanday.executable.execution.ArgumentQuotingStrategy;
+import org.codehaus.plexus.util.cli.shell.CmdShell;
+
+import java.util.List;
+
+/**
+ * <i>Workaround for https://jira.codehaus.org/browse/PLXUTILS-147</i>
+ *
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class ExtendedCmdShell
+ extends CmdShell
+{
+ private ArgumentQuotingStrategy quotingStrategy;
+
+ public ExtendedCmdShell( ArgumentQuotingStrategy quotingStrategy )
+ {
+ this.quotingStrategy = quotingStrategy;
+
+ // is turned off by default for CmdShell
+ setDoubleQuotedArgumentEscaped( true );
+ }
+
+ @Override
+ protected List getRawCommandLine( String executable, String[] arguments )
+ {
+ char[] executableEscapeChars = getEscapeChars(
+ isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped()
+ );
+
+ char[] argumentEscapeChars = getEscapeChars(
+ isSingleQuotedArgumentEscaped(), isDoubleQuotedArgumentEscaped()
+ );
+
+ return ShellUtils.buildCommandLine(
+ quotingStrategy, executable, arguments,
+ /* executable modification */
+ getExecutionPreamble(), isQuotedExecutableEnabled(), executableEscapeChars, getExecutableQuoteDelimiter(),
+ /* arguments modification */
+ isQuotedArgumentsEnabled(), argumentEscapeChars, getArgumentQuoteDelimiter(), getQuotingTriggerChars()
+ );
+ }
+}
+
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCommandShell.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCommandShell.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCommandShell.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ExtendedCommandShell.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.shells;
+
+import npanday.executable.execution.ArgumentQuotingStrategy;
+import org.codehaus.plexus.util.cli.shell.CommandShell;
+
+import java.util.List;
+
+/**
+ * <i>Workaround for https://jira.codehaus.org/browse/PLXUTILS-147</i>
+ *
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class ExtendedCommandShell
+ extends CommandShell
+{
+ private ArgumentQuotingStrategy quotingStrategy;
+
+ public ExtendedCommandShell( ArgumentQuotingStrategy quotingStrategy )
+ {
+ this.quotingStrategy = quotingStrategy;
+
+ // is turned off by default for CommandShell
+ setDoubleQuotedArgumentEscaped( true );
+ }
+
+ @Override
+ protected List getRawCommandLine( String executable, String[] arguments )
+ {
+ char[] executableEscapeChars = getEscapeChars(
+ isSingleQuotedExecutableEscaped(), isDoubleQuotedExecutableEscaped()
+ );
+
+ char[] argumentEscapeChars = getEscapeChars(
+ isSingleQuotedArgumentEscaped(), isDoubleQuotedArgumentEscaped()
+ );
+
+ return ShellUtils.buildCommandLine(
+ quotingStrategy, executable, arguments,
+ /* executable modification */
+ getExecutionPreamble(), isQuotedExecutableEnabled(), executableEscapeChars, getExecutableQuoteDelimiter(),
+ /* arguments modification */
+ isQuotedArgumentsEnabled(), argumentEscapeChars, getArgumentQuoteDelimiter(), getQuotingTriggerChars()
+ );
+ }
+}
+
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ShellUtils.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ShellUtils.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ShellUtils.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/shells/ShellUtils.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.shells;
+
+import npanday.executable.execution.ArgumentQuotingStrategy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * <i>Workaround for https://jira.codehaus.org/browse/PLXUTILS-147</i>
+ *
+ * @author <a href="mailto:lcorneliussen@apache.org">Lars Corneliussen</a>
+ */
+public class ShellUtils
+{
+ public static List buildCommandLine(
+ ArgumentQuotingStrategy quotingStrategy, String executable, String[] arguments, String executionPreamble,
+ boolean quotedExecutableEnabled, char[] executableEscapeChars, char executableQuoteChar,
+ boolean quotedArgumentsEnabled, char[] argumentEscapeChars, char argumentQuoteChar,
+ char[] quotingTriggerChars )
+ {
+ List commandLine = new ArrayList();
+ StringBuffer sb = new StringBuffer();
+
+ if ( executable != null )
+ {
+ String preamble = executionPreamble;
+ if ( preamble != null )
+ {
+ sb.append( preamble );
+ }
+
+ if ( quotedExecutableEnabled )
+ {
+ sb.append(
+ quotingStrategy.quoteAndEscape(
+ executable, executableQuoteChar, executableEscapeChars, quotingTriggerChars, '\\', false
+ )
+ );
+ }
+ else
+ {
+ sb.append( executable );
+ }
+ }
+ for ( int i = 0; i < arguments.length; i++ )
+ {
+ if ( sb.length() > 0 )
+ {
+ sb.append( " " );
+ }
+
+ if ( quotedArgumentsEnabled )
+ {
+ sb.append(
+ quotingStrategy.quoteAndEscape(
+ arguments[i], argumentQuoteChar, argumentEscapeChars, quotingTriggerChars, '\\', false
+ )
+ );
+ }
+ else
+ {
+ sb.append( arguments[i] );
+ }
+ }
+
+ commandLine.add( sb.toString() );
+
+ return commandLine;
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/Switch.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/Switch.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/Switch.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/Switch.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.switches;
+
+public class Switch {
+
+ private SwitchFormat switchFormat;
+
+ private String name;
+
+ private String value;
+
+ public Switch( SwitchFormat switchFormat, String name, String value )
+ {
+
+ this.switchFormat = switchFormat;
+ this.name = name;
+ this.value = value;
+ }
+
+ public SwitchFormat getSwitchFormat()
+ {
+ return switchFormat;
+ }
+
+ public void setSwitchFormat( SwitchFormat switchFormat )
+ {
+ this.switchFormat = switchFormat;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue( String value )
+ {
+ this.value = value;
+ }
+}
Added: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/SwitchFormat.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/SwitchFormat.java?rev=1227326&view=auto
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/SwitchFormat.java (added)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/execution/switches/SwitchFormat.java Wed Jan 4 21:12:08 2012
@@ -0,0 +1,90 @@
+/*
+ * 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.
+ */
+
+package npanday.executable.execution.switches;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class SwitchFormat
+{
+ char leadChar;
+
+ char valueOperatorChar;
+
+ String switchNamePattern;
+
+ Pattern switchPattern;
+
+ public SwitchFormat( char leadChar, char valueOperatorChar )
+ {
+ this( leadChar, "\\w+", valueOperatorChar );
+ }
+
+ public SwitchFormat( char leadChar, String switchNamePattern, char valueOperatorChar )
+ {
+ this.leadChar = leadChar;
+ this.valueOperatorChar = valueOperatorChar;
+ this.switchNamePattern = switchNamePattern;
+
+ this.switchPattern = Pattern.compile(
+ Pattern.quote( String.valueOf( leadChar ) ) + "(" + switchNamePattern + ")" + Pattern.quote(
+ String.valueOf( valueOperatorChar )
+ ) + "(.+)"
+ );
+ }
+
+ public boolean isMatchingSwitch( String argument )
+ {
+ // TODO: is performance relevant here?
+ return switchPattern.matcher( argument ).matches();
+ }
+
+ public Switch parse( String argument ){
+ final Matcher matcher = switchPattern.matcher( argument );
+ if (!matcher.matches()){
+ throw new IllegalArgumentException( "NPANDAY-134-000: Argument '" + argument + "' is not of format " + toString() );
+ }
+
+ // first group will always be the switch name, last always the (.*) for the value
+ return new Switch(this, matcher.group(1), matcher.group(matcher.groupCount()));
+ }
+
+ public String generate(String switchName, String switchValue){
+ return leadChar + switchName + valueOperatorChar + switchValue;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SwitchFormat{leadChar=" + leadChar + ", valueOperatorChar=" + valueOperatorChar
+ + ", switchNamePattern=/" + switchNamePattern + "/}";
+ }
+
+ static Splitter SPLIT_ON_SEMICOLON = Splitter.on( ';' );
+ public static SwitchFormat fromStringDefinition( String formatDefinition )
+ {
+ String[] args = Iterables.toArray(SPLIT_ON_SEMICOLON.split( formatDefinition ), String.class);
+ return new SwitchFormat( args[0].charAt( 0 ), args[1], args[2].charAt( 0 ) );
+ }
+}
+
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerContextImpl.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerContextImpl.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerContextImpl.java Wed Jan 4 21:12:08 2012
@@ -519,7 +519,7 @@ public final class CompilerContextImpl
{
try
{
- CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor();
+ CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor(null);
commandExecutor.setLogger( getLogger() );
String executable = "gacutil";
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerPluginsRepository.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerPluginsRepository.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerPluginsRepository.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CompilerPluginsRepository.java Wed Jan 4 21:12:08 2012
@@ -44,6 +44,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
import static com.google.common.base.Strings.isNullOrEmpty;
@@ -103,6 +104,7 @@ public final class CompilerPluginsReposi
CompilerPlugin plugin = (CompilerPlugin) i.next();
String language = plugin.getLanguage();
String pluginClassName = plugin.getPluginClass();
+ Properties pluginConfiguration = plugin.getPluginConfiguration();
String executable = plugin.getExecutable();
String vendor = plugin.getVendor();
String vendorVersion = plugin.getVendorVersion();
@@ -150,6 +152,8 @@ public final class CompilerPluginsReposi
platformCapability.setLanguage( language );
platformCapability.setOperatingSystem( os );
platformCapability.setPluginClassName( pluginClassName );
+ platformCapability.setPluginConfiguration( pluginConfiguration );
+
platformCapability.setExecutableName( executable );
platformCapability.setIdentifier( identifier );
platformCapability.setFrameworkVersions( frameworkVersions );
Copied: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultNetExecutable.java (from r1226709, incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CommonsExecNetExecutable.java)
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultNetExecutable.java?p2=incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultNetExecutable.java&p1=incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CommonsExecNetExecutable.java&r1=1226709&r2=1227326&rev=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/CommonsExecNetExecutable.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultNetExecutable.java Wed Jan 4 21:12:08 2012
@@ -31,17 +31,17 @@ import npanday.executable.execution.Comm
import npanday.vendor.Vendor;
import org.codehaus.plexus.logging.Logger;
-import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Properties;
/**
* Provides the default implementation of the net executable.
*
* @author Shane Isbell
*/
-public class CommonsExecNetExecutable
+public class DefaultNetExecutable
implements NetExecutable
{
@@ -54,44 +54,31 @@ public class CommonsExecNetExecutable
private Collection<String> commands;
+ private Properties configuration;
+
public List<String> getCommands() throws ExecutionException, PlatformUnsupportedException
{
// TODO: should it fail on unsupported commands?
CommandFilter filter = executableContext.getCommandFilter();
- return Collections.unmodifiableList(filter.filter( commands ));
+ return Collections.unmodifiableList( filter.filter( commands ) );
}
- private String getExecutable()
+ public void execute() throws ExecutionException, PlatformUnsupportedException
{
- String executable = executableContext.getExecutableName();
-
- Collection<String> executablePaths = executableContext.getProbingPaths();
- if ( executablePaths != null && executablePaths.size() > 0 )
- {
- for ( String executablePath : executablePaths )
- {
- File executableFile = PathUtil.getExecutable( new File(executablePath), executable );
- if ( executableFile != null )
- {
- logger.info("NPANDAY-126-001: Found executable file for " + executable + ": \"" + executableFile + "\"");
-
- return executableFile.getAbsolutePath();
- }
- }
- }
- logger.warn( "NPANDAY-126-002: Did not find path for " + executable + " in " + executablePaths );
-
- return executable;
+ innerExecute();
}
- public void execute()
- throws ExecutionException, PlatformUnsupportedException
+ public void innerExecute() throws ExecutionException, PlatformUnsupportedException
{
List<String> commands = getCommands();
- CommandExecutor commandExecutor = new CommonsExecCommandExecutor();
+ CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor((String)configuration.get( "switchformats" ));
commandExecutor.setLogger( logger );
- commandExecutor.executeCommand( getExecutable(), commands, null, true );
+ commandExecutor.executeCommand(
+ PathUtil.getExecutable(
+ executableContext.getExecutableName(), executableContext.getProbingPaths(), logger
+ ), commands, null, true
+ );
}
public Vendor getVendor()
@@ -99,8 +86,9 @@ public class CommonsExecNetExecutable
return executableContext.getVendor();
}
- public void init( NPandayContext npandayContext )
+ public void init( NPandayContext npandayContext, Properties properties )
{
+ configuration = properties;
this.executableContext = (ExecutableContext) npandayContext;
this.logger = executableContext.getLogger();
commands = executableContext.getCommands();
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/DefaultRepositoryNetExecutable.java Wed Jan 4 21:12:08 2012
@@ -29,6 +29,7 @@ import org.codehaus.plexus.logging.Logge
import java.util.List;
import java.util.Collections;
import java.io.File;
+import java.util.Properties;
/**
* @author Shane Isbell
@@ -46,13 +47,14 @@ public class DefaultRepositoryNetExecuta
private List<String> commands;
- public List<String> getCommands()
- throws ExecutionException
+ private Properties configuration;
+
+ public List<String> getCommands() throws ExecutionException
{
return commands;
}
- public File getExecutionPath()
+ public String getExecutable() throws ExecutionException
{
if ( executableContext == null )
{
@@ -67,71 +69,47 @@ public class DefaultRepositoryNetExecuta
File exe = new File( executable );
if ( exe.exists() )
{
- logger.info("NPANDAY-068-005: Choose executable path's parent as execution path: "
- + new File( executable ).getParentFile().getAbsolutePath());
- return new File( executable ).getParentFile();
+ logger.info( "NPANDAY-068-005: Found executable: " + exe.getAbsolutePath() );
+ return exe.getAbsolutePath();
}
}
+ if (executables.size() > 0)
+ {
+ logger.info( "NPANDAY-068-007: Assuming " + executables.get( 0 ) + " will be found on the path." );
+ return executables.get( 0 );
+ }
}
- logger.warn("NPANDAY-068-006: Did not find any of " + executables);
- return null;
+ throw new ExecutionException( "NPANDAY-068-006: Couldn't find anything to be executed!" );
}
- public void execute()
- throws ExecutionException
+ public void execute() throws ExecutionException
{
List<String> commands = getCommands();
- CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor();
+ CommandExecutor commandExecutor = CommandExecutor.Factory.createDefaultCommmandExecutor(
+ (String)configuration.get( "switchformats" )
+ );
commandExecutor.setLogger( logger );
try
{
- commandExecutor.executeCommand( getExecutable(), getCommands(), getExecutionPath(), true );
+ commandExecutor.executeCommand( getExecutable(), getCommands(), null, true );
}
catch ( ExecutionException e )
{
- throw new ExecutionException( "NPANDAY-063-000: Execution Path = " +
- ( ( getExecutionPath() != null ) ? getExecutionPath().getAbsolutePath() : "unknown" ) + ", Executable = " + getExecutable() + ", Args = " +
- commands, e );
- }
- if ( commandExecutor.getStandardOut().contains( "error" )
- && !commandExecutor.getStandardOut().contains( "exit code = 0" ) )
- {
throw new ExecutionException(
- "NPANDAY-063-001: Execution Path = " +
- ( ( getExecutionPath() != null ) ? getExecutionPath().getAbsolutePath() : "unknown" ) + ", Executable = " + getExecutable() + ", Args = " +
- commands );
- }
- }
-
-
- public String getExecutable()
- throws ExecutionException
- {
- if ( executableContext == null )
- {
- throw new ExecutionException( "NPANDAY-063-002: Executable has not been initialized with a context" );
+ "NPANDAY-063-000: Executable = " + getExecutable() + ", Args = " + commands, e
+ );
}
- List<String> executablePaths = executableContext.getExecutableConfig().getExecutionPaths();
- if ( executablePaths != null )
+ if ( commandExecutor.getStandardOut().contains( "error" ) && !commandExecutor.getStandardOut().contains(
+ "exit code = 0"
+ ) )
{
- for ( String executablePath : executablePaths )
- {
- File exe = new File( executablePath );
- logger.debug( "NPANDAY-063-004: Checking executable path = " + exe.getAbsolutePath() );
- if ( exe.exists() )
- {
- return new File( executablePath ).getName();
- }
- else if ( executablePath.equals( "mono" ) )
- {
- return executablePath;
- }
- }
+ throw new ExecutionException(
+ "NPANDAY-063-001: Executable = " + getExecutable() + ", Args = " + commands
+ );
}
- throw new ExecutionException( "NPANDAY-063-003: Executable path has not been set or is invalid" );
}
public Vendor getVendor()
@@ -146,8 +124,9 @@ public class DefaultRepositoryNetExecuta
}
}
- public void init( NPandayContext npandayContext )
+ public void init( NPandayContext npandayContext, Properties properties )
{
+ configuration = properties;
this.executableContext = (RepositoryExecutableContext) npandayContext;
this.logger = executableContext.getLogger();
commands = Collections.unmodifiableList( executableContext.getExecutableConfig().getCommands() );
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutableContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutableContextImpl.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutableContextImpl.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutableContextImpl.java Wed Jan 4 21:12:08 2012
@@ -155,6 +155,6 @@ public class ExecutableContextImpl
commandFilter = CommandFilter.Factory.createDefaultCommandFilter( executableCapability.getCommandCapability(), logger );
netExecutable = createPluginInstance();
- netExecutable.init( this );
+ netExecutable.init( this, executableCapability.getPluginConfiguration() );
}
}
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutablePluginsRepository.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutablePluginsRepository.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutablePluginsRepository.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/ExecutablePluginsRepository.java Wed Jan 4 21:12:08 2012
@@ -44,6 +44,7 @@ import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
+import java.util.Properties;
/**
* Provides services for accessing the executable information within the executable-plugins.xml file.
@@ -124,6 +125,8 @@ public final class ExecutablePluginsRepo
for ( ExecutablePlugin plugin : executablePlugins )
{
String pluginClassName = plugin.getPluginClass();
+ Properties pluginConfiguration = plugin.getPluginConfiguration();
+
String executable = plugin.getExecutable();
String executableVersion = plugin.getExecutableVersion();
String vendor = plugin.getVendor();
@@ -175,6 +178,7 @@ public final class ExecutablePluginsRepo
platformCapability.setOperatingSystem( os );
platformCapability.setPluginClassName( pluginClassName );
+ platformCapability.setPluginConfiguration( pluginConfiguration );
platformCapability.setExecutableName( executable );
platformCapability.setExectuableVersion(executableVersion);
platformCapability.setIdentifier( identifier );
Modified: incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/RepositoryExecutableContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/RepositoryExecutableContextImpl.java?rev=1227326&r1=1227325&r2=1227326&view=diff
==============================================================================
--- incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/RepositoryExecutableContextImpl.java (original)
+++ incubator/npanday/trunk/components/dotnet-executable/src/main/java/npanday/executable/impl/RepositoryExecutableContextImpl.java Wed Jan 4 21:12:08 2012
@@ -30,6 +30,8 @@ import npanday.registry.RepositoryRegist
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
+import java.util.Properties;
+
/**
* Provides an implementation of the repository executable context.
*
@@ -96,6 +98,6 @@ public class RepositoryExecutableContext
{
this.executableConfig = executableConfig;
netExecutable = new DefaultRepositoryNetExecutable();
- netExecutable.init( this );
+ netExecutable.init( this, new Properties( ) );
}
}