HistoryGuru.java revision ebb9f739bca3bc9382340b628554b484e4837d6a
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* ident "@(#)HistoryGuru.java 1.2 06/02/22 SMI"
*/
/**
* The HistoryGuru is used to implement an transparent layer to the various
* source control systems.
*
* @author Chandan
*/
public class HistoryGuru {
/** The one and only instance of the HistoryGuru */
/** Unknown version control system for last file */
private final int UNKNOWN = 0;
/** RCS was used by the last file */
private final int RCS = 1;
/** SCCS was used by the last file */
private final int SCCS = 2;
/** Subversion was used by the last file */
private final int SVN = 3;
/** The last file was located in an "external" repository */
private final int EXTERNAL = 4;
/** Method used on the last file */
private int previousFile;
/** Is JavaSVN available? */
private boolean svnAvailable;
private boolean initializedSvn;
private boolean isSvnAvailable() {
if (!initializedSvn) {
initializedSvn = true;
try {
svnAvailable = true;
}
} catch (ClassNotFoundException ex) {
/* EMPTY */
;
} catch (UnsatisfiedLinkError ex) {
}
}
return svnAvailable;
}
/**
* Creates a new instance of HistoryGuru, and try to set the default
* source control system.
* @todo Set the revision system according to the users preferences, and call the various setups..
*/
private HistoryGuru() {
svnAvailable = false;
}
/**
* Get the one and only instance of the HistoryGuru
* @return the one and only HistoryGuru instance
*/
public static HistoryGuru getInstance() {
return instance;
}
/**
* Try to guess the correct history parser to use. Create an RCS, SCCS or Subversion
* HistoryParser if it looks like the file is managed by the appropriate
* revision control system.
*
* @param file The the file to get the history parser for
* @throws java.io.IOException If an error occurs while trying to access the filesystem
* @return A subclass of HistorParser that may be used to read out history
* data for a named file
*/
throws IOException
{
hpClass = RCSHistoryParser.class;
previousFile = RCS;
} else {
hpClass = SCCSHistoryParser.class;
previousFile = SCCS;
} else {
try {
hpClass = SubversionHistoryParser.class;
previousFile = SVN;
} catch (Exception e) {
;
}
} else {
}
}
}
}
}
return hpClass;
}
/**
* Get the appropriate history reader for the file specified by parent and basename.
* If configured, it will try to use the configured system. If the file is under another
* revision control system, it will try to guess the correct system.
*
* @param file The file to get the history reader for
* @throws java.io.IOException If an error occurs while trying to access the filesystem
* @return A HistorReader that may be used to read out history data for a named file
*/
switch (previousFile) {
case EXTERNAL :
}
break;
case SVN :
parser = SubversionHistoryParser.class;
}
break;
case RCS :
parser = RCSHistoryParser.class;
}
break;
case SCCS :
parser = SCCSHistoryParser.class;
}
break;
default:
;
}
// I did not find a match for the specified system. try to guess..
if (previousFile == EXTERNAL) {
} else {
}
}
try {
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
new IOException("Error while constructing HistoryReader");
throw ioe;
}
}
return null;
}
/**
* Get a named revision of the specified file. Try to guess out the source
* control system that is used.
*
* @param parent The directory containing the file
* @param basename The name of the file
* @param rev The revision to get
* @throws java.io.IOException If an error occurs while reading out the version
* @return An InputStream containing the named revision of the file.
*/
public InputStream guessGetRevision(String parent, String basename, String rev) throws IOException {
previousFile = RCS;
} else {
previousFile = RCS;
} else {
previousFile = SVN;
} else {
}
}
}
return in;
}
/**
* Get a named revision of the specified file.
* @param parent The directory containing the file
* @param basename The name of the file
* @param rev The revision to get
* @throws java.io.IOException If an error occurs while reading out the version
* @return An InputStream containing the named revision of the file.
*/
switch (previousFile) {
case RCS :
}
break;
case SCCS :
}
break;
case SVN :
}
break;
case EXTERNAL :
break;
default:
;
}
}
return in;
}
/**
* Does this directory contain files with source control information?
* @param parent The name of the directory
* @return true if the files in this directory have associated revision history
*/
boolean ret = false;
ret = true;
}
return ret;
}
try{
int c;
}
}
hr.getAuthor() + "\nLOG = " + hr.getComment() + "\nACTV = " + hr.isActive() + "\n-------------------");
}
} catch (Exception e) {
e.printStackTrace();
}
}
// Check if this directory contain a file named .hg
try {
addExternalRepository(rep, s);
return ;
} catch (IOException exp) {
System.err.println("Failed to get canonical path for " + files[ii].getName() + ": " + exp.getMessage());
}
}
}
// Nope, search it's sub-dirs
}
}
}
}
if (r != null) {
ret = r;
break;
}
}
return ret;
}
}
return ret;
}
}
return ret;
}
}