Search in sources :

Example 16 with ArtifactHandler

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();
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) PARArtifactStub(org.apache.maven.plugins.war.stub.PARArtifactStub) TLDArtifactStub(org.apache.maven.plugins.war.stub.TLDArtifactStub) IncludeExcludeWarArtifactStub(org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) EJBClientArtifactStub(org.apache.maven.plugins.war.stub.EJBClientArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) AarArtifactStub(org.apache.maven.plugins.war.stub.AarArtifactStub) File(java.io.File)

Example 17 with ArtifactHandler

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;
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 18 with ArtifactHandler

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);
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File)

Example 19 with ArtifactHandler

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;
}
Also used : PluginManager(org.apache.maven.plugin.PluginManager) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) PlexusContainerException(org.codehaus.plexus.PlexusContainerException) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) FileNotFoundException(java.io.FileNotFoundException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) SecDispatcherException(org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException) IOException(java.io.IOException) Plugin(org.apache.maven.model.Plugin)

Example 20 with ArtifactHandler

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;
}
Also used : ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProject(org.apache.maven.project.MavenProject) File(java.io.File)

Aggregations

ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)35 File (java.io.File)17 Artifact (org.apache.maven.artifact.Artifact)14 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)12 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)10 ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)9 VersionRange (org.apache.maven.artifact.versioning.VersionRange)7 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)6 DefaultArtifactHandlerStub (org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub)5 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)5 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)5 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)5 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)5 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)4 MavenProject (org.apache.maven.project.MavenProject)4