aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2018-05-27 19:10:31 -0400
committerFred Bricon2018-05-29 12:38:39 -0400
commit6dec0543fc69d773d4bad46a4623d48905bf7ed7 (patch)
tree09eb3b59c64e7267b261371456017a16d7707444
parent45ec0e8a197d226ca4ee52070b2e369f106603c6 (diff)
downloadm2e-core-6dec0543fc69d773d4bad46a4623d48905bf7ed7.tar.gz
m2e-core-6dec0543fc69d773d4bad46a4623d48905bf7ed7.tar.xz
m2e-core-6dec0543fc69d773d4bad46a4623d48905bf7ed7.zip
Bug 427437: add possibility to disable archetype catalogs
The ability to disable certain Archetype catalogs makes sense, specifically for the Nexus Index based catalog, which is prone to OOMEs. Change-Id: I548a1bda3df62fa8328e6198b8cec1ce22e7834e Signed-off-by: Fred Bricon <fbricon@gmail.com>
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/Messages.java8
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/messages.properties6
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenArchetypesPreferencePage.java65
-rw-r--r--org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/wizards/MavenProjectWizardArchetypePage.java26
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogFactory.java29
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeCatalogsWriter.java46
-rw-r--r--org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/archetype/ArchetypeManager.java28
7 files changed, 157 insertions, 51 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 f3985066..1ba1ddbc 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
@@ -191,10 +191,16 @@ public class Messages extends NLS {
public static String MavenArchetypesPreferencePage_btnAddRemote;
+ public static String MavenArchetypesPreferencePage_btnDisableAll;
+
public static String MavenArchetypesPreferencePage_btnEdit;
+ public static String MavenArchetypesPreferencePage_btnEnableAll;
+
public static String MavenArchetypesPreferencePage_btnRemove;
+ public static String MavenArchetypesPreferencePage_SystemLabel;
+
public static String MavenArchetypesPreferencePage_error;
public static String MavenArchetypesPreferencePage_link;
@@ -431,6 +437,8 @@ public class Messages extends NLS {
public static String MavenProjectWizardArchetypePage_error_emptyCatalog;
+ public static String MavenProjectWizardArchetypePage_error_noEnabledCatalogs;
+
public static String MavenProjectWizardArchetypePage_error_read;
public static String MavenProjectWizardArchetypePage_error_resolve;
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 62506030..9811f250 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
@@ -114,10 +114,13 @@ MarkerResolutionGenerator_desc=M2E updates the configuration of the project to a
MarkerResolutionGenerator_label=Update project configuration
MavenArchetypesPreferencePage_btnAddLocal=Add &Local Catalog...
MavenArchetypesPreferencePage_btnAddRemote=Add &Remote Catalog...
+MavenArchetypesPreferencePage_btnDisableAll=Disable all
MavenArchetypesPreferencePage_btnEdit=&Edit...
+MavenArchetypesPreferencePage_btnEnableAll=Enable all
MavenArchetypesPreferencePage_btnRemove=&Remove
+MavenArchetypesPreferencePage_SystemLabel={0} [System]
MavenArchetypesPreferencePage_error=Can't save archetype catalog configuration\n{0}
-MavenArchetypesPreferencePage_link=Add, remove or edit <a href\="\#">Maven Archetype catalogs</a>\:
+MavenArchetypesPreferencePage_link=Enable, add, remove or edit <a href\="\#">Maven Archetype catalogs</a>\:
MavenArchetypesPreferencePage_local=Local\: {0}
MavenArchetypesPreferencePage_packaged=Packaged\: {0}
MavenArchetypesPreferencePage_remote=Remote\: {0}
@@ -247,6 +250,7 @@ MavenProjectWizardArchetypePage_btnLast=&Show the last version of Archetype only
MavenProjectWizardArchetypePage_btnSnapshots=&Include snapshot archetypes
MavenProjectWizardArchetypePage_error_emptyNexusIndexer=No archetypes currently available. The archetype list will refresh when the indexes finish updating.
MavenProjectWizardArchetypePage_error_emptyCatalog=No archetypes available for this catalog.
+MavenProjectWizardArchetypePage_error_noEnabledCatalogs=There are no enabled archetype catalogs. Click the 'Configure...' button.
MavenProjectWizardArchetypePage_error_read=Unable to read catalog factory.
MavenProjectWizardArchetypePage_error_resolve=The archetype {0} could not be resolved.
MavenProjectWizardArchetypePage_error_resolve2=Can't resolve Archetype {0}
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
index 14413985..31ebd440 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008-2010 Sonatype, Inc.
+ * Copyright (c) 2008-2018 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -23,6 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.IColorProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -31,7 +32,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.util.NLS;
@@ -73,7 +73,7 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
ArchetypeManager archetypeManager;
- TableViewer archetypesViewer;
+ CheckboxTableViewer archetypesViewer;
List<ArchetypeCatalogFactory> archetypeCatalogs;
@@ -90,7 +90,7 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
it.remove();
}
}
-
+ archetypesViewer.setAllChecked(true);
archetypesViewer.setInput(archetypeCatalogs);
archetypesViewer.setSelection(null, true);
@@ -105,12 +105,14 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
}
}
for(ArchetypeCatalogFactory factory : archetypeCatalogs) {
+ factory.setEnabled(archetypesViewer.getChecked(factory));
if(factory.isEditable()) {
archetypeManager.addArchetypeCatalogFactory(factory);
}
}
try {
+
archetypeManager.saveCatalogs();
} catch(IOException ex) {
setErrorMessage(NLS.bind(Messages.MavenArchetypesPreferencePage_error, ex.getMessage()));
@@ -142,15 +144,14 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
IWebBrowser browser = PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser();
browser.openURL(url);
} catch(MalformedURLException ex) {
- log.error("Malformed URL", ex);
+ log.error("Malformed URL", ex); //$NON-NLS-1$
} catch(PartInitException ex) {
log.error(ex.getMessage(), ex);
}
}
});
- // archetypesViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
- archetypesViewer = new TableViewer(composite, SWT.BORDER | SWT.FULL_SELECTION);
+ archetypesViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER | SWT.FULL_SELECTION);
archetypesViewer.setLabelProvider(new CatalogsLabelProvider());
@@ -174,12 +175,30 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
Table table = archetypesViewer.getTable();
table.setLinesVisible(false);
table.setHeaderVisible(false);
- table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 4));
+ table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 6));
TableColumn typeColumn = new TableColumn(table, SWT.NONE);
typeColumn.setWidth(250);
typeColumn.setText(""); //$NON-NLS-1$
+ Button enableAllBtn = new Button(composite, SWT.NONE);
+ enableAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+ enableAllBtn.setText(Messages.MavenArchetypesPreferencePage_btnEnableAll);
+ enableAllBtn.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ toggleRepositories(true);
+ }
+ });
+
+ Button disableAllBtn = new Button(composite, SWT.NONE);
+ disableAllBtn.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
+ disableAllBtn.setText(Messages.MavenArchetypesPreferencePage_btnDisableAll);
+ disableAllBtn.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ toggleRepositories(false);
+ }
+ });
+
Button addLocalButton = new Button(composite, SWT.NONE);
addLocalButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
addLocalButton.setText(Messages.MavenArchetypesPreferencePage_btnAddLocal);
@@ -258,13 +277,23 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
}
});
+ archetypesViewer.addCheckStateListener((event) -> {
+ archetypesViewer.refresh(event.getElement(), true);
+ });
+
archetypeCatalogs = new ArrayList<ArchetypeCatalogFactory>(archetypeManager.getArchetypeCatalogs());
archetypesViewer.setInput(archetypeCatalogs);
+ archetypeCatalogs.forEach(a -> archetypesViewer.setChecked(a, a.isEnabled()));
archetypesViewer.refresh(); // should listen on property changes instead?
return composite;
}
+ protected void toggleRepositories(boolean toggle) {
+ archetypeCatalogs.forEach(a -> archetypesViewer.setChecked(a, toggle));
+ archetypesViewer.refresh();
+ }
+
protected ArchetypeCatalogFactory getSelectedArchetypeCatalogFactory() {
IStructuredSelection selection = (IStructuredSelection) archetypesViewer.getSelection();
return (ArchetypeCatalogFactory) selection.getFirstElement();
@@ -277,25 +306,32 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
archetypeCatalogs.add(factory);
if(!archetypesViewer.getControl().isDisposed()) {
archetypesViewer.setInput(archetypeCatalogs);
+ archetypesViewer.setChecked(factory, true);
archetypesViewer.setSelection(new StructuredSelection(factory), true);
}
}
- static class CatalogsLabelProvider implements ITableLabelProvider, IColorProvider {
+ class CatalogsLabelProvider implements ITableLabelProvider, IColorProvider {
private Color disabledColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
public String getColumnText(Object element, int columnIndex) {
ArchetypeCatalogFactory factory = (ArchetypeCatalogFactory) element;
+ String description = factory.getDescription();
+ String text;
if(factory instanceof LocalCatalogFactory) {
- return NLS.bind(Messages.MavenArchetypesPreferencePage_local, factory.getDescription());
+ text = NLS.bind(Messages.MavenArchetypesPreferencePage_local, description);
} else if(factory instanceof RemoteCatalogFactory) {
if(factory.isEditable()) {
- return NLS.bind(Messages.MavenArchetypesPreferencePage_remote, factory.getDescription());
+ text = NLS.bind(Messages.MavenArchetypesPreferencePage_remote, description);
+ } else {
+ text = NLS.bind(Messages.MavenArchetypesPreferencePage_packaged, description);
}
- return NLS.bind(Messages.MavenArchetypesPreferencePage_packaged, factory.getDescription());
+ } else {
+ text = description;
}
- return factory.getDescription();
+
+ return factory.isEditable() ? text : NLS.bind(Messages.MavenArchetypesPreferencePage_SystemLabel, text);
}
public Image getColumnImage(Object element, int columnIndex) {
@@ -307,8 +343,7 @@ public class MavenArchetypesPreferencePage extends PreferencePage implements IWo
}
public Color getForeground(Object element) {
- ArchetypeCatalogFactory factory = (ArchetypeCatalogFactory) element;
- return !factory.isEditable() ? disabledColor : null;
+ return archetypesViewer.getChecked(element) ? null : disabledColor;
}
public void dispose() {
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
index 3f237d20..aa5ecdf1 100644
--- 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
@@ -250,6 +250,7 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
catalogsComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
ISelection selection = event.getSelection();
+ boolean loadAll = false;
//hide previous archetypes when switching catalog
if(selection instanceof IStructuredSelection) {
Object factory = ((IStructuredSelection) selection).getFirstElement();
@@ -257,13 +258,18 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
if(factory instanceof ArchetypeCatalogFactory) {
newCatalogFactory = (ArchetypeCatalogFactory) factory;
}
- if(Objects.equals(catalogFactory, newCatalogFactory) && viewer.getInput() != null) {
+ if(factory != null && newCatalogFactory == null) {
+ loadAll = true;
+ } else if(Objects.equals(catalogFactory, newCatalogFactory) && viewer.getInput() != null) {
return;
}
catalogFactory = newCatalogFactory;
viewer.setInput(null);
reloadViewer();
} else {
+ loadAll = true;
+ }
+ if(loadAll) {
catalogFactory = null;
viewer.setInput(null);
loadArchetypes(null, null, null);
@@ -279,7 +285,7 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
});
final ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
- ArrayList allCatalogs = new ArrayList(archetypeManager.getArchetypeCatalogs());
+ ArrayList allCatalogs = new ArrayList(archetypeManager.getActiveArchetypeCatalogs());
allCatalogs.add(0, ALL_CATALOGS);
catalogsComboViewer.setInput(allCatalogs);
@@ -289,12 +295,12 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
configureButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
- Collection<ArchetypeCatalogFactory> oldCatalogs = archetypeManager.getArchetypeCatalogs();
+ Collection<ArchetypeCatalogFactory> oldCatalogs = archetypeManager.getActiveArchetypeCatalogs();
PreferencesUtil.createPreferenceDialogOn(getShell(),
"org.eclipse.m2e.core.preferences.MavenArchetypesPreferencePage", null, null).open(); //$NON-NLS-1$
- Collection<ArchetypeCatalogFactory> newCatalogs = archetypeManager.getArchetypeCatalogs();
+ Collection<ArchetypeCatalogFactory> newCatalogs = archetypeManager.getActiveArchetypeCatalogs();
//Deselect removed catalog if needed
if(catalogFactory != null && !newCatalogs.contains(catalogFactory)) {
@@ -315,6 +321,7 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
catalogsComboViewer.setInput(allCatalogs);
catalogsComboViewer
.setSelection(new StructuredSelection(selectedCatalog == null ? ALL_CATALOGS : selectedCatalog));
+
}
});
@@ -576,8 +583,9 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
@SuppressWarnings("unchecked")
private List<Archetype> getAllArchetypes(IProgressMonitor monitor) {
ArchetypeManager manager = MavenPluginActivator.getDefault().getArchetypeManager();
- Collection<ArchetypeCatalogFactory> archetypeCatalogs = manager.getArchetypeCatalogs();
- ArrayList<Archetype> list = new ArrayList<Archetype>();
+ Collection<ArchetypeCatalogFactory> archetypeCatalogs = manager.getActiveArchetypeCatalogs();
+
+ ArrayList<Archetype> list = new ArrayList<>();
if(monitor == null) {
monitor = new NullProgressMonitor();
@@ -624,7 +632,11 @@ public class MavenProjectWizardArchetypePage extends AbstractMavenWizardPage imp
if(IStatus.ERROR == event.getResult().getSeverity()) {
error = event.getResult().getMessage();
} else if((catalogArchetypes == null || catalogArchetypes.isEmpty())) {
- if(catalogFactory != null && "Nexus Indexer".equals(catalogFactory.getDescription())) { //$NON-NLS-1$
+ ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
+ Collection<ArchetypeCatalogFactory> catalogs = archetypeManager.getActiveArchetypeCatalogs();
+ if(catalogs.isEmpty()) {
+ error = Messages.MavenProjectWizardArchetypePage_error_noEnabledCatalogs;
+ } else if(catalogFactory != null && "Nexus Indexer".equals(catalogFactory.getDescription())) { //$NON-NLS-1$
error = Messages.MavenProjectWizardArchetypePage_error_emptyNexusIndexer;
} else {
error = Messages.MavenProjectWizardArchetypePage_error_emptyCatalog;
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 8877bd56..b1c7d788 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
@@ -49,10 +49,17 @@ public abstract class ArchetypeCatalogFactory {
private final boolean editable;
+ private boolean enabled;
+
public ArchetypeCatalogFactory(String id, String description, boolean editable) {
+ this(id, description, editable, true);
+ }
+
+ public ArchetypeCatalogFactory(String id, String description, boolean editable, boolean enabled) {
this.id = id;
this.description = description;
this.editable = editable;
+ this.enabled = enabled;
}
public String getId() {
@@ -67,6 +74,14 @@ public abstract class ArchetypeCatalogFactory {
return editable;
}
+ public boolean isEnabled() {
+ return enabled;
+ }
+
+ public void setEnabled(boolean enabled) {
+ this.enabled = enabled;
+ }
+
public abstract ArchetypeCatalog getArchetypeCatalog() throws CoreException;
public String toString() {
@@ -136,8 +151,13 @@ public abstract class ArchetypeCatalogFactory {
public static class LocalCatalogFactory extends ArchetypeCatalogFactory {
public LocalCatalogFactory(String path, String description, boolean editable) {
+ this(path, description, editable, true);
+ }
+
+ public LocalCatalogFactory(String path, String description, boolean editable, boolean enabled) {
super(path, description == null || description.trim().length() == 0
- ? NLS.bind(Messages.ArchetypeCatalogFactory_local, path) : description, editable);
+ ? NLS.bind(Messages.ArchetypeCatalogFactory_local, path)
+ : description, editable, enabled);
}
public ArchetypeCatalog getArchetypeCatalog() throws CoreException {
@@ -185,8 +205,13 @@ public abstract class ArchetypeCatalogFactory {
private String repositoryUrl = null;
public RemoteCatalogFactory(String url, String description, boolean editable) {
+ this(url, description, editable, true);
+ }
+
+ public RemoteCatalogFactory(String url, String description, boolean editable, boolean enabled) {
super(url, description == null || description.trim().length() == 0
- ? NLS.bind(Messages.ArchetypeCatalogFactory_remote, url) : description, editable);
+ ? NLS.bind(Messages.ArchetypeCatalogFactory_remote, url)
+ : description, editable, enabled);
repositoryUrl = parseCatalogUrl(url);
}
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
index 10b459f6..4d5a95c2 100644
--- 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
@@ -16,6 +16,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -67,12 +69,19 @@ public class ArchetypeCatalogsWriter {
private static final String TYPE_REMOTE = "remote"; //$NON-NLS-1$
- public Collection<ArchetypeCatalogFactory> readArchetypeCatalogs(InputStream is) throws IOException {
+ private static final String TYPE_SYSTEM = "system"; //$NON-NLS-1$
+
+ public static final String ATT_CATALOG_ID = "id";
+
+ public static final String ATT_CATALOG_ENABLED = "enabled";
+
+ public Collection<ArchetypeCatalogFactory> readArchetypeCatalogs(InputStream is,
+ Map<String, ArchetypeCatalogFactory> existingCatalogs) throws IOException {
Collection<ArchetypeCatalogFactory> catalogs = new ArrayList<ArchetypeCatalogFactory>();
try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
SAXParser parser = parserFactory.newSAXParser();
- parser.parse(is, new ArchetypeCatalogsContentHandler(catalogs));
+ parser.parse(is, new ArchetypeCatalogsContentHandler(catalogs, existingCatalogs));
} catch(SAXException ex) {
String msg = Messages.ArchetypeCatalogsWriter_error_parse;
log.error(msg, ex);
@@ -115,23 +124,24 @@ public class ArchetypeCatalogsWriter {
handler.startElement(null, ELEMENT_CATALOGS, ELEMENT_CATALOGS, new AttributesImpl());
for(ArchetypeCatalogFactory factory : this.catalogs) {
+ AttributesImpl attrs = new AttributesImpl();
if(factory.isEditable()) {
if(factory instanceof LocalCatalogFactory) {
- AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_LOCAL);
attrs.addAttribute(null, ATT_CATALOG_LOCATION, ATT_CATALOG_LOCATION, null, factory.getId());
attrs.addAttribute(null, ATT_CATALOG_DESCRIPTION, ATT_CATALOG_DESCRIPTION, null, factory.getDescription());
- handler.startElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG, attrs);
- handler.endElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG);
} else if(factory instanceof RemoteCatalogFactory) {
- AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_REMOTE);
attrs.addAttribute(null, ATT_CATALOG_LOCATION, ATT_CATALOG_LOCATION, null, factory.getId());
attrs.addAttribute(null, ATT_CATALOG_DESCRIPTION, ATT_CATALOG_DESCRIPTION, null, factory.getDescription());
- handler.startElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG, attrs);
- handler.endElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG);
}
+ } else {
+ attrs.addAttribute(null, ATT_CATALOG_TYPE, ATT_CATALOG_TYPE, null, TYPE_SYSTEM);
+ attrs.addAttribute(null, ATT_CATALOG_ID, ATT_CATALOG_ID, null, factory.getId());
}
+ attrs.addAttribute(null, ATT_CATALOG_ENABLED, ATT_CATALOG_ENABLED, null, Boolean.toString(factory.isEnabled()));
+ handler.startElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG, attrs);
+ handler.endElement(null, ELEMENT_CATALOG, ELEMENT_CATALOG);
}
handler.endElement(null, ELEMENT_CATALOGS, ELEMENT_CATALOGS);
@@ -143,24 +153,38 @@ public class ArchetypeCatalogsWriter {
private Collection<ArchetypeCatalogFactory> catalogs;
- public ArchetypeCatalogsContentHandler(Collection<ArchetypeCatalogFactory> catalogs) {
+ private Map<String, ArchetypeCatalogFactory> existingCatalogs;
+
+ public ArchetypeCatalogsContentHandler(Collection<ArchetypeCatalogFactory> catalogs,
+ Map<String, ArchetypeCatalogFactory> existingCatalogs) {
this.catalogs = catalogs;
+ this.existingCatalogs = existingCatalogs == null ? Collections.emptyMap() : existingCatalogs;
}
public void startElement(String uri, String localName, String qName, Attributes attributes) {
if(ELEMENT_CATALOG.equals(qName) && attributes != null) {
String type = attributes.getValue(ATT_CATALOG_TYPE);
+ String enabledStr = attributes.getValue(ATT_CATALOG_ENABLED);
+ boolean enabled = enabledStr==null||Boolean.parseBoolean(enabledStr);
if(TYPE_LOCAL.equals(type)) {
String path = attributes.getValue(ATT_CATALOG_LOCATION);
if(path != null) {
String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
- catalogs.add(new LocalCatalogFactory(path, description, true));
+ catalogs.add(new LocalCatalogFactory(path, description, true, enabled));
}
} else if(TYPE_REMOTE.equals(type)) {
String url = attributes.getValue(ATT_CATALOG_LOCATION);
if(url != null) {
String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
- catalogs.add(new RemoteCatalogFactory(url, description, true));
+ catalogs.add(new RemoteCatalogFactory(url, description, true, enabled));
+ }
+ } else {
+ String id = attributes.getValue(ATT_CATALOG_ID);
+ if(id != null && !id.isEmpty()) {
+ ArchetypeCatalogFactory catalog = existingCatalogs.get(id);
+ if(catalog != null) {
+ catalog.setEnabled(enabled);
+ }
}
}
}
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
index 82910fdb..b77e90e6 100644
--- 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
@@ -19,10 +19,10 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
@@ -31,7 +31,6 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
-import org.codehaus.plexus.util.IOUtil;
import org.apache.maven.archetype.catalog.Archetype;
import org.apache.maven.archetype.common.ArchetypeArtifactManager;
@@ -85,6 +84,13 @@ public class ArchetypeManager {
return new ArrayList<ArchetypeCatalogFactory>(catalogs.values());
}
+ /**
+ * @return all active ArchetypeCatalogFactory
+ */
+ public Collection<ArchetypeCatalogFactory> getActiveArchetypeCatalogs() {
+ return catalogs.values().stream().filter(ArchetypeCatalogFactory::isEnabled).collect(Collectors.toList());
+ }
+
public void addArchetypeCatalogFactory(ArchetypeCatalogFactory factory) {
if(factory != null) {
catalogs.put(factory.getId(), factory);
@@ -101,26 +107,18 @@ public class ArchetypeManager {
public void readCatalogs() throws IOException {
if(configFile.exists()) {
- InputStream is = null;
- try {
- is = new FileInputStream(configFile);
- Collection<ArchetypeCatalogFactory> catalogs = writer.readArchetypeCatalogs(is);
- for(Iterator<ArchetypeCatalogFactory> it = catalogs.iterator(); it.hasNext();) {
- addArchetypeCatalogFactory(it.next());
+ try (InputStream is = new FileInputStream(configFile)) {
+ Collection<ArchetypeCatalogFactory> userDefinedCatalogs = writer.readArchetypeCatalogs(is, catalogs);
+ for(ArchetypeCatalogFactory it : userDefinedCatalogs) {
+ addArchetypeCatalogFactory(it);
}
- } finally {
- IOUtil.close(is);
}
}
}
public void saveCatalogs() throws IOException {
- OutputStream os = null;
- try {
- os = new FileOutputStream(configFile);
+ try (OutputStream os = new FileOutputStream(configFile)) {
writer.writeArchetypeCatalogs(getArchetypeCatalogs(), os);
- } finally {
- IOUtil.close(os);
}
}