@TaskAction public void generate() { ProjectReportGenerator projectReportGenerator = new ProjectReportGenerator() { @Override public void generateReport(Project project) throws IOException { Configuration configuration = getProject().getBuildscript().getConfigurations().getByName(ScriptHandler.CLASSPATH_CONFIGURATION); renderer.startConfiguration(configuration); renderer.render(configuration); renderer.completeConfiguration(configuration); } }; ReportGenerator reportGenerator = new ReportGenerator(renderer, getClientMetaData(), null, getTextOutputFactory(), projectReportGenerator); reportGenerator.generateReport(Collections.singleton(getProject())); }
private void applyScript(Object script) { URI scriptUri = resolver.resolveUri(script); ScriptSource scriptSource = new UriScriptSource("script", scriptUri); ClassLoaderScope classLoaderScopeChild = classLoaderScope.createChild("script-" + scriptUri.toString()); ScriptHandler scriptHandler = scriptHandlerFactory.create(scriptSource, classLoaderScopeChild); ScriptPlugin configurer = configurerFactory.create(scriptSource, scriptHandler, classLoaderScopeChild, classLoaderScope, false); for (Object target : targets) { configurer.apply(target); } }
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(), true); configurer.apply(settings); }
protected ScriptHandler createScriptHandler() { ScriptHandlerFactory factory = new DefaultScriptHandlerFactory( get(DependencyManagementServices.class), get(FileResolver.class), get(DependencyMetaDataProvider.class)); return factory.create(project.getBuildScriptSource(), project.getClassLoaderScope(), project); }
public void process(final ScriptSource initScript, GradleInternal gradle) { ClassLoaderScope baseScope = gradle.getClassLoaderScope(); URI uri = initScript.getResource().getLocation().getURI(); String id = uri == null ? idGenerator.generateId().toString() : uri.toString(); ClassLoaderScope scriptScope = baseScope.createChild("init-" + id); ScriptHandler scriptHandler = scriptHandlerFactory.create(initScript, scriptScope); ScriptPlugin configurer = configurerFactory.create(initScript, scriptHandler, scriptScope, baseScope, true); configurer.apply(gradle); }
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(); }
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)); }
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); } }
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); }
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); }
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; }
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); } }
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); }
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; }
@TaskAction public void run() { SortedSet<String> dependencies = new TreeSet<String>(); ConfigurationContainer container = getProject().getBuildscript().getConfigurations(); for (File file : container.getByName(ScriptHandler.CLASSPATH_CONFIGURATION)) dependencies.add(file.getName()); for (String dependency : dependencies) System.out.println(dependency); }
@Inject public ScriptHandler getBuildscript() { // Decoration takes care of the implementation throw new UnsupportedOperationException(); }
public ScriptHandler getBuildscript() { return getScriptTarget().getBuildscript(); }
@Override public void addScriptClassPathDependency(Object notation) { getDependencies().add(ScriptHandler.CLASSPATH_CONFIGURATION, notation); }
public ScriptHandler getInitscript() { return getBuildscript(); }
@Override public ScriptHandler getBuildscript() { return __scriptServices.get(ScriptHandler.class); }
public ScriptPlugin create(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope targetScope, ClassLoaderScope baseScope, boolean topLevelScript) { return new ScriptPluginImpl(scriptSource, (ScriptHandlerInternal) scriptHandler, targetScope, baseScope, topLevelScript); }
public void apply(final Object target) { final DefaultServiceRegistry services = new DefaultServiceRegistry() { Factory<PatternSet> createPatternSetFactory() { return fileLookup.getFileResolver().getPatternSetFactory(); } }; services.add(ScriptPluginFactory.class, DefaultScriptPluginFactory.this); services.add(ScriptHandlerFactory.class, scriptHandlerFactory); services.add(ClassLoaderScope.class, targetScope); services.add(LoggingManagerInternal.class, loggingManagerFactory.create()); services.add(Instantiator.class, instantiator); services.add(ScriptHandler.class, scriptHandler); services.add(FileLookup.class, fileLookup); services.add(DirectoryFileTreeFactory.class, directoryFileTreeFactory); services.add(ModelRuleSourceDetector.class, modelRuleSourceDetector); services.add(PluginRepositoryRegistry.class, pluginRepositoryRegistry); services.add(PluginRepositoryFactory.class, pluginRepositoryFactory); final ScriptTarget initialPassScriptTarget = initialPassTarget(target); ScriptCompiler compiler = scriptCompilerFactory.createCompiler(scriptSource); // Pass 1, extract plugin requests and plugin repositories and execute buildscript {}, ignoring (i.e. not even compiling) anything else Class<? extends BasicScript> scriptType = initialPassScriptTarget.getScriptClass(); InitialPassStatementTransformer initialPassStatementTransformer = new InitialPassStatementTransformer(scriptSource, initialPassScriptTarget, documentationRegistry); SubsetScriptTransformer initialTransformer = new SubsetScriptTransformer(initialPassStatementTransformer); String id = INTERNER.intern("cp_" + initialPassScriptTarget.getId()); CompileOperation<PluginRequests> initialOperation = new FactoryBackedCompileOperation<PluginRequests>(id, initialTransformer, initialPassStatementTransformer, pluginRequestsSerializer); ScriptRunner<? extends BasicScript, PluginRequests> initialRunner = compiler.compile(scriptType, initialOperation, baseScope.getExportClassLoader(), Actions.doNothing()); initialRunner.run(target, services); PluginRequests pluginRequests = initialRunner.getData(); PluginManagerInternal pluginManager = initialPassScriptTarget.getPluginManager(); pluginRequestApplicator.applyPlugins(pluginRequests, scriptHandler, pluginManager, targetScope); // Pass 2, compile everything except buildscript {}, pluginRepositories{}, and plugin requests, then run final ScriptTarget scriptTarget = secondPassTarget(target); scriptType = scriptTarget.getScriptClass(); BuildScriptTransformer buildScriptTransformer = new BuildScriptTransformer(scriptSource, scriptTarget); String operationId = scriptTarget.getId(); CompileOperation<BuildScriptData> operation = new FactoryBackedCompileOperation<BuildScriptData>(operationId, buildScriptTransformer, buildScriptTransformer, buildScriptDataSerializer); final ScriptRunner<? extends BasicScript, BuildScriptData> runner = compiler.compile(scriptType, operation, targetScope.getLocalClassLoader(), ClosureCreationInterceptingVerifier.INSTANCE); if (scriptTarget.getSupportsMethodInheritance() && runner.getHasMethods()) { scriptTarget.attachScript(runner.getScript()); } if (!runner.getRunDoesSomething()) { return; } Runnable buildScriptRunner = new Runnable() { public void run() { runner.run(target, services); } }; boolean hasImperativeStatements = runner.getData().getHasImperativeStatements(); scriptTarget.addConfiguration(buildScriptRunner, !hasImperativeStatements); }
@Override public ScriptPlugin create(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope targetScope, ClassLoaderScope baseScope, boolean topLevelScript) { return scriptPluginFactoryFor(scriptSource.getFileName()) .create(scriptSource, scriptHandler, targetScope, baseScope, topLevelScript); }
public ScriptHandler create(ScriptSource scriptSource, ClassLoaderScope classLoaderScope) { return create(scriptSource, classLoaderScope, new BasicDomainObjectContext()); }
public ScriptHandler getBuildscript() { return __scriptServices.get(ScriptHandler.class); }
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); }
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, targetScope); 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); PluginDependenciesService pluginDependenciesService = new PluginDependenciesService(getSource()); services.add(PluginDependenciesService.class, pluginDependenciesService); ScriptCompiler compiler = scriptCompilerFactory.createCompiler(withImports); compiler.setClassloader(baseScope.getExportClassLoader()); boolean supportsPluginsBlock = ProjectScript.class.isAssignableFrom(scriptType); String onPluginBlockError = supportsPluginsBlock ? null : "Only Project build scripts can contain plugins {} blocks"; PluginsAndBuildscriptTransformer scriptBlockTransformer = new PluginsAndBuildscriptTransformer(classpathClosureName, onPluginBlockError, documentationRegistry); StatementExtractingScriptTransformer classpathScriptTransformer = new StatementExtractingScriptTransformer(classpathClosureName, scriptBlockTransformer); compiler.setTransformer(classpathScriptTransformer); ScriptRunner<? extends BasicScript> classPathScriptRunner = compiler.compile(scriptType); classPathScriptRunner.getScript().init(target, services); classPathScriptRunner.run(); List<PluginRequest> pluginRequests = pluginDependenciesService.getRequests(); PluginAware pluginAware = target instanceof PluginAware ? (PluginAware) target : null; pluginRequestApplicator.applyPlugins(pluginRequests, scriptHandler, pluginAware, targetScope); compiler.setClassloader(targetScope.getLocalClassLoader()); BuildScriptTransformer transformer = new BuildScriptTransformer("no_" + classpathScriptTransformer.getId(), classpathScriptTransformer.invert(), scriptSource); compiler.setTransformer(transformer); // TODO - find a less tangled way of getting this in here, see the verifier impl for why it's needed compiler.setVerifier(new ClosureCreationInterceptingVerifier()); ScriptRunner<? extends BasicScript> runner = compiler.compile(scriptType); BasicScript script = runner.getScript(); script.init(target, services); if (ownerScript && target instanceof ScriptAware) { ((ScriptAware) target).setScript(script); } runner.run(); }
public ScriptHandler getBuildscript() { return scriptHandler; }
public void process(final ScriptSource initScript, GradleInternal gradle) { ClassLoaderScope classLoaderScope = gradle.getClassLoaderScope().createSibling(); ScriptHandler scriptHandler = scriptHandlerFactory.create(initScript, classLoaderScope); ScriptPlugin configurer = configurerFactory.create(initScript, scriptHandler, classLoaderScope, "initscript", InitScript.class); configurer.apply(gradle); }
public ScriptPlugin create(ScriptSource scriptSource, ScriptHandler scriptHandler, ClassLoaderScope classLoaderScope, String classpathClosureName, Class<? extends BasicScript> scriptClass) { return new ScriptPluginImpl(scriptSource, scriptHandler, classLoaderScope, classpathClosureName, scriptClass); }
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(); }
/** * Returns the script handler for this script. You can use this handler to manage the classpath used to compile and * execute this script. * * @return the classpath handler. Never returns null. */ ScriptHandler getBuildscript();
/** * Returns the build script handler for this project. You can use this handler to query details about the build * script for this project, and manage the classpath used to compile and execute the project's build script. * * @return the classpath handler. Never returns null. */ ScriptHandler getBuildscript();