From dc26614c084584282e95d89e0f48c610814825b5 Mon Sep 17 00:00:00 2001
From: Hannes Wellmann
Date: Fri, 15 Mar 2024 20:10:32 +0100
Subject: [PATCH] [APITools] Various minor and local code clean-ups and
simplifications
---
.../META-INF/MANIFEST.MF | 2 +-
.../ApiBaselinePreferencePage.java | 16 +-
.../ApiBaselinesConfigurationBlock.java | 70 ++++-----
.../ApiErrorsWarningsConfigurationBlock.java | 28 ++--
.../ApiErrorsWarningsPreferencePage.java | 5 +-
.../ApiUseScanConfigurationBlock.java | 4 +-
.../preferences/ApiUseScanPreferencePage.java | 47 +++---
.../preferences/ProjectSelectionDialog.java | 24 +--
.../api/tools/internal/APIFileGenerator.java | 14 +-
.../api/tools/internal/AntFilterStore.java | 9 +-
.../api/tools/internal/ApiFilterStore.java | 70 +++------
.../pde/api/tools/internal/FilterStore.java | 44 +++---
.../tools/internal/model/BundleComponent.java | 138 +++++-------------
.../search/ConsumerReportConvertor.java | 25 +---
.../internal/search/MissingRefMetadata.java | 17 +--
.../search/MissingRefReportConverter.java | 27 ++--
.../internal/search/UseReportConverter.java | 116 ++++++---------
.../tools/internal/search/UseScanManager.java | 7 +-
.../pde/api/tools/internal/util/Util.java | 14 +-
19 files changed, 246 insertions(+), 431 deletions(-)
diff --git a/apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF b/apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF
index 18d7b18b27..077d05fa4d 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF
+++ b/apitools/org.eclipse.pde.api.tools.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.api.tools.ui; singleton:=true
-Bundle-Version: 1.3.300.qualifier
+Bundle-Version: 1.3.400.qualifier
Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinePreferencePage.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinePreferencePage.java
index e9c0066e0f..266a6319d5 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinePreferencePage.java
+++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinePreferencePage.java
@@ -17,7 +17,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@@ -84,9 +86,9 @@ protected boolean isDefaultBaseline(Object element) {
IApiBaselineManager manager = ApiPlugin.getDefault().getApiBaselineManager();
- private static HashSet removed = new HashSet<>(8);
+ private static Set removed = new HashSet<>(8);
CheckboxTableViewer tableviewer = null;
- ArrayList backingcollection = new ArrayList<>(8);
+ List backingcollection = new ArrayList<>(8);
String newdefault = null;
private Button newbutton = null;
@@ -271,8 +273,7 @@ protected void doEdit(final IApiBaseline baseline) {
* @return if the profile is the default or not
*/
protected boolean isDefault(Object element) {
- if (element instanceof IApiBaseline) {
- IApiBaseline profile = (IApiBaseline) element;
+ if (element instanceof IApiBaseline profile) {
if (newdefault == null) {
IApiBaseline def = ApiPlugin.getDefault().getApiBaselineManager().getDefaultApiBaseline();
if (def != null) {
@@ -378,7 +379,6 @@ private void findAndDeleteCompatibilityMarkers() {
}
}
- return;
}
/**
@@ -429,11 +429,9 @@ protected void performDefaults() {
}
@Override
public void applyData(Object data) {
- if (data instanceof Map) {
- Map, ?> pageData = (Map, ?>) data;
+ if (data instanceof Map, ?> pageData) {
Object key = pageData.get(ApiErrorsWarningsPreferencePage.DATA_SELECT_OPTION_KEY);
- if (key instanceof String) {
- String option = (String) key;
+ if (key instanceof String option) {
if (option.equals(ApiBaselinePreferencePage.MISSING_BASELINE_OPTION)) {
block.selectOption(0);
}
diff --git a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinesConfigurationBlock.java b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinesConfigurationBlock.java
index 97881f198d..029604f356 100644
--- a/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinesConfigurationBlock.java
+++ b/apitools/org.eclipse.pde.api.tools.ui/src/org/eclipse/pde/api/tools/ui/internal/preferences/ApiBaselinesConfigurationBlock.java
@@ -14,6 +14,7 @@
package org.eclipse.pde.api.tools.ui.internal.preferences;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.resources.IMarker;
@@ -187,7 +188,7 @@ public String toString() {
*
* @return the new {@link Key} for the {@link ApiUIPlugin} preference store
*/
- protected final static Key getApiToolsKey(String key) {
+ protected static final Key getApiToolsKey(String key) {
return new Key(ApiPlugin.PLUGIN_ID, key);
}
@@ -222,8 +223,7 @@ protected final static Key getApiToolsKey(String key) {
private final SelectionListener selectionlistener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
- if (e.widget instanceof Combo) {
- Combo combo = (Combo) e.widget;
+ if (e.widget instanceof Combo combo) {
ControlData data = (ControlData) combo.getData();
data.key.setStoredValue(fLookupOrder[0], combo.getText(), fManager);
fDirty = true;
@@ -236,11 +236,11 @@ public void widgetSelected(SelectionEvent e) {
* Listing of all of the {@link Combo}s added to the block
*/
- private final ArrayList fCombos = new ArrayList<>();
+ private final List fCombos = new ArrayList<>();
/**
* Listing of the label in the block
*/
- private final ArrayList
\n" })); //$NON-NLS-1$//$NON-NLS-2$
- String additional = getAdditionalIndexInfo(scanResult.size() > 0);
+ String additional = getAdditionalIndexInfo(!scanResult.isEmpty());
if (additional != null) {
buffer.append(additional);
}
- if (scanResult.size() > 0) {
+ if (!scanResult.isEmpty()) {
buffer.append(OPEN_P).append(SearchMessages.UseReportConverter_inlined_description).append(CLOSE_P);
buffer.append(getColourLegend());
buffer.append(getReferencesTableHeader(SearchMessages.ConsumerReportConvertor_ProducerListHeader, SearchMessages.UseReportConverter_bundle, true));
- if (scanResult.size() > 0) {
+ if (!scanResult.isEmpty()) {
File refereehtml = null;
String link = null;
for (Object obj : scanResult) {
@@ -630,20 +625,16 @@ protected void writeProducerReport(Consumer parentConsumer, Producer producer) t
producerTypes.addAll(producer.types.keySet());
Collections.sort(producerTypes, compare);
- CountGroup counts = null;
- String link = null;
- File typefile = null;
- Type2 type = null;
for (IReferenceTypeDescriptor iReferenceTypeDescriptor : producerTypes) {
- type = producer.types.get(iReferenceTypeDescriptor);
- counts = type.counts;
+ Type2 type = producer.types.get(iReferenceTypeDescriptor);
+ CountGroup counts = type.counts;
String fqname = Signatures.getQualifiedTypeSignature((IReferenceTypeDescriptor) type.desc);
- typefile = new File(htmlroot, fqname + HTML_EXTENSION);
+ File typefile = new File(htmlroot, fqname + HTML_EXTENSION);
if (!typefile.exists()) {
typefile.createNewFile();
}
- link = extractLinkFrom(htmlroot, typefile.getAbsolutePath());
+ String link = extractLinkFrom(htmlroot, typefile.getAbsolutePath());
buffer.append(getReferenceTableEntry(counts, link, fqname, false));
writeTypePage(type.referencingMembers, type, typefile, fqname);
}
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefMetadata.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefMetadata.java
index 9d857604a2..6bb36e8783 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefMetadata.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefMetadata.java
@@ -88,17 +88,15 @@ public MissingRefMetadata(String profile, String reportlocation, String apiusesc
*/
public static MissingRefMetadata getMetadata(File xmlFile) throws Exception {
MissingRefMetadata metadata = new MissingRefMetadata();
- try {
- if (xmlFile.exists()) {
+ if (xmlFile.exists()) {
+ try {
String xmlstr = Util.getFileContentAsString(xmlFile);
Element doc = Util.parseDocument(xmlstr.trim());
- Element element = null;
- String value = null, name = null;
NodeList nodes = doc.getElementsByTagName("*"); //$NON-NLS-1$
for (int i = 0; i < nodes.getLength(); i++) {
- element = (Element) nodes.item(i);
- value = element.getAttribute(MissingRefMetadata.VALUE);
- name = element.getNodeName();
+ Element element = (Element) nodes.item(i);
+ String value = element.getAttribute(MissingRefMetadata.VALUE);
+ String name = element.getNodeName();
if (PROFILE.equals(name)) {
metadata.setProfile(value);
@@ -117,9 +115,10 @@ public static MissingRefMetadata getMetadata(File xmlFile) throws Exception {
continue;
}
}
+ } catch (CoreException e) {
+ throw new Exception(
+ NLS.bind(SearchMessages.MissingRefMetadata_CoreExceptionInParsing, xmlFile.getAbsolutePath()));
}
- } catch (CoreException e) {
- throw new Exception(NLS.bind(SearchMessages.MissingRefMetadata_CoreExceptionInParsing, xmlFile.getAbsolutePath()));
}
return metadata;
}
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefReportConverter.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefReportConverter.java
index 66308a67b1..ee3f5bed8d 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefReportConverter.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/MissingRefReportConverter.java
@@ -101,18 +101,15 @@ private void writeIndexFileForComponent(Report report) throws Exception {
StringBuilder typeProblems = new StringBuilder();
StringBuilder methodProblems = new StringBuilder();
StringBuilder fieldProblems = new StringBuilder();
- Integer key = null;
- TreeMap> types = null;
- for (Entry>> entry : report.apiProblems.entrySet()) {
- key = entry.getKey();
- types = entry.getValue();
- switch (key.intValue()) {
+ report.apiProblems.forEach((key, types) -> {
+ switch (key.intValue())
+ {
case IApiProblem.API_USE_SCAN_TYPE_PROBLEM -> typeProblems.append(getProblemTable(types));
case IApiProblem.API_USE_SCAN_METHOD_PROBLEM -> methodProblems.append(getProblemTable(types));
case IApiProblem.API_USE_SCAN_FIELD_PROBLEM -> fieldProblems.append(getProblemTable(types));
default -> { /**/ }
}
- }
+ });
buffer.append(getProblemsTableHeader(SearchMessages.MissingRefReportConverter_ProblemDetails, SearchMessages.MissingRefReportConverter_ProblemTypes));
if (typeProblems.length() > 0) {
buffer.append(getProblemRow(typeProblems, SearchMessages.MissingRefReportConverter_Type));
@@ -243,17 +240,15 @@ static class Report {
int fieldProblems = 0;
public void add(List apipbs) {
- List list = null;
- TreeMap> types = null;
for (IApiProblem pb : apipbs) {
- Integer key = Integer.valueOf(pb.getKind());
- types = this.apiProblems.get(key);
+ Integer key = pb.getKind();
+ TreeMap> types = this.apiProblems.get(key);
if (types == null) {
types = new TreeMap<>(missingcompare);
this.apiProblems.put(key, types);
}
String tname = pb.getTypeName();
- list = types.get(tname);
+ List list = types.get(tname);
if (list == null) {
list = new ArrayList<>();
types.put(tname, list);
@@ -312,7 +307,7 @@ public void convert(String xslt, IProgressMonitor monitor) throws Exception {
System.out.println("Parsing use scan..."); //$NON-NLS-1$
start = System.currentTimeMillis();
}
- List> result = parse();
+ List result = parse();
if (ApiPlugin.DEBUG_USE_REPORT_CONVERTER) {
System.out.println("done in: " + (System.currentTimeMillis() - start) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println("Sorting reports and writing index..."); //$NON-NLS-1$
@@ -362,9 +357,9 @@ protected void writeIndexPage(List> result) throws Exception {
buffer.append(OPEN_P);
buffer.append(NLS.bind(SearchMessages.MissingRefReportConverter_NotSearched, new String[] {
"", "\n" })); //$NON-NLS-1$//$NON-NLS-2$
- if (result.size() > 0) {
+ if (!result.isEmpty()) {
buffer.append(getProblemSummaryTable());
- if (result.size() > 0) {
+ if (!result.isEmpty()) {
for (Object obj : result) {
if (obj instanceof Report report) {
File refereehtml = new File(getReportsRoot(), report.name + File.separator + "index.html"); //$NON-NLS-1$
@@ -507,7 +502,7 @@ protected void writeMetadataHeaders(StringBuilder buffer) {
/**
* Parse the XML directories and report.xml and generate HTML for them
*/
- protected List> parse() throws Exception {
+ protected List parse() throws Exception {
MissingRefParser lparser = new MissingRefParser();
MissingRefVisitor visitor = new MissingRefVisitor();
lparser.parse(getXmlLocation(), visitor);
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseReportConverter.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseReportConverter.java
index eacefbbcd1..3932ab45d3 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseReportConverter.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseReportConverter.java
@@ -35,6 +35,7 @@
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import java.util.stream.IntStream;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -86,12 +87,12 @@ public class UseReportConverter extends HTMLConvertor {
*/
class Visitor extends UseScanVisitor {
- ArrayList reports = new ArrayList<>();
+ List reports = new ArrayList<>();
Report currentreport = null;
Type currenttype = null, currentreferee = null;
Member currentmember = null;
- HashMap keys = new HashMap<>();
- ArrayList referees = new ArrayList<>();
+ Map keys = new HashMap<>();
+ List referees = new ArrayList<>();
/**
* Returns if the reference should be reported or not
@@ -179,21 +180,10 @@ public boolean visitMember(IMemberDescriptor referencedMember) {
if (desc == null) {
return false;
}
- this.currenttype = this.keys.get(desc);
- if (this.currenttype == null) {
- this.currenttype = new Type(desc);
- this.keys.put(desc, this.currenttype);
- }
- TreeMap map = this.currentreport.children.get(this.currenttype);
- if (map == null) {
- map = new TreeMap<>(compare);
- this.currentreport.children.put(this.currenttype, map);
- }
- this.currentmember = map.get(referencedMember);
- if (this.currentmember == null) {
- this.currentmember = new Member(referencedMember);
- map.put(referencedMember, this.currentmember);
- }
+ this.currenttype = this.keys.computeIfAbsent(desc, Type::new);
+ Map map = this.currentreport.children.computeIfAbsent(this.currenttype,
+ t -> new TreeMap<>(compare));
+ this.currentmember = map.computeIfAbsent(referencedMember, Member::new);
return true;
}
@@ -597,7 +587,7 @@ public UseReportConverter(String htmlroot, String xmlroot, String[] topatterns,
this.xmlLocation = xmlroot;
this.htmlLocation = htmlroot;
if (topatterns != null) {
- ArrayList pats = new ArrayList<>(topatterns.length);
+ List pats = new ArrayList<>(topatterns.length);
for (String topattern : topatterns) {
try {
pats.add(Pattern.compile(topattern));
@@ -613,7 +603,7 @@ public UseReportConverter(String htmlroot, String xmlroot, String[] topatterns,
}
}
if (frompatterns != null) {
- ArrayList pats = new ArrayList<>(frompatterns.length);
+ List pats = new ArrayList<>(frompatterns.length);
for (String frompattern : frompatterns) {
try {
pats.add(Pattern.compile(frompattern));
@@ -885,14 +875,13 @@ protected String getMissingBundlesHeader() {
* HTML report location
*/
void writeMetaPage(File htmlroot) throws Exception {
- File meta = null;
File file = new File(getReportsRoot(), "meta.xml"); //$NON-NLS-1$
if (!file.exists()) {
// do nothing if no meta.xml file
return;
}
String filename = "meta"; //$NON-NLS-1$
- meta = new File(htmlroot, filename + HTML_EXTENSION);
+ File meta = new File(htmlroot, filename + HTML_EXTENSION);
if (!meta.exists()) {
meta.createNewFile();
}
@@ -1165,9 +1154,8 @@ void writeTypePage(Map map, Type type, File typefile,
buffer.append("").append(OPEN_B) //$NON-NLS-1$ //$NON-NLS-2$
.append(SearchMessages.UseReportConverter_member).append(" | \n"); //$NON-NLS-1$
buffer.append(CLOSE_TR);
- IElementDescriptor desc = null;
for (Entry entry : map.entrySet()) {
- desc = entry.getKey();
+ IElementDescriptor desc = entry.getKey();
buffer.append(OPEN_TR);
buffer.append("\n"); //$NON-NLS-1$
buffer.append(OPEN_B);
@@ -1362,23 +1350,21 @@ protected void writeIndexPage(List> scanResult) throws Exception {
}
buffer.append(OPEN_P);
buffer.append(NLS.bind(SearchMessages.UseReportConverter_bundles_that_were_not_searched, new String[] {
- useNotSearchedXml == false ? "" : "", //$NON-NLS-1$//$NON-NLS-2$
+ !useNotSearchedXml ? "" : "", //$NON-NLS-1$//$NON-NLS-2$
"\n" }));//$NON-NLS-1$
- String additional = getAdditionalIndexInfo(scanResult.size() > 0);
+ String additional = getAdditionalIndexInfo(!scanResult.isEmpty());
if (additional != null) {
buffer.append(additional);
}
- if (scanResult.size() > 0) {
+ if (!scanResult.isEmpty()) {
buffer.append(OPEN_P).append(SearchMessages.UseReportConverter_inlined_description).append(CLOSE_P);
buffer.append(getColourLegend());
buffer.append(getReferencesTableHeader(SearchMessages.UseReportConverter_references, SearchMessages.UseReportConverter_bundle, true));
- if (scanResult.size() > 0) {
- File refereehtml = null;
- String link = null;
+ if (!scanResult.isEmpty()) {
for (Object obj : scanResult) {
if (obj instanceof Report report) {
- refereehtml = new File(getReportsRoot(), report.name + File.separator + "index.html"); //$NON-NLS-1$
- link = extractLinkFrom(getReportsRoot(), refereehtml.getAbsolutePath());
+ File refereehtml = new File(getReportsRoot(), report.name + File.separator + "index.html"); //$NON-NLS-1$
+ String link = extractLinkFrom(getReportsRoot(), refereehtml.getAbsolutePath());
buffer.append(getReferenceTableEntry(report.counts, link, report.name, true));
}
}
@@ -1583,31 +1569,23 @@ void writeFilterCount(StringBuilder buffer) throws Exception {
}
}
+
/**
* Returns the use metadata from this scan
*/
IMetadata getMetadata() throws Exception {
if (this.metadata == null) {
- File xml = null;
- try {
- xml = new File(getReportsRoot(), "meta" + XML_EXTENSION); //$NON-NLS-1$
- if (!xml.exists()) {
- // try looking in the default 'xml' directory as a raw
- // report root
- // might have been specified
- xml = new File(getReportsRoot() + File.separator + "xml", "meta" + XML_EXTENSION); //$NON-NLS-1$//$NON-NLS-2$
- }
- if (xml.exists()) {
+ File xml = getXML("meta"); //$NON-NLS-1$
+ if (xml.exists()) {
+ try {
String xmlstr = Util.getFileContentAsString(xml);
Element doc = Util.parseDocument(xmlstr.trim());
this.metadata = new UseMetadata();
- Element element = null;
- String value = null, name = null;
NodeList nodes = doc.getElementsByTagName("*"); //$NON-NLS-1$
for (int i = 0; i < nodes.getLength(); i++) {
- element = (Element) nodes.item(i);
- value = element.getAttribute(UseMetadata.VALUE);
- name = element.getNodeName();
+ Element element = (Element) nodes.item(i);
+ String value = element.getAttribute(UseMetadata.VALUE);
+ String name = element.getNodeName();
if (UseMetadata.FLAGS.equals(name)) {
try {
this.metadata.setSearchflags(Integer.parseInt(value));
@@ -1657,9 +1635,10 @@ IMetadata getMetadata() throws Exception {
continue;
}
}
+ } catch (CoreException e) {
+ throw new Exception(NLS.bind(SearchMessages.UseReportConverter_core_exep_reading_metadata,
+ xml.getAbsolutePath()));
}
- } catch (CoreException e) {
- throw new Exception(NLS.bind(SearchMessages.UseReportConverter_core_exep_reading_metadata, xml.getAbsolutePath()));
}
}
return this.metadata;
@@ -1670,16 +1649,9 @@ IMetadata getMetadata() throws Exception {
*/
int getFilteredCount() throws Exception {
if (this.filteredCount == -1) {
- File xml = null;
- try {
- xml = new File(getReportsRoot(), "counts" + XML_EXTENSION); //$NON-NLS-1$
- if (!xml.exists()) {
- // try looking in the default 'xml' directory as a raw
- // report root
- // might have been specified
- xml = new File(getReportsRoot() + File.separator + "xml", "meta" + XML_EXTENSION); //$NON-NLS-1$//$NON-NLS-2$
- }
- if (xml.exists()) {
+ File xml = getXML("counts"); //$NON-NLS-1$
+ if (xml.exists()) {
+ try {
String xmlstr = Util.getFileContentAsString(xml);
Element doc = Util.parseDocument(xmlstr.trim());
@@ -1692,30 +1664,34 @@ int getFilteredCount() throws Exception {
filteredCount = Integer.parseInt(value);
}
}
+ } catch (CoreException e) {
+ throw new Exception(NLS.bind(SearchMessages.UseReportConverter_core_exep_reading_metadata,
+ xml.getAbsolutePath()));
}
- } catch (CoreException e) {
- throw new Exception(NLS.bind(SearchMessages.UseReportConverter_core_exep_reading_metadata, xml.getAbsolutePath()));
}
}
return filteredCount;
}
+ private File getXML(String type) {
+ File xml = new File(getReportsRoot(), type + XML_EXTENSION);
+ if (xml.exists()) {
+ return xml;
+ }
+ // try looking in the default 'xml' directory as a raw report root
+ // might have been specified
+ return new File(getReportsRoot() + File.separator + "xml", "meta" + XML_EXTENSION); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
/**
* Reads saved patterns from the meta.xml file
*
* @return the array of patterns or null
*/
private String[] readPatterns(Element element) {
- String[] pats = null;
NodeList patterns = element.getElementsByTagName(UseMetadata.PATTERN);
- int length = patterns.getLength();
- if (length > 0) {
- pats = new String[length];
- for (int j = 0; j < length; j++) {
- pats[j] = ((Element) patterns.item(j)).getAttribute(UseMetadata.VALUE);
- }
- }
- return pats;
+ return IntStream.range(0, patterns.getLength()).mapToObj(patterns::item).map(Element.class::cast)
+ .map(e -> e.getAttribute(UseMetadata.VALUE)).toArray(String[]::new);
}
/**
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseScanManager.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseScanManager.java
index 2e19134f7f..069ce26aa0 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseScanManager.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/search/UseScanManager.java
@@ -133,7 +133,7 @@ public IReferenceDescriptor[] getExternalDependenciesFor(IApiComponent apiCompon
references = apiComponent.getExternalDependencies();
}
SubMonitor localmonitor = SubMonitor.convert(monitor, SearchMessages.collecting_external_dependencies, 10);
- ArrayList unavailableMembers = new ArrayList<>();
+ List unavailableMembers = new ArrayList<>();
if (apiUseTypes != null && apiUseTypes.length > 0) {
for (String apiUseType : apiUseTypes) {
if (!references.hasReferencesTo(apiUseType)) {
@@ -333,8 +333,7 @@ public static boolean isValidArchive(File file) {
*/
public static boolean isValidScanLocation(String location) {
if (location != null && location.length() > 0) {
- IPath path = IPath.fromOSString(location);
- File file = path.toFile();
+ File file = new File(location);
return isValidDirectory(file) || isValidArchive(file);
}
return false;
@@ -351,7 +350,7 @@ public String[] getReportLocations() {
}
String[] locations = apiUseScanPaths.split(ESCAPE_REGEX + LOCATION_DELIM);
- ArrayList locationList = new ArrayList<>(locations.length);
+ List locationList = new ArrayList<>(locations.length);
for (String location : locations) {
String[] values = location.split(ESCAPE_REGEX + STATE_DELIM);
if (Boolean.parseBoolean(values[1])) {
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
index bac83abe8c..2378cf0f85 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/util/Util.java
@@ -40,6 +40,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.charset.UnsupportedCharsetException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -48,6 +49,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -1619,7 +1621,7 @@ public static boolean isArchive(String fileName) {
* false otherwise
*/
public static boolean isZipJarFile(String fileName) {
- String normalizedFileName = fileName.toLowerCase();
+ String normalizedFileName = fileName.toLowerCase(Locale.ENGLISH);
return normalizedFileName.endsWith(DOT_ZIP) || normalizedFileName.endsWith(DOT_JAR);
}
@@ -1631,7 +1633,7 @@ public static boolean isZipJarFile(String fileName) {
* otherwise
*/
public static boolean isTGZFile(String fileName) {
- String normalizedFileName = fileName.toLowerCase();
+ String normalizedFileName = fileName.toLowerCase(Locale.ENGLISH);
return normalizedFileName.endsWith(DOT_TAR_GZ) || normalizedFileName.endsWith(DOT_TGZ);
}
@@ -1651,7 +1653,7 @@ public static boolean isClass(int accessFlags) {
* @return true if the name is for a class file false otherwise
*/
public static boolean isClassFile(String fileName) {
- return fileName.toLowerCase().endsWith(DOT_CLASS_SUFFIX);
+ return fileName.toLowerCase(Locale.ENGLISH).endsWith(DOT_CLASS_SUFFIX);
}
public static boolean isDefault(int accessFlags) {
@@ -1691,7 +1693,7 @@ public static final boolean isDifferentVersion(String versionToBeChecked, String
* @return true if the name is for a java source file, false otherwise
*/
public static boolean isJavaFileName(String fileName) {
- return fileName.toLowerCase().endsWith(DOT_JAVA_SUFFIX);
+ return fileName.toLowerCase(Locale.ENGLISH).endsWith(DOT_JAVA_SUFFIX);
}
/**
@@ -1934,8 +1936,8 @@ public static File createTempFile(String prefix, String suffix) throws IOExcepti
*
* @return a new temp directory
*/
- public static File createTempDirectory(String prefix) throws IOException {
- return recordTempFile(Files.createTempDirectory(prefix).toFile());
+ public static Path createTempDirectory(String prefix) throws IOException {
+ return recordTempFile(Files.createTempDirectory(prefix).toFile()).toPath();
}
private static File recordTempFile(File file) throws IOException {
|