package io.trygvis.maven.classpath; import static java.util.Collections.singletonList; import static java.util.Collections.sort; import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_RESOURCES; import static org.apache.maven.plugins.annotations.ResolutionScope.RUNTIME; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.model.Resource; 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.apache.maven.project.MavenProject; import org.codehaus.plexus.util.IOUtil; import org.sonatype.plexus.build.incremental.BuildContext; /** * Writes the path of each compile/runtime dependency of a project to a file, * where each path is relative to the root of a maven repository. *
* For example, if the project depends on commons-lang 2.6 and commons-math 2.2, * then the file written will contain the line: *
* commons-lang/commons-lang/2.6/commons-lang-2.6.jar * org/apache/commons/commons-math/2.2/commons-math-2.2.jar **/ @Mojo(name = "classpath", defaultPhase = GENERATE_RESOURCES, requiresDependencyCollection = RUNTIME) public class ClasspathMojo extends AbstractMojo { @Component private BuildContext context; @Parameter(property = "project", required = true, readonly = true) private MavenProject project; @Parameter(defaultValue = "${project.build.directory}/generated-resources/classpath", property = "classpathOutputDirectory") private File outputDirectory; @Parameter(defaultValue = "classpath.txt") private String file; @Parameter(property = "sort", defaultValue = "false") private boolean sort; public void execute() throws MojoExecutionException, MojoFailureException { List