26
26
import java .util .Map ;
27
27
import java .util .stream .Collectors ;
28
28
29
+ import org .osgi .framework .FrameworkUtil ;
29
30
import org .osgi .service .component .annotations .Activate ;
30
31
import org .osgi .service .component .annotations .Component ;
31
32
import org .osgi .service .component .annotations .Deactivate ;
34
35
import org .slf4j .LoggerFactory ;
35
36
36
37
import com .google .inject .AbstractModule ;
38
+ import com .google .inject .Guice ;
39
+ import com .google .inject .Injector ;
40
+ import com .google .inject .Key ;
37
41
import com .google .inject .Module ;
42
+ import com .google .inject .TypeLiteral ;
43
+ import com .google .inject .util .Modules ;
44
+ import com .google .inject .util .Types ;
38
45
46
+ import org .eclipse .aether .RepositorySystem ;
39
47
import org .eclipse .aether .repository .RemoteRepository ;
40
48
import org .eclipse .core .runtime .Assert ;
41
49
import org .eclipse .core .runtime .CoreException ;
42
50
import org .eclipse .core .runtime .IProgressMonitor ;
43
51
import org .eclipse .core .runtime .NullProgressMonitor ;
44
52
import 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 ;
45
58
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 ;
53
60
54
61
import org .apache .maven .RepositoryUtils ;
55
62
import org .apache .maven .archetype .catalog .Archetype ;
59
66
import org .apache .maven .archetype .metadata .RequiredProperty ;
60
67
import org .apache .maven .archetype .source .ArchetypeDataSource ;
61
68
import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
69
+ import org .apache .maven .cli .logging .Slf4jLogger ;
62
70
63
71
import org .eclipse .m2e .core .embedder .IMaven ;
64
72
import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
@@ -95,30 +103,40 @@ public class ArchetypePlugin {
95
103
96
104
private Map <String , ArchetypeDataSource > archetypeDataSourceMap ;
97
105
98
- private DefaultPlexusContainer container ;
99
-
100
106
public ArchetypePlugin () {
101
107
this .configFile = new File (MavenPluginActivator .getDefault ().getStateLocation ().toFile (),
102
108
M2EUIPluginActivator .PREFS_ARCHETYPES );
103
109
this .writer = new ArchetypeCatalogsWriter ();
104
110
}
105
111
106
112
@ Activate
107
- void activate () throws PlexusContainerException , ComponentLookupException {
108
- final Module logginModule = new AbstractModule () {
113
+ void activate () {
114
+ Module localBindings = new AbstractModule () {
109
115
@ Override
110
116
protected void configure () {
111
117
bind (ILoggerFactory .class ).toInstance (LoggerFactory .getILoggerFactory ());
118
+ try {
119
+ bind (RepositorySystem .class ).toInstance (MavenPluginActivator .getDefault ().getRepositorySystem ());
120
+ } catch (CoreException ex ) {
121
+ ex .printStackTrace ();
122
+ }
112
123
}
113
124
};
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
+
122
140
addArchetypeCatalogFactory (
123
141
new ArchetypeCatalogFactory .InternalCatalogFactory (archetypeDataSourceMap .get ("internal-catalog" )));
124
142
addArchetypeCatalogFactory (
@@ -136,7 +154,6 @@ protected void configure() {
136
154
@ Deactivate
137
155
void shutdown () throws IOException {
138
156
saveCatalogs ();
139
- container .dispose ();
140
157
}
141
158
142
159
public LocalCatalogFactory newLocalCatalogFactory (String path , String description , boolean editable ,
0 commit comments