public void locate() { if (this.file != null) { detectedBaseDir = this.file.getParentFile(); detectedScriptFile = this.file; } else { // otherwise fallback to trying to figure it out ourselves if (this.directory == null) { this.directory = new File("."); } // search for file named "blaze.<ext>" File[] blazeFiles = this.directory.listFiles( (File f) -> f.getName().startsWith("blaze.") && !f.getName().endsWith(".conf") && !f.getName().endsWith(".jar")); if (blazeFiles.length == 0) { throw new MessageOnlyException( "Unable to find a blaze file (e.g. blaze.js). Perhaps this is not a Blaze project?"); } if (blazeFiles.length > 1) { throw new MessageOnlyException( "More than one blaze file found. Either delete the extra files use -f parameter"); } detectedBaseDir = this.directory; detectedScriptFile = blazeFiles[0]; } // at this point we should have a file - verify it exists and works if (!detectedScriptFile.exists()) { throw new MessageOnlyException( "Blaze file " + detectedScriptFile + " not found. Perhaps this is not a Blaze project?"); } if (!detectedScriptFile.isFile()) { throw new MessageOnlyException( "Blaze file " + detectedScriptFile + " is not a file. Perhaps this is not a Blaze project?"); } if (detectedBaseDir != null && detectedBaseDir.getPath().equals(".")) { detectedBaseDir = null; } detectedScriptFile = FileHelper.relativizeToJavaWorkingDir(detectedScriptFile); log.trace("Using blaze dir {} and file {}", detectedBaseDir, detectedScriptFile); }
public void configure() { if (detectedScriptFile == null) { locate(); } File configFile = ConfigHelper.file(detectedBaseDir, detectedScriptFile); config = ConfigHelper.create(configFile); scriptExtension = FileHelper.fileExtension(detectedScriptFile); context = new ContextImpl( (detectedBaseDir != null ? detectedBaseDir.toPath() : null), null, detectedScriptFile.toPath(), config); ContextHolder.set(context); }