-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP fixing problem with PlexusContainer
- Loading branch information
Showing
5 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
sbm-support-rewrite-maven/src/main/java/com/example/PlexusContainerApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example;/* | ||
* Copyright 2021 - 2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import org.apache.maven.Maven; | ||
import org.apache.maven.repository.RepositorySystem; | ||
import org.apache.maven.repository.legacy.LegacyRepositorySystem; | ||
import org.codehaus.plexus.*; | ||
import org.codehaus.plexus.classworlds.ClassWorld; | ||
import org.codehaus.plexus.classworlds.realm.ClassRealm; | ||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | ||
|
||
import java.net.URL; | ||
|
||
/** | ||
* @author Fabian Krüger | ||
*/ | ||
public class PlexusContainerApp { | ||
public static void main(String[] args) throws ComponentLookupException { | ||
PlexusContainer plexusContainer = create(); | ||
Maven maven = plexusContainer.lookup(Maven.class); | ||
System.out.println(maven); | ||
RepositorySystem lookup = plexusContainer.lookup(RepositorySystem.class); | ||
System.out.println(lookup); | ||
} | ||
|
||
public static PlexusContainer create() { | ||
try { | ||
ClassLoader parent = null; | ||
boolean isContainerAutoWiring = false; | ||
String containerClassPathScanning = "on"; | ||
String containerComponentVisibility = null; | ||
URL overridingComponentsXml = null; //getClass().getClassLoader().getResource("META-INF/**/components.xml"); | ||
|
||
ContainerConfiguration configuration = new DefaultContainerConfiguration(); | ||
configuration.setAutoWiring(isContainerAutoWiring) | ||
.setClassPathScanning(containerClassPathScanning) | ||
.setComponentVisibility(containerComponentVisibility) | ||
.setContainerConfigurationURL(overridingComponentsXml); | ||
|
||
// inspired from https://github.com/jenkinsci/lib-jenkins-maven-embedder/blob/master/src/main/java/hudson/maven/MavenEmbedderUtils.java#L141 | ||
ClassWorld classWorld = new ClassWorld(); | ||
ClassRealm classRealm = new ClassRealm(classWorld, "maven", PlexusContainer.class.getClassLoader()); | ||
classRealm.setParentRealm(new ClassRealm(classWorld, "maven-parent", | ||
parent == null ? Thread.currentThread().getContextClassLoader() | ||
: parent)); | ||
configuration.setRealm(classRealm); | ||
|
||
configuration.setClassWorld(classWorld); | ||
return new DefaultPlexusContainer(configuration); | ||
} catch (PlexusContainerException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters