analysis.lami: check if command is executable, and support relative paths
authorPhilippe Proulx <pproulx@efficios.com>
Wed, 1 Jun 2016 21:54:10 +0000 (17:54 -0400)
committerAlexandre Montplaisir <alexmonthy@efficios.com>
Thu, 4 Aug 2016 06:23:33 +0000 (02:23 -0400)
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 <pproulx@efficios.com>
Reviewed-on: https://git.eclipse.org/r/74334
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Hudson CI
Reviewed-by: Alexandre Montplaisir <alexmonthy@efficios.com>
Tested-by: Alexandre Montplaisir <alexmonthy@efficios.com>
analysis/org.eclipse.tracecompass.analysis.lami.core/src/org/eclipse/tracecompass/internal/provisional/analysis/lami/core/module/LamiAnalysis.java

index 50c7d27191363eef012640b9e7042c9dcfcab236..ebcff2235aedf581c354e3eb6c830499ee127e60 100644 (file)
@@ -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;
This page took 0.031307 seconds and 5 git commands to generate.