JDeveloper SCM API

oracle.ide.scm.util
Class SCMSimpleClient

java.lang.Object
  |
  +--oracle.ide.scm.SCMClientAdapter
        |
        +--oracle.ide.scm.util.SCMSimpleClient
All Implemented Interfaces:
oracle.ide.addin.Addin, SCMClient

public abstract class SCMSimpleClient
extends SCMClientAdapter

Simplification superclass for easier integration of a conventional and basic version control extension. Derive from this class if wishing to integrate a version control system fitting the 'reserved checkout model' within the minimum of fuss. Subclasses may implement any number of the provided operation methods, with code to process files.

If ascertaining whether to use make use of this utility in preference to the standard SCM API, consider the following points.

The concrete derivative of this class implements SCMClient and hence Addin, and should be deployed in the usual way.


Sample: RCS extension for JDeveloper.

This class is a code sample to illustrate the use of the SCM API with the framework's extension generalization utility, SCMSimpleClient. It provides a decent level of support for the Revision Control System, or RCS, a popular and fairly straightforward version system.

import oracle.ide.scm.SCMFile;
import oracle.ide.scm.util.SCMLogWriter;
import oracle.ide.scm.util.SCMEnvironmentVars;
import oracle.ide.scm.util.SCMSimpleClient;
import oracle.ide.scm.util.runner.SCMShellRunner;
import oracle.ide.scm.util.runner.SCMProcess;
import oracle.ide.scm.error.SCMException;
import oracle.ide.scm.error.SCMMinimalException;

import java.util.Iterator;
import java.util.Map;
import java.io.File;

public final class RCSClient extends SCMSimpleClient {
  private static final String RCS_ADMIN_DIR_NAME = "RCS";

  public RCSClient() {
    super();

    Map envvars = SCMEnvironmentVars.getInstance().getVariables();

    envvars.put("LOGNAME", System.getProperty("user.name"));
    envvars.put("TZ", "?");

    getShellRunner().setEnvpMap(envvars);
    getShellRunner().setTimeout(10000);
  }

  protected final String getClientExeNameSpi() {
    return "rcs";
  }

  protected final String getClientNameSpi() {
    return "Revision Control System (RCS, example)";
  }

  protected final String getClientShortNameSpi() {
    return "RCS";
  }

  protected boolean getUseCommentsSpi() {
    return true;
  }

  protected final boolean isVersionedSpi(SCMFile file) {
    return (getRCSFile(file) != null);
  }

  protected void doAddSpi(
     Iterator files, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    while (files.hasNext()) {
      SCMFile file = (SCMFile)files.next();

      File parent = file.getParent().toFile();
      File admin = new File(parent, RCS_ADMIN_DIR_NAME);

      if (! (admin.exists() || admin.mkdir())) {
        throw new SCMMinimalException(
          "Failed to create RCS administration directory."
        );
      }
      runRCSCommand("ci -u", file, "", runner);
    }
  }

  protected void doCheckinSpi(
     Iterator files, SCMShellRunner runner, SCMLogWriter log, String comment)
              throws SCMException {
    while (files.hasNext())
      runRCSCommand("ci -u", (SCMFile)files.next(), comment, runner);
  }

  protected void doCheckoutSpi(
     Iterator files, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    while (files.hasNext())
      runRCSCommand("co -f -l", (SCMFile)files.next(), null, runner);
  }

  protected void doUndoCheckoutSpi(
     Iterator files, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    while (files.hasNext())
      runRCSCommand("co -f -u", (SCMFile)files.next(), null, runner);
  }

  protected void doRemoveSpi(
     Iterator files, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    while (files.hasNext()) {
      SCMFile file = (SCMFile)files.next();
      File rcsfile = getRCSFile(file);

      if (rcsfile != null)
        rcsfile.delete();
    }
  }

  protected void viewComparisonSpi(
     SCMFile file, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    runRCSCommand("rcsdiff", file, null, runner);
  }

  protected void viewHistorySpi(
     SCMFile file, SCMShellRunner runner, SCMLogWriter log)
              throws SCMException {
    runRCSCommand("rlog", file, null, runner);
  }

  private final File getRCSFile(SCMFile file) {
    String path =
      RCS_ADMIN_DIR_NAME + File.separator + file.getFileName();
    File parent = file.getParent().toFile();

    File rcsfile = new File(parent, path);
    if (rcsfile.exists()) return rcsfile;

    rcsfile = new File(parent, path + ",v");
    return (rcsfile.exists() ? rcsfile : null);
  }

  private final SCMProcess runRCSCommand(String cmd,
                                         SCMFile file,
                                         String input,
                                         SCMShellRunner runner)
              throws SCMException {
    runner.setCommand(cmd + ' ' + file.getFileName());
    runner.setDirectory(file.getParent().toFile());

    SCMProcess process = runner.exec();

    if (input != null) {
      process.sendInputData(input);
      process.sendInputData(".");
    }
    return process.waitFor();
  }
}


Constructor Summary
SCMSimpleClient()
           
 
Method Summary
 boolean canShutdown()
           
 void detectClient()
          Does not perform any actions for client detection.
protected  void doAddSpi(java.util.Iterator files, SCMShellRunner runner, SCMLogWriter log)
          Adds the given files to version control through the client.
protected  void doCheckinSpi(java.util.Iterator files, SCMShellRunner runner, SCMLogWriter log, java.lang.String comment)
          Checks in the given files to version control through the client.
protected  void doCheckoutSpi(java.util.Iterator files, SCMShellRunner runner, SCMLogWriter log)
          Checks out the given files from version control through the client.
protected  void doRemoveSpi(java.util.Iterator files, SCMShellRunner runner, SCMLogWriter log)
          Removes the given files from version control through the client.
protected  void doUndoCheckoutSpi(java.util.Iterator files, SCMShellRunner runner, SCMLogWriter log)
          Undoes checkouts for the given versioned files through the client.
 void finishClient()
          Does not perform any actions for intermediate client finalization.
protected abstract  java.lang.String getClientExeNameSpi()
          Gets the filename of the executable client program.
protected abstract  java.lang.String getClientNameSpi()
          Gets the descriptive name for the version control client.
protected abstract  java.lang.String getClientShortNameSpi()
          Gets the short name for the version control client.
protected  SCMLogWriter getLogWriter()
          Gets the extension's reused log writer instance.
 SCMOperationSet getOperations()
          Gets an empty operation set for the client.
 java.lang.String getSCMName()
          Gets a user displayable name for the source control system this client represents.
 java.lang.String getSCMShortName()
          Gets a user displayable short name for the source control system this client represents.
protected  SCMShellRunner getShellRunner()
          Gets the extension's reused shell runner instance.
 SCMFileStatus getStatus(SCMFile file)
          Gets a null status for the file.
protected  boolean getUseCommentsSpi()
          Asks whether checkin comments are supported by this extension.
 float ideVersion()
           
 void initialize()
           
 boolean isSourceControlEnabled()
          Gets a verdict of false for source control enablement.
protected abstract  boolean isVersionedSpi(SCMFile file)
          Asks whether the given file is currently under version control.
 void prepareClient()
          Does not perform any actions for intermediate client initialization.
 void shutdown()
           
 float version()
           
protected  void viewComparisonSpi(SCMFile file, SCMShellRunner runner, SCMLogWriter log)
          View comparison information for the given file.
protected  void viewHistorySpi(SCMFile file, SCMShellRunner runner, SCMLogWriter log)
          View historical information for the given file.
 
Methods inherited from class oracle.ide.scm.SCMClientAdapter
getCheckoutLister, getFileSystem, getPropertyCustomizer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCMSimpleClient

public SCMSimpleClient()
Method Detail

version

public float version()

ideVersion

public float ideVersion()

canShutdown

public boolean canShutdown()

shutdown

public void shutdown()

initialize

public void initialize()

detectClient

public void detectClient()
                  throws SCMException
Description copied from class: SCMClientAdapter
Does not perform any actions for client detection.
Overrides:
detectClient in class SCMClientAdapter
Following copied from interface: oracle.ide.scm.SCMClient
Throws:
SCMException - if the client is absent or cannot be facilitated.

prepareClient

public void prepareClient()
                   throws SCMException
Description copied from class: SCMClientAdapter
Does not perform any actions for intermediate client initialization.
Overrides:
prepareClient in class SCMClientAdapter
Following copied from interface: oracle.ide.scm.SCMClient
Throws:
SCMException - if an error occurs in preparing the client for use.

getSCMName

public java.lang.String getSCMName()
Description copied from interface: SCMClient
Gets a user displayable name for the source control system this client represents.
Following copied from interface: oracle.ide.scm.SCMClient
Returns:
a localized string that represents the name of the source control system this client is for.

getSCMShortName

public java.lang.String getSCMShortName()
Description copied from interface: SCMClient
Gets a user displayable short name for the source control system this client represents. This should be under 10 characters long, and is used to display the name of the client to the user when space is at a premium.
Following copied from interface: oracle.ide.scm.SCMClient
Returns:
a short localized string.

getOperations

public SCMOperationSet getOperations()
                              throws SCMException
Description copied from class: SCMClientAdapter
Gets an empty operation set for the client.
Overrides:
getOperations in class SCMClientAdapter
Following copied from class: oracle.ide.scm.SCMClientAdapter
Returns:
a new operation set.

getStatus

public SCMFileStatus getStatus(SCMFile file)
                        throws SCMException
Description copied from class: SCMClientAdapter
Gets a null status for the file.
Overrides:
getStatus in class SCMClientAdapter
Following copied from class: oracle.ide.scm.SCMClientAdapter
Returns:
null.

isSourceControlEnabled

public boolean isSourceControlEnabled()
Description copied from class: SCMClientAdapter
Gets a verdict of false for source control enablement.
Overrides:
isSourceControlEnabled in class SCMClientAdapter
Following copied from class: oracle.ide.scm.SCMClientAdapter
Returns:
false.

finishClient

public void finishClient()
                  throws SCMException
Description copied from class: SCMClientAdapter
Does not perform any actions for intermediate client finalization.
Overrides:
finishClient in class SCMClientAdapter
Following copied from interface: oracle.ide.scm.SCMClient
Throws:
SCMException - if an error occurs in finishing the client session.

getClientExeNameSpi

protected abstract java.lang.String getClientExeNameSpi()
Gets the filename of the executable client program. This program must be found on the system's PATH before the extension may be used.
Returns:
the program's filename.

getClientNameSpi

protected abstract java.lang.String getClientNameSpi()
Gets the descriptive name for the version control client.
Returns:
the name of the source control system, ~ 10-25 characters.

getClientShortNameSpi

protected abstract java.lang.String getClientShortNameSpi()
Gets the short name for the version control client.
Returns:
the name of the source control system, < 10 characters.

isVersionedSpi

protected abstract boolean isVersionedSpi(SCMFile file)
Asks whether the given file is currently under version control.
Parameters:
file - the query file.
Returns:
a verdict on whether the file is versioned.

getUseCommentsSpi

protected boolean getUseCommentsSpi()
Asks whether checkin comments are supported by this extension. Override this method to return true if the feature is required.
Returns:
false, by default.

doAddSpi

protected void doAddSpi(java.util.Iterator files,
                        SCMShellRunner runner,
                        SCMLogWriter log)
                 throws SCMException
Adds the given files to version control through the client.
Parameters:
files - an iterator over files to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing files.

doCheckinSpi

protected void doCheckinSpi(java.util.Iterator files,
                            SCMShellRunner runner,
                            SCMLogWriter log,
                            java.lang.String comment)
                     throws SCMException
Checks in the given files to version control through the client.
Parameters:
files - an iterator over files to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
comment - a comment for the action, or null if not supported.
Throws:
SCMException - if an error occurred processing files.

doCheckoutSpi

protected void doCheckoutSpi(java.util.Iterator files,
                             SCMShellRunner runner,
                             SCMLogWriter log)
                      throws SCMException
Checks out the given files from version control through the client.
Parameters:
files - an iterator over files to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing files.

doUndoCheckoutSpi

protected void doUndoCheckoutSpi(java.util.Iterator files,
                                 SCMShellRunner runner,
                                 SCMLogWriter log)
                          throws SCMException
Undoes checkouts for the given versioned files through the client.
Parameters:
files - an iterator over files to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing files.

doRemoveSpi

protected void doRemoveSpi(java.util.Iterator files,
                           SCMShellRunner runner,
                           SCMLogWriter log)
                    throws SCMException
Removes the given files from version control through the client.
Parameters:
files - an iterator over files to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing files.

viewComparisonSpi

protected void viewComparisonSpi(SCMFile file,
                                 SCMShellRunner runner,
                                 SCMLogWriter log)
                          throws SCMException
View comparison information for the given file.
Parameters:
file - the versioned file to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing the file.

viewHistorySpi

protected void viewHistorySpi(SCMFile file,
                              SCMShellRunner runner,
                              SCMLogWriter log)
                       throws SCMException
View historical information for the given file.
Parameters:
file - the versioned file to process.
runner - a shell runner instance, for convenience.
log - the log writer instance.
Throws:
SCMException - if an error occurred processing the file.

getShellRunner

protected final SCMShellRunner getShellRunner()
Gets the extension's reused shell runner instance.
Returns:
the shell runner of the extension.

getLogWriter

protected final SCMLogWriter getLogWriter()
Gets the extension's reused log writer instance.
Returns:
the log writer of the extension.

Copyright © 2002 Oracle Corporation