Package com.google.devtools.moe.client

Examples of com.google.devtools.moe.client.FileSystem


    File renameRun = new File("/rename_run_foo");
    File newSubFile = new File(renameRun, "joe.txt");

    AppContextForTesting.initForTest();
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    CommandRunner cmd = control.createMock(CommandRunner.class);
    AppContext.RUN.cmd = cmd;
    AppContext.RUN.fileSystem = fileSystem;

    expect(fileSystem.getTemporaryDirectory("rename_run_")).andReturn(renameRun);

    expect(fileSystem.isDirectory(codebaseFile)).andReturn(true);
    expect(fileSystem.listFiles(codebaseFile)).andReturn(new File[] {oldSubFile});
    expect(fileSystem.isDirectory(oldSubFile)).andReturn(false);
    fileSystem.makeDirsForFile(newSubFile);
    fileSystem.copyFile(oldSubFile, newSubFile);

    control.replay();

    new RenamingEditor("renamey", ImmutableMap.of("moe", "joe"), false)
        .edit(codebase,
View Full Code Here


public class InverseRenamingEditorTest extends TestCase {

  public void testEdit() throws Exception {
    AppContextForTesting.initForTest();
    IMocksControl control = EasyMock.createControl();
    FileSystem mockFs = control.createMock(FileSystem.class);
    AppContext.RUN.fileSystem = mockFs;
    ProjectContext context = ProjectContext.builder().build();

    InverseRenamingEditor inverseRenamey = new InverseRenamingEditor(
        new RenamingEditor(
            "renamey", ImmutableMap.of("internal_root", "public_root"), false /*useRegex*/));

    Codebase input = new Codebase(new File("/input"), "public", new RepositoryExpression("input"));
    Codebase destination =
        new Codebase(new File("/destination"), "public", new RepositoryExpression("destination"));

    expect(mockFs.getTemporaryDirectory("inverse_rename_run_")).andReturn(new File("/output"));

    expect(mockFs.findFiles(new File("/input"))).andReturn(ImmutableSet.of(
        new File("/input/toplevel.txt"),
        new File("/input/public_root/1.txt"),
        new File("/input/public_root/new.txt"),
        new File("/input/public_root/inner1/inner2/innernew.txt")));

    expect(mockFs.findFiles(new File("/destination"))).andReturn(ImmutableSet.of(
        new File("/destination/internal_root/1.txt")));

    expectCopy(mockFs, "/input/toplevel.txt", "/output/toplevel.txt");
    expectCopy(mockFs, "/input/public_root/1.txt", "/output/internal_root/1.txt");
    expectCopy(mockFs, "/input/public_root/new.txt", "/output/internal_root/new.txt");
View Full Code Here

  public static class ConcreteFileDiffer implements FileDiffer {

    @Override
    public FileDifference diffFiles(String relativeFilename, File file1, File file2) {
      // Diff their existence.
      FileSystem fileSystem = AppContext.RUN.fileSystem;
      boolean file1Exists = fileSystem.exists(file1);
      boolean file2Exists = fileSystem.exists(file2);

      Preconditions.checkArgument(file1Exists || file2Exists,
                                  "Neither file exists: %s, %s", file1, file2);

      Comparison existence = Comparison.diffBools(file1Exists, file2Exists);

      boolean file1Executable = fileSystem.isExecutable(file1);
      boolean file2Executable = fileSystem.isExecutable(file2);

      Comparison executability = Comparison.diffBools(file1Executable, file2Executable);

      String contentDiff = null;
View Full Code Here

   * @param relativeFilename  the filename to put
   * @param c  the Codebase to take the file from
   */
  void putFile(String relativeFilename, Codebase c) {
    try {
      FileSystem fs = AppContext.RUN.fileSystem;
      File dest = new File(rootDirectory.getAbsolutePath(), relativeFilename);
      File src = c.getFile(relativeFilename);
      boolean srcExists = fs.exists(src);
      boolean destExists = fs.exists(dest);

      boolean srcExecutable = fs.isExecutable(src);
      boolean destExecutable = fs.isExecutable(dest);

      if (!srcExists && !destExists) {
        throw new MoeProblem(
            String.format("Neither src nor dests exists. Unreachable code:%n%s%n%s%n%s",
                          relativeFilename, src, dest));
      }

      if (!srcExists) {
        SvnRepository.runSvnCommand(
            ImmutableList.of("rm", relativeFilename), rootDirectory.getAbsolutePath());
        // TODO(dbentley): handle newly-empty directories
        return;
      }

      try {
        fs.makeDirsForFile(dest);
        fs.copyFile(src, dest);
      } catch (IOException e) {
        throw new MoeProblem(e.getMessage());
      }

      if (!destExists) {
View Full Code Here

    RepositoryConfig repositoryConfig = control.createMock(RepositoryConfig.class);
    expect(repositoryConfig.getUrl()).andReturn(repositoryURL).anyTimes();
    String localCloneTempDir = "/tmp/hg_clone_mockrepo_12345";

    // Mock AppContext.RUN.fileSystem.getTemporaryDirectory()
    FileSystem mockFS = control.createMock(FileSystem.class);
    // The Lifetimes of clones in these tests are arbitrary since we're not really creating any
    // temp dirs and we're not testing clean-up.
    expect(mockFS.getTemporaryDirectory(
        EasyMock.eq("hg_clone_" + repositoryName + "_"), EasyMock.<Lifetime>anyObject()))
        .andReturn(new File(localCloneTempDir));
    AppContext.RUN.fileSystem = mockFS;

    // Mock HgRepository.runHgCommand()
View Full Code Here

*/
public class PatchingEditorTest extends TestCase {
  public void testNoSuchPatchFile() throws Exception {
    AppContextForTesting.initForTest();
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    AppContext.RUN.fileSystem = fileSystem;

    File patcherRun = new File("/patcher_run_foo");
    File codebaseFile = new File("/codebase");
    Codebase codebase = new Codebase(codebaseFile, "internal", null);
    Map<String, String> options = new HashMap<String, String>();
    options.put("file", "notFile");

    expect(fileSystem.getTemporaryDirectory("patcher_run_")).andReturn(patcherRun);
    expect(fileSystem.isReadable(new File("notFile"))).andReturn(false);

    control.replay();

    try {
      new PatchingEditor("patcher").edit(codebase,
View Full Code Here

  }

  public void testPatching() throws Exception {
    AppContextForTesting.initForTest();
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    CommandRunner cmd = control.createMock(CommandRunner.class);
    AppContext.RUN.cmd = cmd;
    AppContext.RUN.fileSystem = fileSystem;

    File patcherRun = new File("/patcher_run_foo");
    File patchFile = new File("/patchfile");
    File codebaseFile = new File("/codebase");

    Codebase codebase = new Codebase(codebaseFile,
                                     "internal",
                                     null /* CodebaseExpression is not needed here. */);

    Map<String, String> options = new HashMap<String, String>();
    options.put("file", "/patchfile");

    expect(fileSystem.getTemporaryDirectory("patcher_run_")).andReturn(patcherRun);
    expect(fileSystem.isReadable(patchFile)).andReturn(true);
    fileSystem.makeDirsForFile(patcherRun);
    expect(fileSystem.isFile(codebaseFile)).andReturn(false);
    expect(fileSystem.listFiles(codebaseFile)).andReturn(new File[] {});

    expect(cmd.runCommand(
        "patch",
        ImmutableList.of("-p0",
                         "--input=/patchfile"),
View Full Code Here

*/
public class FileDifferenceTest extends TestCase {
  public void testExistence() throws Exception {
    AppContextForTesting.initForTest();
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    CommandRunner cmd = control.createMock(CommandRunner.class);
    AppContext.RUN.cmd = cmd;
    AppContext.RUN.fileSystem = fileSystem;

    File file1 = new File("/1/foo");
    File file2 = new File("/2/foo");

    expect(fileSystem.exists(file1)).andReturn(true);
    expect(fileSystem.exists(file2)).andReturn(false);
    expect(fileSystem.isExecutable(file1)).andReturn(false);
    expect(fileSystem.isExecutable(file2)).andReturn(false);
    expect(cmd.runCommand("diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "")).andThrow(
        new CommandRunner.CommandException(
            "diff", ImmutableList.of("-N", "/1/foo", "/2/foo"), "foo", "", 1));

    control.replay();
View Full Code Here

                 ImmutableSet.of(new Revision("r2", "name2"), new Revision("r3", "name2")));
  }

  public void testMakeDbFromFile() throws Exception {
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    AppContext.RUN.fileSystem = fileSystem;

    File dbFile = new File("/path/to/db");
    String dbText = Joiner.on("\n").join(
        "{",
        "  'equivalences': [",
        "    {",
        "      'rev1': {",
        "        'revId': 'r1',",
        "        'repositoryName': 'name1'",
        "      },",
        "      'rev2': {",
        "        'revId': 'r2',",
        "        'repositoryName': 'name2'",
        "      }",
        "    }",
        "  ]",
        "}");

    expect(fileSystem.fileToString(dbFile)).andReturn(dbText);

    control.replay();
    assertEquals(
        FileDb.makeDbFromDbText(dbText).getEquivalences(),
        FileDb.makeDbFromFile(dbFile.getPath()).getEquivalences());
View Full Code Here

    control.verify();
  }

  public void testWriteDbToFile() throws Exception {
    IMocksControl control = EasyMock.createControl();
    FileSystem fileSystem = control.createMock(FileSystem.class);
    AppContext.RUN.fileSystem = fileSystem;

    File dbFile = new File("/path/to/db");
    String dbText = Joiner.on("\n").join(
        "{",
        "  'equivalences': [",
        "    {",
        "      'rev1': {",
        "        'revId': 'r1',",
        "        'repositoryName': 'name1'",
        "      },",
        "      'rev2': {",
        "        'revId': 'r2',",
        "        'repositoryName': 'name2'",
        "      }",
        "    }",
        "  ],",
        "  'migrations': []",
        "}");

    fileSystem.write(dbText.replace('\'', '"'), dbFile);

    control.replay();
    FileDb.makeDbFromDbText(dbText).writeToLocation(dbFile.getPath());
    control.verify();
  }
View Full Code Here

TOP

Related Classes of com.google.devtools.moe.client.FileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.