Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Mar 6, 2024
2 parents 2fd9096 + 298fc0f commit 89fdad1
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 125 deletions.
187 changes: 62 additions & 125 deletions src/main/java/org/jpeek/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
import com.jcabi.xml.XSLDocument;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
import java.util.Map;
import java.util.Objects;
import org.cactoos.io.ResourceOf;
import org.cactoos.io.TeeInput;
import org.cactoos.list.ListOf;
Expand Down Expand Up @@ -91,6 +93,7 @@ public final class App {

/**
* Ctor.
* @param source Source directory
* @param target Target dir
*/
Expand Down Expand Up @@ -118,6 +121,7 @@ public App(final Path source, final Path target) {

/**
* Ctor.
* @param source Source directory
* @param target Target dir
* @param args XSL params
Expand All @@ -131,6 +135,7 @@ public App(final Path source, final Path target,

/**
* Analyze sources.
* @throws IOException If fails
* @todo #452:30min Extract report building
* Analyze method is too big. We need to extract report building from
Expand All @@ -144,8 +149,6 @@ public App(final Path source, final Path target,
})
public void analyze() throws IOException {
final long start = System.currentTimeMillis();
final Base base = new DefaultBase(this.input);
final XML skeleton = new Skeleton(base).xml();
final Collection<XSL> layers = new LinkedList<>();
if (this.params.containsKey("include-ctors")) {
Logger.debug(this, "Constructors will be included");
Expand All @@ -165,130 +168,8 @@ public void analyze() throws IOException {
layers.add(App.xsl("layers/no-private-methods.xsl"));
Logger.debug(this, "Private methods will be ignored");
}
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), xsl,
new ReportData("LCOM", this.params, 10.0d, -5.0d)
)
);
}
if (this.params.containsKey("CAMC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("CAMC", this.params)
)
);
}
if (this.params.containsKey("MMAC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("MMAC", this.params, 0.5d, 0.1d)
)
);
}
if (this.params.containsKey("LCOM5")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("LCOM5", this.params, 0.5d, -0.1d)
)
);
}
if (this.params.containsKey("LCOM4")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("LCOM4", this.params, 0.5d, -0.1d)
)
);
}
if (this.params.containsKey("NHD")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("NHD")
)
);
}
if (this.params.containsKey("LCOM2")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("LCOM2", this.params)
)
);
}
if (this.params.containsKey("LCOM3")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("LCOM3", this.params)
)
);
}
if (this.params.containsKey("SCOM")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("SCOM", this.params)
)
);
}
if (this.params.containsKey("OCC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("OCC", this.params)
)
);
}
if (this.params.containsKey("PCC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("PCC")
)
);
}
if (this.params.containsKey("TCC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("TCC")
)
);
}
if (this.params.containsKey("LCC")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("LCC")
)
);
}
if (this.params.containsKey("CCM")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("CCM")
)
);
}
if (this.params.containsKey("MWE")) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData("MWE")
)
);
}
this.buildReport(layers, reports);
new IoChecked<>(
new AndInThreads(
report -> report.save(this.output),
Expand Down Expand Up @@ -358,8 +239,60 @@ public void analyze() throws IOException {
).value();
}

/**
* Create report.
* @param layers Collection of layers
* @param reports Resulting report
* @throws IOException If fails
*/
private void buildReport(final Collection<XSL> layers, final Collection<Report> reports)
throws IOException {
final Base base = new DefaultBase(this.input);
final XML skeleton = new Skeleton(base).xml();
final XSL chain = new XSLChain(layers);
final Calculus xsl = new XslCalculus();
this.save(skeleton.toString(), "skeleton.xml");
Arrays.stream(Metrics.values())
.filter(
metric -> this.params.containsKey(metric.name())
)
.forEach(
metric -> {
if (Objects.nonNull(metric.getSigma())) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData(
metric.name(),
this.params,
metric.getMean(),
metric.getSigma()
)
)
);
} else if (metric.isIncludeParams()) {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData(metric.name(), this.params)
)
);
} else {
reports.add(
new XslReport(
chain.transform(skeleton), xsl,
new ReportData(metric.name())
)
);
}
}
);
}

/**
* Copy resource.
* @param name The name of resource
* @throws IOException If fails
*/
Expand All @@ -376,6 +309,7 @@ private void copy(final String name) throws IOException {

/**
* Copy XSL.
* @param name The name of resource
* @return TRUE if copied
* @throws IOException If fails
Expand All @@ -387,6 +321,7 @@ private boolean copyXsl(final String name) throws IOException {

/**
* Copy XSL.
* @param name The name of resource
* @return TRUE if copied
* @throws IOException If fails
Expand All @@ -398,6 +333,7 @@ private boolean copyXsd(final String name) throws IOException {

/**
* Save file.
* @param data Content
* @param name The name of destination file
* @throws IOException If fails
Expand All @@ -415,6 +351,7 @@ private void save(final String data, final String name) throws IOException {

/**
* Make XSL.
* @param name The name of XSL file
* @return XSL document
*/
Expand Down
Loading

0 comments on commit 89fdad1

Please sign in to comment.