コード例 #1
0
  /**
   * Creates a task that will execute the given command.
   *
   * @param cmd command to schedule
   * @param globalOptions options to use when running the command
   * @param mgr listener for command events
   * @return RequestProcessor.Task a task ready to execute the command
   * @throws IllegalCommandException if the command is not valid, e.g. it contains files that cannot
   *     be processed by a single command (they do not have a common filesystem root OR their CVS
   *     Roots differ)
   */
  public RequestProcessor.Task createTask(
      Command cmd, GlobalOptions globalOptions, final ExecutorSupport mgr)
      throws IllegalCommandException {

    File[] files = getCommandFiles(cmd);
    if ((cmd instanceof CheckoutCommand) == false && !(cmd instanceof RlogCommand)) { // XXX
      ensureValidCommand(files);
    }

    if (globalOptions.getCVSRoot() == null) {
      globalOptions = (GlobalOptions) globalOptions.clone();
      globalOptions.setCVSRoot(cvsRoot);
    }

    Client client = createClient();
    if ((cmd instanceof RlogCommand)) { // XXX
    } else if ((cmd instanceof CheckoutCommand)) { // XXX
      BasicCommand bc = (BasicCommand) cmd;
      if (bc.getFiles() != null) {
        String path = bc.getFiles()[0].getAbsolutePath();
        client.setLocalPath(path);
      } else {
        // #67315: use some default working dir
        client.setLocalPath(System.getProperty("user.dir")); // NOI18N
      }
    } else if (cmd instanceof ImportCommand) {
      client.setLocalPath(((ImportCommand) cmd).getImportDirectory());
    } else {
      setLocalDirectory(client, files);
    }

    client.getEventManager().addCVSListener(mgr);
    final CommandRunnable cr = new CommandRunnable(client, globalOptions, cmd, mgr);
    mgr.commandEnqueued(cr);
    RequestProcessor.Task task = requestProcessor.create(cr);
    task.addTaskListener(
        new TaskListener() {
          public void taskFinished(Task task) {
            try {
              // There are times when 'commandTerminated()' is not the last method called, therefore
              // I introduced
              // this event that really marks the very end of a command (thread end)
              mgr.commandTerminated(new TerminationEvent(new Result(cr)));
            } catch (Throwable e) {
              ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
            } finally {
              flushLog();
            }
          }
        });
    return task;
  }
コード例 #2
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Remove the files in an array of Files from the repository.
   *
   * @param files the files to remove.
   * @throws CommandException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  BasicServerResponse removeFromRepository(Client client, Collection files)
      throws CommandException, CommandAbortedException, AuthenticationException {
    BasicServerResponse basicServerResponse = new BasicServerResponse();

    if (files.size() < 1) {
      basicServerResponse.commandTerminated(null);
      return basicServerResponse;
    }

    setupConnection(client);
    // setupConnection();
    // Client client = getClient();

    RemoveCommand removeCommand = new RemoveCommand();
    removeCommand.setFiles(listToFileArray(files));

    client.getEventManager().addCVSListener(basicServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());

    printCommand(removeCommand, client);
    try {
      adminHandler.setMildManneredMode(true);
      client.executeCommand(removeCommand, globalOptions);
      basicServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(basicServerResponse);
      disconnect(client);
      adminHandler.setMildManneredMode(false);
    }

    return basicServerResponse;
  }
コード例 #3
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Get status of all the given files. Returns a List of TeamStatusInfo.
   *
   * @param files The files whose status to retrieve
   * @param remoteDirs These are the directories which we know are in the repository. Any file in
   *     the files list which does not exist locally but for which the containing directory is in
   *     the repository, should have that directory listed here.
   * @throws CommandAbortedException
   * @throws CommandException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  public synchronized StatusServerResponse getStatus(Client client, Set files, Set remoteDirs)
      throws CommandAbortedException, CommandException, AuthenticationException {
    // setupConnection();
    // Client client = getClient();
    setupConnection(client);

    // Now we can use the cvs "status" command to get status on the
    // remaining files.

    StatusCommand statusCommand = new StatusCommand();
    statusCommand.setFiles(listToFileArray(files));

    StatusServerResponse statusServerResponse = new StatusServerResponse();
    client.getEventManager().addCVSListener(statusServerResponse);

    client.setLocalPath(projectPath.getAbsolutePath());
    printCommand(statusCommand, client);
    adminHandler.setMildManneredMode(true);

    try {
      client.executeCommand(statusCommand, globalOptions);
      statusServerResponse.waitForExecutionToFinish();
    } finally {
      adminHandler.setMildManneredMode(false);
      client.getEventManager().removeCVSListener(statusServerResponse);
      disconnect(client);
    }

    return statusServerResponse;
  }
コード例 #4
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Import a project into the repository. The project will be put in the repository in a module
   * named after the project.
   *
   * @throws CommandException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  BasicServerResponse importInRepository(Client client)
      throws CommandException, CommandAbortedException, AuthenticationException {
    // setupConnection();
    // Client client = getClient();
    setupConnection(client);

    ImportCommand importCommand = new ImportCommand();

    // importCommand.addWrapper(localPath + "/TestProject/simplePackage/SimpleClass.java",
    // KeywordSubstitutionOptions.DEFAULT);
    // importCommand.addWrapper(localPath + "/TestProject/simplePackage/added.txt",
    // KeywordSubstitutionOptions.DEFAULT);
    importCommand.setModule(projectPath.getName());
    importCommand.setReleaseTag("init");
    importCommand.setLogMessage("logMessage");
    importCommand.setVendorTag("vendor");

    // Ignore all files during checkout. Then we can just commit them in-place.
    importCommand.addIgnoredFile("*");

    BasicServerResponse basicServerResponse = new BasicServerResponse();
    client.getEventManager().addCVSListener(basicServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());
    printCommand(importCommand, client);

    try {
      client.executeCommand(importCommand, globalOptions);
      basicServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(basicServerResponse);
      disconnect(client);
    }

    return basicServerResponse;
  }
コード例 #5
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Checkout project from repostitory to local project.
   *
   * @throws CommandException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  public synchronized BasicServerResponse doCheckout(Client client, File projectPath)
      throws AuthenticationException, CommandAbortedException, CommandException {
    // Client client = getClient();
    // setupConnection();
    setupConnection(client);

    CheckoutCommand checkoutCommand = new CheckoutCommand(true, projectPath.getName());
    checkoutCommand.setRecursive(true);
    checkoutCommand.setPruneDirectories(false);

    BasicServerResponse basicServerResponse = new BasicServerResponse();
    client.getEventManager().addCVSListener(basicServerResponse);
    client.setLocalPath(projectPath.getParent());

    printCommand(checkoutCommand, client);
    try {
      client.executeCommand(checkoutCommand, globalOptions);
      basicServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(basicServerResponse);
      disconnect(client);
    }

    return basicServerResponse;
  }
コード例 #6
0
  private void setLocalDirectory(Client client, File[] files) throws IllegalCommandException {
    if (files.length == 0) {
      return;
    }

    File commonParent;

    if (files[0].isDirectory()) { // XXX it does not work for checkout
      commonParent = files[0];
    } else {
      commonParent = files[0].getParentFile();
    }

    for (int i = 1; i < files.length; i++) {
      if (!Utils.isParentOrEqual(commonParent, files[i])) {
        for (; ; ) {
          commonParent = commonParent.getParentFile();
          if (commonParent == null)
            throw new IllegalCommandException("Files do not have common parent!"); // NOI18N
          if (Utils.isParentOrEqual(commonParent, files[i])) {
            break;
          }
        }
      }
    }

    // we must not run commands from within folders that are not yet in CVS, try to find the closest
    // uptodate parent
    FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache();
    for (File versionedCommonParent = commonParent;
        versionedCommonParent != null;
        versionedCommonParent = versionedCommonParent.getParentFile()) {
      FileInformation info = cache.getStatus(versionedCommonParent);
      if (info.getStatus() == FileInformation.STATUS_VERSIONED_UPTODATE) {
        commonParent = versionedCommonParent;
        break;
      }
    }
    client.setLocalPath(commonParent.getAbsolutePath());
  }
コード例 #7
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Get the history of the repository - all commits, including file, date, revision, user, and
   * comment.
   *
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   * @throws CommandAbortedException
   * @throws CommandException
   */
  public synchronized LogServerResponse doGetLogHistory(Client client)
      throws AuthenticationException, CommandAbortedException, CommandException {
    // Client client = getClient();
    setupConnection(client);

    LogCommand logCommand = new LogCommand();

    LogServerResponse logServerResponse = new LogServerResponse();
    client.getEventManager().addCVSListener(logServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());

    printCommand(logCommand, client);
    try {
      client.executeCommand(logCommand, globalOptions);
      logServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(logServerResponse);
      disconnect(client);
    }

    return logServerResponse;
  }
コード例 #8
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Add an array of Files/directories to the repository. Parent directories must be specified
   * before the sub-directories/files they contain.
   *
   * @param files the files to add
   * @param binary true if the added files should be treated as binary
   * @throws CommandException
   * @throws CommandAbortedException
   * @throws AuthenticationException
   * @throws InvalidCvsRootException
   */
  BasicServerResponse addToRepository(Client client, File[] files, boolean binary)
      throws CommandException, CommandAbortedException, AuthenticationException {
    BasicServerResponse basicServerResponse = new BasicServerResponse();

    // If there's nothing to add, return immediately
    if (files.length < 1) {
      basicServerResponse.commandTerminated(null);
      return basicServerResponse;
    }

    setupConnection(client);
    // setupConnection();
    // Client client = getClient();

    AddCommand addCommand = new AddCommand();
    addCommand.setFiles(files);

    KeywordSubstitutionOptions kso;
    if (binary) {
      kso = KeywordSubstitutionOptions.BINARY;
    } else {
      kso = KeywordSubstitutionOptions.DEFAULT;
    }
    addCommand.setKeywordSubst(kso);

    client.getEventManager().addCVSListener(basicServerResponse);
    client.setLocalPath(projectPath.toString());

    printCommand(addCommand, client);
    try {
      client.executeCommand(addCommand, globalOptions);
      basicServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(basicServerResponse);
      disconnect(client);
    }

    return basicServerResponse;
  }
コード例 #9
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Get a list of modules in the repository.
   *
   * @throws InvalidCvsRootException
   * @throws AuthenticationException
   * @throws CommandAbortedException
   * @throws CommandException
   */
  public synchronized UpdateServerResponse doGetModules(Client client, List modules)
      throws AuthenticationException, CommandAbortedException, CommandException {
    // Client client = getClient();
    setupConnection(client);
    client.setAdminHandler(new EmptyAdminHandler());

    CheckoutCommand checkoutCommand = new CheckoutCommand(true, ".");
    checkoutCommand.setRecursive(true);
    checkoutCommand.setPruneDirectories(false);
    globalOptions.setDoNoChanges(true);

    UpdateServerResponse updateServerResponse = new UpdateServerResponse(null, null);
    client.getEventManager().addCVSListener(updateServerResponse);
    client.setLocalPath(projectPath.getAbsolutePath());
    printCommand(checkoutCommand, client);

    try {
      client.executeCommand(checkoutCommand, globalOptions);
      updateServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(updateServerResponse);
      disconnect(client);
      client.setAdminHandler(adminHandler);
      globalOptions.setDoNoChanges(false);
    }

    List projects = updateServerResponse.getNewDirectoryNames();
    for (Iterator i = projects.iterator(); i.hasNext(); ) {
      String projectName = i.next().toString();
      if (!projectName.equals("CVSROOT")) {
        modules.add(projectName);
      }
    }

    return updateServerResponse;
  }
コード例 #10
0
ファイル: CvsRepository.java プロジェクト: tordf/Greenfoot
  /**
   * Get the response of a "dummy run" update command. The response contains a list of files, which
   * need to be updated or are locally modified etc.
   */
  private UpdateServerResponse getUpdateServerResponse(Client client, String path)
      throws CommandException, CommandAbortedException, AuthenticationException {
    // setupConnection();
    // Client client = getClient();
    setupConnection(client);

    UpdateCommand updateCommand = new UpdateCommand();
    UpdateServerResponse updateServerResponse = new UpdateServerResponse(null, null);
    GlobalOptions globalOptions = new GlobalOptions();

    updateCommand.setRecursive(true);
    updateCommand.setBuildDirectories(true);
    updateCommand.setPruneDirectories(true);
    updateCommand.setCleanCopy(false);
    globalOptions.setCVSRoot(cvsroot.toString());

    globalOptions.setDoNoChanges(true); // -n
    globalOptions.setModeratelyQuiet(true); // -q
    client.setLocalPath(path);
    client.getEventManager().addCVSListener(updateServerResponse);

    // System.out.println("dir: " + client.getLocalPath());
    // System.out.println("globalOptions: " + globalOptions.getCVSCommand());
    printCommand(updateCommand, client);

    // Debug.message("Update command = " + updateCommand.getCVSCommand());
    try {
      client.executeCommand(updateCommand, globalOptions);
      updateServerResponse.waitForExecutionToFinish();
    } finally {
      client.getEventManager().removeCVSListener(updateServerResponse);
      disconnect(client);
    }

    return updateServerResponse;
  }
コード例 #11
0
ファイル: CommitTest.java プロジェクト: Frlk/cvsclient
  /**
   * Client must checks conflicted files timestamps. Until it changes it should not commit the file
   * (it actually decides server by testing sent entry).
   *
   * <p>Uses fake PseudoCvsServer.
   */
  public void test36288() throws Exception {
    File tmpDir = TestKit.createTmpFolder("commitConflictTest");
    String protocolLog = new File(tmpDir, "protocol").getAbsolutePath();
    System.setProperty("cvsClientLog", protocolLog);
    System.out.println(protocolLog);

    // prepare working directory
    File CVSdir = new File(tmpDir, "CVS");
    CVSdir.mkdirs();
    File entries = new File(CVSdir, "Entries");
    OutputStream out = new FileOutputStream(entries);
    String dateString = "Thu Mar 24 15:14:27 2005";
    String data = "/conflict.txt/1.2/Result of merge+" + dateString + "//\nD";
    out.write(data.getBytes("utf8"));
    out.flush();
    out.close();

    File conflict_txt = new File(tmpDir, "conflict.txt");
    out = new FileOutputStream(conflict_txt);
    data =
        "AAA\n"
            + "BBB\n"
            + "<<<<<<< conflict.txt\n"
            + "YYY <= fix\n"
            + "=======\n"
            + "222 <= fix\n"
            + ">>>>>>> 1.2\n"
            + "DDD\n"
            + "EEE\n";
    out.write(data.getBytes("utf8"));
    out.flush();
    out.close();
    Date date = Entry.getLastModifiedDateFormatter().parse(dateString);
    conflict_txt.setLastModified(date.getTime());

    PseudoCvsServer cvss = new PseudoCvsServer("protocol/iz36288.in");

    File requestsLog = File.createTempFile("requests", null, tmpDir);
    cvss.logRequests(new FileOutputStream(requestsLog));
    Thread cvssThread = new Thread(cvss);
    cvssThread.start();
    String cvsRoot = cvss.getCvsRoot();

    File root = new File(CVSdir, "Root");
    out = new FileOutputStream(root);
    out.write(cvsRoot.getBytes("utf8"));
    out.flush();
    out.close();

    File repo = new File(CVSdir, "Repository");
    out = new FileOutputStream(repo);
    out.write("/cvs".getBytes("utf8"));
    out.flush();
    out.close();

    // commit command
    CVSRoot CvsRoot = CVSRoot.parse(cvsRoot);
    GlobalOptions gtx = new GlobalOptions();
    gtx.setCVSRoot(cvsRoot);
    Connection connection = new PServerConnection(CvsRoot);
    Client client = new Client(connection, new StandardAdminHandler());
    client.setLocalPath(tmpDir.getAbsolutePath());

    CommitCommand commit = new CommitCommand();
    File[] files = new File[] {new File(tmpDir, "conflict.txt")};
    commit.setFiles(files);

    client.executeCommand(commit, gtx);
    cvss.stop();
    cvssThread.join();

    // check test matching golden file (here critical line from iz36288.out)

    InputStream actual = new FileInputStream(requestsLog);
    LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(actual, "UTF-8"));
    boolean foundConflictLine = false;
    String line = lineReader.readLine();
    StringBuffer sb = new StringBuffer();
    while (foundConflictLine == false && line != null) {
      sb.append(line + "\n");
      foundConflictLine |= "Entry /conflict.txt/1.2/+=//".equals(line);
      line = lineReader.readLine();
    }
    assertTrue("Missing 'Entry /conflict.txt/1.2/+=//' in:\n" + sb.toString(), foundConflictLine);

    TestKit.deleteRecursively(tmpDir);
  }