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 ed28571bb [SCM-998] Use forward slash in ScmFile.getPath()
ed28571bb is described below

commit ed28571bb9674c68c8cdc1afa3970bb4a4798595
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 17 02:10:57 2026 +0100

    [SCM-998] Use forward slash in ScmFile.getPath()
    
    Fixes #1221
---
 .../main/java/org/apache/maven/scm/ScmFile.java    |  9 +++--
 .../java/org/apache/maven/scm/ScmFileTest.java     | 45 ++++++++++++++++++++++
 2 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/maven-scm-api/src/main/java/org/apache/maven/scm/ScmFile.java 
b/maven-scm-api/src/main/java/org/apache/maven/scm/ScmFile.java
index dc6550128..666e4bafa 100644
--- a/maven-scm-api/src/main/java/org/apache/maven/scm/ScmFile.java
+++ b/maven-scm-api/src/main/java/org/apache/maven/scm/ScmFile.java
@@ -18,6 +18,7 @@
  */
 package org.apache.maven.scm;
 
+import java.io.File;
 import java.io.Serializable;
 
 /**
@@ -31,17 +32,19 @@ public class ScmFile implements Comparable<ScmFile>, 
Serializable {
     private ScmFileStatus status;
 
     /**
-     * @param path   the relative path of the file, should <b>never</b> start 
with any {@link java.io.File#separator}
+     * @param path   the relative path of the file, should <b>never</b> start 
with any {@link java.io.File#separator};
+     *               the operating system separator is converted to forward 
slashes
      * @param status the file status
      */
     public ScmFile(String path, ScmFileStatus status) {
-        this.path = path;
+        this.path = path != null && File.separatorChar == '\\' ? 
path.replace('\\', '/') : path;
 
         this.status = status;
     }
 
     /**
-     * Returns the relative path of the file.
+     * Returns the relative path of the file. The path always uses the forward 
slash {@code /} as separator,
+     * on every operating system. On Windows, backslashes are converted to 
forward slashes.
      *
      * @return the file path
      */
diff --git a/maven-scm-api/src/test/java/org/apache/maven/scm/ScmFileTest.java 
b/maven-scm-api/src/test/java/org/apache/maven/scm/ScmFileTest.java
new file mode 100644
index 000000000..7e8db4079
--- /dev/null
+++ b/maven-scm-api/src/test/java/org/apache/maven/scm/ScmFileTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.scm;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ScmFileTest {
+    @Test
+    @EnabledOnOs(OS.WINDOWS)
+    void testPathUsesForwardSlashOnWindows() {
+        ScmFile file = new ScmFile("src\\main\\Foo.java", ScmFileStatus.ADDED);
+
+        assertEquals("src/main/Foo.java", file.getPath());
+        assertEquals(new ScmFile("src/main/Foo.java", ScmFileStatus.ADDED), 
file);
+    }
+
+    @Test
+    @DisabledOnOs(OS.WINDOWS)
+    void testBackslashIsKeptOnUnix() {
+        ScmFile file = new ScmFile("a\\b", ScmFileStatus.ADDED);
+
+        assertEquals("a\\b", file.getPath());
+    }
+}

Reply via email to