13
13
14
14
package org .eclipse .m2e .core .ui .internal .archetype ;
15
15
16
+ import java .io .File ;
16
17
import java .io .InputStream ;
17
18
import java .net .URI ;
18
19
import java .net .URL ;
24
25
import org .slf4j .Logger ;
25
26
import org .slf4j .LoggerFactory ;
26
27
28
+ import org .eclipse .aether .DefaultRepositorySystemSession ;
29
+ import org .eclipse .aether .repository .LocalRepository ;
30
+ import org .eclipse .aether .repository .NoLocalRepositoryManagerException ;
31
+ import org .eclipse .aether .repository .RemoteRepository ;
32
+ import org .eclipse .aether .spi .localrepo .LocalRepositoryManagerFactory ;
27
33
import org .eclipse .core .runtime .CoreException ;
28
34
import org .eclipse .core .runtime .Status ;
29
35
import org .eclipse .osgi .util .NLS ;
34
40
import org .apache .maven .archetype .source .ArchetypeDataSource ;
35
41
import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
36
42
import org .apache .maven .archetype .source .RemoteCatalogArchetypeDataSource ;
37
- import org .apache .maven .artifact .repository .ArtifactRepository ;
38
- import org .apache .maven .artifact .repository .MavenArtifactRepository ;
39
- import org .apache .maven .project .ProjectBuildingRequest ;
40
43
41
44
import org .eclipse .m2e .core .embedder .IMaven ;
42
- import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
43
45
import org .eclipse .m2e .core .internal .Messages ;
44
46
45
47
@@ -111,7 +113,7 @@ public static class InternalCatalogFactory extends ArchetypeCatalogFactory {
111
113
@ Override
112
114
public ArchetypeCatalog getArchetypeCatalog () {
113
115
try {
114
- return source .getArchetypeCatalog (null );
116
+ return source .getArchetypeCatalog (null , null );
115
117
} catch (ArchetypeDataSourceException e ) {
116
118
return new ArchetypeCatalog ();
117
119
}
@@ -137,9 +139,8 @@ public static class DefaultLocalCatalogFactory extends ArchetypeCatalogFactory {
137
139
@ Override
138
140
public ArchetypeCatalog getArchetypeCatalog () throws CoreException {
139
141
return maven .createExecutionContext ().execute ((ctx , m ) -> {
140
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
141
142
try {
142
- return source .getArchetypeCatalog (buildingRequest );
143
+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
143
144
} catch (ArchetypeDataSourceException e ) {
144
145
return new ArchetypeCatalog ();
145
146
}
@@ -172,39 +173,38 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
172
173
ArchetypeCatalog catalog = getEmbeddedCatalog ();
173
174
if (catalog == null ) {
174
175
//local but not embedded catalog
175
- IMavenExecutionContext context = maven .createExecutionContext ();
176
- ArtifactRepository localRepository = new MavenArtifactRepository ();
177
- localRepository .setUrl (getLocalRepositoryURL ());
178
- context .getExecutionRequest ().setLocalRepository (localRepository );
179
- return context .execute ((ctx , m ) -> {
180
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
181
- buildingRequest .setLocalRepository (localRepository );
176
+ File localRepositoryPath = getLocalRepositoryPath ();
177
+ return maven .createExecutionContext ().execute ((ctx , m ) -> {
182
178
try {
183
- return source .getArchetypeCatalog (buildingRequest );
184
- } catch (ArchetypeDataSourceException e ) {
179
+ var managerFactory = ctx .getComponentLookup ().lookup (LocalRepositoryManagerFactory .class );
180
+ DefaultRepositorySystemSession session = new DefaultRepositorySystemSession (ctx .getRepositorySession ());
181
+ session .setLocalRepositoryManager (
182
+ managerFactory .newInstance (session , new LocalRepository (localRepositoryPath )));
183
+ return source .getArchetypeCatalog (session , List .of ());
184
+ } catch (ArchetypeDataSourceException | NoLocalRepositoryManagerException e ) {
185
185
return new ArchetypeCatalog ();
186
186
}
187
187
}, null );
188
188
}
189
189
return catalog ;
190
190
}
191
191
192
- private String getLocalRepositoryURL () {
192
+ private File getLocalRepositoryPath () {
193
193
Path path ;
194
194
try { // First try to use the id as a path, then as a URI else as it is
195
195
path = Path .of (getId ());
196
196
} catch (Exception e1 ) {
197
197
try {
198
198
path = Path .of (new URI (getId ()));
199
199
} catch (Exception e2 ) {
200
- return getId ();
200
+ return new File ( getId () );
201
201
}
202
202
}
203
203
path = path .toAbsolutePath ();
204
204
if (Files .isRegularFile (path )) {
205
205
path = path .getParent ();
206
206
}
207
- return path .toUri (). toString ();
207
+ return path .toFile ();
208
208
}
209
209
210
210
private ArchetypeCatalog getEmbeddedCatalog () throws CoreException {
@@ -281,13 +281,12 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
281
281
final String remoteUrl = url ;
282
282
283
283
ArchetypeCatalog catalog = maven .createExecutionContext ().execute ((ctx , m ) -> {
284
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
285
284
try {
286
- ArtifactRepository archeTypeRepo = new MavenArtifactRepository ();
287
- archeTypeRepo . setUrl ( remoteUrl );
288
- archeTypeRepo . setId ( RemoteCatalogArchetypeDataSource . ARCHETYPE_REPOSITORY_ID );
289
- buildingRequest . getRemoteRepositories (). add (archeTypeRepo );
290
- return source .getArchetypeCatalog (buildingRequest );
285
+ RemoteRepository archetypeRepo = new RemoteRepository . Builder (
286
+ RemoteCatalogArchetypeDataSource . ARCHETYPE_REPOSITORY_ID , "" , remoteUrl ). build ( );
287
+ List < RemoteRepository > remoteRepositories = new ArrayList <>( ArchetypePlugin . getRemoteRepositories ( ctx ) );
288
+ remoteRepositories . add (0 , archetypeRepo );
289
+ return source .getArchetypeCatalog (ctx . getRepositorySession (), remoteRepositories );
291
290
} catch (ArchetypeDataSourceException e ) {
292
291
return new ArchetypeCatalog ();
293
292
}
0 commit comments