Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java2
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties1
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LocalArchetypeCatalogDialog.java10
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/ExtensionReader.java7
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java48
5 files changed, 57 insertions, 11 deletions
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
index c21c20b2..53dccf56 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java
@@ -159,6 +159,8 @@ public class Messages extends NLS {
public static String LocalArchetypeCatalogDialog_dialog_title;
+ public static String LocalArchetypeCatalogDialog_error;
+
public static String LocalArchetypeCatalogDialog_error_empty;
public static String LocalArchetypeCatalogDialog_error_exist;
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
index 5eceb792..917af0b0 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties
@@ -98,6 +98,7 @@ LifecycleMappingPropertyPage_invalidPom=Can not read pom.xml
LifecycleMappingsViewer_trclmnSource_text=Source
LocalArchetypeCatalogDialog_btnBrowse=&Browse...
LocalArchetypeCatalogDialog_dialog_title=Select Archetype catalog
+LocalArchetypeCatalogDialog_error=Archetype catalog can not be loaded: {0}
LocalArchetypeCatalogDialog_error_empty=Archetype catalog is empty
LocalArchetypeCatalogDialog_error_exist=Archetype catalog does not exist
LocalArchetypeCatalogDialog_error_no_location=Archetype catalog location is required
diff --git a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LocalArchetypeCatalogDialog.java b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LocalArchetypeCatalogDialog.java
index 66195071..13fc2d74 100644
--- a/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LocalArchetypeCatalogDialog.java
+++ b/org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/LocalArchetypeCatalogDialog.java
@@ -16,11 +16,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -217,7 +219,13 @@ public class LocalArchetypeCatalogDialog extends TitleAreaDialog {
}
LocalCatalogFactory factory = new LocalCatalogFactory(location, null, true);
- ArchetypeCatalog archetypeCatalog = factory.getArchetypeCatalog();
+ ArchetypeCatalog archetypeCatalog;
+ try {
+ archetypeCatalog = factory.getArchetypeCatalog();
+ } catch(CoreException ex) {
+ setMessage(NLS.bind(Messages.LocalArchetypeCatalogDialog_error, ex.getMessage()), IStatus.ERROR);
+ return false;
+ }
@SuppressWarnings("unchecked")
List<Archetype> archetypes = archetypeCatalog.getArchetypes();
if(archetypes == null || archetypes.size() == 0) {
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
index ae29f6bb..a58a93ce 100644
--- 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
@@ -80,7 +80,8 @@ public class ExtensionReader {
return archetypeCatalogs;
}
- private static ArchetypeCatalogFactory readArchetypeCatalogs(IConfigurationElement element, IContributor contributor) {
+ private static ArchetypeCatalogFactory readArchetypeCatalogs(IConfigurationElement element,
+ IContributor contributor) {
if(ELEMENT_LOCAL_ARCHETYPE.equals(element.getName())) {
String name = element.getAttribute(ATTR_NAME);
if(name != null) {
@@ -92,9 +93,7 @@ public class ExtensionReader {
if(catalogUrl != null) {
String description = element.getAttribute(ATTR_DESCRIPTION);
String url = catalogUrl.toString();
- // XXX ARCHETYPE-161: RemoteCatalogArchetypeDataSource don't allow to download arbitrary urls
- return new ArchetypeCatalogFactory.RemoteCatalogFactory(url.substring(0, url.lastIndexOf("/")), //$NON-NLS-1$
- description, false);
+ return new ArchetypeCatalogFactory.LocalCatalogFactory(url, description, false);
}
}
log.error("Unable to find Archetype catalog " + name + " in " + contributor.getName());
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
index 2c8728e8..8877bd56 100644
--- 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
@@ -11,6 +11,9 @@
package org.eclipse.m2e.core.internal.archetype;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -25,6 +28,7 @@ import org.eclipse.osgi.util.NLS;
import org.apache.maven.archetype.ArchetypeManager;
import org.apache.maven.archetype.catalog.ArchetypeCatalog;
+import org.apache.maven.archetype.catalog.io.xpp3.ArchetypeCatalogXpp3Reader;
import org.apache.maven.archetype.source.ArchetypeDataSource;
import org.apache.maven.archetype.source.ArchetypeDataSourceException;
@@ -132,12 +136,44 @@ public abstract class ArchetypeCatalogFactory {
public static class LocalCatalogFactory extends ArchetypeCatalogFactory {
public LocalCatalogFactory(String path, String description, boolean editable) {
- super(path, description == null || description.trim().length() == 0 ? NLS.bind(
- Messages.ArchetypeCatalogFactory_local, path) : description, editable);
+ super(path, description == null || description.trim().length() == 0
+ ? NLS.bind(Messages.ArchetypeCatalogFactory_local, path) : description, editable);
}
- public ArchetypeCatalog getArchetypeCatalog() {
- return getArchetyper().getLocalCatalog(getId());
+ public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
+ ArchetypeCatalog catalog = getEmbeddedCatalog();
+ if(catalog == null) {
+ //local but not embedded catalog
+ catalog = getArchetyper().getLocalCatalog(getId());
+ }
+ return catalog;
+ }
+
+ private ArchetypeCatalog getEmbeddedCatalog() throws CoreException {
+ URL url = getEmbeddedUrl();
+ if(url == null) {
+ //Not an embedded catalog, nothing else to do
+ return null;
+ }
+ try (InputStream is = new BufferedInputStream(url.openStream())) {
+ return new ArchetypeCatalogXpp3Reader().read(is);
+ } catch(Exception ex) {
+ String msg = NLS.bind(Messages.ArchetypeCatalogFactory_error_missing_catalog, ex.getMessage());
+ log.error(msg, ex);
+ throw new CoreException(new Status(IStatus.ERROR, IMavenConstants.PLUGIN_ID, -1, msg, ex));
+ }
+ }
+
+ private URL getEmbeddedUrl() {
+ String path = getId();
+ if(path != null && path.startsWith("bundleentry://")) {
+ try {
+ return new URL(path);
+ } catch(Exception ex) {
+ log.error(ex.getMessage(), ex);
+ }
+ }
+ return null;
}
}
@@ -149,8 +185,8 @@ public abstract class ArchetypeCatalogFactory {
private String repositoryUrl = null;
public RemoteCatalogFactory(String url, String description, boolean editable) {
- super(url, description == null || description.trim().length() == 0 ? NLS.bind(
- Messages.ArchetypeCatalogFactory_remote, url) : description, editable);
+ super(url, description == null || description.trim().length() == 0
+ ? NLS.bind(Messages.ArchetypeCatalogFactory_remote, url) : description, editable);
repositoryUrl = parseCatalogUrl(url);
}

Back to the top