Skip to content

Commit

Permalink
Add option to include runtime and provided
Browse files Browse the repository at this point in the history
- New "provided" value for classpathScope includes both runtime and
  provided dependencies
- Closes mojohaus#60
  • Loading branch information
rehevkor5 committed Aug 15, 2016
1 parent 165ef8b commit d30d2f3
Show file tree
Hide file tree
Showing 12 changed files with 304 additions and 6 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@
<extraArtifact>org.apache.maven.plugins:maven-site-plugin:2.0.1:maven-plugin</extraArtifact>
<extraArtifact>commons-io:commons-io:1.1:jar</extraArtifact>
<extraArtifact>commons-logging:commons-logging:1.0.4:jar</extraArtifact>
<extraArtifact>org.slf4j:slf4j-api:1.7.21:jar</extraArtifact>
<extraArtifact>org.slf4j:slf4j-log4j12:1.7.21:jar</extraArtifact>
<extraArtifact>log4j:log4j:1.2.17:jar</extraArtifact>
<extraArtifact>org.codehaus.plexus:plexus-utils:1.1:jar</extraArtifact>
</extraArtifacts>
</configuration>
Expand Down
59 changes: 59 additions & 0 deletions src/it/git-issue-60-exec/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<project>
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<groupId>org.codehaus.mojo.exec-maven-plugin</groupId>
<artifactId>git-issue-60-exec</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<!-- for manual tests. Can't be automated in the unit tests as the plugin's not installed. What about integration tests? -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<classpathScope>provided</classpathScope>
<executable>${JAVA_HOME}/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>gitissue60.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>

</project>
31 changes: 31 additions & 0 deletions src/it/git-issue-60-exec/src/main/java/gitissue60/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gitissue60;

/*
* Copyright 2005 The Codehaus.
*
* Licensed 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.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @version $Id$
*/
public class Main
{
private static final Logger LOGGER = LoggerFactory.getLogger( Main.class );
public static void main( String[] args ) throws Exception {
LOGGER.info( "Can you hear me, Major Tom?" );
}
}
8 changes: 8 additions & 0 deletions src/it/git-issue-60-exec/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Root logger option
log4j.rootLogger=INFO, file

# Direct log messages to stdout
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=exec.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
25 changes: 25 additions & 0 deletions src/it/git-issue-60-exec/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

File execLog = new File(basedir, 'exec.log')
assert execLog.exists()
assert execLog.getText().contains('Can you hear me, Major Tom?')

File buildLog = new File(basedir, 'build.log')
assert buildLog.exists()
58 changes: 58 additions & 0 deletions src/it/git-issue-60-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.codehaus.mojo.exec.it</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>

<groupId>org.codehaus.mojo.exec-maven-plugin</groupId>
<artifactId>git-issue-60-java</artifactId>
<version>0.0.1-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- for manual tests. Can't be automated in the unit tests as the plugin's not installed. What about integration tests? -->
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>gitissue60.Main</mainClass>
<classpathScope>provided</classpathScope>
</configuration>
</plugin>
</plugins>
</build>

</project>
31 changes: 31 additions & 0 deletions src/it/git-issue-60-java/src/main/java/gitissue60/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package gitissue60;

/*
* Copyright 2005 The Codehaus.
*
* Licensed 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.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @version $Id$
*/
public class Main
{
private static final Logger LOGGER = LoggerFactory.getLogger( Main.class );
public static void main( String[] args ) throws Exception {
LOGGER.info( "Can you hear me, Major Tom?" );
}
}
8 changes: 8 additions & 0 deletions src/it/git-issue-60-java/src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Root logger option
log4j.rootLogger=INFO, file

# Direct log messages to stdout
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=exec.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
30 changes: 30 additions & 0 deletions src/it/git-issue-60-java/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
*/

File execLog = new File(basedir, 'exec.log')
assert execLog.exists()
assert execLog.getText().contains('Can you hear me, Major Tom?')

File buildLog = new File(basedir, 'build.log')
assert buildLog.exists()
def buildLogText = buildLog.getText()
assert buildLogText.contains( "Adding project dependency artifact: slf4j-api to classpath" )
assert buildLogText.contains( "Adding project dependency artifact: log4j to classpath" )
assert buildLogText.contains( "Adding project dependency artifact: slf4j-log4j12 to classpath" )
assert !buildLogText.contains( "Adding project dependency artifact: junit to classpath" )
25 changes: 24 additions & 1 deletion src/it/setup/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,30 @@
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.0.4</version>
</dependency>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
26 changes: 24 additions & 2 deletions src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

import java.io.File;
import java.util.HashSet;
import java.util.List;

import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -107,8 +108,17 @@ public abstract class AbstractExecMojo
private String commandlineArgs;

/**
* Defines the scope of the classpath passed to the plugin. Set to compile,test,runtime or system depending on your
* needs. Since 1.1.2, the default value is 'runtime' instead of 'compile'.
* Defines the scope of the classpath passed to the plugin.
*
* <ul>
* <li><code>runtime</code> (default): Include "compile" and "runtime" scopes</li>
* <li><code>compile</code>: Include "compile", "provided", and "system" scopes</li>
* <li><code>test</code>: Include all scopes</li>
* <li><code>provided</code>: Include "compile", "runtime", "provided", and "system" scopes</li>
* <li><code>system</code>: Include "system" scope</li>
* </ul>
*
* Since 1.1.2, the default value is 'runtime' instead of 'compile'.
*/
@Parameter( property = "exec.classpathScope", defaultValue = "runtime" )
protected String classpathScope;
Expand Down Expand Up @@ -184,6 +194,18 @@ else if ( "runtime".equals( classpathScope ) )
theClasspathFiles.add( new File( project.getBuild().getOutputDirectory() ) );
}
}
else if ( "provided".equals( classpathScope ) )
{
// "compile" gives compile, provided, and system scopes
// "runtime" gives compile and runtime scopes
HashSet<Artifact> artifactSet = new HashSet<>( project.getCompileArtifacts() );
artifactSet.addAll( project.getRuntimeArtifacts() );
artifacts.addAll( artifactSet );
if ( addOutputToClasspath )
{
theClasspathFiles.add( new File( project.getBuild().getOutputDirectory() ) );
}
}
else if ( "system".equals( classpathScope ) )
{
artifacts.addAll( project.getSystemArtifacts() );
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/codehaus/mojo/exec/ExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,9 @@ private String computeClasspathString( AbstractPath specifiedClasspath )
*/
private List<String> computePath( AbstractPath specifiedClasspath )
{
List<Artifact> artifacts = new ArrayList<Artifact>();
List<File> theClasspathFiles = new ArrayList<File>();
List<String> resultList = new ArrayList<String>();
List<Artifact> artifacts = new ArrayList<>();
List<File> theClasspathFiles = new ArrayList<>();
List<String> resultList = new ArrayList<>();

collectProjectArtifactsAndClasspath( artifacts, theClasspathFiles );

Expand Down

0 comments on commit d30d2f3

Please sign in to comment.