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 .repository .RemoteRepository ;
27
29
import org .eclipse .core .runtime .CoreException ;
28
30
import org .eclipse .core .runtime .Status ;
29
31
import org .eclipse .osgi .util .NLS ;
34
36
import org .apache .maven .archetype .source .ArchetypeDataSource ;
35
37
import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
36
38
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
39
41
40
import org .eclipse .m2e .core .embedder .IMaven ;
42
41
import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
@@ -111,7 +110,7 @@ public static class InternalCatalogFactory extends ArchetypeCatalogFactory {
111
110
@ Override
112
111
public ArchetypeCatalog getArchetypeCatalog () {
113
112
try {
114
- return source .getArchetypeCatalog (null );
113
+ return source .getArchetypeCatalog (null , null );
115
114
} catch (ArchetypeDataSourceException e ) {
116
115
return new ArchetypeCatalog ();
117
116
}
@@ -137,9 +136,8 @@ public static class DefaultLocalCatalogFactory extends ArchetypeCatalogFactory {
137
136
@ Override
138
137
public ArchetypeCatalog getArchetypeCatalog () throws CoreException {
139
138
return maven .createExecutionContext ().execute ((ctx , m ) -> {
140
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
141
139
try {
142
- return source .getArchetypeCatalog (buildingRequest );
140
+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
143
141
} catch (ArchetypeDataSourceException e ) {
144
142
return new ArchetypeCatalog ();
145
143
}
@@ -173,14 +171,10 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
173
171
if (catalog == null ) {
174
172
//local but not embedded catalog
175
173
IMavenExecutionContext context = maven .createExecutionContext ();
176
- ArtifactRepository localRepository = new MavenArtifactRepository ();
177
- localRepository .setUrl (getLocalRepositoryURL ());
178
- context .getExecutionRequest ().setLocalRepository (localRepository );
174
+ context .getExecutionRequest ().setLocalRepositoryPath (getLocalRepositoryPath ());
179
175
return context .execute ((ctx , m ) -> {
180
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
181
- buildingRequest .setLocalRepository (localRepository );
182
176
try {
183
- return source .getArchetypeCatalog (buildingRequest );
177
+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
184
178
} catch (ArchetypeDataSourceException e ) {
185
179
return new ArchetypeCatalog ();
186
180
}
@@ -189,22 +183,22 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
189
183
return catalog ;
190
184
}
191
185
192
- private String getLocalRepositoryURL () {
186
+ private File getLocalRepositoryPath () {
193
187
Path path ;
194
188
try { // First try to use the id as a path, then as a URI else as it is
195
189
path = Path .of (getId ());
196
190
} catch (Exception e1 ) {
197
191
try {
198
192
path = Path .of (new URI (getId ()));
199
193
} catch (Exception e2 ) {
200
- return getId ();
194
+ throw new IllegalStateException ( "Illegal repository path: " + getId () );
201
195
}
202
196
}
203
197
path = path .toAbsolutePath ();
204
198
if (Files .isRegularFile (path )) {
205
199
path = path .getParent ();
206
200
}
207
- return path .toUri (). toString ();
201
+ return path .toFile ();
208
202
}
209
203
210
204
private ArchetypeCatalog getEmbeddedCatalog () throws CoreException {
@@ -281,13 +275,12 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
281
275
final String remoteUrl = url ;
282
276
283
277
ArchetypeCatalog catalog = maven .createExecutionContext ().execute ((ctx , m ) -> {
284
- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
285
278
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 );
279
+ RemoteRepository archeTypeRepo = new RemoteRepository . Builder (
280
+ RemoteCatalogArchetypeDataSource . ARCHETYPE_REPOSITORY_ID , "" , remoteUrl ). build ( );
281
+ List < RemoteRepository > remoteRepositories = new ArrayList <>( ArchetypePlugin . getRemoteRepositories ( ctx ) );
282
+ remoteRepositories .add (archeTypeRepo );
283
+ return source .getArchetypeCatalog (ctx . getRepositorySession (), remoteRepositories );
291
284
} catch (ArchetypeDataSourceException e ) {
292
285
return new ArchetypeCatalog ();
293
286
}
0 commit comments