Skip to content

Commit

Permalink
#11 XSD
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 19, 2017
1 parent bd622e9 commit ee54ba0
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 5 deletions.
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ The MIT License (MIT)
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/org/jpeek/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
package org.jpeek;

import com.jcabi.xml.StrictXML;
import com.jcabi.xml.XMLDocument;
import com.jcabi.xml.XSD;
import com.jcabi.xml.XSDDocument;
import java.io.IOException;
import java.nio.file.Path;
import org.cactoos.io.LengthOf;
Expand All @@ -47,6 +51,13 @@
*/
public final class App {

/**
* XSD schema.
*/
private static final XSD SCHEMA = XSDDocument.make(
App.class.getResourceAsStream("jpeek.xsd")
);

/**
* Location of the project to analyze.
*/
Expand Down Expand Up @@ -84,7 +95,12 @@ public void analyze() throws IOException {
metric -> {
new LengthOf(
new TeeInput(
new Xembler(metric.xembly()).xmlQuietly(),
new StrictXML(
new XMLDocument(
new Xembler(metric.xembly()).xmlQuietly()
),
App.SCHEMA
).toString(),
this.output.resolve(
String.format(
"%s.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jpeek.metrics.cohesion;
package org.jpeek.metrics;

import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -76,7 +76,7 @@ public final class JavassistClasses implements Metric {
* @param bse The base
* @param fnc Func
*/
JavassistClasses(final Base bse, final Func<CtClass, Double> fnc) {
public JavassistClasses(final Base bse, final Func<CtClass, Double> fnc) {
this.base = bse;
this.pool = ClassPool.getDefault();
this.func = new IoCheckedFunc<>(fnc);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jpeek/metrics/cohesion/CAMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.cactoos.iterator.Mapped;
import org.jpeek.Base;
import org.jpeek.Metric;
import org.jpeek.metrics.JavassistClasses;
import org.xembly.Directive;

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/jpeek/metrics/cohesion/LCOM.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javassist.CtClass;
import org.jpeek.Base;
import org.jpeek.Metric;
import org.jpeek.metrics.JavassistClasses;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/jpeek/metrics/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* 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.
*/

/**
* All metrics.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.3
*/
package org.jpeek.metrics;
50 changes: 50 additions & 0 deletions src/main/resources/org/jpeek/jpeek.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0"?>
<!--
The MIT License (MIT)
Copyright (c) 2017 Yegor Bugayenko
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
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.
-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="class">
<xs:attribute name="id" use="required" type="xs:string"/>
<xs:attribute name="value" use="optional" type="xs:float"/>
</xs:complexType>
<xs:complexType name="package">
<xs:sequence>
<xs:element name="class" type="class" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:string"/>
<xs:attribute name="value" use="optional" type="xs:float"/>
</xs:complexType>
<xs:element name="app">
<xs:complexType>
<xs:sequence>
<xs:element name="package" type="package" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" use="required" type="xs:string"/>
<xs:attribute name="value" use="optional" type="xs:float"/>
</xs:complexType>
<xs:unique name="packageUnique">
<xs:selector xpath="./package"/>
<xs:field xpath="@id"/>
</xs:unique>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.jpeek.metrics.cohesion;
package org.jpeek.metrics;

import java.io.IOException;
import java.nio.file.Files;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/jpeek/metrics/cohesion/CAMCTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Paths;
import org.hamcrest.MatcherAssert;
import org.jpeek.DefaultBase;
import org.jpeek.metrics.FakeBase;
import org.junit.Test;
import org.xembly.Xembler;

Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/jpeek/metrics/cohesion/LCOMTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Paths;
import org.hamcrest.MatcherAssert;
import org.jpeek.DefaultBase;
import org.jpeek.metrics.FakeBase;
import org.junit.Test;
import org.xembly.Xembler;

Expand Down
32 changes: 32 additions & 0 deletions src/test/java/org/jpeek/metrics/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* 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.
*/

/**
* All metrics, tests.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.3
*/
package org.jpeek.metrics;

0 comments on commit ee54ba0

Please sign in to comment.