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,42 @@ 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
+ ILoggerFactory loggerFactory = LoggerFactory .getILoggerFactory ();
115
+ Module localBindings = new AbstractModule () {
109
116
@ Override
110
117
protected void configure () {
111
- bind (ILoggerFactory .class ).toInstance (LoggerFactory .getILoggerFactory ());
118
+ bind (ILoggerFactory .class ).toInstance (loggerFactory );
119
+ try {
120
+ bind (RepositorySystem .class ).toInstance (MavenPluginActivator .getDefault ().getRepositorySystem ());
121
+ } catch (CoreException ex ) {
122
+ ex .printStackTrace ();
123
+ }
112
124
}
113
125
};
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 );
126
+ ClassSpace space = new BundleClassSpace (FrameworkUtil .getBundle (ArchetypeArtifactManager .class ));
127
+ WireModule wireModule = new WireModule (new SpaceModule (space , BeanScanning .INDEX , false ));
128
+ Injector injector = Guice .createInjector (Modules .override (wireModule ).with (localBindings ));
129
+ @ SuppressWarnings ("unchecked" )
130
+ TypeLiteral <Map <String , ArchetypeDataSource >> mapOfDataSourcesType = (TypeLiteral <Map <String , ArchetypeDataSource >>) TypeLiteral
131
+ .get (Types .mapOf (String .class , ArchetypeDataSource .class ));
132
+ archetypeArtifactManager = injector .getInstance (ArchetypeArtifactManager .class );
133
+ archetypeDataSourceMap = injector .getInstance (Key .get (mapOfDataSourcesType ));
134
+
135
+ Slf4jLogger logger = new Slf4jLogger (LoggerFactory .getILoggerFactory ().getLogger ("catalog" ));
136
+ if (archetypeArtifactManager instanceof LogEnabled logEnabled ) {
137
+ logEnabled .enableLogging (logger );
138
+ }
139
+ archetypeDataSourceMap .values ().stream ().filter (LogEnabled .class ::isInstance ).map (LogEnabled .class ::cast )
140
+ .forEach (d -> d .enableLogging (logger ));
141
+
122
142
addArchetypeCatalogFactory (
123
143
new ArchetypeCatalogFactory .InternalCatalogFactory (archetypeDataSourceMap .get ("internal-catalog" )));
124
144
addArchetypeCatalogFactory (
@@ -136,7 +156,6 @@ protected void configure() {
136
156
@ Deactivate
137
157
void shutdown () throws IOException {
138
158
saveCatalogs ();
139
- container .dispose ();
140
159
}
141
160
142
161
public LocalCatalogFactory newLocalCatalogFactory (String path , String description , boolean editable ,
0 commit comments