Build a script from a file.

@param f the file to parse
@return the resulting script
@throws ScriptBuilderException if an error occurred
501948
public Script build(File f) throws ScriptBuilderException {
        int k = f.getAbsolutePath().hashCode();
        if (dates.containsKey(k) && dates.get(k) == f.lastModified() && cache.containsKey(f.getPath())) {
            LOGGER.debug("get '" + f.getName() + "' from the cache");
            return cache.get(f.getPath());
        }

        LOGGER.debug(f.getName() + " is built from the file");
        dates.put(k, f.lastModified());
        String name = f.getName();
        try {
            Script v = build(new ANTLRFileStream(f.getAbsolutePath()));
            if (!name.equals(v.getlocalName() + Script.EXTENSION)) {
                throw new ScriptBuilderException("Script '" + v.getlocalName()
                        + "' must be declared in a file named '" + v.getlocalName() + Script.EXTENSION);
            }
            cache.put(f.getPath(), v);
            return v;
        } catch (IOException e) {
            throw new ScriptBuilderException(e.getMessage(), e);
        }

    }
919765
public Engine fromFile(File file) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                new FileInputStream(file), FuzzyLite.UTF_8));
        String line;
        StringBuilder textEngine = new StringBuilder();
        try {
            while ((line = reader.readLine()) != null) {
                textEngine.append(line).append("\n");
            }
        } catch (IOException ex) {
            throw ex;
        } finally {
            reader.close();
        }
        return fromString(textEngine.toString());
    }
1228477
public Class parseClass(final String text, final String fileName) throws CompilationFailedException {
        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
            public GroovyCodeSource run() {
                return new GroovyCodeSource(text, fileName, "/groovy/script");
            }
        });
        gcs.setCachable(false);
        return parseClass(gcs);
    }
860701
public static ParameterTool fromPropertiesFile(File file) throws IOException {
		if (!file.exists()) {
			throw new FileNotFoundException("Properties file " + file.getAbsolutePath() + " does not exist");
		}
		try (FileInputStream fis = new FileInputStream(file)) {
			return fromPropertiesFile(fis);
		}
	}
364799
public Object evaluate(final String scriptText, final String fileName, final String codeBase) throws CompilationFailedException {
        SecurityManager sm = System.getSecurityManager();
        if (sm != null) {
            sm.checkPermission(new GroovyCodeSourcePermission(codeBase));
        }

        GroovyCodeSource gcs = AccessController.doPrivileged(new PrivilegedAction<GroovyCodeSource>() {
            public GroovyCodeSource run() {
                return new GroovyCodeSource(scriptText, fileName, codeBase);
            }
        });

        return evaluate(gcs);
    }
1100229
static void configure(final InputStream f) {
		new Configurator() {

			@Override
			void withConfigurator(JoranConfigurator configurator)
					throws JoranException {

				if (f == null)
					throw new IllegalArgumentException("File cannot be null");

				configurator.doConfigure(f);

			}
		}.configure();
	}
364740
public Script parse(final GroovyCodeSource codeSource) throws CompilationFailedException {
        return InvokerHelper.createScript(parseClass(codeSource), context);
    }
344718
public void parse(File f, DefaultHandler dh) throws SAXException, IOException
    {
        XMLReader reader = getXMLReader();
        InputSource source = new InputSource(new FileInputStream(f));
        reader.setContentHandler(dh);
        reader.parse(source);
    }
1113354
protected void generateIScriptBuilder() {
		final List<StringConcatenationClient> topElements = generateTopElements(true, false);
		final TypeReference builder = getScriptBuilderInterface();
		final StringConcatenationClient content = new StringConcatenationClient() {
			@Override
			protected void appendTo(TargetStringConcatenation it) {
				it.append("/** Builder of " + getLanguageName() + " scripts."); //$NON-NLS-1$ //$NON-NLS-2$
				it.newLine();
				it.append(" *"); //$NON-NLS-1$
				it.newLine();
				it.append(" * <p>This builder is provided for helping to create " //$NON-NLS-1$
						+ getLanguageName()
						+ " Ecore elements."); //$NON-NLS-1$
				it.newLine();
				it.append(" *"); //$NON-NLS-1$
				it.newLine();
				it.append(" * <p>Do not forget to invoke {@link #finalizeScript()} for creating imports, etc."); //$NON-NLS-1$
				it.newLine();
				it.append(" */"); //$NON-NLS-1$
				it.newLine();
				it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$
				it.newLine();
				it.append("public interface "); //$NON-NLS-1$
				it.append(builder.getSimpleName());
				it.append(" {"); //$NON-NLS-1$
				it.newLineIfNotEmpty();
				it.newLine();
				it.append(generateFieldsAndMethods(true, false));
				for (final StringConcatenationClient element : topElements) {
					it.append(element);
				}
				it.append("}"); //$NON-NLS-1$
				it.newLineIfNotEmpty();
				it.newLine();
			}

		};
		final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(builder, content);
		javaFile.writeTo(getSrcGen());
	}
558323
private ScriptExecutor createScriptExecutor() {
        String className = null;
        ClassLoader loader = ScriptExecutor.class.getClassLoader();

        // 1. try the JVM-instance-wide system property
        try {
            className = System.getProperty(property);
        } catch (RuntimeException e) { /* normally fails for applets */
        }

        // 2. if that fails, try META-INF/services/
        if (StringUtils.isEmpty(className)) {
            try {
                String service = "META-INF/services/" + property;
                InputStream in;
                BufferedReader reader;

                if (loader == null) {
                    in = ClassLoader.getSystemResourceAsStream(service);
                } else {
                    in = loader.getResourceAsStream(service);
                }

                if (in != null) {
                    reader = new BufferedReader(new InputStreamReader(in, System.getProperty("file.encoding", "UTF-8")));
                    className = reader.readLine();
                    in.close();
                }
            } catch (Exception e) {
            }
        }

        // 3. Distro-specific fallback
        if (className == null) {
            className = DEFAULT_SCRIPT;
        }

        Class clazz = ReflectionHelper.forName(className, loader);
        return (ScriptExecutor) ReflectionHelper.newInstance(clazz);
    }
542420
public static <R> FuncN<R> fromFunc(final Func0<? extends R> f) {
        return new FuncN<R>() {

            @Override
            public R call(Object... args) {
                if (args.length != 0) {
                    throw new RuntimeException("Func0 expecting 0 arguments.");
                }
                return f.call();
            }

        };
    }
439396
public static Map<String, File> loadStringToFileMap(final File f) throws IOException {
    return loadStringToFileMap(Files.asCharSource(f, Charsets.UTF_8));
  }
63376
public JavaFileObject asJavaFileObject(File file) {
        JavacFileManager fm = (JavacFileManager)context.get(JavaFileManager.class);
        return fm.getRegularFile(file);
    }
1280053
protected void generateScriptBuilderImpl() {
		final List<StringConcatenationClient> topElements = generateTopElements(false, false);
		final TypeReference script = getScriptBuilderImpl();
		final TypeReference scriptInterface = getScriptBuilderInterface();
		final StringConcatenationClient content = new StringConcatenationClient() {
			@Override
			protected void appendTo(TargetStringConcatenation it) {
				it.append("@SuppressWarnings(\"all\")"); //$NON-NLS-1$
				it.newLine();
				it.append("public class "); //$NON-NLS-1$
				it.append(script.getSimpleName());
				it.append(" extends "); //$NON-NLS-1$
				it.append(getAbstractBuilderImpl());
				it.append(" implements "); //$NON-NLS-1$
				it.append(scriptInterface);
				it.append(" {"); //$NON-NLS-1$
				it.newLineIfNotEmpty();
				it.newLine();
				it.append(generateFieldsAndMethods(false, false));
				for (final StringConcatenationClient element : topElements) {
					it.append(element);
				}
				it.append("}"); //$NON-NLS-1$
				it.newLineIfNotEmpty();
			}

		};
		final JavaFileAccess javaFile = getFileAccessFactory().createJavaFile(script, content);
		javaFile.writeTo(getSrcGen());
	}
511810
public GroovyActionBuilder template(Resource scriptTemplate, Charset charset) {
		try {
            action.setScriptTemplate(FileUtils.readToString(scriptTemplate, charset));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read script template file", e);
        }
		return this;
	}
517227
public String build() {
        StringBuilder scriptBuilder = new StringBuilder();
        StringBuilder scriptBody = new StringBuilder();
        String importStmt = "import ";
        
        try {
            if (scriptCode.contains(importStmt)) {
                BufferedReader reader = new BufferedReader(new StringReader(scriptCode));
                String line;
                while ((line = reader.readLine()) != null) {
                    if (line.trim().startsWith(importStmt)) {
                        scriptBuilder.append(line);
                        scriptBuilder.append("\n");
                    } else {
                        scriptBody.append((scriptBody.length() == 0 ? "" : "\n"));
                        scriptBody.append(line);
                    }
                }
            } else {
                scriptBody.append(scriptCode);
            }
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to construct script from template", e);
        }
        
        scriptBuilder.append(scriptHead);
        scriptBuilder.append(scriptBody.toString());
        scriptBuilder.append(scriptTail);
        
        return scriptBuilder.toString();
    }
280940
def dump(self, f):
        
        self.validate()
        with _open_file_obj(f, "w") as f:
            parser = self._get_parser()
            self.serialize(parser)
            self.build_file(parser, f)