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-doap-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 588de54  Write Git and other typed repositories without Maven SCM
588de54 is described below

commit 588de54583e371d065d2189f6b64211c284941ab
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 14 10:41:15 2026 +0100

    Write Git and other typed repositories without Maven SCM
    
    Maven SCM was only used to recognise Subversion; the plugin shipped no
    other provider, so Git connections fell back to an invalid location.
---
 pom.xml                                            | 23 -------
 .../org/apache/maven/plugin/doap/DoapMojo.java     | 76 +++-------------------
 .../org/apache/maven/plugin/doap/DoapUtil.java     | 64 ++++++++++++++++++
 .../org/apache/maven/plugin/doap/DoapMojoTest.java | 27 ++++++++
 .../org/apache/maven/plugin/doap/DoapUtilTest.java | 36 ++++++++++
 5 files changed, 137 insertions(+), 89 deletions(-)

diff --git a/pom.xml b/pom.xml
index de45911..5c2ccf7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -61,7 +61,6 @@ under the License.
 
   <properties>
     <mavenVersion>3.9.16</mavenVersion>
-    <scmVersion>2.2.1</scmVersion>
     <resolverVersion>1.9.27</resolverVersion>
     
<project.build.outputTimestamp>2026-09-19T15:43:02Z</project.build.outputTimestamp>
   </properties>
@@ -132,28 +131,6 @@ under the License.
       <version>${resolverVersion}</version>
     </dependency>
 
-    <!-- scm -->
-    <dependency>
-      <groupId>org.apache.maven.scm</groupId>
-      <artifactId>maven-scm-api</artifactId>
-      <version>${scmVersion}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven.scm</groupId>
-      <artifactId>maven-scm-provider-svn-commons</artifactId>
-      <version>${scmVersion}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven.scm</groupId>
-      <artifactId>maven-scm-manager-plexus</artifactId>
-      <version>${scmVersion}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven.scm</groupId>
-      <artifactId>maven-scm-provider-svnexe</artifactId>
-      <version>${scmVersion}</version>
-    </dependency>
-
     <!-- misc -->
     <dependency>
       <groupId>javax.inject</groupId>
diff --git a/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java 
b/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
index 6f5a138..a6c0a3d 100644
--- a/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
+++ b/src/main/java/org/apache/maven/plugin/doap/DoapMojo.java
@@ -65,11 +65,6 @@ import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.ProjectBuilder;
 import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectBuildingRequest;
-import org.apache.maven.scm.manager.NoSuchScmProviderException;
-import org.apache.maven.scm.manager.ScmManager;
-import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
-import org.apache.maven.scm.repository.ScmRepository;
-import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.apache.maven.settings.Settings;
 import org.codehaus.plexus.i18n.I18N;
 import org.codehaus.plexus.util.FileUtils;
@@ -138,14 +133,6 @@ public class DoapMojo extends AbstractMojo {
     // Mojo components
     // ----------------------------------------------------------------------
 
-    /**
-     * Maven SCM Manager.
-     *
-     * @since 1.0
-     */
-    @Inject
-    private ScmManager scmManager;
-
     /**
      * Artifact handler manager, used to build {@link Artifact} instances 
directly instead of through the
      * deprecated <code>ArtifactFactory</code> component.
@@ -1498,23 +1485,23 @@ public class DoapMojo extends AbstractMojo {
      * @param connection not null
      * @see <a 
href="http://usefulinc.com/ns/doap#Repository";>http://usefulinc.com/ns/doap#Repository</a>
      * @see <a 
href="http://usefulinc.com/ns/doap#SVNRepository";>http://usefulinc.com/ns/doap#SVNRepository</a>
+     * @see <a 
href="http://usefulinc.com/ns/doap#GitRepository";>http://usefulinc.com/ns/doap#GitRepository</a>
      */
     private void writeSourceRepository(XMLWriter writer, MavenProject project, 
String connection) {
-        ScmRepository repository = getScmRepository(connection);
+        String[] scm = DoapUtil.splitScmConnection(connection);
+        String repositoryType = scm == null ? null : 
DoapUtil.getScmRepositoryType(scm[0]);
 
         DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), 
"repository");
 
-        if (isScmSystem(repository, "svn")) {
-            DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), 
"SVNRepository");
-
-            SvnScmProviderRepository svnRepo = (SvnScmProviderRepository) 
repository.getProviderRepository();
+        if (repositoryType != null) {
+            DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), 
repositoryType);
 
-            DoapUtil.writeRdfResourceElement(writer, 
doapOptions.getXmlnsPrefix(), "location", svnRepo.getUrl());
+            DoapUtil.writeRdfResourceElement(
+                    writer, doapOptions.getXmlnsPrefix(), "location", 
DoapUtil.removeUserInfo(scm[1]));
         } else {
             /*
-             * Supported DOAP repositories actually unsupported by SCM: 
BitKeeper
-             * (http://usefulinc.com/ns/doap#BKRepository) Arch 
(http://usefulinc.com/ns/doap#ArchRepository) Other SCM
-             * repos are unsupported by DOAP.
+             * CVS, Arch, BitKeeper and other systems: DOAP describes them 
with more than a location, so only a
+             * generic repository is written.
              */
             DoapUtil.writeStartElement(writer, doapOptions.getXmlnsPrefix(), 
"Repository");
 
@@ -1528,31 +1515,10 @@ public class DoapMojo extends AbstractMojo {
         DoapUtil.writeRdfResourceElement(
                 writer, doapOptions.getXmlnsPrefix(), "browse", 
project.getScm().getUrl());
 
-        writer.endElement(); // SVNRepository || Repository
+        writer.endElement(); // typed repository || Repository
         writer.endElement(); // repository
     }
 
-    /**
-     * Return a <code>SCM repository</code> defined by a given url.
-     *
-     * @param scmUrl an SCM URL
-     * @return a valid SCM repository or null
-     */
-    private ScmRepository getScmRepository(String scmUrl) {
-        ScmRepository repo = null;
-        if (!(scmUrl == null || scmUrl.isEmpty())) {
-            try {
-                repo = scmManager.makeScmRepository(scmUrl);
-            } catch (NoSuchScmProviderException | ScmRepositoryException e) {
-                if (getLog().isDebugEnabled()) {
-                    getLog().debug(e.getMessage(), e);
-                }
-            }
-        }
-
-        return repo;
-    }
-
     /**
      * Write a Foaf Organization, for instance:
      * <p/>
@@ -1775,26 +1741,4 @@ public class DoapMojo extends AbstractMojo {
     // Static methods
     // ----------------------------------------------------------------------
 
-    /**
-     * Convenience method that return true is the defined <code>SCM 
repository</code> is a known provider.
-     * <p>
-     * Actually, we fully support SVN by the maven-scm-providers component.
-     * </p>
-     *
-     * @param scmRepository a SCM repository
-     * @param scmProvider   a SCM provider name
-     * @return true if the provider of the given SCM repository is equal to 
the given scm provider
-     * @see <a 
href="http://svn.apache.org/repos/asf/maven/scm/trunk/maven-scm-providers/";>maven-scm-providers</a>
-     */
-    private static boolean isScmSystem(ScmRepository scmRepository, String 
scmProvider) {
-        if (scmProvider == null || scmProvider.isEmpty()) {
-            return false;
-        }
-
-        if (scmRepository != null && 
scmProvider.equalsIgnoreCase(scmRepository.getProvider())) {
-            return true;
-        }
-
-        return false;
-    }
 }
diff --git a/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java 
b/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
index 231284f..6406eac 100644
--- a/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
+++ b/src/main/java/org/apache/maven/plugin/doap/DoapUtil.java
@@ -719,6 +719,70 @@ public class DoapUtil {
         }
     }
 
+    /**
+     * DOAP repository classes for the Maven SCM providers that DOAP describes 
by a location alone.
+     */
+    private static final Map<String, String> SCM_REPOSITORY_TYPES = new 
HashMap<>();
+
+    static {
+        SCM_REPOSITORY_TYPES.put("svn", "SVNRepository");
+        SCM_REPOSITORY_TYPES.put("git", "GitRepository");
+        SCM_REPOSITORY_TYPES.put("hg", "HgRepository");
+        SCM_REPOSITORY_TYPES.put("bazaar", "BazaarBranch");
+        SCM_REPOSITORY_TYPES.put("bzr", "BazaarBranch");
+    }
+
+    /**
+     * Split a Maven SCM connection, 
<code>scm:&lt;provider&gt;:&lt;url&gt;</code> or
+     * <code>scm:&lt;provider&gt;|&lt;url&gt;</code>, into its provider and 
URL.
+     *
+     * @param connection a Maven SCM connection, may be null
+     * @return the provider and the URL, or null when the connection does not 
have that form
+     */
+    static String[] splitScmConnection(String connection) {
+        if (connection == null || !connection.startsWith("scm:")) {
+            return null;
+        }
+        String rest = connection.substring("scm:".length());
+        int delimiter = 0;
+        while (delimiter < rest.length() && rest.charAt(delimiter) != ':' && 
rest.charAt(delimiter) != '|') {
+            delimiter++;
+        }
+        if (delimiter == 0 || delimiter >= rest.length() - 1) {
+            return null;
+        }
+        return new String[] {rest.substring(0, delimiter), 
rest.substring(delimiter + 1)};
+    }
+
+    /**
+     * @param provider a Maven SCM provider id, such as <code>git</code>
+     * @return the DOAP repository class for the provider, or null when DOAP 
needs more than a location for it
+     */
+    static String getScmRepositoryType(String provider) {
+        return provider == null ? null : 
SCM_REPOSITORY_TYPES.get(provider.toLowerCase(Locale.ENGLISH));
+    }
+
+    /**
+     * Remove the user name and password from an <code>http</code>, 
<code>https</code>, <code>svn</code> or
+     * <code>git</code> URL, so they are not published in the DOAP file. Other 
URLs, such as
+     * <code>svn+ssh</code> and <code>file</code>, are returned unchanged.
+     *
+     * @param url not null
+     * @return the URL without user information
+     */
+    static String removeUserInfo(String url) {
+        for (String scheme : new String[] {"http://";, "https://";, "svn://", 
"git://"}) {
+            if (url.startsWith(scheme)) {
+                String rest = url.substring(scheme.length());
+                int slash = rest.indexOf('/');
+                String authority = slash < 0 ? rest : rest.substring(0, slash);
+                int at = authority.lastIndexOf('@');
+                return at < 0 ? url : scheme + rest.substring(at + 1);
+            }
+        }
+        return url;
+    }
+
     /**
      * Write extra for DOAP or any extension.
      *
diff --git a/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java 
b/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java
index f86b5e4..ec02435 100644
--- a/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java
+++ b/src/test/java/org/apache/maven/plugin/doap/DoapMojoTest.java
@@ -548,6 +548,33 @@ class DoapMojoTest {
                         + "number is 10.");
     }
 
+    /**
+     * Verify that a Git connection is written as a DOAP Git repository with a 
plain URL as its location.
+     *
+     * @throws Exception if any
+     */
+    @Test
+    @InjectMojo(goal = "generate", pom = 
"doap-configuration-plugin-config.xml")
+    @Basedir("/unit/doap-configuration/")
+    void testGitRepository(DoapMojo mojo) throws Exception {
+        MavenXpp3Reader pomReader = new MavenXpp3Reader();
+        try (InputStream in = Files.newInputStream(
+                getTestFile("doap-configuration-plugin-config.xml").toPath())) 
{
+            mavenProject.setModel(pomReader.read(in));
+        }
+        
mavenProject.getScm().setConnection("scm:git:https://git.example.org/doap-plugin.git";);
+        
mavenProject.getScm().setDeveloperConnection("scm:git|https://[email protected]/doap.git";);
+        setVariableValueToObject(mojo, "about", mavenProject.getUrl());
+
+        mojo.execute();
+
+        String readed = readFile(new File(getBasedir(), 
"target/doap-configuration.rdf"));
+        assertFalse(readed.contains("<SVNRepository>"));
+        assertTrue(readed.contains("<GitRepository>"));
+        assertTrue(readed.contains("<location 
rdf:resource=\"https://git.example.org/doap-plugin.git\"/>"));
+        assertTrue(readed.contains("<location 
rdf:resource=\"https://git.example.org/doap.git\"/>"));
+    }
+
     private String readFile(File file) throws IOException {
         return new String(Files.readAllBytes(file.toPath()), 
StandardCharsets.UTF_8);
     }
diff --git a/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java 
b/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
index ef9257d..3c9260f 100644
--- a/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
+++ b/src/test/java/org/apache/maven/plugin/doap/DoapUtilTest.java
@@ -37,6 +37,7 @@ import org.codehaus.plexus.util.xml.XMLWriter;
 import org.junit.jupiter.api.Test;
 
 import static org.codehaus.plexus.testing.PlexusExtension.getBasedir;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -242,4 +243,39 @@ class DoapUtilTest {
         assertEquals("developerName2", 
DoapUtil.interpolate("${project.developers[1].name}", project, null));
         assertEquals("myValue", DoapUtil.interpolate("${myKey}", project, 
null));
     }
+
+    @Test
+    void testSplitScmConnection() {
+        assertArrayEquals(
+                new String[] {"git", 
"https://gitbox.apache.org/repos/asf/maven.git"},
+                
DoapUtil.splitScmConnection("scm:git:https://gitbox.apache.org/repos/asf/maven.git";));
+        assertArrayEquals(
+                new String[] {"svn", "https://svn.apache.org/repos/asf/maven"},
+                
DoapUtil.splitScmConnection("scm:svn|https://svn.apache.org/repos/asf/maven";));
+        
assertNull(DoapUtil.splitScmConnection("https://github.com/apache/maven";));
+        assertNull(DoapUtil.splitScmConnection("scm:git"));
+        assertNull(DoapUtil.splitScmConnection("scm:git:"));
+        assertNull(DoapUtil.splitScmConnection(null));
+    }
+
+    @Test
+    void testGetScmRepositoryType() {
+        assertEquals("SVNRepository", DoapUtil.getScmRepositoryType("svn"));
+        assertEquals("GitRepository", DoapUtil.getScmRepositoryType("GIT"));
+        assertEquals("HgRepository", DoapUtil.getScmRepositoryType("hg"));
+        assertEquals("BazaarBranch", DoapUtil.getScmRepositoryType("bzr"));
+        assertNull(DoapUtil.getScmRepositoryType("cvs"));
+        assertNull(DoapUtil.getScmRepositoryType(null));
+    }
+
+    @Test
+    void testRemoveUserInfo() {
+        assertEquals(
+                "https://svn.apache.org/repos/asf";,
+                
DoapUtil.removeUserInfo("https://user:[email protected]/repos/asf";));
+        assertEquals("svn://host/repo", 
DoapUtil.removeUserInfo("svn://user@host/repo"));
+        assertEquals("svn+ssh://user@host/repo", 
DoapUtil.removeUserInfo("svn+ssh://user@host/repo"));
+        assertEquals("[email protected]:apache/maven.git", 
DoapUtil.removeUserInfo("[email protected]:apache/maven.git"));
+        assertEquals("https://host/path@tag";, 
DoapUtil.removeUserInfo("https://host/path@tag";));
+    }
 }

Reply via email to