From 0541eefd3a6588cb426d620b4fdfc04fc96f8274 Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Wed, 29 Jun 2022 19:38:00 +0200 Subject: [PATCH] Added -analyzeTargetState [showWarnings] command line option Analyzes target platform state, optionally shows warnings. Eclipse root and bundle version have to be set before. --- .../outputs/console_help_expected | 1 + .../core/CommandLineInterpreter.java | 39 ++++++++++++++++--- .../plugindependencies/core/Logging.java | 4 +- .../plugindependencies/core/Options.java | 26 ++++++++++--- .../core/PlatformState.java | 16 ++++++++ 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/org.eclipselabs.plugindependencies.core.test/outputs/console_help_expected b/org.eclipselabs.plugindependencies.core.test/outputs/console_help_expected index 8587d3e..b63007d 100644 --- a/org.eclipselabs.plugindependencies.core.test/outputs/console_help_expected +++ b/org.eclipselabs.plugindependencies.core.test/outputs/console_help_expected @@ -6,6 +6,7 @@ java plugin_dependencies [-javaHome path] -eclipsePaths folder1 folder2.. [Optio -generateReqFile file Writes requirements of each plugin in the specified file. The file has the form pluginA:pluginB in each line. This just means pluginA depends on pluginB. The plugins are written in the file as canonical paths. -generateBuildFile sourceFolder [targetFolder] Generates the build file with all classpaths of the specified plugin. Optionally path to the extra plugins directory can be specified with targetFolder. Generated file is saved in the plugin folder. Eclipse root and bundle version have to be set before. -generateAllBuild sourceFolder [targetFolder] Generates a build file with all classpaths of every plugin in the specified folder. Optionally path to the extra plugins directory can be specified with targetFolder. Generated files are saved in each plugin folder. Eclipse root and bundle version have to be set before. +-analyzeTargetState [showWarnings] Analyzes target platform state, optionally shows warnings. Eclipse root and bundle version have to be set before. -fullLog [file] Writes the full error log to the specified file (optional, if no file given, to standard out). Warnings are included. -eclipsePaths folder1 [folder2 ...] Eclipse target platform plugin and feature folders are specified here (canonical paths). Either Eclipse folder with subfolders "plugins" and "features" or a folder just containing plugins is possible. -javaHome path Changes the Java home path to the specified path. Default is the Java home of the running Java. diff --git a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/CommandLineInterpreter.java b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/CommandLineInterpreter.java index 0d38227..f610fab 100644 --- a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/CommandLineInterpreter.java +++ b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/CommandLineInterpreter.java @@ -18,16 +18,14 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Set; -import javax.xml.parsers.ParserConfigurationException; - import org.eclipselabs.plugindependencies.core.PlatformState.PlatformSpecs; -import org.xml.sax.SAXException; /** * @author obroesam @@ -42,7 +40,8 @@ public class CommandLineInterpreter { public static final int RC_OK = 0; public static final int RC_RUNTIME_ERROR = -1; - public static final int RC_ANALYSIS_ERROR = -2; + public static final int RC_ANALYSIS_WARNING = -2; + public static final int RC_ANALYSIS_ERROR = -3; public CommandLineInterpreter() { super(); @@ -257,6 +256,35 @@ int generateAllBuildFiles(String sourceDir) { return result; } + int analyzeTargetState(boolean showWarnings) { + if(state.getPlugins().isEmpty()){ + Logging.getLogger().error("no plugins found"); + return RC_RUNTIME_ERROR; + } + Logging.writeStandardOut("Starting to analyze, platform size: " + state.getPlugins().size() + " plugins"); + List errors = state.computeAllDependenciesRecursive(); + if(!errors.isEmpty()) { + Logging.getLogger().error("Errors analyzing bundle dependencies"); + errors.forEach(e -> Logging.getLogger().error(e.toString())); + } + List warnings = Collections.emptyList(); + if(showWarnings && errors.isEmpty()) { + warnings = state.collectWarnings(); + if(!warnings.isEmpty()) { + Logging.getLogger().warning("Warnings analyzing bundle dependencies"); + warnings.forEach(e -> Logging.getLogger().warning(e.toString())); + } + } + if(!errors.isEmpty()) { + return RC_ANALYSIS_ERROR; + } + if(!warnings.isEmpty()) { + return RC_ANALYSIS_WARNING; + } + Logging.writeStandardOut("Successfully analyzed " + state.getPlugins().size() + " plugins"); + return RC_OK; + } + void printFocusedOSGIElement(String arg) { int separatorIndex = arg.indexOf(','); String version = ""; @@ -356,8 +384,7 @@ private static String printLog(NamedElement element, boolean showWarnings, Strin return ret.toString(); } - public int readInEclipseFolder(String eclipsePath) - throws IOException, SAXException, ParserConfigurationException { + public int readInEclipseFolder(String eclipsePath) throws IOException { int result = RC_OK; if(eclipsePath.startsWith("#")){ return result; diff --git a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Logging.java b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Logging.java index cd0dc8f..eb46d83 100644 --- a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Logging.java +++ b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Logging.java @@ -90,7 +90,9 @@ public void error(String message, Throwable ... t) { @Override public void warning(String message, Throwable ... t) { - err.print(PREFIX_WARN); + if(! message.startsWith(PREFIX_WARN)) { + out.print(PREFIX_WARN); + } out.println(message); if(t != null && t.length > 0){ t[0].printStackTrace(out); diff --git a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Options.java b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Options.java index 82e530c..f2ef46e 100644 --- a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Options.java +++ b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/Options.java @@ -21,10 +21,6 @@ import java.util.List; import java.util.Set; -import javax.xml.parsers.ParserConfigurationException; - -import org.xml.sax.SAXException; - enum Options { Providing("-providing", true) { @@ -144,6 +140,26 @@ void printHelp(String arg) { } }, + AnalyzeTargetState("-analyzeTargetState", true) { + @Override + int handle(CommandLineInterpreter cli, List args) { + boolean showWarnings = false; + if(args.size() > 0) { + showWarnings = "showWarnings".equals(args.get(0)); + } + return cli.analyzeTargetState(showWarnings); + } + + @Override + void printHelp(String arg) { + String help = "-analyzeTargetState [showWarnings]" + + "\t\t" + + " Analyzes target platform state, optionally shows warnings." + + " Eclipse root and bundle version have to be set before."; + Logging.writeStandardOut(help); + } + }, + Help("-h", true) { @Override int handle(CommandLineInterpreter cli, List args) { @@ -187,7 +203,7 @@ int handle(CommandLineInterpreter cli, List args) { } cli.getState().resolveDependencies(); return RC_OK; - } catch (IOException | SAXException | ParserConfigurationException e) { + } catch (IOException e) { Logging.getLogger().error("failed to read from: " + args, e); return RC_RUNTIME_ERROR; } diff --git a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/PlatformState.java b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/PlatformState.java index 5dc2685..2347109 100644 --- a/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/PlatformState.java +++ b/org.eclipselabs.plugindependencies.core/src/org/eclipselabs/plugindependencies/core/PlatformState.java @@ -436,6 +436,22 @@ private List collectErrors() { return errors; } + List collectWarnings() { + List warnings = new ArrayList<>(); + Consumer collectWarnings = x -> { + if (x.isWarning()) { + warnings.add(x); + } + }; + for (Plugin plugin : plugins) { + plugin.getLog().forEach(collectWarnings); + } + for (Feature feature : features) { + feature.getLog().forEach(collectWarnings); + } + return warnings; + } + private static boolean hasOnlyWorkspaceDup(List dups) { if(dups.size() != 2) { return false;