Search in sources :

Example 36 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project wildfly-swarm by wildfly-swarm.

the class PackageMojo method executeSpecific.

@SuppressWarnings("deprecation")
@Override
public void executeSpecific() throws MojoExecutionException, MojoFailureException {
    if (this.skip) {
        getLog().info("Skipping packaging");
        return;
    }
    if (this.project.getPackaging().equals("pom")) {
        getLog().info("Not processing project with pom packaging");
        return;
    }
    initProperties(false);
    final Artifact primaryArtifact = this.project.getArtifact();
    final String finalName = this.project.getBuild().getFinalName();
    final String type = primaryArtifact.getType();
    final File primaryArtifactFile = divineFile();
    if (primaryArtifactFile == null) {
        throw new MojoExecutionException("Cannot package without a primary artifact; please `mvn package` prior to invoking wildfly-swarm:package from the command-line");
    }
    final DeclaredDependencies declaredDependencies = new DeclaredDependencies();
    final BuildTool tool = new BuildTool(mavenArtifactResolvingHelper()).projectArtifact(primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), type, primaryArtifactFile, finalName.endsWith("." + type) ? finalName : String.format("%s.%s", finalName, type)).properties(this.properties).mainClass(this.mainClass).bundleDependencies(this.bundleDependencies).executable(executable).executableScript(executableScript).fractionDetectionMode(fractionDetectMode).hollow(hollow).logger(new SimpleLogger() {

        @Override
        public void debug(String msg) {
            getLog().debug(msg);
        }

        @Override
        public void info(String msg) {
            getLog().info(msg);
        }

        @Override
        public void error(String msg) {
            getLog().error(msg);
        }

        @Override
        public void error(String msg, Throwable t) {
            getLog().error(msg, t);
        }
    });
    this.additionalFractions.stream().map(f -> FractionDescriptor.fromGav(FractionList.get(), f)).map(ArtifactSpec::fromFractionDescriptor).forEach(tool::fraction);
    Map<ArtifactSpec, Set<ArtifactSpec>> buckets = createBuckets(this.project.getArtifacts(), this.project.getDependencies());
    for (ArtifactSpec directDep : buckets.keySet()) {
        if (!(directDep.scope.equals("compile") || directDep.scope.equals("runtime"))) {
            // ignore anything but compile and runtime
            continue;
        }
        Set<ArtifactSpec> transientDeps = buckets.get(directDep);
        if (transientDeps.isEmpty()) {
            declaredDependencies.add(directDep);
        } else {
            for (ArtifactSpec transientDep : transientDeps) {
                declaredDependencies.add(directDep, transientDep);
            }
        }
    }
    tool.declaredDependencies(declaredDependencies);
    this.project.getResources().forEach(r -> tool.resourceDirectory(r.getDirectory()));
    Path uberjarResourcesDir = null;
    if (this.uberjarResources == null) {
        uberjarResourcesDir = Paths.get(this.project.getBasedir().toString()).resolve("src").resolve("main").resolve("uberjar");
    } else {
        uberjarResourcesDir = Paths.get(this.uberjarResources);
    }
    tool.uberjarResourcesDirectory(uberjarResourcesDir);
    this.additionalModules.stream().map(m -> new File(this.project.getBuild().getOutputDirectory(), m)).filter(File::exists).map(File::getAbsolutePath).forEach(tool::additionalModule);
    try {
        File jar = tool.build(finalName + (this.hollow ? "-hollow" : ""), Paths.get(this.projectBuildDir));
        ArtifactHandler handler = new DefaultArtifactHandler("jar");
        Artifact swarmJarArtifact = new DefaultArtifact(primaryArtifact.getGroupId(), primaryArtifact.getArtifactId(), primaryArtifact.getBaseVersion(), primaryArtifact.getScope(), "jar", (this.hollow ? "hollow" : "") + "swarm", handler);
        swarmJarArtifact.setFile(jar);
        this.project.addAttachedArtifact(swarmJarArtifact);
        if (this.project.getPackaging().equals("war")) {
            tool.repackageWar(primaryArtifactFile);
        }
    } catch (Exception e) {
        throw new MojoFailureException("Unable to create -swarm.jar", e);
    }
}
Also used : Path(java.nio.file.Path) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) SimpleLogger(org.wildfly.swarm.spi.meta.SimpleLogger) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) Files(java.nio.file.Files) DeclaredDependencies(org.wildfly.swarm.tools.DeclaredDependencies) Set(java.util.Set) FractionDescriptor(org.wildfly.swarm.fractions.FractionDescriptor) BuildTool(org.wildfly.swarm.tools.BuildTool) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) FractionList(org.wildfly.swarm.fractions.FractionList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) Paths(java.nio.file.Paths) Map(java.util.Map) Artifact(org.apache.maven.artifact.Artifact) LifecyclePhase(org.apache.maven.plugins.annotations.LifecyclePhase) ResolutionScope(org.apache.maven.plugins.annotations.ResolutionScope) Path(java.nio.file.Path) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) Set(java.util.Set) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DeclaredDependencies(org.wildfly.swarm.tools.DeclaredDependencies) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) SimpleLogger(org.wildfly.swarm.spi.meta.SimpleLogger) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) BuildTool(org.wildfly.swarm.tools.BuildTool) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 37 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarDependenciesAnalysisTest method testDependencyNowProvided.

public void testDependencyNowProvided() throws Exception {
    // setup test data
    final String testId = "dependency-now-provided";
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact.setArtifactId("lib-test");
    jarArtifact.setVersion("1.0");
    ArtifactStub jarArtifact2 = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact2.setArtifactId("lib-test");
    jarArtifact2.setVersion("1.0");
    jarArtifact2.setScope(Artifact.SCOPE_PROVIDED);
    doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, new ArtifactStub[] { jarArtifact2 }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, null);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub)

Example 38 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarDependenciesAnalysisTest method testDependencyWithUpdatedVersion.

public void testDependencyWithUpdatedVersion() throws Exception {
    // setup test data
    final String testId = "dependency-update-version";
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact.setArtifactId("lib-test");
    jarArtifact.setVersion("1.0");
    ArtifactStub jarArtifact2 = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact2.setArtifactId("lib-test");
    jarArtifact2.setVersion("2.0");
    doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, new ArtifactStub[] { jarArtifact2 }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, new String[] { "WEB-INF/lib/lib-test-2.0.jar" });
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub)

Example 39 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarDependenciesAnalysisTest method testNoChange.

public void testNoChange() throws Exception {
    // setup test data
    final String testId = "no-change";
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact.setArtifactId("lib-test");
    jarArtifact.setVersion("1.0");
    doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, new ArtifactStub[] { jarArtifact }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, new String[] { "WEB-INF/lib/lib-test-1.0.jar" });
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub)

Example 40 with ArtifactHandler

use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.

the class WarDependenciesAnalysisTest method testRemovedDependency.

public void testRemovedDependency() throws Exception {
    // setup test data
    final String testId = "remove-dependency";
    final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
    jarArtifact.setArtifactId("lib-test");
    jarArtifact.setVersion("1.0");
    doTestTwiceWithUpdatedDependency(testId, new ArtifactStub[] { jarArtifact }, null, new String[] { "WEB-INF/lib/lib-test-1.0.jar" }, null);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)51 File (java.io.File)26 Artifact (org.apache.maven.artifact.Artifact)26 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)23 VersionRange (org.apache.maven.artifact.versioning.VersionRange)17 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)10 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 MavenProject (org.apache.maven.project.MavenProject)6 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)6 ArrayList (java.util.ArrayList)5 Random (java.util.Random)4 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)4 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)4 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)4 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)4 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)4