Search in sources :

Example 76 with Plugin

use of org.apache.maven.model.Plugin in project jetty.project by eclipse.

the class WarPluginInfo method getPlugin.

/**
     * Find the maven-war-plugin, if one is configured
     * @return the plugin
     */
public Plugin getPlugin() {
    if (_plugin == null) {
        List plugins = _project.getBuildPlugins();
        if (plugins == null)
            return null;
        Iterator itor = plugins.iterator();
        while (itor.hasNext() && _plugin == null) {
            Plugin plugin = (Plugin) itor.next();
            if ("maven-war-plugin".equals(plugin.getArtifactId()))
                _plugin = plugin;
        }
    }
    return _plugin;
}
Also used : Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Plugin(org.apache.maven.model.Plugin)

Example 77 with Plugin

use of org.apache.maven.model.Plugin in project intellij-plugins by JetBrains.

the class RepositoryReplicatorMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final String localRepositoryBasedir = session.getLocalRepository().getBasedir();
    File localRepositoryFile = new File(localRepositoryBasedir);
    localRepositoryBasedirLength = localRepositoryBasedir.length();
    try {
        final PluginDescriptor pluginDescriptor = pluginManager.getPluginDescriptor(session.getTopLevelProject().getPlugin("org.sonatype.flexmojos:flexmojos-maven-plugin"), session.getCurrentProject().getRemotePluginRepositories(), session.getRepositorySession());
        final File compilerLibsDirectory = new File(outputDirectory, "../build-gant/compiler-libs");
        //noinspection ResultOfMethodCallIgnored
        compilerLibsDirectory.mkdirs();
        for (ComponentDependency dependency : pluginDescriptor.getDependencies()) {
            if (dependency.getGroupId().equals("com.adobe.flex.compiler") && dependency.getType().equals("jar")) {
                final String artifactId = dependency.getArtifactId();
                if (artifactId.equals("adt") || artifactId.equals("asdoc") || artifactId.equals("digest") || artifactId.equals("fcsh") || artifactId.equals("fdb") || artifactId.equals("optimizer") || artifactId.equals("swcdepends")) {
                    continue;
                }
                copyIfLastModifiedNotEquals(new File(localRepositoryFile, "com/adobe/flex/compiler/" + artifactId + "/" + dependency.getVersion() + "/" + artifactId + "-" + dependency.getVersion() + ".jar"), new File(compilerLibsDirectory, artifactId + ".jar"));
            }
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Cannot find flemxojos maven plugin", e);
    }
    if (outputDirectory.exists()) {
        try {
            FileUtils.deleteDirectory(outputDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
    }
    //noinspection ResultOfMethodCallIgnored
    outputDirectory.mkdirs();
    for (MavenProject project : session.getProjects()) {
        // skip projects artifacts
        copiedArtifacts.add(project.getArtifact());
        try {
            copyProjectArtifacts(localRepositoryFile, project);
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
        for (Plugin plugin : project.getBuildPlugins()) {
            if (plugin.getGroupId().startsWith("org.apache.maven")) {
                continue;
            }
            try {
                resolveAndCopyArtifact(repositorySystem.createPluginArtifact(plugin));
            } catch (IOException e) {
                throw new MojoExecutionException("", e);
            }
        }
    }
    for (MavenProject project : session.getProjects()) {
        try {
            copyParentPom(project.getParent());
        } catch (IOException e) {
            throw new MojoExecutionException("", e);
        }
    }
}
Also used : PluginDescriptor(org.apache.maven.plugin.descriptor.PluginDescriptor) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) IOException(java.io.IOException) File(java.io.File) ComponentDependency(org.codehaus.plexus.component.repository.ComponentDependency) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Plugin(org.apache.maven.model.Plugin)

Example 78 with Plugin

use of org.apache.maven.model.Plugin in project intellij-plugins by JetBrains.

the class GeneratorServer method generate.

private String generate(final MavenProject project, final List<String> generators, final URL generatorJarPath) throws Exception {
    session.setCurrentProject(project);
    MojoExecution flexmojosMojoExecution = null;
    try {
        boolean flexmojosGeneratorFound = false;
        boolean buildHelperFound = false;
        boolean buildNumberFound = false;
        for (Plugin plugin : project.getBuildPlugins()) {
            final String pluginGroupId = plugin.getGroupId();
            if (pluginGroupId.equals("org.sonatype.flexmojos") || pluginGroupId.equals("net.flexmojos.oss")) {
                if (flexmojosMojoExecution == null && plugin.getArtifactId().equals("flexmojos-maven-plugin")) {
                    flexmojosMojoExecution = maven.createMojoExecution(plugin, getCompileGoalName(project), project);
                    for (Dependency dependency : plugin.getDependencies()) {
                        if (dependency.getArtifactId().equals("flexmojos-threadlocaltoolkit-wrapper")) {
                            AdditionalSourceRootUtil.addResourcesAsCompileSourceRoots(project);
                            break;
                        }
                    }
                } else if (!flexmojosGeneratorFound && plugin.getArtifactId().equals("flexmojos-generator-mojo")) {
                    AdditionalSourceRootUtil.addByGeneratorMojo(maven.createMojoExecution(plugin, "generate", project), session, project, getLogger());
                    flexmojosGeneratorFound = true;
                }
            } else if (!buildHelperFound && plugin.getArtifactId().equals("build-helper-maven-plugin") && pluginGroupId.equals("org.codehaus.mojo")) {
                AdditionalSourceRootUtil.addByBuildHelper(maven.createMojoExecution(plugin, "add-source", project), session, project, getLogger());
                buildHelperFound = true;
            } else if (!buildNumberFound && plugin.getArtifactId().equals("buildnumber-maven-plugin") && pluginGroupId.equals("org.codehaus.mojo")) {
                populateBuildNumberPluginFields(project, plugin);
                buildNumberFound = true;
            }
            if (flexmojosMojoExecution != null && flexmojosGeneratorFound && buildHelperFound && buildNumberFound) {
                break;
            }
        }
        AdditionalSourceRootUtil.addByUnknownGeneratorMojo(project);
        assert flexmojosMojoExecution != null;
        final ClassRealm flexmojosPluginRealm = maven.getPluginRealm(flexmojosMojoExecution);
        flexmojosPluginRealm.addURL(generatorJarPath);
        final Mojo mojo = mavenPluginManager.getConfiguredMojo(Mojo.class, session, flexmojosMojoExecution);
        try {
            Class<?> configuratorClass = flexmojosPluginRealm.loadClass(generators.get(0));
            FlexConfigGenerator configurator = (FlexConfigGenerator) configuratorClass.getConstructor(MavenSession.class, File.class).newInstance(session, generatorOutputDirectory);
            configurator.preGenerate(project, Flexmojos.getClassifier(mojo));
            if ("swc".equals(project.getPackaging())) {
                configurator.generate(mojo);
            } else {
                configurator.generate(mojo, Flexmojos.getSourceFileForSwf(mojo));
            }
            return configurator.postGenerate(project);
        } finally {
            plexusContainer.release(mojo);
        }
    } finally {
        session.setCurrentProject(null);
        if (flexmojosMojoExecution != null) {
            maven.releaseMojoExecution(flexmojosMojoExecution);
        }
    }
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) Dependency(org.apache.maven.model.Dependency) Plugin(org.apache.maven.model.Plugin)

Example 79 with Plugin

use of org.apache.maven.model.Plugin in project intellij-community by JetBrains.

the class Maven3ServerEmbedderImpl method resolvePlugin.

@Override
public Collection<MavenArtifact> resolvePlugin(@NotNull final MavenPlugin plugin, @NotNull final List<MavenRemoteRepository> repositories, int nativeMavenProjectId, final boolean transitive) throws RemoteException, MavenServerProcessCanceledException {
    try {
        Plugin mavenPlugin = new Plugin();
        mavenPlugin.setGroupId(plugin.getGroupId());
        mavenPlugin.setArtifactId(plugin.getArtifactId());
        mavenPlugin.setVersion(plugin.getVersion());
        MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);
        Plugin pluginFromProject = project.getBuild().getPluginsAsMap().get(plugin.getGroupId() + ':' + plugin.getArtifactId());
        if (pluginFromProject != null) {
            mavenPlugin.setDependencies(pluginFromProject.getDependencies());
        }
        final MavenExecutionRequest request = createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
        DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
        RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
        PluginDependenciesResolver pluginDependenciesResolver = getComponent(PluginDependenciesResolver.class);
        org.eclipse.aether.artifact.Artifact pluginArtifact = pluginDependenciesResolver.resolve(mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);
        org.eclipse.aether.graph.DependencyNode node = pluginDependenciesResolver.resolve(mavenPlugin, pluginArtifact, null, project.getRemotePluginRepositories(), repositorySystemSession);
        PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
        node.accept(nlg);
        List<MavenArtifact> res = new ArrayList<MavenArtifact>();
        for (org.eclipse.aether.artifact.Artifact artifact : nlg.getArtifacts(true)) {
            if (!Comparing.equal(artifact.getArtifactId(), plugin.getArtifactId()) || !Comparing.equal(artifact.getGroupId(), plugin.getGroupId())) {
                res.add(MavenModelConverter.convertArtifact(RepositoryUtils.toArtifact(artifact), getLocalRepositoryFile()));
            }
        }
        return res;
    } catch (Exception e) {
        Maven3ServerGlobals.getLogger().info(e);
        return Collections.emptyList();
    }
}
Also used : RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) InitializationException(org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException) ModelInterpolationException(org.apache.maven.project.interpolation.ModelInterpolationException) RemoteException(java.rmi.RemoteException) ComponentLookupException(org.codehaus.plexus.component.repository.exception.ComponentLookupException) ContextException(org.codehaus.plexus.context.ContextException) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) InvalidRepositoryException(org.apache.maven.artifact.InvalidRepositoryException) PluginDependenciesResolver(org.apache.maven.plugin.internal.PluginDependenciesResolver) Plugin(org.apache.maven.model.Plugin)

Example 80 with Plugin

use of org.apache.maven.model.Plugin 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)

Aggregations

Plugin (org.apache.maven.model.Plugin)140 Xpp3Dom (org.codehaus.plexus.util.xml.Xpp3Dom)39 MavenProject (org.apache.maven.project.MavenProject)26 Build (org.apache.maven.model.Build)22 PluginExecution (org.apache.maven.model.PluginExecution)22 ArrayList (java.util.ArrayList)20 Dependency (org.apache.maven.model.Dependency)17 File (java.io.File)15 Model (org.apache.maven.model.Model)15 HashMap (java.util.HashMap)12 PluginDescriptor (org.apache.maven.plugin.descriptor.PluginDescriptor)12 CoreException (org.eclipse.core.runtime.CoreException)11 IOException (java.io.IOException)9 List (java.util.List)8 PluginManagement (org.apache.maven.model.PluginManagement)8 Map (java.util.Map)7 MavenSession (org.apache.maven.execution.MavenSession)7 ReportPlugin (org.apache.maven.model.ReportPlugin)7 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6