X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=analysis%2Forg.eclipse.tracecompass.analysis.lami.core%2Fsrc%2Forg%2Feclipse%2Ftracecompass%2Finternal%2Fprovisional%2Fanalysis%2Flami%2Fcore%2Fmodule%2FLamiAnalysis.java;h=5cd62122c629a7dced5b3b8f1cc395d8698f1775;hb=ace6413cbfd37cb5dbfcf36c1afb10d32b338ef5;hp=f11f6c9e5f4b8520e32a2f58821832f17bc2510f;hpb=814a7e43052e94745172d76580595565967e271f;p=deliverable%2Ftracecompass.git diff --git a/analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiAnalysis.java b/analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiAnalysis.java index f11f6c9e5f..5cd62122c6 100644 --- a/analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiAnalysis.java +++ b/analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiAnalysis.java @@ -61,6 +61,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; @@ -141,7 +142,7 @@ public class LamiAnalysis implements IOnDemandAnalysis { } @Override - public boolean appliesTo(ITmfTrace trace) { + public final boolean appliesTo(ITmfTrace trace) { return fAppliesTo.test(trace); } @@ -151,7 +152,12 @@ public class LamiAnalysis implements IOnDemandAnalysis { return fIsAvailable; } - private synchronized void initialize() { + /** + * Perform initialization of the LAMI script. This means verifying that it + * is actually present on disk, and that it returns correct --metadata. + */ + @VisibleForTesting + protected synchronized void initialize() { if (fInitialized) { return; } @@ -174,7 +180,15 @@ public class LamiAnalysis implements IOnDemandAnalysis { fInitialized = true; } - private boolean checkMetadata() { + /** + * Verify that this script returns valid metadata. + * + * This will populate all remaining non-final fields of this class. + * + * @return If the metadata is valid or not + */ + @VisibleForTesting + protected boolean checkMetadata() { /* * The initialize() phase of the analysis will be used to check the * script's metadata. Actual runs of the script will use the execute() @@ -638,9 +652,7 @@ public class LamiAnalysis implements IOnDemandAnalysis { } } catch (JSONException e) { - /* Error parsing the output */ - Activator.instance().logError(nullToEmptyString(e.getMessage())); - return Collections.EMPTY_LIST; + throw new OnDemandAnalysisException(e.getMessage()); } return resultsBuilder.build(); @@ -660,8 +672,14 @@ public class LamiAnalysis implements IOnDemandAnalysis { * Get the output of an external command, used for getting the metadata. * Cannot be cancelled, and will not report errors, simply returns null if * the process ended abnormally. + * + * @param command + * The parameters of the command, passed to + * {@link ProcessBuilder} + * @return The command output as a string */ - private static @Nullable String getOutputFromCommand(List command) { + @VisibleForTesting + protected @Nullable String getOutputFromCommand(List command) { try { ProcessBuilder builder = new ProcessBuilder(command); builder.redirectErrorStream(true); @@ -681,14 +699,20 @@ public class LamiAnalysis implements IOnDemandAnalysis { /** * Get the results of invoking the specified command. * - * The result should start with '{"results":...', as specified by the - * LAMI JSON protocol. The JSON itself may be split over multiple lines. + * The result should start with '{"results":...', as specified by the LAMI + * JSON protocol. The JSON itself may be split over multiple lines. * * @param command * The command to run (program and its arguments) + * @param monitor + * The progress monitor * @return The analysis results + * @throws OnDemandAnalysisException + * If the command ended abnormally, and normal results were not + * returned */ - private static String getResultsFromCommand(List command, IProgressMonitor monitor) + @VisibleForTesting + protected String getResultsFromCommand(List command, IProgressMonitor monitor) throws OnDemandAnalysisException { final int scale = 1000;