Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to include runtime and provided #61

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/it/projects/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>
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?" );
}
}
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/projects/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()
1 change: 1 addition & 0 deletions src/it/projects/git-issue-60-java/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.debug = true
58 changes: 58 additions & 0 deletions src/it/projects/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>
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?" );
}
}
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/projects/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" )
20 changes: 20 additions & 0 deletions src/it/projects/setup-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
<artifactId>commons-io</artifactId>
<version>2.7</version>
</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>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.execution.MavenSession;
Expand Down Expand Up @@ -89,8 +91,17 @@ public abstract class AbstractExecMojo extends AbstractMojo {
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 @@ -153,6 +164,15 @@ protected void collectProjectArtifactsAndClasspath(List<Artifact> artifacts, Lis
if (addOutputToClasspath) {
theClasspathFiles.add(Paths.get(project.getBuild().getOutputDirectory()));
}
} else if ("provided".equals(classpathScope)) {
// "compile" gives compile, provided, and system scopes
// "runtime" gives compile and runtime scopes
Set<Artifact> artifactSet = new HashSet<>(project.getCompileArtifacts());
artifactSet.addAll(project.getRuntimeArtifacts());
artifacts.addAll(artifactSet);
if (addOutputToClasspath) {
theClasspathFiles.add(Paths.get(project.getBuild().getOutputDirectory()));
}
} else if ("system".equals(classpathScope)) {
artifacts.addAll(project.getSystemArtifacts());
} else {
Expand Down