Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Feb 26, 2020
2 parents f9042a7 + 6691094 commit 70ca3b8
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 56 deletions.
46 changes: 22 additions & 24 deletions src/main/java/org/jpeek/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,13 @@
* and in `MetricsTest`).
* Once they are resolved add it to reports list.
*/
@SuppressWarnings
(
{
"PMD.AvoidDuplicateLiterals",
"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"
}
)
@SuppressWarnings({
"PMD.AvoidDuplicateLiterals",
"PMD.NPathComplexity",
"PMD.CyclomaticComplexity",
"PMD.StdCyclomaticComplexity",
"PMD.ModifiedCyclomaticComplexity"
})
public final class App {

/**
Expand Down Expand Up @@ -172,115 +169,116 @@ public void analyze() throws IOException {
final XSL chain = new XSLChain(layers);
this.save(skeleton.toString(), "skeleton.xml");
final Collection<Report> reports = new LinkedList<>();
final Calculus xsl = new XslCalculus();
if (this.params.containsKey("LCOM")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"LCOM", this.params, 10.0d, -5.0d
"LCOM", this.params, xsl, 10.0d, -5.0d
)
);
}
if (this.params.containsKey("CAMC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"CAMC", this.params
"CAMC", this.params, xsl
)
);
}
if (this.params.containsKey("MMAC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"MMAC", this.params, 0.5d, 0.1d
"MMAC", this.params, xsl, 0.5d, 0.1d
)
);
}
if (this.params.containsKey("LCOM5")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"LCOM5", this.params, 0.5d, -0.1d
"LCOM5", this.params, xsl, 0.5d, -0.1d
)
);
}
if (this.params.containsKey("NHD")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"NHD"
"NHD", xsl
)
);
}
if (this.params.containsKey("LCOM2")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"LCOM2", this.params
"LCOM2", this.params, xsl
)
);
}
if (this.params.containsKey("LCOM3")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"LCOM3", this.params
"LCOM3", this.params, xsl
)
);
}
if (this.params.containsKey("SCOM")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"SCOM", this.params
"SCOM", this.params, xsl
)
);
}
if (this.params.containsKey("OCC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"OCC", this.params
"OCC", this.params, xsl
)
);
}
if (this.params.containsKey("PCC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"PCC"
"PCC", xsl
)
);
}
if (this.params.containsKey("TCC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"TCC"
"TCC", xsl
)
);
}
if (this.params.containsKey("LCC")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"LCC"
"LCC", xsl
)
);
}
if (this.params.containsKey("CCM")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"CCM"
"CCM", xsl
)
);
}
if (this.params.containsKey("MWE")) {
reports.add(
new XslReport(
chain.transform(skeleton),
"MWE"
"MWE", xsl
)
);
}
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/org/jpeek/Calculus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2019 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.
*/
package org.jpeek;

import com.jcabi.xml.XML;
import java.io.IOException;
import java.util.Map;

/**
* Metrics calculus interface.
* @since 0.30.9
* @todo #390:30min We have a separate interface to calculate XML metrics.
* We should continue to the goal defined in #296 where we should have a java
* implementation to calculate metrics. The motivation is to be able to make
* calculations impossible or too difficult to implement in xsl, like LCOM4.
*/
public interface Calculus {

/**
* Produces {@link XML} representing metrics values.
* @param metric Desired metric to calculate
* @param params Params
* @param skeleton Package input
* @return XML document giving metrics values for classes
* @throws IOException If fails
*/
XML node(String metric, Map<String, Object> params, XML skeleton)
throws IOException;

}
4 changes: 0 additions & 4 deletions src/main/java/org/jpeek/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
/**
* Report interface.
* @since 0.1
* @todo #296:30min Now that we have the infrastructure to implement
* some metrics in other means than XSL transformations. We should try
* to implement some metrics with Java. We could start with LCOM4 metric that
* implies a graph traversal algorithm.
*/
public interface Report {

Expand Down
56 changes: 56 additions & 0 deletions src/main/java/org/jpeek/XslCalculus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017-2019 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.
*/
package org.jpeek;

import com.jcabi.xml.Sources;
import com.jcabi.xml.XML;
import com.jcabi.xml.XSLDocument;
import java.io.IOException;
import java.util.Map;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.FormattedText;
import org.cactoos.text.TextOf;

/**
* Metrics xsl calculus. Use an xsl sheet to transform the input skeleton into
* the xml containing the calculation.
* @since 0.30.9
*/
public final class XslCalculus implements Calculus {

@Override
public XML node(final String metric, final Map<String, Object> params,
final XML skeleton) throws IOException {
return new XSLDocument(
new TextOf(
new ResourceOf(
new FormattedText("org/jpeek/metrics/%s.xsl", metric)
)
).asString(),
Sources.DUMMY,
params
).transform(skeleton);
}

}
46 changes: 25 additions & 21 deletions src/main/java/org/jpeek/XslReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import com.jcabi.log.Logger;
import com.jcabi.xml.ClasspathSources;
import com.jcabi.xml.Sources;
import com.jcabi.xml.StrictXML;
import com.jcabi.xml.XML;
import com.jcabi.xml.XMLDocument;
Expand All @@ -39,11 +38,8 @@
import java.util.HashMap;
import java.util.Map;
import org.cactoos.collection.CollectionOf;
import org.cactoos.io.ResourceOf;
import org.cactoos.io.TeeInput;
import org.cactoos.scalar.LengthOf;
import org.cactoos.text.FormattedText;
import org.cactoos.text.TextOf;
import org.xembly.Directives;
import org.xembly.Xembler;

Expand Down Expand Up @@ -95,6 +91,11 @@ final class XslReport implements Report {
*/
private final String metric;

/**
* Calculus.
*/
private final Calculus calculus;

/**
* Post processing XSLs.
*/
Expand All @@ -109,10 +110,11 @@ final class XslReport implements Report {
* Ctor.
* @param xml Skeleton
* @param name Name of the metric
* @param calc Calculus
*/
XslReport(final XML xml, final String name) {
XslReport(final XML xml, final String name, final Calculus calc) {
this(
xml, name, new HashMap<>(0),
xml, name, new HashMap<>(0), calc,
XslReport.DEFAULT_MEAN, XslReport.DEFAULT_SIGMA
);
}
Expand All @@ -122,10 +124,13 @@ final class XslReport implements Report {
* @param xml Skeleton
* @param name Name of metric
* @param args Params for XSL
* @param calc Calculus
* @checkstyle ParameterNumberCheck (5 lines)
*/
XslReport(final XML xml, final String name, final Map<String, Object> args) {
XslReport(final XML xml, final String name, final Map<String, Object> args,
final Calculus calc) {
this(
xml, name, args,
xml, name, args, calc,
XslReport.DEFAULT_MEAN, XslReport.DEFAULT_SIGMA
);
}
Expand All @@ -135,16 +140,24 @@ final class XslReport implements Report {
* @param xml Skeleton
* @param name Name of the metric
* @param args Params for XSL
* @param calc Calculus
* @param mean Mean
* @param sigma Sigma
* @todo #390:30min this constructor now has too many arguments. We should find a way
* to refactor the constructor or the class to have fewer parameters.
* We could start by analyzing the usage of this.params (args in this
* constructor) and get rid of it if it is not used.
* Another idea could be to have a data class contaning reporting params:
* name, args, mean, sigma.
* @checkstyle ParameterNumberCheck (10 lines)
*/
XslReport(final XML xml, final String name,
final Map<String, Object> args,
final Map<String, Object> args, final Calculus calc,
final double mean, final double sigma) {
this.skeleton = xml;
this.metric = name;
this.params = args;
this.calculus = calc;
this.post = new XSLChain(
new CollectionOf<>(
new XSLDocument(
Expand Down Expand Up @@ -227,18 +240,9 @@ private XML xml() throws IOException {
XslReport.SCHEMA_FILE
)
).applyQuietly(
new XSLDocument(
new TextOf(
new ResourceOf(
new FormattedText(
"org/jpeek/metrics/%s.xsl",
this.metric
)
)
).asString(),
Sources.DUMMY,
this.params
).transform(this.skeleton).node()
this.calculus.node(
this.metric, this.params, this.skeleton
).node()
)
);
}
Expand Down
Loading

3 comments on commit 70ca3b8

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 70ca3b8 Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 296-9cbcd906 disappeared from src/main/java/org/jpeek/Report.java, that's why I closed #390. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 70ca3b8 Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 390-2105ac60 discovered in src/main/java/org/jpeek/XslReport.java and submitted as #396. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 70ca3b8 Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 390-3f627cdf discovered in src/main/java/org/jpeek/Calculus.java and submitted as #397. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.