diff --git a/src/main/java/org/jpeek/web/Reports.java b/src/main/java/org/jpeek/web/Reports.java new file mode 100644 index 00000000..1b39e79b --- /dev/null +++ b/src/main/java/org/jpeek/web/Reports.java @@ -0,0 +1,118 @@ +/** + * 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. + */ +package org.jpeek.web; + +import com.jcabi.xml.XMLDocument; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Path; +import org.cactoos.BiFunc; +import org.cactoos.io.LengthOf; +import org.cactoos.io.TeeInput; +import org.cactoos.text.TextOf; +import org.jpeek.App; + +/** + * Project badge. + * + *

There is no thread-safety guarantee. + * + * @author Yegor Bugayenko (yegor256@gmail.com) + * @version $Id$ + * @since 0.7 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + */ +final class Reports implements BiFunc { + + /** + * Directory with sources. + */ + private final Path sources; + + /** + * Directory with reports. + */ + private final Path target; + + /** + * Ctor. + * @param home Home dir + */ + Reports(final Path home) { + this(home.resolve("sources"), home.resolve("target")); + } + + /** + * Ctor. + * @param input Dir with sources + * @param output Dir with reports + */ + Reports(final Path input, final Path output) { + this.sources = input; + this.target = output; + } + + @Override + public Path apply(final String group, final String artifact) + throws IOException { + final String grp = group.replace(".", "/"); + final String version = new XMLDocument( + new TextOf( + new URL( + String.format( + // @checkstyle LineLength (1 line) + "http://repo1.maven.org/maven2/%s/%s/maven-metadata.xml", + grp, artifact + ) + ) + ).asString() + ).xpath("/metadata/versioning/latest/text()").get(0); + final Path input = this.sources.resolve(grp).resolve(artifact); + final String name = String.format("%s-%s.jar", artifact, version); + new LengthOf( + new TeeInput( + new URL( + String.format( + "http://repo1.maven.org/maven2/%s/%s/%s/%s", + grp, artifact, version, name + ) + ), + input.resolve(name) + ) + ).value(); + try { + new ProcessBuilder() + .directory(input.toFile()) + .command("unzip", name) + .start() + .waitFor(); + } catch (final InterruptedException ex) { + throw new IllegalStateException(ex); + } + final Path output = this.target.resolve(grp).resolve(artifact); + new App(input, output).analyze(); + return output; + } + +} diff --git a/src/main/java/org/jpeek/web/TkApp.java b/src/main/java/org/jpeek/web/TkApp.java index e1222b5a..357e2fb9 100644 --- a/src/main/java/org/jpeek/web/TkApp.java +++ b/src/main/java/org/jpeek/web/TkApp.java @@ -26,6 +26,10 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import org.cactoos.BiFunc; +import org.cactoos.func.StickyBiFunc; +import org.cactoos.func.SyncBiFunc; +import org.takes.Take; import org.takes.facets.fork.FkRegex; import org.takes.facets.fork.TkFork; import org.takes.http.Exit; @@ -47,17 +51,10 @@ public final class TkApp extends TkWrap { /** * Ctor. - * @param dir Home directory + * @param home Home directory */ - public TkApp(final Path dir) { - super( - new TkFork( - new FkRegex( - "/([^/]+)/([^/]+)(.*)", - new TkReport(dir) - ) - ) - ); + public TkApp(final Path home) { + super(TkApp.make(home)); } /** @@ -72,4 +69,23 @@ public static void main(final String... args) throws IOException { ).start(Exit.NEVER); } + /** + * Make it. + * @param home Home directory + * @return The take + */ + private static Take make(final Path home) { + final BiFunc reports = new StickyBiFunc<>( + new SyncBiFunc<>( + new Reports(home) + ) + ); + return new TkFork( + new FkRegex( + "/([^/]+)/([^/]+)(.*)", + new TkReport(reports) + ) + ); + } + } diff --git a/src/main/java/org/jpeek/web/TkReport.java b/src/main/java/org/jpeek/web/TkReport.java index e33e149f..217e074a 100644 --- a/src/main/java/org/jpeek/web/TkReport.java +++ b/src/main/java/org/jpeek/web/TkReport.java @@ -23,18 +23,12 @@ */ package org.jpeek.web; -import com.jcabi.xml.XMLDocument; import java.io.IOException; -import java.net.URL; import java.nio.file.Path; import java.util.regex.Matcher; +import org.cactoos.BiFunc; import org.cactoos.func.IoCheckedBiFunc; -import org.cactoos.func.StickyBiFunc; -import org.cactoos.func.SyncBiFunc; -import org.cactoos.io.LengthOf; -import org.cactoos.io.TeeInput; import org.cactoos.text.TextOf; -import org.jpeek.App; import org.takes.Response; import org.takes.facets.fork.RqRegex; import org.takes.facets.fork.TkRegex; @@ -50,46 +44,19 @@ * @since 0.5 * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ -public final class TkReport implements TkRegex { - - /** - * Directory with sources. - */ - private final Path sources; - - /** - * Directory with reports. - */ - private final Path target; +final class TkReport implements TkRegex { /** * Maker or reports. */ - private final IoCheckedBiFunc reports; + private final BiFunc reports; /** * Ctor. - * @param home Home dir + * @param rpts Reports */ - public TkReport(final Path home) { - this(home.resolve("sources"), home.resolve("target")); - } - - /** - * Ctor. - * @param input Dir with sources - * @param output Dir with reports - */ - public TkReport(final Path input, final Path output) { - this.sources = input; - this.target = output; - this.reports = new IoCheckedBiFunc<>( - new StickyBiFunc<>( - new SyncBiFunc<>( - this::home - ) - ) - ); + TkReport(final BiFunc rpts) { + this.reports = rpts; } @Override @@ -104,7 +71,7 @@ public Response act(final RqRegex req) throws IOException { } return new RsHtml( new TextOf( - this.reports.apply( + new IoCheckedBiFunc<>(this.reports).apply( matcher.group(1), matcher.group(2) ).resolve(path) @@ -112,52 +79,4 @@ public Response act(final RqRegex req) throws IOException { ); } - /** - * Make report and return its path. - * @param group Maven group - * @param artifact Maven artiface - * @return Path to the report files - * @throws IOException If fails - */ - private Path home(final String group, final String artifact) - throws IOException { - final String grp = group.replace(".", "/"); - final String version = new XMLDocument( - new TextOf( - new URL( - String.format( - // @checkstyle LineLength (1 line) - "http://repo1.maven.org/maven2/%s/%s/maven-metadata.xml", - grp, artifact - ) - ) - ).asString() - ).xpath("/metadata/versioning/latest/text()").get(0); - final Path input = this.sources.resolve(grp).resolve(artifact); - final String name = String.format("%s-%s.jar", artifact, version); - new LengthOf( - new TeeInput( - new URL( - String.format( - "http://repo1.maven.org/maven2/%s/%s/%s/%s", - grp, artifact, version, name - ) - ), - input.resolve(name) - ) - ).value(); - try { - new ProcessBuilder() - .directory(input.toFile()) - .command("unzip", name) - .start() - .waitFor(); - } catch (final InterruptedException ex) { - throw new IllegalStateException(ex); - } - final Path output = this.target.resolve(grp).resolve(artifact); - new App(input, output).analyze(); - return output; - } - } diff --git a/src/main/resources/org/jpeek/index.xsl b/src/main/resources/org/jpeek/index.xsl index e1fc86be..dd6fc880 100644 --- a/src/main/resources/org/jpeek/index.xsl +++ b/src/main/resources/org/jpeek/index.xsl @@ -179,7 +179,10 @@ SOFTWARE. "Score" is a weighted average of the numbers from the "Green," "Yellow," and "Red" columns; the weight of green classes is 1.0, yellow ones get 0.25, - and red ones get 0.05. + and red ones get 0.05; if the color of the number is + green, the quality is high enough, if it's orange the quality + is average, if it's red, the quality is too low, for this + particular metric.

This report was generated by