Search in sources :

Example 1 with ClassRealm

use of org.codehaus.plexus.classworlds.realm.ClassRealm in project gradle by gradle.

the class AbstractMavenPublishAction method newPlexusContainer.

private PlexusContainer newPlexusContainer(List<File> wagonJars) {
    try {
        ClassWorld world = new ClassWorld("plexus.core", ClassWorld.class.getClassLoader());
        ClassRealm classRealm = new ClassRealm(world, "plexus.core", ClassWorld.class.getClassLoader());
        if (wagonJars != null) {
            for (File jar : wagonJars) {
                classRealm.addURL(jar.toURI().toURL());
            }
        }
        return new DefaultPlexusContainer(new DefaultContainerConfiguration().setRealm(classRealm));
    } catch (PlexusContainerException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    } catch (MalformedURLException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
Also used : PlexusContainerException(org.codehaus.plexus.PlexusContainerException) ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) MalformedURLException(java.net.MalformedURLException) DefaultPlexusContainer(org.codehaus.plexus.DefaultPlexusContainer) DefaultContainerConfiguration(org.codehaus.plexus.DefaultContainerConfiguration) ClassWorld(org.codehaus.plexus.classworlds.ClassWorld) File(java.io.File)

Example 2 with ClassRealm

use of org.codehaus.plexus.classworlds.realm.ClassRealm 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 3 with ClassRealm

use of org.codehaus.plexus.classworlds.realm.ClassRealm in project intellij-plugins by JetBrains.

the class IdeaConfigurationMojo method generateForProject.

private void generateForProject(MavenProject project, List<String> configurators) throws Exception {
    MojoExecution flexmojosMojoExecution = null;
    MojoExecution flexmojosGeneratorMojoExecution = null;
    for (Plugin plugin : project.getBuildPlugins()) {
        if (plugin.getGroupId().equals("org.sonatype.flexmojos")) {
            if (flexmojosMojoExecution == null && plugin.getArtifactId().equals("flexmojos-maven-plugin")) {
                flexmojosMojoExecution = createMojoExecution(plugin, getCompileGoalName(project), project);
            } else if (flexmojosGeneratorMojoExecution == null && plugin.getArtifactId().equals("flexmojos-generator-mojo")) {
                flexmojosGeneratorMojoExecution = createMojoExecution(plugin, "generate", project);
            }
            if (flexmojosMojoExecution != null && flexmojosGeneratorMojoExecution != null) {
                break;
            }
        }
    }
    if (flexmojosMojoExecution == null) {
        return;
    }
    ClassRealm flexmojosPluginRealm = pluginManager.getPluginRealm(session, flexmojosMojoExecution.getMojoDescriptor().getPluginDescriptor());
    final ClassLoader classLoader = getClass().getClassLoader();
    flexmojosPluginRealm.addURL(new URL(session.getLocalRepository().getUrl() + "com/intellij/flex/maven/idea-configurator/1.5.4/idea-configurator-1.5.4.jar"));
    flexmojosPluginRealm.importFrom(classLoader, "com.intellij.flex.maven.FlexConfigGenerator");
    flexmojosPluginRealm.importFrom(classLoader, "com.intellij.flex.maven.Utils");
    Mojo mojo = null;
    try {
        mojo = mavenPluginManager.getConfiguredMojo(Mojo.class, session, flexmojosMojoExecution);
        for (String configuratorClassName : configurators) {
            Class configuratorClass = flexmojosPluginRealm.loadClass(configuratorClassName);
            FlexConfigGenerator configurator = (FlexConfigGenerator) configuratorClass.getConstructor(MavenSession.class, File.class).newInstance(session, null);
            configurator.preGenerate(project, Flexmojos.getClassifier(mojo));
            if ("swc".equals(project.getPackaging())) {
                configurator.generate(mojo);
            } else {
                configurator.generate(mojo, Flexmojos.getSourceFileForSwf(mojo));
            }
            configurator.postGenerate(project);
        }
    } finally {
        mavenPluginManager.releaseMojo(mojo, mojoExecution);
    }
}
Also used : ClassRealm(org.codehaus.plexus.classworlds.realm.ClassRealm) URL(java.net.URL) Plugin(org.apache.maven.model.Plugin)

Aggregations

ClassRealm (org.codehaus.plexus.classworlds.realm.ClassRealm)3 Plugin (org.apache.maven.model.Plugin)2 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Dependency (org.apache.maven.model.Dependency)1 DefaultContainerConfiguration (org.codehaus.plexus.DefaultContainerConfiguration)1 DefaultPlexusContainer (org.codehaus.plexus.DefaultPlexusContainer)1 PlexusContainerException (org.codehaus.plexus.PlexusContainerException)1 ClassWorld (org.codehaus.plexus.classworlds.ClassWorld)1