You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2024/05/04 10:48:21 UTC
(maven-invoker-plugin) branch master updated: [MINVOKER-364] Rename invoker.systemPropertiesFile to invoker.userPropertiesFile
This is an automated email from the ASF dual-hosted git repository.
sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-invoker-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new a741ea0 [MINVOKER-364] Rename invoker.systemPropertiesFile to invoker.userPropertiesFile
a741ea0 is described below
commit a741ea04854071c2900a323e65e7037449a4bdd3
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Fri May 3 12:18:10 2024 +0200
[MINVOKER-364] Rename invoker.systemPropertiesFile to invoker.userPropertiesFile
---
.../src/it/project/invoker.properties | 4 +--
.../{system1.properties => user.properties} | 0
.../{system2.properties => user3.properties} | 0
.../{verify.bsh => verify.groovy} | 26 +++-----------
.../maven/plugins/invoker/AbstractInvokerMojo.java | 19 +++++-----
.../maven/plugins/invoker/InvokerProperties.java | 41 ++++++++++++++++++++--
.../plugins/invoker/InvokerPropertiesTest.java | 39 ++++++++++++++++++++
7 files changed, 93 insertions(+), 36 deletions(-)
diff --git a/src/it/invocation-multiple/src/it/project/invoker.properties b/src/it/invocation-multiple/src/it/project/invoker.properties
index 89ca088..3d0e138 100644
--- a/src/it/invocation-multiple/src/it/project/invoker.properties
+++ b/src/it/invocation-multiple/src/it/project/invoker.properties
@@ -20,7 +20,7 @@
#######################################
invoker.goals = install
invoker.profiles = plugin,profile0
-invoker.systemPropertiesFile = system1.properties
+invoker.userPropertiesFile = user.properties
#######################################
# First build
@@ -40,4 +40,4 @@ invoker.profiles.2 = plugin,profile1
#######################################
invoker.goals.3 = test:test-maven-plugin:0.1-SNAPSHOT:test
# profiles should fall back to invoker.profiles
-invoker.systemPropertiesFile.3 = system2.properties
+invoker.userPropertiesFile.3 = user3.properties
diff --git a/src/it/invocation-multiple/src/it/project/system1.properties b/src/it/invocation-multiple/src/it/project/user.properties
similarity index 100%
rename from src/it/invocation-multiple/src/it/project/system1.properties
rename to src/it/invocation-multiple/src/it/project/user.properties
diff --git a/src/it/invocation-multiple/src/it/project/system2.properties b/src/it/invocation-multiple/src/it/project/user3.properties
similarity index 100%
rename from src/it/invocation-multiple/src/it/project/system2.properties
rename to src/it/invocation-multiple/src/it/project/user3.properties
diff --git a/src/it/postbuild-executed-only-once/verify.bsh b/src/it/postbuild-executed-only-once/verify.groovy
similarity index 59%
rename from src/it/postbuild-executed-only-once/verify.bsh
rename to src/it/postbuild-executed-only-once/verify.groovy
index e05fbff..8ee560a 100644
--- a/src/it/postbuild-executed-only-once/verify.bsh
+++ b/src/it/postbuild-executed-only-once/verify.groovy
@@ -17,25 +17,9 @@
* under the License.
*/
-import java.io.*;
-import java.util.*;
-import java.util.regex.*;
+// make sure the Invoker Plugin was indeed run and the build didn't fail somewhere else
+def touchFile = new File(basedir, 'target/it/project/target/touch.txt')
+assert touchFile.exists()
-try
-{
- // make sure the Invoker Plugin was indeed run and the build didn't fail somewhere else
- File touchFile = new File( basedir, "target/it/project/target/touch.txt" );
- System.out.println( "Checking for existence of touch file: " + touchFile );
- if ( !touchFile.exists() )
- {
- System.out.println( "FAILED! no touchFile " + touchFile.toString() );
- return false;
- }
-}
-catch( Throwable t )
-{
- t.printStackTrace();
- return false;
-}
-
-return true;
+def logs = new File(basedir, 'build.log').text
+assert logs.contains('[WARNING] property invoker.systemPropertiesFile is deprecated - please use invoker.userPropertiesFile')
diff --git a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
index 3c454b2..09987f4 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/AbstractInvokerMojo.java
@@ -526,11 +526,11 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
* # can be indexed
* invoker.offline = true
*
- * # The path to the properties file from which to load system properties, defaults to the
+ * # The path to the properties file from which to load user properties, defaults to the
* # filename given by the plugin parameter testPropertiesFile
* # Since plugin version 1.4
* # can be indexed
- * invoker.systemPropertiesFile = test.properties
+ * invoker.userPropertiesFile = test.properties
*
* # An optional human friendly name and description for this build job.
* # Both name and description have to be set to be included in the build reports.
@@ -1887,9 +1887,9 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
request.setUserSettingsFile(settingsFile);
}
- Properties systemProperties =
- getSystemProperties(basedir, invokerProperties.getSystemPropertiesFile(invocationIndex));
- request.setProperties(systemProperties);
+ Properties userProperties =
+ getUserProperties(basedir, invokerProperties.getUserPropertiesFile(invocationIndex));
+ request.setProperties(userProperties);
invokerProperties.configureInvocation(request, invocationIndex);
@@ -1999,7 +1999,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
* @return The system properties to use, may be empty but never <code>null</code>.
* @throws org.apache.maven.plugin.MojoExecutionException If the properties file exists but could not be read.
*/
- private Properties getSystemProperties(final File basedir, final String filename) throws MojoExecutionException {
+ private Properties getUserProperties(final File basedir, final String filename) throws MojoExecutionException {
Properties collectedTestProperties = new Properties();
if (properties != null) {
@@ -2014,18 +2014,16 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
File propertiesFile = null;
if (filename != null) {
propertiesFile = new File(basedir, filename);
- } else if (testPropertiesFile != null) {
- propertiesFile = new File(basedir, testPropertiesFile);
}
if (propertiesFile != null && propertiesFile.isFile()) {
- try (InputStream fin = new FileInputStream(propertiesFile)) {
+ try (InputStream fin = Files.newInputStream(propertiesFile.toPath())) {
Properties loadedProperties = new Properties();
loadedProperties.load(fin);
collectedTestProperties.putAll(loadedProperties);
} catch (IOException e) {
- throw new MojoExecutionException("Error reading system properties from " + propertiesFile);
+ throw new MojoExecutionException("Error reading user properties from " + propertiesFile);
}
}
@@ -2369,6 +2367,7 @@ public abstract class AbstractInvokerMojo extends AbstractMojo {
invokerProperties.setDefaultTimeoutInSeconds(timeoutInSeconds);
invokerProperties.setDefaultEnvironmentVariables(environmentVariables);
invokerProperties.setDefaultUpdateSnapshots(updateSnapshots);
+ invokerProperties.setDefaultUserPropertiesFiles(testPropertiesFile);
return invokerProperties;
}
diff --git a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
index 15e246d..4bf09e7 100644
--- a/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
+++ b/src/main/java/org/apache/maven/plugins/invoker/InvokerProperties.java
@@ -32,6 +32,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.maven.shared.invoker.InvocationRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Provides a convenient facade around the <code>invoker.properties</code>.
@@ -39,6 +41,9 @@ import org.apache.maven.shared.invoker.InvocationRequest;
* @author Benjamin Bentmann
*/
class InvokerProperties {
+
+ private final Logger logger = LoggerFactory.getLogger(InvokerProperties.class);
+
private static final String SELECTOR_PREFIX = "selector.";
private static final Pattern ENVIRONMENT_VARIABLES_PATTERN =
@@ -54,6 +59,7 @@ class InvokerProperties {
private Map<String, String> defaultEnvironmentVariables;
private File defaultMavenExecutable;
private Boolean defaultUpdateSnapshots;
+ private String defaultUserPropertiesFiles;
private enum InvocationProperty {
PROJECT("invoker.project"),
@@ -66,6 +72,7 @@ class InvokerProperties {
NON_RECURSIVE("invoker.nonRecursive"),
OFFLINE("invoker.offline"),
SYSTEM_PROPERTIES_FILE("invoker.systemPropertiesFile"),
+ USER_PROPERTIES_FILE("invoker.userPropertiesFile"),
DEBUG("invoker.debug"),
QUIET("invoker.quiet"),
SETTINGS_FILE("invoker.settingsFile"),
@@ -190,6 +197,14 @@ class InvokerProperties {
this.defaultUpdateSnapshots = defaultUpdateSnapshots;
}
+ /**
+ * Default value for userPropertiesFile
+ * @param defaultUserPropertiesFiles a default value
+ */
+ public void setDefaultUserPropertiesFiles(String defaultUserPropertiesFiles) {
+ this.defaultUserPropertiesFiles = defaultUserPropertiesFiles;
+ }
+
/**
* Gets the invoker properties being wrapped.
*
@@ -467,13 +482,33 @@ class InvokerProperties {
}
/**
- * Gets the path to the properties file used to set the system properties for the specified invocation.
+ * Gets the path to the properties file used to set the user properties for the specified invocation.
*
* @param index The index of the invocation, must not be negative.
* @return The path to the properties file or <code>null</code> if not set.
*/
- public String getSystemPropertiesFile(int index) {
- return get(InvocationProperty.SYSTEM_PROPERTIES_FILE, index).orElse(null);
+ public String getUserPropertiesFile(int index) {
+ Optional<String> userProperties = get(InvocationProperty.USER_PROPERTIES_FILE, index);
+ Optional<String> systemProperties = get(InvocationProperty.SYSTEM_PROPERTIES_FILE, index);
+
+ if (userProperties.isPresent() && systemProperties.isPresent()) {
+ throw new IllegalArgumentException("only one property '" + InvocationProperty.USER_PROPERTIES_FILE
+ + "' or '" + InvocationProperty.SYSTEM_PROPERTIES_FILE + "' can be used");
+ }
+
+ if (userProperties.isPresent()) {
+ return userProperties.get();
+ }
+
+ if (systemProperties.isPresent()) {
+ logger.warn(
+ "property {} is deprecated - please use {}",
+ InvocationProperty.SYSTEM_PROPERTIES_FILE,
+ InvocationProperty.USER_PROPERTIES_FILE);
+ return systemProperties.get();
+ }
+
+ return defaultUserPropertiesFiles;
}
/**
diff --git a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
index 26a706e..58285f8 100644
--- a/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
+++ b/src/test/java/org/apache/maven/plugins/invoker/InvokerPropertiesTest.java
@@ -545,4 +545,43 @@ class InvokerPropertiesTest {
assertThat(toolchain.getType()).isEqualTo("jdk");
assertThat(toolchain.getProvides()).containsExactlyEntriesOf(Collections.singletonMap("version", "11"));
}
+
+ @Test
+ void defaultValueForUserPropertiesFileShouldBeReturned() {
+ InvokerProperties facade = new InvokerProperties(new Properties());
+ facade.setDefaultUserPropertiesFiles("test3.properties");
+
+ assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test3.properties");
+ }
+
+ @Test
+ void userPropertiesFilesShouldBeUsed() {
+ Properties props = new Properties();
+ props.put("invoker.userPropertiesFile", "test1");
+ InvokerProperties facade = new InvokerProperties(props);
+
+ assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test1");
+ }
+
+ @Test
+ void systemPropertiesFilesShouldBeUsed() {
+ Properties props = new Properties();
+ props.put("invoker.systemPropertiesFile", "test1");
+ InvokerProperties facade = new InvokerProperties(props);
+
+ assertThat(facade.getUserPropertiesFile(0)).isEqualTo("test1");
+ }
+
+ @Test
+ void userAndSystemPropertiesFilesShouldThrowException() {
+ Properties props = new Properties();
+ props.put("invoker.systemPropertiesFile", "test1");
+ props.put("invoker.userPropertiesFile", "test2");
+ InvokerProperties facade = new InvokerProperties(props);
+
+ assertThatCode(() -> facade.getUserPropertiesFile(0))
+ .isExactlyInstanceOf(IllegalArgumentException.class)
+ .hasMessage(
+ "only one property 'invoker.userPropertiesFile' or 'invoker.systemPropertiesFile' can be used");
+ }
}