Search in sources :

Example 26 with DefaultArtifactHandler

use of org.apache.maven.artifact.handler.DefaultArtifactHandler 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 27 with DefaultArtifactHandler

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

the class ResolutionManagementInfoTest method testAddMultiArtifactWithReplacemen.

public void testAddMultiArtifactWithReplacemen() throws Exception {
    ResolutionManagementInfo rmi = new ResolutionManagementInfo(new MavenProject());
    Artifact a1 = new DefaultArtifact("groupid", "a1", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler());
    Artifact a2 = new DefaultArtifact("groupid", "a2", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler());
    Artifact a3 = new DefaultArtifact("groupid", "a3", VersionRange.createFromVersion("1.0"), "test", "jar", null, new DefaultArtifactHandler());
    rmi.addArtifacts(new HashSet<Artifact>(Arrays.asList(a1, a2, a3)));
    Artifact b2 = new DefaultArtifact("groupid", "a2", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler());
    Artifact b3 = new DefaultArtifact("groupid", "a3", VersionRange.createFromVersion("1.0"), "compile", "jar", null, new DefaultArtifactHandler());
    rmi.addArtifacts(new HashSet<Artifact>(Arrays.asList(b2, b3)));
    assertEquals(3, rmi.getArtifacts().size());
    int compile = 0;
    int test = 0;
    for (Artifact artifact : rmi.getArtifacts()) {
        if (Artifact.SCOPE_COMPILE.equals(artifact.getScope())) {
            compile++;
        } else {
            test++;
        }
    }
    assertEquals(2, compile);
    assertEquals(1, test);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 28 with DefaultArtifactHandler

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

the class TestSourcesMarkerFileHandler method setUp.

protected void setUp() throws Exception {
    super.setUp();
    ArtifactHandler ah = new DefaultArtifactHandler();
    VersionRange vr = VersionRange.createFromVersion("1.1");
    Artifact artifact = new DefaultArtifact("test", "1", vr, Artifact.SCOPE_COMPILE, "jar", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "2", vr, Artifact.SCOPE_PROVIDED, "war", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "3", vr, Artifact.SCOPE_TEST, "sources", "", ah, false);
    artifacts.add(artifact);
    artifact = new DefaultArtifact("test", "4", vr, Artifact.SCOPE_RUNTIME, "zip", "", ah, false);
    artifacts.add(artifact);
    // pick random output location
    Random a = new Random();
    outputFolder = new File("target/markers" + a.nextLong() + "/");
    outputFolder.delete();
    assertFalse(outputFolder.exists());
}
Also used : DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) Random(java.util.Random) VersionRange(org.apache.maven.artifact.versioning.VersionRange) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 29 with DefaultArtifactHandler

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

the class RemoteResourcesMojoTest method testFilteredBundles.

public void testFilteredBundles() throws Exception {
    final MavenProjectResourcesStub project = createTestProject("default-filterbundles");
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.1" });
    setupDefaultProject(project);
    ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
    String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.1"), null, "jar", "", new DefaultArtifactHandler()));
    File file = new File(repo.getBasedir() + "/" + path + ".jar");
    file.getParentFile().mkdirs();
    buildResourceBundle("default-filterbundles-create", null, new String[] { "FILTER.txt.vm" }, file);
    mojo.execute();
    // executing a second time (example: forked lifecycle) should still work
    mojo.execute();
    file = (File) getVariableValueFromObject(mojo, "outputDirectory");
    file = new File(file, "FILTER.txt");
    assertTrue(file.exists());
    String data = FileUtils.fileRead(file);
    assertTrue(data.contains("2007"));
    assertTrue(data.contains("default-filterbundles"));
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 30 with DefaultArtifactHandler

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

the class RemoteResourcesMojoTest method testSimpleBundlesWithClassifier.

public void testSimpleBundlesWithClassifier() throws Exception {
    final MavenProjectResourcesStub project = createTestProject("default-simplebundles");
    final ProcessRemoteResourcesMojo mojo = lookupProcessMojoWithSettings(project, new String[] { "test:test:1.0:jar:test" });
    setupDefaultProject(project);
    ArtifactRepository repo = (ArtifactRepository) getVariableValueFromObject(mojo, "localRepository");
    String path = repo.pathOf(new DefaultArtifact("test", "test", VersionRange.createFromVersion("1.0"), null, "jar", "test", new DefaultArtifactHandler()));
    File file = new File(repo.getBasedir() + "/" + path + ".jar");
    file.getParentFile().mkdirs();
    buildResourceBundle("default-simplebundles-create", null, new String[] { "SIMPLE.txt" }, file);
    mojo.execute();
    file = (File) getVariableValueFromObject(mojo, "outputDirectory");
    file = new File(file, "SIMPLE.txt");
    assertTrue(file.exists());
}
Also used : MavenProjectResourcesStub(org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub) DefaultArtifactHandler(org.apache.maven.artifact.handler.DefaultArtifactHandler) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) File(java.io.File) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Aggregations

DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)31 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)29 Artifact (org.apache.maven.artifact.Artifact)21 File (java.io.File)20 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)8 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)8 VersionRange (org.apache.maven.artifact.versioning.VersionRange)7 MavenProjectResourcesStub (org.apache.maven.plugin.resources.remote.stub.MavenProjectResourcesStub)7 MavenProject (org.apache.maven.project.MavenProject)6 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 FileInputStream (java.io.FileInputStream)2 Path (java.nio.file.Path)2 RemoteException (java.rmi.RemoteException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Random (java.util.Random)2 ArtifactMetadataSource (org.apache.maven.artifact.metadata.ArtifactMetadataSource)2