use of org.gradle.api.plugins.JavaPlugin in project gradle-consistent-versions by palantir.
the class FixLegacyJavaConfigurationsPlugin method apply.
@Override
public final void apply(Project project) {
// ConsistentVersionsPlugin should ensure that we only get applied onto java projects
if (!project.getPlugins().hasPlugin(JavaPlugin.class)) {
throw new GradleException("FixLegacyJavaConfigurationsPlugin must be applied after 'java' / JavaPlugin");
}
if (VersionsLockPlugin.isIgnoreLockFile(project)) {
return;
}
Configuration unifiedClasspath = project.getRootProject().getConfigurations().findByName(VersionsLockPlugin.UNIFIED_CLASSPATH_CONFIGURATION_NAME);
Preconditions.checkNotNull(unifiedClasspath, "FixLegacyJavaConfigurationsPlugin must be applied after VersionsLockPlugin");
fixLegacyResolvableJavaConfigurations(project, unifiedClasspath);
}
use of org.gradle.api.plugins.JavaPlugin in project spring-boot by spring-projects.
the class MavenRepositoryPlugin method setUpProjectRepository.
private void setUpProjectRepository(Project project, Task publishTask, File repositoryLocation) {
publishTask.doFirst(new CleanAction(repositoryLocation));
Configuration projectRepository = project.getConfigurations().create(MAVEN_REPOSITORY_CONFIGURATION_NAME);
project.getArtifacts().add(projectRepository.getName(), repositoryLocation, (artifact) -> artifact.builtBy(publishTask));
DependencySet target = projectRepository.getDependencies();
project.getPlugins().withType(JavaPlugin.class).all((javaPlugin) -> addMavenRepositoryDependencies(project, JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, target));
project.getPlugins().withType(JavaLibraryPlugin.class).all((javaLibraryPlugin) -> addMavenRepositoryDependencies(project, JavaPlugin.API_CONFIGURATION_NAME, target));
project.getPlugins().withType(JavaPlatformPlugin.class).all((javaPlugin) -> addMavenRepositoryDependencies(project, JavaPlatformPlugin.API_CONFIGURATION_NAME, target));
}
use of org.gradle.api.plugins.JavaPlugin in project cayenne by apache.
the class CgenTask method getDestDirFile.
@OutputDirectory
protected File getDestDirFile() {
final Reference<File> javaSourceDir = new Reference<>(null);
if (destDir != null) {
javaSourceDir.set(destDir);
} else if (destDirName != null) {
javaSourceDir.set(getProject().file(destDirName));
} else {
getProject().getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(final JavaPlugin plugin) {
SourceSetContainer sourceSets = (SourceSetContainer) getProject().getProperties().get("sourceSets");
Set<File> sourceDirs = sourceSets.getByName("main").getJava().getSrcDirs();
if (sourceDirs != null && !sourceDirs.isEmpty()) {
// find java directory, if there is no such dir, take first
for (File dir : sourceDirs) {
if (dir.getName().endsWith("java")) {
javaSourceDir.set(dir);
break;
}
}
if (javaSourceDir.get() == null) {
javaSourceDir.set(sourceDirs.iterator().next());
}
}
}
});
}
if (javaSourceDir.get() == null) {
throw new InvalidUserDataException("cgen.destDir is not set and there is no Java source sets found.");
}
if (!javaSourceDir.get().exists()) {
javaSourceDir.get().mkdirs();
}
return javaSourceDir.get();
}
use of org.gradle.api.plugins.JavaPlugin in project gradle by gradle.
the class EclipseWtpPlugin method configureEclipseWtpComponent.
private void configureEclipseWtpComponent(final Project project, final EclipseModel model) {
XmlTransformer xmlTransformer = new XmlTransformer();
xmlTransformer.setIndentation("\t");
final EclipseWtpComponent component = project.getObjects().newInstance(EclipseWtpComponent.class, project, new XmlFileContentMerger(xmlTransformer));
model.getWtp().setComponent(component);
TaskProvider<GenerateEclipseWtpComponent> task = project.getTasks().register(ECLIPSE_WTP_COMPONENT_TASK_NAME, GenerateEclipseWtpComponent.class, component);
task.configure(new Action<GenerateEclipseWtpComponent>() {
@Override
public void execute(final GenerateEclipseWtpComponent task) {
task.setDescription("Generates the Eclipse WTP component settings file.");
task.setInputFile(project.file(".settings/org.eclipse.wst.common.component"));
task.setOutputFile(project.file(".settings/org.eclipse.wst.common.component"));
}
});
addWorker(task, ECLIPSE_WTP_COMPONENT_TASK_NAME);
((IConventionAware) component).getConventionMapping().map("deployName", new Callable<String>() {
@Override
public String call() throws Exception {
return model.getProject().getName();
}
});
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
if (hasWarOrEarPlugin(project)) {
return;
}
Set<Configuration> libConfigurations = component.getLibConfigurations();
libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
component.setClassesDeployPath("/");
((IConventionAware) component).getConventionMapping().map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
return "../";
}
});
((IConventionAware) component).getConventionMapping().map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
project.getPlugins().withType(WarPlugin.class, new Action<WarPlugin>() {
@Override
public void execute(WarPlugin warPlugin) {
Set<Configuration> libConfigurations = component.getLibConfigurations();
Set<Configuration> minusConfigurations = component.getMinusConfigurations();
libConfigurations.add(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
minusConfigurations.add(project.getConfigurations().getByName("providedRuntime"));
component.setClassesDeployPath("/WEB-INF/classes");
ConventionMapping convention = ((IConventionAware) component).getConventionMapping();
convention.map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
return "/WEB-INF/lib";
}
});
convention.map("contextPath", new Callable<String>() {
@Override
public String call() throws Exception {
return ((War) project.getTasks().getByName("war")).getArchiveBaseName().getOrNull();
}
});
convention.map("resources", new Callable<List<WbResource>>() {
@Override
public List<WbResource> call() throws Exception {
File projectDir = project.getProjectDir();
File webAppDir = ((War) project.getTasks().getByName("war")).getWebAppDirectory().get().getAsFile();
String webAppDirName = RelativePathUtil.relativePath(projectDir, webAppDir);
return Lists.newArrayList(new WbResource("/", webAppDirName));
}
});
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
project.getPlugins().withType(EarPlugin.class, new Action<EarPlugin>() {
@Override
public void execute(EarPlugin earPlugin) {
Set<Configuration> libConfigurations = component.getLibConfigurations();
Set<Configuration> rootConfigurations = component.getRootConfigurations();
rootConfigurations.clear();
rootConfigurations.add(project.getConfigurations().getByName("deploy"));
libConfigurations.clear();
libConfigurations.add(project.getConfigurations().getByName("earlib"));
component.setClassesDeployPath("/");
final ConventionMapping convention = ((IConventionAware) component).getConventionMapping();
convention.map("libDeployPath", new Callable<String>() {
@Override
public String call() throws Exception {
String deployPath = ((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getLibDirName();
if (!deployPath.startsWith("/")) {
deployPath = "/" + deployPath;
}
return deployPath;
}
});
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return WrapUtil.toSet(((Ear) project.getTasks().findByName(EarPlugin.EAR_TASK_NAME)).getAppDirectory().get().getAsFile());
}
});
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
return getMainSourceDirs(project);
}
});
}
});
}
});
}
use of org.gradle.api.plugins.JavaPlugin in project gradle by gradle.
the class EclipsePlugin method configureJavaClasspath.
private static void configureJavaClasspath(final Project project, final TaskProvider<GenerateEclipseClasspath> task, final EclipseModel model, Collection<SourceSet> testSourceSetsConvention, Collection<Configuration> testConfigurationsConvention) {
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
((IConventionAware) model.getClasspath()).getConventionMapping().map("plusConfigurations", new Callable<Collection<Configuration>>() {
@Override
public Collection<Configuration> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
List<Configuration> sourceSetsConfigurations = Lists.newArrayListWithCapacity(sourceSets.size() * 2);
ConfigurationContainer configurations = project.getConfigurations();
for (SourceSet sourceSet : sourceSets) {
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getCompileClasspathConfigurationName()));
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
return sourceSetsConfigurations;
}
}).cache();
((IConventionAware) model.getClasspath()).getConventionMapping().map("classFolders", new Callable<List<File>>() {
@Override
public List<File> call() {
List<File> result = Lists.newArrayList();
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
result.addAll(sourceSet.getOutput().getDirs().getFiles());
}
return result;
}
});
task.configure(new Action<GenerateEclipseClasspath>() {
@Override
public void execute(GenerateEclipseClasspath task) {
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
task.dependsOn(sourceSet.getOutput().getDirs());
}
}
});
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
sourceSets.configureEach(new Action<SourceSet>() {
@Override
public void execute(SourceSet sourceSet) {
if (sourceSet.getName().toLowerCase(Locale.ROOT).contains("test")) {
// source sets with 'test' in their name are marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the source sets with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
}
});
project.getConfigurations().all(new Action<Configuration>() {
@Override
public void execute(Configuration configuration) {
if (configuration.isCanBeResolved() && configuration.getName().toLowerCase(Locale.ROOT).contains("test")) {
// resolved dependencies from custom configurations with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(configuration);
}
}
});
}
});
project.getPlugins().withType(JavaTestFixturesPlugin.class, new Action<JavaTestFixturesPlugin>() {
@Override
public void execute(JavaTestFixturesPlugin javaTestFixturesPlugin) {
model.getClasspath().getContainsTestFixtures().convention(true);
project.getPluginManager().withPlugin("java", new Action<AppliedPlugin>() {
@Override
public void execute(AppliedPlugin appliedPlugin) {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
SourceSet sourceSet = sourceSets.getByName(TestFixturesSupport.TEST_FIXTURE_SOURCESET_NAME);
// the testFixtures source set is marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the testFixtures source set are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
});
}
});
project.getPlugins().withType(TestSuiteBasePlugin.class, testSuiteBasePlugin -> {
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
ExtensiblePolymorphicDomainObjectContainer<TestSuite> suites = testing.getSuites();
suites.withType(JvmTestSuite.class).configureEach(jvmTestSuite -> {
// jvm test suite source sets are marked as test on the Eclipse classpath
testSourceSetsConvention.add(jvmTestSuite.getSources());
// resolved dependencies from jvm test suites are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getRuntimeClasspathConfigurationName()));
});
});
}
Aggregations