Search in sources :

Example 31 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class DefaultScriptHandler method defineConfiguration.

private void defineConfiguration() {
    // Defer creation and resolution of configuration until required. Short-circuit when script does not require classpath
    if (configContainer == null) {
        configContainer = dependencyResolutionServices.getConfigurationContainer();
    }
    if (dependencyHandler == null) {
        dependencyHandler = dependencyResolutionServices.getDependencyHandler();
    }
    if (classpathConfiguration == null) {
        classpathConfiguration = configContainer.create(CLASSPATH_CONFIGURATION);
        // should ideally reuse the `JvmEcosystemUtilities` but this code is too low level
        // and this service is therefore not available!
        AttributeContainer attributes = classpathConfiguration.getAttributes();
        attributes.attribute(Usage.USAGE_ATTRIBUTE, instantiator.named(Usage.class, Usage.JAVA_RUNTIME));
        attributes.attribute(Category.CATEGORY_ATTRIBUTE, instantiator.named(Category.class, Category.LIBRARY));
        attributes.attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, instantiator.named(LibraryElements.class, LibraryElements.JAR));
        attributes.attribute(Bundling.BUNDLING_ATTRIBUTE, instantiator.named(Bundling.class, Bundling.EXTERNAL));
        attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, Integer.parseInt(JavaVersion.current().getMajorVersion()));
        attributes.attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, instantiator.named(GradlePluginApiVersion.class, GradleVersion.current().getVersion()));
        classpathConfiguration.getDependencyConstraints().add(dependencyHandler.getConstraints().create(Log4jBannedVersion.LOG4J2_CORE_COORDINATES, constraint -> constraint.version(version -> {
            version.require(Log4jBannedVersion.LOG4J2_CORE_REQUIRED_VERSION);
            version.reject(Log4jBannedVersion.LOG4J2_CORE_VULNERABLE_VERSION_RANGE);
        })));
    }
}
Also used : Bundling(org.gradle.api.attributes.Bundling) NamedObjectInstantiator(org.gradle.api.internal.model.NamedObjectInstantiator) RepositoryHandler(org.gradle.api.artifacts.dsl.RepositoryHandler) JavaEcosystemSupport(org.gradle.api.internal.artifacts.JavaEcosystemSupport) Category(org.gradle.api.attributes.Category) BeanDynamicObject(org.gradle.internal.metaobject.BeanDynamicObject) Closure(groovy.lang.Closure) DynamicObjectAware(org.gradle.api.internal.DynamicObjectAware) Logger(org.gradle.api.logging.Logger) LibraryElements(org.gradle.api.attributes.LibraryElements) Bundling(org.gradle.api.attributes.Bundling) ConfigureUtil(org.gradle.util.internal.ConfigureUtil) Configuration(org.gradle.api.artifacts.Configuration) TargetJvmVersion(org.gradle.api.attributes.java.TargetJvmVersion) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Log4jBannedVersion(org.gradle.internal.logging.util.Log4jBannedVersion) URI(java.net.URI) GradleVersion(org.gradle.util.GradleVersion) DependencyLockingHandler(org.gradle.api.artifacts.dsl.DependencyLockingHandler) Usage(org.gradle.api.attributes.Usage) GradlePluginApiVersion(org.gradle.api.attributes.plugin.GradlePluginApiVersion) JavaVersion(org.gradle.api.JavaVersion) File(java.io.File) DependencyResolutionServices(org.gradle.api.internal.artifacts.DependencyResolutionServices) ScriptSource(org.gradle.groovy.scripts.ScriptSource) ResourceLocation(org.gradle.internal.resource.ResourceLocation) Logging(org.gradle.api.logging.Logging) DynamicObject(org.gradle.internal.metaobject.DynamicObject) ClassPath(org.gradle.internal.classpath.ClassPath) ScriptHandler(org.gradle.api.initialization.dsl.ScriptHandler) ClasspathUtil(org.gradle.internal.classloader.ClasspathUtil) Usage(org.gradle.api.attributes.Usage) Category(org.gradle.api.attributes.Category) GradlePluginApiVersion(org.gradle.api.attributes.plugin.GradlePluginApiVersion) AttributeContainer(org.gradle.api.attributes.AttributeContainer) LibraryElements(org.gradle.api.attributes.LibraryElements)

Example 32 with ClassPath

use of org.gradle.internal.classpath.ClassPath in project gradle by gradle.

the class BuildTreePreparingProjectsPreparer method buildBuildSrcAndLockClassloader.

private void buildBuildSrcAndLockClassloader(GradleInternal gradle, ClassLoaderScope baseProjectClassLoaderScope) {
    ClassPath buildSrcClassPath = buildSourceBuilder.buildAndGetClassPath(gradle);
    baseProjectClassLoaderScope.export(buildSrcClassPath).lock();
}
Also used : ClassPath(org.gradle.internal.classpath.ClassPath)

Aggregations

ClassPath (org.gradle.internal.classpath.ClassPath)32 DefaultClassPath (org.gradle.internal.classpath.DefaultClassPath)13 File (java.io.File)10 IOException (java.io.IOException)6 VisitableURLClassLoader (org.gradle.internal.classloader.VisitableURLClassLoader)5 Method (java.lang.reflect.Method)3 URLClassLoader (java.net.URLClassLoader)3 ArrayList (java.util.ArrayList)3 UncheckedIOException (org.gradle.api.UncheckedIOException)3 DefaultModuleRegistry (org.gradle.api.internal.classpath.DefaultModuleRegistry)3 Module (org.gradle.api.internal.classpath.Module)3 StreamByteBuffer (org.gradle.internal.io.StreamByteBuffer)3 InputStream (java.io.InputStream)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 BuildActionParameters (org.gradle.launcher.exec.BuildActionParameters)2 DefaultBuildActionParameters (org.gradle.launcher.exec.DefaultBuildActionParameters)2 Lists (com.google.common.collect.Lists)1 Closure (groovy.lang.Closure)1