Search in sources :

Example 11 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class CompileGroovyScriptPluginsTask method compileScripts.

@TaskAction
void compileScripts() {
    ClassLoaderScope classLoaderScope = getClassLoaderScopeRegistry().getCoreAndPluginsScope();
    ClassLoader compileClassLoader = new URLClassLoader(DefaultClassPath.of(getClasspath()).getAsURLArray(), classLoaderScope.getLocalClassLoader());
    FileSystemOperations fileSystemOperations = getFileSystemOperations();
    fileSystemOperations.delete(spec -> spec.delete(intermediatePluginMetadataDirectory, intermediatePluginClassesDirectory));
    intermediatePluginMetadataDirectory.get().getAsFile().mkdirs();
    intermediatePluginClassesDirectory.get().getAsFile().mkdirs();
    // TODO: Use worker API?
    for (PrecompiledGroovyScript scriptPlugin : getScriptPlugins().get()) {
        compileBuildScript(scriptPlugin, compileClassLoader);
    }
    fileSystemOperations.sync(copySpec -> {
        copySpec.from(intermediatePluginClassesDirectory.get().getAsFileTree().getFiles());
        copySpec.into(getPrecompiledGroovyScriptsOutputDirectory());
    });
    ClassLoaderUtils.tryClose(compileClassLoader);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) FileSystemOperations(org.gradle.api.file.FileSystemOperations) TaskAction(org.gradle.api.tasks.TaskAction)

Example 12 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class DefaultPluginRequestApplicator method wrapInAlreadyInClasspathResolver.

private PluginResolver wrapInAlreadyInClasspathResolver(ClassLoaderScope classLoaderScope) {
    ClassLoaderScope parentLoaderScope = classLoaderScope.getParent();
    PluginDescriptorLocator scriptClasspathPluginDescriptorLocator = new ClassloaderBackedPluginDescriptorLocator(parentLoaderScope.getExportClassLoader());
    PluginResolver pluginResolver = pluginResolverFactory.create();
    return new AlreadyOnClasspathPluginResolver(pluginResolver, pluginRegistry, parentLoaderScope, scriptClasspathPluginDescriptorLocator, pluginInspector, pluginVersionTracker);
}
Also used : PluginDescriptorLocator(org.gradle.api.internal.plugins.PluginDescriptorLocator) ClassloaderBackedPluginDescriptorLocator(org.gradle.api.internal.plugins.ClassloaderBackedPluginDescriptorLocator) AlreadyOnClasspathPluginResolver(org.gradle.plugin.use.resolve.internal.AlreadyOnClasspathPluginResolver) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ClassloaderBackedPluginDescriptorLocator(org.gradle.api.internal.plugins.ClassloaderBackedPluginDescriptorLocator) PluginResolver(org.gradle.plugin.use.resolve.internal.PluginResolver) AlreadyOnClasspathPluginResolver(org.gradle.plugin.use.resolve.internal.AlreadyOnClasspathPluginResolver)

Example 13 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class DefaultSettingsLoader method findSettingsAndLoadIfAppropriate.

/**
 * Finds the settings.gradle for the given startParameter, and loads it if contains the project selected by the
 * startParameter, or if the startParameter explicitly specifies a settings script.  If the settings file is not
 * loaded (executed), then a null is returned.
 */
private SettingsInternal findSettingsAndLoadIfAppropriate(GradleInternal gradle, StartParameter startParameter) {
    SettingsLocation settingsLocation = findSettings(startParameter);
    // We found the desired settings file, now build the associated buildSrc before loading settings.  This allows
    // the settings script to reference classes in the buildSrc.
    ClassLoaderScope buildSourceClassLoaderScope = buildSourceBuilder.buildAndCreateClassLoader(gradle, settingsLocation.getSettingsDir(), startParameter);
    return settingsProcessor.process(gradle, settingsLocation, buildSourceClassLoaderScope, startParameter);
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope)

Example 14 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class PluginVersionTracker method findPluginVersionAt.

@Nullable
public String findPluginVersionAt(ClassLoaderScope scope, String pluginId) {
    while (scope != null) {
        String pluginVersion = pluginVersionsPerScope.getOrDefault(scope, emptyMap()).get(pluginId);
        if (pluginVersion != null) {
            return pluginVersion;
        }
        ClassLoaderScope parent = scope.getParent();
        if (scope == parent) {
            // See RootClassLoaderScope#getParent()
            break;
        }
        scope = parent;
    }
    return null;
}
Also used : ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) Nullable(javax.annotation.Nullable)

Example 15 with ClassLoaderScope

use of org.gradle.api.internal.initialization.ClassLoaderScope in project gradle by gradle.

the class SettingsFactory method createSettings.

public SettingsInternal createSettings(GradleInternal gradle, File settingsDir, ScriptSource settingsScript, GradleProperties gradleProperties, StartParameter startParameter, ClassLoaderScope baseClassLoaderScope) {
    ClassLoaderScope classLoaderScope = baseClassLoaderScope.createChild("settings[" + gradle.getIdentityPath() + "]");
    DefaultSettings settings = instantiator.newInstance(DefaultSettings.class, serviceRegistryFactory, gradle, classLoaderScope, baseClassLoaderScope, scriptHandlerFactory.create(settingsScript, classLoaderScope), settingsDir, settingsScript, startParameter);
    Map<String, Object> properties = gradleProperties.mergeProperties(emptyMap());
    DynamicObject dynamicObject = ((DynamicObjectAware) settings).getAsDynamicObject();
    ((ExtensibleDynamicObject) dynamicObject).addProperties(properties);
    return settings;
}
Also used : DynamicObject(org.gradle.internal.metaobject.DynamicObject) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) ClassLoaderScope(org.gradle.api.internal.initialization.ClassLoaderScope) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) DynamicObject(org.gradle.internal.metaobject.DynamicObject) ExtensibleDynamicObject(org.gradle.internal.extensibility.ExtensibleDynamicObject) DynamicObjectAware(org.gradle.api.internal.DynamicObjectAware)

Aggregations

ClassLoaderScope (org.gradle.api.internal.initialization.ClassLoaderScope)18 File (java.io.File)4 URI (java.net.URI)2 Nullable (javax.annotation.Nullable)2 ScriptHandler (org.gradle.api.initialization.dsl.ScriptHandler)2 DynamicObjectAware (org.gradle.api.internal.DynamicObjectAware)2 SettingsInternal (org.gradle.api.internal.SettingsInternal)2 ProjectInternal (org.gradle.api.internal.project.ProjectInternal)2 ProjectState (org.gradle.api.internal.project.ProjectState)2 ScriptPlugin (org.gradle.configuration.ScriptPlugin)2 ScriptSource (org.gradle.groovy.scripts.ScriptSource)2 ClassPath (org.gradle.internal.classpath.ClassPath)2 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 StringWriter (java.io.StringWriter)1 URLClassLoader (java.net.URLClassLoader)1 Collections (java.util.Collections)1