use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeTestScope.
public void testCopyDependenciesMojoIncludeTestScope() throws Exception {
mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
mojo.includeScope = "test";
mojo.execute();
ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
Set<Artifact> artifacts = mojo.getProject().getArtifacts();
for (Artifact artifact : artifacts) {
String fileName = DependencyUtil.getFormattedFileName(artifact, false);
File file = new File(mojo.outputDirectory, fileName);
assertEquals(saf.include(artifact), file.exists());
}
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class TestCopyDependenciesMojo2 method testCopyDependenciesMojoIncludeRuntimeScope.
public void testCopyDependenciesMojoIncludeRuntimeScope() throws Exception {
mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
mojo.includeScope = "runtime";
mojo.execute();
ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
Set<Artifact> artifacts = mojo.getProject().getArtifacts();
for (Artifact artifact : artifacts) {
String fileName = DependencyUtil.getFormattedFileName(artifact, false);
File file = new File(mojo.outputDirectory, fileName);
assertEquals(saf.include(artifact), file.exists());
}
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class TestUnpackDependenciesMojo method testIncludeCompileScope.
public void testIncludeCompileScope() throws Exception {
mojo.getProject().setArtifacts(stubFactory.getScopedArtifacts());
mojo.getProject().setDependencyArtifacts(new HashSet<Artifact>());
mojo.includeScope = "compile";
mojo.execute();
ScopeArtifactFilter saf = new ScopeArtifactFilter(mojo.includeScope);
for (Artifact artifact : (Iterable<Artifact>) mojo.getProject().getArtifacts()) {
assertUnpacked(saf.include(artifact), artifact);
}
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class RarMojo method execute.
public void execute() throws MojoExecutionException {
if (skip) {
getLog().info("Skipping rar generation.");
return;
}
// Check if jar file is there and if requested, copy it
try {
if (includeJar) {
File generatedJarFile = new File(outputDirectory, finalName + ".jar");
if (generatedJarFile.exists()) {
getLog().info("Including generated jar file[" + generatedJarFile.getName() + "]");
FileUtils.copyFileToDirectory(generatedJarFile, getBuildDir());
}
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying generated Jar file", e);
}
// Copy dependencies
try {
Set<Artifact> artifacts = project.getArtifacts();
for (Artifact artifact : artifacts) {
ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
if (!artifact.isOptional() && filter.include(artifact) && artifact.getArtifactHandler().isAddedToClasspath()) {
getLog().info("Copying artifact[" + artifact.getGroupId() + ", " + artifact.getId() + ", " + artifact.getScope() + "]");
FileUtils.copyFileToDirectory(artifact.getFile(), getBuildDir());
}
}
} catch (IOException e) {
throw new MojoExecutionException("Error copying RAR dependencies", e);
}
resourceHandling();
// Include custom manifest if necessary
try {
includeCustomRaXmlFile();
} catch (IOException e) {
throw new MojoExecutionException("Error copying ra.xml file", e);
}
// Check if connector deployment descriptor is there
File ddFile = new File(getBuildDir(), RA_XML_URI);
if (!ddFile.exists() && warnOnMissingRaXml) {
getLog().warn("Connector deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
}
File rarFile = getRarFile(outputDirectory, finalName, classifier);
try {
MavenArchiver archiver = new MavenArchiver();
archiver.setArchiver(jarArchiver);
archiver.setOutputFile(rarFile);
// Include custom manifest if necessary
includeCustomManifestFile();
archiver.getArchiver().addDirectory(getBuildDir());
archiver.createArchive(session, project, archive);
} catch (Exception e) {
throw new MojoExecutionException("Error assembling RAR", e);
}
if (classifier != null) {
projectHelper.attachArtifact(project, "rar", classifier, rarFile);
} else {
project.getArtifact().setFile(rarFile);
}
}
use of org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter in project maven-plugins by apache.
the class ArtifactsPackagingTask method performPackaging.
/**
* {@inheritDoc}
*/
public void performPackaging(WarPackagingContext context) throws MojoExecutionException {
try {
final ScopeArtifactFilter filter = new ScopeArtifactFilter(Artifact.SCOPE_RUNTIME);
final List<String> duplicates = findDuplicates(context, artifacts);
for (Artifact artifact : artifacts) {
String targetFileName = getArtifactFinalName(context, artifact);
context.getLog().debug("Processing: " + targetFileName);
if (duplicates.contains(targetFileName)) {
context.getLog().debug("Duplicate found: " + targetFileName);
targetFileName = artifact.getGroupId() + "-" + targetFileName;
context.getLog().debug("Renamed to: " + targetFileName);
}
context.getWebappStructure().registerTargetFileName(artifact, targetFileName);
if (!artifact.isOptional() && filter.include(artifact)) {
try {
String type = artifact.getType();
if ("tld".equals(type)) {
copyFile(id, context, artifact.getFile(), TLD_PATH + targetFileName);
} else if ("aar".equals(type)) {
copyFile(id, context, artifact.getFile(), SERVICES_PATH + targetFileName);
} else if ("mar".equals(type)) {
copyFile(id, context, artifact.getFile(), MODULES_PATH + targetFileName);
} else if ("xar".equals(type)) {
copyFile(id, context, artifact.getFile(), EXTENSIONS_PATH + targetFileName);
} else if ("jar".equals(type) || "ejb".equals(type) || "ejb-client".equals(type) || "test-jar".equals(type) || "bundle".equals(type)) {
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("par".equals(type)) {
targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".jar";
copyFile(id, context, artifact.getFile(), LIB_PATH + targetFileName);
} else if ("war".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("war artifacts are handled as overlays, ignoring [" + artifact + "]");
} else if ("zip".equals(type)) {
// Nothing to do here, it is an overlay and it's already handled
context.getLog().debug("zip artifacts are handled as overlays, ignoring [" + artifact + "]");
} else {
context.getLog().debug("Artifact of type [" + type + "] is not supported, ignoring [" + artifact + "]");
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to copy file for artifact [" + artifact + "]", e);
}
}
}
} catch (InterpolationException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
Aggregations