Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

429677 : fix bad archetype lookups in remote catalogs

Change-Id: Ieeb65d28ad7a666502d6a2d74c67eb3cb4e1f48a
Signed-off-by: Fred Bricon <fbricon@gmail.com>
  • Loading branch information...
commit a3296cccca6d931012869c5f1ca58114f99e5c57 1 parent 11cc883
@fbricon fbricon authored
View
45 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java
@@ -11,6 +11,8 @@
package org.eclipse.m2e.core.internal.archetype;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Properties;
import org.slf4j.Logger;
@@ -180,7 +182,48 @@ public ArchetypeCatalog getArchetypeCatalog() {
if(idx > -1) {
url = url.substring(0, idx);
}
- return getArchetyper().getRemoteCatalog(url);
+ final ArchetypeCatalog catalog = getArchetyper().getRemoteCatalog(url);
+ final String remoteUrl = url;
+ @SuppressWarnings("serial")
+ ArchetypeCatalog catalogWrapper = new ArchetypeCatalog() {
+ public void addArchetype(org.apache.maven.archetype.catalog.Archetype archetype) {
+ catalog.addArchetype(archetype);
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public List getArchetypes() {
+ List<org.apache.maven.archetype.catalog.Archetype> archetypes = new ArrayList<org.apache.maven.archetype.catalog.Archetype>(
+ catalog.getArchetypes());
+ for(org.apache.maven.archetype.catalog.Archetype arch : archetypes) {
+ if(arch.getRepository() == null || arch.getRepository().trim().isEmpty()) {
+ arch.setRepository(remoteUrl);
+ }
+ }
+ return archetypes;
+ }
+
+ public String getModelEncoding() {
+ return catalog.getModelEncoding();
+ }
+
+ public void removeArchetype(org.apache.maven.archetype.catalog.Archetype archetype) {
+ catalog.removeArchetype(archetype);
+ }
+
+ public void setModelEncoding(String modelEncoding) {
+ catalog.setModelEncoding(modelEncoding);
+ }
+
+ public void setArchetypes(List archetypes) {
+ catalog.setArchetypes(archetypes);
+ }
+
+ public String toString() {
+ return catalog.toString();
+ }
+ };
+
+ return catalogWrapper;
}
/**
View
51 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java
@@ -19,7 +19,6 @@
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
@@ -42,12 +41,10 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.eclipse.m2e.core.MavenPlugin;
-import org.eclipse.m2e.core.archetype.ArchetypeUtil;
import org.eclipse.m2e.core.embedder.ICallable;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
import org.eclipse.m2e.core.internal.NoSuchComponentException;
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
/**
@@ -128,34 +125,9 @@ public void saveCatalogs() throws IOException {
}
/**
- * @return the archetypeCatalogFactory containing the archetype parameter, null if none was found.
- */
- @SuppressWarnings("unchecked")
- public <T extends ArchetypeCatalogFactory> T findParentCatalogFactory(Archetype archetype, Class<T> type)
- throws CoreException {
- if(archetype != null) {
- for(ArchetypeCatalogFactory factory : getArchetypeCatalogs()) {
- //temporary hack to get around https://issues.sonatype.org/browse/MNGECLIPSE-1792
- //cf. MavenProjectWizardArchetypePage.getAllArchetypes
- if((type.isAssignableFrom(factory.getClass()))
- && !(factory.getDescription() != null && factory.getDescription().startsWith("Test"))) { //$NON-NLS-1$
- List<Archetype> archetypes = factory.getArchetypeCatalog().getArchetypes();
- for(Archetype knownArchetype : archetypes) {
- if(ArchetypeUtil.areEqual(archetype, knownArchetype)) {
- return (T) factory;
- }
- }
- }
- }
- }
- return null;
- }
-
- /**
* Gets the remote {@link ArtifactRepository} of the given {@link Archetype}, or null if none is found. The repository
- * url is extracted from {@link Archetype#getRepository()}, or, if it has none, the remote catalog the archetype is
- * found in. The {@link ArtifactRepository} id is set to <strong>archetypeId+"-repo"</strong>, to enable
- * authentication on that repository.
+ * url is extracted from {@link Archetype#getRepository(). The {@link ArtifactRepository} id is set to
+ * <strong>archetypeId+"-repo"</strong>, to enable authentication on that repository.
*
* @see <a
* href="http://maven.apache.org/archetype/maven-archetype-plugin/faq.html">http://maven.apache.org/archetype/maven-archetype-plugin/faq.html</a>
@@ -165,14 +137,10 @@ public void saveCatalogs() throws IOException {
*/
public ArtifactRepository getArchetypeRepository(Archetype archetype) throws CoreException {
String repoUrl = archetype.getRepository();
- if(repoUrl == null) {
- RemoteCatalogFactory catalogFactory = findParentCatalogFactory(archetype, RemoteCatalogFactory.class);
- if(catalogFactory != null) {
- repoUrl = catalogFactory.getRepositoryUrl();
- }
+ if(repoUrl == null || repoUrl.trim().isEmpty()) {
+ return null;
}
- return repoUrl == null ? null : MavenPlugin.getMaven().createArtifactRepository(
- archetype.getArtifactId() + "-repo", repoUrl); //$NON-NLS-1$
+ return MavenPlugin.getMaven().createArtifactRepository(archetype.getArtifactId() + "-repo", repoUrl); //$NON-NLS-1$
}
/**
@@ -199,12 +167,9 @@ public ArtifactRepository getArchetypeRepository(Archetype archetype) throws Cor
IMaven maven = MavenPlugin.getMaven();
- final List<ArtifactRepository> repositories;
-
- if(remoteArchetypeRepository == null) {
- repositories = maven.getArtifactRepositories();
- } else {
- repositories = Collections.singletonList(remoteArchetypeRepository);
+ final List<ArtifactRepository> repositories = new ArrayList<ArtifactRepository>(maven.getArtifactRepositories());
+ if(remoteArchetypeRepository != null) {
+ repositories.add(0, remoteArchetypeRepository);
}
@SuppressWarnings("serial")
View
17 org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/project/ProjectConfigurationManager.java
@@ -75,8 +75,6 @@
import org.eclipse.m2e.core.internal.IMavenConstants;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.internal.Messages;
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
-import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
import org.eclipse.m2e.core.internal.embedder.AbstractRunnable;
import org.eclipse.m2e.core.internal.embedder.MavenExecutionContext;
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
@@ -822,21 +820,6 @@ private Artifact resolveArchetype(Archetype a, IProgressMonitor monitor) throws
try {
- if(StringUtils.isBlank(artifactRemoteRepository)) {
-
- IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
- if(!mavenConfiguration.isOffline()) {
- //Try to find the repository from remote catalog if needed
- final ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
- RemoteCatalogFactory factory = archetypeManager.findParentCatalogFactory(a, RemoteCatalogFactory.class);
- if(factory != null) {
- //Grab the computed remote repository url
- artifactRemoteRepository = factory.getRepositoryUrl();
- a.setRepository(artifactRemoteRepository);//Hopefully will prevent further lookups for the same archetype
- }
- }
- }
-
if(StringUtils.isNotBlank(artifactRemoteRepository)) {
ArtifactRepository archetypeRepository = maven.createArtifactRepository(
a.getArtifactId() + "-repo", a.getRepository().trim()); //$NON-NLS-1$
Please sign in to comment.
Something went wrong with that request. Please try again.