public DefaultContext() { super(null, null, null, ConfigHelper.create(null)); }
public Which(Context context) { super(context); // initialize with system environment PATHs this.paths = ConfigHelper.systemEnvironmentPaths(); }
static public List<Path> systemEnvironmentPaths() { List<String> pathStrings = systemEnvironmentPathsAsStrings(); return pathStrings.stream().map(s -> Paths.get(s)).collect(Collectors.toList()); }
classesDir = ConfigHelper.userBlazeEngineScriptClassesDir(context, getName()); log.trace("Using classes dir {}", classesDir);
public void configure() { if (detectedScriptFile == null) { locate(); } Path configFile = null; // a script may not actually have been detected if (this.detectedScriptFile != null) { configFile = ConfigHelper.path(detectedBaseDir, detectedScriptFile); scriptExtension = FileHelper.fileExtension(detectedScriptFile); } config = ConfigHelper.create(configFile); context = new ContextImpl( (detectedBaseDir != null ? detectedBaseDir : null), null, detectedScriptFile, config); ContextHolder.set(context); }
static public Path userBlazeEngineScriptClassesDir(Context context, String engineName) throws IOException { // md5 of the canonical path of this application's base directory // should be a consistent hash very usable for generating classes in String key = new StringBuilder() // base directory where script is from .append(context.baseDir().toFile().getCanonicalPath()) // version of blaze .append(Version.getVersion()) .toString(); String md5hash = md5(key); // ~/.blaze/engine/{engineName}/{md5hash} Path userBlazeEngineScriptClassesDir = userBlazeEngineDir(context, engineName) .resolve(md5hash) .resolve("classes"); Files.createDirectories(userBlazeEngineScriptClassesDir); return userBlazeEngineScriptClassesDir; }
static public Path userBlazeEngineDir(Context context, String engineName) throws IOException { Path userBlazeDir = userBlazeDir(context); // ~/.blaze/engine/{engineName} Path userBlazeEngineDir = userBlazeDir .resolve("engine") .resolve(engineName); Files.createDirectories(userBlazeEngineDir); return userBlazeEngineDir; }
static public Path find(Context context, List<Path> paths, Path command) throws BlazeException { // first, check if the command is already an absolute file if (isExecutableFile(command)) { return command; } // second, check each path to see if the command exists for (Path path : paths) { List<String> commandExtensions = ConfigHelper.commandExtensions(context.config()); for (String ext : commandExtensions) { // cmd -> cmd.exe String commandWithExt = command.toString() + ext; //File commandFile = new File(path.toFile(), commandWithExt); Path exeFile = path.resolve(commandWithExt); log.trace("Trying file: {}", exeFile); if (Files.exists(exeFile)) { if (Files.isRegularFile(exeFile) && Files.isExecutable(exeFile)) { return exeFile; } else { log.warn("Command '" + exeFile + "' found but it isn't executable! (continuing search...)"); } } } } return null; }
@Override public void log(String msg, int level) { // lots of smart filtering for only the useful messages from ivy String trimmedMessage = msg.trim(); if (level < Message.MSG_INFO) { log.error(trimmedMessage); } else if (trimmedMessage.startsWith("downloading ")) { // uppercase the d to match our other logging log.info("D{}", trimmedMessage.substring(1)); } else { if (ConfigHelper.isSuperDebugEnabled()) { log.trace(trimmedMessage); } } }
classesDir = ConfigHelper.userBlazeEngineScriptClassesDir(context, getName()); log.trace("Using classes dir {}", classesDir);
public void configure() { if (detectedScriptFile == null) { locate(); } Path configFile = null; // a script may not actually have been detected if (this.detectedScriptFile != null) { configFile = ConfigHelper.path(detectedBaseDir, detectedScriptFile); scriptExtension = FileHelper.fileExtension(detectedScriptFile); } config = ConfigHelper.create(configFile); context = new ContextImpl( (detectedBaseDir != null ? detectedBaseDir : null), null, detectedScriptFile, config); ContextHolder.set(context); }
static public Path userBlazeEngineScriptClassesDir(Context context, String engineName) throws IOException { // md5 of the canonical path of this application's base directory // should be a consistent hash very usable for generating classes in String key = new StringBuilder() // base directory where script is from .append(context.baseDir().toFile().getCanonicalPath()) // version of blaze .append(Version.getVersion()) .toString(); String md5hash = md5(key); // ~/.blaze/engine/{engineName}/{md5hash} Path userBlazeEngineScriptClassesDir = userBlazeEngineDir(context, engineName) .resolve(md5hash) .resolve("classes"); Files.createDirectories(userBlazeEngineScriptClassesDir); return userBlazeEngineScriptClassesDir; }
static public Path userBlazeEngineDir(Context context, String engineName) throws IOException { Path userBlazeDir = userBlazeDir(context); // ~/.blaze/engine/{engineName} Path userBlazeEngineDir = userBlazeDir .resolve("engine") .resolve(engineName); Files.createDirectories(userBlazeEngineDir); return userBlazeEngineDir; }
static public Path find(Context context, List<Path> paths, Path command) throws BlazeException { // first, check if the command is already an absolute file if (isExecutableFile(command)) { return command; } // second, check each path to see if the command exists for (Path path : paths) { List<String> commandExtensions = ConfigHelper.commandExtensions(context.config()); for (String ext : commandExtensions) { // cmd -> cmd.exe String commandWithExt = command.toString() + ext; //File commandFile = new File(path.toFile(), commandWithExt); Path exeFile = path.resolve(commandWithExt); log.trace("Trying file: {}", exeFile); if (Files.exists(exeFile)) { if (Files.isRegularFile(exeFile) && Files.isExecutable(exeFile)) { return exeFile; } else { log.warn("Command '" + exeFile + "' found but it isn't executable! (continuing search...)"); } } } } return null; }
classesDir = ConfigHelper.userBlazeEngineScriptClassesDir(context, getName()); log.trace("Using classes dir {}", classesDir);
static public Path userBlazeCacheDir(Context context) throws IOException { Path userCacheDir = userBlazeDir(context).resolve("cache"); if (Files.notExists(userCacheDir)) { Files.createDirectory(userCacheDir); } return userCacheDir; }
public Which(Context context) { super(context); // initialize with system environment PATHs this.paths = ConfigHelper.systemEnvironmentPaths(); }
static public List<Path> systemEnvironmentPaths() { List<String> pathStrings = systemEnvironmentPathsAsStrings(); return pathStrings.stream().map(s -> Paths.get(s)).collect(Collectors.toList()); }
public DefaultContext() { super(null, null, null, ConfigHelper.create(null)); }
static public Path userBlazeCacheDir(Context context) throws IOException { Path userCacheDir = userBlazeDir(context).resolve("cache"); if (Files.notExists(userCacheDir)) { Files.createDirectory(userCacheDir); } return userCacheDir; }