org.gradle.internal.classpath.ClassPath Java Examples

The following examples show how to use org.gradle.internal.classpath.ClassPath. 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: BuildSourceBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
ClassPath createBuildSourceClasspath(StartParameter startParameter) {
    assert startParameter.getCurrentDir() != null && startParameter.getBuildFile() == null;

    LOGGER.debug("Starting to build the build sources.");
    if (!startParameter.getCurrentDir().isDirectory()) {
        LOGGER.debug("Gradle source dir does not exist. We leave.");
        return new DefaultClassPath();
    }
    LOGGER.info("================================================" + " Start building buildSrc");

    // If we were not the most recent version of Gradle to build the buildSrc dir, then do a clean build
    // Otherwise, just to a regular build
    final PersistentCache buildSrcCache = createCache(startParameter);
    try {
        GradleLauncher gradleLauncher = buildGradleLauncher(startParameter);
        try {
            return buildSrcCache.useCache("rebuild buildSrc", new BuildSrcUpdateFactory(buildSrcCache, gradleLauncher, new BuildSrcBuildListenerFactory()));
        } finally {
            gradleLauncher.stop();
        }
    } finally {
        // This isn't quite right. We should not unlock the classes until we're finished with them, and the classes may be used across multiple builds
        buildSrcCache.close();
    }
}
 
Example #2
Source File: DistributionFactory.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ClassPath getToolingImpl() {
    if (!gradleHomeDir.exists()) {
        throw new IllegalArgumentException(String.format("The specified %s does not exist.", locationDisplayName));
    }
    if (!gradleHomeDir.isDirectory()) {
        throw new IllegalArgumentException(String.format("The specified %s is not a directory.", locationDisplayName));
    }
    File libDir = new File(gradleHomeDir, "lib");
    if (!libDir.isDirectory()) {
        throw new IllegalArgumentException(String.format("The specified %s does not appear to contain a Gradle distribution.", locationDisplayName));
    }
    Set<File> files = new LinkedHashSet<File>();
    for (File file : libDir.listFiles()) {
        if (file.getName().endsWith(".jar")) {
            files.add(file);
        }
    }
    return new DefaultClassPath(files);
}
 
Example #3
Source File: PluginResolutionServiceResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private ClassPath resolvePluginDependencies(final PluginUseMetaData metadata) {
    DependencyResolutionServices resolution = dependencyResolutionServicesFactory.create();

    RepositoryHandler repositories = resolution.getResolveRepositoryHandler();
    final String repoUrl = metadata.implementation.get("repo");
    repositories.maven(new Action<MavenArtifactRepository>() {
        public void execute(MavenArtifactRepository mavenArtifactRepository) {
            mavenArtifactRepository.setUrl(repoUrl);
        }
    });

    Dependency dependency = resolution.getDependencyHandler().create(metadata.implementation.get("gav"));

    ConfigurationContainerInternal configurations = (ConfigurationContainerInternal) resolution.getConfigurationContainer();
    ConfigurationInternal configuration = configurations.detachedConfiguration(dependency);

    try {
        Set<File> files = configuration.getResolvedConfiguration().getFiles(Specs.satisfyAll());
        return new DefaultClassPath(files);
    } catch (ResolveException e) {
        throw new DependencyResolutionException("Failed to resolve all plugin dependencies from " + repoUrl, e.getCause());
    }
}
 
Example #4
Source File: DefaultClassLoaderScope.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ClassLoader export(ClassPath classpath) {
    if (locked) {
        throw new IllegalStateException("class loader scope is locked");
    }
    if (classpath.isEmpty()) {
        return parent.getChildClassLoader();
    } else {
        if (exportingClassLoader == null) {
            exportingClassLoader = new MultiParentClassLoader();
        }

        ClassLoader classLoader = classLoaderCache.get(parent.getChildClassLoader(), classpath, null);
        exportingClassLoader.addParent(classLoader);
        return classLoader;
    }
}
 
Example #5
Source File: DynamicModulesClassPathProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ClassPath findClassPath(String name) {
    if (name.equals("GRADLE_EXTENSIONS")) {
        Set<Module> coreModules = moduleRegistry.getModule("gradle-core").getAllRequiredModules();
        ClassPath classpath = new DefaultClassPath();
        for (String moduleName : Arrays.asList("gradle-dependency-management", "gradle-plugin-use")) {
            for (Module module : moduleRegistry.getModule(moduleName).getAllRequiredModules()) {
                if (!coreModules.contains(module)) {
                    classpath = classpath.plus(module.getClasspath());
                }
            }
        }
        for (Module pluginModule : pluginModuleRegistry.getPluginModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        return classpath;
    }

    return null;
}
 
Example #6
Source File: BuildSourceBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
ClassPath createBuildSourceClasspath(StartParameter startParameter) {
    assert startParameter.getCurrentDir() != null && startParameter.getBuildFile() == null;

    LOGGER.debug("Starting to build the build sources.");
    if (!startParameter.getCurrentDir().isDirectory()) {
        LOGGER.debug("Gradle source dir does not exist. We leave.");
        return new DefaultClassPath();
    }
    LOGGER.info("================================================" + " Start building buildSrc");

    // If we were not the most recent version of Gradle to build the buildSrc dir, then do a clean build
    // Otherwise, just to a regular build
    final PersistentCache buildSrcCache = createCache(startParameter);
    try {
        GradleLauncher gradleLauncher = buildGradleLauncher(startParameter);
        return buildSrcCache.useCache("rebuild buildSrc", new BuildSrcUpdateFactory(buildSrcCache, gradleLauncher, new BuildSrcBuildListenerFactory()));
    } finally {
        // This isn't quite right. We should not unlock the classes until we're finished with them, and the classes may be used across multiple builds
        buildSrcCache.close();
    }
}
 
Example #7
Source File: BuildSourceBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
ClassPath createBuildSourceClasspath(StartParameter startParameter) {
    assert startParameter.getCurrentDir() != null && startParameter.getBuildFile() == null;

    LOGGER.debug("Starting to build the build sources.");
    if (!startParameter.getCurrentDir().isDirectory()) {
        LOGGER.debug("Gradle source dir does not exist. We leave.");
        return new DefaultClassPath();
    }
    LOGGER.info("================================================" + " Start building buildSrc");

    // If we were not the most recent version of Gradle to build the buildSrc dir, then do a clean build
    // Otherwise, just to a regular build
    final PersistentCache buildSrcCache = createCache(startParameter);
    try {
        GradleLauncher gradleLauncher = buildGradleLauncher(startParameter);
        try {
            return buildSrcCache.useCache("rebuild buildSrc", new BuildSrcUpdateFactory(buildSrcCache, gradleLauncher, new BuildSrcBuildListenerFactory()));
        } finally {
            gradleLauncher.stop();
        }
    } finally {
        // This isn't quite right. We should not unlock the classes until we're finished with them, and the classes may be used across multiple builds
        buildSrcCache.close();
    }
}
 
Example #8
Source File: DynamicModulesClassPathProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ClassPath findClassPath(String name) {
    if (name.equals("GRADLE_EXTENSIONS")) {
        Set<Module> coreModules = moduleRegistry.getModule("gradle-core").getAllRequiredModules();
        ClassPath classpath = new DefaultClassPath();
        for (String moduleName : Arrays.asList("gradle-dependency-management", "gradle-plugin-use")) {
            for (Module module : moduleRegistry.getModule(moduleName).getAllRequiredModules()) {
                if (!coreModules.contains(module)) {
                    classpath = classpath.plus(module.getClasspath());
                }
            }
        }
        for (Module pluginModule : pluginModuleRegistry.getPluginModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        return classpath;
    }

    return null;
}
 
Example #9
Source File: DependencyClassPathProvider.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ClassPath findClassPath(String name) {
    if (name.equals(GRADLE_API.name())) {
        ClassPath classpath = new DefaultClassPath();
        for (String moduleName : Arrays.asList("gradle-core", "gradle-dependency-management", "gradle-plugin-use", "gradle-tooling-api")) {
            for (Module module : moduleRegistry.getModule(moduleName).getAllRequiredModules()) {
                classpath = classpath.plus(module.getClasspath());
            }
        }
        for (Module pluginModule : pluginModuleRegistry.getPluginModules()) {
            classpath = classpath.plus(pluginModule.getClasspath());
        }
        return classpath;
    }
    if (name.equals(LOCAL_GROOVY.name())) {
        return moduleRegistry.getExternalModule("groovy-all").getClasspath();
    }

    return null;
}
 
Example #10
Source File: DefaultClassLoaderScope.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader buildLockedLoader(List<ClassPath> classPaths) {
    if (classPaths.isEmpty()) {
        return parent.getExportClassLoader();
    }
    if (classPaths.size() == 1) {
        return loader(classPaths.get(0));
    }

    List<ClassLoader> loaders = new ArrayList<ClassLoader>(classPaths.size());
    for (ClassPath classPath : classPaths) {
        loaders.add(loader(classPath));
    }
    return new CachingClassLoader(new MultiParentClassLoader(loaders));
}
 
Example #11
Source File: PluginResolutionServiceResolver.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void resolve(PluginRequest pluginRequest, PluginResolutionResult result) throws InvalidPluginRequestException {
    if (pluginRequest.getVersion() == null) {
        result.notFound(getDescription(), "plugin dependency must include a version number for this source");
    } else {
        if (pluginRequest.getVersion().endsWith("-SNAPSHOT")) {
            result.notFound(getDescription(), "snapshot plugin versions are not supported");
        } else if (isDynamicVersion(pluginRequest.getVersion())) {
            result.notFound(getDescription(), "dynamic plugin versions are not supported");
        } else {
            HttpPluginResolutionServiceClient.Response<PluginUseMetaData> response = portalClient.queryPluginMetadata(getUrl(), startParameter.isRefreshDependencies(), pluginRequest);
            if (response.isError()) {
                ErrorResponse errorResponse = response.getErrorResponse();
                if (response.getStatusCode() == 404) {
                    result.notFound(getDescription(), errorResponse.message);
                } else {
                    throw new GradleException(String.format("Plugin resolution service returned HTTP %d with message '%s' (url: %s)", response.getStatusCode(), errorResponse.message, response.getUrl()));
                }
            } else {
                PluginUseMetaData metaData = response.getResponse();
                if (metaData.legacy) {
                    handleLegacy(metaData, result);
                } else {
                    ClassPath classPath = resolvePluginDependencies(metaData);
                    PluginResolution resolution = new ClassPathPluginResolution(instantiator, pluginRequest.getId(), parentScope, Factories.constant(classPath));
                    result.found(getDescription(), resolution);
                }
            }
        }
    }
}
 
Example #12
Source File: BuildSourceBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassLoaderScope buildAndCreateClassLoader(StartParameter startParameter) {
    ClassPath classpath = createBuildSourceClasspath(startParameter);
    ClassLoaderScope childScope = classLoaderScope.createChild();
    childScope.export(classpath);
    childScope.lock();
    return childScope;
}
 
Example #13
Source File: DefaultToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, File userHomeDir) {
    ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, userHomeDir);
    LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
    // On IBM JVM 5, ClassLoader.getResources() uses a combination of findResources() and getParent() and traverses the hierarchy rather than just calling getResources()
    // Wrap our real classloader in one that hides the parent.
    // TODO - move this into FilteringClassLoader
    MultiParentClassLoader parentObfuscatingClassLoader = new MultiParentClassLoader(classLoader);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(parentObfuscatingClassLoader);
    filteringClassLoader.allowPackage("org.gradle.tooling.internal.protocol");
    return new MutableURLClassLoader(filteringClassLoader, implementationClasspath.getAsURLArray());
}
 
Example #14
Source File: DefaultClassPathRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassPath getClassPath(String name) {
    for (ClassPathProvider provider : providers) {
        ClassPath classpath = provider.findClassPath(name);
        if (classpath != null) {
            return classpath;
        }
    }
    throw new IllegalArgumentException(String.format("unknown classpath '%s' requested.", name));
}
 
Example #15
Source File: ProcessBootstrap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void runNoExit(String mainClassName, String[] args) throws Exception {
    ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry(new DefaultClassPathProvider(new DefaultModuleRegistry()));
    ClassLoaderFactory classLoaderFactory = new DefaultClassLoaderFactory();
    ClassPath antClasspath = classPathRegistry.getClassPath("ANT");
    ClassPath runtimeClasspath = classPathRegistry.getClassPath("GRADLE_RUNTIME");
    ClassLoader antClassLoader = classLoaderFactory.createIsolatedClassLoader(antClasspath);
    ClassLoader runtimeClassLoader = new MutableURLClassLoader(antClassLoader, runtimeClasspath);
    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
    Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
    Object entryPoint = mainClass.newInstance();
    Method mainMethod = mainClass.getMethod("run", String[].class);
    mainMethod.invoke(entryPoint, new Object[]{args});
}
 
Example #16
Source File: DefaultClassLoaderScope.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader buildLockedLoader(List<ClassPath> classPaths) {
    if (classPaths.isEmpty()) {
        return parent.getExportClassLoader();
    }
    if (classPaths.size() == 1) {
        return loader(classPaths.get(0));
    }

    List<ClassLoader> loaders = new ArrayList<ClassLoader>(classPaths.size());
    for (ClassPath classPath : classPaths) {
        loaders.add(loader(classPath));
    }
    return new CachingClassLoader(new MultiParentClassLoader(loaders));
}
 
Example #17
Source File: ClassPathPluginResolution.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Class<? extends Plugin> resolve() {
    ClassPath classPath = classPathFactory.create();
    ClassLoaderScope loaderScope = parent.createChild();
    loaderScope.local(classPath);
    loaderScope.lock();
    PluginRegistry pluginRegistry = new DefaultPluginRegistry(loaderScope.getLocalClassLoader(), instantiator);
    return pluginRegistry.getTypeForId(pluginId.toString());
}
 
Example #18
Source File: DefaultClassLoaderRegistry.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultClassLoaderRegistry(ClassPathRegistry classPathRegistry, ClassLoaderFactory classLoaderFactory) {
    ClassLoader runtimeClassLoader = getClass().getClassLoader();

    // Core impl
    ClassPath coreImplClassPath = classPathRegistry.getClassPath("GRADLE_CORE_IMPL");
    coreImplClassLoader = new MutableURLClassLoader(runtimeClassLoader, coreImplClassPath);

    // Add in libs for plugins
    ClassPath pluginsClassPath = classPathRegistry.getClassPath("GRADLE_PLUGINS");
    ClassLoader pluginsImports = new CachingClassLoader(new MultiParentClassLoader(runtimeClassLoader, coreImplClassLoader));
    pluginsClassLoader = new MutableURLClassLoader(pluginsImports, pluginsClassPath);

    FilteringClassLoader rootClassLoader = classLoaderFactory.createFilteringClassLoader(pluginsClassLoader);
    rootClassLoader.allowPackage("org.gradle");
    rootClassLoader.allowResources("META-INF/gradle-plugins");
    rootClassLoader.allowPackage("org.apache.tools.ant");
    rootClassLoader.allowPackage("groovy");
    rootClassLoader.allowPackage("org.codehaus.groovy");
    rootClassLoader.allowPackage("groovyjarjarantlr");
    rootClassLoader.allowPackage("org.apache.ivy");
    rootClassLoader.allowPackage("org.slf4j");
    rootClassLoader.allowPackage("org.apache.commons.logging");
    rootClassLoader.allowPackage("org.apache.log4j");
    rootClassLoader.allowPackage("javax.inject");

    this.rootClassLoader = new CachingClassLoader(rootClassLoader);
}
 
Example #19
Source File: ProcessBootstrap.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void runNoExit(String mainClassName, String[] args) throws Exception {
    ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry(new DefaultClassPathProvider(new DefaultModuleRegistry()));
    ClassLoaderFactory classLoaderFactory = new DefaultClassLoaderFactory();
    ClassPath antClasspath = classPathRegistry.getClassPath("ANT");
    ClassPath runtimeClasspath = classPathRegistry.getClassPath("GRADLE_RUNTIME");
    ClassLoader antClassLoader = classLoaderFactory.createIsolatedClassLoader(antClasspath);
    ClassLoader runtimeClassLoader = new MutableURLClassLoader(antClassLoader, runtimeClasspath);
    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
    Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
    Method mainMethod = mainClass.getMethod("main", String[].class);
    mainMethod.invoke(null, new Object[]{args});
}
 
Example #20
Source File: DefaultToolingImplementationLoader.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, File userHomeDir) {
    ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, userHomeDir);
    LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
    // On IBM JVM 5, ClassLoader.getResources() uses a combination of findResources() and getParent() and traverses the hierarchy rather than just calling getResources()
    // Wrap our real classloader in one that hides the parent.
    // TODO - move this into FilteringClassLoader
    MultiParentClassLoader parentObfuscatingClassLoader = new MultiParentClassLoader(classLoader);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(parentObfuscatingClassLoader);
    filteringClassLoader.allowPackage("org.gradle.tooling.internal.protocol");
    return new MutableURLClassLoader(filteringClassLoader, implementationClasspath.getAsURLArray());
}
 
Example #21
Source File: CachingToolingImplementationLoader.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters) {
    ClassPath classpath = distribution.getToolingImplementationClasspath(progressLoggerFactory, connectionParameters.getGradleUserHomeDir());

    ConsumerConnection connection = connections.get(classpath);
    if (connection == null) {
        connection = loader.create(distribution, progressLoggerFactory, connectionParameters);
        connections.put(classpath, connection);
    }

    return connection;
}
 
Example #22
Source File: DefaultClassLoaderScope.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader buildLockedLoader(ClassLoader additional, List<ClassPath> classPaths) {
    if (classPaths.isEmpty()) {
        return additional;
    }

    List<ClassLoader> loaders = new ArrayList<ClassLoader>(classPaths.size() + 1);
    loaders.add(additional);
    for (ClassPath classPath : classPaths) {
        loaders.add(loader(classPath));
    }
    return new CachingClassLoader(new MultiParentClassLoader(loaders));
}
 
Example #23
Source File: BuildSourceBuilder.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassLoaderScope buildAndCreateClassLoader(StartParameter startParameter) {
    ClassPath classpath = createBuildSourceClasspath(startParameter);
    if (classpath.isEmpty()) {
        return classLoaderScope;
    } else {
        ClassLoaderScope childScope = classLoaderScope.createChild();
        childScope.export(classpath);
        childScope.lock();
        return childScope;
    }
}
 
Example #24
Source File: DefaultToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private ClassLoader createImplementationClassLoader(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, File userHomeDir, BuildCancellationToken cancellationToken) {
    ClassPath implementationClasspath = distribution.getToolingImplementationClasspath(progressLoggerFactory, userHomeDir, cancellationToken);
    LOGGER.debug("Using tooling provider classpath: {}", implementationClasspath);
    // On IBM JVM 5, ClassLoader.getResources() uses a combination of findResources() and getParent() and traverses the hierarchy rather than just calling getResources()
    // Wrap our real classloader in one that hides the parent.
    // TODO - move this into FilteringClassLoader
    MultiParentClassLoader parentObfuscatingClassLoader = new MultiParentClassLoader(classLoader);
    FilteringClassLoader filteringClassLoader = new FilteringClassLoader(parentObfuscatingClassLoader);
    filteringClassLoader.allowPackage("org.gradle.tooling.internal.protocol");
    return new MutableURLClassLoader(filteringClassLoader, implementationClasspath.getAsURLArray());
}
 
Example #25
Source File: DefaultClassLoaderCache.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassLoader get(final ClassLoader parent, final ClassPath classPath, @Nullable final FilteringClassLoader.Spec filterSpec) {
    try {
        return cache.get(new Key(parent, classPath, filterSpec), new Callable<ClassLoader>() {
            public ClassLoader call() throws Exception {
                if (filterSpec == null) {
                    return new URLClassLoader(classPath.getAsURLArray(), parent);
                } else {
                    return new FilteringClassLoader(get(parent, classPath, null), filterSpec);
                }
            }
        });
    } catch (ExecutionException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }
}
 
Example #26
Source File: DefaultClassLoaderScope.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassLoaderScope export(ClassPath classPath) {
    if (classPath.isEmpty()) {
        return this;
    }

    assertNotLocked();
    if (exportingClassLoader != null) {
        exportingClassLoader.addParent(loader(classPath));
    } else {
        export.add(classPath);
    }

    return this;
}
 
Example #27
Source File: DefaultClassLoaderRegistry.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public DefaultClassLoaderRegistry(ClassPathRegistry classPathRegistry, ClassLoaderFactory classLoaderFactory) {
    ClassLoader runtimeClassLoader = getClass().getClassLoader();

    // Core impl
    ClassPath coreImplClassPath = classPathRegistry.getClassPath("GRADLE_CORE_IMPL");
    coreImplClassLoader = new MutableURLClassLoader(runtimeClassLoader, coreImplClassPath);

    // Add in libs for plugins
    ClassPath pluginsClassPath = classPathRegistry.getClassPath("GRADLE_PLUGINS");
    ClassLoader pluginsImports = new CachingClassLoader(new MultiParentClassLoader(runtimeClassLoader, coreImplClassLoader));
    pluginsClassLoader = new MutableURLClassLoader(pluginsImports, pluginsClassPath);

    FilteringClassLoader rootClassLoader = classLoaderFactory.createFilteringClassLoader(pluginsClassLoader);
    rootClassLoader.allowPackage("org.gradle");
    rootClassLoader.allowResources("META-INF/gradle-plugins");
    rootClassLoader.allowPackage("org.apache.tools.ant");
    rootClassLoader.allowPackage("groovy");
    rootClassLoader.allowPackage("org.codehaus.groovy");
    rootClassLoader.allowPackage("groovyjarjarantlr");
    rootClassLoader.allowPackage("org.apache.ivy");
    rootClassLoader.allowPackage("org.slf4j");
    rootClassLoader.allowPackage("org.apache.commons.logging");
    rootClassLoader.allowPackage("org.apache.log4j");
    rootClassLoader.allowPackage("javax.inject");

    this.rootClassLoader = new CachingClassLoader(rootClassLoader);
}
 
Example #28
Source File: ProcessBootstrap.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void runNoExit(String mainClassName, String[] args) throws Exception {
    ClassPathRegistry classPathRegistry = new DefaultClassPathRegistry(new DefaultClassPathProvider(new DefaultModuleRegistry()));
    ClassLoaderFactory classLoaderFactory = new DefaultClassLoaderFactory();
    ClassPath antClasspath = classPathRegistry.getClassPath("ANT");
    ClassPath runtimeClasspath = classPathRegistry.getClassPath("GRADLE_RUNTIME");
    ClassLoader antClassLoader = classLoaderFactory.createIsolatedClassLoader(antClasspath);
    ClassLoader runtimeClassLoader = new MutableURLClassLoader(antClassLoader, runtimeClasspath);
    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
    Class<?> mainClass = runtimeClassLoader.loadClass(mainClassName);
    Method mainMethod = mainClass.getMethod("main", String[].class);
    mainMethod.invoke(null, new Object[]{args});
}
 
Example #29
Source File: CachingToolingImplementationLoader.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters) {
    ClassPath classpath = distribution.getToolingImplementationClasspath(progressLoggerFactory, connectionParameters.getGradleUserHomeDir());

    ConsumerConnection connection = connections.get(classpath);
    if (connection == null) {
        connection = loader.create(distribution, progressLoggerFactory, connectionParameters);
        connections.put(classpath, connection);
    }

    return connection;
}
 
Example #30
Source File: BuildSourceBuilder.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ClassLoaderScope buildAndCreateClassLoader(StartParameter startParameter) {
    ClassPath classpath = createBuildSourceClasspath(startParameter);
    if (classpath.isEmpty()) {
        return classLoaderScope;
    } else {
        ClassLoaderScope childScope = classLoaderScope.createChild();
        childScope.export(classpath);
        childScope.lock();
        return childScope;
    }
}