Skip to content

Commit

Permalink
Added -analyzeTargetState [showWarnings] command line option
Browse files Browse the repository at this point in the history
Analyzes target platform state, optionally shows warnings. Eclipse root
and bundle version have to be set before.
  • Loading branch information
iloveeclipse committed Jun 29, 2022
1 parent 245eb50 commit 0541eef
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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<Problem> errors = state.computeAllDependenciesRecursive();
if(!errors.isEmpty()) {
Logging.getLogger().error("Errors analyzing bundle dependencies");
errors.forEach(e -> Logging.getLogger().error(e.toString()));
}
List<Problem> 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 = "";
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -144,6 +140,26 @@ void printHelp(String arg) {
}
},

AnalyzeTargetState("-analyzeTargetState", true) {
@Override
int handle(CommandLineInterpreter cli, List<String> 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<String> args) {
Expand Down Expand Up @@ -187,7 +203,7 @@ int handle(CommandLineInterpreter cli, List<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,22 @@ private List<Problem> collectErrors() {
return errors;
}

List<Problem> collectWarnings() {
List<Problem> warnings = new ArrayList<>();
Consumer<? super Problem> 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<OSGIElement> dups) {
if(dups.size() != 2) {
return false;
Expand Down

0 comments on commit 0541eef

Please sign in to comment.