use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class WarExplodedMojoTest method testExplodedWarWithJar.
public void testExplodedWarWithJar() throws Exception {
// setup test data
String testId = "ExplodedWarWithJar";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
File webAppDirectory = new File(getTestDirectory(), testId);
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
ArtifactStub jarArtifact = new JarArtifactStub(getBasedir(), artifactHandler);
File jarFile = jarArtifact.getFile();
assertTrue("jar not found: " + jarFile.toString(), jarFile.exists());
// configure mojo
project.addArtifact(jarArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
mojo.execute();
// validate operation
File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
// final name form is <artifactId>-<version>.<type>
File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar");
assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
// house keeping
expectedWebSourceFile.delete();
expectedWebSource2File.delete();
expectedJarArtifact.delete();
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project sling by apache.
the class PrepareTestWebAppMojo method getPrimaryArtifact.
private File getPrimaryArtifact() throws MojoExecutionException {
ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(project.getPackaging());
String artifactName = project.getBuild().getFinalName() + "." + handler.getExtension();
File file = new File(buildDirectory, artifactName);
if (!file.exists()) {
throw new MojoExecutionException("Project's primary artifact (" + file.getPath() + ") doesn't exist.");
}
return file;
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project grails-maven by grails.
the class GrailsPackagePluginMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
// First package the plugin using the Grails script.
runGrails("PackagePlugin");
// Now move the ZIP from the project directory to the build
// output directory.
String zipFileName = project.getArtifactId() + "-" + project.getVersion() + ".zip";
if (!zipFileName.startsWith(PLUGIN_PREFIX))
zipFileName = PLUGIN_PREFIX + zipFileName;
File zipGeneratedByGrails = new File(getBasedir(), zipFileName);
ArtifactHandler handler = artifactHandler;
if (!zipGeneratedByGrails.exists()) {
// try binary jar
final String targetDir = this.project.getBuild().getDirectory();
File jarFile = new File(targetDir, "grails-plugin-" + project.getArtifactId() + "-" + project.getVersion() + ".jar");
if (jarFile.exists()) {
zipGeneratedByGrails = jarFile;
zipFileName = project.getArtifactId() + "-" + project.getVersion() + ".jar";
handler = binaryArtifactHandler;
}
}
File mavenZipFile = new File(project.getBuild().getDirectory(), zipFileName);
mavenZipFile.delete();
if (!zipGeneratedByGrails.renameTo(mavenZipFile)) {
throw new MojoExecutionException("Unable to copy the plugin ZIP to the target directory");
} else {
getLog().info("Moved plugin ZIP to '" + mavenZipFile + "'.");
}
// Attach the zip file to the "grails-plugin" artifact, otherwise
// the "install" and "deploy" phases won't work.
artifact.setFile(mavenZipFile);
artifact.setArtifactHandler(handler);
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project intellij-community by JetBrains.
the class MavenEmbedder method findArtifactTypeHandlers.
@SuppressWarnings({ "unchecked" })
private Map findArtifactTypeHandlers(MavenProject project) {
// end copied from DefaultLifecycleExecutor.findExtensions
Map result = new HashMap();
for (Object each : project.getBuildPlugins()) {
Plugin eachPlugin = (Plugin) each;
if (eachPlugin.isExtensions()) {
try {
PluginManager pluginManager = getComponent(PluginManager.class);
pluginManager.verifyPlugin(eachPlugin, project, mySettings, myLocalRepository);
result.putAll(pluginManager.getPluginComponents(eachPlugin, ArtifactHandler.ROLE));
} catch (Exception e) {
MavenEmbedderLog.LOG.info(e);
continue;
}
for (Object o : result.values()) {
ArtifactHandler handler = (ArtifactHandler) o;
if (project.getPackaging().equals(handler.getPackaging())) {
project.getArtifact().setArtifactHandler(handler);
}
}
}
}
return result;
}
use of org.apache.maven.artifact.handler.ArtifactHandler in project maven-plugins by apache.
the class AbstractJavadocMojo method getSourcePaths.
/**
* Method to get the source paths. If no source path is specified in the parameter, the compile source roots
* of the project will be used.
*
* @return a List of the project absolute source paths as <code>String</code>
* @throws MavenReportException {@link MavenReportException}
* @see JavadocUtil#pruneDirs(MavenProject, List)
*/
protected List<String> getSourcePaths() throws MavenReportException {
List<String> sourcePaths;
if (StringUtils.isEmpty(sourcepath)) {
sourcePaths = new ArrayList<String>(JavadocUtil.pruneDirs(project, getProjectSourceRoots(project)));
if (project.getExecutionProject() != null) {
sourcePaths.addAll(JavadocUtil.pruneDirs(project, getExecutionProjectSourceRoots(project)));
}
/*
* Should be after the source path (i.e. -sourcepath '.../src/main/java;.../src/main/javadoc') and
* *not* the opposite. If not, the javadoc tool always copies doc files, even if -docfilessubdirs is
* not setted.
*/
if (getJavadocDirectory() != null) {
File javadocDir = getJavadocDirectory();
if (javadocDir.exists() && javadocDir.isDirectory()) {
List<String> l = JavadocUtil.pruneDirs(project, Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
sourcePaths.addAll(l);
}
}
if (includeDependencySources) {
sourcePaths.addAll(getDependencySourcePaths());
}
if (isAggregator() && project.isExecutionRoot()) {
for (MavenProject subProject : reactorProjects) {
if (subProject != project) {
List<String> sourceRoots = getProjectSourceRoots(subProject);
if (subProject.getExecutionProject() != null) {
sourceRoots.addAll(getExecutionProjectSourceRoots(subProject));
}
ArtifactHandler artifactHandler = subProject.getArtifact().getArtifactHandler();
if ("java".equals(artifactHandler.getLanguage())) {
sourcePaths.addAll(JavadocUtil.pruneDirs(subProject, sourceRoots));
}
if (getJavadocDirectory() != null) {
String javadocDirRelative = PathUtils.toRelative(project.getBasedir(), getJavadocDirectory().getAbsolutePath());
File javadocDir = new File(subProject.getBasedir(), javadocDirRelative);
if (javadocDir.exists() && javadocDir.isDirectory()) {
List<String> l = JavadocUtil.pruneDirs(subProject, Collections.singletonList(javadocDir.getAbsolutePath()));
sourcePaths.addAll(l);
}
}
}
}
}
} else {
sourcePaths = new ArrayList<String>(Arrays.asList(JavadocUtil.splitPath(sourcepath)));
sourcePaths = JavadocUtil.pruneDirs(project, sourcePaths);
if (getJavadocDirectory() != null) {
List<String> l = JavadocUtil.pruneDirs(project, Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
sourcePaths.addAll(l);
}
}
sourcePaths = JavadocUtil.pruneDirs(project, sourcePaths);
return sourcePaths;
}
Aggregations