[java-mvn-enforcer] 03/03: Stop using deprecated artifact factory

Rod Widdowson rdw at steadingsoftware.com
Mon Nov 15 13:45:30 UTC 2021


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-mvn-enforcer.

View the commit online:
http://git.shibboleth.net/view/?p=java-mvn-enforcer.git;a=commit;h=283ff07ef3b7d05ce684c300c73480670460a554

commit 283ff07ef3b7d05ce684c300c73480670460a554
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Nov 15 13:44:16 2021 +0000

    Stop using deprecated artifact factory
    
    Grab the artifact repository and use that.  The artifact repsository
    then calls the artifact factory - bt thats not our code.
---
 .../shibboleth/mvn/enforcer/impl/JarEnforcer.java  | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
index 7e15c6a..a1b332b 100644
--- a/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
+++ b/src/main/java/net/shibboleth/mvn/enforcer/impl/JarEnforcer.java
@@ -35,7 +35,6 @@ import java.util.List;
 import javax.annotation.Nullable;
 
 import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
@@ -44,6 +43,7 @@ import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
 import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
 import org.slf4j.Logger;
 
 import net.shibboleth.mvn.enforcer.impl.GPGKeyRing.Signature;
@@ -55,7 +55,6 @@ import net.shibboleth.utilities.java.support.xml.XMLConstants;
 /** {@link EnforcerRule} implementation to check various
  * things of interest about our distributions.
  */
- at SuppressWarnings("deprecation")
 public class JarEnforcer implements EnforcerRule, MavenLoader{
 
     /* 
@@ -89,12 +88,6 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
     /** Will we check that all jars in ~/.m2/... jars have valid signatures? */
     private boolean checkM2;
     
-    /** Our artifact factory.  This is deprecated but there seems no easy way to create one.
-     * (No replacement is suggested and the best code out there creates a pom file and parses it.
-     * Really?
-     */
-    private ArtifactFactory artifactFactory;
-
     /** Our artifact resolver. */
     private ArtifactResolver artifactResolver;
 
@@ -107,6 +100,9 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
     /** Our Maven log. */
     private Logger log;
 
+    /** The {@link RepositorySystem} we will use. */
+    private RepositorySystem repositorySystem;
+
     @Override
     public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
         EnforcerLogger.setMavenLogger(helper.getLog());
@@ -125,16 +121,12 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
             throw new EnforcerRuleException("No <jarsDirs/> provided");
         }
         try {
-            org.apache.maven.repository.RepositorySystem rp = helper.getComponent(org.apache.maven.repository.RepositorySystem.class);
-            if (rp != null) {
-                log.error("Non Null repo system!");
-            }
-            artifactFactory = helper.getComponent(ArtifactFactory.class);
+            repositorySystem = helper.getComponent(org.apache.maven.repository.RepositorySystem.class);
             artifactResolver = helper.getComponent(ArtifactResolver.class);
             session = (MavenSession) helper.evaluate( "${session}" );
             project = (MavenProject) helper.evaluate( "${project}" );
             final Path target = Path.of(helper.evaluate( "${basedir}" ).toString()).resolve("target"); 
-            if (artifactFactory == null || artifactResolver == null || session == null || project == null)  {
+            if (repositorySystem == null || artifactResolver == null || session == null || project == null)  {
                 throw new EnforcerRuleException("Could not set up artifact environment");
             }
             final Path pom  = Path.of(parentPomDir).resolve("pom.xml");
@@ -331,7 +323,7 @@ public class JarEnforcer implements EnforcerRule, MavenLoader{
      * @throws Exception
      */
     @Nullable public File downloadArtifact(final String groupId, final String artifactId, final String version, final String type) throws Exception {
-        final Artifact mavenArtifact = artifactFactory.createArtifact(groupId,artifactId, version, "", type);
+        final Artifact mavenArtifact = repositorySystem.createArtifact(groupId,artifactId, version, "", type);
 
         if (mavenArtifact == null) {
             log.error("Could not create {}:{}:{}:{}", groupId, artifactId, version, type);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list