From 5e0d616c86470c4564facf457671fba543f5c02d Mon Sep 17 00:00:00 2001 From: Geoffrey Challen Date: Sun, 3 Feb 2019 10:19:32 -0600 Subject: [PATCH] Prevent checkstyle from failing the entire build. --- .idea/dictionaries/challen.xml | 8 ++++++++ .idea/encodings.xml | 4 ++++ .../cs/cs125/gradlegrader/GradePlugin.groovy | 15 +++++++++++--- .../cs/cs125/gradlegrader/GradeTask.groovy | 20 ++++++++++++++++++- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 .idea/dictionaries/challen.xml create mode 100644 .idea/encodings.xml diff --git a/.idea/dictionaries/challen.xml b/.idea/dictionaries/challen.xml new file mode 100644 index 0000000..b4e1dd0 --- /dev/null +++ b/.idea/dictionaries/challen.xml @@ -0,0 +1,8 @@ + + + + autograder + testsuites + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradePlugin.groovy b/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradePlugin.groovy index 20c5287..6e5b78d 100644 --- a/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradePlugin.groovy +++ b/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradePlugin.groovy @@ -14,11 +14,13 @@ import org.yaml.snakeyaml.Yaml */ class GradePlugin implements Plugin { + @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) @@ -40,12 +42,14 @@ class GradePlugin implements Plugin { 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, @@ -129,6 +133,7 @@ class GradePlugin implements Plugin { 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]) @@ -190,8 +195,12 @@ class GradePlugin implements Plugin { outputs.upToDateWhen { false } } } + try { + project.rootProject.tasks.checkstyleMain.execute() + } catch (Exception ignored) { } } } + allTasks.each { t -> t.mustRunAfter(reconfigureForGrading) } diff --git a/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradeTask.groovy b/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradeTask.groovy index 1349b4a..26a3ab3 100644 --- a/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradeTask.groovy +++ b/src/main/groovy/edu/illinois/cs/cs125/gradlegrader/GradeTask.groovy @@ -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 @@ -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='') { @@ -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 {