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 2022/06/28 13:20:03 UTC

[GitHub] [maven-integration-testing] gnodet commented on a diff in pull request #178: Use a plugin to download all dependencies to bypass conflict resolution

gnodet commented on code in PR #178:
URL: https://github.com/apache/maven-integration-testing/pull/178#discussion_r908471091


##########
core-it-support/core-it-bootstrap/src/main/java/org/apache/maven/its/bootstrap/DownloadMojo.java:
##########
@@ -0,0 +1,153 @@
+package org.apache.maven.its.bootstrap;
+
+/*
+ * 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 java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.plugin.AbstractMojo;
+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.apache.maven.project.DefaultProjectBuildingRequest;
+import org.apache.maven.project.ProjectBuildingRequest;
+import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver;
+import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Boostrap plugin to download all required dependencies
+ */
+@Mojo( name = "download" )
+public class DownloadMojo
+        extends AbstractMojo
+{
+
+    /**
+     * A list of artifacts coordinates.
+     */
+    @Parameter
+    private List<Dependency> dependencies = new ArrayList<>();
+
+    /**
+     * A list of string of the form groupId:artifactId:version[:packaging[:classifier]].
+     */
+    @Parameter
+    private List<String> artifacts = new ArrayList<>();
+
+    /**
+     * A file containing lines of the form groupId:artifactId:version[:packaging[:classifier]].
+     */
+    @Parameter
+    private File file;
+
+    @Component
+    private DependencyResolver dependencyResolver;
+
+    @Component
+    private MavenSession session;
+
+    @Override
+    public void execute() throws MojoFailureException
+    {
+        if ( file != null && file.exists() )
+        {
+            try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) )
+            {
+                while ( true )
+                {
+                    String line = reader.readLine();
+                    if ( line != null )
+                    {
+                        artifacts.add( line );
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+            }
+            catch ( IOException e )
+            {
+                throw ( MojoFailureException ) new MojoFailureException(
+                                "Unable to read dependencies: " + file ).initCause( e );
+            }
+        }
+        for ( String artifact : artifacts )
+        {
+            if ( artifact != null )
+            {
+                String trimmed = artifact.trim();
+                if ( !trimmed.isEmpty() && !trimmed.startsWith( "#" ) )

Review Comment:
   Well, `artifacts` can also be filled from the plugin configuration, so I though it could eventually be useful to support comments there as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org