Example #1
0
  /**
   * 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;
  }
Example #2
0
  /**
   * 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;
  }
Example #3
0
  /**
   * 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;
  }
Example #4
0
  /**
   * 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;
  }
Example #5
0
  @Override
  public void perform(final TaskListener listener)
      throws IOException, InterruptedException, CommandException, AuthenticationException {
    for (CvsRepository repository : revisionState.getModuleFiles().keySet()) {
      for (CvsFile file : revisionState.getModuleState(repository)) {
        AbstractCvs owner = parent.getParent();
        final Client cvsClient =
            owner.getCvsClient(repository, build.getEnvironment(listener), listener);
        final GlobalOptions globalOptions =
            owner.getGlobalOptions(repository, build.getEnvironment(listener));

        globalOptions.setCVSRoot(repository.getCvsRoot());

        RtagCommand rtagCommand = new RtagCommand();

        rtagCommand.setTag(tagName);
        rtagCommand.setTagByRevision(file.getRevision());
        rtagCommand.addModule(file.getName());
        rtagCommand.setMakeBranchTag(createBranch);
        rtagCommand.setOverrideExistingTag(moveTag);
        cvsClient
            .getEventManager()
            .addCVSListener(new BasicListener(listener.getLogger(), listener.getLogger()));

        try {
          cvsClient.executeCommand(rtagCommand, globalOptions);
        } catch (CommandAbortedException e) {
          e.printStackTrace(listener.error("The CVS rtag command was aborted"));
          throw e;
        } catch (CommandException e) {
          e.printStackTrace(listener.error("Error while trying to run CVS rtag command"));
          throw e;
        } catch (AuthenticationException e) {
          e.printStackTrace(
              listener.error("Authentication error while trying to run CVS rtag command"));
          throw e;
        } finally {
          try {
            cvsClient.getConnection().close();
          } catch (IOException ex) {
            listener.error("Could not close client connection: " + ex.getMessage());
          }
        }
      }
    }
  }
Example #6
0
  /**
   * 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;
  }
Example #7
0
  /**
   * 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;
  }
Example #8
0
  /**
   * 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;
  }
Example #9
0
  /**
   * 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;
  }
Example #10
0
  /**
   * 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);
  }