From 31d9ce7e4c2f68675f5abb32abb3333c035b3eac Mon Sep 17 00:00:00 2001 From: Eric Le Goff Date: Tue, 18 Jan 2022 16:16:08 +0100 Subject: [PATCH 1/2] fix issues --- .../communityrust/xunit/StaxParser.java | 75 +++++++------------ .../plugins/communityrust/xunit/TestCase.java | 34 ++++++--- .../communityrust/xunit/XUnitSensor.java | 2 - .../communityrust/xunit/XUnitSensorTest.java | 3 - 4 files changed, 53 insertions(+), 61 deletions(-) diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java index 3bd65476..bf990f4e 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java @@ -3,86 +3,69 @@ * Copyright (C) 2021 Eric Le Goff * mailto:community-rust AT pm DOT me * http://github.com/elegoff/sonar-rust - * + *

* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package org.elegoff.plugins.communityrust.xunit; -import org.apache.commons.lang.StringUtils; import org.codehaus.staxmate.SMInputFactory; import org.codehaus.staxmate.in.SMHierarchicCursor; import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLResolver; import javax.xml.stream.XMLStreamException; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -public class StaxParser { - private SMInputFactory inf; +public class StaxParser { - private XmlStreamHandler streamHandler; + private SMInputFactory inf; - public StaxParser(XmlStreamHandler streamHandler) { - this.streamHandler = streamHandler; - XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); + private XmlStreamHandler streamHandler; - inf = new SMInputFactory(xmlFactory); - } + public StaxParser(XmlStreamHandler streamHandler) { + this.streamHandler = streamHandler; + XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); - public void parse(File xmlFile) throws XMLStreamException { - try (FileInputStream input = new FileInputStream(xmlFile)) { - parse(input); - } catch (IOException e) { - throw new XMLStreamException(e); + inf = new SMInputFactory(xmlFactory); } - } - public void parse(InputStream xmlInput) throws XMLStreamException { - SMHierarchicCursor rootCursor = inf.rootElementCursor(xmlInput); - try { - streamHandler.stream(rootCursor); - } finally { - rootCursor.getStreamReader().closeCompletely(); + public void parse(File xmlFile) throws XMLStreamException { + try (FileInputStream input = new FileInputStream(xmlFile)) { + parse(input); + } catch (IOException e) { + throw new XMLStreamException(e); + } } - } - private static class UndeclaredEntitiesXMLResolver implements XMLResolver { - - @Override - public Object resolveEntity(String arg0, String arg1, String fileName, String undeclaredEntity) throws XMLStreamException { - String undeclared = undeclaredEntity; - // avoid problems with XML docs containing undeclared entities.. return the entity under its raw form if not a Unicode expression - if (StringUtils.startsWithIgnoreCase(undeclaredEntity, "u") && undeclaredEntity.length() == 5) { - int unicodeCharHexValue = Integer.parseInt(undeclaredEntity.substring(1), 16); - if (Character.isDefined(unicodeCharHexValue)) { - undeclared = new String(new char[] {(char) unicodeCharHexValue}); + public void parse(InputStream xmlInput) throws XMLStreamException { + SMHierarchicCursor rootCursor = inf.rootElementCursor(xmlInput); + try { + streamHandler.stream(rootCursor); + } finally { + rootCursor.getStreamReader().closeCompletely(); } - } - return undeclared; } - } - /** - * Simple interface for handling XML stream to parse. - */ - @FunctionalInterface - public interface XmlStreamHandler { - void stream(SMHierarchicCursor rootCursor) throws XMLStreamException; - } + /** + * Simple interface for handling XML stream to parse. + */ + @FunctionalInterface + public interface XmlStreamHandler { + void stream(SMHierarchicCursor rootCursor) throws XMLStreamException; + } } \ No newline at end of file diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java index b0ac6c33..74b01295 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java @@ -3,17 +3,17 @@ * Copyright (C) 2021 Eric Le Goff * mailto:community-rust AT pm DOT me * http://github.com/elegoff/sonar-rust - * + *

* This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + *

* You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -37,15 +37,11 @@ public class TestCase { /** * Constructs a testcase instance out of following parameters - * @param name The name of this testcase * @param status The execution status of the testcase - * @param stackTrace The stack trace occurred while executing of this testcase; pass "" if the testcase passed/skipped. - * @param errorMessage The error message associated with this testcase of the execution was erroneous; pass "" if not. * @param time The execution time in milliseconds * @param file The optional file to which this test case applies. - * @param testClassname The classname of the test. */ - public TestCase(String name, TestCaseStatus status, String stackTrace, String errorMessage, int time, @Nullable String file, @Nullable String testClassname) { + public TestCase(String name, TestCaseStatus status, String stackTrace, String errorMessage, int time, @Nullable String file, @Nullable String testClassname) { this.name = name; this.status = status; this.stackTrace = stackTrace; @@ -54,16 +50,18 @@ public TestCase(String name, TestCaseStatus status, String stackTrace, String er this.file = file; this.testClassname = testClassname; } + /** * Returns true if this testcase is an error, false otherwise */ - public boolean isError(){ + public boolean isError() { return TestCaseStatus.ERROR.equals(status); } + /** * Returns true if this testcase is a failure, false otherwise */ - public boolean isFailure(){ + public boolean isFailure() { return TestCaseStatus.FAILURE.equals(status); } @@ -82,6 +80,22 @@ public String getFile() { return file; } + public String getName() { + return name; + } + + public TestCaseStatus getStatus() { + return status; + } + + public String getStackTrace() { + return stackTrace; + } + + public String getErrorMessage() { + return errorMessage; + } + public String getTestClassname() { return testClassname; } diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/XUnitSensor.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/XUnitSensor.java index 9c42db7b..55ed855a 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/XUnitSensor.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/XUnitSensor.java @@ -50,7 +50,6 @@ public void describe(SensorDescriptor descriptor) { .name("XUnit Sensor for Rust") .onlyOnLanguage(RustLanguage.KEY) .onlyOnFileType(InputFile.Type.MAIN); - ; } @Override @@ -64,7 +63,6 @@ public void execute(SensorContext context) { processReports(context, reports); } catch (Exception e) { LOG.warn("Cannot read report '{}', the following exception occurred: {}", reportPath, e.getMessage()); - e.printStackTrace(); } } diff --git a/community-rust-plugin/src/test/java/org/elegoff/plugins/communityrust/xunit/XUnitSensorTest.java b/community-rust-plugin/src/test/java/org/elegoff/plugins/communityrust/xunit/XUnitSensorTest.java index d4aaab1d..9d91115a 100644 --- a/community-rust-plugin/src/test/java/org/elegoff/plugins/communityrust/xunit/XUnitSensorTest.java +++ b/community-rust-plugin/src/test/java/org/elegoff/plugins/communityrust/xunit/XUnitSensorTest.java @@ -46,9 +46,6 @@ public class XUnitSensorTest { @Rule public LogTester logTester = new LogTester(); - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); - @Before public void init() { From ab162927ba98a9c94e39afa487c5a55dcbfa0e4d Mon Sep 17 00:00:00 2001 From: Eric Le Goff Date: Tue, 18 Jan 2022 16:16:53 +0100 Subject: [PATCH 2/2] license formatting --- .../elegoff/plugins/communityrust/RustTokensVisitor.java | 6 +++--- .../org/elegoff/plugins/communityrust/xunit/StaxParser.java | 6 +++--- .../org/elegoff/plugins/communityrust/xunit/TestCase.java | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/RustTokensVisitor.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/RustTokensVisitor.java index 3fcdf090..3a7adf27 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/RustTokensVisitor.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/RustTokensVisitor.java @@ -3,17 +3,17 @@ * Copyright (C) 2021 Eric Le Goff * mailto:community-rust AT pm DOT me * http://github.com/elegoff/sonar-rust - *

+ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - *

+ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java index bf990f4e..10a495b8 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/StaxParser.java @@ -3,17 +3,17 @@ * Copyright (C) 2021 Eric Le Goff * mailto:community-rust AT pm DOT me * http://github.com/elegoff/sonar-rust - *

+ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - *

+ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java index 74b01295..4257418d 100644 --- a/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java +++ b/community-rust-plugin/src/main/java/org/elegoff/plugins/communityrust/xunit/TestCase.java @@ -3,17 +3,17 @@ * Copyright (C) 2021 Eric Le Goff * mailto:community-rust AT pm DOT me * http://github.com/elegoff/sonar-rust - *

+ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. - *

+ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - *

+ * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.