Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 6.1 checkstyle report finalizer failure #1176

Merged
merged 16 commits into from
Jan 23, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/@unreleased/pr-1176.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: fix
fix:
description: Errors of the form `The value for Report xml property 'required' is
final and cannot be changed any further.` in Gradle 6.1 are now fixed for the
`com.palantir.junit-reports` plugin.
links:
- https://github.com/palantir/gradle-baseline/pull/1176
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* (c) Copyright 2020 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.baseline

import nebula.test.IntegrationSpec
import nebula.test.functional.ExecutionResult
import spock.lang.Unroll

@Unroll
class JunitReportsPluginSpec extends IntegrationSpec {
private static final List<String> GRADLE_TEST_VERSIONS = ['5.6.4', '6.1']

def '#gradleVersionNumber: configures the checkstlye plugin correctly'() {
setup:
gradleVersion = gradleVersionNumber

when:
buildFile << '''
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'com.palantir.junit-reports'

repositories {
jcenter()
}
'''.stripIndent()

file('src/main/java/foo/Foo.java') << '''
package foo;
public class Foo {}
'''.stripIndent()

ExecutionResult executionResult = runTasks('checkstyleMain')

then:
// Running checkstyle inside nebula does not work as there are classpath problems that result in the `groovy-all`
// not being on Gradle's classpath. So the best we can do to verify that the checkstyle actually ran is to
// verify we get the classpath error that happens when the checkstyle class runs :(
// https://github.com/gradle/gradle/issues/3995
executionResult.standardError.contains 'java.lang.ClassNotFoundException: groovy.util.AntBuilder'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to just not use nebula for this one test? i.e. to go through all the ProjectBuilder stuff manually?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can run with a specified gradle version without using nebula?

Copy link
Contributor Author

@CRogers CRogers Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also happens in gradle test kit and the other 3rd party gradleTest framework :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@robert3005 robert3005 Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if you disable debug it will not cause issues. Gradle test runner debug mode is a little too magical on your classpath

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I gave using testkit/ProjectBuilder directly a go and I just couldn't get it to work (kept saying the existing code worked on Gradle 6.1) :( So this (or no test) may have to suffice.


where:
gradleVersionNumber << GRADLE_TEST_VERSIONS
}
}
1 change: 1 addition & 0 deletions gradle-junit-reports/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies {
testCompile 'junit:junit'
testCompile 'org.assertj:assertj-core'
testCompile 'org.mockito:mockito-core'
testImplementation 'com.netflix.nebula:nebula-test'
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import org.w3c.dom.Document;

Expand Down Expand Up @@ -61,6 +62,7 @@ public static void registerFinalizer(
@Inject
public JunitReportsFinalizer() {}

@Input
public final Task getStyleTask() {
return styleTask;
}
Expand All @@ -69,6 +71,7 @@ public final void setStyleTask(Task styleTask) {
this.styleTask = styleTask;
}

@Input
public final TaskTimer getTaskTimer() {
return taskTimer;
}
Expand All @@ -77,6 +80,7 @@ public final void setTaskTimer(TaskTimer taskTimer) {
this.taskTimer = taskTimer;
}

@Input
public final FailuresSupplier getFailuresSupplier() {
return failuresSupplier;
}
Expand All @@ -85,10 +89,12 @@ public final void setFailuresSupplier(FailuresSupplier failuresSupplier) {
this.failuresSupplier = failuresSupplier;
}

@Input
public final RegularFileProperty getTargetFile() {
return targetFile;
}

@Input
public final DirectoryProperty getReportDir() {
return reportDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.UUID;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.reporting.ReportContainer;
import org.gradle.api.reporting.Reporting;
Expand All @@ -33,13 +34,13 @@ public final class XmlReportFailuresSupplier implements FailuresSupplier {
public static <T extends Task & Reporting<? extends ReportContainer<SingleFileReport>>>
XmlReportFailuresSupplier create(final T task, final ReportHandler<T> reportHandler) {
// Ensure any necessary output is enabled
task.doFirst(new Action<Task>() {
task.getProject().afterEvaluate(new Action<Project>() {
@Override
@SuppressWarnings("StrictUnusedVariable")
public void execute(Task ignored) {
public void execute(Project _project) {
reportHandler.configureTask(task);
}
});

return new XmlReportFailuresSupplier(task, reportHandler);
}

Expand Down