analysis.lami: check if command is executable, and support relative paths
[deliverable/tracecompass.git] / 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.030096 seconds and 5 git commands to generate.