Checkstyle clean-ups.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@434563 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
ltheussl 2006-08-24 23:32:54 +00:00
parent 975cdedcb8
commit 2832b0999a
5 changed files with 94 additions and 44 deletions

View File

@ -25,34 +25,37 @@ package org.apache.maven.changes;
public class IssueFinder
{
/**
* @param trackerURL the issue tracker URL (this is supposed to be the
* @param trackerURL the issue tracker URL (this is supposed to be the
* value of <issueTrackingUrl> found in the POM.
* @param issue the issue reference
* @param template the template string. Allowed template patterns are
* <code>%URL%</code> and <code>%ISSUE%</code>. They will be
* replaced by the base tracker URL extracted from trackerURL and
* @param template the template string. Allowed template patterns are
* <code>%URL%</code> and <code>%ISSUE%</code>. They will be
* replaced by the base tracker URL extracted from trackerURL and
* by the issue reference.
* @return The URL of the issue.
*/
public static String getIssueURL(String trackerURL, String issue,
String template)
public static String getIssueURL( String trackerURL, String issue,
String template )
{
// Find base URL of issue tracker
String baseURL;
int pos = trackerURL.lastIndexOf("/");
if (pos > 0) {
baseURL = trackerURL.substring(0, pos);
} else {
throw new RuntimeException("Failed to extract tracker URL from ["
+ trackerURL + "]");
int pos = trackerURL.lastIndexOf( "/" );
if ( pos > 0 )
{
baseURL = trackerURL.substring( 0, pos );
}
else
{
throw new RuntimeException( "Failed to extract tracker URL from ["
+ trackerURL + "]" );
}
// Use template to construct issue URL
String issueURL = replace(template, "%URL%", baseURL);
issueURL = replace(issueURL, "%ISSUE%", issue);
String issueURL = replace( template, "%URL%", baseURL );
issueURL = replace( issueURL, "%ISSUE%", issue );
return issueURL;
}
}
/**
* @param original the original template
@ -60,23 +63,25 @@ public class IssueFinder
* @param newPattern the new pattern
* @return the modified template string with patterns applied
*/
public static final String replace(String original, String oldPattern,
String newPattern)
public static final String replace( String original, String oldPattern,
String newPattern )
{
int index, oldIndex;
StringBuffer buffer = new StringBuffer();
if((index = original.indexOf(oldPattern)) != -1) {
if ( ( index = original.indexOf( oldPattern ) ) != -1 )
{
oldIndex = 0;
while((index = original.indexOf(oldPattern, oldIndex)) != -1) {
buffer.append(original.substring(oldIndex, index));
buffer.append(newPattern);
while ( ( index = original.indexOf( oldPattern, oldIndex ) ) != -1 )
{
buffer.append( original.substring( oldIndex, index ) );
buffer.append( newPattern);
oldIndex = index + oldPattern.length();
}
buffer.append(original.substring(oldIndex));
buffer.append( original.substring( oldIndex ) );
original = buffer.toString();
}
return original;
}
}
}

View File

@ -17,13 +17,30 @@ package org.apache.maven.changes;
* ====================================================================
*/
import java.io.*;
import java.text.*;
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import org.apache.commons.io.FileUtils;
import org.dom4j.*;
import org.dom4j.io.*;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
/**
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
@ -43,19 +60,19 @@ public class ReleaseVersion
throws DocumentException, FileNotFoundException, UnsupportedEncodingException, IOException
{
SAXReader r = new SAXReader();
Document doc = r.read( changesFile );
Element root = doc.getRootElement();
Element releases = root.element( "body" );
for ( Iterator i = releases.elementIterator( "release" ); i.hasNext(); )
{
Element e = ( Element ) i.next();
Attribute v = e.attribute( "version" );
if ( v != null )
{
String text = v.getText();
@ -138,6 +155,6 @@ public class ReleaseVersion
writer.write( doc );
writer.flush();
writer.close();
}
}
}

View File

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>org.apache.maven.changes</title>
</head>
<body>
<p>
Contains utility classes for changes plugin.
</p>
</body>
</html>

View File

@ -44,7 +44,8 @@ public class ReleaseVersionTest
public void testExistingReleaseTargetVersionReleased()
throws Exception
{
File changesFile = new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-target-version-released.xml" );
File changesFile = new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-target-version-released.xml" );
Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", "2004-04-21" );
assertNull( "check transform required", doc );
@ -66,7 +67,8 @@ public class ReleaseVersionTest
public void testExistingReleaseTargetVersionInCvs()
throws Exception
{
File changesFile = new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-target-version-in-cvs.xml" );
File changesFile = new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-target-version-in-cvs.xml" );
Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", "2004-04-21" );
assertNotNull( "check transform required", doc );
@ -84,7 +86,8 @@ public class ReleaseVersionTest
public void testExistingReleaseCurrentVersionReleasedAndTargetVersionInCvs()
throws Exception
{
File changesFile = new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-current-version-released-and-target-version-in-cvs.xml" );
File changesFile = new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-current-version-released-and-target-version-in-cvs.xml" );
Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", "2004-04-21" );
assertNotNull( "check transform required", doc );
@ -107,13 +110,14 @@ public class ReleaseVersionTest
public void testExistingReleaseCurrentVersionReleasedAndTargetVersionReleased()
throws Exception
{
File changesFile = new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-current-version-released-and-target-version-released.xml" );
File changesFile = new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-current-version-released-and-target-version-released.xml" );
Document doc = ReleaseVersion.transformVersion( changesFile, "1.1", "1.2", "2004-04-21" );
assertNull( "check transform required", doc );
SAXReader r = new SAXReader();
doc = r.read( changesFile );
List nodes = doc.selectNodes( "/document/body/release" );
@ -134,13 +138,14 @@ public class ReleaseVersionTest
public void testExistingReleaseCurrentVersionReleased()
throws Exception
{
File changesFile = new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-current-version-released.xml" );
File changesFile = new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-current-version-released.xml" );
Document doc = ReleaseVersion.transformVersion( changesFile, "1.2", "1.2", "2004-04-21" );
assertNull( "check transform required", doc );
SAXReader r = new SAXReader();
doc = r.read( changesFile );
List nodes = doc.selectNodes( "/document/body/release" );
@ -157,7 +162,8 @@ public class ReleaseVersionTest
throws Exception
{
Document doc = ReleaseVersion.transformVersion(
new File( System.getProperty( "basedir" ), "/src/test-data/test-existing-release-current-version-in-cvs.xml" ),
new File( System.getProperty( "basedir" ),
"/src/test-data/test-existing-release-current-version-in-cvs.xml" ),
"1.2-SNAPSHOT", "1.2", "2004-04-21" );
assertNotNull( "check transform required", doc );

View File

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>org.apache.maven.changes</title>
</head>
<body>
<p>
Test classes for org.apache.maven.changes.
</p>
</body>
</html>