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);
}
}
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);
}
}
}
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);
}
}
Aggregations