/** * The application base directory. The base directory is the directory * of the script that is executing. So if your script is located at * "/home/joelauer/project/blaze.java" then this baes directory would be * "/home/joelauer/project" * @return The application base directory */ static public Path baseDir() { return ContextHolder.get().baseDir(); }
/** * The application configuration * @return The application configuration instance. Guaranteed to be present. */ static public Config config() { return ContextHolder.get().config(); }
/** * The current user's home directory such as "/home/joelauer" or "C:\Users\Joe Lauer". * This method differs from <code>System.getProperty("user.home")</code> by * checking the environment variables HOME and HOMEPATH first. This allows * a program running under something like "sudo" to still correctly find * the actual user's home directory rather than "root". * * @return The current user's home directory */ static public Path userDir() { return ContextHolder.get().userDir(); }
throw new MessageOnlyException("Unable to compile " + context.scriptFile() + " to a class file.\n" + " The system java compiler is missing (are you running a JRE rather than a JDK?)\n" + " Either run this with a JDK or add \"org.eclipse.jdt.core.compiler:ecj:<version>\" to blaze.dependencies.");
public void execute(String task) throws Exception { if (task == null || task.equals("")) { task = context.config().value(Config.KEY_DEFAULT_TASK).getOr(Config.DEFAULT_TASK); } String scriptName = (context.scriptFile() != null ? context.scriptFile().toString() : ""); log.info("Executing {}:{}...", scriptName, task); Timer executeTimer = new Timer(); this.script.execute(task); log.info("Executed {}:{} in {} ms", scriptName, task, executeTimer.stop().millis()); }
public JschConnect(Context context, MutableUri uri) { super(context); this.uri = uri; this.connectTimeout = 20000L; this.keepAliveInterval = 10000L; this.configFile = context.withUserDir(".ssh/config"); this.knownHostsFile = context.withUserDir(".ssh/known_hosts"); this.identityFiles = new ArrayList<>(); this.identityFiles.add(context.withUserDir(".ssh/id_rsa")); this.identityFiles.add(context.withUserDir(".ssh/id_dsa")); this.hostChecking = true; }
if (context.config().value(Config.KEY_DEPENDENCY_CLEAN, Boolean.class).getOr(Config.DEFAULT_DEPENDENCY_CLEAN)) { log.info("Cleaning dependency cache..."); ivy.getResolutionCacheManager().clean(); Path cachedFile = context.userDir().resolve(".ivy2/cache/" + d.getGroupId() + "/" + d.getArtifactId() + "/jars/" + d.getArtifactId() + "-" + d.getVersion() + ".jar"); if (Files.exists(cachedFile)) { log.trace("Deleting cached snapshot dependency {}", cachedFile); File userHomeDir = context.userDir().toFile();
/** * Resolves a path relative to the base directory. If the path is absolute * it will be returned intact, otherwise it will be appended to the * current base directory. So if your base directory is "/home/joelauer/project" * and you provide a path of "images/my.png" then a path of "/home/joelauer/project/images/my.png" * will be returned * @param path The path to resolve * @return The resolved path * @see #withBaseDir(java.io.File) * @see #withBaseDir(java.lang.String) */ static public Path withBaseDir(Path path) { return ContextHolder.get().withBaseDir(path); }
/** * A logger for the current context. * @return A logger for the current context. Guaranteed to be present. */ static public Logger logger() { return ContextHolder.get().logger(); }
static public char[] passwordPrompt(String prompt, Object... args) { return ContextHolder.get().passwordPrompt(prompt, args); }
static public String prompt(String prompt, Object... args) { return ContextHolder.get().prompt(prompt, args); }
throw new MessageOnlyException("Unable to compile " + context.scriptFile() + " to a class file.\n" + " The system java compiler is missing (are you running a JRE rather than a JDK?)\n" + " Either run this with a JDK or add \"org.eclipse.jdt.core.compiler:ecj:<version>\" to blaze.dependencies.");
public void execute(String task) throws Exception { if (task == null || task.equals("")) { task = context.config().value(Config.KEY_DEFAULT_TASK).getOr(Config.DEFAULT_TASK); } String scriptName = (context.scriptFile() != null ? context.scriptFile().toString() : ""); log.info("Executing {}:{}...", scriptName, task); Timer executeTimer = new Timer(); this.script.execute(task); log.info("Executed {}:{} in {} ms", scriptName, task, executeTimer.stop().millis()); }
static public Path userBlazeDir(Context context) throws IOException { Path userBlazeDir = context.withUserDir(".blaze"); if (Files.notExists(userBlazeDir)) { Files.createDirectory(userBlazeDir); } return userBlazeDir; }
/** * Resolves a path relative to the base directory. If the path is absolute * it will be returned intact, otherwise it will be appended to the * current base directory. So if your base directory is "/home/joelauer/project" * and you provide a path of "images/my.png" then a path of "/home/joelauer/project/images/my.png" * will be returned * @param path The path to resolve * @return The resolved path * @see #withBaseDir(java.io.File) * @see #withBaseDir(java.lang.String) */ static public Path withBaseDir(Path path) { return ContextHolder.get().withBaseDir(path); }
/** * A logger for the current context. * @return A logger for the current context. Guaranteed to be present. */ static public Logger logger() { return ContextHolder.get().logger(); }
static public char[] passwordPrompt(String prompt, Object... args) { return ContextHolder.get().passwordPrompt(prompt, args); }
static public String prompt(String prompt, Object... args) { return ContextHolder.get().prompt(prompt, args); }
@Override public BlazeGroovyScript compile(Context context) throws BlazeException { try { // must be valid url... String path = context.scriptFile().toUri().toURL().toString(); Binding binding = new Binding(); // add small number of useful bindings // not sure its best practice to polute namespace at all //binding.setVariable("context", context); //binding.setVariable("log", context.logger()); //binding.setVariable("config", context.config()); Script script = script = this.groovy.createScript(path, binding); script.run(); return new BlazeGroovyScript(this, script); } catch (ResourceException | IOException | ScriptException e) { throw new BlazeException("Unable to compile groovy script", e); } } }
static public Path userBlazeDir(Context context) throws IOException { Path userBlazeDir = context.withUserDir(".blaze"); if (Files.notExists(userBlazeDir)) { Files.createDirectory(userBlazeDir); } return userBlazeDir; }