use of org.gradle.api.Project in project jib by google.
the class BuildImageTaskTest method setUp.
@Before
public void setUp() {
Project fakeProject = ProjectBuilder.builder().build();
testBuildImageTask = fakeProject.getTasks().create("task", BuildImageTask.class);
fakeJibExtension = fakeProject.getExtensions().create("jib", JibExtension.class, fakeProject);
}
use of org.gradle.api.Project in project gradle-apt-plugin by tbroyer.
the class AptEclipsePlugin method configureEclipse.
/**
* Inspired by
* https://github.com/mkarneim/pojobuilder/wiki/Enabling-PojoBuilder-for-Eclipse-Using-Gradle
*/
private void configureEclipse(final Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
final EclipseModel eclipseModel = project.getExtensions().getByType(EclipseModel.class);
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(final Project project) {
eclipseModel.getClasspath().getPlusConfigurations().addAll(Arrays.asList(project.getConfigurations().getByName(new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getCompileOnlyConfigurationName()), project.getConfigurations().getByName(new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getCompileOnlyConfigurationName())));
}
});
if (project.getTasks().findByName("eclipseJdtApt") == null) {
GenerateEclipseJdtApt task = project.getTasks().create("eclipseJdtApt", GenerateEclipseJdtApt.class, new Action<GenerateEclipseJdtApt>() {
@Override
public void execute(GenerateEclipseJdtApt generateEclipseJdtApt) {
generateEclipseJdtApt.setDescription("Generates the Eclipse JDT APT settings file.");
generateEclipseJdtApt.setInputFile(project.file(".settings/org.eclipse.jdt.apt.core.prefs"));
generateEclipseJdtApt.setOutputFile(project.file(".settings/org.eclipse.jdt.apt.core.prefs"));
final EclipseJdtApt jdtApt = generateEclipseJdtApt.getJdtApt();
new DslObject(eclipseModel.getJdt()).getConvention().getPlugins().put("net.ltgt.apt-eclipse", new JdtAptConvention(jdtApt));
ConventionMapping conventionMapping = new DslObject(jdtApt).getConventionMapping();
conventionMapping.map("aptEnabled", new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return project.getTasks().findByName(mainSourceSet.getCompileJavaTaskName()).getConvention().getPlugin(AptPlugin.AptConvention.class).getAptOptions().isAnnotationProcessing();
}
});
conventionMapping.map("genSrcDir", new Callable<File>() {
@Override
public File call() throws Exception {
return project.file(".apt_generated");
}
});
conventionMapping.map("processorOptions", new Callable<Map<String, ?>>() {
@Override
public Map<String, ?> call() throws Exception {
return project.getTasks().findByName(mainSourceSet.getCompileJavaTaskName()).getConvention().getPlugin(AptPlugin.AptConvention.class).getAptOptions().getProcessorArgs();
}
});
eclipseModel.getJdt().getFile().withProperties(// withProperties(Action) overload was added in Gradle 2.14
new MethodClosure(new Action<Properties>() {
@Override
public void execute(Properties properties) {
properties.setProperty("org.eclipse.jdt.core.compiler.processAnnotations", jdtApt.isAptEnabled() ? "enabled" : "disabled");
}
}, "execute"));
}
});
project.getTasks().getByName("eclipse").dependsOn(task);
Delete cleanTask = project.getTasks().create("cleanEclipseJdtApt", Delete.class);
cleanTask.delete(getOutputs(task));
project.getTasks().getByName("cleanEclipse").dependsOn(cleanTask);
}
if (project.getTasks().findByName("eclipseFactorypath") == null) {
GenerateEclipseFactorypath task = project.getTasks().create("eclipseFactorypath", GenerateEclipseFactorypath.class, new Action<GenerateEclipseFactorypath>() {
@Override
public void execute(GenerateEclipseFactorypath generateEclipseFactorypath) {
generateEclipseFactorypath.setDescription("Generates the Eclipse factorypath file.");
generateEclipseFactorypath.setInputFile(project.file(".factorypath"));
generateEclipseFactorypath.setOutputFile(project.file(".factorypath"));
EclipseFactorypath factorypath = generateEclipseFactorypath.getFactorypath();
new DslObject(eclipseModel).getConvention().getPlugins().put("net.ltgt.apt-eclipse", new FactorypathConvention(factorypath));
factorypath.setPlusConfigurations(new ArrayList<>(Arrays.asList(project.getConfigurations().getByName(new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorConfigurationName()), project.getConfigurations().getByName(new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class).getAnnotationProcessorConfigurationName()))));
generateEclipseFactorypath.dependsOn(factorypath.getPlusConfigurations().toArray());
}
});
project.getTasks().getByName("eclipse").dependsOn(task);
Delete cleanTask = project.getTasks().create("cleanEclipseFactorypath", Delete.class);
cleanTask.delete(getOutputs(task));
project.getTasks().getByName("cleanEclipse").dependsOn(cleanTask);
}
}
use of org.gradle.api.Project in project gradle-apt-plugin by tbroyer.
the class AptIdeaPlugin method configureIdeaModule.
private void configureIdeaModule(Project project, final SourceSet mainSourceSet, final SourceSet testSourceSet) {
final IdeaModule ideaModule = project.getExtensions().getByType(IdeaModel.class).getModule();
final ModuleApt apt = new ModuleApt();
new DslObject(ideaModule).getConvention().getPlugins().put("net.ltgt.apt-idea", new ModuleAptConvention(apt));
project.afterEvaluate(new Action<Project>() {
@Override
public void execute(Project project) {
if (apt.isAddGeneratedSourcesDirs()) {
Set<File> excl = new LinkedHashSet<>();
for (SourceSet sourceSet : new SourceSet[] { mainSourceSet, testSourceSet }) {
File generatedSourcesDir = new DslObject(sourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
for (File f = generatedSourcesDir; f != null && !f.equals(project.getProjectDir()); f = f.getParentFile()) {
excl.add(f);
}
}
// For some reason, modifying the existing collections doesn't work.
// We need to copy the values and then assign it back.
Set<File> excludeDirs = new LinkedHashSet<>(ideaModule.getExcludeDirs());
if (excl.contains(project.getBuildDir()) && excludeDirs.contains(project.getBuildDir())) {
excludeDirs.remove(project.getBuildDir());
// Race condition: many of these will actually be created afterwards…
File[] subdirs = project.getBuildDir().listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
if (subdirs != null) {
excludeDirs.addAll(Arrays.asList(subdirs));
}
}
excludeDirs.removeAll(excl);
ideaModule.setExcludeDirs(excludeDirs);
File mainGeneratedSourcesDir = new DslObject(mainSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
File testGeneratedSourcesDir = new DslObject(testSourceSet.getOutput()).getConvention().getPlugin(AptPlugin.AptSourceSetOutputConvention.class).getGeneratedSourcesDir();
// For some reason, modifying the existing collections doesn't work.
// We need to copy the values and then assign it back.
ideaModule.setSourceDirs(addToSet(ideaModule.getSourceDirs(), mainGeneratedSourcesDir));
ideaModule.setTestSourceDirs(addToSet(ideaModule.getTestSourceDirs(), testGeneratedSourcesDir));
ideaModule.setGeneratedSourceDirs(addToSet(ideaModule.getGeneratedSourceDirs(), mainGeneratedSourcesDir, testGeneratedSourcesDir));
}
if (apt.isAddCompileOnlyDependencies() || apt.isAddAptDependencies()) {
final AptPlugin.AptSourceSetConvention mainSourceSetConvention = new DslObject(mainSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
final AptPlugin.AptSourceSetConvention testSourceSetConvention = new DslObject(testSourceSet).getConvention().getPlugin(AptPlugin.AptSourceSetConvention.class);
final List<Configuration> mainConfigurations = new ArrayList<>();
final List<Configuration> testConfigurations = new ArrayList<>();
if (apt.isAddCompileOnlyDependencies()) {
mainConfigurations.add(project.getConfigurations().getByName(mainSourceSetConvention.getCompileOnlyConfigurationName()));
testConfigurations.add(project.getConfigurations().getByName(testSourceSetConvention.getCompileOnlyConfigurationName()));
}
if (apt.isAddAptDependencies()) {
mainConfigurations.add(project.getConfigurations().getByName(mainSourceSetConvention.getAnnotationProcessorConfigurationName()));
testConfigurations.add(project.getConfigurations().getByName(testSourceSetConvention.getAnnotationProcessorConfigurationName()));
}
ideaModule.getScopes().get(apt.getMainDependenciesScope()).get("plus").addAll(mainConfigurations);
ideaModule.getScopes().get("TEST").get("plus").addAll(testConfigurations);
project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule generateIdeaModule) {
generateIdeaModule.dependsOn(mainConfigurations.toArray());
generateIdeaModule.dependsOn(testConfigurations.toArray());
}
});
}
}
private Set<File> addToSet(Set<File> sourceDirs, File... dirs) {
Set<File> newSet = new LinkedHashSet<>(sourceDirs);
newSet.addAll(Arrays.asList(dirs));
return newSet;
}
});
}
use of org.gradle.api.Project in project build-info by JFrogDev.
the class TaskHelperConfigurations method setDefaultMavenDescriptor.
protected void setDefaultMavenDescriptor() {
// Flag to publish the Maven POM, but no pom file inputted, activate default Maven "install" task.
// if the project doesn't have the maven install task, warn
Project project = getProject();
TaskContainer tasks = project.getTasks();
Upload installTask = tasks.withType(Upload.class).findByName("install");
if (installTask == null) {
log.warn("Cannot publish pom for project '{}' since it does not contain the Maven " + "plugin install task and task '{}' does not specify a custom pom path.", new Object[] { project.getPath(), getPath() });
artifactoryTask.mavenDescriptor = null;
} else {
artifactoryTask.mavenDescriptor = new File(project.getConvention().getPlugin(MavenPluginConvention.class).getMavenPomDir(), "pom-default.xml");
dependsOn(installTask);
}
}
use of org.gradle.api.Project in project build-info by JFrogDev.
the class GradleBuildInfoExtractor method extract.
@Override
public Build extract(Project rootProject) {
String buildName = clientConf.info.getBuildName();
BuildInfoBuilder bib = new BuildInfoBuilder(buildName);
// backward compat
bib.type(BuildType.GRADLE);
String buildNumber = clientConf.info.getBuildNumber();
bib.number(buildNumber);
String buildStartedIso = clientConf.info.getBuildStarted();
Date buildStartDate = null;
try {
buildStartDate = new SimpleDateFormat(Build.STARTED_FORMAT).parse(buildStartedIso);
} catch (ParseException e) {
log.error("Build start date format error: " + buildStartedIso, e);
}
bib.started(buildStartedIso);
BuildAgent buildAgent = new BuildAgent(clientConf.info.getBuildAgentName(), clientConf.info.getBuildAgentVersion());
bib.buildAgent(buildAgent);
// CI agent
String agentName = clientConf.info.getAgentName();
String agentVersion = clientConf.info.getAgentVersion();
if (StringUtils.isNotBlank(agentName) && StringUtils.isNotBlank(agentVersion)) {
bib.agent(new Agent(agentName, agentVersion));
} else {
// Fallback for standalone builds
bib.agent(new Agent(buildAgent.getName(), buildAgent.getVersion()));
}
long durationMillis = buildStartDate != null ? System.currentTimeMillis() - buildStartDate.getTime() : 0;
bib.durationMillis(durationMillis);
Set<Project> allProjects = rootProject.getAllprojects();
for (Project project : allProjects) {
if (project.getState().getExecuted()) {
ArtifactoryTask buildInfoTask = getBuildInfoTask(project);
if (buildInfoTask != null && buildInfoTask.hasModules()) {
bib.addModule(extractModule(project));
}
}
}
String parentName = clientConf.info.getParentBuildName();
String parentNumber = clientConf.info.getParentBuildNumber();
if (parentName != null && parentNumber != null) {
bib.parentName(parentName);
bib.parentNumber(parentNumber);
}
String principal = clientConf.info.getPrincipal();
if (StringUtils.isBlank(principal)) {
principal = System.getProperty("user.name");
}
bib.principal(principal);
String artifactoryPrincipal = clientConf.publisher.getUsername();
if (StringUtils.isBlank(artifactoryPrincipal)) {
artifactoryPrincipal = System.getProperty("user.name");
}
bib.artifactoryPrincipal(artifactoryPrincipal);
String artifactoryPluginVersion = clientConf.info.getArtifactoryPluginVersion();
if (StringUtils.isBlank(artifactoryPluginVersion)) {
artifactoryPluginVersion = "Unknown";
}
bib.artifactoryPluginVersion(artifactoryPluginVersion);
String buildUrl = clientConf.info.getBuildUrl();
if (StringUtils.isNotBlank(buildUrl)) {
bib.url(buildUrl);
}
String vcsRevision = clientConf.info.getVcsRevision();
Vcs vcs = new Vcs();
if (StringUtils.isNotBlank(vcsRevision)) {
vcs.setRevision(vcsRevision);
bib.vcsRevision(vcsRevision);
}
String vcsUrl = clientConf.info.getVcsUrl();
if (StringUtils.isNotBlank(vcsUrl)) {
vcs.setUrl(vcsUrl);
bib.vcsUrl(vcsUrl);
}
if (!vcs.isEmpty()) {
bib.vcs(Arrays.asList(vcs));
}
LicenseControl licenseControl = new LicenseControl(clientConf.info.licenseControl.isRunChecks());
String notificationRecipients = clientConf.info.licenseControl.getViolationRecipients();
if (StringUtils.isNotBlank(notificationRecipients)) {
licenseControl.setLicenseViolationsRecipientsList(notificationRecipients);
}
licenseControl.setIncludePublishedArtifacts(clientConf.info.licenseControl.isIncludePublishedArtifacts());
String scopes = clientConf.info.licenseControl.getScopes();
if (StringUtils.isNotBlank(scopes)) {
licenseControl.setScopesList(scopes);
}
licenseControl.setAutoDiscover(clientConf.info.licenseControl.isAutoDiscover());
bib.licenseControl(licenseControl);
final BlackDuckProperties blackDuckProperties;
if (clientConf.info.blackDuckProperties.isRunChecks()) {
blackDuckProperties = clientConf.info.blackDuckProperties.copyBlackDuckProperties();
} else {
blackDuckProperties = new BlackDuckProperties();
}
Governance governance = new Governance();
governance.setBlackDuckProperties(blackDuckProperties);
bib.governance(governance);
if (clientConf.info.isReleaseEnabled()) {
String stagingRepository = clientConf.publisher.getRepoKey();
String comment = clientConf.info.getReleaseComment();
if (comment == null) {
comment = "";
}
bib.addStatus(new PromotionStatusBuilder(Promotion.STAGED).timestampDate(buildStartDate).comment(comment).repository(stagingRepository).ciUser(principal).user(artifactoryPrincipal).build());
}
String issueTrackerName = clientConf.info.issues.getIssueTrackerName();
if (StringUtils.isNotBlank(issueTrackerName)) {
Issues issues = new Issues();
issues.setAggregateBuildIssues(clientConf.info.issues.getAggregateBuildIssues());
issues.setAggregationBuildStatus(clientConf.info.issues.getAggregationBuildStatus());
issues.setTracker(new IssueTracker(issueTrackerName, clientConf.info.issues.getIssueTrackerVersion()));
Set<Issue> affectedIssuesSet = clientConf.info.issues.getAffectedIssuesSet();
if (!affectedIssuesSet.isEmpty()) {
issues.setAffectedIssues(affectedIssuesSet);
}
bib.issues(issues);
}
for (Map.Entry<String, String> runParam : clientConf.info.getRunParameters().entrySet()) {
MatrixParameter matrixParameter = new MatrixParameter(runParam.getKey(), runParam.getValue());
bib.addRunParameters(matrixParameter);
}
if (clientConf.isIncludeEnvVars()) {
Properties envProperties = new Properties();
envProperties.putAll(clientConf.getAllProperties());
envProperties = BuildInfoExtractorUtils.getEnvProperties(envProperties, clientConf.getLog());
for (Map.Entry<Object, Object> envProp : envProperties.entrySet()) {
bib.addProperty(envProp.getKey(), envProp.getValue());
}
}
log.debug("buildInfoBuilder = " + bib);
// for backward compatibility for Artifactory 2.2.3
Build build = bib.build();
if (parentName != null && parentNumber != null) {
build.setParentBuildId(parentName);
}
return build;
}
Aggregations