From 3647eb9374b3b821d33b5989349096dbede4d785 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sun, 23 Feb 2025 09:34:02 +0100 Subject: [PATCH 1/6] [TP] Update to Archetype 3.3.1 and unify archetypes OSGi metadata - Adapt to API changes in archetype-common - Updating to Archetype 3.3. allows to remove the 'maven-artifact-transfer' dependency. --- m2e-core-tests | 2 +- org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF | 13 +++-- .../archetype/ArchetypeCatalogFactory.java | 35 +++++-------- .../internal/archetype/ArchetypePlugin.java | 35 ++++++------- org.eclipse.m2e.feature/feature.xml | 4 -- target-platform/target-platform.target | 52 +++++++------------ 6 files changed, 57 insertions(+), 84 deletions(-) diff --git a/m2e-core-tests b/m2e-core-tests index c153faa8aa..da85ee3a2e 160000 --- a/m2e-core-tests +++ b/m2e-core-tests @@ -1 +1 @@ -Subproject commit c153faa8aa9286f51fa35b7123718a96fc3a7bd5 +Subproject commit da85ee3a2ebb7f3ab6de48da8c5cd11539daef68 diff --git a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF index 5abf9d3ddf..b3a2a2bfcc 100644 --- a/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF @@ -44,12 +44,12 @@ Require-Bundle: org.eclipse.m2e.core;bundle-version="[2.0.0,3.0.0)", org.eclipse.ui.navigator, org.eclipse.debug.ui Import-Package: org.apache.maven.archetype.catalog;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.archetype.catalog.io.xpp3;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.archetype.common;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.archetype.exception;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.archetype.metadata;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.archetype.source;provider=m2e;version="[3.2.1,4.0.0)", - org.apache.maven.shared.transfer.artifact;provider=m2e;version="[0.13.1,1.0.0)", + org.apache.maven.archetype.catalog.io.xpp3;provider=m2e;version="[3.3.0,4.0.0)", + org.apache.maven.archetype.common;provider=m2e;version="[3.3.0,4.0.0)", + org.apache.maven.archetype.downloader;provider=m2e;version="[3.3.0,4.0.0)", + org.apache.maven.archetype.exception;provider=m2e;version="[3.3.0,4.0.0)", + org.apache.maven.archetype.metadata;provider=m2e;version="[3.3.0,4.0.0)", + org.apache.maven.archetype.source;provider=m2e;version="[3.3.0,4.0.0)", org.eclipse.compare.rangedifferencer, org.eclipse.ltk.core.refactoring, org.slf4j;version="[1.7.0,3.0.0)" @@ -57,4 +57,3 @@ Service-Component: OSGI-INF/component.xml, OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypeGenerator.xml, OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypePlugin.xml Automatic-Module-Name: org.eclipse.m2e.core.ui - diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeCatalogFactory.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeCatalogFactory.java index 41de8cd4b6..1924eb31d7 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeCatalogFactory.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeCatalogFactory.java @@ -13,6 +13,7 @@ package org.eclipse.m2e.core.ui.internal.archetype; +import java.io.File; import java.io.InputStream; import java.net.URI; import java.net.URL; @@ -24,6 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; import org.eclipse.osgi.util.NLS; @@ -34,9 +36,6 @@ import org.apache.maven.archetype.source.ArchetypeDataSource; import org.apache.maven.archetype.source.ArchetypeDataSourceException; import org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.MavenArtifactRepository; -import org.apache.maven.project.ProjectBuildingRequest; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.embedder.IMavenExecutionContext; @@ -111,7 +110,7 @@ public static class InternalCatalogFactory extends ArchetypeCatalogFactory { @Override public ArchetypeCatalog getArchetypeCatalog() { try { - return source.getArchetypeCatalog(null); + return source.getArchetypeCatalog(null, null); } catch(ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } @@ -137,9 +136,8 @@ public static class DefaultLocalCatalogFactory extends ArchetypeCatalogFactory { @Override public ArchetypeCatalog getArchetypeCatalog() throws CoreException { return maven.createExecutionContext().execute((ctx, m) -> { - ProjectBuildingRequest buildingRequest = ctx.newProjectBuildingRequest(); try { - return source.getArchetypeCatalog(buildingRequest); + return source.getArchetypeCatalog(ctx.getRepositorySession(), ArchetypePlugin.getRemoteRepositories(ctx)); } catch(ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } @@ -173,14 +171,10 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException { if(catalog == null) { //local but not embedded catalog IMavenExecutionContext context = maven.createExecutionContext(); - ArtifactRepository localRepository = new MavenArtifactRepository(); - localRepository.setUrl(getLocalRepositoryURL()); - context.getExecutionRequest().setLocalRepository(localRepository); + context.getExecutionRequest().setLocalRepositoryPath(getLocalRepositoryPath()); return context.execute((ctx, m) -> { - ProjectBuildingRequest buildingRequest = ctx.newProjectBuildingRequest(); - buildingRequest.setLocalRepository(localRepository); try { - return source.getArchetypeCatalog(buildingRequest); + return source.getArchetypeCatalog(ctx.getRepositorySession(), ArchetypePlugin.getRemoteRepositories(ctx)); } catch(ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } @@ -189,7 +183,7 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException { return catalog; } - private String getLocalRepositoryURL() { + private File getLocalRepositoryPath() { Path path; try { // First try to use the id as a path, then as a URI else as it is path = Path.of(getId()); @@ -197,14 +191,14 @@ private String getLocalRepositoryURL() { try { path = Path.of(new URI(getId())); } catch(Exception e2) { - return getId(); + throw new IllegalStateException("Illegal repository path: " + getId()); } } path = path.toAbsolutePath(); if(Files.isRegularFile(path)) { path = path.getParent(); } - return path.toUri().toString(); + return path.toFile(); } private ArchetypeCatalog getEmbeddedCatalog() throws CoreException { @@ -281,13 +275,12 @@ public ArchetypeCatalog getArchetypeCatalog() throws CoreException { final String remoteUrl = url; ArchetypeCatalog catalog = maven.createExecutionContext().execute((ctx, m) -> { - ProjectBuildingRequest buildingRequest = ctx.newProjectBuildingRequest(); try { - ArtifactRepository archeTypeRepo = new MavenArtifactRepository(); - archeTypeRepo.setUrl(remoteUrl); - archeTypeRepo.setId(RemoteCatalogArchetypeDataSource.ARCHETYPE_REPOSITORY_ID); - buildingRequest.getRemoteRepositories().add(archeTypeRepo); - return source.getArchetypeCatalog(buildingRequest); + RemoteRepository archeTypeRepo = new RemoteRepository.Builder( + RemoteCatalogArchetypeDataSource.ARCHETYPE_REPOSITORY_ID, "", remoteUrl).build(); + List remoteRepositories = new ArrayList<>(ArchetypePlugin.getRemoteRepositories(ctx)); + remoteRepositories.add(archeTypeRepo); + return source.getArchetypeCatalog(ctx.getRepositorySession(), remoteRepositories); } catch(ArchetypeDataSourceException e) { return new ArchetypeCatalog(); } diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index 24a349d31e..6512bcae2b 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -36,6 +36,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Module; +import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; @@ -50,6 +51,7 @@ import org.codehaus.plexus.classworlds.ClassWorld; import org.codehaus.plexus.component.repository.exception.ComponentLookupException; +import org.apache.maven.RepositoryUtils; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.common.ArchetypeArtifactManager; import org.apache.maven.archetype.exception.UnknownArchetype; @@ -57,10 +59,9 @@ import org.apache.maven.archetype.metadata.RequiredProperty; import org.apache.maven.archetype.source.ArchetypeDataSource; import org.apache.maven.archetype.source.ArchetypeDataSourceException; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.project.ProjectBuildingRequest; import org.eclipse.m2e.core.embedder.IMaven; +import org.eclipse.m2e.core.embedder.IMavenExecutionContext; import org.eclipse.m2e.core.internal.MavenPluginActivator; import org.eclipse.m2e.core.project.IArchetype; import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator; @@ -114,6 +115,7 @@ protected void configure() { .setClassWorld(new ClassWorld("plexus.core", ArchetypeArtifactManager.class.getClassLoader())) //$NON-NLS-1$ .setClassPathScanning(PlexusConstants.SCANNING_INDEX) // .setAutoWiring(true) // + .setJSR250Lifecycle(true) // .setName("plexus"); //$NON-NLS-1$ container = new DefaultPlexusContainer(cc, logginModule); archetypeArtifactManager = container.lookup(ArchetypeArtifactManager.class); @@ -219,36 +221,33 @@ public List getRequiredProperties(IArchetype archetype, IProgr final String artifactId = archetype.getArtifactId(); final String version = archetype.getVersion(); - final List repositories = new ArrayList<>(maven.getArtifactRepositories()); - return maven.createExecutionContext().execute((context, monitor1) -> { - ArtifactRepository localRepository = context.getLocalRepository(); - if(archetypeArtifactManager.isFileSetArchetype(groupId, artifactId, version, null, localRepository, repositories, - context.newProjectBuildingRequest())) { - ArchetypeDescriptor descriptor; - try { - descriptor = archetypeArtifactManager.getFileSetArchetypeDescriptor(groupId, artifactId, version, null, - localRepository, repositories, context.newProjectBuildingRequest()); - } catch(UnknownArchetype ex) { - throw new CoreException(Status.error("UnknownArchetype", ex)); + try { + File archetypeFile = archetypeArtifactManager.getArchetypeFile(groupId, artifactId, version, + getRemoteRepositories(context), context.getRepositorySession()); + if(archetypeArtifactManager.isFileSetArchetype(archetypeFile)) { + ArchetypeDescriptor descriptor = archetypeArtifactManager.getFileSetArchetypeDescriptor(archetypeFile); + return descriptor.getRequiredProperties(); } - return descriptor.getRequiredProperties(); + return null; + } catch(UnknownArchetype ex) { + throw new CoreException(Status.error("UnknownArchetype", ex)); } - return null; }, monitor); } public void updateLocalCatalog(Archetype archetype) throws CoreException { maven.createExecutionContext().execute((ctx, m) -> { - ProjectBuildingRequest request = ctx.newProjectBuildingRequest(); try { ArchetypeDataSource source = archetypeDataSourceMap.get("catalog"); - - source.updateCatalog(request, archetype); + source.updateCatalog(ctx.getRepositorySession(), archetype); } catch(ArchetypeDataSourceException e) { } return null; }, null); } + static List getRemoteRepositories(IMavenExecutionContext ctx) throws CoreException { + return RepositoryUtils.toRepos(ctx.getExecutionRequest().getRemoteRepositories()); + } } diff --git a/org.eclipse.m2e.feature/feature.xml b/org.eclipse.m2e.feature/feature.xml index c5adf59544..87cbad0e4c 100644 --- a/org.eclipse.m2e.feature/feature.xml +++ b/org.eclipse.m2e.feature/feature.xml @@ -34,10 +34,6 @@ id="org.eclipse.m2e.archetype.descriptor" version="0.0.0"/> - - diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index 6abfaaaefe..a04ca9e498 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -133,60 +133,46 @@ - + org.apache.maven.archetype archetype-common - 3.2.1 + 3.3.1 jar - - - - - org.apache.maven.archetype archetype-catalog - 3.2.1 + 3.3.1 jar org.apache.maven.archetype archetype-descriptor - 3.2.1 - jar - - - org.apache.maven.shared - maven-artifact-transfer - 0.13.1 + 3.3.1 jar From fb761849904bf0634045167e1443536ced17fc2e Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 1 Mar 2025 19:54:26 +0100 Subject: [PATCH 2/6] [FIXUP] Migrate to Guice directly --- .../internal/archetype/ArchetypePlugin.java | 22 +++++++++++++++++++ org.eclipse.m2e.maven.runtime/pom.xml | 8 ++++--- pom.xml | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index 6512bcae2b..63e2d82df6 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.stream.Collectors; +import org.osgi.framework.FrameworkUtil; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Deactivate; @@ -34,6 +35,8 @@ import org.slf4j.LoggerFactory; import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.Module; import org.eclipse.aether.repository.RemoteRepository; @@ -42,6 +45,11 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; +import org.eclipse.sisu.space.BeanScanning; +import org.eclipse.sisu.space.BundleClassSpace; +import org.eclipse.sisu.space.ClassSpace; +import org.eclipse.sisu.space.SpaceModule; +import org.eclipse.sisu.wire.WireModule; import org.codehaus.plexus.ContainerConfiguration; import org.codehaus.plexus.DefaultContainerConfiguration; @@ -54,6 +62,8 @@ import org.apache.maven.RepositoryUtils; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.common.ArchetypeArtifactManager; +import org.apache.maven.archetype.common.DefaultArchetypeArtifactManager; +import org.apache.maven.archetype.downloader.Downloader; import org.apache.maven.archetype.exception.UnknownArchetype; import org.apache.maven.archetype.metadata.ArchetypeDescriptor; import org.apache.maven.archetype.metadata.RequiredProperty; @@ -117,7 +127,19 @@ protected void configure() { .setAutoWiring(true) // .setJSR250Lifecycle(true) // .setName("plexus"); //$NON-NLS-1$ + + ClassSpace space = new BundleClassSpace(FrameworkUtil.getBundle(ArchetypeArtifactManager.class)); + Injector injector = Guice.createInjector(logginModule, + new WireModule(new SpaceModule(space, BeanScanning.INDEX, false))); + ArchetypeArtifactManager mgr1 = injector.getInstance(DefaultArchetypeArtifactManager.class); + try { + ArchetypeArtifactManager mgr2 = injector.getInstance(ArchetypeArtifactManager.class); + } catch(Exception ex) { + //TODO: doesn't work? + } container = new DefaultPlexusContainer(cc, logginModule); + Downloader downloader = container.lookup(Downloader.class); + //TODO: a Downloader can be created, but isn't injected into the fields of a created archetypeArtifactManager archetypeArtifactManager = container.lookup(ArchetypeArtifactManager.class); archetypeDataSourceMap = container.lookupMap(ArchetypeDataSource.class); addArchetypeCatalogFactory( diff --git a/org.eclipse.m2e.maven.runtime/pom.xml b/org.eclipse.m2e.maven.runtime/pom.xml index 8c9c800819..132d8d893a 100644 --- a/org.eclipse.m2e.maven.runtime/pom.xml +++ b/org.eclipse.m2e.maven.runtime/pom.xml @@ -21,7 +21,7 @@ org.eclipse.m2e.maven.runtime - 3.9.900-SNAPSHOT + 3.9.901-SNAPSHOT jar M2E Embedded Maven Runtime (includes Incubating components) @@ -202,8 +202,10 @@ org.slf4j.*;version="[1.7.31,3.0.0)",\ javax.inject;version="[1.0.0,2.0.0)",\ javax.annotation;version="[1.2.0,2.0.0)", \ - org.apache.commons.cli;version="[1.4.0,2.0.0)", \ - org.apache.commons.codec* + org.apache.commons.cli;version="[1.4.0,2.0.0)",\ + org.apache.commons.codec*,\ + org.osgi.*,\ + Require-Bundle: \ com.google.guava;bundle-version="32.2.1" diff --git a/pom.xml b/pom.xml index 3ffe83e7c3..e44d1cb5e5 100644 --- a/pom.xml +++ b/pom.xml @@ -99,7 +99,7 @@ org.eclipse.m2e org.eclipse.m2e.maven.runtime - 3.9.900-SNAPSHOT + 3.9.901-SNAPSHOT From defc2e2d522880a4c9565866debd07ce8b4eaac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 2 Mar 2025 09:20:14 +0100 Subject: [PATCH 3/6] Use Sisu/Guice instead of plexus container for component lookup --- .../internal/archetype/ArchetypePlugin.java | 72 +++++++------------ target-platform/target-platform.target | 2 +- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index 63e2d82df6..b5166e1dc1 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -39,6 +39,7 @@ import com.google.inject.Injector; import com.google.inject.Module; +import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.repository.RemoteRepository; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; @@ -51,24 +52,16 @@ import org.eclipse.sisu.space.SpaceModule; import org.eclipse.sisu.wire.WireModule; -import org.codehaus.plexus.ContainerConfiguration; -import org.codehaus.plexus.DefaultContainerConfiguration; -import org.codehaus.plexus.DefaultPlexusContainer; -import org.codehaus.plexus.PlexusConstants; -import org.codehaus.plexus.PlexusContainerException; -import org.codehaus.plexus.classworlds.ClassWorld; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; - import org.apache.maven.RepositoryUtils; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.common.ArchetypeArtifactManager; -import org.apache.maven.archetype.common.DefaultArchetypeArtifactManager; -import org.apache.maven.archetype.downloader.Downloader; import org.apache.maven.archetype.exception.UnknownArchetype; import org.apache.maven.archetype.metadata.ArchetypeDescriptor; import org.apache.maven.archetype.metadata.RequiredProperty; -import org.apache.maven.archetype.source.ArchetypeDataSource; import org.apache.maven.archetype.source.ArchetypeDataSourceException; +import org.apache.maven.archetype.source.InternalCatalogArchetypeDataSource; +import org.apache.maven.archetype.source.LocalCatalogArchetypeDataSource; +import org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.embedder.IMavenExecutionContext; @@ -87,6 +80,10 @@ @Component(service = ArchetypePlugin.class) public class ArchetypePlugin { + private static final InternalCatalogArchetypeDataSource INTERNAL_CATALOG_ARCHETYPE_DATA_SOURCE = new InternalCatalogArchetypeDataSource(); + + private static final LocalCatalogArchetypeDataSource LOCAL_CATALOG = new LocalCatalogArchetypeDataSource(); + public static final String ARCHETYPE_PREFIX = "archetype"; private final Map catalogs = new LinkedHashMap<>(); @@ -103,10 +100,6 @@ public class ArchetypePlugin { private ArchetypeArtifactManager archetypeArtifactManager; - private Map archetypeDataSourceMap; - - private DefaultPlexusContainer container; - public ArchetypePlugin() { this.configFile = new File(MavenPluginActivator.getDefault().getStateLocation().toFile(), M2EUIPluginActivator.PREFS_ARCHETYPES); @@ -114,38 +107,30 @@ public ArchetypePlugin() { } @Activate - void activate() throws PlexusContainerException, ComponentLookupException { + void activate() { final Module logginModule = new AbstractModule() { @Override protected void configure() { bind(ILoggerFactory.class).toInstance(LoggerFactory.getILoggerFactory()); } }; - final ContainerConfiguration cc = new DefaultContainerConfiguration() // - .setClassWorld(new ClassWorld("plexus.core", ArchetypeArtifactManager.class.getClassLoader())) //$NON-NLS-1$ - .setClassPathScanning(PlexusConstants.SCANNING_INDEX) // - .setAutoWiring(true) // - .setJSR250Lifecycle(true) // - .setName("plexus"); //$NON-NLS-1$ - ClassSpace space = new BundleClassSpace(FrameworkUtil.getBundle(ArchetypeArtifactManager.class)); - Injector injector = Guice.createInjector(logginModule, - new WireModule(new SpaceModule(space, BeanScanning.INDEX, false))); - ArchetypeArtifactManager mgr1 = injector.getInstance(DefaultArchetypeArtifactManager.class); - try { - ArchetypeArtifactManager mgr2 = injector.getInstance(ArchetypeArtifactManager.class); - } catch(Exception ex) { - //TODO: doesn't work? - } - container = new DefaultPlexusContainer(cc, logginModule); - Downloader downloader = container.lookup(Downloader.class); - //TODO: a Downloader can be created, but isn't injected into the fields of a created archetypeArtifactManager - archetypeArtifactManager = container.lookup(ArchetypeArtifactManager.class); - archetypeDataSourceMap = container.lookupMap(ArchetypeDataSource.class); - addArchetypeCatalogFactory( - new ArchetypeCatalogFactory.InternalCatalogFactory(archetypeDataSourceMap.get("internal-catalog"))); + final Module repositorySystemModule = new AbstractModule() { + @Override + protected void configure() { + try { + bind(RepositorySystem.class).toInstance(MavenPluginActivator.getDefault().getRepositorySystem()); + } catch(CoreException ex) { + ex.printStackTrace(); + } + } + }; + Injector injector = Guice.createInjector( + new WireModule(logginModule, repositorySystemModule, new SpaceModule(space, BeanScanning.INDEX, false))); + archetypeArtifactManager = injector.getInstance(ArchetypeArtifactManager.class); addArchetypeCatalogFactory( - new ArchetypeCatalogFactory.DefaultLocalCatalogFactory(maven, archetypeDataSourceMap.get("catalog"))); + new ArchetypeCatalogFactory.InternalCatalogFactory(INTERNAL_CATALOG_ARCHETYPE_DATA_SOURCE)); + addArchetypeCatalogFactory(new ArchetypeCatalogFactory.DefaultLocalCatalogFactory(maven, LOCAL_CATALOG)); for(ArchetypeCatalogFactory archetypeCatalogFactory : ExtensionReader.readArchetypeExtensions(this)) { addArchetypeCatalogFactory(archetypeCatalogFactory); } @@ -159,18 +144,16 @@ protected void configure() { @Deactivate void shutdown() throws IOException { saveCatalogs(); - container.dispose(); } public LocalCatalogFactory newLocalCatalogFactory(String path, String description, boolean editable, boolean enabled) { - return new LocalCatalogFactory(path, description, editable, enabled, maven, archetypeDataSourceMap.get("catalog")); + return new LocalCatalogFactory(path, description, editable, enabled, maven, LOCAL_CATALOG); } public RemoteCatalogFactory newRemoteCatalogFactory(String url, String description, boolean editable, boolean enabled) { - return new RemoteCatalogFactory(url, description, editable, enabled, maven, - archetypeDataSourceMap.get("remote-catalog")); + return new RemoteCatalogFactory(url, description, editable, enabled, maven, new RemoteCatalogArchetypeDataSource()); } public ArchetypeGenerator getGenerator() { @@ -261,8 +244,7 @@ public List getRequiredProperties(IArchetype archetype, IProgr public void updateLocalCatalog(Archetype archetype) throws CoreException { maven.createExecutionContext().execute((ctx, m) -> { try { - ArchetypeDataSource source = archetypeDataSourceMap.get("catalog"); - source.updateCatalog(ctx.getRepositorySession(), archetype); + LOCAL_CATALOG.updateCatalog(ctx.getRepositorySession(), archetype); } catch(ArchetypeDataSourceException e) { } return null; diff --git a/target-platform/target-platform.target b/target-platform/target-platform.target index a04ca9e498..85fbea2631 100644 --- a/target-platform/target-platform.target +++ b/target-platform/target-platform.target @@ -168,7 +168,7 @@ Eclipse-ExtensibleAPI: true Require-Bundle: \ org.eclipse.m2e.maven.runtime;bundle-version="[3.8.0,4.0.0)", \ com.ibm.icu -Import-Package: org.jdom2* +Import-Package: org.jdom2*,javax.inject Export-Package: \ META-INF.sisu;-noimport:=true;x-internal:=true, \ org.apache.maven.archetype.*;provider=m2e;mandatory:=provider;version="${version}";x-friends:="org.eclipse.m2e.core.ui", \ From eb20e7eb8a2cf4491ee4535e89239c8b6b36e162 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 2 Mar 2025 09:27:35 +0100 Subject: [PATCH 4/6] Try using "deprecated" constructor --- .../eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index b5166e1dc1..4554a12689 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -126,7 +126,7 @@ protected void configure() { } }; Injector injector = Guice.createInjector( - new WireModule(logginModule, repositorySystemModule, new SpaceModule(space, BeanScanning.INDEX, false))); + new WireModule(logginModule, repositorySystemModule, new SpaceModule(space, BeanScanning.INDEX))); archetypeArtifactManager = injector.getInstance(ArchetypeArtifactManager.class); addArchetypeCatalogFactory( new ArchetypeCatalogFactory.InternalCatalogFactory(INTERNAL_CATALOG_ARCHETYPE_DATA_SOURCE)); From c49b0b5488acded4da9c5b2b59dd7e8bced76782 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 2 Mar 2025 11:19:26 +0100 Subject: [PATCH 5/6] Setup the logger --- .../internal/archetype/ArchetypePlugin.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index 4554a12689..bda99f172a 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -52,6 +52,8 @@ import org.eclipse.sisu.space.SpaceModule; import org.eclipse.sisu.wire.WireModule; +import org.codehaus.plexus.logging.LogEnabled; + import org.apache.maven.RepositoryUtils; import org.apache.maven.archetype.catalog.Archetype; import org.apache.maven.archetype.common.ArchetypeArtifactManager; @@ -62,6 +64,7 @@ import org.apache.maven.archetype.source.InternalCatalogArchetypeDataSource; import org.apache.maven.archetype.source.LocalCatalogArchetypeDataSource; import org.apache.maven.archetype.source.RemoteCatalogArchetypeDataSource; +import org.apache.maven.cli.logging.Slf4jLogger; import org.eclipse.m2e.core.embedder.IMaven; import org.eclipse.m2e.core.embedder.IMavenExecutionContext; @@ -80,7 +83,12 @@ @Component(service = ArchetypePlugin.class) public class ArchetypePlugin { - private static final InternalCatalogArchetypeDataSource INTERNAL_CATALOG_ARCHETYPE_DATA_SOURCE = new InternalCatalogArchetypeDataSource(); + /** + * + */ + private static final RemoteCatalogArchetypeDataSource REMOTE_CATALOG = new RemoteCatalogArchetypeDataSource(); + + private static final InternalCatalogArchetypeDataSource INTERNAL_CATALOG = new InternalCatalogArchetypeDataSource(); private static final LocalCatalogArchetypeDataSource LOCAL_CATALOG = new LocalCatalogArchetypeDataSource(); @@ -114,6 +122,10 @@ protected void configure() { bind(ILoggerFactory.class).toInstance(LoggerFactory.getILoggerFactory()); } }; + Slf4jLogger logger = new Slf4jLogger(LoggerFactory.getILoggerFactory().getLogger("catalog")); + REMOTE_CATALOG.enableLogging(logger); + INTERNAL_CATALOG.enableLogging(logger); + LOCAL_CATALOG.enableLogging(logger); ClassSpace space = new BundleClassSpace(FrameworkUtil.getBundle(ArchetypeArtifactManager.class)); final Module repositorySystemModule = new AbstractModule() { @Override @@ -128,8 +140,11 @@ protected void configure() { Injector injector = Guice.createInjector( new WireModule(logginModule, repositorySystemModule, new SpaceModule(space, BeanScanning.INDEX))); archetypeArtifactManager = injector.getInstance(ArchetypeArtifactManager.class); + if(archetypeArtifactManager instanceof LogEnabled le) { + le.enableLogging(logger); + } addArchetypeCatalogFactory( - new ArchetypeCatalogFactory.InternalCatalogFactory(INTERNAL_CATALOG_ARCHETYPE_DATA_SOURCE)); + new ArchetypeCatalogFactory.InternalCatalogFactory(INTERNAL_CATALOG)); addArchetypeCatalogFactory(new ArchetypeCatalogFactory.DefaultLocalCatalogFactory(maven, LOCAL_CATALOG)); for(ArchetypeCatalogFactory archetypeCatalogFactory : ExtensionReader.readArchetypeExtensions(this)) { addArchetypeCatalogFactory(archetypeCatalogFactory); @@ -153,7 +168,7 @@ public LocalCatalogFactory newLocalCatalogFactory(String path, String descriptio public RemoteCatalogFactory newRemoteCatalogFactory(String url, String description, boolean editable, boolean enabled) { - return new RemoteCatalogFactory(url, description, editable, enabled, maven, new RemoteCatalogArchetypeDataSource()); + return new RemoteCatalogFactory(url, description, editable, enabled, maven, REMOTE_CATALOG); } public ArchetypeGenerator getGenerator() { From 6ea2f5264c2cea742407d7156bb9b450d60617cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 2 Mar 2025 11:53:41 +0100 Subject: [PATCH 6/6] let injector create remote catlog --- .../ui/internal/archetype/ArchetypePlugin.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java index bda99f172a..13597ef6b6 100644 --- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java +++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java @@ -83,11 +83,6 @@ @Component(service = ArchetypePlugin.class) public class ArchetypePlugin { - /** - * - */ - private static final RemoteCatalogArchetypeDataSource REMOTE_CATALOG = new RemoteCatalogArchetypeDataSource(); - private static final InternalCatalogArchetypeDataSource INTERNAL_CATALOG = new InternalCatalogArchetypeDataSource(); private static final LocalCatalogArchetypeDataSource LOCAL_CATALOG = new LocalCatalogArchetypeDataSource(); @@ -108,6 +103,8 @@ public class ArchetypePlugin { private ArchetypeArtifactManager archetypeArtifactManager; + private RemoteCatalogArchetypeDataSource remoteCatalog; + public ArchetypePlugin() { this.configFile = new File(MavenPluginActivator.getDefault().getStateLocation().toFile(), M2EUIPluginActivator.PREFS_ARCHETYPES); @@ -123,7 +120,6 @@ protected void configure() { } }; Slf4jLogger logger = new Slf4jLogger(LoggerFactory.getILoggerFactory().getLogger("catalog")); - REMOTE_CATALOG.enableLogging(logger); INTERNAL_CATALOG.enableLogging(logger); LOCAL_CATALOG.enableLogging(logger); ClassSpace space = new BundleClassSpace(FrameworkUtil.getBundle(ArchetypeArtifactManager.class)); @@ -143,6 +139,10 @@ protected void configure() { if(archetypeArtifactManager instanceof LogEnabled le) { le.enableLogging(logger); } + this.remoteCatalog = injector.getInstance(RemoteCatalogArchetypeDataSource.class); + if(remoteCatalog instanceof LogEnabled le) { + le.enableLogging(logger); + } addArchetypeCatalogFactory( new ArchetypeCatalogFactory.InternalCatalogFactory(INTERNAL_CATALOG)); addArchetypeCatalogFactory(new ArchetypeCatalogFactory.DefaultLocalCatalogFactory(maven, LOCAL_CATALOG)); @@ -168,7 +168,7 @@ public LocalCatalogFactory newLocalCatalogFactory(String path, String descriptio public RemoteCatalogFactory newRemoteCatalogFactory(String url, String description, boolean editable, boolean enabled) { - return new RemoteCatalogFactory(url, description, editable, enabled, maven, REMOTE_CATALOG); + return new RemoteCatalogFactory(url, description, editable, enabled, maven, remoteCatalog); } public ArchetypeGenerator getGenerator() {