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 .repository .RemoteRepository ;
2729import org .eclipse .core .runtime .CoreException ;
2830import org .eclipse .core .runtime .Status ;
2931import org .eclipse .osgi .util .NLS ;
3436import org .apache .maven .archetype .source .ArchetypeDataSource ;
3537import org .apache .maven .archetype .source .ArchetypeDataSourceException ;
3638import 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 ;
4039
4140import org .eclipse .m2e .core .embedder .IMaven ;
4241import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
@@ -111,7 +110,7 @@ public static class InternalCatalogFactory extends ArchetypeCatalogFactory {
111110 @ Override
112111 public ArchetypeCatalog getArchetypeCatalog () {
113112 try {
114- return source .getArchetypeCatalog (null );
113+ return source .getArchetypeCatalog (null , null );
115114 } catch (ArchetypeDataSourceException e ) {
116115 return new ArchetypeCatalog ();
117116 }
@@ -137,9 +136,8 @@ public static class DefaultLocalCatalogFactory extends ArchetypeCatalogFactory {
137136 @ Override
138137 public ArchetypeCatalog getArchetypeCatalog () throws CoreException {
139138 return maven .createExecutionContext ().execute ((ctx , m ) -> {
140- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
141139 try {
142- return source .getArchetypeCatalog (buildingRequest );
140+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
143141 } catch (ArchetypeDataSourceException e ) {
144142 return new ArchetypeCatalog ();
145143 }
@@ -173,14 +171,10 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
173171 if (catalog == null ) {
174172 //local but not embedded catalog
175173 IMavenExecutionContext context = maven .createExecutionContext ();
176- ArtifactRepository localRepository = new MavenArtifactRepository ();
177- localRepository .setUrl (getLocalRepositoryURL ());
178- context .getExecutionRequest ().setLocalRepository (localRepository );
174+ context .getExecutionRequest ().setLocalRepositoryPath (getLocalRepositoryPath ());
179175 return context .execute ((ctx , m ) -> {
180- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
181- buildingRequest .setLocalRepository (localRepository );
182176 try {
183- return source .getArchetypeCatalog (buildingRequest );
177+ return source .getArchetypeCatalog (ctx . getRepositorySession (), ArchetypePlugin . getRemoteRepositories ( ctx ) );
184178 } catch (ArchetypeDataSourceException e ) {
185179 return new ArchetypeCatalog ();
186180 }
@@ -189,22 +183,22 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
189183 return catalog ;
190184 }
191185
192- private String getLocalRepositoryURL () {
186+ private File getLocalRepositoryPath () {
193187 Path path ;
194188 try { // First try to use the id as a path, then as a URI else as it is
195189 path = Path .of (getId ());
196190 } catch (Exception e1 ) {
197191 try {
198192 path = Path .of (new URI (getId ()));
199193 } catch (Exception e2 ) {
200- return getId ();
194+ throw new IllegalStateException ( "Illegal repository path: " + getId () );
201195 }
202196 }
203197 path = path .toAbsolutePath ();
204198 if (Files .isRegularFile (path )) {
205199 path = path .getParent ();
206200 }
207- return path .toUri (). toString ();
201+ return path .toFile ();
208202 }
209203
210204 private ArchetypeCatalog getEmbeddedCatalog () throws CoreException {
@@ -281,13 +275,12 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
281275 final String remoteUrl = url ;
282276
283277 ArchetypeCatalog catalog = maven .createExecutionContext ().execute ((ctx , m ) -> {
284- ProjectBuildingRequest buildingRequest = ctx .newProjectBuildingRequest ();
285278 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 );
291284 } catch (ArchetypeDataSourceException e ) {
292285 return new ArchetypeCatalog ();
293286 }
0 commit comments