Internal method to check a script from a stream.

@param cs the stream to analyze
@return the built script
@throws ScriptBuilderException in an error occurred while building the script
333125
@SuppressWarnings("squid:S1166") //For the UnsupportedOperationException
    private Script build(CharStream cs) throws ScriptBuilderException {

        Script v = new Script();

        ANTLRBtrplaceSL2Lexer lexer = new ANTLRBtrplaceSL2Lexer(cs);

        ErrorReporter errorReporter = errBuilder.build(v);

        lexer.setErrorReporter(errorReporter);
        CommonTokenStream tokens = new CommonTokenStream(lexer);

        ANTLRBtrplaceSL2Parser parser = new ANTLRBtrplaceSL2Parser(tokens);
        parser.setErrorReporter(errorReporter);

        SymbolsTable t = new SymbolsTable();

        parser.setTreeAdaptor(new BtrPlaceTreeAdaptor(v, model, namingServiceNodes, namingServiceVMs, tpls, errorReporter, t, includes, catalog));

        try {
            BtrPlaceTree tree = (BtrPlaceTree) parser.script_decl().getTree();
            if (tree != null) {
                if (tree.token != null) {
                        tree.go(tree); //Single instruction
                } else {
                    for (int i = 0; i < tree.getChildCount(); i++) {
                            tree.getChild(i).go(tree);
                        }
                    }
            }
        } catch (RecognitionException e) {
            throw new ScriptBuilderException(e.getMessage(), e);
        } catch (UnsupportedOperationException e) {
            //We only keep the error message
            errorReporter.append(0, 0, e.getMessage());
        }
        if (!errorReporter.getErrors().isEmpty()) {
            throw new ScriptBuilderException(errorReporter);
        }
        return v;
    }
376945
public static IActionType<?> getType(String script) {
        for (IActionType<?> actionType : instance) {
            if (actionType.matches(script)) {
                return actionType;
            }
        }

        throw new IllegalArgumentException("Script type was not recognized: " + script);
    }
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);
    }
518008
public Script getScriptSig() throws ScriptException {
        // Transactions that generate new coins don't actually have a script. Instead this
        // parameter is overloaded to be something totally different.
        Script script = scriptSig == null ? null : scriptSig.get();
        if (script == null) {
            script = new Script(scriptBytes);
            scriptSig = new WeakReference<>(script);
        }
        return script;
    }
1108119
public static Script createInputScript(@Nullable TransactionSignature signature, ECKey pubKey) {
        byte[] pubkeyBytes = pubKey.getPubKey();
        byte[] sigBytes = signature != null ? signature.encodeToBitcoin() : new byte[]{};
        return new ScriptBuilder().data(sigBytes).data(pubkeyBytes).build();
    }
409951
@SuppressWarnings("unchecked")
	private StringBuffer buildEngineScript(StringBuffer engineScript,ServletContext servletContext) {
		List<Container> containers = ContainerUtil.getAllPublishedContainers(servletContext);
		String allowGetForSafariButMakeForgeryEasier = "";
		String scriptTagProtection = DwrConstants.SCRIPT_TAG_PROTECTION;
		String pollWithXhr = "";
		String sessionCookieName = "JSESSIONID";
		

		
		for(Iterator<Container> it = containers.iterator();it.hasNext();) {
			Container container = it.next();
			ServerLoadMonitor monitor = (ServerLoadMonitor) container.getBean(ServerLoadMonitor.class.getName());
			pollWithXhr = monitor.supportsStreaming() ? "false" : "true";
			
			if(null != container.getBean("allowGetForSafariButMakeForgeryEasier")){
				allowGetForSafariButMakeForgeryEasier = (String)container.getBean("allowGetForSafariButMakeForgeryEasier");
			}
			if(null != container.getBean("scriptTagProtection")){
				scriptTagProtection = (String)container.getBean("scriptTagProtection");
			}
			if(null != container.getBean("sessionCookieName")){
				sessionCookieName = (String)container.getBean("sessionCookieName");
			}		
		}
		StringBuffer sb = new StringBuffer();
		Matcher matcher = PARAMS_PATTERN.matcher(engineScript);
		while(matcher.find()) {
			String match = matcher.group();
			if("${allowGetForSafariButMakeForgeryEasier}".equals(match)){
				matcher.appendReplacement(sb, allowGetForSafariButMakeForgeryEasier);				
			}
			else if("${pollWithXhr}".equals(match)){
				matcher.appendReplacement(sb, pollWithXhr);				
			}
			else if("${sessionCookieName}".equals(match)){
				matcher.appendReplacement(sb, sessionCookieName);				
			}
			else if("${scriptTagProtection}".equals(match)){
				matcher.appendReplacement(sb, scriptTagProtection);				
			}
			else if("${scriptSessionId}".equals(match)){
				matcher.appendReplacement(sb, "\"+JAWR.dwr_scriptSessionId+\"");	
			}
			else if("${defaultPath}".equals(match)){

				matcher.appendReplacement(sb, "\"+JAWR.jawr_dwr_path+\"");
			}
		}
		DWRParamWriter.setUseDynamicSessionId(true);
		matcher.appendTail(sb);
		return sb;
	}
280594
public CompiledScript compile(String scriptSource) throws ScriptException {
        try {
            return new GroovyCompiledScript(this,
                    getScriptClass(scriptSource));
        } catch (SyntaxException e) {
            throw new ScriptException(e.getMessage(),
                    e.getSourceLocator(), e.getLine());
        } catch (IOException e) {
            throw new ScriptException(e);
        } catch (CompilationFailedException ee) {
            throw new ScriptException(ee);
        }
    }
821320
public AbstractBuilder getPropertyBuilder(ClassWriter classWriter) throws Exception {
        final PropertyWriter propertyWriter =
                writerFactory.getPropertyWriter(classWriter);
        return PropertyBuilder.getInstance(context,
                                           classWriter.getClassDoc(),
                                           propertyWriter);
    }
868792
@Override
	public Scriptable createThreadScope(Context cx, Scriptable protoScope) {
		final String sourceMethod = "createThreadScope"; //$NON-NLS-1$
		final boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(sourceClass, sourceMethod, new Object[]{cx, protoScope});
		}
		Scriptable threadScope = super.createThreadScope(cx, protoScope);
		for (Script script : lessJsScript) {
			script.exec(cx, threadScope);
		};
		compilerScript.exec(cx, threadScope);
		ReadFileExtFunction readFileFn = new ReadFileExtFunction(threadScope, getAggregator());
		ScriptableObject.putProperty(threadScope, ReadFileExtFunction.FUNCTION_NAME, readFileFn);


		if (isTraceLogging) {
			log.exiting(sourceMethod, sourceMethod, threadScope);
		}
		return threadScope;
	}
1340988
private void executeScript(String script) {
        try {
            final StatementSplitter statementSplitter =
                new StatementSplitterResolver(scriptConfigurationInstance.get()).resolve();
            final ScriptExecutor scriptExecutor =
                new ScriptExecutor(databaseConnection.get().getConnection(), scriptConfigurationInstance.get(),
                    statementSplitter);
            scriptExecutor.execute(script);
        } catch (SQLException e) {
            throw new DBUnitConnectionException("Unable to execute script.", e);
        }
    }
116052
public static GeneratedScript script(final String script, final String[] args, final String fileExtension) {
        return new GeneratedScriptBuilder(script, args, fileExtension);
    }
782346
public void exec(String source, int lineNo, int columnNo, Object script) throws BSFException {
        try {
            //          shell.run(script.toString(), source, EMPTY_ARGS);

            Class scriptClass = execScripts.get(script);
            if (scriptClass == null) {
                scriptClass = loader.parseClass(script.toString(), source);
                execScripts.put(script, scriptClass);
            } else {
                LOG.fine("exec() - Using cached version of class...");
            }
            InvokerHelper.invokeMethod(scriptClass, "main", EMPTY_ARGS);
        } catch (Exception e) {
            LOG.log(Level.WARNING, "BSF trace", e);
            throw new BSFException(BSFException.REASON_EXECUTION_ERROR, "exception from Groovy: " + e, e);
        }
    }
77373
public <T extends AbstractGoogleJsonClient.Builder> T fromClientSecretsFile(T builder,
      File clientSecretsJson) {
    Preconditions.checkNotNull(builder);
    Preconditions.checkNotNull(clientSecretsJson);
    return prepareBuilder(builder,
        CredentialFactory.getCredentialFromClientSecrets(clientSecretsJson.getAbsolutePath(),
            applicationName),
        null);
  }
1228897
@Override
    public <T> T runScript(final Reader reader, final String sourceName) throws IOException {
        return runWithContext(new RhinoCallable<T, IOException>() {
            @SuppressWarnings("unchecked")
            @Override
            protected T doCall(Context cx, Scriptable scope) throws IOException {
                Object val = cx.evaluateReader(scope, reader, sourceName, 1, null);
                val = unwrappedValue(val);
                return (T) val;
            }
        });
    }
805876
public Script getScript(int id) {
        PreparedStatement statement = null;
        ResultSet results = null;

        try (Connection sqlConnection = SQLService.getInstance().getConnection()) {
            statement = sqlConnection.prepareStatement(
                "SELECT * FROM " + Constants.DB_TABLE_SCRIPT +
                    " WHERE id = ?"
            );
            statement.setInt(1, id);
            results = statement.executeQuery();
            if (results.next()) {
                return scriptFromSQLResult(results);
            }
        } catch (Exception e) {

        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return null;
    }
858952
public JavaScriptActionBuilder javascript(String script) {
        JavaScriptAction action = new JavaScriptAction();
        action.setScript(script);
        action(action);
        return new JavaScriptActionBuilder(action);
    }
477431
public ExecuteSQLQueryBuilder validateScript(Resource scriptResource, String type, Charset charset) {
        ScriptValidationContext scriptValidationContext = new ScriptValidationContext(type);
        try {
            scriptValidationContext.setValidationScript(FileUtils.readToString(scriptResource, charset));
        } catch (IOException e) {
            throw new CitrusRuntimeException("Failed to read script resource", e);
        }
        action.setScriptValidationContext(scriptValidationContext);
        return this;
    }