diff --git a/src/main/java/org/jpeek/Report.java b/src/main/java/org/jpeek/Report.java index 1c4998fe..d64adc10 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,37 @@ final class Report { * @param mean Mean * @param sigma Sigma * @checkstyle ParameterNumberCheck (10 lines) + * @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, final Map args, final double mean, final double sigma) { this.skeleton = xml; this.metric = name; - this.params = args; + this.params = new MapOf<>( + args, + new MapEntry<>("schemaLocation", Report.SCHEMA_FILE) + ); this.post = new XSLChain( new CollectionOf<>( + new XSLDocument( + new UncheckedText( + new TextOf( + new InputOf( + 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 7cf26379..d176ecec 100644 --- a/src/main/resources/org/jpeek/xsd/index.xsd +++ b/src/main/resources/org/jpeek/xsd/index.xsd @@ -26,6 +26,9 @@ SOFTWARE. @todo #134:30min Index.xsd: add `xsd:documentation` tags as per issue #134. We need to 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 + 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 3749e740..c966ff8c 100644 --- a/src/main/resources/org/jpeek/xsd/matrix.xsd +++ b/src/main/resources/org/jpeek/xsd/matrix.xsd @@ -26,6 +26,9 @@ SOFTWARE. @todo #134:30min Matrix.xsd: add `xsd:documentation` tags as per issue #134. We need to 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 + matrix.xml. Schemas from src/resources/org/jpeek/xsd must be referenced in + generated XMLs. --> diff --git a/src/main/resources/org/jpeek/xsd/skeleton.xsd b/src/main/resources/org/jpeek/xsd/skeleton.xsd index 5d46936a..ae6e6579 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']" + ) + ); + } }