You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2018/07/31 17:21:40 UTC

[GitHub] khmarbaise closed pull request #20: [MRESOLVER-40] Convert legacy Plexus components into JSR-330 annotations

khmarbaise closed pull request #20: [MRESOLVER-40] Convert legacy Plexus components into JSR-330 annotations
URL: https://github.com/apache/maven-resolver/pull/20
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml b/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml
index 4496679a..cf88db24 100644
--- a/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml
+++ b/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml
@@ -73,6 +73,22 @@
       <groupId>org.apache.maven.resolver</groupId>
       <artifactId>maven-resolver-util</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.plugin-tools</groupId>
+      <artifactId>maven-plugin-annotations</artifactId>
+      <scope>provided</scope>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <scope>provided</scope>
+    </dependency>
   </dependencies>
 
   <profiles>
diff --git a/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java
index 38b9f2d6..57e09792 100644
--- a/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java
+++ b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java
@@ -24,6 +24,9 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
 import org.eclipse.aether.RepositorySystem;
 import org.eclipse.aether.RepositorySystemSession;
 import org.eclipse.aether.artifact.Artifact;
@@ -32,44 +35,39 @@
 import org.eclipse.aether.resolution.ArtifactRequest;
 import org.eclipse.aether.resolution.ArtifactResolutionException;
 import org.eclipse.aether.resolution.ArtifactResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Resolves a single artifact (not including its transitive dependencies).
- * 
- * @goal resolve-artifact
  */
+@Mojo( name = "resolve-artifact", threadSafe = true )
 public class ResolveArtifactMojo
     extends AbstractMojo
 {
-
+    private static final Logger LOGGER = LoggerFactory.getLogger( ResolveArtifactMojo.class );
     /**
      * The entry point to Maven Artifact Resolver, i.e. the component doing all the work.
-     * 
-     * @component
      */
+    @Component
     private RepositorySystem repoSystem;
 
     /**
      * The current repository/network configuration of Maven.
-     * 
-     * @parameter default-value="${repositorySystemSession}"
-     * @readonly
      */
+    @Parameter( defaultValue = "${repositorySystemSession}", readonly = true )
     private RepositorySystemSession repoSession;
 
     /**
      * The project's remote repositories to use for the resolution.
-     * 
-     * @parameter default-value="${project.remoteProjectRepositories}"
-     * @readonly
      */
+    @Parameter( defaultValue = "${project.remotePluginRepositories}", readonly = true )
     private List<RemoteRepository> remoteRepos;
 
     /**
      * The {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>} of the artifact to resolve.
-     * 
-     * @parameter property="resolver.artifactCoords"
      */
+    @Parameter ( property = "resolver.artifactCoords", readonly = true )
     private String artifactCoords;
 
     /**
@@ -92,7 +90,7 @@ public void execute()
         request.setArtifact( artifact );
         request.setRepositories( remoteRepos );
 
-        getLog().info( "Resolving artifact " + artifact + " from " + remoteRepos );
+        LOGGER.info( "Resolving artifact {} from {}", artifact, remoteRepos );
 
         ArtifactResult result;
         try
@@ -104,8 +102,8 @@ public void execute()
             throw new MojoExecutionException( e.getMessage(), e );
         }
 
-        getLog().info( "Resolved artifact " + artifact + " to " + result.getArtifact().getFile() + " from "
-                           + result.getRepository() );
+        LOGGER.info( "Resolved artifact {} to {} from {}", artifact, result.getArtifact().getFile(),
+                result.getRepository() );
     }
 
 }
diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java
index fcec471e..6b1691af 100644
--- a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java
+++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/guice/DemoResolverModule.java
@@ -26,7 +26,7 @@
 import javax.inject.Named;
 import javax.inject.Singleton;
 
-import org.apache.maven.repository.internal.MavenAetherModule;
+import org.apache.maven.repository.internal.MavenResolverModule;
 import org.eclipse.aether.connector.basic.BasicRepositoryConnectorFactory;
 import org.eclipse.aether.spi.connector.RepositoryConnectorFactory;
 import org.eclipse.aether.spi.connector.transport.TransporterFactory;
@@ -44,7 +44,7 @@
     @Override
     protected void configure()
     {
-        install( new MavenAetherModule() );
+        install( new MavenResolverModule() );
         // alternatively, use the Guice Multibindings extensions
         bind( RepositoryConnectorFactory.class ).annotatedWith( Names.named( "basic" ) ).to( BasicRepositoryConnectorFactory.class );
         bind( TransporterFactory.class ).annotatedWith( Names.named( "file" ) ).to( FileTransporterFactory.class );
@@ -55,7 +55,7 @@ protected void configure()
     @Singleton
     Set<RepositoryConnectorFactory> provideRepositoryConnectorFactories( @Named( "basic" ) RepositoryConnectorFactory basic )
     {
-        Set<RepositoryConnectorFactory> factories = new HashSet<RepositoryConnectorFactory>();
+        Set<RepositoryConnectorFactory> factories = new HashSet<>();
         factories.add( basic );
         return Collections.unmodifiableSet( factories );
     }
@@ -65,7 +65,7 @@ protected void configure()
     Set<TransporterFactory> provideTransporterFactories( @Named( "file" ) TransporterFactory file,
                                                          @Named( "http" ) TransporterFactory http )
     {
-        Set<TransporterFactory> factories = new HashSet<TransporterFactory>();
+        Set<TransporterFactory> factories = new HashSet<>();
         factories.add( file );
         factories.add( http );
         return Collections.unmodifiableSet( factories );
diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/plexus/PlexusRepositorySystemFactory.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/plexus/PlexusRepositorySystemFactory.java
deleted file mode 100644
index 616f19c2..00000000
--- a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/plexus/PlexusRepositorySystemFactory.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.maven.resolver.examples.plexus;
-
-/*
- * 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.
- */
-
-import org.codehaus.plexus.ContainerConfiguration;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import org.codehaus.plexus.PlexusConstants;
-import org.eclipse.aether.RepositorySystem;
-
-/**
- * A factory for repository system instances that employs Plexus to wire up the system's components.
- */
-public class PlexusRepositorySystemFactory
-{
-
-    public static RepositorySystem newRepositorySystem()
-    {
-        /*
-         * Maven Artifact Resolver's components are equipped with plexus-specific metadata to enable discovery and
-         * wiring of components by a Plexus container so this is as easy as looking up the implementation.
-         */
-        try
-        {
-            ContainerConfiguration config = new DefaultContainerConfiguration();
-            config.setAutoWiring( true );
-            config.setClassPathScanning( PlexusConstants.SCANNING_INDEX );
-            return new DefaultPlexusContainer( config ).lookup( RepositorySystem.class );
-        }
-        catch ( Exception e )
-        {
-            throw new IllegalStateException( "dependency injection failed", e );
-        }
-    }
-
-}
diff --git a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java
index 62db10ee..7a4eb21f 100644
--- a/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java
+++ b/maven-resolver-demos/maven-resolver-demo-snippets/src/main/java/org/apache/maven/resolver/examples/util/Booter.java
@@ -20,7 +20,7 @@
  */
 
 import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
@@ -41,7 +41,6 @@ public static RepositorySystem newRepositorySystem()
         return org.apache.maven.resolver.examples.manual.ManualRepositorySystemFactory.newRepositorySystem();
         // return org.eclipse.aether.examples.guice.GuiceRepositorySystemFactory.newRepositorySystem();
         // return org.eclipse.aether.examples.sisu.SisuRepositorySystemFactory.newRepositorySystem();
-        // return org.eclipse.aether.examples.plexus.PlexusRepositorySystemFactory.newRepositorySystem();
     }
 
     public static DefaultRepositorySystemSession newRepositorySystemSession( RepositorySystem system )
@@ -62,7 +61,7 @@ public static DefaultRepositorySystemSession newRepositorySystemSession( Reposit
 
     public static List<RemoteRepository> newRepositories( RepositorySystem system, RepositorySystemSession session )
     {
-        return new ArrayList<RemoteRepository>( Arrays.asList( newCentralRepository() ) );
+        return new ArrayList<>( Collections.singletonList( newCentralRepository() ) );
     }
 
     private static RemoteRepository newCentralRepository()
diff --git a/maven-resolver-transport-wagon/pom.xml b/maven-resolver-transport-wagon/pom.xml
index 7a980ab4..df46bb0a 100644
--- a/maven-resolver-transport-wagon/pom.xml
+++ b/maven-resolver-transport-wagon/pom.xml
@@ -64,12 +64,6 @@
       <scope>provided</scope>
       <optional>true</optional>
     </dependency>
-    <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-component-annotations</artifactId>
-      <scope>provided</scope>
-      <optional>true</optional>
-    </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-classworlds</artifactId>
@@ -121,10 +115,6 @@
 
   <build>
     <plugins>
-      <plugin>
-        <groupId>org.codehaus.plexus</groupId>
-        <artifactId>plexus-component-metadata</artifactId>
-      </plugin>
       <plugin>
         <groupId>org.eclipse.sisu</groupId>
         <artifactId>sisu-maven-plugin</artifactId>
diff --git a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonConfigurator.java b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonConfigurator.java
index 7fe22b8f..b4bf957c 100644
--- a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonConfigurator.java
+++ b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonConfigurator.java
@@ -24,8 +24,6 @@
 import org.apache.maven.wagon.Wagon;
 import org.codehaus.plexus.PlexusContainer;
 import org.codehaus.plexus.classworlds.realm.ClassRealm;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
 import org.codehaus.plexus.component.configurator.AbstractComponentConfigurator;
 import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
 import org.codehaus.plexus.component.configurator.ConfigurationListener;
@@ -36,34 +34,27 @@
 import org.codehaus.plexus.util.xml.Xpp3Dom;
 import org.eclipse.aether.transport.wagon.WagonConfigurator;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
 /**
  * A wagon configurator based on the Plexus component configuration framework.
  */
-@Component( role = WagonConfigurator.class, hint = "plexus" )
+@Named ( "plexus" )
+@Singleton
 public class PlexusWagonConfigurator
     implements WagonConfigurator
 {
-
-    @Requirement
     private PlexusContainer container;
 
-    /**
-     * Creates an uninitialized wagon configurator.
-     * 
-     * @noreference This constructor only supports the Plexus IoC container and should not be called directly by
-     *              clients.
-     */
-    public PlexusWagonConfigurator()
-    {
-        // enables no-arg constructor
-    }
-
     /**
      * Creates a wagon configurator using the specified Plexus container.
      *
      * @param container The Plexus container instance to use, must not be {@code null}.
      */
-    public PlexusWagonConfigurator( PlexusContainer container )
+    @Inject
+    public PlexusWagonConfigurator( final PlexusContainer container )
     {
         this.container = requireNonNull( container, "plexus container cannot be null" );
     }
@@ -71,7 +62,7 @@ public PlexusWagonConfigurator( PlexusContainer container )
     public void configure( Wagon wagon, Object configuration )
         throws Exception
     {
-        PlexusConfiguration config = null;
+        PlexusConfiguration config;
         if ( configuration instanceof PlexusConfiguration )
         {
             config = (PlexusConfiguration) configuration;
diff --git a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonProvider.java b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonProvider.java
index d534695a..6b46f679 100644
--- a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonProvider.java
+++ b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/PlexusWagonProvider.java
@@ -23,38 +23,29 @@
 
 import org.apache.maven.wagon.Wagon;
 import org.codehaus.plexus.PlexusContainer;
-import org.codehaus.plexus.component.annotations.Component;
-import org.codehaus.plexus.component.annotations.Requirement;
 import org.eclipse.aether.transport.wagon.WagonProvider;
 
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
 /**
  * A wagon provider backed by a Plexus container and the wagons registered with this container.
  */
-@Component( role = WagonProvider.class, hint = "plexus" )
+@Named( "plexus" )
+@Singleton
 public class PlexusWagonProvider
     implements WagonProvider
 {
-
-    @Requirement
     private PlexusContainer container;
 
-    /**
-     * Creates an uninitialized wagon provider.
-     * 
-     * @noreference This constructor only supports the Plexus IoC container and should not be called directly by
-     *              clients.
-     */
-    public PlexusWagonProvider()
-    {
-        // enables no-arg constructor
-    }
-
     /**
      * Creates a wagon provider using the specified Plexus container.
      *
      * @param container The Plexus container instance to use, must not be {@code null}.
      */
-    public PlexusWagonProvider( PlexusContainer container )
+    @Inject
+    public PlexusWagonProvider( final PlexusContainer container )
     {
         this.container = requireNonNull( container, "plexus container cannot be null" );
     }
diff --git a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/package-info.java b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/package-info.java
index df14e9c5..1d87669f 100644
--- a/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/package-info.java
+++ b/maven-resolver-transport-wagon/src/main/java/org/eclipse/aether/internal/transport/wagon/package-info.java
@@ -18,7 +18,7 @@
  * under the License.
  */
 /**
- * Integration with the Plexus IoC container which is the native runtime environment expected by many wagon
+ * Integration with the IoC container which is the native runtime environment expected by many wagon
  * implementations.
  */
 package org.eclipse.aether.internal.transport.wagon;
diff --git a/pom.xml b/pom.xml
index 7b8d6428..5718aa4c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -159,12 +159,6 @@
         <version>1</version>
         <scope>provided</scope>
       </dependency>
-      <dependency>
-        <groupId>org.codehaus.plexus</groupId>
-        <artifactId>plexus-component-annotations</artifactId>
-        <version>1.7.1</version>
-        <scope>provided</scope>
-      </dependency>
 
       <dependency>
         <groupId>org.eclipse.sisu</groupId>
@@ -316,19 +310,6 @@
             </systemPropertyVariables>
           </configuration>
         </plugin>
-        <plugin>
-          <groupId>org.codehaus.plexus</groupId>
-          <artifactId>plexus-component-metadata</artifactId>
-          <executions>
-            <execution>
-              <id>generate-components-xml</id>
-              <phase>process-classes</phase>
-              <goals>
-                <goal>generate-metadata</goal>
-              </goals>
-            </execution>
-          </executions>
-        </plugin>
         <plugin>
           <groupId>org.eclipse.sisu</groupId>
           <artifactId>sisu-maven-plugin</artifactId>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services