Search in sources :

Example 6 with JavaVersion

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();
    }
}
Also used : TestResultSerializer(org.gradle.api.internal.tasks.testing.junit.result.TestResultSerializer) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) TestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.TestResultsProvider) InMemoryTestResultsProvider(org.gradle.api.internal.tasks.testing.junit.result.InMemoryTestResultsProvider) HashMap(java.util.HashMap) TestResultProcessor(org.gradle.api.internal.tasks.testing.TestResultProcessor) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) TestClassResult(org.gradle.api.internal.tasks.testing.junit.result.TestClassResult) TestCountLogger(org.gradle.api.internal.tasks.testing.logging.TestCountLogger) StateTrackingTestResultProcessor(org.gradle.api.internal.tasks.testing.results.StateTrackingTestResultProcessor) JavaVersion(org.gradle.api.JavaVersion) LogLevel(org.gradle.api.logging.LogLevel) TestEventLogger(org.gradle.api.internal.tasks.testing.logging.TestEventLogger) TestReportDataCollector(org.gradle.api.internal.tasks.testing.junit.result.TestReportDataCollector) StartParameter(org.gradle.StartParameter) TestOutputAssociation(org.gradle.api.internal.tasks.testing.junit.result.TestOutputAssociation) TestLogging(org.gradle.api.tasks.testing.logging.TestLogging) NoMatchingTestsReporter(org.gradle.api.internal.tasks.testing.NoMatchingTestsReporter) UnsupportedJavaRuntimeException(org.gradle.internal.jvm.UnsupportedJavaRuntimeException) TestListenerAdapter(org.gradle.api.internal.tasks.testing.results.TestListenerAdapter) DefaultTestExecuter(org.gradle.api.internal.tasks.testing.detection.DefaultTestExecuter) Binary2JUnitXmlReportGenerator(org.gradle.api.internal.tasks.testing.junit.result.Binary2JUnitXmlReportGenerator) TestOutputStore(org.gradle.api.internal.tasks.testing.junit.result.TestOutputStore) TestExceptionFormatter(org.gradle.api.internal.tasks.testing.logging.TestExceptionFormatter) File(java.io.File) DefaultTestReport(org.gradle.api.internal.tasks.testing.junit.report.DefaultTestReport) DirectoryReport(org.gradle.api.reporting.DirectoryReport) TaskAction(org.gradle.api.tasks.TaskAction)

Example 7 with JavaVersion

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());
}
Also used : Action(org.gradle.api.Action) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) Set(java.util.Set) CollectionUtils(org.gradle.util.CollectionUtils) IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) GenerateIdeaModule(org.gradle.plugins.ide.idea.GenerateIdeaModule) IdeaModule(org.gradle.plugins.ide.idea.model.IdeaModule) LanguageSourceSet(org.gradle.language.base.LanguageSourceSet) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Mutate(org.gradle.model.Mutate)

Example 8 with JavaVersion

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());
        }
    }
}
Also used : Node(groovy.util.Node) JavaVersion(org.gradle.api.JavaVersion)

Example 9 with JavaVersion

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());
                        }
                    });
                }
            });
        }
    });
}
Also used : EclipseJdt(org.gradle.plugins.ide.eclipse.model.EclipseJdt) Action(org.gradle.api.Action) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) JavaBasePlugin(org.gradle.api.plugins.JavaBasePlugin) IConventionAware(org.gradle.api.internal.IConventionAware)

Example 10 with JavaVersion

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());
                }
            });
        }
    });
}
Also used : IdeaLanguageLevel(org.gradle.plugins.ide.idea.model.IdeaLanguageLevel) FileCollection(org.gradle.api.file.FileCollection) JavaVersion(org.gradle.api.JavaVersion) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) File(java.io.File)

Aggregations

JavaVersion (org.gradle.api.JavaVersion)11 File (java.io.File)4 ConventionMapping (org.gradle.api.internal.ConventionMapping)4 IdeaLanguageLevel (org.gradle.plugins.ide.idea.model.IdeaLanguageLevel)4 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)3 IdeaModule (org.gradle.plugins.ide.idea.model.IdeaModule)3 IdeaProject (org.gradle.plugins.ide.idea.model.IdeaProject)3 LinkedHashMap (java.util.LinkedHashMap)2 Action (org.gradle.api.Action)2 Project (org.gradle.api.Project)2 IConventionAware (org.gradle.api.internal.IConventionAware)2 DefaultIdeaJavaLanguageSettings (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaJavaLanguageSettings)2 DefaultIdeaLanguageLevel (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaLanguageLevel)2 DefaultIdeaModule (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaModule)2 DefaultIdeaProject (org.gradle.plugins.ide.internal.tooling.idea.DefaultIdeaProject)2 Predicate (com.google.common.base.Predicate)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Node (groovy.util.Node)1 HashMap (java.util.HashMap)1 List (java.util.List)1