Blame 0005-Port-to-latest-version-of-maven-archetypes.patch

998de9f
From 69b028840c120ea2516eeed37e6e5f9f251704cb Mon Sep 17 00:00:00 2001
293108a
From: Mat Booth <mat.booth@redhat.com>
98ab5b2
Date: Wed, 25 Mar 2020 11:26:45 +0000
82aede6
Subject: [PATCH 5/6] Port to latest version of maven-archetypes
293108a
293108a
---
293108a
 .../org.eclipse.m2e.archetype.common/pom.xml  |   9 +-
98ab5b2
 .../MavenArchetypesPreferencePage.java        |  93 +--------
998de9f
 .../MavenProjectWizardArchetypePage.java      |  14 +-
293108a
 .../m2e/core/internal/ExtensionReader.java    |  27 +--
293108a
 .../eclipse/m2e/core/internal/Messages.java   |   2 -
98ab5b2
 .../archetype/ArchetypeCatalogFactory.java    | 192 +++---------------
98ab5b2
 .../archetype/ArchetypeCatalogsWriter.java    |  49 +----
98ab5b2
 .../internal/archetype/ArchetypeManager.java  |   4 +-
98ab5b2
 .../index/nexus/NexusIndexManager.java        |   2 +-
998de9f
 9 files changed, 51 insertions(+), 341 deletions(-)
293108a
293108a
diff --git a/m2e-maven-runtime/org.eclipse.m2e.archetype.common/pom.xml b/m2e-maven-runtime/org.eclipse.m2e.archetype.common/pom.xml
f789efe
index 96ec268..6bb1bd0 100644
293108a
--- a/m2e-maven-runtime/org.eclipse.m2e.archetype.common/pom.xml
293108a
+++ b/m2e-maven-runtime/org.eclipse.m2e.archetype.common/pom.xml
293108a
@@ -24,7 +24,7 @@
293108a
   <name>Maven Archetype Common Bundle</name>
293108a
 
293108a
   <properties>
293108a
-    <archetype-common.version>2.4</archetype-common.version>
4ed71fc
+    <archetype-common.version>3.2.0</archetype-common.version>
293108a
   </properties>
293108a
 
293108a
   <dependencies>
293108a
@@ -34,11 +34,6 @@
293108a
       <version>${archetype-common.version}</version>
293108a
       <optional>true</optional>
293108a
       <exclusions>
293108a
-        <exclusion>
293108a
-          
293108a
-          <artifactId>velocity</artifactId>
293108a
-          <groupId>velocity</groupId>
293108a
-        </exclusion>
293108a
         <exclusion>
293108a
           <artifactId>plexus-container-default</artifactId>
293108a
           <groupId>org.codehaus.plexus</groupId>
0593cb3
@@ -76,12 +71,10 @@
293108a
               archetype-common,
293108a
               archetype-catalog,
293108a
               archetype-descriptor,
293108a
-              archetype-registry,
293108a
               maven-invoker,
293108a
               commons-collections,
293108a
               commons-io,
293108a
               commons-lang,
f6a869e
-              dom4j;version=2.1.3,
293108a
               jchardet,
293108a
               jdom,
293108a
               oro,
293108a
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java
0593cb3
index 0c95b17..486e3c9 100644
293108a
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java
293108a
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java
0593cb3
@@ -55,8 +55,6 @@ import org.eclipse.ui.browser.IWebBrowser;
293108a
 
293108a
 import org.eclipse.m2e.core.internal.MavenPluginActivator;
293108a
 import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory;
293108a
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.LocalCatalogFactory;
293108a
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
293108a
 import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
0593cb3
 import org.eclipse.m2e.core.internal.preferences.MavenPreferenceConstants;
0593cb3
 import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
0593cb3
@@ -174,84 +172,6 @@ public class MavenArchetypesPreferencePage extends FieldEditorPreferencePage imp
293108a
     typeColumn.setWidth(250);
293108a
     typeColumn.setText(""); //$NON-NLS-1$
293108a
 
293108a
-    Button enableAllBtn = new Button(composite, SWT.NONE);
293108a
-    enableAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
293108a
-    enableAllBtn.setText(Messages.MavenArchetypesPreferencePage_btnEnableAll);
0593cb3
-    enableAllBtn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> toggleRepositories(true)));
293108a
-
293108a
-    Button disableAllBtn = new Button(composite, SWT.NONE);
293108a
-    disableAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
293108a
-    disableAllBtn.setText(Messages.MavenArchetypesPreferencePage_btnDisableAll);
0593cb3
-    disableAllBtn.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> toggleRepositories(false)));
293108a
-
293108a
-    Button addLocalButton = new Button(composite, SWT.NONE);
293108a
-    addLocalButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
293108a
-    addLocalButton.setText(Messages.MavenArchetypesPreferencePage_btnAddLocal);
0593cb3
-    addLocalButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
0593cb3
-      LocalArchetypeCatalogDialog dialog = new LocalArchetypeCatalogDialog(getShell(), null);
0593cb3
-      if(dialog.open() == Window.OK) {
0593cb3
-        addCatalogFactory(dialog.getArchetypeCatalogFactory());
293108a
-      }
0593cb3
-    }));
293108a
-
293108a
-    Button addRemoteButton = new Button(composite, SWT.NONE);
293108a
-    addRemoteButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
293108a
-    addRemoteButton.setText(Messages.MavenArchetypesPreferencePage_btnAddRemote);
0593cb3
-    addRemoteButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
0593cb3
-      RemoteArchetypeCatalogDialog dialog = new RemoteArchetypeCatalogDialog(getShell(), null);
0593cb3
-      if(dialog.open() == Window.OK) {
0593cb3
-        addCatalogFactory(dialog.getArchetypeCatalogFactory());
293108a
-      }
0593cb3
-    }));
293108a
-
293108a
-    final Button editButton = new Button(composite, SWT.NONE);
293108a
-    editButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
293108a
-    editButton.setEnabled(false);
293108a
-    editButton.setText(Messages.MavenArchetypesPreferencePage_btnEdit);
0593cb3
-    editButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
0593cb3
-      ArchetypeCatalogFactory factory = getSelectedArchetypeCatalogFactory();
0593cb3
-      ArchetypeCatalogFactory newFactory = null;
0593cb3
-      if(factory instanceof LocalCatalogFactory) {
0593cb3
-        LocalArchetypeCatalogDialog dialog = new LocalArchetypeCatalogDialog(getShell(), factory);
0593cb3
-        if(dialog.open() == Window.OK) {
0593cb3
-          newFactory = dialog.getArchetypeCatalogFactory();
293108a
-        }
0593cb3
-      } else if(factory instanceof RemoteCatalogFactory) {
0593cb3
-        RemoteArchetypeCatalogDialog dialog = new RemoteArchetypeCatalogDialog(getShell(), factory);
0593cb3
-        if(dialog.open() == Window.OK) {
0593cb3
-          newFactory = dialog.getArchetypeCatalogFactory();
293108a
-        }
293108a
-      }
0593cb3
-      if(newFactory != null) {
0593cb3
-        int n = archetypeCatalogs.indexOf(factory);
0593cb3
-        if(n > -1) {
0593cb3
-          archetypeCatalogs.set(n, newFactory);
0593cb3
-          archetypesViewer.setInput(archetypeCatalogs);
0593cb3
-          archetypesViewer.setSelection(new StructuredSelection(newFactory), true);
0593cb3
-        }
0593cb3
-      }
0593cb3
-    }));
293108a
-
293108a
-    final Button removeButton = new Button(composite, SWT.NONE);
293108a
-    removeButton.setEnabled(false);
293108a
-    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, true));
293108a
-    removeButton.setText(Messages.MavenArchetypesPreferencePage_btnRemove);
0593cb3
-    removeButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
0593cb3
-      ArchetypeCatalogFactory factory = getSelectedArchetypeCatalogFactory();
0593cb3
-      archetypeCatalogs.remove(factory);
0593cb3
-      archetypesViewer.setInput(archetypeCatalogs);
0593cb3
-      archetypesViewer.setSelection(null, true);
0593cb3
-    }));
293108a
-
293108a
-    archetypesViewer.addSelectionChangedListener(event -> {
293108a
-      if(archetypesViewer.getSelection() instanceof IStructuredSelection) {
293108a
-        ArchetypeCatalogFactory factory = getSelectedArchetypeCatalogFactory();
293108a
-        boolean isEnabled = factory != null && factory.isEditable();
293108a
-        removeButton.setEnabled(isEnabled);
293108a
-        editButton.setEnabled(isEnabled);
293108a
-      }
293108a
-    });
293108a
-
293108a
     archetypesViewer.addCheckStateListener((event) -> {
293108a
       archetypesViewer.refresh(event.getElement(), true);
293108a
     });
0593cb3
@@ -294,18 +214,7 @@ public class MavenArchetypesPreferencePage extends FieldEditorPreferencePage imp
293108a
     public String getColumnText(Object element, int columnIndex) {
293108a
       ArchetypeCatalogFactory factory = (ArchetypeCatalogFactory) element;
293108a
       String description = factory.getDescription();
293108a
-      String text;
293108a
-      if(factory instanceof LocalCatalogFactory) {
293108a
-        text = NLS.bind(Messages.MavenArchetypesPreferencePage_local, description);
293108a
-      } else if(factory instanceof RemoteCatalogFactory) {
293108a
-        if(factory.isEditable()) {
293108a
-          text = NLS.bind(Messages.MavenArchetypesPreferencePage_remote, description);
293108a
-        } else {
293108a
-          text = NLS.bind(Messages.MavenArchetypesPreferencePage_packaged, description);
293108a
-        }
293108a
-      } else {
293108a
-        text = description;
293108a
-      }
293108a
+      String text = description;
293108a
 
293108a
       return factory.isEditable() ? text : NLS.bind(Messages.MavenArchetypesPreferencePage_SystemLabel, text);
293108a
     }
293108a
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java
998de9f
index 90547dd..acd296f 100644
293108a
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java
293108a
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java
998de9f
@@ -82,11 +82,13 @@ import org.apache.maven.artifact.Artifact;
293108a
 import org.apache.maven.artifact.repository.ArtifactRepository;
293108a
 import org.apache.maven.artifact.versioning.ArtifactVersion;
293108a
 import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
998de9f
+import org.apache.maven.project.ProjectBuildingRequest;
293108a
 
293108a
 import org.eclipse.m2e.core.MavenPlugin;
293108a
 import org.eclipse.m2e.core.archetype.ArchetypeUtil;
998de9f
 import org.eclipse.m2e.core.embedder.ArtifactKey;
998de9f
 import org.eclipse.m2e.core.embedder.IMaven;
998de9f
+import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
998de9f
 import org.eclipse.m2e.core.internal.MavenPluginActivator;
998de9f
 import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory;
998de9f
 import org.eclipse.m2e.core.internal.archetype.ArchetypeManager;
998de9f
@@ -846,9 +848,15 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
998de9f
             archetype.setArtifactId(archetypeArtifactId);
998de9f
             archetype.setVersion(archetypeVersion);
293108a
             archetype.setRepository(repositoryUrl);
998de9f
-            org.apache.maven.archetype.ArchetypeManager archetyper = MavenPluginActivator.getDefault()
998de9f
-                .getArchetypeManager().getArchetyper();
293108a
-            archetyper.updateLocalCatalog(archetype);
293108a
+
998de9f
+            IMavenExecutionContext ctx = maven.createExecutionContext();
998de9f
+            Void v = ctx.execute((context, pm) -> {
998de9f
+              org.apache.maven.archetype.ArchetypeManager archetyper = MavenPluginActivator.getDefault()
998de9f
+                  .getArchetypeManager().getArchetyper();
998de9f
+              ProjectBuildingRequest projectBuildingRequest = context.newProjectBuildingRequest();
998de9f
+              archetyper.updateLocalCatalog(projectBuildingRequest, archetype);
998de9f
+              return null;
998de9f
+            }, new NullProgressMonitor());
293108a
 
293108a
             archetypesCache.clear();
293108a
 
293108a
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
293108a
index a7a4fd4..0afbc71 100644
293108a
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
293108a
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java
293108a
@@ -13,11 +13,9 @@
293108a
 
293108a
 package org.eclipse.m2e.core.internal;
293108a
 
293108a
-import java.net.URL;
293108a
 import java.util.ArrayList;
293108a
 import java.util.List;
293108a
 
293108a
-import org.osgi.framework.Bundle;
293108a
 import org.slf4j.Logger;
293108a
 import org.slf4j.LoggerFactory;
293108a
 
293108a
@@ -84,29 +82,8 @@ public class ExtensionReader {
293108a
 
293108a
   private static ArchetypeCatalogFactory readArchetypeCatalogs(IConfigurationElement element,
293108a
       IContributor contributor) {
293108a
-    if(ELEMENT_LOCAL_ARCHETYPE.equals(element.getName())) {
293108a
-      String name = element.getAttribute(ATTR_NAME);
293108a
-      if(name != null) {
293108a
-        Bundle[] bundles = Platform.getBundles(contributor.getName(), null);
293108a
-        URL catalogUrl = null;
293108a
-        for(int i = 0; i < bundles.length; i++ ) {
293108a
-          Bundle bundle = bundles[i];
293108a
-          catalogUrl = bundle.getEntry(name);
293108a
-          if(catalogUrl != null) {
293108a
-            String description = element.getAttribute(ATTR_DESCRIPTION);
293108a
-            String url = catalogUrl.toString();
293108a
-            return new ArchetypeCatalogFactory.LocalCatalogFactory(url, description, false);
293108a
-          }
293108a
-        }
293108a
-        log.error("Unable to find Archetype catalog " + name + " in " + contributor.getName());
293108a
-      }
293108a
-    } else if(ELEMENT_REMOTE_ARCHETYPE.equals(element.getName())) {
293108a
-      String url = element.getAttribute(ATTR_URL);
293108a
-      if(url != null) {
293108a
-        String description = element.getAttribute(ATTR_DESCRIPTION);
293108a
-        return new ArchetypeCatalogFactory.RemoteCatalogFactory(url, description, false);
293108a
-      }
293108a
-    }
293108a
+    log.error("Local and remote Archetype catalogs specified by URL from " + contributor.getName()
293108a
+        + " are no longer supported");
293108a
     return null;
293108a
   }
293108a
 
293108a
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Messages.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Messages.java
293108a
index 0f486cd..069e210 100644
293108a
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Messages.java
293108a
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/Messages.java
293108a
@@ -50,8 +50,6 @@ public class Messages extends NLS {
293108a
 
293108a
   public static String ArchetypeCatalogFactory_internal;
293108a
 
293108a
-  public static String ArchetypeCatalogFactory_local;
293108a
-
293108a
   public static String ArchetypeCatalogFactory_remote;
293108a
 
293108a
   public static String ArchetypeCatalogsWriter_error_parse;
293108a
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java
98ab5b2
index 8c82854..6772ad0 100644
293108a
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java
293108a
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java
98ab5b2
@@ -13,28 +13,24 @@
98ab5b2
 
98ab5b2
 package org.eclipse.m2e.core.internal.archetype;
98ab5b2
 
98ab5b2
-import java.io.BufferedInputStream;
98ab5b2
-import java.io.InputStream;
98ab5b2
-import java.net.URL;
98ab5b2
-import java.util.ArrayList;
98ab5b2
-import java.util.List;
98ab5b2
-import java.util.Properties;
98ab5b2
-
98ab5b2
 import org.slf4j.Logger;
98ab5b2
 import org.slf4j.LoggerFactory;
98ab5b2
 
98ab5b2
 import org.eclipse.core.runtime.CoreException;
98ab5b2
 import org.eclipse.core.runtime.IStatus;
98ab5b2
+import org.eclipse.core.runtime.NullProgressMonitor;
98ab5b2
 import org.eclipse.core.runtime.Status;
98ab5b2
 import org.eclipse.osgi.util.NLS;
98ab5b2
 
293108a
 import org.apache.maven.archetype.ArchetypeManager;
98ab5b2
-import org.apache.maven.archetype.catalog.Archetype;
293108a
 import org.apache.maven.archetype.catalog.ArchetypeCatalog;
293108a
-import org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reader;
293108a
 import org.apache.maven.archetype.source.ArchetypeDataSource;
293108a
 import org.apache.maven.archetype.source.ArchetypeDataSourceException;
293108a
+import org.apache.maven.project.ProjectBuildingRequest;
293108a
 
293108a
+import org.eclipse.m2e.core.MavenPlugin;
293108a
+import org.eclipse.m2e.core.embedder.IMaven;
293108a
+import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
293108a
 import org.eclipse.m2e.core.internal.IMavenConstants;
293108a
 import org.eclipse.m2e.core.internal.MavenPluginActivator;
293108a
 import org.eclipse.m2e.core.internal.Messages;
98ab5b2
@@ -106,14 +102,20 @@ public abstract class ArchetypeCatalogFactory {
98ab5b2
     }
293108a
 
293108a
     public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
98ab5b2
-      try {
98ab5b2
-        ArchetypeDataSource source = MavenPluginActivator.getDefault().getIndexManager().getArchetypeCatalog();
293108a
-        return source.getArchetypeCatalog(new Properties());
98ab5b2
-      } catch(ArchetypeDataSourceException ex) {
98ab5b2
-        String msg = NLS.bind(Messages.ArchetypeCatalogFactory_error_missing_catalog, ex.getMessage());
98ab5b2
-        log.error(msg, ex);
98ab5b2
-        throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, msg, ex));
98ab5b2
-      }
98ab5b2
+      final IMaven maven = MavenPlugin.getMaven();
98ab5b2
+      IMavenExecutionContext ctx = maven.createExecutionContext();
98ab5b2
+      ArchetypeCatalog cat = ctx.execute((context, pm) -> {
98ab5b2
+        try {
98ab5b2
+          ArchetypeDataSource source = MavenPluginActivator.getDefault().getIndexManager().getArchetypeCatalog();
98ab5b2
+          ProjectBuildingRequest projectBuildingRequest = context.newProjectBuildingRequest();
98ab5b2
+          return source.getArchetypeCatalog(projectBuildingRequest);
98ab5b2
+        } catch(ArchetypeDataSourceException ex) {
98ab5b2
+          String msg = NLS.bind(Messages.ArchetypeCatalogFactory_error_missing_catalog, ex.getMessage());
98ab5b2
+          log.error(msg, ex);
98ab5b2
+          throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, msg, ex));
98ab5b2
+        }
98ab5b2
+      }, new NullProgressMonitor());
98ab5b2
+      return cat;
98ab5b2
     }
98ab5b2
 
98ab5b2
   }
98ab5b2
@@ -143,156 +145,14 @@ public abstract class ArchetypeCatalogFactory {
293108a
       super(ID, Messages.ArchetypeCatalogFactory_default_local, false);
293108a
     }
293108a
 
293108a
-    public ArchetypeCatalog getArchetypeCatalog() {
293108a
-      return getArchetyper().getDefaultLocalCatalog();
293108a
-    }
293108a
-  }
293108a
-
293108a
-  /**
293108a
-   * Factory for local ArchetypeCatalog
293108a
-   */
293108a
-  public static class LocalCatalogFactory extends ArchetypeCatalogFactory {
293108a
-
293108a
-    public LocalCatalogFactory(String path, String description, boolean editable) {
293108a
-      this(path, description, editable, true);
293108a
-    }
293108a
-
293108a
-    public LocalCatalogFactory(String path, String description, boolean editable, boolean enabled) {
293108a
-      super(path, description == null || description.trim().length() == 0
293108a
-          ? NLS.bind(Messages.ArchetypeCatalogFactory_local, path)
293108a
-          : description, editable, enabled);
293108a
-    }
293108a
-
293108a
     public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
293108a
-      ArchetypeCatalog catalog = getEmbeddedCatalog();
293108a
-      if(catalog == null) {
293108a
-        //local but not embedded catalog
293108a
-        catalog = getArchetyper().getLocalCatalog(getId());
293108a
-      }
293108a
-      return catalog;
293108a
-    }
293108a
-
293108a
-    private ArchetypeCatalog getEmbeddedCatalog() throws CoreException {
293108a
-      URL url = getEmbeddedUrl();
293108a
-      if(url == null) {
293108a
-        //Not an embedded catalog, nothing else to do
293108a
-        return null;
293108a
-      }
293108a
-      try (InputStream is = new BufferedInputStream(url.openStream())) {
293108a
-        return new ArchetypeCatalogXpp3Reader().read(is);
293108a
-      } catch(Exception ex) {
293108a
-        String msg = NLS.bind(Messages.ArchetypeCatalogFactory_error_missing_catalog, ex.getMessage());
293108a
-        log.error(msg, ex);
293108a
-        throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, msg, ex));
293108a
-      }
293108a
-    }
293108a
-
293108a
-    private URL getEmbeddedUrl() {
293108a
-      String path = getId();
293108a
-      if(path != null && path.startsWith("bundleentry://")) {
293108a
-        try {
293108a
-          return new URL(path);
293108a
-        } catch(Exception ex) {
293108a
-          log.error(ex.getMessage(), ex);
293108a
-        }
293108a
-      }
293108a
-      return null;
293108a
-    }
293108a
-  }
293108a
-
293108a
-  /**
293108a
-   * Factory for remote ArchetypeCatalog
293108a
-   */
293108a
-  public static class RemoteCatalogFactory extends ArchetypeCatalogFactory {
293108a
-
293108a
-    private String repositoryUrl = null;
293108a
-
293108a
-    public RemoteCatalogFactory(String url, String description, boolean editable) {
293108a
-      this(url, description, editable, true);
293108a
-    }
293108a
-
293108a
-    public RemoteCatalogFactory(String url, String description, boolean editable, boolean enabled) {
293108a
-      super(url, description == null || description.trim().length() == 0
293108a
-          ? NLS.bind(Messages.ArchetypeCatalogFactory_remote, url)
293108a
-          : description, editable, enabled);
293108a
-      repositoryUrl = parseCatalogUrl(url);
293108a
-    }
293108a
-
293108a
-    /**
293108a
-     * @param url
293108a
-     * @return
293108a
-     */
293108a
-    private String parseCatalogUrl(String url) {
293108a
-      if(url == null) {
293108a
-        return null;
293108a
-      }
293108a
-      int length = url.length();
293108a
-      if(length > 1 && url.endsWith("/")) //$NON-NLS-1$
293108a
-      {
293108a
-        return url.substring(0, url.length() - 1);
293108a
-      }
293108a
-      int idx = url.lastIndexOf("/"); //$NON-NLS-1$
293108a
-      idx = (idx > 0) ? idx : 0;
293108a
-      if(url.lastIndexOf(".") >= idx) { //$NON-NLS-1$
293108a
-        //Assume last fragment of the url is a file, let's keep its parent folder
293108a
-        return url.substring(0, idx);
293108a
-      }
293108a
-      return url;
293108a
-    }
293108a
-
293108a
-    public ArchetypeCatalog getArchetypeCatalog() {
293108a
-      String url = getId();
293108a
-      int idx = url.lastIndexOf("/archetype-catalog.xml");
293108a
-      if(idx > -1) {
293108a
-        url = url.substring(0, idx);
293108a
-      }
293108a
-      final ArchetypeCatalog catalog = getArchetyper().getRemoteCatalog(url);
293108a
-      final String remoteUrl = url;
293108a
-      @SuppressWarnings("serial")
293108a
-      ArchetypeCatalog catalogWrapper = new ArchetypeCatalog() {
293108a
-        public void addArchetype(Archetype archetype) {
293108a
-          catalog.addArchetype(archetype);
293108a
-        }
293108a
-
293108a
-        public List<Archetype> getArchetypes() {
293108a
-          List<Archetype> archetypes = new ArrayList<>(catalog.getArchetypes());
293108a
-          for(Archetype arch : archetypes) {
293108a
-            if(arch.getRepository() == null || arch.getRepository().trim().isEmpty()) {
293108a
-              arch.setRepository(remoteUrl);
293108a
-            }
293108a
-          }
293108a
-          return archetypes;
293108a
-        }
293108a
-
293108a
-        public String getModelEncoding() {
293108a
-          return catalog.getModelEncoding();
293108a
-        }
293108a
-
293108a
-        public void removeArchetype(Archetype archetype) {
293108a
-          catalog.removeArchetype(archetype);
293108a
-        }
293108a
-
293108a
-        public void setModelEncoding(String modelEncoding) {
293108a
-          catalog.setModelEncoding(modelEncoding);
293108a
-        }
293108a
-
293108a
-        public void setArchetypes(List<Archetype> archetypes) {
293108a
-          catalog.setArchetypes(archetypes);
293108a
-        }
293108a
-
293108a
-        public String toString() {
293108a
-          return catalog.toString();
293108a
-        }
293108a
-      };
293108a
-
293108a
-      return catalogWrapper;
293108a
-    }
293108a
-
293108a
-    /**
293108a
-     * @return the url of the remote repository hosting the catalog
293108a
-     */
293108a
-    public String getRepositoryUrl() {
293108a
-      return repositoryUrl;
293108a
+      final IMaven maven = MavenPlugin.getMaven();
98ab5b2
+      IMavenExecutionContext ctx = maven.createExecutionContext();
98ab5b2
+      ArchetypeCatalog cat = ctx.execute((context, pm) -> {
98ab5b2
+        ProjectBuildingRequest projectBuildingRequest = context.newProjectBuildingRequest();
98ab5b2
+        return getArchetyper().getLocalCatalog(projectBuildingRequest);
98ab5b2
+      }, new NullProgressMonitor());
98ab5b2
+      return cat;
293108a
     }
293108a
   }
293108a
 
293108a
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogsWriter.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogsWriter.java
293108a
index 2adb946..31ef580 100644
293108a
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogsWriter.java
293108a
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogsWriter.java
293108a
@@ -45,8 +45,6 @@ import org.xml.sax.helpers.XMLFilterImpl;
293108a
 import org.eclipse.osgi.util.NLS;
293108a
 
293108a
 import org.eclipse.m2e.core.internal.Messages;
293108a
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.LocalCatalogFactory;
293108a
-import org.eclipse.m2e.core.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
293108a
 
293108a
 
293108a
 /**
293108a
@@ -63,14 +61,8 @@ public class ArchetypeCatalogsWriter {
293108a
 
293108a
   private static final String ATT_CATALOG_TYPE = "type"; //$NON-NLS-1$
293108a
 
293108a
-  private static final String ATT_CATALOG_LOCATION = "location"; //$NON-NLS-1$
293108a
-
293108a
   public static final String ATT_CATALOG_DESCRIPTION = "description"; //$NON-NLS-1$
293108a
 
293108a
-  private static final String TYPE_LOCAL = "local"; //$NON-NLS-1$
293108a
-
293108a
-  private static final String TYPE_REMOTE = "remote"; //$NON-NLS-1$
293108a
-
293108a
   private static final String TYPE_SYSTEM = "system"; //$NON-NLS-1$
293108a
 
293108a
   public static final String ATT_CATALOG_ID = "id";
293108a
@@ -127,20 +119,8 @@ public class ArchetypeCatalogsWriter {
293108a
 
293108a
       for(ArchetypeCatalogFactory factory : this.catalogs) {
293108a
         AttributesImpl attrs = new AttributesImpl();
293108a
-        if(factory.isEditable()) {
293108a
-          if(factory instanceof LocalCatalogFactory) {
293108a
-            attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_LOCAL);
293108a
-            attrs.addAttribute(null, ATT_CATALOG_LOCATION, ATT_CATALOG_LOCATION, null, factory.getId());
293108a
-            attrs.addAttribute(null, ATT_CATALOG_DESCRIPTION, ATT_CATALOG_DESCRIPTION, null, factory.getDescription());
293108a
-          } else if(factory instanceof RemoteCatalogFactory) {
293108a
-            attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_REMOTE);
293108a
-            attrs.addAttribute(null, ATT_CATALOG_LOCATION, ATT_CATALOG_LOCATION, null, factory.getId());
293108a
-            attrs.addAttribute(null, ATT_CATALOG_DESCRIPTION, ATT_CATALOG_DESCRIPTION, null, factory.getDescription());
293108a
-          }
293108a
-        } else {
293108a
-          attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_SYSTEM);
293108a
-          attrs.addAttribute(null, ATT_CATALOG_ID, ATT_CATALOG_ID, null, factory.getId());
293108a
-        }
293108a
+        attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_SYSTEM);
293108a
+        attrs.addAttribute(null, ATT_CATALOG_ID, ATT_CATALOG_ID, null, factory.getId());
293108a
         attrs.addAttribute(null, ATT_CATALOG_ENABLED, ATT_CATALOG_ENABLED, null, Boolean.toString(factory.isEnabled()));
293108a
         handler.startElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG, attrs);
293108a
         handler.endElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG);
293108a
@@ -165,28 +145,13 @@ public class ArchetypeCatalogsWriter {
293108a
 
293108a
     public void startElement(String uri, String localName, String qName, Attributes attributes) {
293108a
       if(ELEMENT_CATALOG.equals(qName) && attributes != null) {
293108a
-        String type = attributes.getValue(ATT_CATALOG_TYPE);
293108a
         String enabledStr = attributes.getValue(ATT_CATALOG_ENABLED);
293108a
         boolean enabled = enabledStr==null||Boolean.parseBoolean(enabledStr);
293108a
-        if(TYPE_LOCAL.equals(type)) {
293108a
-          String path = attributes.getValue(ATT_CATALOG_LOCATION);
293108a
-          if(path != null) {
293108a
-            String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
293108a
-            catalogs.add(new LocalCatalogFactory(path, description, true, enabled));
293108a
-          }
293108a
-        } else if(TYPE_REMOTE.equals(type)) {
293108a
-          String url = attributes.getValue(ATT_CATALOG_LOCATION);
293108a
-          if(url != null) {
293108a
-            String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
293108a
-            catalogs.add(new RemoteCatalogFactory(url, description, true, enabled));
293108a
-          }
293108a
-        } else {
293108a
-          String id = attributes.getValue(ATT_CATALOG_ID);
293108a
-          if(id != null && !id.isEmpty()) {
293108a
-            ArchetypeCatalogFactory catalog = existingCatalogs.get(id);
293108a
-            if(catalog != null) {
293108a
-              catalog.setEnabled(enabled);
293108a
-            }
293108a
+        String id = attributes.getValue(ATT_CATALOG_ID);
293108a
+        if(id != null && !id.isEmpty()) {
293108a
+          ArchetypeCatalogFactory catalog = existingCatalogs.get(id);
293108a
+          if(catalog != null) {
293108a
+            catalog.setEnabled(enabled);
293108a
           }
293108a
         }
293108a
       }
293108a
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java
98ab5b2
index d14614f..25ce804 100644
293108a
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java
293108a
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java
98ab5b2
@@ -180,11 +180,11 @@ public class ArchetypeManager {
0593cb3
     try {
0593cb3
       return maven.execute((context, monitor1) -> {
0593cb3
         ArtifactRepository localRepository = context.getLocalRepository();
0593cb3
-        if(aaMgr.isFileSetArchetype(groupId, artifactId, version, null, localRepository, repositories)) {
98ab5b2
+        if(aaMgr.isFileSetArchetype(groupId, artifactId, version, null, localRepository, repositories, context.newProjectBuildingRequest())) {
0593cb3
           ArchetypeDescriptor descriptor;
0593cb3
           try {
0593cb3
             descriptor = aaMgr.getFileSetArchetypeDescriptor(groupId, artifactId, version, null, localRepository,
0593cb3
-                repositories);
0593cb3
+                repositories, context.newProjectBuildingRequest());
0593cb3
           } catch(UnknownArchetype ex) {
0593cb3
             throw new WrappedUnknownArchetype(ex);
0593cb3
           }
98ab5b2
diff --git a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
98ab5b2
index e7e0688..61e3762 100644
98ab5b2
--- a/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
98ab5b2
+++ b/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/index/nexus/NexusIndexManager.java
98ab5b2
@@ -1313,7 +1313,7 @@ public class NexusIndexManager implements IndexManager, IMavenProjectChangedList
98ab5b2
    */
98ab5b2
   public ArchetypeDataSource getArchetypeCatalog() {
98ab5b2
     try {
98ab5b2
-      return container.lookup(ArchetypeDataSource.class, "nexus");
98ab5b2
+      return container.lookup(ArchetypeDataSource.class, "remote-catalog");
98ab5b2
     } catch(ComponentLookupException ex) {
98ab5b2
       throw new NoSuchComponentException(ex);
98ab5b2
     }
293108a
-- 
f789efe
2.28.0
293108a