From ec97f4dd03f0393a20bbc810479cb8518af702e9 Mon Sep 17 00:00:00 2001 From: Shannon Carey Date: Sun, 14 Aug 2016 16:41:08 -0500 Subject: [PATCH] Add "provided" classpathScope (runtime+provided) - New "provided" value for classpathScope includes both runtime and provided dependencies - Closes #60 --- src/it/projects/git-issue-60-exec/pom.xml | 59 +++++++++++++++++++ .../src/main/java/gitissue60/Main.java | 31 ++++++++++ .../src/main/resources/log4j.properties | 8 +++ .../projects/git-issue-60-exec/verify.groovy | 25 ++++++++ .../git-issue-60-java/invoker.properties | 1 + src/it/projects/git-issue-60-java/pom.xml | 58 ++++++++++++++++++ .../src/main/java/gitissue60/Main.java | 31 ++++++++++ .../src/main/resources/log4j.properties | 8 +++ .../projects/git-issue-60-java/verify.groovy | 30 ++++++++++ src/it/projects/setup-parent/pom.xml | 20 +++++++ .../codehaus/mojo/exec/AbstractExecMojo.java | 24 +++++++- 11 files changed, 293 insertions(+), 2 deletions(-) create mode 100644 src/it/projects/git-issue-60-exec/pom.xml create mode 100644 src/it/projects/git-issue-60-exec/src/main/java/gitissue60/Main.java create mode 100644 src/it/projects/git-issue-60-exec/src/main/resources/log4j.properties create mode 100644 src/it/projects/git-issue-60-exec/verify.groovy create mode 100644 src/it/projects/git-issue-60-java/invoker.properties create mode 100644 src/it/projects/git-issue-60-java/pom.xml create mode 100644 src/it/projects/git-issue-60-java/src/main/java/gitissue60/Main.java create mode 100644 src/it/projects/git-issue-60-java/src/main/resources/log4j.properties create mode 100644 src/it/projects/git-issue-60-java/verify.groovy diff --git a/src/it/projects/git-issue-60-exec/pom.xml b/src/it/projects/git-issue-60-exec/pom.xml new file mode 100644 index 00000000..5ea2dd91 --- /dev/null +++ b/src/it/projects/git-issue-60-exec/pom.xml @@ -0,0 +1,59 @@ + + 4.0.0 + + + org.codehaus.mojo.exec.it + parent + 0.1 + + + org.codehaus.mojo.exec-maven-plugin + git-issue-60-exec + 0.0.1-SNAPSHOT + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + provided + + + + + + + + org.codehaus.mojo + exec-maven-plugin + @project.version@ + + + test + + exec + + + + + provided + ${JAVA_HOME}/bin/java + + -classpath + + gitissue60.Main + + + + + + + diff --git a/src/it/projects/git-issue-60-exec/src/main/java/gitissue60/Main.java b/src/it/projects/git-issue-60-exec/src/main/java/gitissue60/Main.java new file mode 100644 index 00000000..36ab1c9a --- /dev/null +++ b/src/it/projects/git-issue-60-exec/src/main/java/gitissue60/Main.java @@ -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?" ); + } +} diff --git a/src/it/projects/git-issue-60-exec/src/main/resources/log4j.properties b/src/it/projects/git-issue-60-exec/src/main/resources/log4j.properties new file mode 100644 index 00000000..eb83c002 --- /dev/null +++ b/src/it/projects/git-issue-60-exec/src/main/resources/log4j.properties @@ -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 \ No newline at end of file diff --git a/src/it/projects/git-issue-60-exec/verify.groovy b/src/it/projects/git-issue-60-exec/verify.groovy new file mode 100644 index 00000000..9ffe1022 --- /dev/null +++ b/src/it/projects/git-issue-60-exec/verify.groovy @@ -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() \ No newline at end of file diff --git a/src/it/projects/git-issue-60-java/invoker.properties b/src/it/projects/git-issue-60-java/invoker.properties new file mode 100644 index 00000000..20eaebac --- /dev/null +++ b/src/it/projects/git-issue-60-java/invoker.properties @@ -0,0 +1 @@ +invoker.debug = true diff --git a/src/it/projects/git-issue-60-java/pom.xml b/src/it/projects/git-issue-60-java/pom.xml new file mode 100644 index 00000000..5f165cd5 --- /dev/null +++ b/src/it/projects/git-issue-60-java/pom.xml @@ -0,0 +1,58 @@ + + 4.0.0 + + org.codehaus.mojo.exec.it + parent + 0.1 + + + org.codehaus.mojo.exec-maven-plugin + git-issue-60-java + 0.0.1-SNAPSHOT + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + runtime + + + log4j + log4j + provided + + + junit + junit + test + + + + + + + + org.codehaus.mojo + exec-maven-plugin + @project.version@ + + + test + + java + + + + + gitissue60.Main + provided + + + + + + diff --git a/src/it/projects/git-issue-60-java/src/main/java/gitissue60/Main.java b/src/it/projects/git-issue-60-java/src/main/java/gitissue60/Main.java new file mode 100644 index 00000000..36ab1c9a --- /dev/null +++ b/src/it/projects/git-issue-60-java/src/main/java/gitissue60/Main.java @@ -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?" ); + } +} diff --git a/src/it/projects/git-issue-60-java/src/main/resources/log4j.properties b/src/it/projects/git-issue-60-java/src/main/resources/log4j.properties new file mode 100644 index 00000000..eb83c002 --- /dev/null +++ b/src/it/projects/git-issue-60-java/src/main/resources/log4j.properties @@ -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 \ No newline at end of file diff --git a/src/it/projects/git-issue-60-java/verify.groovy b/src/it/projects/git-issue-60-java/verify.groovy new file mode 100644 index 00000000..d7cbe3e2 --- /dev/null +++ b/src/it/projects/git-issue-60-java/verify.groovy @@ -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" ) \ No newline at end of file diff --git a/src/it/projects/setup-parent/pom.xml b/src/it/projects/setup-parent/pom.xml index a849490a..8895647b 100644 --- a/src/it/projects/setup-parent/pom.xml +++ b/src/it/projects/setup-parent/pom.xml @@ -30,6 +30,26 @@ commons-io 2.7 + + org.slf4j + slf4j-api + 1.7.21 + + + org.slf4j + slf4j-log4j12 + 1.7.21 + + + log4j + log4j + 1.2.17 + + + junit + junit + 3.8.1 + diff --git a/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java b/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java index 48fe8ed8..d859776a 100644 --- a/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java +++ b/src/main/java/org/codehaus/mojo/exec/AbstractExecMojo.java @@ -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; @@ -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. + * + * + * + * Since 1.1.2, the default value is 'runtime' instead of 'compile'. */ @Parameter(property = "exec.classpathScope", defaultValue = "runtime") protected String classpathScope; @@ -153,6 +164,15 @@ protected void collectProjectArtifactsAndClasspath(List 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 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 {