All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.dagere.peass.execution.utils.EnvironmentVariables Maven / Gradle / Ivy

The newest version!
package de.dagere.peass.execution.utils;

import java.io.File;
import java.io.Serializable;
import java.util.Map;
import java.util.TreeMap;

public class EnvironmentVariables implements Serializable {

   private static final long serialVersionUID = 6287969989033845334L;

   private final Map environmentVariables = new TreeMap<>();

   private final String properties;

   public EnvironmentVariables(final String properties) {
      if (properties != null) {
         this.properties = properties;
      } else {
         this.properties = "";
      }
   }

   public EnvironmentVariables() {
      properties = "";
   }

   public Map getEnvironmentVariables() {
      return environmentVariables;
   }

   public String getProperties() {
      return properties;
   }

   public String fetchMavenCall(File projectFolder) {
      if (projectFolder != null) {
         if (!isWindows()) {
            File potentialWrapper = new File(projectFolder, "mvnw");
            if (potentialWrapper.exists() && potentialWrapper.canExecute()) {
               return "./mvnw";
            }
         } else {
            File potentialWrapper = new File(projectFolder, "mvnw.cmd");
            if (potentialWrapper.exists()) {
               return potentialWrapper.getAbsolutePath();
            }
         }
      }

      return fetchMavenCall();
   }

   private String fetchMavenCall() {
      String mvnCall;
      if (environmentVariables.containsKey("MVN_CMD")) {
         mvnCall = environmentVariables.get("MVN_CMD");
      } else if (!isWindows()) {
         mvnCall = "mvn";
      } else {
         mvnCall = "mvn.cmd";
      }
      return mvnCall;
   }

   public static String fetchMavenCallGeneric() {
      String mvnCall;
      if (!isWindows()) {
         mvnCall = "mvn";
      } else {
         mvnCall = "mvn.cmd";
      }
      return mvnCall;
   }

   public static String fetchGradleCall() {
      String gradleCall;
      if (!isWindows()) {
         gradleCall = "./gradlew";
      } else {
         gradleCall = "gradlew.bat";
      }
      return gradleCall;
   }

   public static String fetchAdbCall() {
      String adbCall;
      adbCall = new File(System.getenv("ANDROID_SDK_ROOT"), "platform-tools/adb").getAbsolutePath();
      return adbCall;
   }

   public static boolean isWindows() {
      return System.getProperty("os.name").startsWith("Windows");
   }

   public static boolean isLinux() {
      return !System.getProperty("os.name").startsWith("Windows") && !System.getProperty("os.name").startsWith("Mac");
   }
   
   public static int getVersion() {
      String version = System.getProperty("java.version");
      if(version.startsWith("1.")) {
          version = version.substring(2, 3);
      } else {
          int dot = version.indexOf(".");
          if(dot != -1) { version = version.substring(0, dot); }
      } return Integer.parseInt(version);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy