2626import java .util .Map ;
2727import java .util .stream .Collectors ;
2828
29+ import org .osgi .framework .FrameworkUtil ;
2930import org .osgi .service .component .annotations .Activate ;
3031import org .osgi .service .component .annotations .Component ;
3132import org .osgi .service .component .annotations .Deactivate ;
3435import org .slf4j .LoggerFactory ;
3536
3637import com .google .inject .AbstractModule ;
38+ import com .google .inject .Guice ;
39+ import com .google .inject .Injector ;
40+ import com .google .inject .Key ;
3741import com .google .inject .Module ;
42+ import com .google .inject .TypeLiteral ;
43+ import com .google .inject .util .Modules ;
44+ import com .google .inject .util .Types ;
3845
46+ import org .eclipse .aether .RepositorySystem ;
3947import org .eclipse .aether .repository .RemoteRepository ;
4048import org .eclipse .core .runtime .Assert ;
4149import org .eclipse .core .runtime .CoreException ;
4250import org .eclipse .core .runtime .IProgressMonitor ;
4351import org .eclipse .core .runtime .NullProgressMonitor ;
4452import org .eclipse .core .runtime .Status ;
53+ import org .eclipse .sisu .space .BeanScanning ;
54+ import org .eclipse .sisu .space .BundleClassSpace ;
55+ import org .eclipse .sisu .space .ClassSpace ;
56+ import org .eclipse .sisu .space .SpaceModule ;
57+ import org .eclipse .sisu .wire .WireModule ;
4558
46- import org .codehaus .plexus .ContainerConfiguration ;
47- import org .codehaus .plexus .DefaultContainerConfiguration ;
48- import org .codehaus .plexus .DefaultPlexusContainer ;
49- import org .codehaus .plexus .PlexusConstants ;
50- import org .codehaus .plexus .PlexusContainerException ;
51- import org .codehaus .plexus .classworlds .ClassWorld ;
52- import org .codehaus .plexus .component .repository .exception .ComponentLookupException ;
59+ import org .codehaus .plexus .logging .LogEnabled ;
5360
5461import org .apache .maven .RepositoryUtils ;
5562import org .apache .maven .archetype .catalog .Archetype ;
5966import org .apache .maven .archetype .metadata .RequiredProperty ;
6067import org .apache .maven .archetype .source .ArchetypeDataSource ;
6168import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
69+ import org .apache .maven .cli .logging .Slf4jLogger ;
6270
6371import org .eclipse .m2e .core .embedder .IMaven ;
6472import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
@@ -95,30 +103,40 @@ public class ArchetypePlugin {
95103
96104 private Map <String , ArchetypeDataSource > archetypeDataSourceMap ;
97105
98- private DefaultPlexusContainer container ;
99-
100106 public ArchetypePlugin () {
101107 this .configFile = new File (MavenPluginActivator .getDefault ().getStateLocation ().toFile (),
102108 M2EUIPluginActivator .PREFS_ARCHETYPES );
103109 this .writer = new ArchetypeCatalogsWriter ();
104110 }
105111
106112 @ Activate
107- void activate () throws PlexusContainerException , ComponentLookupException {
108- final Module logginModule = new AbstractModule () {
113+ void activate () {
114+ Module localBindings = new AbstractModule () {
109115 @ Override
110116 protected void configure () {
111117 bind (ILoggerFactory .class ).toInstance (LoggerFactory .getILoggerFactory ());
118+ try {
119+ bind (RepositorySystem .class ).toInstance (MavenPluginActivator .getDefault ().getRepositorySystem ());
120+ } catch (CoreException ex ) {
121+ ex .printStackTrace ();
122+ }
112123 }
113124 };
114- final ContainerConfiguration cc = new DefaultContainerConfiguration () //
115- .setClassWorld (new ClassWorld ("plexus.core" , ArchetypeArtifactManager .class .getClassLoader ())) //$NON-NLS-1$
116- .setClassPathScanning (PlexusConstants .SCANNING_INDEX ) //
117- .setAutoWiring (true ) //
118- .setName ("plexus" ); //$NON-NLS-1$
119- container = new DefaultPlexusContainer (cc , logginModule );
120- archetypeArtifactManager = container .lookup (ArchetypeArtifactManager .class );
121- archetypeDataSourceMap = container .lookupMap (ArchetypeDataSource .class );
125+ ClassSpace space = new BundleClassSpace (FrameworkUtil .getBundle (ArchetypeArtifactManager .class ));
126+ WireModule wireModule = new WireModule (new SpaceModule (space , BeanScanning .INDEX ));
127+ Injector injector = Guice .createInjector (Modules .override (wireModule ).with (localBindings ));
128+ @ SuppressWarnings ("unchecked" )
129+ TypeLiteral <Map <String , ArchetypeDataSource >> mapOfDataSourcesType = (TypeLiteral <Map <String , ArchetypeDataSource >>) TypeLiteral
130+ .get (Types .mapOf (String .class , ArchetypeDataSource .class ));
131+ archetypeArtifactManager = injector .getInstance (ArchetypeArtifactManager .class );
132+ archetypeDataSourceMap = injector .getInstance (Key .get (mapOfDataSourcesType ));
133+
134+ if (archetypeArtifactManager instanceof LogEnabled logEnabled ) {
135+ logEnabled .enableLogging (new Slf4jLogger (LoggerFactory .getLogger (archetypeArtifactManager .getClass ())));
136+ }
137+ archetypeDataSourceMap .values ().stream ().filter (LogEnabled .class ::isInstance ).map (LogEnabled .class ::cast )
138+ .forEach (d -> d .enableLogging (new Slf4jLogger (LoggerFactory .getLogger (d .getClass ()))));
139+
122140 addArchetypeCatalogFactory (
123141 new ArchetypeCatalogFactory .InternalCatalogFactory (archetypeDataSourceMap .get ("internal-catalog" )));
124142 addArchetypeCatalogFactory (
@@ -136,7 +154,6 @@ protected void configure() {
136154 @ Deactivate
137155 void shutdown () throws IOException {
138156 saveCatalogs ();
139- container .dispose ();
140157 }
141158
142159 public LocalCatalogFactory newLocalCatalogFactory (String path , String description , boolean editable ,
0 commit comments