Skip to content

Commit 6952c5a

Browse files
committed
Don't use static access in ArchetypeCatalogsWriter
Fix #971
1 parent cc03fad commit 6952c5a

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypeCatalogsWriter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.eclipse.osgi.util.NLS;
4646

4747
import org.eclipse.m2e.core.internal.Messages;
48-
import org.eclipse.m2e.core.ui.internal.M2EUIPluginActivator;
4948
import org.eclipse.m2e.core.ui.internal.archetype.ArchetypeCatalogFactory.LocalCatalogFactory;
5049
import org.eclipse.m2e.core.ui.internal.archetype.ArchetypeCatalogFactory.RemoteCatalogFactory;
5150

@@ -78,13 +77,13 @@ public class ArchetypeCatalogsWriter {
7877

7978
public static final String ATT_CATALOG_ENABLED = "enabled";
8079

81-
public Collection<ArchetypeCatalogFactory> readArchetypeCatalogs(InputStream is,
82-
Map<String, ArchetypeCatalogFactory> existingCatalogs) throws IOException {
80+
Collection<ArchetypeCatalogFactory> readArchetypeCatalogs(InputStream is,
81+
Map<String, ArchetypeCatalogFactory> existingCatalogs, ArchetypePlugin plugin) throws IOException {
8382
Collection<ArchetypeCatalogFactory> catalogs = new ArrayList<>();
8483
try {
8584
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
8685
SAXParser parser = parserFactory.newSAXParser();
87-
parser.parse(is, new ArchetypeCatalogsContentHandler(catalogs, existingCatalogs));
86+
parser.parse(is, new ArchetypeCatalogsContentHandler(catalogs, existingCatalogs, plugin));
8887
} catch(SAXException ex) {
8988
String msg = Messages.ArchetypeCatalogsWriter_error_parse;
9089
log.error(msg, ex);
@@ -159,9 +158,12 @@ static class ArchetypeCatalogsContentHandler extends DefaultHandler {
159158

160159
private final Map<String, ArchetypeCatalogFactory> existingCatalogs;
161160

161+
private ArchetypePlugin plugin;
162+
162163
public ArchetypeCatalogsContentHandler(Collection<ArchetypeCatalogFactory> catalogs,
163-
Map<String, ArchetypeCatalogFactory> existingCatalogs) {
164+
Map<String, ArchetypeCatalogFactory> existingCatalogs, ArchetypePlugin plugin) {
164165
this.catalogs = catalogs;
166+
this.plugin = plugin;
165167
this.existingCatalogs = existingCatalogs == null ? Collections.emptyMap() : existingCatalogs;
166168
}
167169

@@ -175,14 +177,14 @@ public void startElement(String uri, String localName, String qName, Attributes
175177
String path = attributes.getValue(ATT_CATALOG_LOCATION);
176178
if(path != null) {
177179
String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
178-
catalogs.add(M2EUIPluginActivator.getDefault().getArchetypePlugin().newLocalCatalogFactory(path,
180+
catalogs.add(plugin.newLocalCatalogFactory(path,
179181
description, true, enabled));
180182
}
181183
} else if(TYPE_REMOTE.equals(type)) {
182184
String url = attributes.getValue(ATT_CATALOG_LOCATION);
183185
if(url != null) {
184186
String description = attributes.getValue(ATT_CATALOG_DESCRIPTION);
185-
catalogs.add(M2EUIPluginActivator.getDefault().getArchetypePlugin().newRemoteCatalogFactory(url,
187+
catalogs.add(plugin.newRemoteCatalogFactory(url,
186188
description, true, enabled));
187189
}
188190
} else {

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/archetype/ArchetypePlugin.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.LinkedHashMap;
2525
import java.util.List;
2626
import java.util.Map;
27-
import java.util.Map.Entry;
2827
import java.util.stream.Collectors;
2928

3029
import org.osgi.service.component.annotations.Activate;
@@ -104,7 +103,7 @@ public ArchetypePlugin() {
104103
}
105104

106105
@Activate
107-
void activate() throws IOException, PlexusContainerException, ComponentLookupException {
106+
void activate() throws PlexusContainerException, ComponentLookupException {
108107
final Module logginModule = new AbstractModule() {
109108
@Override
110109
protected void configure() {
@@ -119,18 +118,18 @@ protected void configure() {
119118
container = new DefaultPlexusContainer(cc, logginModule);
120119
archetypeArtifactManager = container.lookup(ArchetypeArtifactManager.class);
121120
archetypeDataSourceMap = container.lookupMap(ArchetypeDataSource.class);
122-
for(Entry<String, ArchetypeDataSource> entry : archetypeDataSourceMap.entrySet()) {
123-
System.out.println(entry.getKey() + " :: " + entry.getValue());
124-
}
125-
System.out.println(archetypeArtifactManager);
126121
addArchetypeCatalogFactory(
127122
new ArchetypeCatalogFactory.InternalCatalogFactory(archetypeDataSourceMap.get("internal-catalog")));
128123
addArchetypeCatalogFactory(
129124
new ArchetypeCatalogFactory.DefaultLocalCatalogFactory(maven, archetypeDataSourceMap.get("catalog")));
130125
for(ArchetypeCatalogFactory archetypeCatalogFactory : ExtensionReader.readArchetypeExtensions(this)) {
131126
addArchetypeCatalogFactory(archetypeCatalogFactory);
132127
}
133-
readCatalogs();
128+
try {
129+
readCatalogs();
130+
} catch(IOException e) {
131+
M2EUIPluginActivator.getDefault().getLog().error("Can't read catalogs!", e);
132+
}
134133
}
135134

136135
@Deactivate
@@ -185,7 +184,7 @@ public ArchetypeCatalogFactory getArchetypeCatalogFactory(String catalogId) {
185184
public void readCatalogs() throws IOException {
186185
if(configFile.exists()) {
187186
try (InputStream is = new FileInputStream(configFile)) {
188-
Collection<ArchetypeCatalogFactory> userDefinedCatalogs = writer.readArchetypeCatalogs(is, catalogs);
187+
Collection<ArchetypeCatalogFactory> userDefinedCatalogs = writer.readArchetypeCatalogs(is, catalogs, this);
189188
for(ArchetypeCatalogFactory it : userDefinedCatalogs) {
190189
addArchetypeCatalogFactory(it);
191190
}
@@ -229,8 +228,7 @@ public List<RequiredProperty> getRequiredProperties(IArchetype archetype, IProgr
229228
ArchetypeDescriptor descriptor;
230229
try {
231230
descriptor = archetypeArtifactManager.getFileSetArchetypeDescriptor(groupId, artifactId, version, null,
232-
localRepository,
233-
repositories, context.newProjectBuildingRequest());
231+
localRepository, repositories, context.newProjectBuildingRequest());
234232
} catch(UnknownArchetype ex) {
235233
throw new CoreException(Status.error("UnknownArchetype", ex));
236234
}

0 commit comments

Comments
 (0)