From 5f7c6b8481145e598796b03a1cf1b9e5f839289c Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Wed, 1 Jun 2016 17:54:10 -0400 Subject: [PATCH] analysis.lami: check if command is executable, and support relative paths This patch makes LamiAnalysis check if a given executable name is indeed executable, not just existing. It also adds support for relative paths. For example, if your current working directory is /tmp/hello, and there's an analysis at /tmp/hello/my-analysis, then creating a custom external analysis starting with `./my-analysis` finds the executable file/link. Change-Id: I7a6ba4bbd95a9c190296c07f0f04c87aca2ecf34 Signed-off-by: Philippe Proulx Reviewed-on: https://git.eclipse.org/r/74334 Reviewed-by: Matthew Khouzam Reviewed-by: Hudson CI Reviewed-by: Alexandre Montplaisir Tested-by: Alexandre Montplaisir --- .../lami/core/module/LamiAnalysis.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) 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 50c7d27191..ebcff2235a 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 @@ -160,6 +160,21 @@ public class LamiAnalysis implements IOnDemandAnalysis { return fIsAvailable; } + private static boolean executableExists(String name) { + if (name.contains(File.separator)) { + // This seems like a path, not just an executable name + return Files.isExecutable(Paths.get(name)); + } + + // Check if this name is found in the PATH environment variable + final String pathEnv = System.getenv("PATH"); //$NON-NLS-1$ + final String[] exeDirs = pathEnv.split(checkNotNull(Pattern.quote(File.pathSeparator))); + + return Stream.of(exeDirs) + .map(Paths::get) + .anyMatch(path -> Files.isExecutable(path.resolve(name))); + } + /** * Perform initialization of the LAMI script. This means verifying that it * is actually present on disk, and that it returns correct --metadata. @@ -173,11 +188,10 @@ public class LamiAnalysis implements IOnDemandAnalysis { /* Do the analysis's initialization */ /* Check if the script's expected executable is on the PATH */ - String executable = fScriptCommand.get(0); - boolean exists = Stream.of(System.getenv("PATH").split(checkNotNull(Pattern.quote(File.pathSeparator)))) //$NON-NLS-1$ - .map(Paths::get) - .anyMatch(path -> Files.exists(path.resolve(executable))); - if (!exists) { + final String executable = fScriptCommand.get(0); + final boolean executableExists = executableExists(executable); + + if (!executableExists) { /* Script is not found */ fIsAvailable = false; fInitialized = true; -- 2.34.1