2525import org .slf4j .Logger ;
2626import org .slf4j .LoggerFactory ;
2727
28+ import org .eclipse .aether .DefaultRepositorySystemSession ;
29+ import org .eclipse .aether .repository .LocalRepository ;
30+ import org .eclipse .aether .repository .NoLocalRepositoryManagerException ;
2831import org .eclipse .aether .repository .RemoteRepository ;
32+ import org .eclipse .aether .spi .localrepo .LocalRepositoryManagerFactory ;
2933import org .eclipse .core .runtime .CoreException ;
3034import org .eclipse .core .runtime .Status ;
3135import org .eclipse .osgi .util .NLS ;
3842import org .apache .maven .archetype .source .RemoteCatalogArchetypeDataSource ;
3943
4044import org .eclipse .m2e .core .embedder .IMaven ;
41- import org .eclipse .m2e .core .embedder .IMavenExecutionContext ;
4245import org .eclipse .m2e .core .internal .Messages ;
4346
4447
@@ -170,12 +173,15 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
170173 ArchetypeCatalog catalog = getEmbeddedCatalog ();
171174 if (catalog == null ) {
172175 //local but not embedded catalog
173- IMavenExecutionContext context = maven .createExecutionContext ();
174- context .getExecutionRequest ().setLocalRepositoryPath (getLocalRepositoryPath ());
175- return context .execute ((ctx , m ) -> {
176+ File localRepositoryPath = getLocalRepositoryPath ();
177+ return maven .createExecutionContext ().execute ((ctx , m ) -> {
176178 try {
177- return source .getArchetypeCatalog (ctx .getRepositorySession (), ArchetypePlugin .getRemoteRepositories (ctx ));
178- } 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 ) {
179185 return new ArchetypeCatalog ();
180186 }
181187 }, null );
@@ -191,7 +197,7 @@ private File getLocalRepositoryPath() {
191197 try {
192198 path = Path .of (new URI (getId ()));
193199 } catch (Exception e2 ) {
194- throw new IllegalStateException ( "Illegal repository path: " + getId ());
200+ return new File ( getId ());
195201 }
196202 }
197203 path = path .toAbsolutePath ();
@@ -276,10 +282,10 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
276282
277283 ArchetypeCatalog catalog = maven .createExecutionContext ().execute ((ctx , m ) -> {
278284 try {
279- RemoteRepository archeTypeRepo = new RemoteRepository .Builder (
285+ RemoteRepository archetypeRepo = new RemoteRepository .Builder (
280286 RemoteCatalogArchetypeDataSource .ARCHETYPE_REPOSITORY_ID , "" , remoteUrl ).build ();
281287 List <RemoteRepository > remoteRepositories = new ArrayList <>(ArchetypePlugin .getRemoteRepositories (ctx ));
282- remoteRepositories .add (archeTypeRepo );
288+ remoteRepositories .add (0 , archetypeRepo );
283289 return source .getArchetypeCatalog (ctx .getRepositorySession (), remoteRepositories );
284290 } catch (ArchetypeDataSourceException e ) {
285291 return new ArchetypeCatalog ();
0 commit comments