HistoryGuru.java revision 82a1601128d06fe280a89464faa0b1bba419e171
/*
* 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
*/
{
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 <code>HistoryParser</code> to use for the specified file.
*/
switch (previousFile) {
case EXTERNAL:
}
break;
case SVN:
parser = SubversionHistoryParser.class;
}
break;
case RCS:
parser = RCSHistoryParser.class;
}
break;
case SCCS:
parser = SCCSHistoryParser.class;
}
break;
}
// I did not find a match for the specified system. try to guess..
}
return parser;
}
/**
* Annotate the specified revision of a file.
*
* @param file the file to annotate
* @param rev the revision to annotate (<code>null</code> means BASE)
* @return file annotation, or <code>null</code> if the
* <code>HistoryParser</code> does not support annotation
*/
if (parserClass != null) {
}
return null;
}
/**
* 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
*/
if (file.isDirectory()) {
return getDirectoryHistoryReader(file);
}
try {
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
new IOException("Error while constructing HistoryReader");
throw ioe;
}
}
return null;
}
}
// I did not find a match for the specified system. Use the default directory reader
parser = DirectoryHistoryParser.class;
}
try {
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
e.printStackTrace();
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.
*/
private 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;
}
/**
* Check if we can annotate the specified file.
*
* @param file the file to check
* @return <code>true</code> if the file is under version control and the
* version control system supports annotation
*/
if (file.isDirectory()) {
return false;
}
return false;
}
try {
} catch (Exception e) {
return false;
}
}
try{
int c;
}
}
hr.getAuthor() + "\nLOG = " + hr.getComment() + "\nACTV = " + hr.isActive() + "\n-------------------");
}
if (annotation == null) {
} else {
annotation.getAuthor(i));
}
}
} catch (Exception e) {
"\nUsage: HistoryGuru file [annotate-rev]");
e.printStackTrace();
}
}
// Check if this directory contain a file named .hg
try {
return ;
} catch (IOException exp) {
System.err.println("Failed to get canonical path for " + files[ii].getName() + ": " + exp.getMessage());
}
return;
}
}
}
// Nope, search it's sub-dirs
}
}
}
private void addExternalRepository(ExternalRepository rep, String path, Map<String, ExternalRepository> repos) {
}
}
if (r != null) {
ret = r;
break;
}
}
return ret;
}
}
return ret;
}
}
return ret;
}
}