Skip to content

Commit

Permalink
#30 Reports
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 27, 2017
1 parent a98f47c commit 4dbdae1
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 99 deletions.
118 changes: 118 additions & 0 deletions src/main/java/org/jpeek/web/Reports.java
Original file line number Diff line number Diff line change
@@ -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.
*
* <p>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<String, String, Path> {

/**
* 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;
}

}
36 changes: 26 additions & 10 deletions src/main/java/org/jpeek/web/TkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand All @@ -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<String, String, Path> reports = new StickyBiFunc<>(
new SyncBiFunc<>(
new Reports(home)
)
);
return new TkFork(
new FkRegex(
"/([^/]+)/([^/]+)(.*)",
new TkReport(reports)
)
);
}

}
95 changes: 7 additions & 88 deletions src/main/java/org/jpeek/web/TkReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, String, Path> reports;
private final BiFunc<String, String, Path> 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<String, String, Path> rpts) {
this.reports = rpts;
}

@Override
Expand All @@ -104,60 +71,12 @@ 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)
).asString()
);
}

/**
* 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;
}

}
5 changes: 4 additions & 1 deletion src/main/resources/org/jpeek/index.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ SOFTWARE.
<xsl:text>"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. </xsl:text>
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. </xsl:text>
</p>
<p style="color:gray;font-size:75%;">
<xsl:text>This report was generated by </xsl:text>
Expand Down

0 comments on commit 4dbdae1

Please sign in to comment.