Browse Source

checkstyle changes

Obtained from: Kevin Jackson


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277126 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 20 years ago
parent
commit
a0ba302efe
2 changed files with 124 additions and 78 deletions
  1. +64
    -23
      src/main/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java
  2. +60
    -55
      src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java

+ 64
- 23
src/main/org/apache/tools/ant/taskdefs/cvslib/CVSEntry.java View File

@@ -24,46 +24,87 @@ import java.util.Vector;
* *
* @version $Revision$ $Date$ * @version $Revision$ $Date$
*/ */
class CVSEntry {
private Date m_date;
private String m_author;
private final String m_comment;
private final Vector m_files = new Vector();
public class CVSEntry {
private Date date;
private String author;
private final String comment;
private final Vector files = new Vector();


public CVSEntry(Date date, String author, String comment) {
m_date = date;
m_author = author;
m_comment = comment;
/**
* Creates a new instance of a CVSEntry
* @param date the date
* @param author the author
* @param comment a comment to be added to the revision
*/
public CVSEntry(final Date date, final String author, final String comment) {
this.date = date;
this.author = author;
this.comment = comment;
} }


public void addFile(String file, String revision) {
m_files.addElement(new RCSFile(file, revision));
/**
* Adds a file to the CVSEntry
* @param file the file to add
* @param revision the revision
*/
public void addFile(final String file, final String revision) {
files.addElement(new RCSFile(file, revision));
} }


public void addFile(String file, String revision, String previousRevision) {
m_files.addElement(new RCSFile(file, revision, previousRevision));
/**
* Adds a file to the CVSEntry
* @param file the file to add
* @param revision the revision
* @param previousRevision the previous revision
*/
public void addFile(final String file, final String revision, final String previousRevision) {
files.addElement(new RCSFile(file, revision, previousRevision));
} }


Date getDate() {
return m_date;
/**
* Gets the date of the CVSEntry
* @return the date
*/
public Date getDate() {
return date;
} }


void setAuthor(final String author) {
m_author = author;
/**
* Sets the author of the CVSEntry
* @param author the author
*/
public void setAuthor(final String author) {
this.author = author;
} }


String getAuthor() {
return m_author;
/**
* Gets the author of the CVSEntry
* @return the author
*/
public String getAuthor() {
return author;
} }


String getComment() {
return m_comment;
/**
* Gets the comment for the CVSEntry
* @return the comment
*/
public String getComment() {
return comment;
} }


Vector getFiles() {
return m_files;
/**
* Gets the files in this CVSEntry
* @return the files
*/
public Vector getFiles() {
return files;
} }


/**
* Gets a String containing author, date, files and comment
* @return a string representation of this CVSEntry
*/
public String toString() { public String toString() {
return getAuthor() + "\n" + getDate() + "\n" + getFiles() + "\n" return getAuthor() + "\n" + getDate() + "\n" + getFiles() + "\n"
+ getComment(); + getComment();


+ 60
- 55
src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java View File

@@ -37,35 +37,35 @@ class ChangeLogParser {
private static final int GET_PREVIOUS_REV = 5; private static final int GET_PREVIOUS_REV = 5;


/** input format for dates read in from cvs log */ /** input format for dates read in from cvs log */
private static final SimpleDateFormat c_inputDate
private static final SimpleDateFormat INPUT_DATE
= new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");


static { static {
TimeZone utc = TimeZone.getTimeZone("UTC"); TimeZone utc = TimeZone.getTimeZone("UTC");
c_inputDate.setTimeZone(utc);
INPUT_DATE.setTimeZone(utc);
} }


//The following is data used while processing stdout of CVS command //The following is data used while processing stdout of CVS command
private String m_file;
private String m_date;
private String m_author;
private String m_comment;
private String m_revision;
private String m_previousRevision;
private String file;
private String date;
private String author;
private String comment;
private String revision;
private String previousRevision;


private int m_status = GET_FILE;
private int status = GET_FILE;


/** rcs entries */ /** rcs entries */
private final Hashtable m_entries = new Hashtable();
private final Hashtable entries = new Hashtable();


/** /**
* Get a list of rcs entries as an array. * Get a list of rcs entries as an array.
* *
* @return a list of rcs entries as an array * @return a list of rcs entries as an array
*/ */
CVSEntry[] getEntrySetAsArray() {
final CVSEntry[] array = new CVSEntry[ m_entries.size() ];
Enumeration e = m_entries.elements();
public CVSEntry[] getEntrySetAsArray() {
final CVSEntry[] array = new CVSEntry[ entries.size() ];
Enumeration e = entries.elements();
int i = 0; int i = 0;
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
array[i++] = (CVSEntry) e.nextElement(); array[i++] = (CVSEntry) e.nextElement();
@@ -76,9 +76,10 @@ class ChangeLogParser {
/** /**
* Receive notification about the process writing * Receive notification about the process writing
* to standard output. * to standard output.
* @param line the line to process
*/ */
public void stdout(final String line) { public void stdout(final String line) {
switch(m_status) {
switch(status) {
case GET_FILE: case GET_FILE:
// make sure attributes are reset when // make sure attributes are reset when
// working on a 'new' file. // working on a 'new' file.
@@ -100,6 +101,10 @@ class ChangeLogParser {
case GET_PREVIOUS_REV: case GET_PREVIOUS_REV:
processGetPreviousRevision(line); processGetPreviousRevision(line);
break; break;

default:
// Do nothing
break;
} }
} }


@@ -110,114 +115,115 @@ class ChangeLogParser {
*/ */
private void processComment(final String line) { private void processComment(final String line) {
final String lineSeparator = System.getProperty("line.separator"); final String lineSeparator = System.getProperty("line.separator");
if (line.equals("=============================================================================")) {
if (line.equals(
"=============================================================================")) {
//We have ended changelog for that particular file //We have ended changelog for that particular file
//so we can save it //so we can save it
final int end final int end
= m_comment.length() - lineSeparator.length(); //was -1
m_comment = m_comment.substring(0, end);
= comment.length() - lineSeparator.length(); //was -1
comment = comment.substring(0, end);
saveEntry(); saveEntry();
m_status = GET_FILE;
status = GET_FILE;
} else if (line.equals("----------------------------")) { } else if (line.equals("----------------------------")) {
final int end final int end
= m_comment.length() - lineSeparator.length(); //was -1
m_comment = m_comment.substring(0, end);
m_status = GET_PREVIOUS_REV;
= comment.length() - lineSeparator.length(); //was -1
comment = comment.substring(0, end);
status = GET_PREVIOUS_REV;
} else { } else {
m_comment += line + lineSeparator;
comment += line + lineSeparator;
} }
} }


/** /**
* Process a line while in "GET_FILE" state. * Process a line while in "GET_FILE" state.
* *
* @param line the line
* @param line the line to process
*/ */
private void processFile(final String line) { private void processFile(final String line) {
if (line.startsWith("Working file:")) { if (line.startsWith("Working file:")) {
m_file = line.substring(14, line.length());
m_status = GET_REVISION;
file = line.substring(14, line.length());
status = GET_REVISION;
} }
} }


/** /**
* Process a line while in "REVISION" state. * Process a line while in "REVISION" state.
* *
* @param line the line
* @param line the line to process
*/ */
private void processRevision(final String line) { private void processRevision(final String line) {
if (line.startsWith("revision")) { if (line.startsWith("revision")) {
m_revision = line.substring(9);
m_status = GET_DATE;
revision = line.substring(9);
status = GET_DATE;
} else if (line.startsWith("======")) { } else if (line.startsWith("======")) {
//There was no revisions in this changelog //There was no revisions in this changelog
//entry so lets move unto next file //entry so lets move unto next file
m_status = GET_FILE;
status = GET_FILE;
} }
} }


/** /**
* Process a line while in "DATE" state. * Process a line while in "DATE" state.
* *
* @param line the line
* @param line the line to process
*/ */
private void processDate(final String line) { private void processDate(final String line) {
if (line.startsWith("date:")) { if (line.startsWith("date:")) {
m_date = line.substring(6, 25);
date = line.substring(6, 25);
String lineData = line.substring(line.indexOf(";") + 1); String lineData = line.substring(line.indexOf(";") + 1);
m_author = lineData.substring(10, lineData.indexOf(";"));
author = lineData.substring(10, lineData.indexOf(";"));


m_status = GET_COMMENT;
status = GET_COMMENT;


//Reset comment to empty here as we can accumulate multiple lines //Reset comment to empty here as we can accumulate multiple lines
//in the processComment method //in the processComment method
m_comment = "";
comment = "";
} }
} }


/** /**
* Process a line while in "GET_PREVIOUS_REVISION" state. * Process a line while in "GET_PREVIOUS_REVISION" state.
* *
* @param line the line
* @param line the line to process
*/ */
private void processGetPreviousRevision(final String line) { private void processGetPreviousRevision(final String line) {
if (!line.startsWith("revision")) { if (!line.startsWith("revision")) {
throw new IllegalStateException("Unexpected line from CVS: " throw new IllegalStateException("Unexpected line from CVS: "
+ line); + line);
} }
m_previousRevision = line.substring(9);
previousRevision = line.substring(9);


saveEntry(); saveEntry();


m_revision = m_previousRevision;
m_status = GET_DATE;
revision = previousRevision;
status = GET_DATE;
} }


/** /**
* Utility method that saves the current entry. * Utility method that saves the current entry.
*/ */
private void saveEntry() { private void saveEntry() {
final String entryKey = m_date + m_author + m_comment;
final String entryKey = date + author + comment;
CVSEntry entry; CVSEntry entry;
if (!m_entries.containsKey(entryKey)) {
entry = new CVSEntry(parseDate(m_date), m_author, m_comment);
m_entries.put(entryKey, entry);
if (!entries.containsKey(entryKey)) {
entry = new CVSEntry(parseDate(date), author, comment);
entries.put(entryKey, entry);
} else { } else {
entry = (CVSEntry) m_entries.get(entryKey);
entry = (CVSEntry) entries.get(entryKey);
} }


entry.addFile(m_file, m_revision, m_previousRevision);
entry.addFile(file, revision, previousRevision);
} }


/** /**
* Parse date out from expected format. * Parse date out from expected format.
* *
* @param date the string holding dat
* @param date the string holding date
* @return the date object or null if unknown date format * @return the date object or null if unknown date format
*/ */
private Date parseDate(final String date) { private Date parseDate(final String date) {
try { try {
return c_inputDate.parse(date);
return INPUT_DATE.parse(date);
} catch (ParseException e) { } catch (ParseException e) {
//final String message = REZ.getString( "changelog.bat-date.error", date ); //final String message = REZ.getString( "changelog.bat-date.error", date );
//getContext().error( message ); //getContext().error( message );
@@ -226,15 +232,14 @@ class ChangeLogParser {
} }


/** /**
* reset all internal attributes except status.
* Reset all internal attributes except status.
*/ */
private void reset() {
m_file = null;
m_date = null;
m_author = null;
m_comment = null;
m_revision = null;
m_previousRevision = null;
public void reset() {
this.file = null;
this.date = null;
this.author = null;
this.comment = null;
this.revision = null;
this.previousRevision = null;
} }

} }

Loading…
Cancel
Save