Ejemplo n.º 1
0
  /** Executes the map command using the provided options. */
  @Override
  protected void runInternal(GeogitCLI cli) throws IOException {

    if (args == null || args.isEmpty() || args.size() != 1) {
      printUsage(cli);
      throw new CommandFailedException();
    }

    String path = args.get(0);

    geogit = cli.getGeogit();

    ObjectId oldTreeId = geogit.getRepository().workingTree().getTree().getId();

    ObjectId newTreeId = geogit.command(OSMUnmapOp.class).setPath(path).call().getId();

    ConsoleReader console = cli.getConsole();
    if (newTreeId.equals(oldTreeId)) {
      console.println(
          "No differences were found after unmapping.\n"
              + "No changes have been made to the working tree");
    } else {
      // print something?
    }
  }
Ejemplo n.º 2
0
 @Test
 public void testImport() throws Exception {
   String filename = OSMImportOp.class.getResource("ways.xml").getFile();
   File file = new File(filename);
   cli.execute("osm", "import", file.getAbsolutePath());
   long unstaged = cli.getGeogit().getRepository().getWorkingTree().countUnstaged("node");
   assertTrue(unstaged > 0);
   unstaged = cli.getGeogit().getRepository().getWorkingTree().countUnstaged("way");
   assertTrue(unstaged > 0);
 }
Ejemplo n.º 3
0
 @Test
 public void testImportWithMapping() throws Exception {
   String filename = OSMImportOp.class.getResource("ways.xml").getFile();
   File file = new File(filename);
   String mappingFilename = OSMMap.class.getResource("mapping.json").getFile();
   File mappingFile = new File(mappingFilename);
   cli.execute(
       "osm", "import", file.getAbsolutePath(), "--mapping", mappingFile.getAbsolutePath());
   long unstaged = cli.getGeogit().getRepository().getWorkingTree().countUnstaged("onewaystreets");
   assertTrue(unstaged > 0);
 }
Ejemplo n.º 4
0
 @Before
 public void setUp() throws Exception {
   ConsoleReader consoleReader =
       new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
   cli = new GeogitCLI(consoleReader);
   File workingDirectory = tempFolder.getRoot();
   Platform platform = new TestPlatform(workingDirectory);
   cli.setPlatform(platform);
   cli.execute("init");
   cli.execute("config", "user.name", "Gabriel Roldan");
   cli.execute("config", "user.email", "*****@*****.**");
   assertTrue(new File(workingDirectory, ".geogit").exists());
 }
Ejemplo n.º 5
0
  @Override
  public void runInternal(GeogitCLI cli) throws Exception {
    checkState(cli.getGeogit() != null, "Not a geogit repository: " + cli.getPlatform().pwd());
    String ref;
    if (refList.isEmpty()) {
      ref = null;
    } else {
      ref = refList.get(0);
    }
    Iterator<RevObject> iter =
        cli.getGeogit() //
            .command(WalkGraphOp.class)
            .setReference(ref) //
            // .setStrategy(lsStrategy) //
            .call();

    final ConsoleReader console = cli.getConsole();
    if (!iter.hasNext()) {
      if (ref == null) {
        console.println("The working tree is empty");
      } else {
        console.println("The specified path is empty");
      }
      return;
    }

    Function<RevObject, CharSequence> printFunctor =
        new Function<RevObject, CharSequence>() {
          @Override
          public CharSequence apply(RevObject input) {
            if (verbose) {
              return String.format("%s: %s %s", input.getId(), input.getType(), input);
            } else {
              return String.format("%s: %s", input.getId(), input.getType());
            }
          }
        };

    Iterator<CharSequence> lines = Iterators.transform(iter, printFunctor);

    while (lines.hasNext()) {
      console.println(lines.next());
    }
    console.flush();
  }
Ejemplo n.º 6
0
  @Override
  public void runInternal(GeogitCLI cli) throws IOException {
    ImmutableList<ObjectId> updatedObjects = cli.getGeogit().command(RebuildGraphOp.class).call();

    final ConsoleReader console = cli.getConsole();
    if (updatedObjects.size() > 0) {
      if (quiet) {
        console.println(updatedObjects.size() + " graph elements (commits) were fixed.");
      } else {
        console.println(
            "The following graph elements (commits) were incomplete or missing and have been fixed:");
        for (ObjectId object : updatedObjects) {
          console.println(object.toString());
        }
      }
    } else {
      console.println("No missing or incomplete graph elements (commits) were found.");
    }
  }
Ejemplo n.º 7
0
  @Override
  public void setUpInternal() throws Exception {
    ConsoleReader consoleReader =
        new ConsoleReader(System.in, System.out, new UnsupportedTerminal());
    cli = new GeogitCLI(consoleReader);

    cli.setGeogit(geogit);

    // Add points
    insertAndAdd(points1);
    insertAndAdd(points2);
    insertAndAdd(points3);

    geogit.command(CommitOp.class).call();

    // Add lines
    insertAndAdd(lines1);
    insertAndAdd(lines2);
    insertAndAdd(lines3);

    geogit.command(CommitOp.class).call();
  }
Ejemplo n.º 8
0
  /**
   * Executes the describe command using the provided options.
   *
   * @param cli
   * @see
   *     org.geogit.geotools.cli.porcelain.AbstractOracleCommand#runInternal(org.geogit.cli.GeogitCLI)
   */
  @Override
  protected void runInternal(GeogitCLI cli) throws IOException {
    DataStore dataStore = getDataStore();

    try {
      cli.getConsole().println("Fetching table...");

      Optional<Map<String, String>> propertyMap =
          cli.getGeogit().command(DescribeOp.class).setTable(table).setDataStore(dataStore).call();

      if (propertyMap.isPresent()) {
        cli.getConsole().println("Table : " + table);
        cli.getConsole().println("----------------------------------------");
        for (Entry<String, String> entry : propertyMap.get().entrySet()) {
          cli.getConsole().println("\tProperty  : " + entry.getKey());
          cli.getConsole().println("\tType      : " + entry.getValue());
          cli.getConsole().println("----------------------------------------");
        }
      } else {
        throw new CommandFailedException("Could not find the specified table.");
      }
    } catch (GeoToolsOpException e) {
      switch (e.statusCode) {
        case TABLE_NOT_DEFINED:
          throw new CommandFailedException("No table supplied.", e);
        case UNABLE_TO_GET_FEATURES:
          throw new CommandFailedException("Unable to read the feature source.", e);
        case UNABLE_TO_GET_NAMES:
          throw new CommandFailedException("Unable to read feature types.", e);
        default:
          throw new CommandFailedException("Exception: " + e.statusCode.name(), e);
      }

    } finally {
      dataStore.dispose();
      cli.getConsole().flush();
    }
  }
Ejemplo n.º 9
0
 @Override
 public void tearDownInternal() throws Exception {
   cli.close();
 }
Ejemplo n.º 10
0
  /**
   * Executes the log command using the provided options.
   *
   * @param cli
   * @throws IOException
   * @see org.geogit.cli.AbstractCommand#runInternal(org.geogit.cli.GeogitCLI)
   */
  @Override
  public void runInternal(GeogitCLI cli) throws Exception {
    final Platform platform = cli.getPlatform();
    Preconditions.checkState(
        cli.getGeogit() != null, "Not a geogit repository: " + platform.pwd().getAbsolutePath());

    Preconditions.checkArgument(
        !(args.summary && args.oneline), "--summary and --oneline cannot be used together");
    Preconditions.checkArgument(
        !(args.stats && args.oneline), "--stats and --oneline cannot be used together");
    Preconditions.checkArgument(
        !(args.stats && args.oneline), "--name-only and --oneline cannot be used together");

    geogit = cli.getGeogit();

    LogOp op =
        geogit.command(LogOp.class).setTopoOrder(args.topo).setFirstParentOnly(args.firstParent);

    refs = Maps.newHashMap();
    if (args.decoration) {
      Optional<Ref> head = geogit.command(RefParse.class).setName(Ref.HEAD).call();
      refs.put(head.get().getObjectId(), Ref.HEAD);
      ImmutableSet<Ref> set = geogit.command(ForEachRef.class).call();
      for (Ref ref : set) {
        ObjectId id = ref.getObjectId();
        if (refs.containsKey(id)) {
          refs.put(id, refs.get(id) + ", " + ref.getName());
        } else {
          refs.put(id, ref.getName());
        }
      }
    }
    if (args.all) {
      ImmutableSet<Ref> refs = geogit.command(ForEachRef.class).call();
      List<ObjectId> list = Lists.newArrayList();
      for (Ref ref : refs) {
        list.add(ref.getObjectId());
      }
      Optional<Ref> head = geogit.command(RefParse.class).setName(Ref.HEAD).call();
      if (head.isPresent()) {
        Ref ref = head.get();
        if (ref instanceof SymRef) {
          ObjectId id = ref.getObjectId();
          list.remove(id);
          list.add(id); // put the HEAD ref in the last position, to give it preference
        }
      }
      for (ObjectId id : list) {
        op.addCommit(id);
      }
    } else if (args.branch != null) {
      Optional<Ref> obj = geogit.command(RefParse.class).setName(args.branch).call();
      Preconditions.checkArgument(obj.isPresent(), "Wrong branch name: " + args.branch);
      op.addCommit(obj.get().getObjectId());
    }

    if (args.author != null && !args.author.isEmpty()) {
      op.setAuthor(args.author);
    }
    if (args.committer != null && !args.committer.isEmpty()) {
      op.setCommiter(args.committer);
    }
    if (args.skip != null) {
      op.setSkip(args.skip.intValue());
    }
    if (args.limit != null) {
      op.setLimit(args.limit.intValue());
    }
    if (args.since != null || args.until != null) {
      Date since = new Date(0);
      Date until = new Date();
      if (args.since != null) {
        since = new Date(geogit.command(ParseTimestamp.class).setString(args.since).call());
      }
      if (args.until != null) {
        until = new Date(geogit.command(ParseTimestamp.class).setString(args.until).call());
        if (args.all) {
          throw new IllegalStateException(
              "Cannot specify 'until' commit when listing all branches");
        }
      }
      op.setTimeRange(new Range<Date>(Date.class, since, until));
    }
    if (!args.sinceUntilPaths.isEmpty()) {
      List<String> sinceUntil =
          ImmutableList.copyOf((Splitter.on("..").split(args.sinceUntilPaths.get(0))));
      Preconditions.checkArgument(
          sinceUntil.size() == 1 || sinceUntil.size() == 2,
          "Invalid refSpec format, expected [<until>]|[<since>..<until>]: %s",
          args.sinceUntilPaths.get(0));

      String sinceRefSpec;
      String untilRefSpec;
      if (sinceUntil.size() == 1) {
        // just until was given
        sinceRefSpec = null;
        untilRefSpec = sinceUntil.get(0);
      } else {
        sinceRefSpec = sinceUntil.get(0);
        untilRefSpec = sinceUntil.get(1);
      }
      if (sinceRefSpec != null) {
        Optional<ObjectId> since;
        since = geogit.command(RevParse.class).setRefSpec(sinceRefSpec).call();
        Preconditions.checkArgument(since.isPresent(), "Object not found '%s'", sinceRefSpec);
        op.setSince(since.get());
      }
      if (untilRefSpec != null) {
        if (args.all) {
          throw new IllegalStateException(
              "Cannot specify 'until' commit when listing all branches");
        }
        Optional<ObjectId> until;
        until = geogit.command(RevParse.class).setRefSpec(untilRefSpec).call();
        Preconditions.checkArgument(until.isPresent(), "Object not found '%s'", sinceRefSpec);
        op.setUntil(until.get());
      }
    }
    if (!args.pathNames.isEmpty()) {
      for (String s : args.pathNames) {
        op.addPath(s);
      }
    }
    Iterator<RevCommit> log = op.call();
    console = cli.getConsole();
    Terminal terminal = console.getTerminal();
    switch (args.color) {
      case never:
        useColor = false;
        break;
      case always:
        useColor = true;
        break;
      default:
        useColor = terminal.isAnsiSupported();
    }

    if (!log.hasNext()) {
      console.println("No commits to show");
      console.flush();
      return;
    }

    LogEntryPrinter printer;
    if (args.oneline) {
      printer = new OneLineConverter();
    } else {
      LOG_DETAIL detail;
      if (args.summary) {
        detail = LOG_DETAIL.SUMMARY;
      } else if (args.names) {
        detail = LOG_DETAIL.NAMES_ONLY;
      } else if (args.stats) {
        detail = LOG_DETAIL.STATS;
      } else {
        detail = LOG_DETAIL.NOTHING;
      }

      printer = new StandardConverter(detail, geogit.getPlatform());
    }

    while (log.hasNext()) {
      printer.print(log.next());
      console.flush();
    }
  }