This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-scm.git
The following commit(s) were added to refs/heads/master by this push:
new b069b543e [SCM-944] Restore the working directory system property
after scm:validate
b069b543e is described below
commit b069b543e42fc2365c70ab1b1ec7090fc5c9571b
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 17 02:04:49 2026 +0100
[SCM-944] Restore the working directory system property after scm:validate
scm:validate with scmCheckWorkingDirectoryUrl set a JVM-wide property and
never cleared it, so later executions in the same build, scm:export for one,
were checked against the validated URL.
Fixes #1168
---
.../org/apache/maven/scm/plugin/ValidateMojo.java | 13 ++++++++-
.../apache/maven/scm/plugin/ValidateMojoTest.java | 14 ++++++++++
.../validate/validateWithWorkingDirectoryCheck.xml | 31 ++++++++++++++++++++++
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git
a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ValidateMojo.java
b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ValidateMojo.java
index 6d8e3ce1d..4fd30ac97 100644
---
a/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ValidateMojo.java
+++
b/maven-scm-plugin/src/main/java/org/apache/maven/scm/plugin/ValidateMojo.java
@@ -99,12 +99,23 @@ public void execute() throws MojoExecutionException {
}
private void validateConnection(String connectionString, String type)
throws MojoExecutionException {
+ String previous =
System.getProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY);
if (scmCheckWorkingDirectoryUrl) {
System.setProperty(
AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY,
project.getFile().getParentFile().getAbsolutePath());
}
- List<String> messages =
getScmManager().validateScmRepository(connectionString);
+ List<String> messages;
+ try {
+ messages = getScmManager().validateScmRepository(connectionString);
+ } finally {
+ // the property is JVM-wide and would otherwise leak into other
executions in the same build
+ if (previous == null) {
+
System.clearProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY);
+ } else {
+
System.setProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY, previous);
+ }
+ }
if (!messages.isEmpty()) {
getLog().error("Validation of scm url connection (" + type + ")
failed :");
diff --git
a/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ValidateMojoTest.java
b/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ValidateMojoTest.java
index cc9b17c8f..0ff5a28da 100644
---
a/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ValidateMojoTest.java
+++
b/maven-scm-plugin/src/test/java/org/apache/maven/scm/plugin/ValidateMojoTest.java
@@ -21,10 +21,12 @@
import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.scm.provider.svn.AbstractSvnScmProvider;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
@@ -58,4 +60,16 @@ void testValidateWithInvalidScmUrls(ValidateMojo mojo)
throws Exception {
void testValidateWithInvalidScmUrlsAndSkip(ValidateMojo mojo) {
assertDoesNotThrow(mojo::execute);
}
+
+ @Test
+ @InjectMojo(goal = "validate", pom =
"classpath:/mojos/validate/validateWithWorkingDirectoryCheck.xml")
+ void testWorkingDirectoryPropertyIsNotLeaked(ValidateMojo mojo) {
+
assertNull(System.getProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY));
+ try {
+ assertDoesNotThrow(mojo::execute);
+
assertNull(System.getProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY));
+ } finally {
+
System.clearProperty(AbstractSvnScmProvider.CURRENT_WORKING_DIRECTORY);
+ }
+ }
}
diff --git
a/maven-scm-plugin/src/test/resources/mojos/validate/validateWithWorkingDirectoryCheck.xml
b/maven-scm-plugin/src/test/resources/mojos/validate/validateWithWorkingDirectoryCheck.xml
new file mode 100644
index 000000000..01f0e4fe5
--- /dev/null
+++
b/maven-scm-plugin/src/test/resources/mojos/validate/validateWithWorkingDirectoryCheck.xml
@@ -0,0 +1,31 @@
+<!--
+ ~ 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.
+ -->
+<project>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-scm-plugin</artifactId>
+ <configuration>
+
<connectionUrl>scm:git:https://github.com/apache/maven-scm.git</connectionUrl>
+ <scmCheckWorkingDirectoryUrl>true</scmCheckWorkingDirectoryUrl>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>