diff --git a/pom.xml b/pom.xml index 383b1eff10..2fd0382650 100644 --- a/pom.xml +++ b/pom.xml @@ -143,6 +143,11 @@ com.google.guava guava + + org.cactoos + cactoos + 0.25.3 + xml-apis xml-apis @@ -503,6 +508,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + diff --git a/src/main/java/com/rultor/agents/IndexesRequests.java b/src/main/java/com/rultor/agents/IndexesRequests.java index 92d006f873..3afd8d358a 100644 --- a/src/main/java/com/rultor/agents/IndexesRequests.java +++ b/src/main/java/com/rultor/agents/IndexesRequests.java @@ -29,13 +29,14 @@ */ package com.rultor.agents; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Ordering; import com.rultor.spi.SuperAgent; import com.rultor.spi.Talk; import com.rultor.spi.Talks; import java.io.IOException; +import org.cactoos.collection.Mapped; +import org.cactoos.list.SolidList; +import org.cactoos.scalar.MaxOf; +import org.cactoos.scalar.NumberOf; import org.xembly.Directives; /** @@ -83,20 +84,18 @@ private int index(final Talks talks) throws IOException { * @throws IOException if the content of the {@link Talk} object can't be * read */ + @SuppressWarnings("PMD.AvoidCatchingThrowable") private int index(final Talk talk) throws IOException { - final Iterable indexes = Iterables.transform( + final SolidList indexes = new SolidList<>( + new Mapped<>( + input -> new NumberOf(input), talk.read() - .xpath("/talk/archive/log/@index|/talk/request/@index"), - new Function() { - @Override - public Integer apply(final String input) { - return Integer.parseInt(input); - } - } + .xpath("/talk/archive/log/@index|/talk/request/@index") + ) ); final int index; if (indexes.iterator().hasNext()) { - index = Ordering.natural().max(indexes); + index = new MaxOf(indexes).intValue(); } else { index = 0; } diff --git a/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java b/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java index 2cf02060b9..6fe51cd529 100644 --- a/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java +++ b/src/main/java/com/rultor/agents/daemons/ArchivesDaemon.java @@ -30,7 +30,6 @@ package com.rultor.agents.daemons; import com.amazonaws.services.s3.model.ObjectMetadata; -import com.google.common.base.Joiner; import com.jcabi.aspects.Immutable; import com.jcabi.log.Logger; import com.jcabi.s3.Bucket; @@ -53,6 +52,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.input.NullInputStream; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.text.JoinedText; import org.xembly.Directive; import org.xembly.Directives; @@ -92,7 +92,8 @@ public Iterable process(final XML xml) throws IOException { final File file = File.createTempFile("rultor", ".log"); final String dir = xml.xpath("/talk/daemon/dir/text()").get(0); new Shell.Safe(shell).exec( - Joiner.on("; ").join( + new JoinedText( + "; ", String.format("if [ -d %s ]", SSH.escape(dir)), String.format("then cd %s", SSH.escape(dir)), "else echo 'Build directory is absent, internal error'", @@ -104,7 +105,7 @@ public Iterable process(final XML xml) throws IOException { "then cat stdout | iconv -f utf-8 -t utf-8 -c | LANG=en_US.UTF-8 col -bx", "else echo 'Stdout not found, internal error'", "fi" - ), + ).asString(), new NullInputStream(0L), new FileOutputStream(file), Logger.stream(Level.WARNING, this) diff --git a/src/main/java/com/rultor/agents/daemons/EndsDaemon.java b/src/main/java/com/rultor/agents/daemons/EndsDaemon.java index 42aaafc253..e9e96846ce 100644 --- a/src/main/java/com/rultor/agents/daemons/EndsDaemon.java +++ b/src/main/java/com/rultor/agents/daemons/EndsDaemon.java @@ -29,12 +29,6 @@ */ package com.rultor.agents.daemons; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; import com.jcabi.log.Logger; @@ -44,10 +38,17 @@ import com.rultor.agents.AbstractAgent; import com.rultor.agents.shells.TalkShells; import java.io.IOException; -import java.util.Collection; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.lang3.StringUtils; +import org.cactoos.Text; +import org.cactoos.collection.Mapped; +import org.cactoos.iterable.Filtered; +import org.cactoos.iterable.Skipped; +import org.cactoos.list.SolidList; +import org.cactoos.text.JoinedText; +import org.cactoos.text.SplitText; +import org.cactoos.text.TextOf; import org.xembly.Directive; import org.xembly.Directives; import org.xembly.Xembler; @@ -110,34 +111,35 @@ public Iterable process(final XML xml) throws IOException { private Iterable end(final Shell shell, final String dir) throws IOException { final int exit = EndsDaemon.exit(shell, dir); - final Collection lines = Lists.newArrayList( - Splitter.on(System.lineSeparator()).split( - EndsDaemon.stdout(shell, dir) + final SolidList lines = new SolidList<>( + new SplitText( + System.lineSeparator(), + new TextOf( + EndsDaemon.stdout(shell, dir) + ) ) ); - final String highlights = Joiner.on("\n").join( - Iterables.transform( - Iterables.filter( - lines, - new Predicate() { - @Override - public boolean apply(final String input) { - return input.startsWith( - EndsDaemon.HIGHLIGHTS_PREFIX - ); - } - } - ), - new Function() { - @Override - public String apply(final String str) { - return StringUtils.removeStart( - str, EndsDaemon.HIGHLIGHTS_PREFIX - ); - } - } + final SolidList linesAsString = new SolidList<>( + new Mapped<>( + line -> line.asString(), + lines ) ); + final String highlights = new JoinedText( + "\n", + new Mapped<>( + s -> StringUtils.removeStart( + s.asString(), + EndsDaemon.HIGHLIGHTS_PREFIX + ), + new Filtered<>( + input -> input.asString().startsWith( + EndsDaemon.HIGHLIGHTS_PREFIX + ), + lines + ) + ) + ).asString(); Logger.info(this, "daemon finished at %s, exit: %d", dir, exit); return new Directives() .xpath("/talk/daemon") @@ -149,12 +151,13 @@ public String apply(final String str) { .set( Xembler.escape( StringUtils.substring( - Joiner.on(System.lineSeparator()).join( - Iterables.skip( - lines, - Math.max(lines.size() - Tv.SIXTY, 0) + new JoinedText( + System.lineSeparator(), + new Skipped<>( + Math.max(lines.size() - Tv.SIXTY, 0), + linesAsString ) - ), + ).asString(), -Tv.HUNDRED * Tv.THOUSAND ) ) @@ -197,7 +200,8 @@ private static CharSequence stdout(final Shell shell, final String dir) return new ShellCommand( shell, dir, - Joiner.on(';').join( + new JoinedText( + ";", "size=$(stat -c%s stdout)", String.format("if [ $size -gt %d ]", max), "then echo \"Output is too big ($size bytes)\"", @@ -205,7 +209,7 @@ private static CharSequence stdout(final Shell shell, final String dir) String.format("tail -c %d stdout", max), "else cat stdout", "fi" - ) + ).asString() ).exec(); } diff --git a/src/main/java/com/rultor/agents/daemons/Script.java b/src/main/java/com/rultor/agents/daemons/Script.java index 454e6c3138..f0900b1dfe 100644 --- a/src/main/java/com/rultor/agents/daemons/Script.java +++ b/src/main/java/com/rultor/agents/daemons/Script.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.daemons; -import com.google.common.base.Joiner; import com.jcabi.aspects.Immutable; import com.jcabi.log.Logger; import com.jcabi.ssh.SSH; @@ -40,6 +39,7 @@ import java.util.logging.Level; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.text.JoinedText; /** * Script to run. @@ -85,14 +85,15 @@ public int exec(final XML xml) throws IOException { Logger.stream(Level.WARNING, this) ); return new Shell.Empty(shell).exec( - Joiner.on(" && ").join( + new JoinedText( + " && ", "set -o pipefail", String.format("cd %s", SSH.escape(dir)), String.format( "/bin/bash %s >> stdout 2>&1", SSH.escape(this.name) ) - ) + ).asString() ); } diff --git a/src/main/java/com/rultor/agents/daemons/ShellCommand.java b/src/main/java/com/rultor/agents/daemons/ShellCommand.java index a89b765b41..5f41b52e65 100644 --- a/src/main/java/com/rultor/agents/daemons/ShellCommand.java +++ b/src/main/java/com/rultor/agents/daemons/ShellCommand.java @@ -29,11 +29,11 @@ */ package com.rultor.agents.daemons; -import com.google.common.base.Joiner; import com.jcabi.aspects.Immutable; import com.jcabi.ssh.SSH; import com.jcabi.ssh.Shell; import java.io.IOException; +import org.cactoos.text.JoinedText; /** * Command to run in a given shell and working directory. @@ -84,10 +84,11 @@ final class ShellCommand { */ public String exec() throws IOException { return new Shell.Plain(new Shell.Safe(this.shell)).exec( - Joiner.on(ShellCommand.SHELL_JOINER).join( + new JoinedText( + ShellCommand.SHELL_JOINER, String.format("cd %s", SSH.escape(this.directory)), this.command - ) + ).asString() ); } diff --git a/src/main/java/com/rultor/agents/daemons/StartsDaemon.java b/src/main/java/com/rultor/agents/daemons/StartsDaemon.java index 7c2a59680b..c5a3f6cb80 100644 --- a/src/main/java/com/rultor/agents/daemons/StartsDaemon.java +++ b/src/main/java/com/rultor/agents/daemons/StartsDaemon.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.daemons; -import com.google.common.base.Joiner; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.RetryOnFailure; import com.jcabi.log.Logger; @@ -55,6 +54,7 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.NullInputStream; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.text.JoinedText; import org.xembly.Directive; import org.xembly.Directives; @@ -127,7 +127,8 @@ public String run(final XML xml) throws IOException { new Shell.Safe(shell).exec( String.format("cd %s; cat > run.sh", SSH.escape(dir)), IOUtils.toInputStream( - Joiner.on('\n').join( + new JoinedText( + "\n", "#!/bin/bash", "set -x", "set -e", @@ -148,20 +149,21 @@ public String run(final XML xml) throws IOException { "uptime", this.upload(shell, dir), daemon.xpath("script/text()").get(0) - ), + ).asString(), CharEncoding.UTF_8 ), Logger.stream(Level.INFO, this), Logger.stream(Level.WARNING, this) ); new Shell.Empty(new Shell.Safe(shell)).exec( - Joiner.on(" && ").join( + new JoinedText( + " && ", String.format("cd %s", SSH.escape(dir)), "chmod a+x run.sh", "echo 'run.sh failed to start' > stdout", // @checkstyle LineLength (1 line) "( ( nohup ./run.sh stdout 2>&1; echo $? >status ) /dev/null & )" - ) + ).asString() ); Logger.info(this, "daemon started at %s", dir); return dir; @@ -210,6 +212,7 @@ private String upload(final Shell shell, final String dir) * @param dir Dir * @throws IOException If fails */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private void gpg(final Shell shell, final String dir) throws IOException { final Collection entries = this.profile.read().nodes( "/p/entry[@key='decrypt']/entry" @@ -218,11 +221,12 @@ private void gpg(final Shell shell, final String dir) throws IOException { final String[] names = {"pubring.gpg", "secring.gpg"}; for (final String name : names) { shell.exec( - Joiner.on(" && ").join( + new JoinedText( + " && ", String.format("cd %s ", SSH.escape(dir)), "mkdir -p .gpg", String.format("cat > \".gpg/%s\"", name) - ), + ).asString(), this.ring(name), Logger.stream(Level.INFO, true), Logger.stream(Level.WARNING, true) diff --git a/src/main/java/com/rultor/agents/github/Answer.java b/src/main/java/com/rultor/agents/github/Answer.java index 5d04e0335f..f1df0a5177 100644 --- a/src/main/java/com/rultor/agents/github/Answer.java +++ b/src/main/java/com/rultor/agents/github/Answer.java @@ -29,26 +29,25 @@ */ package com.rultor.agents.github; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; import com.jcabi.github.Comment; +import com.jcabi.github.Comment.Smart; import com.jcabi.github.Issue; import com.jcabi.github.Smarts; import com.jcabi.log.Logger; import java.io.IOException; import java.util.Collection; -import java.util.Collections; import java.util.Date; -import java.util.List; import java.util.Locale; import java.util.TreeSet; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.lang3.StringUtils; +import org.cactoos.iterable.Mapped; +import org.cactoos.iterable.Reversed; +import org.cactoos.list.SolidList; +import org.cactoos.text.JoinedText; import org.xembly.Xembler; /** @@ -68,6 +67,11 @@ public final class Answer { */ private static final int MAX = 5; + /** + * Space char. + */ + private static final String SPACE = " "; + /** * Original comment. */ @@ -91,10 +95,13 @@ public Answer(final Comment.Smart cmt) { public void post(final boolean success, final String msg, final Object... args) throws IOException { final Issue issue = this.comment.issue(); - final List comments = Lists.newArrayList( - new Smarts(issue.comments().iterate(new Date(0L))) + final SolidList comments = new SolidList<>( + new Reversed<>( + new Smarts( + issue.comments().iterate(new Date(0L)) + ) + ) ); - Collections.reverse(comments); final String self = issue.repo().github().users().self().login(); int mine = 0; for (final Comment.Smart cmt : comments) { @@ -127,7 +134,7 @@ private String msg(final boolean success, final String text) { String.format( "> %s\n\n", StringUtils.abbreviate( - this.comment.body().replaceAll("\\p{Space}", " "), + this.comment.body().replaceAll("\\p{Space}", SPACE), Tv.HUNDRED ) ) @@ -140,19 +147,15 @@ private String msg(final boolean success, final String text) { ); } msg.append( - Joiner.on(' ').join( - Iterables.transform( - logins, - new Function() { - @Override - public String apply(final String login) { - return String.format( - "@%s", login.toLowerCase(Locale.ENGLISH) - ); - } - } + new JoinedText( + SPACE, + new Mapped<>( + login -> String.format( + "@%s", login.toLowerCase(Locale.ENGLISH) + ), + logins ) - ) + ).asString() ); msg.append(' ').append(text); // @checkstyle IllegalCatchCheck (1 line) diff --git a/src/main/java/com/rultor/agents/github/CommitsLog.java b/src/main/java/com/rultor/agents/github/CommitsLog.java index be221bd3d5..42a7bf1344 100644 --- a/src/main/java/com/rultor/agents/github/CommitsLog.java +++ b/src/main/java/com/rultor/agents/github/CommitsLog.java @@ -29,13 +29,11 @@ */ package com.rultor.agents.github; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; import com.jcabi.github.Repo; import com.jcabi.github.RepoCommit; +import com.jcabi.github.RepoCommit.Smart; import com.jcabi.github.Smarts; import java.io.IOException; import java.text.DateFormat; @@ -43,10 +41,14 @@ import java.util.Collection; import java.util.Date; import java.util.LinkedList; -import java.util.List; import java.util.Locale; +import java.util.Map; import java.util.TimeZone; import javax.json.JsonObject; +import org.cactoos.list.SolidList; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; +import org.cactoos.text.JoinedText; /** * Log of commits. @@ -84,6 +86,7 @@ final class CommitsLog { * @return Release body text. * @throws IOException In case of problem communicating with git. */ + @SuppressWarnings("PMD.UseConcurrentHashMap") public String build(final Date prev, final Date current) throws IOException { final DateFormat format = new SimpleDateFormat( @@ -91,12 +94,11 @@ public String build(final Date prev, final Date current) ); format.setTimeZone(TimeZone.getTimeZone("UTC")); final Collection lines = new LinkedList<>(); - final ImmutableMap params = - new ImmutableMap.Builder() - .put("since", format.format(prev)) - .put("until", format.format(current)) - .build(); - final List commits = Lists.newArrayList( + final Map params = new SolidMap( + new MapEntry("since", format.format(prev)), + new MapEntry("until", format.format(current)) + ); + final SolidList commits = new SolidList<>( new Smarts( this.repo.commits().iterate(params) ) @@ -115,7 +117,10 @@ public String build(final Date prev, final Date current) lines.add(CommitsLog.asText(commit)); ++count; } - return Joiner.on('\n').join(lines); + return new JoinedText( + "\n", + lines + ).asString(); } /** diff --git a/src/main/java/com/rultor/agents/github/Understands.java b/src/main/java/com/rultor/agents/github/Understands.java index ec360faed7..6633eb73c3 100644 --- a/src/main/java/com/rultor/agents/github/Understands.java +++ b/src/main/java/com/rultor/agents/github/Understands.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.github.Bulk; import com.jcabi.github.Comment; @@ -49,6 +48,7 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.cactoos.iterable.Joined; import org.xembly.Directive; import org.xembly.Directives; @@ -109,7 +109,7 @@ public Iterable process(final XML xml) throws IOException { final Issue.Smart issue = new TalkIssues(this.github, xml).get(); final Iterator comments = new SafeIterator<>( new Smarts( - Iterables.concat( + new Joined( Collections.singleton(new FirstComment(issue)), new Bulk<>(issue.comments().iterate(new Date(0L))) ) diff --git a/src/main/java/com/rultor/agents/github/qtn/QnAskedBy.java b/src/main/java/com/rultor/agents/github/qtn/QnAskedBy.java index a8e362e7d4..bb1cde6405 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnAskedBy.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnAskedBy.java @@ -29,9 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Repo; @@ -48,6 +45,8 @@ import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.lang3.StringUtils; +import org.cactoos.iterable.Filtered; +import org.cactoos.iterable.Mapped; /** * Question asked by one of them. @@ -129,22 +128,12 @@ public Req understand(final Comment.Smart comment, private String commandersAsDelimitedList(final Collection logins, final String excluded) { return StringUtils.join( - Iterables.transform( - Iterables.filter( - logins, - new Predicate() { - @Override - public boolean apply(final Object input) { - return !excluded.equals(input); - } - } - ), - new Function() { - @Override - public Object apply(final String input) { - return String.format("@%s", input); - } - } + new Mapped<>( + input -> String.format("@%s", input), + new Filtered<>( + login -> !excluded.equals(login), + logins + ) ), ", " ); diff --git a/src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java b/src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java index a2a322492f..0a39bde764 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnByArchitect.java @@ -29,8 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.base.Function; -import com.google.common.collect.Lists; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.rultor.agents.github.Answer; @@ -39,11 +37,12 @@ import com.rultor.spi.Profile; import java.io.IOException; import java.net.URI; -import java.util.List; import java.util.Locale; import java.util.ResourceBundle; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.iterable.Mapped; +import org.cactoos.list.SolidList; /** * Question by architect only (if configured). @@ -95,14 +94,11 @@ public QnByArchitect(final Profile prof, final String path, public Req understand(final Comment.Smart comment, final URI home) throws IOException { final Req req; - final List logins = Lists.transform( - this.profile.read().xpath(this.xpath), - new Function() { - @Override - public String apply(final String input) { - return input.toLowerCase(Locale.ENGLISH); - } - } + final SolidList logins = new SolidList<>( + new Mapped<>( + input -> input.toLowerCase(Locale.ENGLISH), + this.profile.read().xpath(this.xpath) + ) ); final boolean legal = logins.isEmpty() || logins.contains( comment.author().login().toLowerCase(Locale.ENGLISH) diff --git a/src/main/java/com/rultor/agents/github/qtn/QnDeploy.java b/src/main/java/com/rultor/agents/github/qtn/QnDeploy.java index a7fc2f86d3..4a9ead2b73 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnDeploy.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnDeploy.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.collect.ImmutableMap; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Issue; @@ -43,6 +42,8 @@ import java.util.ResourceBundle; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; /** * Deploy request. @@ -81,16 +82,18 @@ public Req understand(final Comment.Smart comment, ); return new Req.Simple( "deploy", - new ImmutableMap.Builder() - .put("head_branch", "master") - .put( + new SolidMap( + new MapEntry( + "head_branch", "master" + ), + new MapEntry<>( "head", String.format( "git@github.com:%s.git", repo.coordinates() ) ) - .build() + ) ); } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnGithubIssue.java b/src/main/java/com/rultor/agents/github/qtn/QnGithubIssue.java index 353c97ad86..c2cfad9117 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnGithubIssue.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnGithubIssue.java @@ -29,12 +29,12 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.collect.Iterables; import com.jcabi.github.Comment; import com.rultor.agents.github.Question; import com.rultor.agents.github.Req; import java.io.IOException; import java.net.URI; +import org.cactoos.list.SolidList; import org.xembly.Directive; import org.xembly.Directives; @@ -64,8 +64,9 @@ public QnGithubIssue(final Question question) { public Req understand(final Comment.Smart comment, final URI home) throws IOException { Req req = this.origin.understand(comment, home); - if (!Iterables.isEmpty(req.dirs())) { - final Directives dirs = new Directives().append(req.dirs()); + final SolidList reqDirs = new SolidList<>(req.dirs()); + if (!reqDirs.isEmpty()) { + final Directives dirs = new Directives().append(reqDirs); req = new Req() { @Override public Iterable dirs() { diff --git a/src/main/java/com/rultor/agents/github/qtn/QnIfUnlocked.java b/src/main/java/com/rultor/agents/github/qtn/QnIfUnlocked.java index 0017df4d0e..959f38061f 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnIfUnlocked.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnIfUnlocked.java @@ -29,9 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Contents; @@ -51,6 +48,8 @@ import lombok.ToString; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.iterable.Mapped; +import org.cactoos.text.JoinedText; /** * If target branch is unlocked. @@ -104,17 +103,13 @@ public Req understand(final Comment.Smart comment, false, QnIfUnlocked.PHRASES.getString("QnIfUnlocked.denied"), branch, - Joiner.on(", ").join( - Iterables.transform( - guards, - new Function() { - @Override - public String apply(final String input) { - return String.format("@%s", input); - } - } + new JoinedText( + ", ", + new Mapped<>( + input -> String.format("@%s", input), + guards ) - ) + ).asString() ); req = Req.EMPTY; } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnLock.java b/src/main/java/com/rultor/agents/github/qtn/QnLock.java index dbd95c8dd0..607ad3b4dd 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnLock.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnLock.java @@ -29,10 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Contents; @@ -55,6 +51,8 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringUtils; +import org.cactoos.iterable.Mapped; +import org.cactoos.text.JoinedText; import org.xembly.Directive; import org.xembly.Directives; import org.xembly.Xembler; @@ -97,21 +95,16 @@ public Req understand(final Comment.Smart comment, users.add(comment.author().login().toLowerCase(Locale.ENGLISH)); if (!args.nodes("//arg[@name='users']").isEmpty()) { users.addAll( - Collections2.transform( + new org.cactoos.list.Mapped<>( + input -> StringUtils.stripStart( + input.trim().toLowerCase(Locale.ENGLISH), + "@" + ), Arrays.asList( args.xpath( "//arg[@name='users']/text()" ).get(0).split(",") - ), - new Function() { - @Override - public String apply(final String input) { - return StringUtils.stripStart( - input.trim().toLowerCase(Locale.ENGLISH), - "@" - ); - } - } + ) ) ); } @@ -140,9 +133,10 @@ public String apply(final String input) { .add( "content", Base64.encodeBase64String( - Joiner.on("\n").join(users).getBytes( - CharEncoding.UTF_8 - ) + new JoinedText( + "\n", + users + ).asString().getBytes(CharEncoding.UTF_8) ) ) .add("branch", branch) @@ -153,17 +147,13 @@ public String apply(final String input) { String.format( QnLock.PHRASES.getString("QnLock.response"), branch, - Joiner.on(", ").join( - Iterables.transform( - users, - new Function() { - @Override - public String apply(final String input) { - return String.format("@%s", input); - } - } + new JoinedText( + ", ", + new Mapped<>( + input -> String.format("@%s", input), + users ) - ) + ).asString() ) ); } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnMerge.java b/src/main/java/com/rultor/agents/github/qtn/QnMerge.java index 8d846cf17e..4d4be491a5 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnMerge.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnMerge.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.collect.ImmutableMap; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Issue; @@ -44,6 +43,8 @@ import java.util.ResourceBundle; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; /** * Merge request. @@ -123,26 +124,38 @@ private static Req pack(final Comment.Smart comment, } else { req = new Req.Simple( "merge", - new ImmutableMap.Builder() - .put("pull_id", Integer.toString(pull.number())) - .put("pull_title", new Issue.Smart(comment.issue()).title()) - .put("fork_branch", head.ref()) - .put("head_branch", base.ref()) - .put( + new SolidMap( + new MapEntry( + "pull_id", + Integer.toString(pull.number()) + ), + new MapEntry( + "pull_title", + new Issue.Smart(comment.issue()).title() + ), + new MapEntry( + "fork_branch", + head.ref() + ), + new MapEntry( + "head_branch", + base.ref() + ), + new MapEntry( "head", String.format( "git@github.com:%s.git", base.repo().coordinates().toString() ) - ) - .put( + ), + new MapEntry( "fork", String.format( "git@github.com:%s.git", head.repo().coordinates().toString() ) ) - .build() + ) ); } return req; diff --git a/src/main/java/com/rultor/agents/github/qtn/QnParametrized.java b/src/main/java/com/rultor/agents/github/qtn/QnParametrized.java index c96f5359f8..5d568e4efb 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnParametrized.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnParametrized.java @@ -29,19 +29,23 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.rultor.agents.github.Question; import com.rultor.agents.github.Req; import java.io.IOException; import java.net.URI; +import java.util.LinkedList; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.list.SolidList; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; import org.xembly.Directive; import org.xembly.Directives; @@ -83,7 +87,8 @@ public Req understand(final Comment.Smart comment, final URI home) throws IOException { final Map map = QnParametrized.params(comment); Req req = this.origin.understand(comment, home); - if (!Iterables.isEmpty(req.dirs())) { + final List directives = new SolidList<>(req.dirs()); + if (!directives.isEmpty()) { final Directives dirs = new Directives().append(req.dirs()); req = new Req() { @Override @@ -112,15 +117,21 @@ public Iterable dirs() { * @return Map of params * @throws IOException If fails */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private static Map params(final Comment.Smart comment) throws IOException { - final ImmutableMap.Builder map = - new ImmutableMap.Builder<>(); + final List> entries = new LinkedList<>(); final Matcher matcher = QnParametrized.PTN.matcher(comment.body()); while (matcher.find()) { - map.put(matcher.group(1), matcher.group(2)); + entries.add( + new MapEntry( + matcher.group(1), matcher.group(2) + ) + ); } - return map.build(); + return new SolidMap( + entries + ); } } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnRelease.java b/src/main/java/com/rultor/agents/github/qtn/QnRelease.java index 4aa166bb21..f1bf4a478d 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnRelease.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnRelease.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.collect.ImmutableMap; import com.jcabi.aspects.Immutable; import com.jcabi.github.Comment; import com.jcabi.github.Issue; @@ -44,6 +43,8 @@ import java.util.regex.Pattern; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; /** * Release request. @@ -119,15 +120,16 @@ private static Req affirmative(final Comment.Smart comment, ); return new Req.Simple( "release", - new ImmutableMap.Builder() - .put("head_branch", "master") - .put( + new SolidMap( + new MapEntry("head_branch", "master"), + new MapEntry( "head", String.format( "git@github.com:%s.git", comment.issue().repo().coordinates() ) - ).build() + ) + ) ); } diff --git a/src/main/java/com/rultor/agents/github/qtn/QnStatus.java b/src/main/java/com/rultor/agents/github/qtn/QnStatus.java index f80c062ee4..2951587f8c 100644 --- a/src/main/java/com/rultor/agents/github/qtn/QnStatus.java +++ b/src/main/java/com/rultor/agents/github/qtn/QnStatus.java @@ -29,8 +29,6 @@ */ package com.rultor.agents.github.qtn; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; import com.jcabi.github.Comment; @@ -48,12 +46,12 @@ import java.io.IOException; import java.net.URI; import java.util.Collection; -import java.util.Collections; import java.util.LinkedList; import java.util.ResourceBundle; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; +import org.cactoos.text.JoinedText; +import org.cactoos.text.SubText; /** * Show current status. @@ -106,7 +104,7 @@ public Req understand(final Comment.Smart comment, lines.add( String.format( " * Docker container ID: `%s...`", - StringUtils.substring( + new SubText( shell.exec( String.format( // @checkstyle LineLength (1 line) @@ -115,7 +113,7 @@ public Req understand(final Comment.Smart comment, ) ), 0, Tv.TWENTY - ) + ).asString() ) ); lines.add( @@ -139,14 +137,11 @@ public Req understand(final Comment.Smart comment, true, String.format( QnStatus.PHRASES.getString("QnStatus.response"), - Joiner.on('\n').join( - Iterables.concat( - Collections.singleton( - QnStatus.REPORT.applyTo(xml).trim() - ), - lines - ) - ) + new JoinedText( + "\n", + QnStatus.REPORT.applyTo(xml).trim(), + lines.toString() + ).asString() ) ); Logger.info(this, "status request in #%d", comment.issue().number()); diff --git a/src/main/java/com/rultor/agents/req/Brackets.java b/src/main/java/com/rultor/agents/req/Brackets.java index f49e30105c..0c28ccc5f6 100644 --- a/src/main/java/com/rultor/agents/req/Brackets.java +++ b/src/main/java/com/rultor/agents/req/Brackets.java @@ -29,10 +29,10 @@ */ package com.rultor.agents.req; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; import com.jcabi.ssh.SSH; +import java.io.IOException; +import org.cactoos.iterable.Mapped; +import org.cactoos.text.JoinedText; /** * List of texts for the script, in brackets. @@ -58,20 +58,20 @@ final class Brackets { @Override public String toString() { - return String.format( - "( %s )", - Joiner.on(' ').join( - Iterables.transform( - this.items, - new Function() { - @Override - public String apply(final String input) { - return SSH.escape(input); - } - } - ) - ) - ); + try { + return String.format( + "( %s )", + new JoinedText( + " ", + new Mapped<>( + input -> SSH.escape(input), + this.items + ) + ).asString() + ); + } catch (final IOException ex) { + throw new IllegalStateException(ex); + } } } diff --git a/src/main/java/com/rultor/agents/req/Decrypt.java b/src/main/java/com/rultor/agents/req/Decrypt.java index eaec3ca7e7..7f74faeca5 100644 --- a/src/main/java/com/rultor/agents/req/Decrypt.java +++ b/src/main/java/com/rultor/agents/req/Decrypt.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.req; -import com.google.common.base.Joiner; import com.jcabi.aspects.Immutable; import com.jcabi.ssh.SSH; import com.jcabi.xml.XML; @@ -39,6 +38,7 @@ import java.util.LinkedList; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.text.JoinedText; /** * Decrypt. @@ -50,15 +50,13 @@ @Immutable @ToString @EqualsAndHashCode(of = "profile") -/** - * Tests for {@link Decrypt}. - * - * @author Yegor Bugayenko (yegor256@gmail.com) - * @version $Id$ - * @since 1.37.4 - */ final class Decrypt { + /** + * Space delimiter. + */ + private static final String SPACE = " "; + /** * Profile. */ @@ -97,6 +95,7 @@ final class Decrypt { * @return Instructions * @throws IOException If fails */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public Iterable commands() throws IOException { final Collection assets = this.profile.read().nodes("/p/entry[@key='decrypt']/entry"); @@ -104,11 +103,12 @@ public Iterable commands() throws IOException { if (!assets.isEmpty()) { commands.add("gpgconf --reload gpg-agent"); commands.add( - Joiner.on(' ').join( + new JoinedText( + SPACE, "gpg --keyserver hkp://pool.sks-keyservers.net", this.proxy, "--verbose --recv-keys 9AF0FA4C" - ) + ).asString() ); commands.add("gpg --version"); } @@ -116,7 +116,8 @@ public Iterable commands() throws IOException { final String key = asset.xpath("@key").get(0); final String enc = String.format("%s.enc", key); commands.add( - Joiner.on(' ').join( + new JoinedText( + SPACE, "gpg --verbose \"--keyring=$(pwd)/.gpg/pubring.gpg\"", "\"--secret-keyring=$(pwd)/.gpg/secring.gpg\"", String.format( @@ -124,14 +125,15 @@ public Iterable commands() throws IOException { SSH.escape(asset.xpath("./text()").get(0)), SSH.escape(enc) ) - ) + ).asString() ); commands.add( String.format( - Joiner.on(' ').join( + new JoinedText( + SPACE, "gpg --no-tty --batch --verbose --decrypt", "--passphrase %s %s > %s" - ), + ).asString(), SSH.escape( String.format("rultor-key:%s", this.profile.name()) ), diff --git a/src/main/java/com/rultor/agents/req/DockerRun.java b/src/main/java/com/rultor/agents/req/DockerRun.java index 9ec05b32c6..a6cb3802e2 100644 --- a/src/main/java/com/rultor/agents/req/DockerRun.java +++ b/src/main/java/com/rultor/agents/req/DockerRun.java @@ -29,10 +29,6 @@ */ package com.rultor.agents.req; -import com.google.common.base.Function; -import com.google.common.collect.Collections2; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.jcabi.aspects.Immutable; import com.jcabi.xml.XML; import com.jcabi.xml.XMLDocument; @@ -42,10 +38,14 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedList; +import java.util.List; import java.util.Map; +import java.util.Map.Entry; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.lang3.StringUtils; +import org.cactoos.iterable.Joined; +import org.cactoos.list.SolidList; /** * Docker run command. @@ -54,6 +54,7 @@ * @version $Id$ * @since 1.0 * @checkstyle MultipleStringLiteralsCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @Immutable @ToString @@ -91,16 +92,16 @@ public Iterable script() throws IOException { if (this.profile.read().nodes("/p/entry[@key='uninstall']").isEmpty()) { trap = Collections.emptyList(); } else { - trap = Iterables.concat( - Lists.newArrayList("function", "clean_up()", "{"), + trap = new Joined( + new SolidList("function", "clean_up()", "{"), DockerRun.scripts( this.profile.read(), "/p/entry[@key='uninstall']" ), - Lists.newArrayList("}", ";"), - Lists.newArrayList("trap", "clean_up", "EXIT", ";") + new SolidList("}", ";"), + new SolidList("trap", "clean_up", "EXIT", ";") ); } - return Iterables.concat( + return new Joined( trap, DockerRun.scripts( this.profile.read(), "/p/entry[@key='install']" @@ -117,21 +118,18 @@ public Iterable script() throws IOException { */ public Iterable envs(final Map extra) throws IOException { - return Iterables.concat( + final List entries = new LinkedList<>(); + for (final Entry ent : extra.entrySet()) { + entries.add( + String.format( + "%s=%s", ent.getKey(), ent.getValue() + ) + ); + } + return new Joined( DockerRun.envs(this.profile.read(), "/p/entry[@key='env']"), DockerRun.envs(this.node(), "entry[@key='env']"), - Collections2.transform( - extra.entrySet(), - new Function, String>() { - @Override - public String apply( - final Map.Entry ent) { - return String.format( - "%s=%s", ent.getKey(), ent.getValue() - ); - } - } - ) + new SolidList(entries) ); } @@ -236,14 +234,11 @@ private static Iterable envs(final XML xml, final String path) { parts = DockerRun.lines(node); } envs.addAll( - Collections2.transform( - parts, - new Function() { - @Override - public String apply(final String input) { - return String.format("%s", input); - } - } + new SolidList( + new org.cactoos.collection.Mapped<>( + input -> String.format("%s", input), + parts + ) ) ); } @@ -259,16 +254,13 @@ private static Collection lines(final XML node) { final Collection lines = new LinkedList(); if (node.node().hasChildNodes()) { lines.addAll( - Collections2.transform( - Arrays.asList( - StringUtils.split(node.xpath("text()").get(0), '\n') - ), - new Function() { - @Override - public String apply(final String line) { - return line.trim(); - } - } + new SolidList( + new org.cactoos.collection.Mapped<>( + input -> input.trim(), + Arrays.asList( + StringUtils.split(node.xpath("text()").get(0), '\n') + ) + ) ) ); } diff --git a/src/main/java/com/rultor/agents/req/StartsRequest.java b/src/main/java/com/rultor/agents/req/StartsRequest.java index f15e245ba2..d9523ad4a3 100644 --- a/src/main/java/com/rultor/agents/req/StartsRequest.java +++ b/src/main/java/com/rultor/agents/req/StartsRequest.java @@ -29,12 +29,6 @@ */ package com.rultor.agents.req; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.jcabi.aspects.Immutable; import com.jcabi.log.Logger; import com.jcabi.ssh.SSH; @@ -45,12 +39,19 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedList; +import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.iterable.Joined; +import org.cactoos.iterable.Mapped; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; +import org.cactoos.text.JoinedText; import org.xembly.Directive; import org.xembly.Directives; @@ -60,6 +61,7 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 1.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @Immutable @ToString @@ -133,29 +135,24 @@ public Iterable process(final XML xml) throws IOException { @SuppressWarnings("unchecked") private String script(final XML req, final String type, final String name) throws IOException { - return Joiner.on('\n').join( - Iterables.concat( - Iterables.transform( - Sets.union( + return new JoinedText( + "\n", + new Joined( + new Mapped, String>( + input -> String.format( + "%s=%s", input.getKey(), + StartsRequest.escape(input.getValue()) + ), + new Joined>( this.vars(req, type).entrySet(), - Sets.newHashSet( - Maps.immutableEntry( + new SolidMap( + new MapEntry( "container", name.replaceAll("[^a-zA-Z0-9_.-]", "_") .toLowerCase(Locale.ENGLISH) ) - ) - ), - new Function, String>() { - @Override - public String apply( - final Map.Entry input) { - return String.format( - "%s=%s", input.getKey(), - StartsRequest.escape(input.getValue()) - ); - } - } + ).entrySet() + ) ), Collections.singleton(this.asRoot()), Collections.singleton( @@ -174,7 +171,7 @@ public String apply( ) ) ) - ); + ).asString(); } /** @@ -211,79 +208,106 @@ private String asRoot() throws IOException { * @return Vars * @throws IOException If fails */ + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") private Map vars(final XML req, final String type) throws IOException { - final ImmutableMap.Builder vars = - new ImmutableMap.Builder<>(); + final List> entries = new LinkedList<>(); for (final XML arg : req.nodes("args/arg")) { - vars.put( - arg.xpath("@name").get(0), - arg.xpath("text()").get(0) + entries.add( + new MapEntry( + arg.xpath("@name").get(0), + arg.xpath("text()").get(0) + ) ); } final DockerRun docker = new DockerRun( this.profile, String.format("/p/entry[@key='%s']", type) ); - vars.put("author", req.xpath("author/text()").get(0)); - vars.put( - "scripts", - new Brackets( - Iterables.concat( - StartsRequest.export(docker.envs(vars.build())), - docker.script() - ) - ).toString() + entries.add( + new MapEntry( + "author", req.xpath("author/text()").get(0) + ) ); - vars.put( - "vars", - new Brackets( - Iterables.transform( - docker.envs(vars.build()), - new Function() { - @Override - public String apply(final String input) { - return String.format("--env=%s", input); - } - } - ) - ).toString() + entries.add( + new MapEntry( + "scripts", + new Brackets( + new Joined( + StartsRequest.export( + docker.envs( + new SolidMap( + entries + ) + ) + ), + docker.script() + ) + ).toString() + ) + ); + entries.add( + new MapEntry( + "vars", + new Brackets( + new Mapped<>( + input -> String.format("--env=%s", input), + docker.envs( + new SolidMap( + entries + ) + ) + ) + ).toString() + ) ); final Profile.Defaults def = new Profile.Defaults(this.profile); - vars.put( - "image", - def.text( - "/p/entry[@key='docker']/entry[@key='image']", - "yegor256/rultor" + entries.add( + new MapEntry( + "image", + def.text( + "/p/entry[@key='docker']/entry[@key='image']", + "yegor256/rultor" + ) ) ); - vars.put( - "directory", - def.text("/p/entry[@key='docker']/entry[@key='directory']") + entries.add( + new MapEntry( + "directory", + def.text("/p/entry[@key='docker']/entry[@key='directory']") + ) ); if (!this.profile.read().nodes("/p/entry[@key='merge']").isEmpty()) { - vars.put( - "squash", - def.text( - "/p/entry[@key='merge']/entry[@key='squash']", - Boolean.FALSE.toString() - ).toLowerCase(Locale.ENGLISH) + entries.add( + new MapEntry( + "squash", + def.text( + "/p/entry[@key='merge']/entry[@key='squash']", + Boolean.FALSE.toString() + ).toLowerCase(Locale.ENGLISH) + ) ); - vars.put( - "ff", - def.text( - "/p/entry[@key='merge']/entry[@key='fast-forward']", - "default" - ).toLowerCase(Locale.ENGLISH) + entries.add( + new MapEntry( + "ff", + def.text( + "/p/entry[@key='merge']/entry[@key='fast-forward']", + "default" + ).toLowerCase(Locale.ENGLISH) + ) ); - vars.put( - "rebase", - def.text( - "/p/entry[@key='merge']/entry[@key='rebase']", - Boolean.FALSE.toString() - ).toLowerCase(Locale.ENGLISH) + entries.add( + new MapEntry( + "rebase", + def.text( + "/p/entry[@key='merge']/entry[@key='rebase']", + Boolean.FALSE.toString() + ).toLowerCase(Locale.ENGLISH) + ) ); } - return vars.build(); + return new SolidMap( + entries + ); } /** diff --git a/src/main/java/com/rultor/agents/twitter/Tweets.java b/src/main/java/com/rultor/agents/twitter/Tweets.java index bb41780c1c..eccc8ea363 100644 --- a/src/main/java/com/rultor/agents/twitter/Tweets.java +++ b/src/main/java/com/rultor/agents/twitter/Tweets.java @@ -42,7 +42,7 @@ import java.io.IOException; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.apache.commons.lang3.StringUtils; +import org.cactoos.text.SubText; import org.xembly.Directive; import org.xembly.Directives; @@ -114,10 +114,11 @@ private static String tweet(final Repo.Smart repo, final String tag) final StringBuilder text = new StringBuilder(2 * Tv.HUNDRED); if (repo.hasDescription() && !repo.description().isEmpty()) { text.append( - StringUtils.substring( + new SubText( repo.description(), - 0, Tv.HUNDRED - ) + 0, + Tv.HUNDRED + ).asString() ); } else { text.append(repo.coordinates().repo()); diff --git a/src/main/java/com/rultor/cached/CdTalks.java b/src/main/java/com/rultor/cached/CdTalks.java index 396123a41e..63aff3dbb1 100644 --- a/src/main/java/com/rultor/cached/CdTalks.java +++ b/src/main/java/com/rultor/cached/CdTalks.java @@ -29,9 +29,6 @@ */ package com.rultor.cached; -import com.google.common.base.Function; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.jcabi.aspects.Cacheable; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; @@ -42,6 +39,7 @@ import java.util.concurrent.TimeUnit; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.iterable.Mapped; /** * Cached talks. @@ -110,48 +108,27 @@ public void create(final String repo, final String name) @Override @Cacheable public Iterable active() { - return Lists.newArrayList( - Iterables.transform( - this.origin.active(), - new Function() { - @Override - public Talk apply(final Talk input) { - return new CdTalk(input); - } - } - ) + return new Mapped<>( + input -> new CdTalk(input), + this.origin.active() ); } @Override @Cacheable(lifetime = Tv.TWENTY, unit = TimeUnit.MINUTES) public Iterable recent() { - return Lists.newArrayList( - Iterables.transform( - this.origin.recent(), - new Function() { - @Override - public Talk apply(final Talk input) { - return new CdTalk(input); - } - } - ) + return new Mapped<>( + input -> new CdTalk(input), + this.origin.recent() ); } @Override @Cacheable public Iterable siblings(final String repo, final Date since) { - return Lists.newArrayList( - Iterables.transform( - this.origin.siblings(repo, since), - new Function() { - @Override - public Talk apply(final Talk input) { - return new CdTalk(input); - } - } - ) + return new Mapped<>( + input -> new CdTalk(input), + this.origin.siblings(repo, since) ); } } diff --git a/src/main/java/com/rultor/dynamo/DyTalk.java b/src/main/java/com/rultor/dynamo/DyTalk.java index 0d73d27ff1..79c8fa99b7 100644 --- a/src/main/java/com/rultor/dynamo/DyTalk.java +++ b/src/main/java/com/rultor/dynamo/DyTalk.java @@ -32,7 +32,6 @@ import com.amazonaws.services.dynamodbv2.model.AttributeAction; import com.amazonaws.services.dynamodbv2.model.AttributeValue; import com.amazonaws.services.dynamodbv2.model.AttributeValueUpdate; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.dynamo.AttributeUpdates; import com.jcabi.dynamo.Item; @@ -46,13 +45,14 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.nio.charset.Charset; import java.util.Date; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; +import org.cactoos.list.SolidList; import org.w3c.dom.Node; import org.xembly.Directive; import org.xembly.ImpossibleModificationException; @@ -79,6 +79,11 @@ public final class DyTalk implements Talk { */ private static final int LIMIT = 399 << 10; + /** + * UTF-8. + */ + private static final String UTF_8 = "UTF-8"; + /** * Item. */ @@ -127,7 +132,7 @@ public XML read() throws IOException { @Override public void modify(final Iterable dirs) throws IOException { - if (!Iterables.isEmpty(dirs)) { + if (!new SolidList<>(dirs).isEmpty()) { final XML xml = this.read(); final Node node = xml.node(); try { @@ -188,7 +193,7 @@ private static byte[] zip(final String xml) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final OutputStream output = new GZIPOutputStream(baos); IOUtils.copy( - IOUtils.toInputStream(xml, Charsets.UTF_8), + IOUtils.toInputStream(xml, Charset.forName(UTF_8)), output ); output.close(); @@ -207,7 +212,7 @@ private static String unzip(final byte[] bytes) throws IOException { new GZIPInputStream(new ByteArrayInputStream(bytes)), baos ); - return new String(baos.toByteArray(), Charsets.UTF_8); + return new String(baos.toByteArray(), Charset.forName(UTF_8)); } } diff --git a/src/main/java/com/rultor/dynamo/DyTalks.java b/src/main/java/com/rultor/dynamo/DyTalks.java index 8ca8ed1afb..2244d93cb8 100644 --- a/src/main/java/com/rultor/dynamo/DyTalks.java +++ b/src/main/java/com/rultor/dynamo/DyTalks.java @@ -34,15 +34,11 @@ import com.amazonaws.services.dynamodbv2.model.ComparisonOperator; import com.amazonaws.services.dynamodbv2.model.Condition; import com.amazonaws.services.dynamodbv2.model.Select; -import com.google.common.base.Function; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import com.google.common.collect.Iterables; import com.jcabi.aspects.Immutable; import com.jcabi.aspects.Tv; import com.jcabi.dynamo.Attributes; import com.jcabi.dynamo.Conditions; -import com.jcabi.dynamo.Item; import com.jcabi.dynamo.QueryValve; import com.jcabi.dynamo.Region; import com.rultor.spi.Talk; @@ -51,6 +47,9 @@ import java.util.Date; import lombok.EqualsAndHashCode; import lombok.ToString; +import org.cactoos.iterable.Filtered; +import org.cactoos.iterable.Limited; +import org.cactoos.iterable.Mapped; /** * Talks in Dynamo. @@ -209,7 +208,7 @@ public void delete(final String name) { .frame() .through(new QueryValve().withLimit(1)) .where(DyTalks.HASH, name), - Predicates.alwaysTrue() + item -> true ); } @@ -233,7 +232,8 @@ public void create(final String repo, final String name) @Override public Iterable active() { - return Iterables.transform( + return new Mapped<>( + input -> new DyTalk(input), this.region.table(DyTalks.TBL) .frame() .through( @@ -243,21 +243,26 @@ public Iterable active() { .withSelect(Select.SPECIFIC_ATTRIBUTES) .withAttributesToGet(DyTalks.HASH, DyTalks.ATTR_NUMBER) ) - .where(DyTalks.ATTR_ACTIVE, Boolean.toString(true)), - new Function() { - @Override - public Talk apply(final Item input) { - return new DyTalk(input); - } - } + .where(DyTalks.ATTR_ACTIVE, Boolean.toString(true)) ); } @Override public Iterable recent() { - return Iterables.limit( - Iterables.filter( - Iterables.transform( + return new Limited<>( + Tv.FIVE, + new Filtered<>( + input -> { + try { + return !input.read().nodes( + "/talk[@public='true']" + ).isEmpty(); + } catch (final IOException ex) { + throw new IllegalStateException(ex); + } + }, + new Mapped<>( + input -> new DyTalk(input), this.region.table(DyTalks.TBL) .frame() .through( @@ -270,34 +275,16 @@ public Iterable recent() { ) .where( DyTalks.ATTR_ACTIVE, Boolean.toString(false) - ), - new Function() { - @Override - public Talk apply(final Item input) { - return new DyTalk(input); - } - } - ), - new Predicate() { - @Override - public boolean apply(final Talk talk) { - try { - return !talk.read().nodes( - "/talk[@public='true']" - ).isEmpty(); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } - } - } - ), - Tv.FIVE + ) + ) + ) ); } @Override public Iterable siblings(final String repo, final Date since) { - return Iterables.transform( + return new Mapped<>( + input -> new DyTalk(input), this.region.table(DyTalks.TBL) .frame() .through( @@ -318,13 +305,7 @@ public Iterable siblings(final String repo, final Date since) { Long.toString(since.getTime()) ) ) - ), - new Function() { - @Override - public Talk apply(final Item input) { - return new DyTalk(input); - } - } + ) ); } } diff --git a/src/main/java/com/rultor/profiles/GithubProfile.java b/src/main/java/com/rultor/profiles/GithubProfile.java index 8fbc864e46..4f602fd513 100644 --- a/src/main/java/com/rultor/profiles/GithubProfile.java +++ b/src/main/java/com/rultor/profiles/GithubProfile.java @@ -29,10 +29,6 @@ */ package com.rultor.profiles; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Collections2; -import com.google.common.collect.ImmutableMap; import com.jcabi.aspects.Immutable; import com.jcabi.github.Content; import com.jcabi.github.Coordinates; @@ -44,15 +40,22 @@ import java.io.InputStream; import java.util.Collection; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; import lombok.EqualsAndHashCode; import lombok.ToString; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.collection.Mapped; +import org.cactoos.list.SolidList; +import org.cactoos.map.MapEntry; +import org.cactoos.map.SolidMap; +import org.cactoos.text.JoinedText; /** * Github Profile. @@ -65,6 +68,7 @@ * @version $Id$ * @since 1.0 * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) + * @checkstyle AvoidInstantiatingObjectsInLoops */ @Immutable @ToString @@ -122,18 +126,21 @@ public XML read() throws IOException { return new YamlXML(this.yml()).get(); } + @SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") @Override public Map assets() throws IOException { - final ImmutableMap.Builder assets = - new ImmutableMap.Builder<>(); final XML xml = this.read(); - for (final XML asset : xml.nodes("/p/entry[@key='assets']/entry")) { - assets.put( - asset.xpath("@key").get(0), - this.asset(asset.xpath("text()").get(0)) + final List nodes = xml.nodes("/p/entry[@key='assets']/entry"); + final List> entries = new LinkedList<>(); + for (final XML node : nodes) { + entries.add( + new MapEntry<>( + node.xpath("@key").get(0), + this.asset(node.xpath("text()").get(0)) + ) ); } - return assets.build(); + return new SolidMap(entries); } /** @@ -161,22 +168,20 @@ private InputStream asset(final String path) throws IOException { ) ); } - final Collection friends = Collections2.transform( - new YamlXML( - new String( - new Content.Smart( - rpo.contents().get(GithubProfile.FILE) - ).decoded(), - CharEncoding.UTF_8 + final Collection friends = + new SolidList<>( + new Mapped<>( + input -> input.toLowerCase(Locale.ENGLISH), + new YamlXML( + new String( + new Content.Smart( + rpo.contents().get(GithubProfile.FILE) + ).decoded(), + CharEncoding.UTF_8 + ) + ).get().xpath("/p/entry[@key='friends']/item/text()") ) - ).get().xpath("/p/entry[@key='friends']/item/text()"), - new Function() { - @Override - public String apply(final String input) { - return input.toLowerCase(Locale.ENGLISH); - } - } - ); + ); final String coords = this.repo.coordinates() .toString().toLowerCase(Locale.ENGLISH); if (!friends.contains(coords)) { @@ -243,7 +248,10 @@ private String yml() throws IOException { String.format( "`%s` is not valid according to schema:\n``%s``", GithubProfile.FILE, - Joiner.on('\n').join(msg) + new JoinedText( + "\n", + msg + ).asString() ) ); } diff --git a/src/main/java/com/rultor/spi/Talks.java b/src/main/java/com/rultor/spi/Talks.java index 9e97cf6a81..a576a77db9 100644 --- a/src/main/java/com/rultor/spi/Talks.java +++ b/src/main/java/com/rultor/spi/Talks.java @@ -29,24 +29,22 @@ */ package com.rultor.spi; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.io.Files; import com.jcabi.aspects.Immutable; import com.jcabi.log.Logger; import com.jcabi.xml.StrictXML; import com.jcabi.xml.XMLDocument; import java.io.File; import java.io.IOException; -import java.util.ArrayList; +import java.nio.file.Files; import java.util.Collection; -import java.util.Collections; import java.util.Date; -import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.CharEncoding; +import org.cactoos.iterable.Filtered; +import org.cactoos.iterable.Mapped; +import org.cactoos.iterable.Sorted; +import org.cactoos.list.SolidList; +import org.cactoos.text.JoinedText; /** * Talks in a repo. @@ -54,6 +52,7 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 1.0 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ @Immutable @SuppressWarnings("PMD.TooManyMethods") @@ -134,9 +133,12 @@ final class InDir implements Talks { private final transient String path; /** * Ctor. + * @throws IOException ex */ - public InDir() { - this.path = Files.createTempDir().getAbsolutePath(); + public InDir() throws IOException { + this.path = Files.createTempDirectory("") + .toAbsolutePath() + .toString(); } @Override public boolean exists(final long number) { @@ -144,20 +146,17 @@ public boolean exists(final long number) { } @Override public Talk get(final long number) { - return Iterables.find( - this.active(), - new Predicate() { - @Override - public boolean apply(final Talk talk) { - try { - return talk.read().xpath("/talk/@number").get(0) - .equals(Long.toString(number)); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } + return new Filtered<>( + talk -> { + try { + return talk.read().xpath("/talk/@number").get(0) + .equals(Long.toString(number)); + } catch (final IOException ex) { + throw new IllegalStateException(ex); } - } - ); + }, + this.active() + ).iterator().next(); } @Override public boolean exists(final String name) { @@ -165,20 +164,17 @@ public boolean exists(final String name) { } @Override public Talk get(final String name) { - return Iterables.find( - this.active(), - new Predicate() { - @Override - public boolean apply(final Talk talk) { - try { - return talk.read().xpath("/talk/@name").get(0) - .equals(name); - } catch (final IOException ex) { - throw new IllegalStateException(ex); - } + return new Filtered<>( + talk -> { + try { + return talk.read().xpath("/talk/@name").get(0) + .equals(name); + } catch (final IOException ex) { + throw new IllegalStateException(ex); } - } - ); + }, + this.active() + ).iterator().next(); } @Override public void delete(final String name) { @@ -192,7 +188,8 @@ public void create(final String repo, final String name) file, new StrictXML( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + " ", String.format( "", name @@ -203,7 +200,7 @@ public void create(final String repo, final String name) name ), "" - ) + ).asString() ), Talk.SCHEMA ).toString(), @@ -216,17 +213,15 @@ public Iterable active() { final Collection files = FileUtils.listFiles( new File(this.path), null, false ); - final List list = new ArrayList(files); - Collections.sort(list); + final SolidList list = new SolidList<>( + new Sorted<>( + files + ) + ); Logger.info(this, "%d files in %s", files.size(), this.path); - return Iterables.transform( - list, - new Function() { - @Override - public Talk apply(final File file) { - return new Talk.InFile(file); - } - } + return new Mapped<>( + file -> new Talk.InFile(file), + list ); } @Override diff --git a/src/main/java/com/rultor/web/RqUser.java b/src/main/java/com/rultor/web/RqUser.java index 3718c19820..077dea38e6 100644 --- a/src/main/java/com/rultor/web/RqUser.java +++ b/src/main/java/com/rultor/web/RqUser.java @@ -29,14 +29,13 @@ */ package com.rultor.web; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; import com.jcabi.xml.XML; import com.rultor.profiles.Profiles; import com.rultor.spi.Profile; import com.rultor.spi.Talk; import java.io.IOException; import java.util.Collection; +import org.cactoos.scalar.Or; import org.takes.Request; import org.takes.facets.auth.Identity; import org.takes.facets.auth.RqAuth; @@ -76,6 +75,7 @@ public boolean anonymous() throws IOException { * @return TRUE if I can see it * @throws IOException If fails */ + @SuppressWarnings("PMD.AvoidCatchingThrowable") public boolean canSee(final Talk talk) throws IOException { final XML xml; try { @@ -91,16 +91,16 @@ public boolean canSee(final Talk talk) throws IOException { granted = true; } else { final Identity identity = this.identity(); - granted = Iterables.any( - readers, - new Predicate() { - @Override - public boolean apply(final String input) { - return !identity.equals(Identity.ANONYMOUS) - && input.trim().equals(identity.urn()); - } - } - ); + try { + granted = new Or( + r -> !identity.equals(Identity.ANONYMOUS) + && r.trim().equals(identity.urn()), + readers + ).value(); + // @checkstyle IllegalCatchCheck (1 line) + } catch (final Throwable ex) { + throw new IOException(ex); + } } return granted; } diff --git a/src/main/java/com/rultor/web/TkHome.java b/src/main/java/com/rultor/web/TkHome.java index 313158ee91..09e75ee454 100644 --- a/src/main/java/com/rultor/web/TkHome.java +++ b/src/main/java/com/rultor/web/TkHome.java @@ -29,13 +29,13 @@ */ package com.rultor.web; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Tv; import com.jcabi.xml.XML; import com.rultor.Toggles; import com.rultor.spi.Talk; import com.rultor.spi.Talks; import java.io.IOException; +import org.cactoos.iterable.Limited; import org.ocpsoft.prettytime.PrettyTime; import org.takes.Request; import org.takes.Response; @@ -105,7 +105,7 @@ public Iterable toXembly() throws IOException { private Directives recent() throws IOException { final Directives dirs = new Directives().add("recent"); final PrettyTime pretty = new PrettyTime(); - for (final Talk talk : Iterables.limit(this.talks.recent(), Tv.FIVE)) { + for (final Talk talk : new Limited<>(Tv.FIVE, this.talks.recent())) { dirs.add("talk").set(talk.name()) .attr("timeago", pretty.format(talk.updated())); final XML xml = talk.read(); diff --git a/src/main/java/com/rultor/web/TkSiblings.java b/src/main/java/com/rultor/web/TkSiblings.java index 5e5836bf55..396d7f63c3 100644 --- a/src/main/java/com/rultor/web/TkSiblings.java +++ b/src/main/java/com/rultor/web/TkSiblings.java @@ -29,8 +29,6 @@ */ package com.rultor.web; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; import com.jcabi.aspects.Tv; import com.jcabi.xml.XML; import com.rultor.agents.daemons.Home; @@ -40,6 +38,8 @@ import java.util.Date; import java.util.List; import java.util.logging.Level; +import org.cactoos.iterable.Limited; +import org.cactoos.list.SolidList; import org.ocpsoft.prettytime.PrettyTime; import org.takes.Response; import org.takes.facets.flash.RsFlash; @@ -87,9 +87,10 @@ public Response act(final RqRegex req) throws IOException { ) ); final String repo = req.matcher().group(1); - final List siblings = Lists.newArrayList( - Iterables.limit( - this.talks.siblings(repo, since), Tv.TWENTY + final SolidList siblings = new SolidList<>( + new Limited<>( + Tv.TWENTY, + this.talks.siblings(repo, since) ) ); if (!siblings.isEmpty() diff --git a/src/main/java/com/rultor/web/TkStatus.java b/src/main/java/com/rultor/web/TkStatus.java index 8209234872..34e4c49229 100644 --- a/src/main/java/com/rultor/web/TkStatus.java +++ b/src/main/java/com/rultor/web/TkStatus.java @@ -29,13 +29,13 @@ */ package com.rultor.web; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Tv; import com.jcabi.log.Logger; import com.rultor.spi.Pulse; import com.rultor.spi.Tick; import java.net.HttpURLConnection; import java.util.concurrent.TimeUnit; +import org.cactoos.list.SolidList; import org.takes.Request; import org.takes.Response; import org.takes.Take; @@ -68,15 +68,15 @@ final class TkStatus implements Take { @Override public Response act(final Request req) { - final Iterable ticks = this.pulse.ticks(); + final SolidList ticks = new SolidList<>(this.pulse.ticks()); final StringBuilder msg = new StringBuilder(Tv.THOUSAND); final Response response; - if (Iterables.isEmpty(ticks)) { + if (ticks.isEmpty()) { response = new RsWithStatus(HttpURLConnection.HTTP_NO_CONTENT); msg.append("There is no activity yet, refresh in a few seconds"); } else { final long age = System.currentTimeMillis() - - Iterables.getLast(ticks).start(); + - ticks.get(ticks.size() - 1).start(); if (age > TimeUnit.MINUTES.toMillis((long) Tv.FIVE)) { response = new RsWithStatus( HttpURLConnection.HTTP_INTERNAL_ERROR diff --git a/src/test/java/com/rultor/agents/daemons/TailITCase.java b/src/test/java/com/rultor/agents/daemons/TailITCase.java index bbf0bdefde..b1f99edfb0 100644 --- a/src/test/java/com/rultor/agents/daemons/TailITCase.java +++ b/src/test/java/com/rultor/agents/daemons/TailITCase.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.daemons; -import com.google.common.base.Charsets; import com.jcabi.ssh.SSH; import com.jcabi.ssh.Shell; import com.rultor.Time; @@ -37,6 +36,7 @@ import com.rultor.agents.shells.PfShell; import com.rultor.spi.Profile; import com.rultor.spi.Talk; +import java.nio.charset.Charset; import org.apache.commons.io.IOUtils; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -93,7 +93,7 @@ public void tailsNonUtf() throws Exception { MatcherAssert.assertThat( IOUtils.toString( new Tail(talk.read(), hash).read(), - Charsets.UTF_8 + Charset.forName("UTF-8") ), Matchers.is(String.format("%sĂȘ\n", clean)) ); diff --git a/src/test/java/com/rultor/agents/github/AnswerTest.java b/src/test/java/com/rultor/agents/github/AnswerTest.java index 95b085360a..e3bba4e2a6 100644 --- a/src/test/java/com/rultor/agents/github/AnswerTest.java +++ b/src/test/java/com/rultor/agents/github/AnswerTest.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github; -import com.google.common.collect.Iterables; import com.jcabi.aspects.Tv; import com.jcabi.github.Comment; import com.jcabi.github.Issue; @@ -37,6 +36,7 @@ import com.jcabi.github.mock.MkGithub; import java.io.IOException; import java.util.Date; +import org.cactoos.list.SolidList; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -85,7 +85,7 @@ public void preventsSpam() throws Exception { answer.post(true, "oops"); } MatcherAssert.assertThat( - Iterables.size(issue.comments().iterate(new Date(0L))), + new SolidList<>(issue.comments().iterate(new Date(0L))).size(), Matchers.is(Tv.SIX) ); } diff --git a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java index 95ec105c9e..b78e5d2c82 100644 --- a/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java +++ b/src/test/java/com/rultor/agents/github/ReleaseBinariesTest.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.github; -import com.google.common.io.Files; import com.jcabi.aspects.Tv; import com.jcabi.github.Issue; import com.jcabi.github.Releases; @@ -44,6 +43,8 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; +import org.cactoos.io.LengthOf; +import org.cactoos.io.TeeInput; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Ignore; @@ -82,9 +83,9 @@ public void attachesBinaryToRelease() throws Exception { final File bin = FileUtils.getFile( dir.getAbsolutePath(), "repo", target, name.replace("${tag}", tag) ); - Files.createParentDirs(bin); + bin.mkdirs(); final byte[] content = RandomUtils.nextBytes(Tv.HUNDRED); - Files.write(content, bin); + new LengthOf(new TeeInput(content, bin)).value(); final Talk talk = ReleaseBinariesTest .talk(repo.issues().create("", ""), tag, dir); new CommentsTag(repo.github()).execute(talk); diff --git a/src/test/java/com/rultor/agents/req/BracketsTest.java b/src/test/java/com/rultor/agents/req/BracketsTest.java new file mode 100644 index 0000000000..437f9b5420 --- /dev/null +++ b/src/test/java/com/rultor/agents/req/BracketsTest.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2009-2018, rultor.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: 1) Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. 3) Neither the name of the rultor.com nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.rultor.agents.req; + +import org.cactoos.list.SolidList; +import org.hamcrest.MatcherAssert; +import org.hamcrest.Matchers; +import org.junit.Test; + +/** + * Tests for {@link Brackets}. + * + * @author Filipe Freire (livrofubia@gmail.com) + * @version $Id$ + * @since ? + */ +public final class BracketsTest { + /** + * Brackets can fetch environment vars. + * @throws Exception In case of error. + */ + @Test + public void escapesInput() throws Exception { + final Brackets brackets = new Brackets( + new SolidList<>( + "Elegant", + "Objects" + ) + ); + MatcherAssert.assertThat( + brackets.toString(), + Matchers.equalTo("( 'Elegant' 'Objects' )") + ); + } +} diff --git a/src/test/java/com/rultor/agents/req/DecryptTest.java b/src/test/java/com/rultor/agents/req/DecryptTest.java index ab0187f0a3..f81d262d63 100644 --- a/src/test/java/com/rultor/agents/req/DecryptTest.java +++ b/src/test/java/com/rultor/agents/req/DecryptTest.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.req; -import com.google.common.base.Joiner; import com.jcabi.log.VerboseProcess; import com.jcabi.xml.XMLDocument; import com.rultor.spi.Profile; @@ -39,6 +38,7 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Assume; @@ -52,28 +52,14 @@ * @author Yegor Bugayenko (yegor256@gmail.com) * @version $Id$ * @since 1.37.4 + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class DecryptTest { /** - * Encoded test file. + * Newline. */ - private static final String ASC = Joiner.on('\n').join( - "-----BEGIN PGP MESSAGE-----", - "Version: GnuPG v1\n", - "hQEMA5qETcGag5w6AQgAvm/P0JUlQAdOtGng5zHLx5cV+BrbpFt1m2ja4BjacYMU", - "wcubtJSh+n0XNLk6zMMCsrDnTfzvi/FEFaRsPVb/ZJHiJGvwhNGyenQWgd6bczIL", - "1UxBZ1BpHTPv5hVK43fb6cYq+e/gniBMvIKlKV+Qh/NVtiQACQJ5xL1M16S9SQuY", - "hjnVEL3JNHiLEAfPS/8xS05DY/w1k/JyPXMZlrR7YGMxUsG6aDaFPAdjcdSbzGCT", - "j4yZPdZtyqePFGXn0VJE7GRywWcmk3Nj+oZzgx6DLV3PH40HSYNuyA9a2xFpghTr", - "7uiYRf+rRzXlx7qnBLsvETlhc77zpf0FW4pLq/08ttLADQFsIU2BNHJGPw+96GKJ", - "AVNAm0OxfaMz+U+gy2kIgteuMQmfkYDF0u9HE7NwZ1PlXO5Oszhfdim2LPSyxYMi", - "sKlVilWhPwdumSjmY0IG1B6yc8ZLG4BjBucu3dMjj98iKRjlKvEmqqdUmoZY+l/N", - "Ye9gRf0UY44jJ0f4H81osGtmXg1dRc47OE/pUGGbIare4GNvBB/oiksvoCDOOEKy", - "cj6IAjR/BnSZ1mYvSShSPatu7QRFdd/HFRt76pGj2G6ibnnDNpfjDwgNaWbiGUU=", - "=d2bb", - "-----END PGP MESSAGE-----" - ); + private static final String NEWLINE = "\n"; /** * Test port for proxy settings test. @@ -101,14 +87,18 @@ public void decryptsAssets() throws Exception { "test/test" ) ).commands(); - final String script = Joiner.on('\n').join( + final String script = new JoinedText( + NEWLINE, "set -x", "set -e", "set -o pipefail", - Joiner.on('\n').join(commands) - ); + new JoinedText( + NEWLINE, + commands + ).asString() + ).asString(); final File dir = this.temp.newFolder(); - FileUtils.write(new File(dir, "a.txt.asc"), DecryptTest.ASC); + FileUtils.write(new File(dir, "a.txt.asc"), new FakePGP().asString()); final String[] keys = {"pubring", "secring"}; for (final String key : keys) { final String gpg = IOUtils.toString( @@ -164,14 +154,19 @@ public void testHttpProxyHandling() throws IOException { * @return XML document */ private XMLDocument createTestProfileXML() { - return new XMLDocument( - Joiner.on("").join( - "

", - "", - "a.txt.asc", - "", - "

" - ) - ); + try { + return new XMLDocument( + new JoinedText( + "", + "

", + "", + "a.txt.asc", + "", + "

" + ).asString() + ); + } catch (final IOException ex) { + throw new IllegalStateException(ex); + } } } diff --git a/src/test/java/com/rultor/agents/req/DockerRunTest.java b/src/test/java/com/rultor/agents/req/DockerRunTest.java index ecf09fb133..0e1c13efc1 100644 --- a/src/test/java/com/rultor/agents/req/DockerRunTest.java +++ b/src/test/java/com/rultor/agents/req/DockerRunTest.java @@ -29,10 +29,10 @@ */ package com.rultor.agents.req; -import com.google.common.base.Joiner; import com.jcabi.immutable.ArrayMap; import com.jcabi.xml.XMLDocument; import com.rultor.spi.Profile; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -47,6 +47,11 @@ */ public final class DockerRunTest { + /** + * Space char. + */ + private static final String SPACE = " "; + /** * DockerRun can fetch environment vars. * @throws Exception In case of error. @@ -55,13 +60,14 @@ public final class DockerRunTest { public void fetchesEnvVars() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

", "A=5B=f e", "HELLO='1'", "", "works

" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -92,12 +98,13 @@ public void fetchesEnvVars() throws Exception { public void fetchesScript() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

", "mvn clean", "", "pwls

" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -118,7 +125,8 @@ public void fetchesScript() throws Exception { public void executesWithComment() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

", "echo \"first\"", "# some comment", @@ -130,7 +138,7 @@ public void executesWithComment() throws Exception { "", // @checkstyle MultipleStringLiterals (1 line) "

" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -182,11 +190,12 @@ public void fetchesFromEmptyProfile() throws Exception { public void fetchesInstallScript() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

hi", "onetwo", "

" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -205,14 +214,15 @@ public void fetchesInstallScript() throws Exception { public void fetchesUninstallScript() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

", "", "onetwo", "", "hi", "

" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -234,10 +244,11 @@ public void fetchesUninstallScript() throws Exception { public void fetchesEnvVarsDefaults() throws Exception { final Profile profile = new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + SPACE, "

A=123", "ALPHA=909

" - ) + ).asString() ) ); MatcherAssert.assertThat( diff --git a/src/test/java/com/rultor/agents/req/FakePGP.java b/src/test/java/com/rultor/agents/req/FakePGP.java new file mode 100644 index 0000000000..561a2ae22d --- /dev/null +++ b/src/test/java/com/rultor/agents/req/FakePGP.java @@ -0,0 +1,83 @@ +/** + * Copyright (c) 2009-2018, rultor.com + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: 1) Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. 2) Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. 3) Neither the name of the rultor.com nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT + * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.rultor.agents.req; + +import java.io.IOException; +import org.cactoos.list.SolidList; +import org.cactoos.text.JoinedText; + +/** + * Fake PGP Signature. + * + * @author Filipe Freire (livrofubia@gmail.com) + * @version $Id$ + * @since ? + */ +final class FakePGP { + + /** + * Returns FakePGP string. + * + * @return String + * @throws IOException ex + */ + public String asString() throws IOException { + return new JoinedText( + "\n", + new SolidList<>( + "-----BEGIN PGP MESSAGE-----", + "Version: GnuPG v1\n", + "hQEMA5qETcGag5w6AQgAvm/P0JUlQAd", + "OtGng5zHLx5cV+BrbpFt1m2ja4BjacYMU", + "wcubtJSh+n0XNLk6zMMCsrDnTfzvi/F", + "EFaRsPVb/ZJHiJGvwhNGyenQWgd6bczIL", + "1UxBZ1BpHTPv5hVK43fb6cYq+e/gniB", + "MvIKlKV+Qh/NVtiQACQJ5xL1M16S9SQuY", + "hjnVEL3JNHiLEAfPS/8xS05DY/w1k/J", + "yPXMZlrR7YGMxUsG6aDaFPAdjcdSbzGCT", + "j4yZPdZtyqePFGXn0VJE7GRywWcmk3N", + "j+oZzgx6DLV3PH40HSYNuyA9a2xFpghTr", + "7uiYRf+rRzXlx7qnBLsvETlhc77zpf0", + "FW4pLq/08ttLADQFsIU2BNHJGPw+96GKJ", + "AVNAm0OxfaMz+U+gy2kIgteuMQmfkYD", + "F0u9HE7NwZ1PlXO5Oszhfdim2LPSyxYMi", + "sKlVilWhPwdumSjmY0IG1B6yc8ZLG4B", + "jBucu3dMjj98iKRjlKvEmqqdUmoZY+l/N", + "Ye9gRf0UY44jJ0f4H81osGtmXg1dRc4", + "7OE/pUGGbIare4GNvBB/oiksvoCDOOEKy", + "cj6IAjR/BnSZ1mYvSShSPatu7QRFdd/", + "HFRt76pGj2G6ibnnDNpfjDwgNaWbiGUU=", + "=d2bb", + "-----END PGP MESSAGE-----" + ) + ).asString(); + } + +} diff --git a/src/test/java/com/rultor/agents/req/StartsRequestITCase.java b/src/test/java/com/rultor/agents/req/StartsRequestITCase.java index 234e34defd..1ed4dc4317 100644 --- a/src/test/java/com/rultor/agents/req/StartsRequestITCase.java +++ b/src/test/java/com/rultor/agents/req/StartsRequestITCase.java @@ -29,13 +29,13 @@ */ package com.rultor.agents.req; -import com.google.common.base.Joiner; import com.jcabi.ssh.SSH; import com.jcabi.ssh.Shell; import com.jcabi.xml.XMLDocument; import com.rultor.spi.Agent; import com.rultor.spi.Profile; import com.rultor.spi.Talk; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Assume; @@ -86,7 +86,8 @@ public void composesCorrectDeployRequest() throws Exception { ); final String repo = String.format("/tmp/%d.git", System.nanoTime()); new Shell.Plain(new Shell.Safe(shell)).exec( - Joiner.on(';').join( + new JoinedText( + ";", "cd /tmp", String.format("git init %s", repo), String.format("cd %s", repo), @@ -100,17 +101,18 @@ public void composesCorrectDeployRequest() throws Exception { "git commit -am 'modified file'", "git checkout master", "git config receive.denyCurrentBranch ignore" - ) + ).asString() ); final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - Joiner.on('\n').join( + new JoinedText( + "\n", "

", "echo 'Hello, world!'", "echo 'I am' $(id -u -n)", "

" - ) + ).asString() ) ) ); @@ -127,17 +129,19 @@ public void composesCorrectDeployRequest() throws Exception { agent.execute(talk); final String dir = String.format("/tmp/test-%d", System.nanoTime()); final String stdout = new Shell.Plain(shell).exec( - Joiner.on('\n').join( + new JoinedText( + "\n", String.format("mkdir %s", dir), String.format("cd %s", dir), talk.read().xpath("//script/text()").get(0) - ) + ).asString() ); new Shell.Plain(new Shell.Safe(shell)).exec( - Joiner.on('\n').join( + new JoinedText( + "\n", String.format("rm -rf %s", repo), String.format("sudo rm -rf %s", dir) - ) + ).asString() ); MatcherAssert.assertThat( stdout, diff --git a/src/test/java/com/rultor/agents/req/StartsRequestTest.java b/src/test/java/com/rultor/agents/req/StartsRequestTest.java index 430928cfcf..c7e38e141b 100644 --- a/src/test/java/com/rultor/agents/req/StartsRequestTest.java +++ b/src/test/java/com/rultor/agents/req/StartsRequestTest.java @@ -29,7 +29,6 @@ */ package com.rultor.agents.req; -import com.google.common.base.Joiner; import com.jcabi.immutable.Array; import com.jcabi.log.VerboseProcess; import com.jcabi.matchers.XhtmlMatchers; @@ -41,7 +40,7 @@ import java.io.IOException; import java.util.logging.Level; import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; +import org.cactoos.text.JoinedText; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -109,13 +108,14 @@ public void startsDeployRequest() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + " ", "

", "echo HEY", "", "-Xmx2g -Xms1g", "

" - ) + ).asString() ) ) ); @@ -132,10 +132,11 @@ public void startsDeployRequest() throws Exception { agent.execute(talk); talk.modify( new Directives().xpath("/talk/daemon/script").set( - Joiner.on('\n').join( + new JoinedText( + "\n", talk.read().xpath("/talk/daemon/script/text()").get(0), "cd ..; cat entry.sh; cat script.sh" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -176,12 +177,13 @@ public void startsReleaseRequest() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - StringUtils.join( + new JoinedText( + "", "

", "echo HEY", "a/b", "

" - ) + ).asString() ) ) ); @@ -210,10 +212,11 @@ public void startsMergeRequest() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - StringUtils.join( + new JoinedText( + "", "

", "echo HEY

" - ) + ).asString() ) ) ); @@ -248,12 +251,13 @@ public void runsReleaseWithDockerfile() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - StringUtils.join( + new JoinedText( + "", "

", "echo HEY", String.format("%s", dir), "

" - ) + ).asString() ) ) ); @@ -300,10 +304,11 @@ public void decryptsAssets() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - StringUtils.join( + new JoinedText( + "", "

", "a.txt.asc

" - ) + ).asString() ) ) ); @@ -334,12 +339,13 @@ public void runsAsRootIfRequested() throws Exception { final Agent agent = new StartsRequest( new Profile.Fixed( new XMLDocument( - StringUtils.join( + new JoinedText( + "", "

", "true", "", "echo BOOM

" - ) + ).asString() ) ) ); @@ -356,10 +362,11 @@ public void runsAsRootIfRequested() throws Exception { agent.execute(talk); talk.modify( new Directives().xpath("/talk/daemon/script").set( - Joiner.on('\n').join( + new JoinedText( + "\n", talk.read().xpath("/talk/daemon/script/text()").get(0), "cd ..; cat entry.sh" - ) + ).asString() ) ); MatcherAssert.assertThat( @@ -375,7 +382,8 @@ public void runsAsRootIfRequested() throws Exception { * @throws java.io.IOException If fails */ private String exec(final Talk talk) throws IOException { - final String script = Joiner.on('\n').join( + final String script = new JoinedText( + "\n", "set -x", "set -e", "set -o pipefail", @@ -390,7 +398,7 @@ private String exec(final Talk talk) throws IOException { " done", "} ", talk.read().xpath("//script/text()").get(0) - ); + ).asString(); return new VerboseProcess( new ProcessBuilder().command( "/bin/bash", "-c", script @@ -410,7 +418,8 @@ private File repo() throws IOException { new ProcessBuilder().command( "/bin/bash", "-c", - Joiner.on(';').join( + new JoinedText( + ";", "set -x", "set -e", "set -o pipefail", @@ -425,7 +434,7 @@ private File repo() throws IOException { "git commit -am 'modified file'", "git checkout master", "git config receive.denyCurrentBranch ignore" - ) + ).asString() ).directory(repo) ).stdout(); return repo; diff --git a/src/test/java/com/rultor/agents/shells/RegistersShellTest.java b/src/test/java/com/rultor/agents/shells/RegistersShellTest.java index 2c8676e1a7..f5a07b99eb 100644 --- a/src/test/java/com/rultor/agents/shells/RegistersShellTest.java +++ b/src/test/java/com/rultor/agents/shells/RegistersShellTest.java @@ -29,12 +29,12 @@ */ package com.rultor.agents.shells; -import com.google.common.base.Joiner; import com.jcabi.matchers.XhtmlMatchers; import com.jcabi.xml.XMLDocument; import com.rultor.spi.Agent; import com.rultor.spi.Profile; import com.rultor.spi.Talk; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.junit.Test; import org.mockito.Mockito; @@ -62,14 +62,15 @@ public void registersShell() throws Exception { final Agent agent = new RegistersShell( new Profile.Fixed( new XMLDocument( - Joiner.on(' ').join( + new JoinedText( + " ", "

", String.format("%s", host), String.format("%d", port), String.format("%s", key), String.format("%s", login), "

" - ) + ).asString() ) ), "localhost", 22, "rultor", "def-key" diff --git a/src/test/java/com/rultor/agents/twitter/TweetsTest.java b/src/test/java/com/rultor/agents/twitter/TweetsTest.java index 44173c2488..a90f4d5d98 100644 --- a/src/test/java/com/rultor/agents/twitter/TweetsTest.java +++ b/src/test/java/com/rultor/agents/twitter/TweetsTest.java @@ -29,15 +29,13 @@ */ package com.rultor.agents.twitter; -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; import com.jcabi.github.Issue; -import com.jcabi.github.Language; import com.jcabi.github.Repo; import com.jcabi.github.mock.MkGithub; import com.rultor.spi.Talk; import java.io.IOException; +import org.cactoos.iterable.Mapped; +import org.cactoos.text.JoinedText; import org.junit.Test; import org.mockito.Matchers; import org.mockito.Mockito; @@ -80,17 +78,13 @@ public void postsTweetWithLanguages() throws Exception { ); Mockito.verify(twitter).post( Matchers.contains( - Joiner.on(' ').join( - Iterables.transform( - repo.languages(), - new Function() { - @Override - public String apply(final Language lang) { - return String.format("#%s", lang.name()); - } - } + new JoinedText( + " ", + new Mapped<>( + lang -> String.format("#%s", lang.name()), + repo.languages() ) - ) + ).asString() ) ); } diff --git a/src/test/java/com/rultor/profiles/GithubProfileTest.java b/src/test/java/com/rultor/profiles/GithubProfileTest.java index e1a5c58de1..107e355821 100644 --- a/src/test/java/com/rultor/profiles/GithubProfileTest.java +++ b/src/test/java/com/rultor/profiles/GithubProfileTest.java @@ -29,7 +29,6 @@ */ package com.rultor.profiles; -import com.google.common.base.Joiner; import com.jcabi.github.Coordinates; import com.jcabi.github.Github; import com.jcabi.github.Repo; @@ -38,8 +37,9 @@ import com.jcabi.matchers.XhtmlMatchers; import com.rultor.spi.Profile; import java.io.IOException; +import java.util.Base64; import javax.json.Json; -import org.apache.commons.codec.binary.Base64; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Test; @@ -61,7 +61,8 @@ public final class GithubProfileTest { @Test public void fetchesYamlConfig() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets:", " test.xml: jeff/test1#test.xml", " beta: jeff/test1#test.xml", @@ -70,7 +71,7 @@ public void fetchesYamlConfig() throws Exception { " - donald", "merge:", " script: hello!" - ) + ).asString() ); final String yaml = "friends:\n - jeff/test2"; repo.github() @@ -80,7 +81,10 @@ public void fetchesYamlConfig() throws Exception { Json.createObjectBuilder() .add("path", ".rultor.yml") .add("message", "rultor config") - .add("content", Base64.encodeBase64String(yaml.getBytes())) + .add( + "content", + Base64.getEncoder().encodeToString(yaml.getBytes()) + ) .build() ); final Profile profile = new GithubProfile(repo); @@ -122,10 +126,11 @@ public void throwsWhenYamlIsBroken() throws Exception { @Test(expected = Profile.ConfigException.class) public void throwsWhenAssetIsMisconfigured() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets: ", " something.xml: -invalid.user.name/test1#test.xml" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -137,10 +142,11 @@ public void throwsWhenAssetIsMisconfigured() throws Exception { @Test(expected = Profile.ConfigException.class) public void throwsWhenAssetsUsernameContainsUnderscore() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets: ", " something.xml: invalid_username/test1#test.xml" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -154,10 +160,11 @@ public void throwsWhenAssetsUsernameContainsUnderscore() throws Exception { public void throwsWhenAssetsUsernameStartsWithUnderscore() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets: ", " something.xml: _invalidusername/test1#test.xml" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -179,14 +186,15 @@ public void acceptsAssetsFromDotRepo() throws Exception { .add("message", "just test") .add( "content", - Base64.encodeBase64String( - Joiner.on('\n').join( + Base64.getEncoder().encodeToString( + new JoinedText( + "\n", "assets: ", String.format( " something.xml: jeff/%s#.rultor.yml", name ), "friends:", String.format(" - jeff/%s", name) - ).getBytes() + ).asString().getBytes() ) ).build() ); @@ -203,10 +211,11 @@ public void acceptsAssetsFromDotRepo() throws Exception { @Test(expected = Profile.ConfigException.class) public void throwsWhenRultorConfigIsAbsent() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets: ", " something.xml: jeff/test2#.rultor.yml" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -218,10 +227,11 @@ public void throwsWhenRultorConfigIsAbsent() throws Exception { @Test(expected = Profile.ConfigException.class) public void throwsWhenFriendNotDefined() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets: ", " a.xml: jeff/test1#test.xml" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -234,12 +244,13 @@ public void throwsWhenFriendNotDefined() throws Exception { @Test(expected = Profile.ConfigException.class) public void testAssetNotFound() throws Exception { final Repo repo = GithubProfileTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets:", " test.xml: jeff/test1#test.xmls", "merge:", " script: hello!" - ) + ).asString() ); final String yaml = "friends:\n - jeff/test2"; repo.github() @@ -249,7 +260,10 @@ public void testAssetNotFound() throws Exception { Json.createObjectBuilder() .add("path", ".rultor.yml") .add("message", "rultor config") - .add("content", Base64.encodeBase64String(yaml.getBytes())) + .add( + "content", + Base64.getEncoder().encodeToString(yaml.getBytes()) + ) .build() ); final Profile profile = new GithubProfile(repo); @@ -271,7 +285,10 @@ private static Repo repo(final String yaml) throws IOException { Json.createObjectBuilder() .add("path", "test.xml") .add("message", "just test msg") - .add("content", Base64.encodeBase64String("hey".getBytes())) + .add( + "content", + Base64.getEncoder().encodeToString("hey".getBytes()) + ) .build() ); final Repo repo = github.repos().create( @@ -281,7 +298,10 @@ private static Repo repo(final String yaml) throws IOException { Json.createObjectBuilder() .add("path", ".rultor.yml") .add("message", "just test") - .add("content", Base64.encodeBase64String(yaml.getBytes())) + .add( + "content", + Base64.getEncoder().encodeToString(yaml.getBytes()) + ) .build() ); return repo; diff --git a/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java b/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java index 10d92312fc..d65d0d04a8 100644 --- a/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java +++ b/src/test/java/com/rultor/profiles/GithubProfileValidationTest.java @@ -29,7 +29,6 @@ */ package com.rultor.profiles; -import com.google.common.base.Joiner; import com.jcabi.github.Github; import com.jcabi.github.Repo; import com.jcabi.github.Repos; @@ -37,9 +36,10 @@ import com.rultor.spi.Profile; import java.io.IOException; import java.io.InputStream; +import java.util.Base64; import java.util.Map; import javax.json.Json; -import org.apache.commons.codec.binary.Base64; +import org.cactoos.text.JoinedText; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; import org.junit.Ignore; @@ -78,10 +78,11 @@ public void acceptsEmptyYaml() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectsYamlWithoutMergeScript() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "merge:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -94,10 +95,11 @@ public void rejectsYamlWithoutMergeScript() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectsYamlWithoutDeployScript() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "deploy:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -110,10 +112,11 @@ public void rejectsYamlWithoutDeployScript() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectsYamlWithoutReleaseScript() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "release:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -125,11 +128,12 @@ public void rejectsYamlWithoutReleaseScript() throws Exception { @Test public void acceptsYamlWithOnlyMerge() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "merge:", " script:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -141,11 +145,12 @@ public void acceptsYamlWithOnlyMerge() throws Exception { @Test public void acceptsYamlWithOnlyRelease() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "release:", " script:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -157,11 +162,12 @@ public void acceptsYamlWithOnlyRelease() throws Exception { @Test public void acceptsYamlWithOnlyDeploy() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "deploy:", " script:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -173,7 +179,8 @@ public void acceptsYamlWithOnlyDeploy() throws Exception { @Test public void acceptsYamlWithAllCommands() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "deploy:", " script:", " - pwd", @@ -183,7 +190,7 @@ public void acceptsYamlWithAllCommands() throws Exception { "merge:", " script:", " - pwd" - ) + ).asString() ); new GithubProfile(repo).read(); } @@ -195,12 +202,13 @@ public void acceptsYamlWithAllCommands() throws Exception { @Test public void getExistAssets() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "friends:", " - jeff/test", "assets:", " settings.xml: \"jeff/test#exist.txt\"" - ) + ).asString() ); final Map map = new GithubProfile(repo).assets(); MatcherAssert.assertThat( @@ -216,12 +224,13 @@ public void getExistAssets() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectGetAssetWithNotExistFile() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "friends:", " - jeff/test", "assets:", " settings.xml: \"jeff/test#something.txt\"" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -233,12 +242,13 @@ public void rejectGetAssetWithNotExistFile() throws Exception { @Test(expected = IllegalArgumentException.class) public void rejectGetAssetWithWrongRepo() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "friends:", " - jeff/test", "assets:", " settings.xml: \"jeff/fail#exist.txt\"" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -250,12 +260,13 @@ public void rejectGetAssetWithWrongRepo() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectGetAssetWithNoFriendUser() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "friends:", " - zheus/test", "assets:", " settings.xml: \"jeff/test#exist.txt\"" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -267,10 +278,11 @@ public void rejectGetAssetWithNoFriendUser() throws Exception { @Test(expected = Profile.ConfigException.class) public void rejectGetAssetWithNoFriends() throws Exception { final Repo repo = GithubProfileValidationTest.repo( - Joiner.on('\n').join( + new JoinedText( + "\n", "assets:", " settings.xml: \"jeff/test#exist.txt\"" - ) + ).asString() ); new GithubProfile(repo).assets(); } @@ -290,7 +302,10 @@ private static Repo repo(final String yaml) throws IOException { Json.createObjectBuilder() .add("path", ".rultor.yml") .add("message", "just test") - .add("content", Base64.encodeBase64String(yaml.getBytes())) + .add( + "content", + Base64.getEncoder().encodeToString(yaml.getBytes()) + ) .build() ); repo.contents().create(