1313
1414package org .eclipse .m2e .core .ui .internal .archetype ;
1515
16+ import java .io .File ;
1617import java .io .InputStream ;
1718import java .net .URI ;
1819import java .net .URL ;
2425import org .slf4j .Logger ;
2526import org .slf4j .LoggerFactory ;
2627
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 ;
2733import org .eclipse .core .runtime .CoreException ;
2834import org .eclipse .core .runtime .Status ;
2935import org .eclipse .osgi .util .NLS ;
3440import org .apache .maven .archetype .source .ArchetypeDataSource ;
3541import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
3642import 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 ;
4043
4144import org .eclipse .m2e .core .embedder .IMaven ;
42- import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
4345import org .eclipse .m2e .core .internal .Messages ;
4446
4547
@@ -111,7 +113,7 @@ public static class InternalCatalogFactory extends ArchetypeCatalogFactory {
111113 @ Override
112114 public ArchetypeCatalog getArchetypeCatalog () {
113115 try {
114- return source .getArchetypeCatalog (null );
116+ return source .getArchetypeCatalog (null , null );
115117 } catch (ArchetypeDataSourceException e ) {
116118 return new ArchetypeCatalog ();
117119 }
@@ -137,9 +139,8 @@ public static class DefaultLocalCatalogFactory extends ArchetypeCatalogFactory {
137139 @ Override
138140 public ArchetypeCatalog getArchetypeCatalog () throws CoreException {
139141 return maven .createExecutionContext ().execute ((ctx , m ) -> {
140- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
141142 try {
142- return source .getArchetypeCatalog (buildingRequest );
143+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
143144 } catch (ArchetypeDataSourceException e ) {
144145 return new ArchetypeCatalog ();
145146 }
@@ -172,39 +173,38 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
172173 ArchetypeCatalog catalog = getEmbeddedCatalog ();
173174 if (catalog == null ) {
174175 //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 ) -> {
182178 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 ) {
185185 return new ArchetypeCatalog ();
186186 }
187187 }, null );
188188 }
189189 return catalog ;
190190 }
191191
192- private String getLocalRepositoryURL () {
192+ private File getLocalRepositoryPath () {
193193 Path path ;
194194 try { // First try to use the id as a path, then as a URI else as it is
195195 path = Path .of (getId ());
196196 } catch (Exception e1 ) {
197197 try {
198198 path = Path .of (new URI (getId ()));
199199 } catch (Exception e2 ) {
200- return getId ();
200+ return new File ( getId () );
201201 }
202202 }
203203 path = path .toAbsolutePath ();
204204 if (Files .isRegularFile (path )) {
205205 path = path .getParent ();
206206 }
207- return path .toUri (). toString ();
207+ return path .toFile ();
208208 }
209209
210210 private ArchetypeCatalog getEmbeddedCatalog () throws CoreException {
@@ -281,13 +281,12 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
281281 final String remoteUrl = url ;
282282
283283 ArchetypeCatalog catalog = maven .createExecutionContext ().execute ((ctx , m ) -> {
284- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
285284 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 );
291290 } catch (ArchetypeDataSourceException e ) {
292291 return new ArchetypeCatalog ();
293292 }
0 commit comments