use of org.apache.maven.artifact.DefaultArtifact 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);
}
}
use of org.apache.maven.artifact.DefaultArtifact in project build-info by JFrogDev.
the class ArtifactorySonatypeRepositoryListener method toMavenArtifact.
/**
* Converts org.sonatype.aether.artifact.Artifact objects into org.apache.maven.artifact.Artifact objects.
*/
private org.apache.maven.artifact.Artifact toMavenArtifact(final org.sonatype.aether.artifact.Artifact art, String scope) {
if (art == null) {
return null;
}
String classifier = art.getClassifier();
classifier = classifier == null ? "" : classifier;
DefaultArtifact artifact = new DefaultArtifact(art.getGroupId(), art.getArtifactId(), art.getVersion(), scope, art.getExtension(), classifier, null);
artifact.setFile(art.getFile());
return artifact;
}
use of org.apache.maven.artifact.DefaultArtifact in project build-info by JFrogDev.
the class ArtifactoryEclipseRepositoryListener method toMavenArtifact.
/**
* Converts org.eclipse.aether.artifact.Artifact objects into org.apache.maven.artifact.Artifact objects.
*/
private org.apache.maven.artifact.Artifact toMavenArtifact(final org.eclipse.aether.artifact.Artifact art, String scope) {
if (art == null) {
return null;
}
String classifier = art.getClassifier();
classifier = classifier == null ? "" : classifier;
DefaultArtifact artifact = new DefaultArtifact(art.getGroupId(), art.getArtifactId(), art.getVersion(), scope, art.getExtension(), classifier, null);
artifact.setFile(art.getFile());
return artifact;
}
use of org.apache.maven.artifact.DefaultArtifact 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);
}
use of org.apache.maven.artifact.DefaultArtifact in project maven-plugins by apache.
the class MinijarFilterTest method mockProject.
private MavenProject mockProject(File file) {
MavenProject mavenProject = mock(MavenProject.class);
Artifact artifact = mock(Artifact.class);
when(artifact.getGroupId()).thenReturn("com");
when(artifact.getArtifactId()).thenReturn("aid");
when(artifact.getVersion()).thenReturn("1.9");
when(artifact.getClassifier()).thenReturn("classifier1");
when(artifact.getScope()).thenReturn(Artifact.SCOPE_COMPILE);
when(mavenProject.getArtifact()).thenReturn(artifact);
DefaultArtifact dependencyArtifact = new DefaultArtifact("dep.com", "dep.aid", "1.0", "compile", "jar", "classifier2", null);
dependencyArtifact.setFile(file);
Set<Artifact> artifacts = new TreeSet<Artifact>();
artifacts.add(dependencyArtifact);
when(mavenProject.getArtifacts()).thenReturn(artifacts);
when(mavenProject.getArtifact().getFile()).thenReturn(file);
return mavenProject;
}
Aggregations