Added logging information as to what command line was being run

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@112840 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
bwalding
2003-02-05 07:42:56 +00:00
parent 450178cfec
commit 1ab41a850c

View File

@@ -86,256 +86,267 @@ import org.apache.tools.ant.types.Commandline;
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @author <a href="mailto:pete-apache-dev@kazmier.com">Pete Kazmier</a>
* @version
* $Id: AbstractChangeLogGenerator.java,v 1.1 2003/01/24 03:44:50 jvanzyl Exp $
* $Id: AbstractChangeLogGenerator.java,v 1.2 2003/02/05 07:42:56 bwalding Exp $
*/
public abstract class AbstractChangeLogGenerator
implements ChangeLogGenerator, ExecuteStreamHandler
public abstract class AbstractChangeLogGenerator implements ChangeLogGenerator, ExecuteStreamHandler
{
/**
* The working directory.
*/
protected File base;
/**
* The working directory.
*/
protected File base;
/**
* Reference to the enclosing ChangeLog instance - used to obtain
* any necessary configuration information.
*/
protected ChangeLog changeLogExecutor;
/**
* The parser that takes the log output and transforms it into a
* collection of ChangeLogEntry's.
*/
protected ChangeLogParser clParser;
/**
* Reference to the enclosing ChangeLog instance - used to obtain
* any necessary configuration information.
*/
protected ChangeLog changeLogExecutor;
/** The connection string from the project */
private String connection;
/**
* The date range.
*/
protected String dateRange;
/**
* The parser that takes the log output and transforms it into a
* collection of ChangeLogEntry's.
*/
protected ChangeLogParser clParser;
/**
* The collection of ChangeLogEntry's returned from clParser.
*/
protected Collection entries;
/** The connection string from the project */
private String connection;
/**
* Stderr stream eater.
*/
protected AsyncStreamReader errorReader;
/**
* The date range.
*/
protected String dateRange;
/**
* The scm process input stream.
*/
protected InputStream in;
/**
* The collection of ChangeLogEntry's returned from clParser.
*/
protected Collection entries;
/** Log */
private static final Log LOG = LogFactory.getLog(
AbstractChangeLogGenerator.class);
/**
* Stderr stream eater.
*/
protected AsyncStreamReader errorReader;
/**
* Initialize the generator from the changelog controller.
*
* @param changeLog The invoking controller (useful for logging)
* @see ChangeLogGenerator#init(ChangeLog)
*/
public void init(ChangeLog changeLog)
/**
* The scm process input stream.
*/
protected InputStream in;
/** Log */
private static final Log LOG = LogFactory.getLog(AbstractChangeLogGenerator.class);
/**
* Initialize the generator from the changelog controller.
*
* @param changeLog The invoking controller (useful for logging)
* @see ChangeLogGenerator#init(ChangeLog)
*/
public void init(ChangeLog changeLog)
{
changeLogExecutor = changeLog;
base = changeLogExecutor.getBasedir();
// This lets the user 'not' set a limit on the log command. We
// need this cuz Subversion doesn't currently support date
// commands on web-based repositories, so it would be nice to
// let the user still use the changelog plugin.
if (changeLogExecutor.getRange() != null && changeLogExecutor.getRange().length() != 0)
{
changeLogExecutor = changeLog;
base = changeLogExecutor.getBasedir();
// This lets the user 'not' set a limit on the log command. We
// need this cuz Subversion doesn't currently support date
// commands on web-based repositories, so it would be nice to
// let the user still use the changelog plugin.
if (changeLogExecutor.getRange() != null &&
changeLogExecutor.getRange().length() != 0)
{
setDateRange(changeLogExecutor.getRange());
}
setConnection(changeLogExecutor.getRepositoryConnection());
setDateRange(changeLogExecutor.getRange());
}
/**
* Set the dateRange member based on the number of days obtained
* from the ChangeLog.
*
* @param numDaysString The number of days of log output to
* generate.
*/
protected void setDateRange(String numDaysString)
setConnection(changeLogExecutor.getRepositoryConnection());
}
/**
* Set the dateRange member based on the number of days obtained
* from the ChangeLog.
*
* @param numDaysString The number of days of log output to
* generate.
*/
protected void setDateRange(String numDaysString)
{
int days = Integer.parseInt(numDaysString);
Date before = new Date(System.currentTimeMillis() - (long) days * 24 * 60 * 60 * 1000);
Date to = new Date(System.currentTimeMillis() + (long) 1 * 24 * 60 * 60 * 1000);
dateRange = getScmDateArgument(before, to);
}
/**
* Execute scm client driving the given parser.
*
* @param parser A {@link ChangeLogParser parser} to process the scm
* output.
* @return A collection of {@link ChangeLogEntry entries} parsed from
* the scm output.
* @throws IOException When there are issues executing scm.
* @see ChangeLogGenerator#getEntries(ChangeLogParser)
*/
public Collection getEntries(ChangeLogParser parser) throws IOException
{
if (parser == null)
{
int days = Integer.parseInt(numDaysString);
Date before = new Date(
System.currentTimeMillis() - (long) days * 24 * 60 * 60 * 1000);
Date to = new Date(
System.currentTimeMillis() + (long) 1 * 24 * 60 * 60 * 1000);
dateRange = getScmDateArgument(before, to);
throw new NullPointerException("parser cannot be null");
}
/**
* Execute scm client driving the given parser.
*
* @param parser A {@link ChangeLogParser parser} to process the scm
* output.
* @return A collection of {@link ChangeLogEntry entries} parsed from
* the scm output.
* @throws IOException When there are issues executing scm.
* @see ChangeLogGenerator#getEntries(ChangeLogParser)
*/
public Collection getEntries(ChangeLogParser parser) throws IOException
if (base == null)
{
if (parser == null)
{
throw new NullPointerException("parser cannot be null");
}
if (base == null)
{
throw new NullPointerException("basedir must be set");
}
if (!base.exists())
{
throw new FileNotFoundException(
"Cannot find base dir " + base.getAbsolutePath());
}
clParser = parser;
try
{
Execute exe = new Execute(this);
exe.setCommandline(getScmLogCommand().getCommandline());
exe.setWorkingDirectory(base);
exe.execute();
// log messages from stderr
String errors = errorReader.toString().trim();
if (errors.length() > 0)
{
LOG.error(errors);
}
}
catch (IOException ioe)
{
handleParserException(ioe);
}
return entries;
throw new NullPointerException("basedir must be set");
}
/**
* Handle ChangeLogParser IOExceptions. The default implementation
* just throws the exception again.
*
* @param ioe The IOException thrown.
* @throws IOException If the handler doesn't wish to handle the
* exception (the default behavior).
*/
protected void handleParserException(IOException ioe)
throws IOException
if (!base.exists())
{
throw ioe;
throw new FileNotFoundException("Cannot find base dir " + base.getAbsolutePath());
}
/**
* Clean up any generated resources for this run.
*
* @see ChangeLogGenerator#cleanup()
*/
public void cleanup()
clParser = parser;
try
{
Execute exe = new Execute(this);
exe.setCommandline(getScmLogCommand().getCommandline());
exe.setWorkingDirectory(base);
logExecute(exe, base);
exe.execute();
// log messages from stderr
String errors = errorReader.toString().trim();
if (errors.length() > 0)
{
LOG.error(errors);
}
}
catch (IOException ioe)
{
handleParserException(ioe);
}
/**
* Constructs the appropriate command line to execute the scm's
* log command. This method must be implemented by subclasses.
*
* @return The command line to be executed.
*/
protected abstract Commandline getScmLogCommand();
return entries;
}
/**
* Construct the command-line argument that is passed to the scm
* client to specify the appropriate date range.
*
* @param before The starting point.
* @param to The ending point.
* @return A string that can be used to specify a date to a scm
* system.
*/
protected abstract String getScmDateArgument(Date before, Date to);
/**
* Handle ChangeLogParser IOExceptions. The default implementation
* just throws the exception again.
*
* @param ioe The IOException thrown.
* @throws IOException If the handler doesn't wish to handle the
* exception (the default behavior).
*/
protected void handleParserException(IOException ioe) throws IOException
{
throw ioe;
}
/**
* Stop the process - currently unimplemented
*/
public void stop()
{
}
/**
* Clean up any generated resources for this run.
*
* @see ChangeLogGenerator#cleanup()
*/
public void cleanup()
{
}
/**
* Set the input stream for the scm process.
* @param os An {@link java.io.OutputStream}
*/
public void setProcessInputStream(OutputStream os)
{
}
/**
* Constructs the appropriate command line to execute the scm's
* log command. This method must be implemented by subclasses.
*
* @return The command line to be executed.
*/
protected abstract Commandline getScmLogCommand();
/**
* Set the error stream for reading from scm log. This stream will
* be read on a separate thread.
*
* @param is An {@link java.io.InputStream}
*/
public void setProcessErrorStream(InputStream is)
{
errorReader = new AsyncStreamReader(is);
}
/**
* Construct the command-line argument that is passed to the scm
* client to specify the appropriate date range.
*
* @param before The starting point.
* @param to The ending point.
* @return A string that can be used to specify a date to a scm
* system.
*/
protected abstract String getScmDateArgument(Date before, Date to);
/**
* Set the input stream used to read from scm log.
*
* @param is A stream of scm log output to be read from
*/
public void setProcessOutputStream(InputStream is)
{
in = is;
}
/**
* Stop the process - currently unimplemented
*/
public void stop()
{
}
/**
* Start read from the scm log.
*
* @throws IOException When there are errors reading from the
* streams previously provided
*/
public void start() throws IOException
{
errorReader.start();
entries = clParser.parse(in);
}
/**
* Returns the connection.
* @return String
*/
public String getConnection()
{
return connection;
}
/**
* Set the input stream for the scm process.
* @param os An {@link java.io.OutputStream}
*/
public void setProcessInputStream(OutputStream os)
{
}
/**
* Sets the connection.
* @param connection The connection to set
*/
public void setConnection(String connection)
/**
* Set the error stream for reading from scm log. This stream will
* be read on a separate thread.
*
* @param is An {@link java.io.InputStream}
*/
public void setProcessErrorStream(InputStream is)
{
errorReader = new AsyncStreamReader(is);
}
/**
* Set the input stream used to read from scm log.
*
* @param is A stream of scm log output to be read from
*/
public void setProcessOutputStream(InputStream is)
{
in = is;
}
/**
* Start read from the scm log.
*
* @throws IOException When there are errors reading from the
* streams previously provided
*/
public void start() throws IOException
{
errorReader.start();
entries = clParser.parse(in);
}
/**
* Returns the connection.
* @return String
*/
public String getConnection()
{
return connection;
}
/**
* Sets the connection.
* @param connection The connection to set
*/
public void setConnection(String connection)
{
this.connection = connection;
}
/**
* Logs the pertinent details to the logging system (info level)
* @param exe The object to log
* @param base The working directory
*/
public static void logExecute(Execute exe, File base)
{
String c[] = exe.getCommandline();
LOG.info("SCM Working Directory: " + base);
for (int i = 0; i < c.length; i++)
{
this.connection = connection;
String string = c[i];
LOG.info("SCM Command Line[0]: " + string);
}
}
}