From 23e5c58d0bf2b0e5c66e34e76e9b37cdea34159b Mon Sep 17 00:00:00 2001 From: George Aristy Date: Sun, 18 Feb 2018 10:09:33 -0400 Subject: [PATCH 1/4] (#135) Added schema location to metric.xml --- src/main/java/org/jpeek/Report.java | 34 +++++++++++++++- src/main/resources/org/jpeek/xsd/index.xsd | 5 +++ src/main/resources/org/jpeek/xsd/matrix.xsd | 5 +++ src/main/resources/org/jpeek/xsd/skeleton.xsd | 5 +++ .../org/jpeek/xsl/metric-post-schemaloc.xsl | 40 +++++++++++++++++++ src/test/java/org/jpeek/ReportTest.java | 14 +++++++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl diff --git a/src/main/java/org/jpeek/Report.java b/src/main/java/org/jpeek/Report.java index 1c4998fe..b9822849 100644 --- a/src/main/java/org/jpeek/Report.java +++ b/src/main/java/org/jpeek/Report.java @@ -39,9 +39,13 @@ import java.util.HashMap; import java.util.Map; import org.cactoos.collection.CollectionOf; +import org.cactoos.io.InputOf; import org.cactoos.io.LengthOf; import org.cactoos.io.TeeInput; +import org.cactoos.map.MapEntry; +import org.cactoos.map.MapOf; import org.cactoos.text.TextOf; +import org.cactoos.text.UncheckedText; /** * Single report. @@ -63,11 +67,16 @@ final class Report { */ private static final double DEFAULT_SIGMA = 0.1d; + /** + * Location to the schema file. + */ + private static final String SCHEMA_FILE = "xsd/metric.xsd"; + /** * XSD schema. */ private static final XSD SCHEMA = XSDDocument.make( - Report.class.getResourceAsStream("xsd/metric.xsd") + Report.class.getResourceAsStream(Report.SCHEMA_FILE) ); /** @@ -130,15 +139,36 @@ final class Report { * @param mean Mean * @param sigma Sigma * @checkstyle ParameterNumberCheck (10 lines) + * @todo #135:30min Make Report save 'metric.xsd' itself. Currently, Report + * is setting the schema's location on the output metric XML based on the + * assumption that App will always save it to a relative subdirectory + * 'xsd' and with the same filename 'metric.xsd'. This promise is best + * kept if Report class has the responsibility of saving metric.xsd itself. */ + @SuppressWarnings("unchecked") Report(final XML xml, final String name, final Map args, final double mean, final double sigma) { this.skeleton = xml; this.metric = name; - this.params = args; + this.params = new MapOf<>( + // @checkstyle LineLength (1 line) + args, new MapEntry<>("schemaLocation", Report.SCHEMA_FILE) + ); this.post = new XSLChain( new CollectionOf<>( + new XSLDocument( + new UncheckedText( + new TextOf( + new InputOf( + // @checkstyle LineLength (1 line) + Report.class.getResourceAsStream("xsl/metric-post-schemaloc.xsl") + ) + ) + ).asString(), + Sources.DUMMY, + this.params + ), new XSLDocument( Report.class.getResourceAsStream( "xsl/metric-post-colors.xsl" diff --git a/src/main/resources/org/jpeek/xsd/index.xsd b/src/main/resources/org/jpeek/xsd/index.xsd index e2d7a8d2..2047875c 100644 --- a/src/main/resources/org/jpeek/xsd/index.xsd +++ b/src/main/resources/org/jpeek/xsd/index.xsd @@ -22,6 +22,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> + diff --git a/src/main/resources/org/jpeek/xsd/matrix.xsd b/src/main/resources/org/jpeek/xsd/matrix.xsd index c55a3b2f..89e8bedd 100644 --- a/src/main/resources/org/jpeek/xsd/matrix.xsd +++ b/src/main/resources/org/jpeek/xsd/matrix.xsd @@ -22,6 +22,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> + diff --git a/src/main/resources/org/jpeek/xsd/skeleton.xsd b/src/main/resources/org/jpeek/xsd/skeleton.xsd index 030ddbe0..88318797 100644 --- a/src/main/resources/org/jpeek/xsd/skeleton.xsd +++ b/src/main/resources/org/jpeek/xsd/skeleton.xsd @@ -22,6 +22,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> + diff --git a/src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl b/src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl new file mode 100644 index 00000000..40508c5e --- /dev/null +++ b/src/main/resources/org/jpeek/xsl/metric-post-schemaloc.xsl @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/jpeek/ReportTest.java b/src/test/java/org/jpeek/ReportTest.java index 688bda0d..f92155c7 100644 --- a/src/test/java/org/jpeek/ReportTest.java +++ b/src/test/java/org/jpeek/ReportTest.java @@ -135,4 +135,18 @@ public void createsFullXmlReport() throws IOException { ); } + @Test + public void setsCorrectschemaLocation() throws IOException { + final Path output = Files.createTempDirectory(""); + new Report(new Skeleton(new FakeBase()).xml(), "LCOM").save(output); + MatcherAssert.assertThat( + XhtmlMatchers.xhtml( + new TextOf(output.resolve("LCOM.xml")).asString() + ), + XhtmlMatchers.hasXPaths( + // @checkstyle LineLength (1 line) + "/metric[@xsi:noNamespaceSchemaLocation = 'xsd/metric.xsd']" + ) + ); + } } From e745f72277cc60844dbee8411605a476e305dae8 Mon Sep 17 00:00:00 2001 From: George Aristy Date: Tue, 20 Feb 2018 14:06:28 -0400 Subject: [PATCH 2/4] (#135) Added schema location to metric.xml As per PR review: * fixed indentation in Report.java --- src/main/java/org/jpeek/Report.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jpeek/Report.java b/src/main/java/org/jpeek/Report.java index b9822849..bd05407e 100644 --- a/src/main/java/org/jpeek/Report.java +++ b/src/main/java/org/jpeek/Report.java @@ -152,8 +152,8 @@ final class Report { this.skeleton = xml; this.metric = name; this.params = new MapOf<>( - // @checkstyle LineLength (1 line) - args, new MapEntry<>("schemaLocation", Report.SCHEMA_FILE) + args, + new MapEntry<>("schemaLocation", Report.SCHEMA_FILE) ); this.post = new XSLChain( new CollectionOf<>( @@ -161,8 +161,9 @@ final class Report { new UncheckedText( new TextOf( new InputOf( - // @checkstyle LineLength (1 line) - Report.class.getResourceAsStream("xsl/metric-post-schemaloc.xsl") + Report.class.getResourceAsStream( + "xsl/metric-post-schemaloc.xsl" + ) ) ) ).asString(), From 8811e77064c38b8e083326420a257ce426e915a6 Mon Sep 17 00:00:00 2001 From: George Aristy Date: Wed, 21 Feb 2018 09:38:49 -0400 Subject: [PATCH 3/4] (#135) Added schema location to metric.xml Fixed typos --- src/main/resources/org/jpeek/xsd/index.xsd | 2 +- src/main/resources/org/jpeek/xsd/matrix.xsd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/org/jpeek/xsd/index.xsd b/src/main/resources/org/jpeek/xsd/index.xsd index 322697e1..d176ecec 100644 --- a/src/main/resources/org/jpeek/xsd/index.xsd +++ b/src/main/resources/org/jpeek/xsd/index.xsd @@ -27,7 +27,7 @@ SOFTWARE. document the schemas in src/resources/org/jpeek/xsd so that the semantics of the generated XML documents is transparent for maintainers. @todo #135:30min Index.xsd: add a reference to this schema from the generated - skeleton.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in + index.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in generated XMLs. --> diff --git a/src/main/resources/org/jpeek/xsd/matrix.xsd b/src/main/resources/org/jpeek/xsd/matrix.xsd index 8a25ee4c..c966ff8c 100644 --- a/src/main/resources/org/jpeek/xsd/matrix.xsd +++ b/src/main/resources/org/jpeek/xsd/matrix.xsd @@ -27,7 +27,7 @@ SOFTWARE. document the schemas in src/resources/org/jpeek/xsd so that the semantics of the generated XML documents is transparent for maintainers. @todo #135:30min Matrix.xsd: add a reference to this schema from the generated - skeleton.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in + matrix.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in generated XMLs. --> From 752b4d52b6a0c293e8a71cd4ca902b3656fcf43e Mon Sep 17 00:00:00 2001 From: George Aristy Date: Tue, 27 Feb 2018 12:50:55 -0400 Subject: [PATCH 4/4] (#135) Added schema location to metric.xml As per ARC review: * Left puzzle for further refactor towards simpler solution --- src/main/java/org/jpeek/Report.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jpeek/Report.java b/src/main/java/org/jpeek/Report.java index bd05407e..d64adc10 100644 --- a/src/main/java/org/jpeek/Report.java +++ b/src/main/java/org/jpeek/Report.java @@ -139,11 +139,11 @@ final class Report { * @param mean Mean * @param sigma Sigma * @checkstyle ParameterNumberCheck (10 lines) - * @todo #135:30min Make Report save 'metric.xsd' itself. Currently, Report - * is setting the schema's location on the output metric XML based on the - * assumption that App will always save it to a relative subdirectory - * 'xsd' and with the same filename 'metric.xsd'. This promise is best - * kept if Report class has the responsibility of saving metric.xsd itself. + * @todo #135:30min The current solution to add the reference to + * 'metric.xsd' in the generated 'metric.xml' is too complex for + * the task at hand. Refactor towards a simpler solution that + * ideally would just require one or two Xembly instructions to + * add the required attribute. */ @SuppressWarnings("unchecked") Report(final XML xml, final String name,