/** Creates the configurations used by plugin. */ private void addJacocoConfigurations() { Configuration agentConf = project.getConfigurations().create(AGENT_CONFIGURATION_NAME); agentConf.setVisible(false); agentConf.setTransitive(true); agentConf.setDescription("The Jacoco agent to use to get coverage data."); Configuration antConf = project.getConfigurations().create(ANT_CONFIGURATION_NAME); antConf.setVisible(false); antConf.setTransitive(true); antConf.setDescription("The Jacoco ant tasks to use to get execute Gradle tasks."); }
private ModuleDescriptor findProject(DependencyDescriptor descriptor) { String projectPathValue = descriptor.getAttribute(DependencyDescriptorFactory.PROJECT_PATH_KEY); if (projectPathValue == null) { return null; } Project project = gradle.getRootProject().project(projectPathValue); Module projectModule = ((ProjectInternal) project).getModule(); ModuleDescriptor projectDescriptor = moduleDescriptorConverter.convert( project.getConfigurations().getAll(), projectModule, IvyContext.getContext().getIvy().getSettings()); for (DependencyArtifactDescriptor artifactDescriptor : descriptor.getAllDependencyArtifacts()) { for (Artifact artifact : projectDescriptor.getAllArtifacts()) { if (artifact.getName().equals(artifactDescriptor.getName()) && artifact.getExt().equals(artifactDescriptor.getExt())) { String path = artifact.getExtraAttribute(DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE); ReflectionUtil.invoke( artifactDescriptor, "setExtraAttribute", new Object[] {DefaultIvyDependencyPublisher.FILE_PATH_EXTRA_ATTRIBUTE, path}); } } } return projectDescriptor; }
public void apply(String taskName) { for (Configuration configuration : project.getConfigurations()) { if (taskName.equals(configuration.getUploadTaskName())) { createUploadTask(configuration.getUploadTaskName(), configuration, project); } } }
private void addArtifacts(Project project, List<GradleFileBuildOutcome> outcomes) { Configuration configuration = project.getConfigurations().findByName("archives"); if (configuration != null) { for (PublishArtifact artifact : configuration.getArtifacts()) { GradleFileBuildOutcome outcome = artifactTransformer.transform(artifact, project); outcomes.add(outcome); } } }
// @Todo: refactor this task configuration to extend a copy task and use replace tokens private void addCreateScriptsTask() { CreateStartScripts startScripts = project.getTasks().create(TASK_START_SCRIPTS_NAME, CreateStartScripts.class); startScripts.setDescription( "Creates OS specific scripts to run the project as a JVM application."); startScripts.setClasspath( project .getTasks() .getAt(JavaPlugin.JAR_TASK_NAME) .getOutputs() .getFiles() .plus(project.getConfigurations().getByName("runtime"))); startScripts .getConventionMapping() .map( "mainClassName", new Callable<Object>() { @Override public Object call() throws Exception { return pluginConvention.getMainClassName(); } }); startScripts .getConventionMapping() .map( "applicationName", new Callable<Object>() { @Override public Object call() throws Exception { return pluginConvention.getApplicationName(); } }); startScripts .getConventionMapping() .map( "outputDir", new Callable<Object>() { @Override public Object call() throws Exception { return new File(project.getBuildDir(), "scripts"); } }); startScripts .getConventionMapping() .map( "defaultJvmOpts", new Callable<Object>() { @Override public Object call() throws Exception { return pluginConvention.getApplicationDefaultJvmArgs(); } }); }
public void apply(Project project) { JavaBasePlugin javaBasePlugin = project.getPlugins().apply(JavaBasePlugin.class); project .getConfigurations() .add(GROOVY_CONFIGURATION_NAME) .setVisible(false) .setTransitive(false) .setDescription("The groovy libraries to be used for this Groovy project."); configureCompileDefaults(project); configureSourceSetDefaults(project, javaBasePlugin); configureGroovydoc(project); }
/** * Configures the agent dependencies using the 'jacocoAnt' configuration. Uses the version * declared in 'toolVersion' of the Jacoco extension if no dependencies are explicitly declared. * * @param extension the extension that has the tool version to use */ private void configureAgentDependencies( JacocoAgentJar jacocoAgentJar, final JacocoPluginExtension extension) { Configuration config = project.getConfigurations().getAt(AGENT_CONFIGURATION_NAME); ((IConventionAware) jacocoAgentJar) .getConventionMapping() .map("agentConf", Callables.returning(config)); config.defaultDependencies( new Action<DependencySet>() { @Override public void execute(DependencySet dependencies) { dependencies.add( project .getDependencies() .create("org.jacoco:org.jacoco.agent:" + extension.getToolVersion())); } }); }
/** * @param project the project on which we'll call {@link Project#javaexec(Action)}. * @param input the JavaExecable which we'll take as input and call run() on. * @param settings any extra settings you'd like to set on the JavaExec (e.g. heap) * @return the JavaExecable after it has had run() called. */ public static <T extends JavaExecable> T exec( Project project, T input, Action<JavaExecSpec> settings) throws Throwable { // copy the classpath from the project's buildscript (and its parents) List<FileCollection> classpaths = TreeStream.toParent(ProjectPlugin.treeDef(), project) .map(p -> p.getBuildscript().getConfigurations().getByName(BUILDSCRIPT_CLASSPATH)) .collect(Collectors.toList()); // add the gradleApi, workaround from // https://discuss.gradle.org/t/gradle-doesnt-add-the-same-dependencies-to-classpath-when-applying-plugins/9759/6?u=ned_twigg classpaths.add( project.getConfigurations().detachedConfiguration(project.getDependencies().gradleApi())); // add stuff from the local classloader too, to fix testkit's classpath classpaths.add(JavaExecableImp.fromLocalClassloader()); // run it FileCollection classpath = new UnionFileCollection(classpaths); return JavaExecableImp.execInternal( input, classpath, settings, execSpec -> JavaExecWinFriendly.javaExec(project, execSpec)); }
private CopySpec configureDistSpec(CopySpec distSpec) { Task jar = project.getTasks().getAt(JavaPlugin.JAR_TASK_NAME); Task startScripts = project.getTasks().getAt(TASK_START_SCRIPTS_NAME); CopySpec libChildSpec = project.copySpec(); libChildSpec.into("lib"); libChildSpec.from(jar); libChildSpec.from(project.getConfigurations().getByName("runtime")); CopySpec binChildSpec = project.copySpec(); binChildSpec.into("bin"); binChildSpec.from(startScripts); binChildSpec.setFileMode(0755); CopySpec childSpec = project.copySpec(); childSpec.from(project.file("src/dist")); childSpec.with(libChildSpec); childSpec.with(binChildSpec); distSpec.with(childSpec); distSpec.with(pluginConvention.getApplicationDistribution()); return distSpec; }
@Nullable @Override public Object buildAll(final String modelName, final Project project) { final List<IdeaDependency> dependencies = new ArrayList<IdeaDependency>(); final Map<DependencyVersionId, Scopes> scopesMap = new LinkedHashMap<DependencyVersionId, Scopes>(); final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor(); boolean offline = false; boolean downloadJavadoc = false; boolean downloadSources = true; final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class); Map<String, Map<String, Collection<Configuration>>> userScopes = Collections.emptyMap(); if (ideaPlugin != null) { IdeaModel ideaModel = ideaPlugin.getModel(); if (ideaModel != null && ideaModel.getModule() != null) { offline = ideaModel.getModule().isOffline(); downloadJavadoc = ideaModel.getModule().isDownloadJavadoc(); downloadSources = ideaModel.getModule().isDownloadSources(); userScopes = ideaModel.getModule().getScopes(); } } for (final Configuration configuration : project.getConfigurations()) { Collection<Configuration> plusConfigurations = new ArrayList<Configuration>(); plusConfigurations.add(configuration); final Collection<IdeProjectDependency> ideProjectDependencies = dependenciesExtractor.extractProjectDependencies( project, plusConfigurations, new ArrayList<Configuration>()); for (IdeProjectDependency ideProjectDependency : ideProjectDependencies) { merge(scopesMap, ideProjectDependency, userScopes); } if (!offline) { final Collection<IdeExtendedRepoFileDependency> ideRepoFileDependencies = dependenciesExtractor.extractRepoFileDependencies( project.getConfigurations(), plusConfigurations, new ArrayList<Configuration>(), downloadSources, downloadJavadoc); for (IdeExtendedRepoFileDependency repoFileDependency : ideRepoFileDependencies) { merge(scopesMap, repoFileDependency, userScopes); } } final Collection<IdeLocalFileDependency> ideLocalFileDependencies = dependenciesExtractor.extractLocalFileDependencies( plusConfigurations, new ArrayList<Configuration>()); for (IdeLocalFileDependency fileDependency : ideLocalFileDependencies) { merge(scopesMap, fileDependency, userScopes); } } for (Map.Entry<DependencyVersionId, Scopes> entry : scopesMap.entrySet()) { DependencyVersionId versionId = entry.getKey(); for (GradleDependencyScope scope : entry.getValue().getScopes()) { if (versionId.getIdeDependency() instanceof IdeExtendedRepoFileDependency) { IdeExtendedRepoFileDependency repoFileDependency = (IdeExtendedRepoFileDependency) versionId.getIdeDependency(); IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( new IdeaDependencyScopeImpl(scope), versionId.getName(), versionId.getGroup(), versionId.getVersion(), versionId.getClassifier()); libraryDependency.setFile(repoFileDependency.getFile()); libraryDependency.setSource(repoFileDependency.getSourceFile()); libraryDependency.setJavadoc(repoFileDependency.getJavadocFile()); dependencies.add(libraryDependency); } else if (versionId.getIdeDependency() instanceof IdeProjectDependency) { IdeProjectDependency projectDependency = (IdeProjectDependency) versionId.getIdeDependency(); String ideaModuleName = findDeDuplicatedModuleName(projectDependency.getProject()); if (ideaModuleName == null) { ideaModuleName = versionId.getName(); } IdeaModuleDependencyImpl moduleDependency = new IdeaModuleDependencyImpl( new IdeaDependencyScopeImpl(scope), ideaModuleName, versionId.getGroup(), versionId.getVersion(), versionId.getClassifier()); moduleDependency.setIdeaModule(new StubIdeaModule(ideaModuleName)); dependencies.add(moduleDependency); } else if (versionId.getIdeDependency() instanceof IdeLocalFileDependency) { IdeLocalFileDependency fileDependency = (IdeLocalFileDependency) versionId.getIdeDependency(); IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( new IdeaDependencyScopeImpl(scope), versionId.getName(), versionId.getGroup(), versionId.getVersion(), versionId.getClassifier()); libraryDependency.setFile(fileDependency.getFile()); attachGradleSdkSources(libraryDependency, fileDependency); dependencies.add(libraryDependency); } } } return new ProjectDependenciesModelImpl(project.getPath(), dependencies); }