-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/CopyMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.plugin.mp; | ||
|
||
import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport; | ||
import eu.maveniverse.maven.toolbox.shared.Output; | ||
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; | ||
import java.util.stream.Collectors; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.eclipse.aether.graph.Dependency; | ||
|
||
/** | ||
* Resolves selected dependencies and copies resulting artifacts to target. | ||
*/ | ||
@Mojo(name = "copy", threadSafe = true) | ||
public final class CopyMojo extends MPMojoSupport { | ||
/** | ||
* The target spec. | ||
*/ | ||
@Parameter(property = "targetSpec", required = true) | ||
private String targetSpec; | ||
|
||
/** | ||
* The dependency matcher spec. | ||
*/ | ||
@Parameter(property = "depSpec", required = true) | ||
private String depSpec; | ||
|
||
@Override | ||
protected boolean doExecute(Output output, ToolboxCommando toolboxCommando) throws Exception { | ||
return toolboxCommando.copy( | ||
projectAsResolutionRoot().getDependencies().stream() | ||
.filter(toolboxCommando.parseDependencyMatcherSpec(depSpec)) | ||
.map(Dependency::getArtifact) | ||
.collect(Collectors.toList()), | ||
toolboxCommando.artifactSink(output, targetSpec), | ||
output); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
toolbox/src/main/java/eu/maveniverse/maven/toolbox/plugin/mp/CopyTransitiveMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.plugin.mp; | ||
|
||
import eu.maveniverse.maven.toolbox.plugin.MPMojoSupport; | ||
import eu.maveniverse.maven.toolbox.shared.Output; | ||
import eu.maveniverse.maven.toolbox.shared.ResolutionRoot; | ||
import eu.maveniverse.maven.toolbox.shared.ResolutionScope; | ||
import eu.maveniverse.maven.toolbox.shared.ToolboxCommando; | ||
import java.util.stream.Collectors; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
/** | ||
* Resolves selected dependencies transitively and copies all of them to target. | ||
*/ | ||
@Mojo(name = "copy-transitive", threadSafe = true) | ||
public final class CopyTransitiveMojo extends MPMojoSupport { | ||
/** | ||
* The target spec. | ||
*/ | ||
@Parameter(property = "targetSpec", required = true) | ||
private String targetSpec; | ||
|
||
/** | ||
* The resolution scope to resolve (default is 'runtime'). | ||
*/ | ||
@Parameter(property = "scope", defaultValue = "runtime", required = true) | ||
private String scope; | ||
|
||
/** | ||
* The dependency matcher spec. | ||
*/ | ||
@Parameter(property = "depSpec", required = true) | ||
private String depSpec; | ||
|
||
@Override | ||
protected boolean doExecute(Output output, ToolboxCommando toolboxCommando) throws Exception { | ||
ResolutionRoot project = projectAsResolutionRoot(); | ||
return toolboxCommando.copyTransitive( | ||
ResolutionScope.parse(scope), | ||
projectAsResolutionRoot().getDependencies().stream() | ||
.filter(toolboxCommando.parseDependencyMatcherSpec(depSpec)) | ||
.map(d -> ResolutionRoot.ofLoaded(d.getArtifact()) | ||
.withManagedDependencies(project.getManagedDependencies()) | ||
.build()) | ||
.collect(Collectors.toList()), | ||
toolboxCommando.artifactSink(output, targetSpec), | ||
output); | ||
} | ||
} |