Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jan 24, 2019
2 parents 413d46b + 6551efa commit 48e372b
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<parent>
<groupId>com.jcabi</groupId>
<artifactId>parent</artifactId>
<version>0.40</version>
<version>0.49.3</version>
</parent>
<groupId>com.qulice</groupId>
<artifactId>qulice</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.ReplacedText;
import org.cactoos.text.TextOf;
import org.cactoos.text.TrimmedText;
import org.xml.sax.InputSource;

/**
Expand Down Expand Up @@ -168,8 +170,15 @@ private String header(final Environment env) {
final URL url = CheckstyleValidator.toUrl(env, name);
final String content;
try {
content = IOUtils.toString(url.openStream())
.trim().replaceAll("[\\r\\n]+$", "");
content = new ReplacedText(
new TrimmedText(
new TextOf(
url.openStream()
)
),
"[\\r\\n]+$",
""
).asString();
} catch (final IOException ex) {
throw new IllegalStateException("Failed to read license", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.puppycrawl.tools.checkstyle.api.AuditEvent;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
Expand Down Expand Up @@ -122,7 +123,8 @@ public void testCheckstyleTruePositive() throws Exception {
IOUtils.toString(
this.getClass().getResourceAsStream(
String.format("%s/violations.txt", this.dir)
)
),
StandardCharsets.UTF_8
),
"\n"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.io.ResourceOf;
import org.cactoos.list.ListOf;
import org.cactoos.text.FormattedText;
import org.cactoos.text.JoinedText;
import org.cactoos.text.TextOf;
import org.hamcrest.Description;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -54,6 +56,8 @@
* @todo #412:30min Split this class into smaller ones and remove PMD
* exclude `TooManyMethods`. Good candidates for moving out of this class
* are all that use `validateCheckstyle` method.
* @checkstyle ClassDataAbstractionCoupling (800 lines)
* Can also be removed after splitting up this class into smaller ones.
*/
@SuppressWarnings(
{
Expand Down Expand Up @@ -632,10 +636,11 @@ public void rejectsUppercaseAbbreviations() throws Exception {
file, false
);
final String name = "AbbreviationAsWordInNameCheck";
final String message = StringUtils.join(
"Abbreviation in name '%s' ",
final String message = new JoinedText(
" ",
"Abbreviation in name '%s'",
"must contain no more than '2' consecutive capital letters."
);
).asString();
MatcherAssert.assertThat(
results,
Matchers.hasItems(
Expand Down Expand Up @@ -788,9 +793,11 @@ private Collection<Violation> runValidation(final String file,
)
.withFile(
String.format("src/main/java/foo/%s", file),
IOUtils.toString(
this.getClass().getResourceAsStream(file)
)
new TextOf(
new ResourceOf(
new FormattedText("com/qulice/checkstyle/%s", file)
)
).asString()
);
final Collection<Violation> results =
new CheckstyleValidator(env).validate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
import com.jcabi.aspects.Tv;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.JoinedText;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
Expand Down Expand Up @@ -121,7 +122,8 @@ public File file() throws IOException {
FileUtils.forceDeleteOnExit(license);
FileUtils.writeStringToFile(
license,
StringUtils.join(this.lines, this.eol)
new JoinedText(this.eol, this.lines).asString(),
StandardCharsets.UTF_8
);
if (this.directory != null) {
this.makePackageInfo(this.directory);
Expand Down Expand Up @@ -152,7 +154,11 @@ private void makePackageInfo(final File dir) throws IOException {
.append(" */").append(this.eol)
.append("package ").append(this.pkg)
.append(';').append(this.eol);
FileUtils.writeStringToFile(info, body.toString());
FileUtils.writeStringToFile(
info,
body.toString(),
StandardCharsets.UTF_8
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ private static String excludes(final Environment env,
try {
FileUtils.writeStringToFile(
new File(path),
FindBugsValidator.generateExcludes(excludes)
FindBugsValidator.generateExcludes(excludes),
StandardCharsets.UTF_8
);
} catch (final IOException exc) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.jcabi.log.Logger;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -66,7 +67,11 @@ public BytecodeMocker withSource(final String src) {
public byte[] mock() throws IOException {
final File outdir = Files.createTempDir();
final File input = File.createTempFile("input", ".java");
FileUtils.writeStringToFile(input, this.source);
FileUtils.writeStringToFile(
input,
this.source,
StandardCharsets.UTF_8
);
final ProcessBuilder builder = new ProcessBuilder(
"javac",
"-d",
Expand All @@ -85,7 +90,10 @@ public byte[] mock() throws IOException {
throw new IllegalStateException(
String.format(
"Failed to compile '%s':%n%s", this.source,
IOUtils.toString(process.getErrorStream())
IOUtils.toString(
process.getErrorStream(),
StandardCharsets.UTF_8
)
)
);
}
Expand Down
6 changes: 6 additions & 0 deletions qulice-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
<maven.version>3.0.5</maven.version>
</properties>
<dependencies>
<dependency>
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<version>0.38</version>
</dependency>
<dependency>
<groupId>com.qulice</groupId>
<artifactId>qulice-spi</artifactId>
Expand Down Expand Up @@ -118,6 +123,7 @@
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.qulice.spi.ValidationException;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.Charsets;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ private static XML pom(final Environment env) {
"pom.xml"
)
),
Charsets.UTF_8
StandardCharsets.UTF_8
)
).registerNs("pom", "http://maven.apache.org/POM/4.0.0");
} catch (final IOException exc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
import java.io.File;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.project.MavenProject;
import org.cactoos.text.TextOf;
import org.cactoos.text.TrimmedText;
import org.cactoos.text.UncheckedText;

/**
* Check for required svn properties in all text files.
Expand Down Expand Up @@ -175,7 +177,13 @@ private static String propget(final File file, final String name) {
try {
final Process process = builder.start();
process.waitFor();
return IOUtils.toString(process.getInputStream()).trim();
return new UncheckedText(
new TrimmedText(
new TextOf(
process.getInputStream()
)
)
).asString();
} catch (final java.io.IOException ex) {
throw new IllegalArgumentException(ex);
} catch (final InterruptedException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import com.qulice.spi.Environment;
import com.qulice.spi.ResourceValidator;
import com.qulice.spi.Validator;
import java.io.File;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.context.Context;
Expand Down Expand Up @@ -89,7 +88,7 @@ public void validatesUsingAllProvidedValidators() throws Exception {
Mockito.verify(internal).validate(Mockito.any(MavenEnvironment.class));
Mockito.verify(external).validate(Mockito.any(Environment.class));
Mockito.verify(rexternal, Mockito.atLeastOnce())
.validate(Mockito.anyCollectionOf(File.class));
.validate(Mockito.anyCollection());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
package com.qulice.maven;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.cactoos.io.ResourceOf;
import org.cactoos.text.TextOf;
import org.junit.Test;

/**
Expand All @@ -54,16 +56,17 @@ public void canValidatePomWithXpath() throws Exception {
"/pom:project/pom:dependencies/pom:dependency[pom:artifactId='commons-io']/pom:version[.='1.2.5']/text()"
)
).mock();
final String pom = IOUtils.toString(
this.getClass().getResourceAsStream("PomXpathValidator/pom.xml")
);
final String pom = new TextOf(
new ResourceOf("com/qulice/maven/PomXpathValidator/pom.xml")
).asString();
FileUtils.write(
new File(
String.format(
"%s%spom.xml", env.basedir(), File.separator
)
),
pom
pom,
StandardCharsets.UTF_8
);
new PomXpathValidator().validate(env);
}
Expand Down
6 changes: 5 additions & 1 deletion qulice-pmd/src/test/java/com/qulice/pmd/PmdAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.qulice.spi.Environment;
import com.qulice.spi.Violation;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -74,14 +75,17 @@ final class PmdAssert {
/**
* Validated given file against PMD.
* @throws Exception In case of error.
* @todo #966:5min Add Cactoos dependency to qulice-pmd and replace IOUtils
* usage with Cactoos alternatives `TextOf` and `ResourceOf`
*/
public void validate() throws Exception {
final Environment.Mock mock = new Environment.Mock();
final String name = String.format("src/main/java/foo/%s", this.file);
final Environment env = mock.withFile(
name,
IOUtils.toString(
this.getClass().getResourceAsStream(this.file)
this.getClass().getResourceAsStream(this.file),
StandardCharsets.UTF_8
)
);
final Collection<Violation> violations = new PmdValidator(env).validate(
Expand Down
7 changes: 6 additions & 1 deletion qulice-spi/src/main/java/com/qulice/spi/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -191,7 +192,11 @@ public Environment.Mock withParam(final String name,
public Environment.Mock withFile(final String name,
final String content) throws IOException {
final File file = new File(this.basedir, name);
FileUtils.writeStringToFile(file, content);
FileUtils.writeStringToFile(
file,
content,
StandardCharsets.UTF_8
);
return this;
}

Expand Down

1 comment on commit 48e372b

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 48e372b Jan 24, 2019

Choose a reason for hiding this comment

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

Puzzle 966-537ebfc3 discovered in qulice-pmd/src/test/java/com/qulice/pmd/PmdAssert.java and submitted as #1009. 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.