From e424286e610e70732317bf6aa937abf1f0ea975f Mon Sep 17 00:00:00 2001 From: ltheussl Date: Thu, 19 Jan 2006 19:29:01 +0000 Subject: [PATCH] PR: MPCHANGELOG-80 Submitted by: Christoph Jerolimov Add MKS SI support git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@370578 13f79535-47bb-0310-9956-ffa450edef68 --- changelog/project.xml | 3 + .../org/apache/maven/changelog/ChangeLog.java | 1 + .../maven/mkslib/MksChangeLogFactory.java | 52 ++++ .../maven/mkslib/MksChangeLogGenerator.java | 79 +++++ .../maven/mkslib/MksChangeLogParser.java | 286 ++++++++++++++++++ .../src/test-resources/mkslib/mkslog.txt | 56 ++++ .../maven/cvslib/CvsConnectionTest.java | 2 - .../maven/mkslib/MksChangeLogParserTest.java | 91 ++++++ .../org/apache/maven/util/RepositoryTest.java | 6 +- changelog/xdocs/changes.xml | 1 + changelog/xdocs/index.xml | 4 +- changelog/xdocs/properties.xml | 2 + 12 files changed, 576 insertions(+), 7 deletions(-) create mode 100644 changelog/src/main/org/apache/maven/mkslib/MksChangeLogFactory.java create mode 100644 changelog/src/main/org/apache/maven/mkslib/MksChangeLogGenerator.java create mode 100644 changelog/src/main/org/apache/maven/mkslib/MksChangeLogParser.java create mode 100644 changelog/src/test-resources/mkslib/mkslog.txt create mode 100644 changelog/src/test/org/apache/maven/mkslib/MksChangeLogParserTest.java diff --git a/changelog/project.xml b/changelog/project.xml index 1532facf..d4c24997 100644 --- a/changelog/project.xml +++ b/changelog/project.xml @@ -84,6 +84,9 @@ David Jackman + + Christoph Jerolimov + diff --git a/changelog/src/main/org/apache/maven/changelog/ChangeLog.java b/changelog/src/main/org/apache/maven/changelog/ChangeLog.java index 344c621c..a51d5d6f 100644 --- a/changelog/src/main/org/apache/maven/changelog/ChangeLog.java +++ b/changelog/src/main/org/apache/maven/changelog/ChangeLog.java @@ -72,6 +72,7 @@ public class ChangeLog FACTORIES.put( "starteam", "org.apache.maven.starteamlib.StarteamChangeLogFactory" ); FACTORIES.put( "vss", "org.apache.maven.vsslib.VssChangeLogFactory" ); + FACTORIES.put( "mks", "org.apache.maven.mkslib.MksChangeLogFactory" ); } /** Used to specify whether to build the log from a range, absolute date, or tag. */ diff --git a/changelog/src/main/org/apache/maven/mkslib/MksChangeLogFactory.java b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogFactory.java new file mode 100644 index 00000000..1fc0175b --- /dev/null +++ b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogFactory.java @@ -0,0 +1,52 @@ +package org.apache.maven.mkslib; + +/* ==================================================================== + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + + +import org.apache.maven.changelog.ChangeLogFactory; +import org.apache.maven.changelog.ChangeLogGenerator; +import org.apache.maven.changelog.ChangeLogParser; + +/** + * Provides mks ChangeLogGenerator and ChangeLogParser. + * + * @author Christoph Jerolimov + * @version $Id$ + */ +public class MksChangeLogFactory implements ChangeLogFactory +{ + /** + * Create a MKS specific ChangeLogGenerator. + * + * @return a MKS specific ChangeLogGenerator. + */ + public ChangeLogGenerator createGenerator() + { + return new MksChangeLogGenerator(); + } + + /** + * Create a MKS specific ChangeLogParser. + * + * @return a MKS specific ChangeLogParser. + */ + public ChangeLogParser createParser() + { + return new MksChangeLogParser(); + } +} diff --git a/changelog/src/main/org/apache/maven/mkslib/MksChangeLogGenerator.java b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogGenerator.java new file mode 100644 index 00000000..cb1890c9 --- /dev/null +++ b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogGenerator.java @@ -0,0 +1,79 @@ +package org.apache.maven.mkslib; + +/* ==================================================================== + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + + +import java.util.Date; + +import org.apache.maven.changelog.AbstractChangeLogGenerator; +import org.apache.maven.util.RepositoryUtils; +import org.apache.tools.ant.types.Commandline; + +/** + * A log-generator for the mks commandline tool. + * + * It supports an input file with + * + * @author Christoph Jerolimov + * @version $Id$ + */ +public class MksChangeLogGenerator extends AbstractChangeLogGenerator +{ + + /** + * @return the mks command line to be executed. + */ + protected Commandline getScmLogCommand() + { + String[] tokens = + RepositoryUtils.splitSCMConnection( getConnection() ); + + Commandline commandline = new Commandline(); + + commandline.setExecutable( tokens[2] ); + + for ( int i = 3; i < tokens.length; i++ ) + { + commandline.createArgument().setValue( tokens[i] ); + } + + return commandline; + } + + /** + * Construct the MKS command-line argument that is used to specify the + * appropriate date range. Currently always returns null. + * + * @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 String getScmDateArgument( Date before, Date to ) + { + return null; + } + + /** + * Currently always returns null. + * @see AbstractChangeLogGenerator#getScmTagArgument(String, String) + */ + protected String getScmTagArgument( String tagStart, String tagEnd ) + { + return null; + } +} diff --git a/changelog/src/main/org/apache/maven/mkslib/MksChangeLogParser.java b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogParser.java new file mode 100644 index 00000000..dde6512c --- /dev/null +++ b/changelog/src/main/org/apache/maven/mkslib/MksChangeLogParser.java @@ -0,0 +1,286 @@ +package org.apache.maven.mkslib; + +/* ==================================================================== + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +import java.text.ParseException; +import java.text.SimpleDateFormat; + +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Map; +import java.util.TreeMap; + +import org.apache.maven.changelog.ChangeLog; +import org.apache.maven.changelog.ChangeLogEntry; +import org.apache.maven.changelog.ChangeLogFile; +import org.apache.maven.changelog.ChangeLogParser; + +/** + * This class parse mks log output. + * + * @author Christoph Jerolimov + * @version $Id$ + */ +public class MksChangeLogParser implements ChangeLogParser +{ + /** + * This date/time formatter will be uses to parse a mks date. + */ + private static final SimpleDateFormat MKS_TIMESTAMP_FORMAT = + new SimpleDateFormat( "MMM d, yyyy - h:mm a" ); + + /** + * Custom date/time formatter. Rounds ChangeLogEntry times to the nearest + * minute. + */ + private static final SimpleDateFormat ENTRY_KEY_TIMESTAMP_FORMAT = + new SimpleDateFormat( "yyyyMMddHHmm" ); + + /** expecting file name */ + private static final int GET_FILE_NAME = 1; + + /** expecting file revision */ + private static final int GET_FILE_REVISION = 2; + + /** expecting entry revision */ + private static final int WAITFOR_ENTRY_REVISION = 3; + + /** expecting file revision */ + private static final int GET_ENTRY_INFO = 4; + + /** expecting file revision */ + private static final int GET_ENTRY_COMMENT = 5; + + /** rcs entries, in reverse (date, time, author, comment) order */ + private Map entries = new TreeMap( Collections.reverseOrder() ); + + /** current status of the parser */ + private int status = GET_FILE_NAME; + + /** current changelog entry */ + private ChangeLogEntry changeLogEntry; + + /** current changelog file */ + private ChangeLogFile changeLogFile; + + public void init( ChangeLog changeLog ) + { + } + + public void cleanup() + { + } + + public void setDateFormatInFile( String dateFormat ) + { + } + + public Collection parse( InputStream in ) + throws IOException + { + try + { + BufferedReader reader = + new BufferedReader( new InputStreamReader( in ) ); + + String line; + + while ( ( line = reader.readLine() ) != null ) + { + if ( line.startsWith( + "========================================" ) ) + { + status = GET_FILE_NAME; + } + + switch ( status ) + { + case GET_FILE_NAME : + addEntry(); + processGetFileName( line ); + + break; + + case GET_FILE_REVISION : + processGetFileRevision( line ); + + break; + + case WAITFOR_ENTRY_REVISION : + processWaitForEntryRevision( line ); + + break; + + case GET_ENTRY_INFO : + processGetEntryInfo( line ); + + break; + + case GET_ENTRY_COMMENT : + processGetEntryComment( line ); + + break; + + default : + + // wait for next entry + break; + } + } + + addEntry(); + } + catch ( RuntimeException e ) + { + e.printStackTrace(); + throw e; + } + catch ( IOException e ) + { + e.printStackTrace(); + throw e; + } + + return entries.values(); + } + + protected void processGetFileName( String line ) + { + if ( line.startsWith( "member name: " ) ) + { + String filename; + + if ( line.indexOf( ";" ) == -1 ) + { + filename = line.substring( 13 ); + } + else + { + filename = line.substring( 13, line.indexOf( ";" ) ); + } + + changeLogFile = new ChangeLogFile( filename ); + status = GET_FILE_REVISION; + } + } + + protected void processGetFileRevision( String line ) + { + if ( line.startsWith( "member:\t" ) ) + { + changeLogFile.setRevision( line.substring( 8 ) ); + status = WAITFOR_ENTRY_REVISION; + } + } + + protected void processWaitForEntryRevision( String line ) + { + if ( line.equals( "-----------------------" ) ) + { + status = GET_ENTRY_INFO; + } + } + + protected void processGetEntryInfo( String line ) + { + if ( line.startsWith( "date: " ) ) + { + changeLogEntry = new ChangeLogEntry(); + + int posAuthor = line.indexOf( "; author: " ); + + if ( posAuthor == -1 ) + { + return; + } + + int posState = line.indexOf( "; state: " ); + + if ( posState == -1 ) + { + return; + } + + try + { + Date date = + MKS_TIMESTAMP_FORMAT.parse( line.substring( 6, posAuthor ) ); + String author = line.substring( posAuthor + 10, posState ); + + changeLogEntry.setDate( date ); + changeLogEntry.setAuthor( author ); + status = GET_ENTRY_COMMENT; + } + catch ( ParseException e ) + { + throw new IllegalArgumentException( + "I don't understand this date: " + + line.substring( 6, posAuthor ) ); + } + } + } + + protected void processGetEntryComment( String line ) + { + if ( line.equals( "-----------------------" ) ) + { + addEntry(); + status = GET_ENTRY_INFO; + + return; + } + + changeLogEntry.setComment( changeLogEntry.getComment() + line + "\n" ); + } + + protected void addEntry() + { + if ( ( changeLogEntry == null ) || ( changeLogFile == null ) ) + { + return; + } + + // do not add if entry is not populated + if ( ( changeLogEntry.getAuthor() == null ) + || ( changeLogEntry.getDate() == null ) ) + { + return; + } + + String key = + ENTRY_KEY_TIMESTAMP_FORMAT.format( changeLogEntry.getDate() ) + + changeLogEntry.getAuthor() + changeLogEntry.getComment(); + + if ( !entries.containsKey( key ) ) + { + changeLogEntry.addFile( changeLogFile ); + entries.put( key, changeLogEntry ); + } + else + { + ( (ChangeLogEntry) entries.get( key ) ).addFile( changeLogFile ); + } + } +} diff --git a/changelog/src/test-resources/mkslib/mkslog.txt b/changelog/src/test-resources/mkslib/mkslog.txt new file mode 100644 index 00000000..ac9d9a97 --- /dev/null +++ b/changelog/src/test-resources/mkslib/mkslog.txt @@ -0,0 +1,56 @@ +member name: myproject/myfile; working file: /myproject/myfile +head: 1.1 +member: 1.1 +branch: +locks: ; strict +attributes: +file format: text +revision storage: reverse deltas +total revisions: 1; branches: 0; branch revisions: 0 +description: +Initial Version +----------------------- +revision 1.1 +date: Jan 16, 2006 - 16:02 PM; author: AUTHOR; state: InWork; lines: +0 -0 +Initial revision +=============================================================================== +member name: myproject/myfile2; working file: /myproject/myfile2 +head: 1.1 +member: 1.1 +branch: +locks: ; strict +attributes: +file format: text +revision storage: reverse deltas +total revisions: 1; branches: 0; branch revisions: 0 +description: +Initial Version +----------------------- +revision 1.1 +date: Jan 16, 2006 - 16:02 PM; author: AUTHOR; state: InWork; lines: +0 -0 +Initial revision +=============================================================================== +member name: myproject/myfile3; working file: /myproject/myfile3 +head: 1.3 +member: 1.3 +branch: +locks: ; strict +attributes: +file format: text +revision storage: reverse deltas +total revisions: 1; branches: 0; branch revisions: 0 +description: +Initial Version +----------------------- +revision 1.3 +date: Jan 16, 2006 - 16:14 PM; author: AUTHOR; state: InWork; lines: +0 -2 +Revision 1.3 +----------------------- +revision 1.2 +date: Jan 16, 2006 - 16:11 PM; author: AUTHOR; state: InWork; lines: +2 -0 +Revision 1.2 +----------------------- +revision 1.1 +date: Jan 16, 2006 - 16:02 PM; author: AUTHOR; state: InWork; lines: +0 -0 +Initial revision +=============================================================================== diff --git a/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java b/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java index 7564cda7..fc7725e9 100644 --- a/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java +++ b/changelog/src/test/org/apache/maven/cvslib/CvsConnectionTest.java @@ -31,8 +31,6 @@ import junit.framework.TestCase; public class CvsConnectionTest extends TestCase { - /** the {@link CvsConnection} used for testing */ - private CvsConnection instance; /** test data */ private String testData = ":pserver:user@server:/home/cvs"; private String[] testTrueData = { diff --git a/changelog/src/test/org/apache/maven/mkslib/MksChangeLogParserTest.java b/changelog/src/test/org/apache/maven/mkslib/MksChangeLogParserTest.java new file mode 100644 index 00000000..0f1401c6 --- /dev/null +++ b/changelog/src/test/org/apache/maven/mkslib/MksChangeLogParserTest.java @@ -0,0 +1,91 @@ +package org.apache.maven.mkslib; + +/* ==================================================================== + * Copyright 2006 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ==================================================================== + */ + + +import junit.framework.TestCase; + +import org.apache.maven.changelog.ChangeLogEntry; + +import java.io.FileInputStream; +import java.io.IOException; + +import java.util.Collection; +import java.util.Iterator; + +/** + * This class test the mks parser with an inputstream. + * + * @author dion (writes CvsChangeLogParserTest) + * @author Christoph Jerolimov + * @version $Id$ + */ +public class MksChangeLogParserTest extends TestCase +{ + /** the {@link MksChangeLogParser} used for testing */ + private MksChangeLogParser instance; + + /** file with test results to check against */ + private String testFile; + + /** + * Create a test with the given name + * @param testName the name of the test + */ + public MksChangeLogParserTest( String testName ) + { + super( testName ); + } + + /** + * Initialize per test data + * @throws Exception when there is an unexpected problem + */ + public void setUp() throws Exception + { + String baseDir = System.getProperty( "basedir" ); + + assertNotNull( "The system property basedir was not defined.", baseDir ); + testFile = baseDir + "/src/test-resources/mkslib/mkslog.txt"; + instance = new MksChangeLogParser(); + } + + /** + * Test the mks parser. + * @throws IOException when there is an unexpected problem + */ + public void testParser() + throws IOException + { + FileInputStream fis = new FileInputStream( testFile ); + Collection entries = instance.parse( fis ); + + assertEquals( "Wrong number of entries returned", 3, entries.size() ); + + ChangeLogEntry entry = null; + + for ( Iterator i = entries.iterator(); i.hasNext(); ) + { + entry = (ChangeLogEntry) i.next(); + assertEquals( "Wrong author parsed", "AUTHOR", entry.getAuthor() ); + System.out.println( entry ); + assertTrue( "ChangeLogEntry erroneously picked up", + entry.toString().indexOf( "ChangeLogEntry.java" ) == -1 ); + } + } +} diff --git a/changelog/src/test/org/apache/maven/util/RepositoryTest.java b/changelog/src/test/org/apache/maven/util/RepositoryTest.java index 232acda7..9c7860d4 100644 --- a/changelog/src/test/org/apache/maven/util/RepositoryTest.java +++ b/changelog/src/test/org/apache/maven/util/RepositoryTest.java @@ -55,7 +55,7 @@ public class RepositoryTest String con = "scm:cvs:local:/cvs/root"; try { - String[] tokens = RepositoryUtils.splitSCMConnection(con); + RepositoryUtils.splitSCMConnection(con); fail("Should throw an exception splitting " + con); } catch ( IllegalArgumentException expected ) @@ -69,7 +69,7 @@ public class RepositoryTest String con = "scm:cvs:pserver:user@host:/cvs/root"; try { - String[] tokens = RepositoryUtils.splitSCMConnection(con); + RepositoryUtils.splitSCMConnection(con); fail("Should throw an exception splitting " + con); } catch ( IllegalArgumentException expected ) @@ -83,7 +83,7 @@ public class RepositoryTest String con = "scm:cvs:local:foo:/cvs/root:module"; try { - String[] tokens = RepositoryUtils.splitSCMConnection(con); + RepositoryUtils.splitSCMConnection(con); fail("Should throw an exception splitting " + con); } catch ( IllegalArgumentException expected ) diff --git a/changelog/xdocs/changes.xml b/changelog/xdocs/changes.xml index c43acabf..56dd4520 100644 --- a/changelog/xdocs/changes.xml +++ b/changelog/xdocs/changes.xml @@ -25,6 +25,7 @@ + Add MKS SI support. Changelog returns 0 entries on Windows with CVS (not CVSNT). New property maven.changelog.quoteDate. Changelog plugin creates wrong links for Subversion repositories. New property maven.changelog.svn.baseurl. Update dependencies to match ones in maven 1.1 core and to unify them between plugins. The following dependencies are updated : diff --git a/changelog/xdocs/index.xml b/changelog/xdocs/index.xml index 5ec3348c..f919360c 100644 --- a/changelog/xdocs/index.xml +++ b/changelog/xdocs/index.xml @@ -30,9 +30,9 @@

This plugin produces a nicely formatted changelog report so project team members can see at a glance what changes have - been made recently to the project. Currently, there are five + been made recently to the project. Currently, there are six supported source control systems: CVS, Perforce, StarTeam, IBM - Rational ClearCase, Visual Source Safe and Subversion. + Rational ClearCase, Visual Source Safe, Subversion and MKS SI.

For more information on the functionality provided by this plugin, diff --git a/changelog/xdocs/properties.xml b/changelog/xdocs/properties.xml index a496630f..58bde142 100644 --- a/changelog/xdocs/properties.xml +++ b/changelog/xdocs/properties.xml @@ -117,6 +117,8 @@ href="apidocs/org/apache/maven/starteamlib/StarteamChangeLogFactory.html">org.apache.maven.starteamlib.StarteamChangeLogFactory

  • Visual Source Safe: org.apache.maven.vsslib.VssChangeLogFactory
  • +
  • MKS Source Integrity: org.apache.maven.mkslib.MksChangeLogFactory