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 30, 2024
2 parents fb289fb + d73a068 commit de102d8
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 56 deletions.
7 changes: 1 addition & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<version>1.18.32</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-xml</artifactId>
Expand Down Expand Up @@ -137,7 +132,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>org.cactoos</groupId>
Expand Down
3 changes: 2 additions & 1 deletion qulice-checkstyle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<!-- version from parent -->
<version>3.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.puppycrawl.tools.checkstyle.api.AbstractFileSetCheck;
import com.puppycrawl.tools.checkstyle.api.FileText;
import java.io.File;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;

/**
* Make sure each line indentation is either:
Expand Down Expand Up @@ -67,11 +67,12 @@ public void processFiltered(final File file, final FileText lines) {
this.log(
pos + 1,
String.format(
StringUtils.join(
new Joined(
"",
"Indentation (%d) must be same or ",
"less than previous line (%d), or ",
"bigger by exactly 4"
),
).toString(),
current,
previous
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.IoCheckedText;
import org.cactoos.text.Replaced;
import org.cactoos.text.TextOf;
Expand Down Expand Up @@ -213,10 +212,9 @@ private String header() {
throw new IllegalStateException("Failed to read license", ex);
}
final StringBuilder builder = new StringBuilder(100);
final String eol = System.getProperty("line.separator");
final String eol = System.lineSeparator();
builder.append("/*").append(eol);
for (final String line
: StringUtils.splitPreserveAllTokens(content, eol)) {
for (final String line : CheckstyleValidator.splitPreserve(content, eol)) {
builder.append(" *");
if (!line.trim().isEmpty()) {
builder.append(' ').append(line.trim());
Expand Down Expand Up @@ -261,4 +259,27 @@ private URL toUrl(final String name) {
}
return url;
}

/**
* Divide string using separators to the parts adding empty lines for
* two consistently separators.
* @param content String line
* @param separators Separators string
* @return List of line parts
*/
private static List<String> splitPreserve(final String content, final String separators) {
final List<String> tokens = new LinkedList<>();
final int len = content.length();
int ind = 0;
int start = 0;
while (ind < len) {
if (separators.indexOf(content.charAt(ind)) >= 0) {
tokens.add(content.substring(start, ind));
start = ind + 1;
}
++ind;
}
tokens.add(content.substring(start, ind));
return tokens;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

/**
* Check if the class/interface javadoc contains properly formatted author
Expand Down Expand Up @@ -190,10 +189,7 @@ private void findProhibited(final String[] lines, final int start,
if (!found.isEmpty()) {
this.log(
start + 1,
StringUtils.join(
"Prohibited ''@{0}'' tag in",
" class/interface comment"
),
"Prohibited ''@{0}'' tag in class/interface comment",
tag
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
import java.util.Properties;
import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.cactoos.text.Joined;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -73,17 +73,14 @@ void testCheckstyleTruePositive(final String dir) throws Exception {
Mockito.doAnswer(collector).when(listener)
.addError(Mockito.any(AuditEvent.class));
this.check(dir, "/Invalid.java", listener);
final String[] violations = StringUtils.split(
IOUtils.toString(
this.getClass().getResourceAsStream(
String.format("%s/violations.txt", dir)
),
StandardCharsets.UTF_8
final String[] violations = IOUtils.toString(
this.getClass().getResourceAsStream(
String.format("%s/violations.txt", dir)
),
"\n"
);
StandardCharsets.UTF_8
).split("\n");
for (final String line : violations) {
final String[] sectors = StringUtils.split(line, ":");
final String[] sectors = line.split(":");
final Integer pos = Integer.valueOf(sectors[0]);
final String needle = sectors[1].trim();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -260,7 +257,7 @@ public String summary() {
)
);
}
return StringUtils.join(msgs, "; ");
return new Joined("; ", msgs).toString();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ void catchesCheckstyleViolationsInLicense() throws Exception {
.file();
final String content =
// @checkstyle StringLiteralsConcatenation (4 lines)
// @checkstyle RegexpSingleline (1 line)
"/" + "**\n * License-3.\n *\n * License-2.\n */\n"
"/" + "*\n * License-3.\n *\n * License-2.\n */\n"
+ "package foo;\n"
+ "public class Foo { }\n";
final String name = "Foo.java";
Expand Down
5 changes: 0 additions & 5 deletions qulice-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,11 +238,6 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<!-- version from parent -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.0.1</version>
<version>2.16.0</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
package com.qulice.foo;

import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;

Expand All @@ -44,7 +45,7 @@ public final class Sample {
* @return Stream.
* @checkstyle NonStaticMethod (2 lines)
*/
public InputStream test() {
return IOUtils.toInputStream("oops");
public InputStream test() throws IOException {
return IOUtils.toInputStream("oops", "UTF-8");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
package com.qulice.foo;

import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;

Expand All @@ -44,7 +45,7 @@ public final class Sample {
* @return Stream.
* @checkstyle NonStaticMethod (2 lines)
*/
public InputStream test() {
return IOUtils.toInputStream("oops");
public InputStream test() throws IOException {
return IOUtils.toInputStream("oops", "UTF-8");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -124,15 +123,15 @@ private void run() throws ValidationException {
this,
"%s: %s[%s]: %s (%s)",
result.validator(),
StringUtils.removeStart(
result.file(),
result.file().replace(
String.format(
"%s/", this.session().getExecutionRootDirectory()
)
),
result.lines(),
result.message(),
result.name()
""
),
result.lines(),
result.message(),
result.name()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public Collection<String> asserts() {
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Collection<File> files(final String pattern) {
final Collection<File> files = new LinkedList<>();
final IOFileFilter filter = new WildcardFileFilter(pattern);
final IOFileFilter filter = WildcardFileFilter.builder().setWildcards(pattern).get();
final String[] dirs = {
"src",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
import com.qulice.spi.ValidationException;
import java.util.Collection;
import java.util.LinkedList;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzer;
import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException;
import org.cactoos.text.Joined;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void validate(final MavenEnvironment env)
this,
"Unused declared dependencies found:%s%s",
DependenciesValidator.SEP,
StringUtils.join(unused, DependenciesValidator.SEP)
new Joined(DependenciesValidator.SEP, unused).toString()
);
}
final Collection<String> used = Collections2.filter(
Expand All @@ -94,7 +94,7 @@ public void validate(final MavenEnvironment env)
this,
"Used undeclared dependencies found:%s%s",
DependenciesValidator.SEP,
StringUtils.join(used, DependenciesValidator.SEP)
new Joined(DependenciesValidator.SEP, used)
);
}
if (!used.isEmpty() || !unused.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.InvalidPluginDescriptorException;
Expand Down Expand Up @@ -105,7 +104,7 @@ public MojoExecutor(final MavenPluginManager mngr,
public void execute(final String coords, final String goal,
final Properties config) throws ValidationException {
final Plugin plugin = new Plugin();
final String[] sectors = StringUtils.split(coords, ':');
final String[] sectors = coords.split(":");
plugin.setGroupId(sectors[0]);
plugin.setArtifactId(sectors[1]);
plugin.setVersion(sectors[2]);
Expand Down
17 changes: 17 additions & 0 deletions qulice-pmd/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<groupId>com.qulice</groupId>
<artifactId>qulice-spi</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<!-- version from parent -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<!-- version from parent -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-matchers</artifactId>
Expand Down Expand Up @@ -177,6 +189,11 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<excludes combine.children="append">
<exclude>checkstyle:/src/test/resources/.*</exclude>
<exclude>pmd:.*/src/test/resources/.*</exclude>
<!-- @todo #1:5min add commons-lang3 to exception after the
next qulice version update.
commons-lang3 library is used in pmd libs and make a duplicate
-->
<exclude>duplicatefinder:</exclude>
</excludes>
</configuration>
</plugin>
Expand Down
2 changes: 1 addition & 1 deletion qulice-spi/src/main/java/com/qulice/spi/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public Collection<String> classpath() {
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public Collection<File> files(final String pattern) {
final Collection<File> files = new LinkedList<>();
final IOFileFilter filter = new WildcardFileFilter(pattern);
final IOFileFilter filter = WildcardFileFilter.builder().setWildcards(pattern).get();
for (final String dir : new String[]{"src"}) {
final File sources = new File(this.basedir(), dir);
if (sources.exists()) {
Expand Down

0 comments on commit de102d8

Please sign in to comment.