From dd446b83d869878e2108c226761a1480b175d9e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 00:34:22 -0600 Subject: [PATCH 01/16] Refactoring CommandRunner class and updating its documentation. For this refactoring, the following modifications were performed: - Two inner classes were extracted from the class. - Some variable were renamed to follow programming patterns. --- .../devtools/moe/client/CommandException.java | 49 ++++++++++++ .../devtools/moe/client/CommandOutput.java | 39 +++++++++ .../devtools/moe/client/CommandRunner.java | 79 ++++--------------- .../com/google/devtools/moe/client/Utils.java | 3 +- .../moe/client/codebase/CodebaseMerger.java | 6 +- .../directives/CreateCodebaseDirective.java | 2 +- .../moe/client/dvcs/AbstractDvcsWriter.java | 8 +- .../client/dvcs/git/GitClonedRepository.java | 8 +- .../client/dvcs/git/GitRepositoryFactory.java | 3 +- .../client/dvcs/git/GitRevisionHistory.java | 6 +- .../moe/client/dvcs/git/GitWriter.java | 2 +- .../client/dvcs/hg/HgClonedRepository.java | 10 +-- .../client/dvcs/hg/HgRepositoryFactory.java | 2 +- .../moe/client/dvcs/hg/HgRevisionHistory.java | 8 +- .../devtools/moe/client/dvcs/hg/HgWriter.java | 2 +- .../moe/client/editors/PatchingEditor.java | 5 +- .../moe/client/editors/ScrubbingEditor.java | 5 +- .../moe/client/editors/ShellEditor.java | 5 +- .../moe/client/svn/SvnCodebaseCreator.java | 3 +- .../moe/client/svn/SvnRevisionHistory.java | 2 +- .../devtools/moe/client/svn/SvnUtil.java | 5 +- .../devtools/moe/client/svn/SvnWriter.java | 11 +-- .../client/testing/FileCodebaseCreator.java | 2 +- .../moe/client/tools/FileDifference.java | 11 +-- .../moe/client/SystemCommandRunnerTest.java | 11 ++- .../client/codebase/CodebaseMergerTest.java | 5 +- .../codebase/FileCodebaseCreatorTest.java | 2 +- .../dvcs/git/GitRevisionHistoryTest.java | 2 +- .../moe/client/dvcs/git/GitWriterTest.java | 2 +- .../client/dvcs/hg/HgRevisionHistoryTest.java | 2 +- .../moe/client/dvcs/hg/HgWriterTest.java | 2 +- .../client/svn/SvnRevisionHistoryTest.java | 2 +- .../moe/client/svn/SvnWriterTest.java | 2 +- .../moe/client/tools/FileDifferenceTest.java | 9 ++- 34 files changed, 182 insertions(+), 133 deletions(-) create mode 100644 java/com/google/devtools/moe/client/CommandException.java create mode 100644 java/com/google/devtools/moe/client/CommandOutput.java diff --git a/java/com/google/devtools/moe/client/CommandException.java b/java/com/google/devtools/moe/client/CommandException.java new file mode 100644 index 00000000..908a3b5b --- /dev/null +++ b/java/com/google/devtools/moe/client/CommandException.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2011 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.moe.client; + +import java.util.Collections; +import java.util.List; + +/** + * A class responsible for storing the information about the exception for a + * command execution. + */ +public class CommandException extends Exception { + + public final String COMMAND; + public final List ARGS; + public final String STDOUT; + public final String STDERR; + public final int RETURN_STATUS; + + public CommandException(String command, List args, String stdout, + String stderr, int returnStatus) { + super(String.format( + "Running %s with args %s returned %d with stdout %s and stderr %s", + command, + args, + returnStatus, + stdout, + stderr)); + this.COMMAND = command; + this.ARGS = Collections.unmodifiableList(args); + this.STDOUT = stdout; + this.STDERR = stderr; + this.RETURN_STATUS = returnStatus; + } +} diff --git a/java/com/google/devtools/moe/client/CommandOutput.java b/java/com/google/devtools/moe/client/CommandOutput.java new file mode 100644 index 00000000..1d68eca6 --- /dev/null +++ b/java/com/google/devtools/moe/client/CommandOutput.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2011 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.moe.client; + +/** + * The complete result, including stdout and stderr, of running a command. + */ +public class CommandOutput { + + private final String stdout; + private final String stderr; + + public CommandOutput(String stdout, String stderr) { + this.stdout = stdout; + this.stderr = stderr; + } + + public String getStdout() { + return stdout; + } + + public String getStderr() { + return stderr; + } +} diff --git a/java/com/google/devtools/moe/client/CommandRunner.java b/java/com/google/devtools/moe/client/CommandRunner.java index 17d56f6e..839d0f0a 100644 --- a/java/com/google/devtools/moe/client/CommandRunner.java +++ b/java/com/google/devtools/moe/client/CommandRunner.java @@ -16,7 +16,6 @@ package com.google.devtools.moe.client; -import java.util.Collections; import java.util.List; /** @@ -24,76 +23,30 @@ */ public interface CommandRunner { - public static class CommandException extends Exception { - public final String cmd; - public final List args; - public final String stdout; - public final String stderr; - public final int returnStatus; - - public CommandException( - String cmd, List args, String stdout, String stderr, int returnStatus) { - super( - String.format( - "Running %s with args %s returned %d with stdout %s and stderr %s", - cmd, - args, - returnStatus, - stdout, - stderr)); - this.cmd = cmd; - this.args = Collections.unmodifiableList(args); - this.stdout = stdout; - this.stderr = stderr; - this.returnStatus = returnStatus; - } - } - - /** - * The complete result, including stdout and stderr, of running a command. - */ - public static class CommandOutput { - private final String stdout; - private final String stderr; - - public CommandOutput(String stdout, String stderr) { - this.stdout = stdout; - this.stderr = stderr; - } - - public String getStdout() { - return stdout; - } - - public String getStderr() { - return stderr; - } - } - /** * Runs a command. * - * @param cmd the binary to invoke. If not a path, it will be resolved. - * @param args the arguments to pass to the binary - * @param workingDirectory the directory to run in - * - * @returns the output of the command - * @throws CommandException - * - * TODO(dbentley): make it easier to do error-handling + * @param command the binary to invoke. If not a path, it will be resolved. + * @param args the arguments to pass to the binary. + * @param workingDirectory the directory to run in. + * + * @return the output of the command. + * @throws CommandException if some error occurs in the command execution. */ - String runCommand(String cmd, List args, String workingDirectory) throws CommandException; + // TODO(dbentley): make it easier to do error-handling + public String runCommand(String command, List args, String workingDirectory) + throws CommandException; /** * Runs a command. * - * @param cmd the binary to invoke. If not a path, it will be resolved. - * @param args the arguments to pass to the binary - * @param workingDirectory the directory to run in + * @param command the binary to invoke. If not a path, it will be resolved. + * @param args the arguments to pass to the binary. + * @param workingDirectory the directory to run in. * - * @returns a {@link CommandOutput} with the full results of the command - * @throws CommandException + * @return a {@link CommandOutput} with the full results of the command. + * @throws CommandException if some error occurs in the command execution. */ - CommandOutput runCommandWithFullOutput(String cmd, List args, String workingDirectory) - throws CommandException; + public CommandOutput runCommandWithFullOutput(String command, List args, + String workingDirectory) throws CommandException; } diff --git a/java/com/google/devtools/moe/client/Utils.java b/java/com/google/devtools/moe/client/Utils.java index b97bae80..60ab1ed5 100644 --- a/java/com/google/devtools/moe/client/Utils.java +++ b/java/com/google/devtools/moe/client/Utils.java @@ -22,7 +22,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; -import com.google.devtools.moe.client.CommandRunner.CommandException; import com.google.gson.Gson; import java.io.File; @@ -130,7 +129,7 @@ public static File expandTar(File tar) throws IOException, CommandException { .cmd() .runCommand( "tar", ImmutableList.of("-xf", tar.getAbsolutePath()), expandedDir.getAbsolutePath()); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { Injector.INSTANCE.fileSystem().deleteRecursively(expandedDir); throw e; } diff --git a/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java b/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java index 52eafb64..19c415e0 100644 --- a/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java +++ b/java/com/google/devtools/moe/client/codebase/CodebaseMerger.java @@ -20,8 +20,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; @@ -239,12 +239,12 @@ public void generateMergedFile(String filename) { mergedFiles.add(mergedFile.getAbsolutePath()); } catch (CommandException e) { // If merge fails with exit status 1, then a conflict occurred. Make a note of the filepath. - if (e.returnStatus == 1) { + if (e.RETURN_STATUS == 1) { failedToMergeFiles.add(mergedFile.getAbsolutePath()); } else { throw new MoeProblem( "Merge returned with unexpected status %d when trying to run \"merge -p %s %s %s\"", - e.returnStatus, + e.RETURN_STATUS, destFile.getAbsolutePath(), origFile.getAbsolutePath(), modFile.getAbsolutePath()); diff --git a/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java b/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java index 0532e6bc..31d6eabb 100644 --- a/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java +++ b/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java @@ -19,8 +19,8 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.Ui.Task; import com.google.devtools.moe.client.codebase.Codebase; diff --git a/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java b/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java index f4c9e40e..8d164909 100644 --- a/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.dvcs; import com.google.common.collect.Sets; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; @@ -86,11 +86,11 @@ private DraftRevision putCodebase(Codebase incomingChangeCodebase) { putFile(filename, incomingChangeCodebase); } catch (CommandException e) { StringBuilder sb = new StringBuilder("Problem occurred while running '"); - sb.append(e.cmd); - for (String arg : e.args) { + sb.append(e.COMMAND); + for (String arg : e.ARGS) { sb.append(" ").append(arg); } - sb.append("': ").append(e.stderr); + sb.append("': ").append(e.STDERR); throw new MoeProblem(sb.toString()); } } diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java b/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java index db547561..da3e0ecb 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java @@ -20,8 +20,8 @@ import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.FileSystem.Lifetime; import com.google.devtools.moe.client.Lifetimes; @@ -119,7 +119,7 @@ public void cloneLocallyAtHead(Lifetime cloneLifetime) { clonedLocally = true; this.revId = "HEAD"; } catch (CommandException e) { - throw new MoeProblem("Could not clone from git repo at " + repositoryUrl + ": " + e.stderr); + throw new MoeProblem("Could not clone from git repo at " + repositoryUrl + ": " + e.STDERR); } } @@ -137,7 +137,7 @@ public void updateToRevision(String revId) { } this.revId = revId; } catch (CommandException e) { - throw new MoeProblem("Could not update git repo at " + localCloneTempDir + ": " + e.stderr); + throw new MoeProblem("Could not update git repo at " + localCloneTempDir + ": " + e.STDERR); } } @@ -179,7 +179,7 @@ public File archiveAtRevision(String revId) { "Could not archive git clone at " + localCloneTempDir.getAbsolutePath() + ": " - + e.stderr); + + e.STDERR); } catch (IOException e) { throw new MoeProblem( "IOException archiving clone at " diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java b/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java index 2f324b87..08eb6687 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java @@ -20,6 +20,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -108,7 +109,7 @@ public GitClonedRepository get() { * Run git with the specified args in the specified directory. */ static String runGitCommand(List args, String workingDirectory) - throws CommandRunner.CommandException { + throws CommandException { return Injector.INSTANCE.cmd().runCommand("git", args, workingDirectory); } } diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistory.java b/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistory.java index 2cab5035..cb02312c 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistory.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitRevisionHistory.java @@ -22,7 +22,7 @@ import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.repositories.AbstractRevisionHistory; import com.google.devtools.moe.client.repositories.Revision; @@ -69,7 +69,7 @@ public Revision findHighestRevision(String revId) { try { hashID = headClone.runGitCommand("log", "--max-count=1", "--format=%H", revId).trim(); } catch (CommandException e) { - throw new MoeProblem("Failed git log run: %d %s %s", e.returnStatus, e.stdout, e.stderr); + throw new MoeProblem("Failed git log run: %d %s %s", e.RETURN_STATUS, e.STDOUT, e.STDERR); } return Revision.create(hashID, headClone.getRepositoryName()); } @@ -104,7 +104,7 @@ public RevisionMetadata getMetadata(Revision revision) { "--ignore-missing", revision.revId()); } catch (CommandException e) { - throw new MoeProblem("Failed git run: %d %s %s", e.returnStatus, e.stdout, e.stderr); + throw new MoeProblem("Failed git run: %d %s %s", e.RETURN_STATUS, e.STDOUT, e.STDERR); } return parseMetadata(log); diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java b/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java index e03aba47..adb4a63b 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java @@ -19,7 +19,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java b/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java index 65284c33..94ecfbab 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java @@ -23,7 +23,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.FileSystem.Lifetime; import com.google.devtools.moe.client.Lifetimes; @@ -120,7 +120,7 @@ public void cloneLocallyAtHead(Lifetime cloneLifetime) { HgRepositoryFactory.runHgCommand(asList("branch"), localCloneTempDir.getAbsolutePath()) .trim(); } catch (CommandException e) { - throw new MoeProblem("Could not clone from hg repo at " + repositoryUrl + ": " + e.stderr); + throw new MoeProblem("Could not clone from hg repo at " + repositoryUrl + ": " + e.STDERR); } } @@ -133,7 +133,7 @@ public void updateToRevision(String revId) { updatedToRev = true; } catch (CommandException e) { throw new MoeProblem( - "Could not clone from hg repo at " + localCloneTempDir + ": " + e.stderr); + "Could not clone from hg repo at " + localCloneTempDir + ": " + e.STDERR); } } @@ -153,7 +153,7 @@ public File archiveAtRevision(String revId) { filesystem.deleteRecursively(new File(archiveLocation, ".hg_archival.txt")); } catch (CommandException e) { throw new MoeProblem( - "Could not archive hg clone at " + localCloneTempDir.getAbsolutePath() + ": " + e.stderr); + "Could not archive hg clone at " + localCloneTempDir.getAbsolutePath() + ": " + e.STDERR); } catch (IOException e) { throw new MoeProblem( "IOException archiving clone at " @@ -170,7 +170,7 @@ public File archiveAtRevision(String revId) { * Runs an hg command with the given arguments, in this cloned repository's directory. * * @param args a list of arguments to the 'hg' command - * @return the stdout output of the command + * @return the STDOUT output of the command */ String runHgCommand(String... args) throws CommandException { return cmd.runCommand( diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java b/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java index 28448f05..21d5d094 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java @@ -21,7 +21,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.Lifetimes; diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistory.java b/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistory.java index 2d740583..fb57b476 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistory.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistory.java @@ -21,7 +21,7 @@ import com.google.common.base.Strings; import com.google.common.base.Supplier; import com.google.common.collect.ImmutableList; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.repositories.AbstractRevisionHistory; import com.google.devtools.moe.client.repositories.Revision; @@ -78,7 +78,7 @@ public Revision findHighestRevision(@Nullable String revId) { changesetID = HgRepositoryFactory.runHgCommand(args, tipClone.getLocalTempDir().getAbsolutePath()); } catch (CommandException e) { - throw new MoeProblem("Failed hg run: %s %d %s %s", args, e.returnStatus, e.stdout, e.stderr); + throw new MoeProblem("Failed hg run: %s %d %s %s", args, e.RETURN_STATUS, e.STDOUT, e.STDERR); } return Revision.create(changesetID, tipClone.getRepositoryName()); @@ -115,7 +115,7 @@ public RevisionMetadata getMetadata(Revision revision) { try { log = HgRepositoryFactory.runHgCommand(args, tipClone.getLocalTempDir().getAbsolutePath()); } catch (CommandException e) { - throw new MoeProblem("Failed hg run: %s %d %s %s", args, e.returnStatus, e.stdout, e.stderr); + throw new MoeProblem("Failed hg run: %s %d %s %s", args, e.RETURN_STATUS, e.STDOUT, e.STDERR); } return parseMetadata(log); @@ -180,7 +180,7 @@ protected List findHeadRevisions() { tipClone.getLocalTempDir().getAbsolutePath()); } catch (CommandException e) { throw new MoeProblem( - "Failed hg run: %s %d %s %s", e.args, e.returnStatus, e.stdout, e.stderr); + "Failed hg run: %s %d %s %s", e.ARGS, e.RETURN_STATUS, e.STDOUT, e.STDERR); } ImmutableList.Builder result = ImmutableList.builder(); diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java b/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java index a07902ff..809f47b0 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java @@ -19,7 +19,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.Ui; diff --git a/java/com/google/devtools/moe/client/editors/PatchingEditor.java b/java/com/google/devtools/moe/client/editors/PatchingEditor.java index 7f7f2cec..b37e1a27 100644 --- a/java/com/google/devtools/moe/client/editors/PatchingEditor.java +++ b/java/com/google/devtools/moe/client/editors/PatchingEditor.java @@ -19,6 +19,7 @@ import static com.google.common.base.Strings.isNullOrEmpty; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -70,7 +71,7 @@ public Codebase edit(Codebase input, ProjectContext context, Map } try { Utils.copyDirectory(input.getPath(), tempDir); - } catch (IOException | CommandRunner.CommandException e) { + } catch (IOException | CommandException e) { throw new MoeProblem(e.getMessage()); } try { @@ -78,7 +79,7 @@ public Codebase edit(Codebase input, ProjectContext context, Map "patch", ImmutableList.of("-p0", "--input=" + patchFilePath), tempDir.getAbsolutePath()); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { throw new MoeProblem(e.getMessage()); } return new Codebase(filesystem, tempDir, input.getProjectSpace(), input.getExpression()); diff --git a/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java b/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java index 1f84d29c..5b5d6bf6 100644 --- a/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java +++ b/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java @@ -19,6 +19,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -109,13 +110,13 @@ public Codebase edit(Codebase input, ProjectContext context, Map // TODO(cgruber): Eliminate this static gson method reference. input.getPath().getAbsolutePath()), SCRUBBER_BINARY_SUPPLIER.get().getParentFile().getPath()); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { throw new MoeProblem(e.getMessage()); } File expandedDir = null; try { expandedDir = Utils.expandTar(outputTar); - } catch (IOException | CommandRunner.CommandException e) { + } catch (IOException | CommandException e) { throw new MoeProblem(e.getMessage()); } return new Codebase(filesystem, expandedDir, input.getProjectSpace(), input.getExpression()); diff --git a/java/com/google/devtools/moe/client/editors/ShellEditor.java b/java/com/google/devtools/moe/client/editors/ShellEditor.java index 981bbed8..f67c4348 100644 --- a/java/com/google/devtools/moe/client/editors/ShellEditor.java +++ b/java/com/google/devtools/moe/client/editors/ShellEditor.java @@ -17,6 +17,7 @@ package com.google.devtools.moe.client.editors; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -71,12 +72,12 @@ public Codebase edit(Codebase input, ProjectContext context, Map File tempDir = filesystem.getTemporaryDirectory("shell_run_"); try { Utils.copyDirectory(input.getPath(), tempDir); - } catch (IOException | CommandRunner.CommandException e) { + } catch (IOException | CommandException e) { throw new MoeProblem(e.getMessage()); } try { cmd.runCommand("bash", ImmutableList.of("-c", this.commandString), tempDir.getAbsolutePath()); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { throw new MoeProblem(e.getMessage()); } return new Codebase(filesystem, tempDir, input.getProjectSpace(), input.getExpression()); diff --git a/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java b/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java index c0add9ee..93c6be7c 100644 --- a/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java +++ b/java/com/google/devtools/moe/client/svn/SvnCodebaseCreator.java @@ -17,6 +17,7 @@ package com.google.devtools.moe.client.svn; import com.google.common.base.Predicate; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; @@ -71,7 +72,7 @@ public Codebase create(Map options) throws CodebaseCreationError try { util.runSvnCommand( "export", config.getUrl(), "-r", rev.revId(), exportPath.getAbsolutePath()); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { throw new MoeProblem("could not export from svn" + e.getMessage()); } diff --git a/java/com/google/devtools/moe/client/svn/SvnRevisionHistory.java b/java/com/google/devtools/moe/client/svn/SvnRevisionHistory.java index fa9e7bb2..23b48514 100644 --- a/java/com/google/devtools/moe/client/svn/SvnRevisionHistory.java +++ b/java/com/google/devtools/moe/client/svn/SvnRevisionHistory.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.svn; import com.google.common.collect.ImmutableList; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.repositories.AbstractRevisionHistory; import com.google.devtools.moe.client.repositories.Revision; diff --git a/java/com/google/devtools/moe/client/svn/SvnUtil.java b/java/com/google/devtools/moe/client/svn/SvnUtil.java index d79990f6..3bea5fab 100644 --- a/java/com/google/devtools/moe/client/svn/SvnUtil.java +++ b/java/com/google/devtools/moe/client/svn/SvnUtil.java @@ -17,6 +17,7 @@ package com.google.devtools.moe.client.svn; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import java.util.Arrays; @@ -36,13 +37,13 @@ public SvnUtil(CommandRunner cmd) { } String runSvnCommandWithWorkingDirectory(String workingDirectory, String command, String... args) - throws CommandRunner.CommandException { + throws CommandException { ImmutableList.Builder withAuthArgs = ImmutableList.builder(); withAuthArgs.add("--no-auth-cache").add(command).addAll(Arrays.asList(args)); return cmd.runCommand("svn", withAuthArgs.build(), workingDirectory); } - String runSvnCommand(String command, String... args) throws CommandRunner.CommandException { + String runSvnCommand(String command, String... args) throws CommandException { return runSvnCommandWithWorkingDirectory("", command, args); } } diff --git a/java/com/google/devtools/moe/client/svn/SvnWriter.java b/java/com/google/devtools/moe/client/svn/SvnWriter.java index 40e6041c..82ea16d9 100644 --- a/java/com/google/devtools/moe/client/svn/SvnWriter.java +++ b/java/com/google/devtools/moe/client/svn/SvnWriter.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Sets; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -64,8 +65,8 @@ public void checkOut() { try { util.runSvnCommand( "co", "-r", revision.revId(), config.getUrl(), rootDirectory.getAbsolutePath()); - } catch (CommandRunner.CommandException e) { - throw new MoeProblem("Could not check out from svn: " + e.stderr); + } catch (CommandException e) { + throw new MoeProblem("Could not check out from svn: " + e.STDERR); } } @@ -163,7 +164,7 @@ void putFile(String relativePath, Codebase codebase) { try { util.runSvnCommandWithWorkingDirectory( rootDirectory.getAbsolutePath(), "propset", "svn:mime-type", mimeType, relativePath); - } catch (CommandRunner.CommandException e) { + } catch (CommandException e) { // If the mime type setting fails, it's not really a big deal. // Just log it and keep going. Injector.INSTANCE.ui().info("Error setting mime-type for %s", relativePath); @@ -179,8 +180,8 @@ void putFile(String relativePath, Codebase codebase) { rootDirectory.getAbsolutePath(), "propdel", "svn:executable", relativePath); } } - } catch (CommandRunner.CommandException e) { - throw new MoeProblem("problem occurred while running svn: " + e.stderr); + } catch (CommandException e) { + throw new MoeProblem("problem occurred while running svn: " + e.STDERR); } } diff --git a/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java b/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java index 6126b5b1..93fc01d9 100644 --- a/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java +++ b/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java @@ -18,7 +18,7 @@ import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.Utils; diff --git a/java/com/google/devtools/moe/client/tools/FileDifference.java b/java/com/google/devtools/moe/client/tools/FileDifference.java index 99d5dfb7..f8d3ad8b 100644 --- a/java/com/google/devtools/moe/client/tools/FileDifference.java +++ b/java/com/google/devtools/moe/client/tools/FileDifference.java @@ -19,6 +19,7 @@ import com.google.auto.value.AutoValue; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.MoeProblem; @@ -153,12 +154,12 @@ public FileDifference diffFiles(String relativeFilename, File file1, File file2) // -N treats absent files as empty. ImmutableList.of("-N", file1.getAbsolutePath(), file2.getAbsolutePath()), ""); - } catch (CommandRunner.CommandException e) { - if (e.returnStatus != DIFF_ERROR_CODE_FILES_DIFFERENT - && e.returnStatus != DIFF_ERROR_CODE_FILES_BINARY) { - throw new MoeProblem("diff returned unknown status: %d", e.returnStatus); + } catch (CommandException e) { + if (e.RETURN_STATUS != DIFF_ERROR_CODE_FILES_DIFFERENT + && e.RETURN_STATUS != DIFF_ERROR_CODE_FILES_BINARY) { + throw new MoeProblem("diff returned unknown status: %d", e.RETURN_STATUS); } - contentDiff = e.stdout; + contentDiff = e.STDOUT; } return FileDifference.create( diff --git a/javatests/com/google/devtools/moe/client/SystemCommandRunnerTest.java b/javatests/com/google/devtools/moe/client/SystemCommandRunnerTest.java index 3a390824..ac5b6f4e 100644 --- a/javatests/com/google/devtools/moe/client/SystemCommandRunnerTest.java +++ b/javatests/com/google/devtools/moe/client/SystemCommandRunnerTest.java @@ -17,7 +17,6 @@ package com.google.devtools.moe.client; import com.google.common.collect.ImmutableList; -import com.google.devtools.moe.client.CommandRunner.CommandException; import junit.framework.TestCase; @@ -47,8 +46,8 @@ public void testLongStderr() throws Exception { } /** - * Tests that a process with a large stdout and stderr doesn't produce stream contention or - * deadlock behavior. + * Tests that a process with a large STDOUT and STDERR doesn't produce stream contention or + deadlock behavior. */ public void testLongStdoutAndStderr() throws Exception { int bytesOutput = 1000000; @@ -64,9 +63,9 @@ public void testLongStdoutAndStderr() throws Exception { fail("Non-zero return code didn't raise CommandException."); } catch (CommandException expected) { - assertEquals("returnStatus", 1, expected.returnStatus); - assertEquals("stdout length", bytesOutput, expected.stdout.length()); - assertEquals("stderr length", bytesOutput, expected.stderr.length()); + assertEquals("returnStatus", 1, expected.RETURN_STATUS); + assertEquals("stdout length", bytesOutput, expected.STDOUT.length()); + assertEquals("stderr length", bytesOutput, expected.STDERR.length()); } } } diff --git a/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java b/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java index 08a0fe0c..7c54616e 100644 --- a/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java +++ b/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -266,7 +267,7 @@ public void testGenerateMergedFileConflict() throws Exception { mergedFile.getAbsolutePath(), origFile.getAbsolutePath(), modFile.getAbsolutePath()); expect(cmd.runCommand("merge", mergeArgs, mergedCodebaseLocation.getAbsolutePath())) - .andThrow(new CommandRunner.CommandException("merge", mergeArgs, "", "", 1)); + .andThrow(new CommandException("merge", mergeArgs, "", "", 1)); control.replay(); @@ -389,7 +390,7 @@ public void testGenerateMergedFileNoOrigConflict() throws Exception { mergedFile.getAbsolutePath(), origFile.getAbsolutePath(), modFile.getAbsolutePath()); expect(cmd.runCommand("merge", mergeArgs, mergedCodebaseLocation.getAbsolutePath())) - .andThrow(new CommandRunner.CommandException("merge", mergeArgs, "", "", 1)); + .andThrow(new CommandException("merge", mergeArgs, "", "", 1)); control.replay(); diff --git a/javatests/com/google/devtools/moe/client/codebase/FileCodebaseCreatorTest.java b/javatests/com/google/devtools/moe/client/codebase/FileCodebaseCreatorTest.java index 5c12b1ed..00d66918 100644 --- a/javatests/com/google/devtools/moe/client/codebase/FileCodebaseCreatorTest.java +++ b/javatests/com/google/devtools/moe/client/codebase/FileCodebaseCreatorTest.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; diff --git a/javatests/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java b/javatests/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java index bfaff591..8c858869 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/git/GitRevisionHistoryTest.java @@ -24,7 +24,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.NullFileSystemModule; diff --git a/javatests/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java b/javatests/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java index 6e9e4b77..b2f674f1 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/git/GitWriterTest.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.SystemCommandRunner; diff --git a/javatests/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java b/javatests/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java index be6b1af6..c27c952d 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/hg/HgRevisionHistoryTest.java @@ -22,7 +22,7 @@ import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.NullFileSystemModule; diff --git a/javatests/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java b/javatests/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java index 3f8f5f19..a5346e69 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/hg/HgWriterTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.codebase.Codebase; diff --git a/javatests/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java b/javatests/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java index 6c86699b..38877857 100644 --- a/javatests/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java +++ b/javatests/com/google/devtools/moe/client/svn/SvnRevisionHistoryTest.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.NullFileSystemModule; import com.google.devtools.moe.client.database.DbStorage; diff --git a/javatests/com/google/devtools/moe/client/svn/SvnWriterTest.java b/javatests/com/google/devtools/moe/client/svn/SvnWriterTest.java index bd960391..e40ed147 100644 --- a/javatests/com/google/devtools/moe/client/svn/SvnWriterTest.java +++ b/javatests/com/google/devtools/moe/client/svn/SvnWriterTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.moe.client.CommandRunner; -import com.google.devtools.moe.client.CommandRunner.CommandException; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; diff --git a/javatests/com/google/devtools/moe/client/tools/FileDifferenceTest.java b/javatests/com/google/devtools/moe/client/tools/FileDifferenceTest.java index 9050b78b..1288cd77 100644 --- a/javatests/com/google/devtools/moe/client/tools/FileDifferenceTest.java +++ b/javatests/com/google/devtools/moe/client/tools/FileDifferenceTest.java @@ -19,6 +19,7 @@ import static org.easymock.EasyMock.expect; import com.google.common.collect.ImmutableList; +import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; import com.google.devtools.moe.client.Injector; @@ -81,7 +82,7 @@ public void testExistence() throws Exception { expect(fileSystem.isExecutable(file2)).andReturn(false); expect(cmd.runCommand("diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "")) .andThrow( - new CommandRunner.CommandException( + new CommandException( "diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "foo", "", 1)); control.replay(); @@ -102,7 +103,7 @@ public void testExistence2() throws Exception { expect(fileSystem.isExecutable(file2)).andReturn(false); expect(cmd.runCommand("diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "")) .andThrow( - new CommandRunner.CommandException( + new CommandException( "diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "foo", "", 1)); control.replay(); @@ -159,7 +160,7 @@ public void testContents() throws Exception { expect(fileSystem.isExecutable(file2)).andReturn(true); expect(cmd.runCommand("diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "")) .andThrow( - new CommandRunner.CommandException( + new CommandException( "diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "foo", "", 1)); control.replay(); @@ -180,7 +181,7 @@ public void testExecutabilityAndContents() throws Exception { expect(fileSystem.isExecutable(file2)).andReturn(false); expect(cmd.runCommand("diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "")) .andThrow( - new CommandRunner.CommandException( + new CommandException( "diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "foo", "", 1)); control.replay(); From 985c84b103a7d64dd5dc58aa498249a614d2bc79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 01:22:42 -0600 Subject: [PATCH 02/16] Refactoring FileSystem class and updating its documentation. For this refactoring, the following modifications were performed: - One inner class was extracted from the class. - Some variable and methods were renamed to follow programming patterns. --- .../devtools/moe/client/FileSystem.java | 148 ++++++++++++------ .../google/devtools/moe/client/Lifetime.java | 34 ++++ .../google/devtools/moe/client/Lifetimes.java | 2 +- java/com/google/devtools/moe/client/Ui.java | 4 +- .../moe/client/codebase/LocalWorkspace.java | 2 +- .../client/dvcs/git/GitClonedRepository.java | 2 +- .../client/dvcs/hg/HgClonedRepository.java | 2 +- .../client/testing/InMemoryFileSystem.java | 1 + .../dvcs/git/GitClonedRepositoryTest.java | 2 +- .../dvcs/hg/HgClonedRepositoryTest.java | 2 +- .../moe/client/parser/ExpressionTest.java | 2 +- .../testing/InMemoryFileSystemTest.java | 2 +- 12 files changed, 148 insertions(+), 55 deletions(-) create mode 100644 java/com/google/devtools/moe/client/Lifetime.java diff --git a/java/com/google/devtools/moe/client/FileSystem.java b/java/com/google/devtools/moe/client/FileSystem.java index 93f8319f..ae956ad6 100644 --- a/java/com/google/devtools/moe/client/FileSystem.java +++ b/java/com/google/devtools/moe/client/FileSystem.java @@ -30,8 +30,9 @@ public interface FileSystem { * is equivalent to calling {@link #getTemporaryDirectory(String, Lifetime)} with * {@link Lifetimes#currentTask()}. * - * @param prefix a prefix for the basename of the created directory - * @return a path to an uncreated, available temporary directory + * @param prefix a prefix for the basename of the created directory. + * + * @return a path to an uncreated, available temporary directory. */ // TODO(user): Delete all usages of this method in favor of the explicit form. public File getTemporaryDirectory(String prefix); @@ -39,9 +40,10 @@ public interface FileSystem { /** * Finds a Temporary Directory starting with prefix, with the given lifetime. * - * @param prefix a prefix for the basename of the created directory - * @param lifetime a {@code Lifetime} specifying the clean-up behavior of this temp dir - * @return a path to an uncreated, available temporary directory + * @param prefix a prefix for the basename of the created directory. + * @param lifetime a {@code Lifetime} specifying the clean-up behavior of this temp dir. + * + * @return a path to an uncreated, available temporary directory. */ public File getTemporaryDirectory(String prefix, Lifetime lifetime); @@ -49,6 +51,9 @@ public interface FileSystem { * Deletes files/directories created by {@link #getTemporaryDirectory(String, Lifetime)} whose * {@code Lifetime}s specify deletion at this juncture. * + * @throws java.io.IOException if some error occurs while cleaning up the + * temporary directories. + * * @see #setLifetime(File, Lifetime) */ public void cleanUpTempDirs() throws IOException; @@ -56,84 +61,144 @@ public interface FileSystem { /** * Sets the {@link Lifetime} for a path. The path must have been provided by * {@link #getTemporaryDirectory(String, Lifetime)}. + * + * @param path path of the lifetime. + * @param lifetime new value for the lifetime. */ public void setLifetime(File path, Lifetime lifetime); /** - * Find the relative names of files under path. - * + * Find the relative names of files under some path. * NB: returns only files, not directories + * + * @param path path to find the files. + * + * @return the set of files under {@code path}. */ public Set findFiles(File path); /** - * Returns an array of files and directories under path. + * Lists the files and directories under some path. + * + * @param path path to get the files list. + * + * @return an array of files. */ // TODO(user): Return List instead of array. public File[] listFiles(File path); /** * Returns whether the file exists. + * + * @param file file to be checked. + * + * @return true if the file exists or false, otherwise. */ - public boolean exists(File f); + public boolean exists(File file); /** - * Returns the file's name. + * Gets the name of a file. + * + * @param file file to get the name. + * + * @return the name of the file. */ - public String getName(File f); + public String getName(File file); /** - * Returns whether the file is a file. + * Checks if a file is a file. + * + * @param file file to be checked. + * + * @return true if the file is a file or false, otherwise. */ - public boolean isFile(File f); + public boolean isFile(File file); /** - * Returns whether the file is a directory. + * Checks if a file is a directory. + * + * @param file file to be checked. + * + * @return true if the file is a directory or false, otherwise. */ - public boolean isDirectory(File f); + public boolean isDirectory(File file); /** - * Returns whether the file is executable. + * Checks if a file is executable. + * + * @param file file to be checked. + * + * @return true if the file is executable or false, otherwise. */ - public boolean isExecutable(File f); + public boolean isExecutable(File file); /** - * Returns whether the file is readable + * Checks if a file is readable. + * + * @param file file to be checked. + * + * @return true if the file is readable or false, otherwise. */ - public boolean isReadable(File f); + public boolean isReadable(File file); /** * Makes a file executable for all users. + * + * @param file file to be set as executable. */ - public void setExecutable(File f); + public void setExecutable(File file); /** * Makes a file non-executable for all users. + * + * @param file file to be set as non-executable. */ - public void setNonExecutable(File f); + public void setNonExecutable(File file); /** - * Make the parent directory for f exist. + * Make the parent directory for file exist. + * + * @param file parent directory to be created. + * + * @throws java.io.IOException if some error occurs during the directory creation. */ - public void makeDirsForFile(File f) throws IOException; + public void makeDirsForFile(File file) throws IOException; /** - * Make the directory f exist. + * Make the directory exist. + * + * @param file directory to be created. + * + * @throws java.io.IOException if some error occurs during the directory creation. */ - public void makeDirs(File f) throws IOException; + public void makeDirs(File file) throws IOException; /** - * Copy File src's contents into dest. + * Copy the source file contents into destination file. + * + * @param source source of the contents to be copied. + * @param destination destination of the content. + * + * @throws java.io.IOException if some error occurs while copping the content. */ - public void copyFile(File src, File dest) throws IOException; + public void copyFile(File source, File destination) throws IOException; /** - * Write contents to File f. + * Write contents to a file. + * + * @param contents content to be written to the file. + * @param file file where the content will be written. + * + * @throws java.io.IOException if some error occurs while writing to the file. */ - public void write(String contents, File f) throws IOException; + public void write(String contents, File file) throws IOException; /** * Deletes a file or directory and all contents recursively. + * + * @param file file to be deleted. + * @throws java.io.IOException if some error occurs while deleting the file. + * */ public void deleteRecursively(File file) throws IOException; @@ -143,26 +208,19 @@ public interface FileSystem { * @param resource the name of the resource to extract * * @return a path to the resource in the file system + * + * @throws java.io.IOException if some error occurs while getting the file. */ public File getResourceAsFile(String resource) throws IOException; /** - * Reads all characters from f into a String - */ - public String fileToString(File f) throws IOException; - - /** - * A specification of whether a temporary directory should be cleaned up on a call to - * {@link FileSystem#cleanUpTempDirs()}. On clean-up, each temporary directory's {@code Lifetime} - * is looked up, and {@link #shouldCleanUp()} is called. + * Reads all characters from a file into a String. + * + * @param file file to be read. + * + * @return returns the characters from a file into a String. + * @throws java.io.IOException */ - public static interface Lifetime { + public String fileToString(File file) throws IOException; - /** - * Returns whether a temporary directory with this {@code Lifetime} should be cleaned up now. - * - * @see FileSystem#cleanUpTempDirs() - */ - boolean shouldCleanUp(); - } } diff --git a/java/com/google/devtools/moe/client/Lifetime.java b/java/com/google/devtools/moe/client/Lifetime.java new file mode 100644 index 00000000..d96b704c --- /dev/null +++ b/java/com/google/devtools/moe/client/Lifetime.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2012 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.devtools.moe.client; + +/** + * A specification of whether a temporary directory should be cleaned up on a call to + * {@link FileSystem#cleanUpTempDirs()}. On clean-up, each temporary directory's {@code Lifetime} + * is looked up, and {@link #shouldCleanUp()} is called. + */ +public interface Lifetime { + + /** + * Checks if a temporary directory with this {@code Lifetime} should be cleaned up now. + * + * @return true if the directory should be cleaned up now or false, otherwise. + * @see FileSystem#cleanUpTempDirs() + */ + boolean shouldCleanUp(); + +} diff --git a/java/com/google/devtools/moe/client/Lifetimes.java b/java/com/google/devtools/moe/client/Lifetimes.java index 07ea2822..5b698b5d 100644 --- a/java/com/google/devtools/moe/client/Lifetimes.java +++ b/java/com/google/devtools/moe/client/Lifetimes.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; /** * Static utility methods that return common {@link Lifetime}s. diff --git a/java/com/google/devtools/moe/client/Ui.java b/java/com/google/devtools/moe/client/Ui.java index 723a1b23..0c21ec73 100644 --- a/java/com/google/devtools/moe/client/Ui.java +++ b/java/com/google/devtools/moe/client/Ui.java @@ -18,7 +18,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import java.io.File; import java.io.IOException; @@ -153,7 +153,7 @@ Lifetime moeExecutionLifetime() { */ private class TaskLifetime implements Lifetime { - private final Task task; + final Task task; TaskLifetime(Task task) { this.task = task; diff --git a/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java b/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java index 6dce6cfb..aa532453 100644 --- a/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java +++ b/java/com/google/devtools/moe/client/codebase/LocalWorkspace.java @@ -16,7 +16,7 @@ package com.google.devtools.moe.client.codebase; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.project.RepositoryConfig; import java.io.File; diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java b/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java index da3e0ecb..33cbde3d 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitClonedRepository.java @@ -23,7 +23,7 @@ import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.LocalWorkspace; diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java b/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java index 94ecfbab..67d685c9 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgClonedRepository.java @@ -25,7 +25,7 @@ import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.codebase.LocalWorkspace; diff --git a/java/com/google/devtools/moe/client/testing/InMemoryFileSystem.java b/java/com/google/devtools/moe/client/testing/InMemoryFileSystem.java index d047884b..b274b4bd 100644 --- a/java/com/google/devtools/moe/client/testing/InMemoryFileSystem.java +++ b/java/com/google/devtools/moe/client/testing/InMemoryFileSystem.java @@ -22,6 +22,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import com.google.devtools.moe.client.FileSystem; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Lifetimes; import dagger.Provides; diff --git a/javatests/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java b/javatests/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java index 8a66d29c..52d4bbd9 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/git/GitClonedRepositoryTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.project.RepositoryConfig; diff --git a/javatests/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java b/javatests/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java index 101100f2..9c72124e 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/hg/HgClonedRepositoryTest.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.project.RepositoryConfig; diff --git a/javatests/com/google/devtools/moe/client/parser/ExpressionTest.java b/javatests/com/google/devtools/moe/client/parser/ExpressionTest.java index 08a0b707..60406dee 100644 --- a/javatests/com/google/devtools/moe/client/parser/ExpressionTest.java +++ b/javatests/com/google/devtools/moe/client/parser/ExpressionTest.java @@ -21,7 +21,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.devtools.moe.client.FileSystem; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.NullFileSystemModule; diff --git a/javatests/com/google/devtools/moe/client/testing/InMemoryFileSystemTest.java b/javatests/com/google/devtools/moe/client/testing/InMemoryFileSystemTest.java index 94aa52d8..9796c690 100644 --- a/javatests/com/google/devtools/moe/client/testing/InMemoryFileSystemTest.java +++ b/javatests/com/google/devtools/moe/client/testing/InMemoryFileSystemTest.java @@ -18,7 +18,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.devtools.moe.client.FileSystem.Lifetime; +import com.google.devtools.moe.client.Lifetime; import com.google.devtools.moe.client.Injector; import com.google.devtools.moe.client.Lifetimes; import com.google.devtools.moe.client.NullFileSystemModule; From 2bda26f276a9df18e554adb6da9d69005b58a09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 01:31:47 -0600 Subject: [PATCH 03/16] Refactoring Injector class. For this refactoring, the contants and methods were renamed according to programming patterns. --- .../google/devtools/moe/client/Injector.java | 34 +++++++++---------- .../google/devtools/moe/client/Lifetimes.java | 4 +-- java/com/google/devtools/moe/client/Moe.java | 4 +-- .../com/google/devtools/moe/client/Utils.java | 32 ++++++++--------- .../moe/client/dvcs/AbstractDvcsWriter.java | 6 ++-- .../client/dvcs/git/GitRepositoryFactory.java | 2 +- .../moe/client/dvcs/git/GitWriter.java | 2 +- .../client/dvcs/hg/HgRepositoryFactory.java | 2 +- .../devtools/moe/client/dvcs/hg/HgWriter.java | 2 +- .../moe/client/editors/ForwardTranslator.java | 4 +-- .../client/editors/InverseRenamingEditor.java | 4 +-- .../moe/client/editors/InverseTranslator.java | 12 +++---- .../moe/client/editors/PatchingEditor.java | 4 +-- .../moe/client/editors/RenamingEditor.java | 2 +- .../moe/client/editors/ScrubbingEditor.java | 10 +++--- .../moe/client/editors/ShellEditor.java | 4 +-- .../moe/client/parser/EditExpression.java | 4 +-- .../client/parser/RepositoryExpression.java | 12 +++---- .../client/parser/TranslateExpression.java | 6 ++-- .../moe/client/project/ScrubberConfig.java | 2 +- .../devtools/moe/client/svn/SvnWriter.java | 8 ++--- .../moe/client/svn/SvnWriterCreator.java | 2 +- .../client/testing/FileCodebaseCreator.java | 8 ++--- .../moe/client/SystemFileSystemTest.java | 28 +++++++-------- .../client/codebase/CodebaseMergerTest.java | 2 +- .../dvcs/AbstractDvcsCodebaseCreatorTest.java | 4 +-- .../client/svn/SvnCodebaseCreatorTest.java | 2 +- 27 files changed, 103 insertions(+), 103 deletions(-) diff --git a/java/com/google/devtools/moe/client/Injector.java b/java/com/google/devtools/moe/client/Injector.java index 20018787..c264ac52 100644 --- a/java/com/google/devtools/moe/client/Injector.java +++ b/java/com/google/devtools/moe/client/Injector.java @@ -35,37 +35,37 @@ public class Injector { // TODO(cgruber): Eliminate this public static mutable. public static Injector INSTANCE; - @Nullable private final FileSystem fileSystem; + @Nullable private final FileSystem FILE_SYSTEM; - private final CommandRunner cmd; - private final ProjectContextFactory contextFactory; - private final Ui ui; + private final CommandRunner COMMAND; + private final ProjectContextFactory CONTEXT_FACTORY; + private final Ui UI; @Inject public Injector( @Nullable FileSystem fileSystem, - CommandRunner cmd, + CommandRunner command, ProjectContextFactory contextFactory, Ui ui) { - this.fileSystem = fileSystem; - this.cmd = cmd; - this.contextFactory = contextFactory; - this.ui = ui; + this.FILE_SYSTEM = fileSystem; + this.COMMAND = command; + this.CONTEXT_FACTORY = contextFactory; + this.UI = ui; } - public CommandRunner cmd() { - return cmd; + public CommandRunner getCommand() { + return COMMAND; } - public ProjectContextFactory contextFactory() { - return contextFactory; + public ProjectContextFactory getContextFactory() { + return CONTEXT_FACTORY; } - public FileSystem fileSystem() { - return fileSystem; + public FileSystem getFileSystem() { + return FILE_SYSTEM; } - public Ui ui() { - return ui; + public Ui getUi() { + return UI; } } diff --git a/java/com/google/devtools/moe/client/Lifetimes.java b/java/com/google/devtools/moe/client/Lifetimes.java index 5b698b5d..f1261bf2 100644 --- a/java/com/google/devtools/moe/client/Lifetimes.java +++ b/java/com/google/devtools/moe/client/Lifetimes.java @@ -38,14 +38,14 @@ public boolean shouldCleanUp() { * {@link Ui.Task} is completed. */ public static final Lifetime currentTask() { - return Injector.INSTANCE.ui().currentTaskLifetime(); + return Injector.INSTANCE.getUi().currentTaskLifetime(); } /** * Returns a {@code Lifetime} for a temp dir that should only be cleaned up when MOE terminates. */ public static final Lifetime moeExecution() { - return Injector.INSTANCE.ui().moeExecutionLifetime(); + return Injector.INSTANCE.getUi().moeExecutionLifetime(); } /** diff --git a/java/com/google/devtools/moe/client/Moe.java b/java/com/google/devtools/moe/client/Moe.java index f5bf6e20..8fd33996 100644 --- a/java/com/google/devtools/moe/client/Moe.java +++ b/java/com/google/devtools/moe/client/Moe.java @@ -77,7 +77,7 @@ static int doMain(String... args) { DaggerMoe_Component.builder().optionsModule(new OptionsModule(args)).build(); boolean debug = component.optionsParser().debug(); Injector.INSTANCE = component.context(); - Ui ui = component.context().ui(); + Ui ui = component.context().getUi(); try { Directive directive = component.directives().getSelectedDirective(); @@ -93,7 +93,7 @@ static int doMain(String... args) { int result = directive.perform(); Ui.Task terminateTask = ui.pushTask(MOE_TERMINATION_TASK_NAME, "Final clean-up"); try { - component.context().fileSystem().cleanUpTempDirs(); + component.context().getFileSystem().cleanUpTempDirs(); } catch (IOException e) { ui.info( "WARNING: Moe enocuntered a problem cleaning up temporary directories: %s", diff --git a/java/com/google/devtools/moe/client/Utils.java b/java/com/google/devtools/moe/client/Utils.java index 60ab1ed5..4508dcc6 100644 --- a/java/com/google/devtools/moe/client/Utils.java +++ b/java/com/google/devtools/moe/client/Utils.java @@ -72,7 +72,7 @@ public static Set makeFilenamesRelative(Set files, File basePath) /** Applies the given Function to all files under baseDir. */ public static void doToFiles(File baseDir, Function doFunction) { - for (File file : Injector.INSTANCE.fileSystem().findFiles(baseDir)) { + for (File file : Injector.INSTANCE.getFileSystem().findFiles(baseDir)) { doFunction.apply(file); } } @@ -87,7 +87,7 @@ public static void filterFiles(File baseDir, final Predicate posit public Void apply(File file) { if (!positiveFilter.apply(baseUri.relativize(file.toURI()).getPath())) { try { - Injector.INSTANCE.fileSystem().deleteRecursively(file); + Injector.INSTANCE.getFileSystem().deleteRecursively(file); } catch (IOException e) { throw new MoeProblem("Error deleting file: " + file); } @@ -122,15 +122,15 @@ public static File expandToDirectory(File inputFile) throws IOException, Command } public static File expandTar(File tar) throws IOException, CommandException { - File expandedDir = Injector.INSTANCE.fileSystem().getTemporaryDirectory("expanded_tar_"); - Injector.INSTANCE.fileSystem().makeDirs(expandedDir); + File expandedDir = Injector.INSTANCE.getFileSystem().getTemporaryDirectory("expanded_tar_"); + Injector.INSTANCE.getFileSystem().makeDirs(expandedDir); try { Injector.INSTANCE - .cmd() + .getCommand() .runCommand( "tar", ImmutableList.of("-xf", tar.getAbsolutePath()), expandedDir.getAbsolutePath()); } catch (CommandException e) { - Injector.INSTANCE.fileSystem().deleteRecursively(expandedDir); + Injector.INSTANCE.getFileSystem().deleteRecursively(expandedDir); throw e; } return expandedDir; @@ -140,20 +140,20 @@ public static void copyDirectory(File src, File dest) throws IOException, Comman if (src == null) { return; } - Injector.INSTANCE.fileSystem().makeDirsForFile(dest); - if (Injector.INSTANCE.fileSystem().isFile(src)) { - Injector.INSTANCE.fileSystem().copyFile(src, dest); + Injector.INSTANCE.getFileSystem().makeDirsForFile(dest); + if (Injector.INSTANCE.getFileSystem().isFile(src)) { + Injector.INSTANCE.getFileSystem().copyFile(src, dest); return; } - File[] files = Injector.INSTANCE.fileSystem().listFiles(src); + File[] files = Injector.INSTANCE.getFileSystem().listFiles(src); if (files != null) { for (File subFile : files) { - File newFile = new File(dest, Injector.INSTANCE.fileSystem().getName(subFile)); - if (Injector.INSTANCE.fileSystem().isDirectory(subFile)) { + File newFile = new File(dest, Injector.INSTANCE.getFileSystem().getName(subFile)); + if (Injector.INSTANCE.getFileSystem().isDirectory(subFile)) { copyDirectory(subFile, newFile); } else { - Injector.INSTANCE.fileSystem().makeDirsForFile(newFile); - Injector.INSTANCE.fileSystem().copyFile(subFile, newFile); + Injector.INSTANCE.getFileSystem().makeDirsForFile(newFile); + Injector.INSTANCE.getFileSystem().copyFile(subFile, newFile); } } } @@ -169,8 +169,8 @@ public static void copyDirectory(File src, File dest) throws IOException, Comman public static void makeShellScript(String content, String name) { try { File script = new File(name); - Injector.INSTANCE.fileSystem().write("#!/bin/sh -e\n" + content, script); - Injector.INSTANCE.fileSystem().setExecutable(script); + Injector.INSTANCE.getFileSystem().write("#!/bin/sh -e\n" + content, script); + Injector.INSTANCE.getFileSystem().setExecutable(script); } catch (IOException e) { throw new MoeProblem("Could not generate shell script: " + e); } diff --git a/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java b/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java index 8d164909..e074e18e 100644 --- a/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/AbstractDvcsWriter.java @@ -76,7 +76,7 @@ private DraftRevision putCodebase(Codebase incomingChangeCodebase) { Set writerRepoFiles = Utils.filterByRegEx( Utils.makeFilenamesRelative( - Injector.INSTANCE.fileSystem().findFiles(getRoot()), getRoot()), + Injector.INSTANCE.getFileSystem().findFiles(getRoot()), getRoot()), getIgnoreFilePatterns()); Set filesToUpdate = Sets.union(codebaseFiles, writerRepoFiles); @@ -115,7 +115,7 @@ private DraftRevision putCodebase(Codebase incomingChangeCodebase) { private void putFile(String relativeFilename, Codebase incomingChangeCodebase) throws CommandException { - FileSystem fs = Injector.INSTANCE.fileSystem(); + FileSystem fs = Injector.INSTANCE.getFileSystem(); File src = incomingChangeCodebase.getFile(relativeFilename); File dest = new File(getRoot().getAbsolutePath(), relativeFilename); boolean srcExists = fs.exists(src); @@ -171,7 +171,7 @@ public DraftRevision putCodebase( try { commitChanges(revMetaData); Injector.INSTANCE - .ui() + .getUi() .info("Converted draft revision to writer at " + getRoot().getAbsolutePath()); } catch (CommandException e) { throw new WritingError("Error committing: " + e); diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java b/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java index 08eb6687..1416e0d5 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitRepositoryFactory.java @@ -110,6 +110,6 @@ public GitClonedRepository get() { */ static String runGitCommand(List args, String workingDirectory) throws CommandException { - return Injector.INSTANCE.cmd().runCommand("git", args, workingDirectory); + return Injector.INSTANCE.getCommand().runCommand("git", args, workingDirectory); } } diff --git a/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java b/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java index adb4a63b..1eb7f876 100644 --- a/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/git/GitWriter.java @@ -96,7 +96,7 @@ public void printPushMessage() { throw new MoeProblem("'git' command error: " + e); } - Ui ui = Injector.INSTANCE.ui(); + Ui ui = Injector.INSTANCE.getUi(); ui.info("====="); ui.info("MOE changes have been committed to a clone at " + getRoot()); if (moeBranchName.startsWith(GitClonedRepository.MOE_MIGRATIONS_BRANCH_PREFIX)) { diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java b/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java index 21d5d094..0f8daab6 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgRepositoryFactory.java @@ -105,6 +105,6 @@ public HgClonedRepository get() { } static String runHgCommand(List args, String workingDirectory) throws CommandException { - return Injector.INSTANCE.cmd().runCommand("hg", args, workingDirectory); + return Injector.INSTANCE.getCommand().runCommand("hg", args, workingDirectory); } } diff --git a/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java b/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java index 809f47b0..6c8ed962 100644 --- a/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java +++ b/java/com/google/devtools/moe/client/dvcs/hg/HgWriter.java @@ -89,7 +89,7 @@ protected boolean hasPendingChanges() { @Override public void printPushMessage() { - Ui ui = Injector.INSTANCE.ui(); + Ui ui = Injector.INSTANCE.getUi(); ui.info("====="); ui.info("MOE changes have been committed to a clone at " + getRoot()); ui.info("Changes may have created a new head. Merge heads if needed, then push to remote."); diff --git a/java/com/google/devtools/moe/client/editors/ForwardTranslator.java b/java/com/google/devtools/moe/client/editors/ForwardTranslator.java index 8f419e1f..a34b3335 100644 --- a/java/com/google/devtools/moe/client/editors/ForwardTranslator.java +++ b/java/com/google/devtools/moe/client/editors/ForwardTranslator.java @@ -41,10 +41,10 @@ public Codebase translate( Codebase toTranslate, Map options, ProjectContext context) { Codebase translated = toTranslate; for (TranslatorStep s : steps) { - Ui.Task editTask = Injector.INSTANCE.ui().pushTask("edit", "Translation editor: " + s.name); + Ui.Task editTask = Injector.INSTANCE.getUi().pushTask("edit", "Translation editor: " + s.name); // Pass the translation options to each editor. translated = s.editor.edit(translated, context, options); - Injector.INSTANCE.ui().popTaskAndPersist(editTask, translated.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(editTask, translated.getPath()); } return translated; } diff --git a/java/com/google/devtools/moe/client/editors/InverseRenamingEditor.java b/java/com/google/devtools/moe/client/editors/InverseRenamingEditor.java index 423525d4..b0e8789f 100644 --- a/java/com/google/devtools/moe/client/editors/InverseRenamingEditor.java +++ b/java/com/google/devtools/moe/client/editors/InverseRenamingEditor.java @@ -65,8 +65,8 @@ public class InverseRenamingEditor implements InverseEditor { private static final Joiner FILE_SEP_JOINER = Joiner.on(File.separator); private static final Splitter FILE_SEP_SPLITTER = Splitter.on(File.separator); - private final FileSystem filesystem = Injector.INSTANCE.fileSystem(); // TODO(cgruber) @Inject - private final Messenger messenger = Injector.INSTANCE.ui(); // TODO(cgruber) @Inject + private final FileSystem filesystem = Injector.INSTANCE.getFileSystem(); // TODO(cgruber) @Inject + private final Messenger messenger = Injector.INSTANCE.getUi(); // TODO(cgruber) @Inject public static InverseRenamingEditor makeInverseRenamingEditor( String editorName, EditorConfig config) { diff --git a/java/com/google/devtools/moe/client/editors/InverseTranslator.java b/java/com/google/devtools/moe/client/editors/InverseTranslator.java index 700e9799..52614c11 100644 --- a/java/com/google/devtools/moe/client/editors/InverseTranslator.java +++ b/java/com/google/devtools/moe/client/editors/InverseTranslator.java @@ -126,7 +126,7 @@ public Codebase translate( for (InverseTranslatorStep inverseStep : inverseSteps) { Task task = Injector.INSTANCE - .ui() + .getUi() .pushTask( "inverseEdit", "Inverse-translating step %s by merging codebase %s onto %s", @@ -139,7 +139,7 @@ public Codebase translate( .getInverseEditor() .inverseEdit(inverseTranslated, refFrom, refTo, context, options); - Injector.INSTANCE.ui().popTaskAndPersist(task, inverseTranslated.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(task, inverseTranslated.getPath()); refFrom = forwardTranslationStack.pop(); refTo = forwardTranslationStack.peek(); } @@ -155,13 +155,13 @@ private Deque makeForwardTranslationStack( try { Task task = Injector.INSTANCE - .ui() + .getUi() .pushTask( "refTo", "Pushing to forward-translation stack: " + options.get("referenceToCodebase")); refTo = Parser.parseExpression(options.get("referenceToCodebase")).createCodebase(context); forwardTransStack.push(refTo); - Injector.INSTANCE.ui().popTaskAndPersist(task, refTo.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(task, refTo.getPath()); } catch (ParseError e) { throw new CodebaseCreationError("Couldn't parse in translation: " + e); } @@ -172,11 +172,11 @@ private Deque makeForwardTranslationStack( forwardEditExp = forwardEditExp.editWith(forwardStep.name, ImmutableMap.of()); Task task = Injector.INSTANCE - .ui() + .getUi() .pushTask("edit", "Pushing to forward-translation stack: " + forwardEditExp); refTo = forwardStep.editor.edit(refTo, context, options).copyWithExpression(forwardEditExp); forwardTransStack.push(refTo); - Injector.INSTANCE.ui().popTaskAndPersist(task, refTo.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(task, refTo.getPath()); } return forwardTransStack; diff --git a/java/com/google/devtools/moe/client/editors/PatchingEditor.java b/java/com/google/devtools/moe/client/editors/PatchingEditor.java index b37e1a27..ce685cd4 100644 --- a/java/com/google/devtools/moe/client/editors/PatchingEditor.java +++ b/java/com/google/devtools/moe/client/editors/PatchingEditor.java @@ -38,8 +38,8 @@ */ public class PatchingEditor implements Editor { - private final CommandRunner cmd = Injector.INSTANCE.cmd(); // TODO(cgruber) @Inject - private final FileSystem filesystem = Injector.INSTANCE.fileSystem(); // TODO(cgruber) @Inject + private final CommandRunner cmd = Injector.INSTANCE.getCommand(); // TODO(cgruber) @Inject + private final FileSystem filesystem = Injector.INSTANCE.getFileSystem(); // TODO(cgruber) @Inject private final String name; PatchingEditor(String editorName) { diff --git a/java/com/google/devtools/moe/client/editors/RenamingEditor.java b/java/com/google/devtools/moe/client/editors/RenamingEditor.java index 952fe7a3..1e70e09f 100644 --- a/java/com/google/devtools/moe/client/editors/RenamingEditor.java +++ b/java/com/google/devtools/moe/client/editors/RenamingEditor.java @@ -44,7 +44,7 @@ public class RenamingEditor implements Editor { /** CharMatcher for trimming leading and trailing file path separators. */ private static final CharMatcher SEP_CHAR_MATCHER = CharMatcher.is(File.separatorChar); - private final FileSystem filesystem = Injector.INSTANCE.fileSystem(); // TODO(cgruber) @Inject + private final FileSystem filesystem = Injector.INSTANCE.getFileSystem(); // TODO(cgruber) @Inject private final String editorName; private final Map regexMappings; diff --git a/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java b/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java index 5b5d6bf6..cccbe7aa 100644 --- a/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java +++ b/java/com/google/devtools/moe/client/editors/ScrubbingEditor.java @@ -40,8 +40,8 @@ */ public class ScrubbingEditor implements Editor { - private final CommandRunner cmd = Injector.INSTANCE.cmd(); // TODO(cgruber) @Inject - private final FileSystem filesystem = Injector.INSTANCE.fileSystem(); // TODO(cgruber) @Inject + private final CommandRunner cmd = Injector.INSTANCE.getCommand(); // TODO(cgruber) @Inject + private final FileSystem filesystem = Injector.INSTANCE.getFileSystem(); // TODO(cgruber) @Inject /** * A {@code Supplier} that extracts the scrubber binary. We use a Supplier because we don't want @@ -59,12 +59,12 @@ public File get() { // TODO(dbentley): what will this resource be under ant? File scrubberBinary = Injector.INSTANCE - .fileSystem() + .getFileSystem() .getResourceAsFile("/devtools/moe/scrubber/scrubber.par"); - Injector.INSTANCE.fileSystem().setExecutable(scrubberBinary); + Injector.INSTANCE.getFileSystem().setExecutable(scrubberBinary); return scrubberBinary; } catch (IOException ioEx) { - Injector.INSTANCE.ui().error(ioEx, "Error extracting scrubber"); + Injector.INSTANCE.getUi().error(ioEx, "Error extracting scrubber"); throw new MoeProblem("Error extracting scrubber: " + ioEx.getMessage()); } } diff --git a/java/com/google/devtools/moe/client/editors/ShellEditor.java b/java/com/google/devtools/moe/client/editors/ShellEditor.java index f67c4348..e6efc8ba 100644 --- a/java/com/google/devtools/moe/client/editors/ShellEditor.java +++ b/java/com/google/devtools/moe/client/editors/ShellEditor.java @@ -40,8 +40,8 @@ */ public class ShellEditor implements Editor { - private final CommandRunner cmd = Injector.INSTANCE.cmd(); // TODO(cgruber) @Inject - private final FileSystem filesystem = Injector.INSTANCE.fileSystem(); // TODO(cgruber) @Inject + private final CommandRunner cmd = Injector.INSTANCE.getCommand(); // TODO(cgruber) @Inject + private final FileSystem filesystem = Injector.INSTANCE.getFileSystem(); // TODO(cgruber) @Inject private final String name; private final String commandString; diff --git a/java/com/google/devtools/moe/client/parser/EditExpression.java b/java/com/google/devtools/moe/client/parser/EditExpression.java index e53ac58e..0ac3983c 100644 --- a/java/com/google/devtools/moe/client/parser/EditExpression.java +++ b/java/com/google/devtools/moe/client/parser/EditExpression.java @@ -52,7 +52,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr Ui.Task editTask = Injector.INSTANCE - .ui() + .getUi() .pushTask( "edit", "Editing %s with editor %s", @@ -61,7 +61,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr Codebase editedCodebase = editor.edit(codebaseToEdit, context, editOp.term.options); - Injector.INSTANCE.ui().popTaskAndPersist(editTask, editedCodebase.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(editTask, editedCodebase.getPath()); return editedCodebase.copyWithExpression(this); } diff --git a/java/com/google/devtools/moe/client/parser/RepositoryExpression.java b/java/com/google/devtools/moe/client/parser/RepositoryExpression.java index 33be55e7..31783c92 100644 --- a/java/com/google/devtools/moe/client/parser/RepositoryExpression.java +++ b/java/com/google/devtools/moe/client/parser/RepositoryExpression.java @@ -75,16 +75,16 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr String repositoryName = term.identifier; CodebaseCreator cc; if (repositoryName.equals("file")) { - cc = new FileCodebaseCreator(Injector.INSTANCE.fileSystem()); + cc = new FileCodebaseCreator(Injector.INSTANCE.getFileSystem()); } else { RepositoryType repo = context.getRepository(repositoryName); cc = repo.codebaseCreator(); } Ui.Task createTask = - Injector.INSTANCE.ui().pushTask("create_codebase", "Creating from '%s'", this); + Injector.INSTANCE.getUi().pushTask("create_codebase", "Creating from '%s'", this); Codebase c = cc.create(term.options); - Injector.INSTANCE.ui().popTaskAndPersist(createTask, c.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(createTask, c.getPath()); return c; } @@ -99,13 +99,13 @@ public Writer createWriter(ProjectContext context) throws WritingError { RepositoryType r = context.getRepository(term.identifier); WriterCreator wc = r.writerCreator(); - Ui.Task t = Injector.INSTANCE.ui().pushTask("create_writer", "Creating Writer \"%s\"", term); + Ui.Task t = Injector.INSTANCE.getUi().pushTask("create_writer", "Creating Writer \"%s\"", term); try { Writer writer = wc.create(term.options); - Injector.INSTANCE.ui().popTaskAndPersist(t, writer.getRoot()); + Injector.INSTANCE.getUi().popTaskAndPersist(t, writer.getRoot()); return writer; } catch (WritingError e) { - Injector.INSTANCE.ui().error(e, "Error creating writer"); + Injector.INSTANCE.getUi().error(e, "Error creating writer"); throw e; } } diff --git a/java/com/google/devtools/moe/client/parser/TranslateExpression.java b/java/com/google/devtools/moe/client/parser/TranslateExpression.java index 888eeae3..195a112d 100644 --- a/java/com/google/devtools/moe/client/parser/TranslateExpression.java +++ b/java/com/google/devtools/moe/client/parser/TranslateExpression.java @@ -59,7 +59,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr Ui.Task translateTask = Injector.INSTANCE - .ui() + .getUi() .pushTask( "translate", "Translating %s from project space \"%s\" to \"%s\"", @@ -72,9 +72,9 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr // Don't mark the translated codebase for persistence if it wasn't allocated by the Translator. if (translatedCodebase.equals(codebaseToTranslate)) { - Injector.INSTANCE.ui().popTask(translateTask, translatedCodebase.getPath() + " (unmodified)"); + Injector.INSTANCE.getUi().popTask(translateTask, translatedCodebase.getPath() + " (unmodified)"); } else { - Injector.INSTANCE.ui().popTaskAndPersist(translateTask, translatedCodebase.getPath()); + Injector.INSTANCE.getUi().popTaskAndPersist(translateTask, translatedCodebase.getPath()); } return translatedCodebase.copyWithExpression(this).copyWithProjectSpace(toProjectSpace); } diff --git a/java/com/google/devtools/moe/client/project/ScrubberConfig.java b/java/com/google/devtools/moe/client/project/ScrubberConfig.java index 7f1a6f0a..336a8d4c 100644 --- a/java/com/google/devtools/moe/client/project/ScrubberConfig.java +++ b/java/com/google/devtools/moe/client/project/ScrubberConfig.java @@ -81,7 +81,7 @@ public boolean shouldScrubAuthor(String author) throws InvalidProject { UsernamesConfig usernamesConfig = GsonModule.provideGson() // TODO(cgruber): Eliminate this static reference. .fromJson( - Injector.INSTANCE.fileSystem().fileToString(new File(usernamesFile)), + Injector.INSTANCE.getFileSystem().fileToString(new File(usernamesFile)), UsernamesConfig.class); addUsernames(usernamesToScrub, usernamesConfig.getScrubbableUsernames()); addUsernames(usernamesToPublish, usernamesConfig.getPublishableUsernames()); diff --git a/java/com/google/devtools/moe/client/svn/SvnWriter.java b/java/com/google/devtools/moe/client/svn/SvnWriter.java index 82ea16d9..1f04dc2b 100644 --- a/java/com/google/devtools/moe/client/svn/SvnWriter.java +++ b/java/com/google/devtools/moe/client/svn/SvnWriter.java @@ -86,7 +86,7 @@ private DraftRevision putCodebase(Codebase c) { Set writerFiles = Utils.filterByRegEx( Utils.makeFilenamesRelative( - Injector.INSTANCE.fileSystem().findFiles(rootDirectory), rootDirectory), + Injector.INSTANCE.getFileSystem().findFiles(rootDirectory), rootDirectory), ignoreFilePatterns); Set union = Sets.union(codebaseFiles, writerFiles); @@ -112,7 +112,7 @@ public DraftRevision putCodebase(Codebase c, @Nullable RevisionMetadata rm) thro Utils.makeShellScript(script, rootDirectory.getAbsolutePath() + "/svn_commit.sh"); Injector.INSTANCE - .ui() + .getUi() .info( "To submit, run: cd %s && ./svn_commit.sh && cd -", rootDirectory.getAbsolutePath()); } @@ -127,7 +127,7 @@ public DraftRevision putCodebase(Codebase c, @Nullable RevisionMetadata rm) thro */ void putFile(String relativePath, Codebase codebase) { try { - FileSystem fs = Injector.INSTANCE.fileSystem(); + FileSystem fs = Injector.INSTANCE.getFileSystem(); File dest = new File(rootDirectory.getAbsolutePath(), relativePath); File src = codebase.getFile(relativePath); boolean srcExists = fs.exists(src); @@ -167,7 +167,7 @@ void putFile(String relativePath, Codebase codebase) { } catch (CommandException e) { // If the mime type setting fails, it's not really a big deal. // Just log it and keep going. - Injector.INSTANCE.ui().info("Error setting mime-type for %s", relativePath); + Injector.INSTANCE.getUi().info("Error setting mime-type for %s", relativePath); } } diff --git a/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java b/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java index 6c93acdd..4ad9a441 100644 --- a/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java +++ b/java/com/google/devtools/moe/client/svn/SvnWriterCreator.java @@ -51,7 +51,7 @@ public Writer create(Map options) throws WritingError { Revision r = revisionHistory.findHighestRevision(options.get("revision")); File tempDir = Injector.INSTANCE - .fileSystem() + .getFileSystem() .getTemporaryDirectory(String.format("svn_writer_%s_", r.revId())); SvnWriter writer = new SvnWriter(config, r, tempDir, util); writer.checkOut(); diff --git a/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java b/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java index 93fc01d9..32f87083 100644 --- a/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java +++ b/java/com/google/devtools/moe/client/testing/FileCodebaseCreator.java @@ -75,19 +75,19 @@ public Codebase create(Map options) throws CodebaseCreationError */ public static File getCodebasePath(File sourceFile) throws CodebaseCreationError { // Check whether the specified path is valid. - if (!Injector.INSTANCE.fileSystem().exists(sourceFile)) { + if (!Injector.INSTANCE.getFileSystem().exists(sourceFile)) { throw new CodebaseCreationError( "The specified codebase path \"%s\" does not exist.", sourceFile); } try { // Get the target path based upon whether we are dealing with a directory or a file. - if (Injector.INSTANCE.fileSystem().isDirectory(sourceFile)) { + if (Injector.INSTANCE.getFileSystem().isDirectory(sourceFile)) { // If it is a directory, make a copy and return the path of the copy. - File destFile = Injector.INSTANCE.fileSystem().getTemporaryDirectory("file_codebase_copy_"); + File destFile = Injector.INSTANCE.getFileSystem().getTemporaryDirectory("file_codebase_copy_"); Utils.copyDirectory(sourceFile, destFile); return destFile; - } else if (Injector.INSTANCE.fileSystem().isFile(sourceFile)) { + } else if (Injector.INSTANCE.getFileSystem().isFile(sourceFile)) { // If it is a file, assume that it is an archive and try to extract it. File extractedArchive = Utils.expandToDirectory(sourceFile); if (extractedArchive != null) { diff --git a/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java b/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java index 75858ccb..29957aca 100644 --- a/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java +++ b/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java @@ -199,22 +199,22 @@ interface Component { public void testCleanUpTempDirsWithTasks() throws Exception { Injector.INSTANCE = DaggerSystemFileSystemTest_Component.create().context(); - FileSystem fs = Injector.INSTANCE.fileSystem(); + FileSystem fs = Injector.INSTANCE.getFileSystem(); File taskless = fs.getTemporaryDirectory("taskless", Lifetimes.moeExecution()); Files.touch(taskless); - Task outer = Injector.INSTANCE.ui().pushTask("outer", "outer"); + Task outer = Injector.INSTANCE.getUi().pushTask("outer", "outer"); File outer1 = touchTempDir("outer1", fs); File outer2 = touchTempDir("outer2", fs); - Task inner = Injector.INSTANCE.ui().pushTask("inner", "inner"); + Task inner = Injector.INSTANCE.getUi().pushTask("inner", "inner"); File inner1 = touchTempDir("inner1", fs); File inner2 = touchTempDir("inner2", fs); File innerPersist = fs.getTemporaryDirectory("innerPersist", Lifetimes.moeExecution()); Files.touch(innerPersist); - Injector.INSTANCE.ui().popTask(inner, "popping inner, persisting nothing"); + Injector.INSTANCE.getUi().popTask(inner, "popping inner, persisting nothing"); assertFalse("inner1", inner1.exists()); assertFalse("inner2", inner2.exists()); assertTrue("innerPersist", innerPersist.exists()); @@ -222,47 +222,47 @@ public void testCleanUpTempDirsWithTasks() throws Exception { assertTrue("outer1", outer1.exists()); assertTrue("outer2", outer2.exists()); - Injector.INSTANCE.ui().popTask(outer, "popping outer, persisting nothing"); + Injector.INSTANCE.getUi().popTask(outer, "popping outer, persisting nothing"); assertFalse("outer1", outer1.exists()); assertFalse("outer2", outer2.exists()); assertTrue("innerPersist", innerPersist.exists()); assertTrue("taskless", taskless.exists()); Task moeTermination = - Injector.INSTANCE.ui().pushTask(Ui.MOE_TERMINATION_TASK_NAME, "Final clean-up"); + Injector.INSTANCE.getUi().pushTask(Ui.MOE_TERMINATION_TASK_NAME, "Final clean-up"); fs.cleanUpTempDirs(); - Injector.INSTANCE.ui().popTask(moeTermination, "Finished clean-up"); + Injector.INSTANCE.getUi().popTask(moeTermination, "Finished clean-up"); assertFalse("innerPersist", innerPersist.exists()); assertFalse("taskless", taskless.exists()); } public void testMarkAsPersistentWithTasks() throws Exception { Injector.INSTANCE = DaggerSystemFileSystemTest_Component.create().context(); - FileSystem fs = Injector.INSTANCE.fileSystem(); + FileSystem fs = Injector.INSTANCE.getFileSystem(); - Task outer = Injector.INSTANCE.ui().pushTask("outer", "outer"); + Task outer = Injector.INSTANCE.getUi().pushTask("outer", "outer"); File outer1 = touchTempDir("outer1", fs); File outer2 = touchTempDir("outer2", fs); - Task inner = Injector.INSTANCE.ui().pushTask("inner", "inner"); + Task inner = Injector.INSTANCE.getUi().pushTask("inner", "inner"); File inner1 = touchTempDir("inner1", fs); File inner2 = touchTempDir("inner2", fs); - Injector.INSTANCE.ui().popTaskAndPersist(inner, inner1); + Injector.INSTANCE.getUi().popTaskAndPersist(inner, inner1); assertTrue("inner1", inner1.exists()); assertFalse("inner2", inner2.exists()); assertTrue("outer1", outer1.exists()); assertTrue("outer2", outer2.exists()); - Injector.INSTANCE.ui().popTaskAndPersist(outer, outer1); + Injector.INSTANCE.getUi().popTaskAndPersist(outer, outer1); assertFalse("inner1", inner1.exists()); assertTrue("outer1", outer1.exists()); assertFalse("outer2", outer2.exists()); Task moeTermination = - Injector.INSTANCE.ui().pushTask(Ui.MOE_TERMINATION_TASK_NAME, "Final clean-up"); + Injector.INSTANCE.getUi().pushTask(Ui.MOE_TERMINATION_TASK_NAME, "Final clean-up"); fs.cleanUpTempDirs(); - Injector.INSTANCE.ui().popTask(moeTermination, "Finished clean-up"); + Injector.INSTANCE.getUi().popTask(moeTermination, "Finished clean-up"); // outer1 was persisted from a top-level task, so it shouldn't be cleaned up at all. assertTrue("outer1", outer1.exists()); } diff --git a/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java b/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java index 7c54616e..327614e1 100644 --- a/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java +++ b/javatests/com/google/devtools/moe/client/codebase/CodebaseMergerTest.java @@ -81,7 +81,7 @@ public class CodebaseMergerTest extends TestCase { @Override public void setUp() throws Exception { super.setUp(); - //Injector.INSTANCE = new Injector(fileSystem, cmd, contextFactory, ui); + //Injector.INSTANCE = new Injector(getFileSystem, getCommand, getContextFactory, getUi); orig = control.createMock(Codebase.class); dest = control.createMock(Codebase.class); mod = control.createMock(Codebase.class); diff --git a/javatests/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java b/javatests/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java index 2898af3f..5dc30c2c 100644 --- a/javatests/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java +++ b/javatests/com/google/devtools/moe/client/dvcs/AbstractDvcsCodebaseCreatorTest.java @@ -94,7 +94,7 @@ protected void setUp() throws Exception { public void testCreate_noGivenRev() throws Exception { String archiveTempDir = "/tmp/git_archive_mockrepo_head"; // Short-circuit Utils.filterFilesByPredicate(ignore_files_re). - expect(Injector.INSTANCE.fileSystem().findFiles(new File(archiveTempDir))) + expect(Injector.INSTANCE.getFileSystem().findFiles(new File(archiveTempDir))) .andReturn(ImmutableSet.of()); expect(mockRevHistory.findHighestRevision(null)) @@ -117,7 +117,7 @@ public void testCreate_givenRev() throws Exception { String givenRev = "givenrev"; String archiveTempDir = "/tmp/git_reclone_mockrepo_head_" + givenRev; // Short-circuit Utils.filterFilesByPredicate(ignore_files_re). - expect(Injector.INSTANCE.fileSystem().findFiles(new File(archiveTempDir))) + expect(Injector.INSTANCE.getFileSystem().findFiles(new File(archiveTempDir))) .andReturn(ImmutableSet.of()); expect(mockRevHistory.findHighestRevision(givenRev)) diff --git a/javatests/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java b/javatests/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java index 49fb75b0..b7d372fc 100644 --- a/javatests/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java +++ b/javatests/com/google/devtools/moe/client/svn/SvnCodebaseCreatorTest.java @@ -99,7 +99,7 @@ public void testExportExplicitRevision() throws Exception { "")) .andReturn(""); // Short-circuit Utils.filterFiles for ignore_files_re. - expect(Injector.INSTANCE.fileSystem().findFiles(new File("/dummy/path/45"))) + expect(Injector.INSTANCE.getFileSystem().findFiles(new File("/dummy/path/45"))) .andReturn(ImmutableSet.of()); control.replay(); From ec38acaba0d03f892125307fa725972934ac8622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 01:43:29 -0600 Subject: [PATCH 04/16] Updating documentation of the class Lifetimes. For this updating, the javadoc of the methods were filled and improved. --- .../google/devtools/moe/client/Lifetimes.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/java/com/google/devtools/moe/client/Lifetimes.java b/java/com/google/devtools/moe/client/Lifetimes.java index f1261bf2..ee943e85 100644 --- a/java/com/google/devtools/moe/client/Lifetimes.java +++ b/java/com/google/devtools/moe/client/Lifetimes.java @@ -16,8 +16,6 @@ package com.google.devtools.moe.client; -import com.google.devtools.moe.client.Lifetime; - /** * Static utility methods that return common {@link Lifetime}s. */ @@ -34,23 +32,30 @@ public boolean shouldCleanUp() { }; /** - * Returns a {@code Lifetime} for a temp dir that should be cleaned up when the current - * {@link Ui.Task} is completed. + * Gets the current {@code Lifetime} for a temporary directory that should be + * cleaned up when the current {@link Ui.Task} is completed. + * + * @return the current task lifetime. */ public static final Lifetime currentTask() { return Injector.INSTANCE.getUi().currentTaskLifetime(); } /** - * Returns a {@code Lifetime} for a temp dir that should only be cleaned up when MOE terminates. + * Gets a {@code Lifetime} for a temporary directory that should only be + * cleaned up when MOE terminates. + * + * @return the lifetime for the MOE execution. */ public static final Lifetime moeExecution() { return Injector.INSTANCE.getUi().moeExecutionLifetime(); } /** - * Returns a {@code Lifetime} for a temp dir that should never be cleaned up, even when MOE - * terminates. + * Returns a {@code Lifetime} for a temporary directory that should never be + * cleaned up, even when MOE terminates. + * + * @return the lifetime for the MOE execution. */ public static final Lifetime persistent() { return PERSISTENT; From 0b294b3928a28dc5c06614542a183172dfd30c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 01:51:40 -0600 Subject: [PATCH 05/16] Refactoring Messenger class and updating its documentation. For this refactoring, the following modifications were performed: - The methods parameters were renamed. - The javadoc was completed with the documentation for the parameters. --- .../google/devtools/moe/client/Messenger.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/java/com/google/devtools/moe/client/Messenger.java b/java/com/google/devtools/moe/client/Messenger.java index fcd8a932..45fb27cf 100644 --- a/java/com/google/devtools/moe/client/Messenger.java +++ b/java/com/google/devtools/moe/client/Messenger.java @@ -18,20 +18,40 @@ /** * A type used to wrap logging. - * - * TODO(cgruber): Replace with fluent logger when it is released (go/flogger) */ +// TODO(cgruber): Replace with fluent logger when it is released (go/flogger) public interface Messenger { - /** Sends an informational message to the user. */ - void info(String msgfmt, Object... args); + /** + * Sends an informational message to the user. + * + * @param messageFormat format of the message. + * @param args arguments to create the message. + */ + void info(String messageFormat, Object... args); - /** Reports an error to the user. */ - void error(String msgfmt, Object... args); + /** + * Reports an error to the user. + * + * @param messageFormat format of the message. + * @param args arguments to create the message. + */ + void error(String messageFormat, Object... args); - /** Reports an error to the user, logging additional information about the error. */ - void error(Throwable e, String msgfmt, Object... args); + /** + * Reports an error to the user, logging additional information about the error. + * + * @param throwable the occurred error. + * @param messageFormat format of the message. + * @param args arguments to create the message. + */ + void error(Throwable throwable, String messageFormat, Object... args); - /** Sends a debug message to the logs. */ - void debug(String msgfmt, Object... args); + /** + * Sends a debug message to the logs. + * + * @param messageFormat format of the message. + * @param args arguments to create the message. + */ + void debug(String messageFormat, Object... args); } From f60732fddd2efcf5b166aadf2a8c5122fa4b101b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 03:10:32 -0600 Subject: [PATCH 06/16] Refactoring Moe class and updating its documentation. For this refactoring, the following modifications were performed: - The methods of the inner class Component were renamed. - The variable allMoeLogger was renamed to ALL_MOE_LOGGER, once it is a constant. - The javadoc was complemented. --- java/com/google/devtools/moe/client/Moe.java | 39 ++++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/java/com/google/devtools/moe/client/Moe.java b/java/com/google/devtools/moe/client/Moe.java index 8fd33996..3e68d8ae 100644 --- a/java/com/google/devtools/moe/client/Moe.java +++ b/java/com/google/devtools/moe/client/Moe.java @@ -42,7 +42,7 @@ * Errors are SEVERE logs written to STDERR. */ public class Moe { - static final Logger allMoeLogger = Logger.getLogger("com.google.devtools.moe"); + static final Logger ALL_MOE_LOGGER = Logger.getLogger("com.google.devtools.moe"); /** * The Dagger surface for the MOE application. @@ -51,41 +51,48 @@ public class Moe { @Singleton @dagger.Component(modules = MoeModule.class) public abstract static class Component { - abstract Injector context(); // Legacy context object for static initialization. - public abstract OptionsParser optionsParser(); - public abstract Directives directives(); + abstract Injector getContext(); // Legacy getContext object for static initialization. + public abstract OptionsParser GetOptionsParser(); + public abstract Directives getDirectives(); } + /** - * a main() that works with the new Task framework. + * Implements the main method of MOE and works with the new Task framework. + * + * @param args arguments passed to the MOE system. */ public static void main(String... args) { ConsoleHandler sysErrHandler = new ConsoleHandler(); sysErrHandler.setLevel(Level.WARNING); - allMoeLogger.addHandler(sysErrHandler); - allMoeLogger.setUseParentHandlers(false); + ALL_MOE_LOGGER.addHandler(sysErrHandler); + ALL_MOE_LOGGER.setUseParentHandlers(false); System.exit(doMain(args)); } - /** Implements the main method logic for Moe, returning an error code if there is any */ + /** + * Implements the main method logic for Moe, returning an error code if there + * is any. + * + * @param args arguments passed to the MOE system. + */ static int doMain(String... args) { if (args.length < 1) { System.err.println("Usage: moe "); return 1; } // This needs to get called first, so that DirectiveFactory can report errors appropriately. - Moe.Component component = - DaggerMoe_Component.builder().optionsModule(new OptionsModule(args)).build(); - boolean debug = component.optionsParser().debug(); - Injector.INSTANCE = component.context(); - Ui ui = component.context().getUi(); + Moe.Component component = DaggerMoe_Component.builder().optionsModule(new OptionsModule(args)).build(); + boolean debug = component.GetOptionsParser().debug(); + Injector.INSTANCE = component.getContext(); + Ui ui = component.getContext().getUi(); try { - Directive directive = component.directives().getSelectedDirective(); + Directive directive = component.getDirectives().getSelectedDirective(); if (directive == null) { return 1; // Directive lookup will have reported the error already.. } - boolean parseError = !component.optionsParser().parseFlags(directive); + boolean parseError = !component.GetOptionsParser().parseFlags(directive); if (directive.shouldDisplayHelp() || parseError) { return parseError ? 1 : 0; } @@ -93,7 +100,7 @@ static int doMain(String... args) { int result = directive.perform(); Ui.Task terminateTask = ui.pushTask(MOE_TERMINATION_TASK_NAME, "Final clean-up"); try { - component.context().getFileSystem().cleanUpTempDirs(); + component.getContext().getFileSystem().cleanUpTempDirs(); } catch (IOException e) { ui.info( "WARNING: Moe enocuntered a problem cleaning up temporary directories: %s", From eef9facd6fd4302c212f57608a4b43adffcb2cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 03:20:20 -0600 Subject: [PATCH 07/16] Refacotoring MeoModule class. For this refactoring, the methods were renamed to have a verb. --- .../com/google/devtools/moe/client/MoeModule.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/java/com/google/devtools/moe/client/MoeModule.java b/java/com/google/devtools/moe/client/MoeModule.java index cafd031a..49fb68b5 100644 --- a/java/com/google/devtools/moe/client/MoeModule.java +++ b/java/com/google/devtools/moe/client/MoeModule.java @@ -45,6 +45,7 @@ } ) public class MoeModule { + @Provides @Singleton Ui ui(SystemUi sysui) { @@ -53,32 +54,32 @@ Ui ui(SystemUi sysui) { /* Alias to UI which extends this interface */ @Provides - public Messenger messenger(Ui ui) { + public Messenger getMessenger(Ui ui) { return ui; } @Provides @Singleton - ProjectContextFactory projectContextFactory(FileReadingProjectContextFactory factory) { + ProjectContextFactory getProjectContextFactory(FileReadingProjectContextFactory factory) { return factory; } @Provides @Singleton - CommandRunner commandRunner(SystemCommandRunner runner) { + CommandRunner getCommandRunner(SystemCommandRunner runner) { return runner; } @Provides @Singleton - FileSystem fileSystem(SystemFileSystem sysfs) { - return sysfs; + FileSystem getFileSystem(SystemFileSystem systemFileSystem) { + return systemFileSystem; } @Provides @Singleton - FileDiffer fileDiffer(ConcreteFileDiffer cfd) { - return cfd; + FileDiffer getFileDiffer(ConcreteFileDiffer fileDiffer) { + return fileDiffer; } @Provides From 2c7c5e381851894c9ad80013970968c918648775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 03:24:22 -0600 Subject: [PATCH 08/16] Refactoring the MeoProblem class. For this refactoring, the class documentation was updated and one comment for a video from youtube was removed. --- java/com/google/devtools/moe/client/MoeProblem.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/java/com/google/devtools/moe/client/MoeProblem.java b/java/com/google/devtools/moe/client/MoeProblem.java index 5885be22..91e6e56c 100644 --- a/java/com/google/devtools/moe/client/MoeProblem.java +++ b/java/com/google/devtools/moe/client/MoeProblem.java @@ -17,11 +17,10 @@ package com.google.devtools.moe.client; /** - * A problem that we do not expect to routinely happen. They should end execution of MOE and require - * intervention by moe-team. + * A problem that we do not expect to routinely happen. They should end + * execution of MOE and require intervention by moe-team. */ public class MoeProblem extends RuntimeException { - // https://www.youtube.com/watch?v=xZ4tNmnuMgQ // TODO(cgruber): Figure out why this is public mutable and fix. public String explanation; From 78b4d7c20a17c472ea748eceb2afd7a13ba7ca9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 03:28:10 -0600 Subject: [PATCH 09/16] Refacotring and updating documentation of the MoeUserProblem class. The parameter 'ui' was renamed to messenger and the documentation for this parameter was added to the javadoc. --- java/com/google/devtools/moe/client/MoeUserProblem.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/com/google/devtools/moe/client/MoeUserProblem.java b/java/com/google/devtools/moe/client/MoeUserProblem.java index a9fe9663..84d4a549 100644 --- a/java/com/google/devtools/moe/client/MoeUserProblem.java +++ b/java/com/google/devtools/moe/client/MoeUserProblem.java @@ -27,6 +27,8 @@ public MoeUserProblem() {} * A method which allows the user-visible message to be reported appropriately to the * {@link Ui} class. Implementers should override this message and log any user output * relevant to the error. + * + * @param ui messenger to receive a message. */ public abstract void reportTo(Messenger ui); } From 1c74af9ad7bf274078efc1ab6fd116579be40e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Mon, 15 Feb 2016 09:00:13 -0600 Subject: [PATCH 10/16] Refactoring MeoUserProblem class. For this refactoring, a param tag was added to the javadoc of the method reportTo and this same method had the parameter name changed. --- java/com/google/devtools/moe/client/MoeUserProblem.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java/com/google/devtools/moe/client/MoeUserProblem.java b/java/com/google/devtools/moe/client/MoeUserProblem.java index 84d4a549..99ca632a 100644 --- a/java/com/google/devtools/moe/client/MoeUserProblem.java +++ b/java/com/google/devtools/moe/client/MoeUserProblem.java @@ -28,7 +28,7 @@ public MoeUserProblem() {} * {@link Ui} class. Implementers should override this message and log any user output * relevant to the error. * - * @param ui messenger to receive a message. + * @param messenger messenger to receive a message. */ - public abstract void reportTo(Messenger ui); + public abstract void reportTo(Messenger messenger); } From f75c5edfa8b8df1ccda808e3e72cd41fde00412e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 15:01:17 -0600 Subject: [PATCH 11/16] Adding comments to the functions of SystemCommandRunner and its private inner class Sink. --- .../moe/client/SystemCommandRunner.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/java/com/google/devtools/moe/client/SystemCommandRunner.java b/java/com/google/devtools/moe/client/SystemCommandRunner.java index 0d73c8e7..327051fd 100644 --- a/java/com/google/devtools/moe/client/SystemCommandRunner.java +++ b/java/com/google/devtools/moe/client/SystemCommandRunner.java @@ -128,6 +128,10 @@ public String runCommand(String cmd, List args, String workingDirectory) return runCommandWithFullOutput(cmd, args, workingDirectory).getStdout(); } + /** + * Class responsible to manager the use of streams by the + * {@link SystemCommandRunner} class. + */ private static class Sink { private final List bytes = Lists.newArrayList(); private InputStream stream; @@ -136,14 +140,32 @@ private static class Sink { this.stream = stream; } + /** + * Checks if a stream is available to be read. + * + * @return true if the stream is available or false, otherwise. + * + * @throws IOException if some error occurs during the checking. + */ boolean isAvailable() throws IOException { return stream != null && stream.available() > 0; } + /** + * Closes the stream. It is the same of making stream equals to null. + */ void closeStream() { stream = null; } + /** + * Reads the next byte from the stream to the {@link #bytes} list. + * + * @return true is the byte was read successfully or false if there was no + * more byte to read. + * + * @throws IOException if some error occurs when reading the byte. + */ boolean consumeByte() throws IOException { int data = stream.read(); if (data == -1) { @@ -154,6 +176,11 @@ boolean consumeByte() throws IOException { } } + /** + * Gets the bytes read from the stream as a string. + * + * @return the string represented by the bytes read from the stream. + */ String getData() { byte[] byteArray = new byte[bytes.size()]; int i = 0; @@ -164,7 +191,9 @@ String getData() { } } - /** A Dagger module for binding this implementation of {@link CommandRunner}. */ + /** + * A Dagger module for binding this implementation of {@link CommandRunner}. + */ @dagger.Module public static class Module { @Provides From 7de134e5ad75124a943d037e1f3b1e1c262c71f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 15:39:27 -0600 Subject: [PATCH 12/16] Adding javadoc comments to the SystemFileSytem methods. Renaming method parameters to more appropriate names. --- .../devtools/moe/client/SystemFileSystem.java | 109 ++++++++++-------- 1 file changed, 60 insertions(+), 49 deletions(-) diff --git a/java/com/google/devtools/moe/client/SystemFileSystem.java b/java/com/google/devtools/moe/client/SystemFileSystem.java index d96fe0e1..062406a7 100644 --- a/java/com/google/devtools/moe/client/SystemFileSystem.java +++ b/java/com/google/devtools/moe/client/SystemFileSystem.java @@ -16,7 +16,6 @@ package com.google.devtools.moe.client; -import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.Files.walkFileTree; import com.google.common.base.Preconditions; @@ -31,7 +30,6 @@ import java.io.OutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Path; -import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; @@ -50,7 +48,7 @@ */ @Singleton public class SystemFileSystem implements FileSystem { - private final Map tempDirLifetimes = Maps.newHashMap(); + private final Map temporaryDirectoryOfLifetimes = Maps.newHashMap(); @Inject public SystemFileSystem() {} @@ -62,20 +60,20 @@ public File getTemporaryDirectory(String prefix) { @Override public File getTemporaryDirectory(String prefix, Lifetime lifetime) { - File tempDir; + File temporaryDirectory; try { - tempDir = File.createTempFile("moe_" + prefix, ""); - tempDir.delete(); + temporaryDirectory = File.createTempFile("moe_" + prefix, ""); + temporaryDirectory.delete(); } catch (IOException e) { throw new MoeProblem("could not create temp file: " + e.getMessage()); } - tempDirLifetimes.put(tempDir, lifetime); - return tempDir; + temporaryDirectoryOfLifetimes.put(temporaryDirectory, lifetime); + return temporaryDirectory; } @Override public void cleanUpTempDirs() throws IOException { - Iterator> tempDirIterator = tempDirLifetimes.entrySet().iterator(); + Iterator> tempDirIterator = temporaryDirectoryOfLifetimes.entrySet().iterator(); while (tempDirIterator.hasNext()) { Entry entry = tempDirIterator.next(); if (entry.getValue().shouldCleanUp()) { @@ -88,15 +86,12 @@ public void cleanUpTempDirs() throws IOException { @Override public void setLifetime(File path, Lifetime lifetime) { Preconditions.checkState( - tempDirLifetimes.containsKey(path), + temporaryDirectoryOfLifetimes.containsKey(path), "Trying to set the Lifetime for an unknown path: %s", path); - tempDirLifetimes.put(path, lifetime); + temporaryDirectoryOfLifetimes.put(path, lifetime); } - /** - * Find files under a path. - */ @Override public Set findFiles(File path) { Set result = Sets.newHashSet(); @@ -104,13 +99,19 @@ public Set findFiles(File path) { return result; } - void findFilesRecursiveHelper(File f, Set result) { - if (f.exists() && f.isFile()) { - result.add(f); + /** + * Finds a file recursively in a directory. + * + * @param file file to be searched. + * @param result set where the found files will be added. + */ + void findFilesRecursiveHelper(File file, Set result) { + if (file.exists() && file.isFile()) { + result.add(file); return; } - for (File subFile : f.listFiles()) { + for (File subFile : file.listFiles()) { findFilesRecursiveHelper(subFile, result); } } @@ -121,64 +122,64 @@ public File[] listFiles(File path) { } @Override - public boolean exists(File f) { - return f.exists(); + public boolean exists(File file) { + return file.exists(); } @Override - public String getName(File f) { - return f.getName(); + public String getName(File file) { + return file.getName(); } @Override - public boolean isFile(File f) { - return f.isFile(); + public boolean isFile(File file) { + return file.isFile(); } @Override - public boolean isDirectory(File f) { - return f.isDirectory(); + public boolean isDirectory(File file) { + return file.isDirectory(); } @Override - public boolean isExecutable(File f) { - return exists(f) && f.canExecute(); + public boolean isExecutable(File file) { + return exists(file) && file.canExecute(); } @Override - public boolean isReadable(File f) { - return exists(f) && f.canRead(); + public boolean isReadable(File file) { + return exists(file) && file.canRead(); } @Override - public void setExecutable(File f) { - f.setExecutable(true, false); + public void setExecutable(File file) { + file.setExecutable(true, false); } @Override - public void setNonExecutable(File f) { - f.setExecutable(false, false); + public void setNonExecutable(File file) { + file.setExecutable(false, false); } @Override - public void makeDirsForFile(File f) throws IOException { - Files.createParentDirs(f); + public void makeDirsForFile(File file) throws IOException { + Files.createParentDirs(file); } @Override - public void makeDirs(File f) throws IOException { - Files.createParentDirs(new File(f, "foo")); + public void makeDirs(File file) throws IOException { + Files.createParentDirs(new File(file, "foo")); } @Override - public void copyFile(File src, File dest) throws IOException { - Files.copy(src, dest); - dest.setExecutable(src.canExecute(), false); + public void copyFile(File source, File destination) throws IOException { + Files.copy(source, destination); + destination.setExecutable(source.canExecute(), false); } @Override - public void write(String contents, File f) throws IOException { - Files.write(contents, f, UTF_8); + public void write(String contents, File file) throws IOException { + Files.write(contents, file, UTF_8); } @Override @@ -186,10 +187,17 @@ public void deleteRecursively(File file) throws IOException { deleteRecursively(file.toPath()); } + /** + * Deletes a file recursively. + * Note, this does not attempt to perform the action securely and is + * vulnerable to a racey replacement of a directory about to be deleted with + * a symlink which can lead to files outside the parent directory to be deleted. + * + * @param path path of the file to be deleted. + * + * @throws IOException if some error occurs while deleting the file. + */ private void deleteRecursively(final Path path) throws IOException { - // Note, this does not attempt to perform the action securely and is vulnerable to a - // racey replacement of a directory about to be deleted with a symlink which can lead to - // files outside the parent directory to be deleted. final List exceptions = new ArrayList<>(); walkFileTree(path, new SimpleFileVisitor() { @Override @@ -201,6 +209,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { } return FileVisitResult.CONTINUE; } + @Override public FileVisitResult postVisitDirectory(Path dir, IOException ignore) throws IOException { // Since we're collecting exceptions in visitFile and never throwing, ignore the exception. @@ -241,11 +250,13 @@ public File getResourceAsFile(String resource) throws IOException { } @Override - public String fileToString(File f) throws IOException { - return Files.toString(f, UTF_8); + public String fileToString(File file) throws IOException { + return Files.toString(file, UTF_8); } - /** A Dagger module for binding this implementation of {@link FileSystem}. */ + /** + * A Dagger module for binding this implementation of {@link FileSystem}. + */ @dagger.Module public static class Module { @Provides From 297e244d0507ae63a95bbe033f6e6956aaae3891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 16:09:47 -0600 Subject: [PATCH 13/16] Adding javadoc comments to the class SystemUi. Renaming methods parameters to more appropriate names. --- .../google/devtools/moe/client/SystemUi.java | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/java/com/google/devtools/moe/client/SystemUi.java b/java/com/google/devtools/moe/client/SystemUi.java index 48a1beaf..7a833ad1 100644 --- a/java/com/google/devtools/moe/client/SystemUi.java +++ b/java/com/google/devtools/moe/client/SystemUi.java @@ -33,7 +33,7 @@ */ @Singleton public class SystemUi extends Ui { - private final Logger logger = Logger.getLogger(SystemUi.class.getName()); + private static final Logger LOGGER = Logger.getLogger(SystemUi.class.getName()); // We store the task that is the current output, if any, so that we can special case a Task that // is popped right after it is pushed. In this case, we can output: "Doing...Done" on one line. @@ -56,40 +56,51 @@ private void clearOutput() { currentOutput = null; } - private String indent(String msg) { + /** + * Indents a message according to the stack size. + * + * @param message message to be indented. + * @return the message indented. + */ + private String indent(String message) { String indentation = Strings.repeat(" ", stack.size()); - return indentation + Joiner.on("\n" + indentation).join(Splitter.on('\n').split(msg)); + return indentation + Joiner.on("\n" + indentation).join(Splitter.on('\n').split(message)); } @Override - public void info(String msg, Object... args) { + public void info(String message, Object... args) { clearOutput(); - logHelper(indent(String.format(msg, args))); + logHelper(indent(String.format(message, args))); } @Override - public void debug(String msg, Object... args) { - logger.log(Level.INFO, String.format(msg, args)); + public void debug(String message, Object... args) { + LOGGER.log(Level.INFO, String.format(message, args)); } + /** + * Logs a message with {@link Level#INFO} level. + * + * @param message message to be logged. + */ private void logHelper(String message) { System.out.println(message); - logger.log(Level.INFO, message); + LOGGER.log(Level.INFO, message); } @Override - public void error(String msg, Object... args) { + public void error(String messageFormat, Object... args) { clearOutput(); - logger.log(Level.SEVERE, String.format(msg, args)); + LOGGER.log(Level.SEVERE, String.format(messageFormat, args)); } @Override - public void error(Throwable e, String msg, Object... args) { + public void error(Throwable throwable, String messageFormat, Object... args) { clearOutput(); - String message = String.format(msg, args); + String message = String.format(messageFormat, args); // Do not expose the stack trace to the user. Just send it to the INFO logs. - logger.log(Level.SEVERE, message + ": " + e.getMessage()); - logger.log(Level.INFO, message, e); + LOGGER.log(Level.SEVERE, message + ": " + throwable.getMessage()); + LOGGER.log(Level.INFO, message, throwable); } @Override @@ -98,7 +109,7 @@ public Ui.Task pushTask(String task, String descriptionFormat, Object... args) { String description = String.format(descriptionFormat, args); String indented = indent(description + "... "); System.out.print(indented); - logger.log(Level.INFO, indented); + LOGGER.log(Level.INFO, indented); currentOutput = super.pushTask(task, description); return currentOutput; @@ -120,7 +131,9 @@ public void popTask(Ui.Task task, String result) { currentOutput = null; } - /** A Dagger module for binding this implementation of {@link Ui}. */ + /** + * A Dagger module for binding this implementation of {@link Ui}. + */ @dagger.Module public static class Module { @Provides From 443b2fdf87e77633af567f1be059594efbfa1586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 19:30:40 -0600 Subject: [PATCH 14/16] Refactoring the Ui class. Some methods had the name changed to actions and had their parameters renamed. Also, javadoc documentation was added to the class. Moving the inner class Task out of the Ui class. --- .../google/devtools/moe/client/Lifetimes.java | 4 +- java/com/google/devtools/moe/client/Moe.java | 2 +- .../google/devtools/moe/client/SystemUi.java | 12 +-- java/com/google/devtools/moe/client/Task.java | 27 ++++++ java/com/google/devtools/moe/client/Ui.java | 94 +++++++++---------- .../moe/client/database/Bookkeeper.java | 13 +-- .../client/directives/ChangeDirective.java | 2 +- .../directives/CreateCodebaseDirective.java | 2 +- .../directives/GithubPullDirective.java | 2 +- .../moe/client/directives/MagicDirective.java | 5 +- .../directives/MigrateBranchDirective.java | 11 ++- .../moe/client/editors/ForwardTranslator.java | 3 +- .../moe/client/editors/InverseTranslator.java | 2 +- .../moe/client/parser/EditExpression.java | 3 +- .../client/parser/RepositoryExpression.java | 5 +- .../client/parser/TranslateExpression.java | 3 +- .../FileReadingProjectContextFactory.java | 3 +- .../moe/client/testing/RecordingUi.java | 3 +- .../moe/client/writer/DraftRevision.java | 3 +- .../moe/client/SystemFileSystemTest.java | 2 +- .../google/devtools/moe/client/UiTest.java | 4 +- 21 files changed, 117 insertions(+), 88 deletions(-) create mode 100644 java/com/google/devtools/moe/client/Task.java diff --git a/java/com/google/devtools/moe/client/Lifetimes.java b/java/com/google/devtools/moe/client/Lifetimes.java index ee943e85..1b25adcf 100644 --- a/java/com/google/devtools/moe/client/Lifetimes.java +++ b/java/com/google/devtools/moe/client/Lifetimes.java @@ -38,7 +38,7 @@ public boolean shouldCleanUp() { * @return the current task lifetime. */ public static final Lifetime currentTask() { - return Injector.INSTANCE.getUi().currentTaskLifetime(); + return Injector.INSTANCE.getUi().getCurrentTaskLifetime(); } /** @@ -48,7 +48,7 @@ public static final Lifetime currentTask() { * @return the lifetime for the MOE execution. */ public static final Lifetime moeExecution() { - return Injector.INSTANCE.getUi().moeExecutionLifetime(); + return Injector.INSTANCE.getUi().getMoeExecutionLifetime(); } /** diff --git a/java/com/google/devtools/moe/client/Moe.java b/java/com/google/devtools/moe/client/Moe.java index 3e68d8ae..8392b00e 100644 --- a/java/com/google/devtools/moe/client/Moe.java +++ b/java/com/google/devtools/moe/client/Moe.java @@ -98,7 +98,7 @@ static int doMain(String... args) { } int result = directive.perform(); - Ui.Task terminateTask = ui.pushTask(MOE_TERMINATION_TASK_NAME, "Final clean-up"); + Task terminateTask = ui.pushTask(MOE_TERMINATION_TASK_NAME, "Final clean-up"); try { component.getContext().getFileSystem().cleanUpTempDirs(); } catch (IOException e) { diff --git a/java/com/google/devtools/moe/client/SystemUi.java b/java/com/google/devtools/moe/client/SystemUi.java index 7a833ad1..f6ff8d2b 100644 --- a/java/com/google/devtools/moe/client/SystemUi.java +++ b/java/com/google/devtools/moe/client/SystemUi.java @@ -37,7 +37,7 @@ public class SystemUi extends Ui { // We store the task that is the current output, if any, so that we can special case a Task that // is popped right after it is pushed. In this case, we can output: "Doing...Done" on one line. - Ui.Task currentOutput; + Task currentOutput; @Inject public SystemUi() { @@ -57,13 +57,13 @@ private void clearOutput() { } /** - * Indents a message according to the stack size. + * Indents a message according to the STACK size. * * @param message message to be indented. * @return the message indented. */ private String indent(String message) { - String indentation = Strings.repeat(" ", stack.size()); + String indentation = Strings.repeat(" ", STACK.size()); return indentation + Joiner.on("\n" + indentation).join(Splitter.on('\n').split(message)); } @@ -98,13 +98,13 @@ public void error(String messageFormat, Object... args) { public void error(Throwable throwable, String messageFormat, Object... args) { clearOutput(); String message = String.format(messageFormat, args); - // Do not expose the stack trace to the user. Just send it to the INFO logs. + // Do not expose the STACK trace to the user. Just send it to the INFO logs. LOGGER.log(Level.SEVERE, message + ": " + throwable.getMessage()); LOGGER.log(Level.INFO, message, throwable); } @Override - public Ui.Task pushTask(String task, String descriptionFormat, Object... args) { + public Task pushTask(String task, String descriptionFormat, Object... args) { clearOutput(); String description = String.format(descriptionFormat, args); String indented = indent(description + "... "); @@ -116,7 +116,7 @@ public Ui.Task pushTask(String task, String descriptionFormat, Object... args) { } @Override - public void popTask(Ui.Task task, String result) { + public void popTask(Task task, String result) { super.popTask(task, result); if (result.isEmpty()) { result = "Done"; diff --git a/java/com/google/devtools/moe/client/Task.java b/java/com/google/devtools/moe/client/Task.java new file mode 100644 index 00000000..f4322dd0 --- /dev/null +++ b/java/com/google/devtools/moe/client/Task.java @@ -0,0 +1,27 @@ +package com.google.devtools.moe.client; + +/** + * Class describing the task data structure. + */ +public class Task { + + public final String taskName; + public final String description; + + public Task(String taskName, String description) { + this.taskName = taskName; + this.description = description; + } + + public Task(String taskName, String descriptionFormat, Object... args) { + this.taskName = taskName; + // TODO(cgruber) make this lazy once Task is an autovalue. + this.description = String.format(descriptionFormat, args); + } // TODO(cgruber) make this lazy once Task is an autovalue. + + @Override + public String toString() { + return taskName; + } + +} diff --git a/java/com/google/devtools/moe/client/Ui.java b/java/com/google/devtools/moe/client/Ui.java index 0c21ec73..9c5ada27 100644 --- a/java/com/google/devtools/moe/client/Ui.java +++ b/java/com/google/devtools/moe/client/Ui.java @@ -18,7 +18,6 @@ import com.google.common.base.Preconditions; import com.google.common.collect.Iterables; -import com.google.devtools.moe.client.Lifetime; import java.io.File; import java.io.IOException; @@ -42,65 +41,44 @@ public abstract class Ui implements Messenger { */ public static final String MOE_TERMINATION_TASK_NAME = "moe_termination"; - protected final Deque stack = new ArrayDeque(); - - public static class Task { - public final String taskName; - public final String description; - - public Task(String taskName, String description) { - this.taskName = taskName; - this.description = description; - } - - public Task(String taskName, String descriptionFormat, Object... args) { - this.taskName = taskName; - // TODO(cgruber) make this lazy once Task is an autovalue. - this.description = String.format(descriptionFormat, args); - } - - @Override - public String toString() { - return taskName; - } - } + protected final Deque STACK = new ArrayDeque(); /** * Pushes a task onto the Task Stack. * - *

MOE's UI operates on a stack model. Tasks get pushed onto the stack and then what is popped - * must be the top task on the stack, allowing nesting only. + *

MOE's UI operates on a STACK model. Tasks get pushed onto the STACK and + * then what is popped must be the top task on the STACK, allowing nesting only. * - * @param task the name of the task; should be sensical to a computer + * @param taskName the name of the task; should be sensical to a computer * @param descriptionFormat a String.format() template for the description of what MOE is * about to do, suitable for a user. * @param formatArgs arguments which will be used to format the descriptionFormat template * - * @returns the Task created + * @return the Task created. */ - public Task pushTask(String task, String descriptionFormat, Object... formatArgs) { - Task t = new Task(task, descriptionFormat, formatArgs); - stack.addFirst(t); - return t; + public Task pushTask(String taskName, String descriptionFormat, Object... formatArgs) { + Task task = new Task(taskName, descriptionFormat, formatArgs); + STACK.addFirst(task); + return task; } /** * Pops a task from the Task Stack. No files or directories are persisted beyond this Task. After * the Task is popped, temp dirs are cleaned up via {@link FileSystem#cleanUpTempDirs()}. * - * @param task the task to pop. This must be the task on the top of the stack. + * @param task the task to pop. This must be the task on the top of the STACK. * @param result the result of the task, if applicable, or "". - * @throws MoeProblem if task is not on the top of the stack + * @throws MoeProblem if task is not on the top of the STACK */ public void popTask(Task task, String result) { - if (stack.isEmpty()) { + if (STACK.isEmpty()) { throw new MoeProblem("Tried to end task %s, but stack is empty", task.taskName); } - Task top = stack.removeFirst(); + Task top = STACK.removeFirst(); if (top != task) { - throw new MoeProblem("Tried to end task %s, but stack contains: %s", task.taskName, stack); + throw new MoeProblem("Tried to end task %s, but stack contains: %s", task.taskName, STACK); } if (fileSystem != null) { @@ -114,23 +92,25 @@ public void popTask(Task task, String result) { } /** - * Pops a task from the Task Stack, persisting the given File beyond this Task. In general, use - * this if you call {@link FileSystem#getTemporaryDirectory(String, Lifetime)} within a Task and - * need to keep the resulting temp dir past completion of this Task. - * - * If there is a parent Task on the stack after the one being popped here, then + * Pops a task from the Task Stack, persisting the given File beyond this Task. + * In general, use this if you call {@link FileSystem#getTemporaryDirectory(String, Lifetime)} + * within a Task and need to keep the resulting temporary directory past completion of this Task. + * If there is a parent Task on the STACK after the one being popped here, then * {@code persistentResult} will be cleaned up when the parent Task is popped (unless it's * persisted within that Task too). If there is no parent Task, then {@code persistentResult} * will be persisted beyond MOE execution. So any results persisted beyond a top-level Task * constitute outputs of MOE execution. + * + * @param task task to be popped. + * @param persistentResult file to the persistent result. */ public void popTaskAndPersist(Task task, File persistentResult) { if (fileSystem != null) { Lifetime newLifetime; - if (stack.size() == 1) { + if (STACK.size() == 1) { newLifetime = Lifetimes.persistent(); } else { - Task parentTask = Iterables.get(stack, 1); + Task parentTask = Iterables.get(STACK, 1); newLifetime = new TaskLifetime(parentTask); } fileSystem.setLifetime(persistentResult, newLifetime); @@ -139,17 +119,28 @@ public void popTaskAndPersist(Task task, File persistentResult) { popTask(task, persistentResult.getAbsolutePath()); } - Lifetime currentTaskLifetime() { - Preconditions.checkState(!stack.isEmpty()); - return new TaskLifetime(stack.peek()); + /** + * Gets the TaskLifetime of the top of the stack. + * + * @return TaskLifetime of the top of the stack. + */ + Lifetime getCurrentTaskLifetime() { + Preconditions.checkState(!STACK.isEmpty()); + return new TaskLifetime(STACK.peek()); } - Lifetime moeExecutionLifetime() { + /** + * Gets the a new instance of the MoeExecutionLifetime class. + * + * @return a new MoeExecutionLifetime instance. + */ + Lifetime getMoeExecutionLifetime() { return new MoeExecutionLifetime(); } /** - * A {@code Lifetime} for a temp dir that should be cleaned up when the given Task is completed. + * A {@code Lifetime} for a temporary directory that should be cleaned up when + * the given Task is completed. */ private class TaskLifetime implements Lifetime { @@ -161,18 +152,19 @@ private class TaskLifetime implements Lifetime { @Override public boolean shouldCleanUp() { - return !stack.contains(task); + return !STACK.contains(task); } } /** - * A {@code Lifetime} for a temp dir that should be cleaned up when MOE completes execution. + * A {@code Lifetime} for a temporary directory that should be cleaned up when + * MOE completes execution. */ private class MoeExecutionLifetime implements Lifetime { @Override public boolean shouldCleanUp() { - return !stack.isEmpty() && stack.peek().taskName.equals(MOE_TERMINATION_TASK_NAME); + return !STACK.isEmpty() && STACK.peek().taskName.equals(MOE_TERMINATION_TASK_NAME); } } diff --git a/java/com/google/devtools/moe/client/database/Bookkeeper.java b/java/com/google/devtools/moe/client/database/Bookkeeper.java index a146fd95..a2adbca8 100644 --- a/java/com/google/devtools/moe/client/database/Bookkeeper.java +++ b/java/com/google/devtools/moe/client/database/Bookkeeper.java @@ -18,6 +18,7 @@ import com.google.common.base.Joiner; import com.google.devtools.moe.client.MoeProblem; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -83,7 +84,7 @@ private void updateHeadEquivalence( return; } - Ui.Task t = ui.pushTask("diff_codebases", "Diff codebases '%s' and '%s'", from, to); + Task t = ui.pushTask("diff_codebases", "Diff codebases '%s' and '%s'", from, to); if (!differ.diffCodebases(from, to).areDifferent()) { db.noteEquivalence(RepositoryEquivalence.create(fromHead, toHead)); } @@ -166,7 +167,7 @@ private void processMigration( return; } - Ui.Task t = ui.pushTask("diff_codebases", "Diff codebases '%s' and '%s'", from, to); + Task t = ui.pushTask("diff_codebases", "Diff codebases '%s' and '%s'", from, to); if (!differ.diffCodebases(from, to).areDifferent()) { RepositoryEquivalence newEquiv = RepositoryEquivalence.create(fromRev, toRev); db.noteEquivalence(newEquiv); @@ -206,10 +207,10 @@ private static TranslatorConfig getTranslatorConfig( * @return 0 on success, 1 on failure */ public int bookkeep(Db db, ProjectContext context) { - Ui.Task t = ui.pushTask("perform_checks", "Updating database"); + Task t = ui.pushTask("perform_checks", "Updating database"); for (MigrationConfig config : context.migrationConfigs().values()) { - Ui.Task bookkeepOneMigrationTask = + Task bookkeepOneMigrationTask = ui.pushTask( "bookkeping_one_migration", "Doing bookkeeping between '%s' and '%s' for migration '%s'", @@ -222,7 +223,7 @@ public int bookkeep(Db db, ProjectContext context) { // TODO(user): ? Switch the order of these two checks, so that we don't have to look back // through the history for irrelevant equivalences if there's one at head. - Ui.Task checkMigrationsTask = + Task checkMigrationsTask = ui.pushTask( "check_migrations", "Checking completed migrations for new equivalence between '%s' and '%s'", @@ -239,7 +240,7 @@ public int bookkeep(Db db, ProjectContext context) { // Skip head-equivalence checking for inverse translation -- assume it will be performed via // the forward-translated migration. if (!migrationTranslator.isInverse()) { - Ui.Task checkHeadsTask = + Task checkHeadsTask = ui.pushTask( "check_heads", "Checking head equivalence between '%s' and '%s'", diff --git a/java/com/google/devtools/moe/client/directives/ChangeDirective.java b/java/com/google/devtools/moe/client/directives/ChangeDirective.java index 80755592..53f7b0da 100644 --- a/java/com/google/devtools/moe/client/directives/ChangeDirective.java +++ b/java/com/google/devtools/moe/client/directives/ChangeDirective.java @@ -17,7 +17,7 @@ package com.google.devtools.moe.client.directives; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.Ui.Task; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; import com.google.devtools.moe.client.parser.Parser; diff --git a/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java b/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java index 31d6eabb..695c6790 100644 --- a/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java +++ b/java/com/google/devtools/moe/client/directives/CreateCodebaseDirective.java @@ -22,7 +22,7 @@ import com.google.devtools.moe.client.CommandException; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.Ui.Task; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; import com.google.devtools.moe.client.parser.Parser; diff --git a/java/com/google/devtools/moe/client/directives/GithubPullDirective.java b/java/com/google/devtools/moe/client/directives/GithubPullDirective.java index 30f296f6..1c84d5cf 100644 --- a/java/com/google/devtools/moe/client/directives/GithubPullDirective.java +++ b/java/com/google/devtools/moe/client/directives/GithubPullDirective.java @@ -20,7 +20,7 @@ import com.google.devtools.moe.client.Messenger; import com.google.devtools.moe.client.MoeUserProblem; import com.google.devtools.moe.client.Ui; -import com.google.devtools.moe.client.Ui.Task; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.github.GithubAPI.PullRequest; import com.google.devtools.moe.client.github.GithubClient; import com.google.devtools.moe.client.github.PullRequestUrl; diff --git a/java/com/google/devtools/moe/client/directives/MagicDirective.java b/java/com/google/devtools/moe/client/directives/MagicDirective.java index 68182efa..34ce63ee 100644 --- a/java/com/google/devtools/moe/client/directives/MagicDirective.java +++ b/java/com/google/devtools/moe/client/directives/MagicDirective.java @@ -21,6 +21,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; import com.google.devtools.moe.client.MoeProblem; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -108,7 +109,7 @@ protected int performDirectiveBehavior() { ImmutableList.Builder migrationsMadeBuilder = ImmutableList.builder(); for (String migrationName : migrationNames) { - Ui.Task migrationTask = + Task migrationTask = ui.pushTask("perform_migration", "Performing migration '%s'", migrationName); MigrationConfig migrationConfig = context().migrationConfigs().get(migrationName); @@ -173,7 +174,7 @@ protected int performDirectiveBehavior() { new RepositoryExpression(migrationConfig.getToRepository()) .withOption("localroot", toWriter.getRoot().getAbsolutePath()); - Ui.Task oneMigrationTask = + Task oneMigrationTask = ui.pushTask( "perform_individual_migration", "Performing %s/%s migration '%s'", diff --git a/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java b/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java index dd48efbf..f99952f7 100644 --- a/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java +++ b/java/com/google/devtools/moe/client/directives/MigrateBranchDirective.java @@ -28,6 +28,7 @@ import com.google.devtools.moe.client.Messenger; import com.google.devtools.moe.client.MoeProblem; import com.google.devtools.moe.client.MoeUserProblem; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -127,7 +128,7 @@ protected int performBranchMigration( findMigrationConfigForRepository( overrideUrl, originalFromRepository + "_fork", originalFromRepository); - Ui.Task migrationTask = + Task migrationTask = ui.pushTask( "perform_migration", "Performing migration '%s' from branch '%s'", @@ -177,7 +178,7 @@ protected int performBranchMigration( new RepositoryExpression(migrationConfig.getToRepository()) .withOption("localroot", toWriter.getRoot().getAbsolutePath()); - Ui.Task performMigration = + Task performMigration = ui.pushTask( "perform_individual_migration", "Performing individual migration '%s'", @@ -319,7 +320,7 @@ private List findMigrationsBetweenBranches( RevisionHistory baseRevisions, RevisionHistory fromRevisions, boolean batchChanges) { - Ui.Task determineMigrationsTask = ui.pushTask("determind migrations", "Determine migrations"); + Task determineMigrationsTask = ui.pushTask("determind migrations", "Determine migrations"); List toMigrate = findDescendantRevisions(fromRevisions, baseRevisions); ui.popTask(determineMigrationsTask, ""); @@ -376,7 +377,7 @@ List findDescendantRevisions(RevisionHistory branch, RevisionHistory p Revision head = parentBranch.findHighestRevision(null); String parentRepositoryName = head.repositoryName(); - Ui.Task ancestorTask = ui.pushTask("scan_ancestor_branch", "Gathering ancestor revisions"); + Task ancestorTask = ui.pushTask("scan_ancestor_branch", "Gathering ancestor revisions"); Deque revisionsToProcess = new ArrayDeque<>(); revisionsToProcess.add(head); int count = 0; @@ -395,7 +396,7 @@ List findDescendantRevisions(RevisionHistory branch, RevisionHistory p } ui.popTask(ancestorTask, "Scanned revisions: " + count); - Ui.Task migrationBranchTask = ui.pushTask("scan_target_branch", "Finding mergeable commits"); + Task migrationBranchTask = ui.pushTask("scan_target_branch", "Finding mergeable commits"); LinkedHashSet commitsNotInParentBranch = new LinkedHashSet<>(); revisionsToProcess = new ArrayDeque<>(); revisionsToProcess.add(branch.findHighestRevision(null)); diff --git a/java/com/google/devtools/moe/client/editors/ForwardTranslator.java b/java/com/google/devtools/moe/client/editors/ForwardTranslator.java index a34b3335..efaac35e 100644 --- a/java/com/google/devtools/moe/client/editors/ForwardTranslator.java +++ b/java/com/google/devtools/moe/client/editors/ForwardTranslator.java @@ -17,6 +17,7 @@ package com.google.devtools.moe.client.editors; import com.google.devtools.moe.client.Injector; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.project.ProjectContext; @@ -41,7 +42,7 @@ public Codebase translate( Codebase toTranslate, Map options, ProjectContext context) { Codebase translated = toTranslate; for (TranslatorStep s : steps) { - Ui.Task editTask = Injector.INSTANCE.getUi().pushTask("edit", "Translation editor: " + s.name); + Task editTask = Injector.INSTANCE.getUi().pushTask("edit", "Translation editor: " + s.name); // Pass the translation options to each editor. translated = s.editor.edit(translated, context, options); Injector.INSTANCE.getUi().popTaskAndPersist(editTask, translated.getPath()); diff --git a/java/com/google/devtools/moe/client/editors/InverseTranslator.java b/java/com/google/devtools/moe/client/editors/InverseTranslator.java index 52614c11..257bd322 100644 --- a/java/com/google/devtools/moe/client/editors/InverseTranslator.java +++ b/java/com/google/devtools/moe/client/editors/InverseTranslator.java @@ -19,7 +19,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.devtools.moe.client.Injector; -import com.google.devtools.moe.client.Ui.Task; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; import com.google.devtools.moe.client.parser.Expression; diff --git a/java/com/google/devtools/moe/client/parser/EditExpression.java b/java/com/google/devtools/moe/client/parser/EditExpression.java index 0ac3983c..00c4cfa5 100644 --- a/java/com/google/devtools/moe/client/parser/EditExpression.java +++ b/java/com/google/devtools/moe/client/parser/EditExpression.java @@ -18,6 +18,7 @@ import com.google.common.base.Preconditions; import com.google.devtools.moe.client.Injector; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -50,7 +51,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr throw new CodebaseCreationError("no editor " + editorName); } - Ui.Task editTask = + Task editTask = Injector.INSTANCE .getUi() .pushTask( diff --git a/java/com/google/devtools/moe/client/parser/RepositoryExpression.java b/java/com/google/devtools/moe/client/parser/RepositoryExpression.java index 31783c92..d8d8420c 100644 --- a/java/com/google/devtools/moe/client/parser/RepositoryExpression.java +++ b/java/com/google/devtools/moe/client/parser/RepositoryExpression.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap; import com.google.devtools.moe.client.Injector; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -81,7 +82,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr cc = repo.codebaseCreator(); } - Ui.Task createTask = + Task createTask = Injector.INSTANCE.getUi().pushTask("create_codebase", "Creating from '%s'", this); Codebase c = cc.create(term.options); Injector.INSTANCE.getUi().popTaskAndPersist(createTask, c.getPath()); @@ -99,7 +100,7 @@ public Writer createWriter(ProjectContext context) throws WritingError { RepositoryType r = context.getRepository(term.identifier); WriterCreator wc = r.writerCreator(); - Ui.Task t = Injector.INSTANCE.getUi().pushTask("create_writer", "Creating Writer \"%s\"", term); + Task t = Injector.INSTANCE.getUi().pushTask("create_writer", "Creating Writer \"%s\"", term); try { Writer writer = wc.create(term.options); Injector.INSTANCE.getUi().popTaskAndPersist(t, writer.getRoot()); diff --git a/java/com/google/devtools/moe/client/parser/TranslateExpression.java b/java/com/google/devtools/moe/client/parser/TranslateExpression.java index 195a112d..3c3014b9 100644 --- a/java/com/google/devtools/moe/client/parser/TranslateExpression.java +++ b/java/com/google/devtools/moe/client/parser/TranslateExpression.java @@ -18,6 +18,7 @@ import com.google.common.base.Preconditions; import com.google.devtools.moe.client.Injector; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.codebase.CodebaseCreationError; @@ -57,7 +58,7 @@ public Codebase createCodebase(ProjectContext context) throws CodebaseCreationEr context.translators().keySet()); } - Ui.Task translateTask = + Task translateTask = Injector.INSTANCE .getUi() .pushTask( diff --git a/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java b/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java index 593a6865..ba1c6846 100644 --- a/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java +++ b/java/com/google/devtools/moe/client/project/FileReadingProjectContextFactory.java @@ -21,6 +21,7 @@ import com.google.common.io.Files; import com.google.devtools.moe.client.CommandRunner; import com.google.devtools.moe.client.FileSystem; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.repositories.Repositories; import com.google.devtools.moe.client.tools.FileDifference.FileDiffer; @@ -48,7 +49,7 @@ public FileReadingProjectContextFactory( @Override public ProjectConfig loadConfiguration(String configFilename) throws InvalidProject { String configText; - Ui.Task task = ui.pushTask("read_config", "Reading config file from %s", configFilename); + Task task = ui.pushTask("read_config", "Reading config file from %s", configFilename); try { try { configText = Files.toString(new File(configFilename), UTF_8); diff --git a/java/com/google/devtools/moe/client/testing/RecordingUi.java b/java/com/google/devtools/moe/client/testing/RecordingUi.java index 4093c94d..56703cb6 100644 --- a/java/com/google/devtools/moe/client/testing/RecordingUi.java +++ b/java/com/google/devtools/moe/client/testing/RecordingUi.java @@ -17,6 +17,7 @@ package com.google.devtools.moe.client.testing; import com.google.devtools.moe.client.SystemUi; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import dagger.Provides; @@ -51,7 +52,7 @@ public void error(String msg, Object... args) { } @Override - public void popTask(Ui.Task task, String result) { + public void popTask(Task task, String result) { lastTaskResult = result; super.popTask(task, result); } diff --git a/java/com/google/devtools/moe/client/writer/DraftRevision.java b/java/com/google/devtools/moe/client/writer/DraftRevision.java index 1eb476d4..1840bdcc 100644 --- a/java/com/google/devtools/moe/client/writer/DraftRevision.java +++ b/java/com/google/devtools/moe/client/writer/DraftRevision.java @@ -16,6 +16,7 @@ package com.google.devtools.moe.client.writer; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.Ui; import com.google.devtools.moe.client.codebase.Codebase; import com.google.devtools.moe.client.repositories.RevisionMetadata; @@ -59,7 +60,7 @@ public Factory(Ui ui) { */ public DraftRevision create(Codebase c, Writer destination, @Nullable RevisionMetadata rm) { try { - Ui.Task t = ui.pushTask("push_codebase", "Putting files from Codebase into Writer"); + Task t = ui.pushTask("push_codebase", "Putting files from Codebase into Writer"); DraftRevision r = destination.putCodebase(c, rm); ui.popTask(t, ""); return r; diff --git a/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java b/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java index 29957aca..a4ff9565 100644 --- a/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java +++ b/javatests/com/google/devtools/moe/client/SystemFileSystemTest.java @@ -20,7 +20,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.io.Files; -import com.google.devtools.moe.client.Ui.Task; +import com.google.devtools.moe.client.Task; import com.google.devtools.moe.client.testing.TestingModule; import junit.framework.TestCase; diff --git a/javatests/com/google/devtools/moe/client/UiTest.java b/javatests/com/google/devtools/moe/client/UiTest.java index 4a156706..22f4a75e 100644 --- a/javatests/com/google/devtools/moe/client/UiTest.java +++ b/javatests/com/google/devtools/moe/client/UiTest.java @@ -40,13 +40,13 @@ public void debug(String msg, Object... args) {} public void testStackHelpers() throws Exception { Ui ui = new NoOpUi(); - Ui.Task t = ui.pushTask("foo", "bar"); + Task t = ui.pushTask("foo", "bar"); ui.popTask(t, ""); assertEquals("bar", t.description); t = ui.pushTask("foo", "bar"); try { - ui.popTask(new Ui.Task("baz", "quux"), ""); + ui.popTask(new Task("baz", "quux"), ""); } catch (MoeProblem expected) { return; } From 2b10d4e7b523923140d66928fcbea44087c013cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 19:32:04 -0600 Subject: [PATCH 15/16] Adding Google licence header to the Task class file. --- java/com/google/devtools/moe/client/Task.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/java/com/google/devtools/moe/client/Task.java b/java/com/google/devtools/moe/client/Task.java index f4322dd0..a62dcab9 100644 --- a/java/com/google/devtools/moe/client/Task.java +++ b/java/com/google/devtools/moe/client/Task.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2011 Google, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.google.devtools.moe.client; /** From 43a88b1765f10486c3a71a5f4141006c662d37dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cleber=20de=20Souza=20Alc=C3=A2ntara?= Date: Tue, 23 Feb 2016 20:00:38 -0600 Subject: [PATCH 16/16] Refactoring Utils class by adding javadoc comments to the methods. --- .../com/google/devtools/moe/client/Utils.java | 111 ++++++++++++++---- 1 file changed, 85 insertions(+), 26 deletions(-) diff --git a/java/com/google/devtools/moe/client/Utils.java b/java/com/google/devtools/moe/client/Utils.java index 4508dcc6..6ac70d92 100644 --- a/java/com/google/devtools/moe/client/Utils.java +++ b/java/com/google/devtools/moe/client/Utils.java @@ -38,12 +38,23 @@ public class Utils { /** * Returns a Set that excludes strings matching any of excludeRes. + * + * @param originalSet original set of strings to be filtered. + * @param excludeRes regular expressions to be used as filter. + * + * @return new Set of strings filtered. */ - public static Set filterByRegEx(Set c, List excludeRes) { - return ImmutableSet.copyOf(Sets.filter(c, nonMatchingPredicateFromRes(excludeRes))); + public static Set filterByRegEx(Set originalSet, List excludeRes) { + return ImmutableSet.copyOf(Sets.filter(originalSet, nonMatchingPredicateFromRes(excludeRes))); } - /** @return a Predicate that's true iff a CharSequence doesn't match any of the given regexes */ + /** + * Creates a Predicate with the nonmatching regular expressions. + * + * @param excludeRes regular expressions to match. + * @return a Predicate that's true if a CharSequence doesn't match any of the + * given regular expressions. + */ public static Predicate nonMatchingPredicateFromRes(List excludeRes) { ImmutableList.Builder> rePredicateBuilder = ImmutableList.builder(); for (String excludeRe : excludeRes) { @@ -52,13 +63,27 @@ public static Predicate nonMatchingPredicateFromRes(List e return Predicates.and(rePredicateBuilder.build()); } + /** + * Checks the keys passed into the options to MOE. If an invalid option is + * found, a MoeProblem is thrown. + * + * @param options options received to be checked. + * @param allowedOptions allowed options. + */ public static void checkKeys(Map options, Set allowedOptions) { if (!allowedOptions.containsAll(options.keySet())) { throw new MoeProblem( "Options contains invalid keys:%nOptions: %s%nAllowed keys: %s", options, allowedOptions); } } - + + /** + * Makes the files under a path become relative. + * + * @param files files to have the path converted. + * @param basePath base path for the files. + * @return set of strings containing the relative paths created. + */ public static Set makeFilenamesRelative(Set files, File basePath) { Set result = Sets.newLinkedHashSet(); for (File f : files) { @@ -70,18 +95,29 @@ public static Set makeFilenamesRelative(Set files, File basePath) return ImmutableSet.copyOf(result); } - /** Applies the given Function to all files under baseDir. */ - public static void doToFiles(File baseDir, Function doFunction) { - for (File file : Injector.INSTANCE.getFileSystem().findFiles(baseDir)) { + /** + * Applies the given Function to all files under a base directory. + * + * @param baseDirectory the base directory to have the files applied to the function. + * @param doFunction function to be applied to the files. + */ + public static void doToFiles(File baseDirectory, Function doFunction) { + for (File file : Injector.INSTANCE.getFileSystem().findFiles(baseDirectory)) { doFunction.apply(file); } } - /** Delete files under baseDir whose paths relative to baseDir don't match the given Predicate. */ - public static void filterFiles(File baseDir, final Predicate positiveFilter) { - final URI baseUri = baseDir.toURI(); + /** + * Delete files under a base directory whose paths relative to base directory + * don't match the given Predicate. + * + * @param baseDirectory the base directory containing the files. + * @param positiveFilter predicate to be used as filter. + */ + public static void filterFiles(File baseDirectory, final Predicate positiveFilter) { + final URI baseUri = baseDirectory.toURI(); Utils.doToFiles( - baseDir, + baseDirectory, new Function() { @Override public Void apply(File file) { @@ -98,12 +134,13 @@ public Void apply(File file) { } /** - * Expands the specified File to a new temporary directory, or returns null if the file - * type is unsupported. + * Expands the specified File to a new temporary directory. + * * @param inputFile The File to be extracted. - * @return File pointing to a directory, or null. - * @throws CommandException - * @throws IOException + * @return File pointing to a directory, or null if the file type is unsupported. + * + * @throws CommandException if some error occurs while performing the command. + * @throws IOException is some I/O error occurs. */ public static File expandToDirectory(File inputFile) throws IOException, CommandException { // If the specified path already is a directory, return it without modification. @@ -121,6 +158,14 @@ public static File expandToDirectory(File inputFile) throws IOException, Command return null; } + /** + * Expands a tar file. + * + * @param tar tar file to be expanded. + * @return the expanded directory for the tar file. + * @throws IOException if some error occurs while expanding the tar. + * @throws CommandException if some error occurs while running the command. + */ public static File expandTar(File tar) throws IOException, CommandException { File expandedDir = Injector.INSTANCE.getFileSystem().getTemporaryDirectory("expanded_tar_"); Injector.INSTANCE.getFileSystem().makeDirs(expandedDir); @@ -136,19 +181,28 @@ public static File expandTar(File tar) throws IOException, CommandException { return expandedDir; } - public static void copyDirectory(File src, File dest) throws IOException, CommandException { - if (src == null) { + /** + * Copies a directory to another. + * + * @param source source directory to be copied. + * @param destination destination directory of the copy. + * + * @throws IOException if some I/O error occurs while copying the directory. + * @throws CommandException if some error occurs while performing the command. + */ + public static void copyDirectory(File source, File destination) throws IOException, CommandException { + if (source == null) { return; } - Injector.INSTANCE.getFileSystem().makeDirsForFile(dest); - if (Injector.INSTANCE.getFileSystem().isFile(src)) { - Injector.INSTANCE.getFileSystem().copyFile(src, dest); + Injector.INSTANCE.getFileSystem().makeDirsForFile(destination); + if (Injector.INSTANCE.getFileSystem().isFile(source)) { + Injector.INSTANCE.getFileSystem().copyFile(source, destination); return; } - File[] files = Injector.INSTANCE.getFileSystem().listFiles(src); + File[] files = Injector.INSTANCE.getFileSystem().listFiles(source); if (files != null) { for (File subFile : files) { - File newFile = new File(dest, Injector.INSTANCE.getFileSystem().getName(subFile)); + File newFile = new File(destination, Injector.INSTANCE.getFileSystem().getName(subFile)); if (Injector.INSTANCE.getFileSystem().isDirectory(subFile)) { copyDirectory(subFile, newFile); } else { @@ -157,7 +211,6 @@ public static void copyDirectory(File src, File dest) throws IOException, Comman } } } - return; } /** @@ -176,13 +229,19 @@ public static void makeShellScript(String content, String name) { } } - /** A Gson parser used specifically for cloning Gson-ready objects */ + /** + * A Gson parser used specifically for cloning Gson-ready objects + */ private static final Gson CLONER = new Gson(); /** * Does a simple clone of a Gson-ready object, by marshalling into a Json intermediary and * processing into a new object. This is not in any way efficient, but it guarantees the correct - * cloning semantics. It should not be used in tight loops where performance is a concern. + * cloning semantics. It should not be used in tight loops where performance is a concern. + * + * @param type of the object being cloned. + * @param t object to be cloned. + * @return object cloned. */ @SuppressWarnings("unchecked") public static T cloneGsonObject(T t) {