org.gradle.api.initialization.dsl.ScriptHandler Java Examples

The following examples show how to use org.gradle.api.initialization.dsl.ScriptHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultScriptHandlerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope, DomainObjectContext context) {
    DependencyResolutionServices services = dependencyManagementServices.create(fileResolver, dependencyMetaDataProvider, projectFinder, context);
    RepositoryHandler repositoryHandler = services.getResolveRepositoryHandler();
    ConfigurationContainer configurationContainer = services.getConfigurationContainer();
    DependencyHandler dependencyHandler = services.getDependencyHandler();
    return new DefaultScriptHandler(scriptSource, repositoryHandler, dependencyHandler, configurationContainer, new ScriptHandlerClassLoaderFactory(scriptSource, classLoaderScope));
}
 
Example #2
Source File: DefaultScriptPluginFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptPluginImpl(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope classLoaderScope, String classpathClosureName, Class<? extends BasicScript> scriptType) {
    this.scriptSource = scriptSource;
    this.classLoaderScope = classLoaderScope;
    this.classpathClosureName = classpathClosureName;
    this.scriptHandler = scriptHandler;
    this.scriptType = scriptType;
}
 
Example #3
Source File: DefaultInitScriptProcessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void process(final ScriptSource initScript, GradleInternal gradle) {
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope scriptScope = baseScope.createChild();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(initScript, scriptScope);
    ScriptPlugin configurer = configurerFactory.create(initScript, scriptHandler, scriptScope, baseScope, "initscript", InitScript.class, false);
    configurer.apply(gradle);
}
 
Example #4
Source File: ProjectScopeServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ScriptHandler createScriptHandler() {
    ScriptHandlerFactory factory = new DefaultScriptHandlerFactory(
            get(DependencyManagementServices.class),
            get(FileResolver.class),
            get(DependencyMetaDataProvider.class));
    return factory.create(project.getBuildScriptSource(), project.getClassLoaderScope(), project);
}
 
Example #5
Source File: DefaultScriptPluginFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptPluginImpl(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope targetScope, ClassLoaderScope baseScope, String classpathClosureName, Class<? extends BasicScript> scriptType, boolean ownerScript) {
    this.scriptSource = scriptSource;
    this.targetScope = targetScope;
    this.baseScope = baseScope;
    this.classpathClosureName = classpathClosureName;
    this.scriptHandler = scriptHandler;
    this.scriptType = scriptType;
    this.ownerScript = ownerScript;
}
 
Example #6
Source File: DefaultScriptHandlerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope, DomainObjectContext context) {
    DependencyResolutionServices services = dependencyManagementServices.create(fileResolver, dependencyMetaDataProvider, projectFinder, context);
    RepositoryHandler repositoryHandler = services.getResolveRepositoryHandler();
    ConfigurationContainer configurationContainer = services.getConfigurationContainer();
    DependencyHandler dependencyHandler = services.getDependencyHandler();
    return new DefaultScriptHandler(scriptSource, repositoryHandler, dependencyHandler, configurationContainer, new ScriptHandlerClassLoaderFactory(scriptSource, classLoaderScope));
}
 
Example #7
Source File: DefaultObjectConfigurationAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    UriScriptSource scriptSource = new UriScriptSource("script", scriptUri);
    ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScopeChild);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScopeChild, classLoaderScope, "buildscript", DefaultScript.class, false);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
 
Example #8
Source File: ScriptEvaluatingSettingsProcessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applySettingsScript(SettingsLocation settingsLocation, final SettingsInternal settings) {
    ScriptSource settingsScriptSource = settingsLocation.getSettingsScriptSource();
    ClassLoaderScope settingsClassLoaderScope = settings.getClassLoaderScope();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(settingsScriptSource, settingsClassLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(settingsScriptSource, scriptHandler, settingsClassLoaderScope, settings.getRootClassLoaderScope(), "buildscript", SettingsScript.class, false);
    configurer.apply(settings);
}
 
Example #9
Source File: DefaultScriptHandlerFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope, DomainObjectContext context) {
    DependencyResolutionServices services = dependencyManagementServices.create(fileResolver, dependencyMetaDataProvider, projectFinder, context);
    RepositoryHandler repositoryHandler = services.getResolveRepositoryHandler();
    ConfigurationContainer configurationContainer = services.getConfigurationContainer();
    DependencyHandler dependencyHandler = services.getDependencyHandler();
    return new DefaultScriptHandler(scriptSource, repositoryHandler, dependencyHandler, configurationContainer, new ScriptHandlerClassLoaderFactory(scriptSource, classLoaderScope));
}
 
Example #10
Source File: ProjectScopeServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ScriptHandler createScriptHandler() {
    ScriptHandlerFactory factory = new DefaultScriptHandlerFactory(
            get(DependencyManagementServices.class),
            get(FileResolver.class),
            get(DependencyMetaDataProvider.class));
    return factory.create(project.getBuildScriptSource(), project.getClassLoaderScope(), project);
}
 
Example #11
Source File: DefaultObjectConfigurationAction.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    UriScriptSource scriptSource = new UriScriptSource("script", scriptUri);
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScope, "buildscript", DefaultScript.class);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
 
Example #12
Source File: ScriptEvaluatingSettingsProcessor.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applySettingsScript(SettingsLocation settingsLocation, final SettingsInternal settings) {
    ScriptSource settingsScriptSource = settingsLocation.getSettingsScriptSource();
    ClassLoaderScope classLoaderScope = settings.getClassLoaderScope();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(settingsScriptSource, classLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(settingsScriptSource, scriptHandler, classLoaderScope, "buildscript", SettingsScript.class);
    configurer.apply(settings);
}
 
Example #13
Source File: DefaultScriptPluginFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptPluginImpl(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope classLoaderScope, String classpathClosureName, Class<? extends BasicScript> scriptType) {
    this.scriptSource = scriptSource;
    this.classLoaderScope = classLoaderScope;
    this.classpathClosureName = classpathClosureName;
    this.scriptHandler = scriptHandler;
    this.scriptType = scriptType;
}
 
Example #14
Source File: DefaultPluginRequestApplicator.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void defineScriptHandlerClassScope(ScriptHandler scriptHandler, ClassLoaderScope classLoaderScope) {
    Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
    Set<File> files = classpathConfiguration.getFiles();
    ClassPath classPath = new DefaultClassPath(files);
    classLoaderScope.export(classPath);
    classLoaderScope.lock();
}
 
Example #15
Source File: ScriptEvaluatingSettingsProcessor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applySettingsScript(SettingsLocation settingsLocation, final SettingsInternal settings) {
    ScriptSource settingsScriptSource = settingsLocation.getSettingsScriptSource();
    ClassLoaderScope classLoaderScope = settings.getClassLoaderScope();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(settingsScriptSource, classLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(settingsScriptSource, scriptHandler, classLoaderScope, "buildscript", SettingsScript.class);
    configurer.apply(settings);
}
 
Example #16
Source File: DefaultScriptHandlerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope, DomainObjectContext context) {
    DependencyResolutionServices services = dependencyManagementServices.create(fileResolver, dependencyMetaDataProvider, projectFinder, context);
    RepositoryHandler repositoryHandler = services.getResolveRepositoryHandler();
    ConfigurationContainer configurationContainer = services.getConfigurationContainer();
    DependencyHandler dependencyHandler = services.getDependencyHandler();
    return new DefaultScriptHandler(scriptSource, repositoryHandler, dependencyHandler, configurationContainer, new ScriptHandlerClassLoaderFactory(scriptSource, classLoaderScope));
}
 
Example #17
Source File: ProjectScopeServices.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ScriptHandler createScriptHandler() {
    ScriptHandlerFactory factory = new DefaultScriptHandlerFactory(
            get(DependencyManagementServices.class),
            get(FileResolver.class),
            get(DependencyMetaDataProvider.class));
    return factory.create(project.getBuildScriptSource(), project.getClassLoaderScope(), project);
}
 
Example #18
Source File: DefaultObjectConfigurationAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    UriScriptSource scriptSource = new UriScriptSource("script", scriptUri);
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScope, "buildscript", DefaultScript.class);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
 
Example #19
Source File: DefaultObjectConfigurationAction.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applyScript(Object script) {
    URI scriptUri = resolver.resolveUri(script);
    UriScriptSource scriptSource = new UriScriptSource("script", scriptUri);
    ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScopeChild);
    ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScopeChild, classLoaderScope, "buildscript", DefaultScript.class, false);
    for (Object target : targets) {
        configurer.apply(target);
    }
}
 
Example #20
Source File: DefaultPluginRequestApplicator.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void defineScriptHandlerClassScope(ScriptHandler scriptHandler, ClassLoaderScope classLoaderScope) {
    Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
    Set<File> files = classpathConfiguration.getFiles();
    ClassPath classPath = new DefaultClassPath(files);
    classLoaderScope.export(classPath);
    classLoaderScope.lock();
}
 
Example #21
Source File: ScriptEvaluatingSettingsProcessor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void applySettingsScript(SettingsLocation settingsLocation, final SettingsInternal settings) {
    ScriptSource settingsScriptSource = settingsLocation.getSettingsScriptSource();
    ClassLoaderScope settingsClassLoaderScope = settings.getClassLoaderScope();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(settingsScriptSource, settingsClassLoaderScope);
    ScriptPlugin configurer = configurerFactory.create(settingsScriptSource, scriptHandler, settingsClassLoaderScope, settings.getRootClassLoaderScope(), "buildscript", SettingsScript.class, false);
    configurer.apply(settings);
}
 
Example #22
Source File: DefaultScriptPluginFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ScriptPluginImpl(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope targetScope, ClassLoaderScope baseScope, String classpathClosureName, Class<? extends BasicScript> scriptType, boolean ownerScript) {
    this.scriptSource = scriptSource;
    this.targetScope = targetScope;
    this.baseScope = baseScope;
    this.classpathClosureName = classpathClosureName;
    this.scriptHandler = scriptHandler;
    this.scriptType = scriptType;
    this.ownerScript = ownerScript;
}
 
Example #23
Source File: ProjectScopeServices.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected ScriptHandler createScriptHandler() {
    ScriptHandlerFactory factory = new DefaultScriptHandlerFactory(
            get(DependencyManagementServices.class),
            get(FileResolver.class),
            get(DependencyMetaDataProvider.class));
    return factory.create(project.getBuildScriptSource(), project.getClassLoaderScope(), project);
}
 
Example #24
Source File: DefaultInitScriptProcessor.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void process(final ScriptSource initScript, GradleInternal gradle) {
    ClassLoaderScope baseScope = gradle.getClassLoaderScope();
    ClassLoaderScope scriptScope = baseScope.createChild();
    ScriptHandler scriptHandler = scriptHandlerFactory.create(initScript, scriptScope);
    ScriptPlugin configurer = configurerFactory.create(initScript, scriptHandler, scriptScope, baseScope, "initscript", InitScript.class, false);
    configurer.apply(gradle);
}
 
Example #25
Source File: DefaultScriptPluginFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ScriptPlugin create(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope targetScope, ClassLoaderScope baseScope, String classpathClosureName, Class<? extends BasicScript> scriptClass, boolean ownerScript) {
    return new ScriptPluginImpl(scriptSource, scriptHandler, targetScope, baseScope, classpathClosureName, scriptClass, ownerScript);
}
 
Example #26
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ScriptHandler getBuildscript() {
    return __scriptServices.get(ScriptHandler.class);
}
 
Example #27
Source File: DefaultScriptHandlerFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope) {
    return create(scriptSource, classLoaderScope, new BasicDomainObjectContext());
}
 
Example #28
Source File: AbstractProject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Inject
public ScriptHandler getBuildscript() {
    // Decoration takes care of the implementation
    throw new UnsupportedOperationException();
}
 
Example #29
Source File: AbstractProject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public ScriptHandler getBuildscript() {
    return scriptHandler;
}
 
Example #30
Source File: DefaultScriptPluginFactory.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void apply(final Object target) {
    DefaultServiceRegistry services = new DefaultServiceRegistry();
    services.add(ScriptPluginFactory.class, DefaultScriptPluginFactory.this);
    services.add(ScriptHandlerFactory.class, scriptHandlerFactory);
    services.add(ClassLoaderScope.class, classLoaderScope);
    services.add(LoggingManagerInternal.class, loggingManagerFactory.create());
    services.add(Instantiator.class, instantiator);
    services.add(ScriptHandler.class, scriptHandler);
    services.add(FileLookup.class, fileLookup);

    ScriptSource withImports = importsReader.withImports(scriptSource);

    List<PluginRequest> pluginRequests = new LinkedList<PluginRequest>();
    if (target instanceof PluginAware) {
        services.add(PluginHandler.class, new DefaultPluginHandler(pluginRequests));
    } else {
        services.add(PluginHandler.class, new NonPluggableTargetPluginHandler(target));
    }

    ScriptCompiler compiler = scriptCompilerFactory.createCompiler(withImports);
    compiler.setClassloader(classLoaderScope.getBase().getChildClassLoader());

    PluginsAndBuildscriptTransformer scriptBlockTransformer = new PluginsAndBuildscriptTransformer(classpathClosureName);

    StatementExtractingScriptTransformer classpathScriptTransformer = new StatementExtractingScriptTransformer(classpathClosureName, scriptBlockTransformer);

    compiler.setTransformer(classpathScriptTransformer);

    ScriptRunner<? extends BasicScript> classPathScriptRunner = compiler.compile(scriptType);
    classPathScriptRunner.getScript().init(target, services);
    classPathScriptRunner.run();

    Configuration classpathConfiguration = scriptHandler.getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION);
    Set<File> files = classpathConfiguration.getFiles();
    ClassPath classPath = new DefaultClassPath(files);

    ClassLoader exportedClassLoader = classLoaderScope.export(classPath);

    if (!pluginRequests.isEmpty()) {
        PluginResolver pluginResolver = pluginResolverFactory.createPluginResolver(exportedClassLoader);
        @SuppressWarnings("ConstantConditions")
        PluginResolutionApplicator resolutionApplicator = new PluginResolutionApplicator((PluginAware) target, classLoaderScope);
        PluginRequestApplicator requestApplicator = new PluginRequestApplicator(pluginResolver, resolutionApplicator);
        requestApplicator.applyPlugin(pluginRequests);
    }

    classLoaderScope.lock();

    compiler.setClassloader(classLoaderScope.getScopeClassLoader());

    compiler.setTransformer(new BuildScriptTransformer("no_" + classpathScriptTransformer.getId(), classpathScriptTransformer.invert()));
    ScriptRunner<? extends BasicScript> runner = compiler.compile(scriptType);

    BasicScript script = runner.getScript();
    script.init(target, services);
    if (target instanceof ScriptAware) {
        ((ScriptAware) target).setScript(script);
    }
    runner.run();
}