Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Prevent checkstyle from failing the entire build.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Feb 3, 2019
1 parent 7f905c6 commit 5e0d616
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .idea/dictionaries/challen.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import org.yaml.snakeyaml.Yaml
*/
class GradePlugin implements Plugin<Project> {

@SuppressWarnings("UnstableApiUsage")
void apply(Project project) {
project.tasks.register('grade', GradeTask) { gradeTask ->
register(project, gradeTask)
}
}

void register(Project project, GradeTask gradeTask) {
def extension = project.extensions.create('grade', GradePluginExtension, project)

Expand All @@ -40,12 +42,14 @@ class GradePlugin implements Plugin<Project> {

if (gradeConfiguration.checkstyle) {
gradeTask.addListener(project.rootProject.tasks.checkstyleMain)
gradeTask.dependsOn(project.rootProject.tasks.checkstyleMain)
}

if (gradeConfiguration.files) {
if (gradeConfiguration.checkstyle && !project.tasks.hasProperty('checkstyleMain')) {
throw new GradleException("checkstyle is configured for grading but not in build.gradle")
if (gradeConfiguration.checkstyle) {
if (!project.tasks.hasProperty('checkstyleMain')) {
throw new GradleException("checkstyle is configured for grading but not in build.gradle")
}
gradeTask.dependsOn(project.rootProject.tasks.checkstyleMain)
}

[project.tasks.processResources,
Expand Down Expand Up @@ -129,6 +133,7 @@ class GradePlugin implements Plugin<Project> {
gradeTask.addListener(testTask)
if (project.hasProperty("grade.secure") && gradeConfiguration.secure) {
gradeConfiguration.secureRun = true
//noinspection SpellCheckingInspection
testTask.jvmArgs("-Djava.security.manager=net.sourceforge.prograde.sm.ProGradeJSM")
testTask.jvmArgs("-Djava.security.policy=" + (String) gradeConfiguration.secure)
testTask.systemProperties(["main.sources": project.sourceSets.main.java.outputDir])
Expand Down Expand Up @@ -190,8 +195,12 @@ class GradePlugin implements Plugin<Project> {
outputs.upToDateWhen { false }
}
}
try {
project.rootProject.tasks.checkstyleMain.execute()
} catch (Exception ignored) { }
}
}

allTasks.each { t ->
t.mustRunAfter(reconfigureForGrading)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import org.gradle.api.GradleException
import org.gradle.api.logging.StandardOutputListener
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskAction
import org.xml.sax.ErrorHandler
import org.xml.sax.SAXException
import org.xml.sax.SAXParseException

import javax.xml.parsers.DocumentBuilderFactory

import static javax.xml.xpath.XPathConstants.BOOLEAN

Expand All @@ -34,7 +39,19 @@ class GradeTask extends DefaultTask {
* @return a DOM object representing the data in the file.
*/
def static openXML(path) {
return DOMBuilder.parse(new StringReader(path.text), false, false).documentElement
def documentBuilderFactory = DocumentBuilderFactory.newInstance()
documentBuilderFactory.setValidating(false)
documentBuilderFactory.setNamespaceAware(false)
def documentBuilder = documentBuilderFactory.newDocumentBuilder()
documentBuilder.setErrorHandler(new ErrorHandler() {
@Override
void warning(SAXParseException exception) throws SAXException { }
@Override
void error(SAXParseException exception) throws SAXException { }
@Override
void fatalError(SAXParseException exception) throws SAXException { }
})
return documentBuilder.parse(path).documentElement
}

def static fill(text, width=78, prefix='') {
Expand Down Expand Up @@ -231,6 +248,7 @@ class GradeTask extends DefaultTask {
* Investigate checkstyle results.
*/
def toKeep = []

if (gradeConfiguration.checkstyle) {
def checkstyleResultsPath = project.tasks.checkstyleMain.getReports().getXml().getDestination()
try {
Expand Down

0 comments on commit 5e0d616

Please sign in to comment.