use of org.gradle.api.JavaVersion in project gradle by gradle.
the class Test method executeTests.
@TaskAction
public void executeTests() {
LogLevel currentLevel = determineCurrentLogLevel();
TestLogging levelLogging = testLogging.get(currentLevel);
TestExceptionFormatter exceptionFormatter = getExceptionFormatter(levelLogging);
TestEventLogger eventLogger = new TestEventLogger(getTextOutputFactory(), currentLevel, levelLogging, exceptionFormatter);
addTestListener(eventLogger);
addTestOutputListener(eventLogger);
if (getFilter().isFailOnNoMatchingTests() && !getFilter().getIncludePatterns().isEmpty()) {
addTestListener(new NoMatchingTestsReporter("No tests found for given includes: " + getFilter().getIncludePatterns()));
}
File binaryResultsDir = getBinResultsDir();
getProject().delete(binaryResultsDir);
getProject().mkdir(binaryResultsDir);
Map<String, TestClassResult> results = new HashMap<String, TestClassResult>();
TestOutputStore testOutputStore = new TestOutputStore(binaryResultsDir);
TestOutputStore.Writer outputWriter = testOutputStore.writer();
TestReportDataCollector testReportDataCollector = new TestReportDataCollector(results, outputWriter);
addTestListener(testReportDataCollector);
addTestOutputListener(testReportDataCollector);
TestCountLogger testCountLogger = new TestCountLogger(getProgressLoggerFactory());
addTestListener(testCountLogger);
testListenerInternalBroadcaster.add(new TestListenerAdapter(testListenerBroadcaster.getSource(), testOutputListenerBroadcaster.getSource()));
TestResultProcessor resultProcessor = new StateTrackingTestResultProcessor(testListenerInternalBroadcaster.getSource());
if (testExecuter == null) {
testExecuter = new DefaultTestExecuter(getProcessBuilderFactory(), getActorFactory(), getModuleRegistry(), getServices().get(BuildOperationWorkerRegistry.class), getServices().get(BuildOperationExecutor.class), getServices().get(StartParameter.class).getMaxWorkerCount());
}
JavaVersion javaVersion = getJavaVersion();
if (!javaVersion.isJava6Compatible()) {
throw new UnsupportedJavaRuntimeException("Support for test execution using Java 5 or earlier was removed in Gradle 3.0.");
}
try {
testExecuter.execute(this, resultProcessor);
} finally {
testExecuter = null;
testListenerBroadcaster.removeAll();
testOutputListenerBroadcaster.removeAll();
testListenerInternalBroadcaster.removeAll();
outputWriter.close();
}
new TestResultSerializer(binaryResultsDir).write(results.values());
TestResultsProvider testResultsProvider = new InMemoryTestResultsProvider(results.values(), testOutputStore);
try {
if (testReporter == null) {
testReporter = new DefaultTestReport(getBuildOperationProcessor());
}
JUnitXmlReport junitXml = reports.getJunitXml();
if (junitXml.isEnabled()) {
TestOutputAssociation outputAssociation = junitXml.isOutputPerTestCase() ? TestOutputAssociation.WITH_TESTCASE : TestOutputAssociation.WITH_SUITE;
Binary2JUnitXmlReportGenerator binary2JUnitXmlReportGenerator = new Binary2JUnitXmlReportGenerator(junitXml.getDestination(), testResultsProvider, outputAssociation, getBuildOperationProcessor(), getInetAddressFactory().getHostname());
binary2JUnitXmlReportGenerator.generate();
}
DirectoryReport html = reports.getHtml();
if (!html.isEnabled()) {
getLogger().info("Test report disabled, omitting generation of the HTML test report.");
} else {
testReporter.generateReport(testResultsProvider, html.getDestination());
}
} finally {
CompositeStoppable.stoppable(testResultsProvider).stop();
testReporter = null;
testFramework = null;
}
if (testCountLogger.hadFailures()) {
handleTestFailures();
}
}
use of org.gradle.api.JavaVersion in project gradle by gradle.
the class PlayIdeaPlugin method configureIdeaModule.
@Mutate
public void configureIdeaModule(@Path("tasks.ideaModule") GenerateIdeaModule ideaModule, @Path("binaries.playBinary") final PlayApplicationBinarySpec playApplicationBinarySpec, @Path("buildDir") final File buildDir, ConfigurationContainer configurations, final FileResolver fileResolver) {
IdeaModule module = ideaModule.getModule();
module.setScopes(buildScopes(configurations));
ConventionMapping conventionMapping = conventionMappingFor(module);
conventionMapping.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: Assets should probably be a source set too
Set<File> sourceDirs = Sets.newHashSet(playApplicationBinarySpec.getAssets().getAssetDirs());
return CollectionUtils.inject(sourceDirs, playApplicationBinarySpec.getInputs(), new Action<CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet>>() {
@Override
public void execute(CollectionUtils.InjectionStep<Set<File>, LanguageSourceSet> step) {
step.getTarget().addAll(step.getItem().getSource().getSrcDirs());
}
});
}
});
conventionMapping.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
// TODO: This should be modeled as a source set
return Collections.singleton(fileResolver.resolve("test"));
}
});
conventionMapping.map("singleEntryLibraries", new Callable<Map<String, Iterable<File>>>() {
@Override
public Map<String, Iterable<File>> call() throws Exception {
return ImmutableMap.<String, Iterable<File>>builder().put("COMPILE", Collections.singleton(playApplicationBinarySpec.getClasses().getClassesDir())).put("RUNTIME", playApplicationBinarySpec.getClasses().getResourceDirs()).put("TEST", Collections.singleton(new File(buildDir, "playBinary/testClasses"))).build();
}
});
module.setScalaPlatform(playApplicationBinarySpec.getTargetPlatform().getScalaPlatform());
conventionMapping.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() throws Exception {
return getTargetJavaVersion(playApplicationBinarySpec);
}
});
conventionMapping.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() throws Exception {
return new IdeaLanguageLevel(getTargetJavaVersion(playApplicationBinarySpec));
}
});
ideaModule.dependsOn(playApplicationBinarySpec.getInputs());
ideaModule.dependsOn(playApplicationBinarySpec.getAssets());
}
use of org.gradle.api.JavaVersion in project gradle by gradle.
the class Project method storeBytecodeLevels.
private void storeBytecodeLevels() {
Node bytecodeLevelConfiguration = findOrCreateBytecodeLevelConfiguration();
bytecodeLevelConfiguration.attributes().put("target", bytecodeVersion.toString());
for (IdeaModule module : modules) {
List<Node> bytecodeLevelModules = getChildren(bytecodeLevelConfiguration, "module");
Node moduleNode = findFirstWithAttributeValue(bytecodeLevelModules, "name", module.getName());
JavaVersion moduleBytecodeVersionOverwrite = module.getTargetBytecodeVersion();
if (moduleBytecodeVersionOverwrite == null) {
if (moduleNode != null) {
bytecodeLevelConfiguration.remove(moduleNode);
}
} else {
if (moduleNode == null) {
moduleNode = bytecodeLevelConfiguration.appendNode("module");
moduleNode.attributes().put("name", module.getName());
}
moduleNode.attributes().put("target", moduleBytecodeVersionOverwrite.toString());
}
}
}
use of org.gradle.api.JavaVersion in project gradle by gradle.
the class EclipsePlugin method configureEclipseJdt.
private void configureEclipseJdt(final Project project, final EclipseModel model) {
final EclipsePlugin eclipsePlugin = this;
project.getPlugins().withType(JavaBasePlugin.class, new Action<JavaBasePlugin>() {
@Override
public void execute(JavaBasePlugin javaBasePlugin) {
maybeAddTask(project, eclipsePlugin, ECLIPSE_JDT_TASK_NAME, GenerateEclipseJdt.class, new Action<GenerateEclipseJdt>() {
@Override
public void execute(GenerateEclipseJdt task) {
// task properties:
task.setDescription("Generates the Eclipse JDT settings file.");
task.setOutputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
task.setInputFile(project.file(".settings/org.eclipse.jdt.core.prefs"));
// model properties:
EclipseJdt jdt = task.getJdt();
model.setJdt(jdt);
ConventionMapping conventionMapping = ((IConventionAware) jdt).getConventionMapping();
conventionMapping.map("sourceCompatibility", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility();
}
});
conventionMapping.map("targetCompatibility", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
return project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
}
});
conventionMapping.map("javaRuntimeName", new Callable<String>() {
@Override
public String call() {
return eclipseJavaRuntimeNameFor(project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility());
}
});
}
});
}
});
}
use of org.gradle.api.JavaVersion in project gradle by gradle.
the class IdeaPlugin method configureIdeaModuleForJava.
private void configureIdeaModuleForJava(final Project project) {
project.getTasks().withType(GenerateIdeaModule.class, new Action<GenerateIdeaModule>() {
@Override
public void execute(GenerateIdeaModule ideaModule) {
// Defaults
setupScopes(ideaModule);
// Convention
ConventionMapping convention = ((IConventionAware) ideaModule.getModule()).getConventionMapping();
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("main").getAllSource().getSrcDirs();
}
});
convention.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("test").getAllSource().getSrcDirs();
}
});
convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {
@Override
public Map<String, FileCollection> call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
LinkedHashMap<String, FileCollection> map = new LinkedHashMap<String, FileCollection>(2);
map.put("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
map.put("TEST", sourceSets.getByName("test").getOutput().getDirs());
return map;
}
});
convention.map("targetBytecodeVersion", new Callable<JavaVersion>() {
@Override
public JavaVersion call() {
JavaVersion moduleTargetBytecodeLevel = project.getConvention().getPlugin(JavaPluginConvention.class).getTargetCompatibility();
return includeModuleBytecodeLevelOverride(project.getRootProject(), moduleTargetBytecodeLevel) ? moduleTargetBytecodeLevel : null;
}
});
convention.map("languageLevel", new Callable<IdeaLanguageLevel>() {
@Override
public IdeaLanguageLevel call() {
IdeaLanguageLevel moduleLanguageLevel = new IdeaLanguageLevel(project.getConvention().getPlugin(JavaPluginConvention.class).getSourceCompatibility());
return includeModuleLanguageLevelOverride(project.getRootProject(), moduleLanguageLevel) ? moduleLanguageLevel : null;
}
});
// Dependencies
ideaModule.dependsOn(new Callable<FileCollection>() {
@Override
public FileCollection call() {
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets();
return sourceSets.getByName("main").getOutput().getDirs().plus(sourceSets.getByName("test").getOutput().getDirs());
}
});
}
});
}
Aggregations