use of org.codehaus.plexus.classworlds.ClassWorld in project gradle by gradle.
the class MavenProjectsCreator method createNow.
private Set<MavenProject> createNow(Settings settings, File pomFile) throws PlexusContainerException, ComponentLookupException, MavenExecutionRequestPopulationException, ProjectBuildingException {
ContainerConfiguration containerConfiguration = new DefaultContainerConfiguration().setClassWorld(new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader())).setName("mavenCore").setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true);
DefaultPlexusContainer container = new DefaultPlexusContainer(containerConfiguration);
ProjectBuilder builder = container.lookup(ProjectBuilder.class);
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
final Properties properties = SystemProperties.getInstance().withSystemProperties(() -> {
final Properties currentProperties = new Properties();
currentProperties.putAll(System.getProperties());
return currentProperties;
});
executionRequest.setSystemProperties(properties);
MavenExecutionRequestPopulator populator = container.lookup(MavenExecutionRequestPopulator.class);
populateFromSettings(settings, executionRequest, populator);
populator.populateDefaults(executionRequest);
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
buildingRequest.getRemoteRepositories().forEach(repository -> {
if (repository.getId().equals(RepositorySystem.DEFAULT_REMOTE_REPO_ID)) {
repository.setUrl(RepositoryHandler.MAVEN_CENTRAL_URL);
}
});
buildingRequest.setProcessPlugins(false);
MavenProject mavenProject = builder.build(pomFile, buildingRequest).getProject();
Set<MavenProject> reactorProjects = new LinkedHashSet<>();
// TODO adding the parent project first because the converter needs it this way ATM. This is oversimplified.
// the converter should not depend on the order of reactor projects.
// we should add coverage for nested multi-project builds with multiple parents.
reactorProjects.add(mavenProject);
List<ProjectBuildingResult> allProjects = builder.build(ImmutableList.of(pomFile), true, buildingRequest);
// noinspection NullableProblems
CollectionUtils.collect(allProjects, reactorProjects, ProjectBuildingResult::getProject);
MavenExecutionResult result = new DefaultMavenExecutionResult();
result.setProject(mavenProject);
RepositorySystemSession repoSession = new DefaultRepositorySystemSession();
@SuppressWarnings("deprecation") MavenSession session = new MavenSession(container, repoSession, executionRequest, result);
session.setCurrentProject(mavenProject);
return reactorProjects;
}
use of org.codehaus.plexus.classworlds.ClassWorld in project scala-maven-plugin by davidB.
the class MiscTest method classworldSeftFirstStrategy.
@Test
public void classworldSeftFirstStrategy() throws Exception {
ClassWorld w = new ClassWorld("zero", null);
ClassRealm rMojo = w.newRealm("mojo", getClass().getClassLoader());
Strategy s = new SelfFirstStrategy(w.newRealm("scalaScript", null));
ClassRealm rScript = s.getRealm();
rScript.setParentClassLoader(getClass().getClassLoader());
rScript.importFrom("mojo", MavenProject.class.getPackage().getName());
rScript.importFrom("mojo", MavenSession.class.getPackage().getName());
rScript.importFrom("mojo", Log.class.getPackage().getName());
assertEquals(rScript, rScript.getStrategy().getRealm());
assertEquals(SelfFirstStrategy.class, rScript.getStrategy().getClass());
File olderjar = new File(System.getProperty("user.home"), ".m2/repository/net/alchim31/maven/scala-maven-plugin/3.1.0/scala-maven-plugin-3.1.0.jar");
if (olderjar.exists()) {
System.out.println("found older jar");
rScript.addURL(olderjar.toURI().toURL());
String clname = "scala_maven.ScalaScriptMojo";
// assertNotSame(s.loadClass(clname), getClass().getClassLoader().loadClass(clname));
assertNotSame(rScript.loadClass(clname), getClass().getClassLoader().loadClass(clname));
assertSame(rMojo.loadClass(clname), getClass().getClassLoader().loadClass(clname));
assertSame(rScript.loadClass(MavenProject.class.getCanonicalName()), MavenProject.class);
assertSame(rScript.loadClass(MavenSession.class.getCanonicalName()), MavenSession.class);
assertSame(rScript.loadClass(Log.class.getCanonicalName()), Log.class);
}
}
use of org.codehaus.plexus.classworlds.ClassWorld in project spring-cloud-function by spring-cloud.
the class DependencyResolutionModule method initialize.
private void initialize() {
if (this.container == null) {
synchronized (lock) {
if (this.container == null) {
ClassWorld classWorld = new ClassWorld("plexus.core", Thread.currentThread().getContextClassLoader());
ContainerConfiguration config = new DefaultContainerConfiguration().setClassWorld(classWorld).setRealm(classWorld.getClassRealm("plexus.core")).setClassPathScanning(PlexusConstants.SCANNING_INDEX).setAutoWiring(true).setName("maven");
PlexusContainer container;
try {
container = new DefaultPlexusContainer(config, new AetherModule(), new DependencyResolutionModule());
localRepositoryManagerFactory = container.lookup(LocalRepositoryManagerFactory.class);
container.addComponent(new ClassRealmManager((MutablePlexusContainer) container, new DefaultBeanLocator()), ClassRealmManager.class.getName());
projectBuilder = container.lookup(ProjectBuilder.class);
repositorySystem = container.lookup(RepositorySystem.class);
} catch (Exception e) {
throw new IllegalStateException("Cannot create container", e);
}
this.container = container;
this.settings = new MavenSettingsReader().readSettings();
}
}
}
}
use of org.codehaus.plexus.classworlds.ClassWorld in project sts4 by spring-projects.
the class MavenBridge method newPlexusContainer.
private static DefaultPlexusContainer newPlexusContainer() throws PlexusContainerException {
final ClassWorld classWorld = new ClassWorld(MAVEN_CORE_REALM_ID, ClassWorld.class.getClassLoader());
final ClassRealm realm;
try {
realm = classWorld.getRealm(MAVEN_CORE_REALM_ID);
} catch (NoSuchRealmException e) {
throw new PlexusContainerException("Could not lookup required class realm", e);
}
final ContainerConfiguration mavenCoreCC = //
new DefaultContainerConfiguration().setClassWorld(//
classWorld).setRealm(//
realm).setClassPathScanning(//
PlexusConstants.SCANNING_INDEX).setAutoWiring(//
true).setName(// $NON-NLS-1$
"mavenCore");
final Module logginModule = new AbstractModule() {
protected void configure() {
bind(ILoggerFactory.class).toInstance(LoggerFactory.getILoggerFactory());
}
};
final Module coreExportsModule = new AbstractModule() {
protected void configure() {
ClassRealm realm = mavenCoreCC.getRealm();
CoreExtensionEntry entry = CoreExtensionEntry.discoverFrom(realm);
CoreExports exports = new CoreExports(entry);
bind(CoreExports.class).toInstance(exports);
}
};
return new DefaultPlexusContainer(mavenCoreCC, logginModule, coreExportsModule);
}
use of org.codehaus.plexus.classworlds.ClassWorld in project aries by apache.
the class GenerateMojo method createProjectScopeFinder.
private ClassFinder createProjectScopeFinder() throws Exception {
List<URL> urls = new ArrayList<>();
long startTime = System.currentTimeMillis();
ClassRealm classRealm = new ClassRealm(new ClassWorld(), "maven-blueprint-plugin-classloader", getClass().getClassLoader());
classRealm.addURL(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
urls.add(new File(project.getBuild().getOutputDirectory()).toURI().toURL());
ArtifactFilter artifactFilter = new ArtifactFilter(includeArtifacts, excludeArtifacts);
for (Object artifactO : project.getArtifacts()) {
Artifact artifact = (Artifact) artifactO;
File file = artifact.getFile();
if (file == null) {
continue;
}
URL artifactUrl = file.toURI().toURL();
classRealm.addURL(artifactUrl);
if (artifactFilter.shouldExclude(artifact)) {
getLog().debug("Excluded artifact: " + artifact);
continue;
}
getLog().debug("Taken artifact: " + artifact);
urls.add(artifactUrl);
}
getLog().debug(" Create class loader: " + (System.currentTimeMillis() - startTime) + "ms");
startTime = System.currentTimeMillis();
ClassFinder classFinder = new ClassFinder(classRealm, urls);
getLog().debug(" Building class finder: " + (System.currentTimeMillis() - startTime) + "ms");
return classFinder;
}
Aggregations