summaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-base
diff options
context:
space:
mode:
authorBrett Porter <brett@apache.org>2009-03-17 13:40:10 +0000
committerBrett Porter <brett@apache.org>2009-03-17 13:40:10 +0000
commit3cdb8ce93405bb47b021482e798944c2f00bc557 (patch)
tree23a4ca1d76b02cb7c192560607429e73745eece5 /archiva-modules/archiva-base
parent51ad4bdec94c15ff08d73032e3f9f580f8004aee (diff)
downloadarchiva-3cdb8ce93405bb47b021482e798944c2f00bc557.tar.gz
archiva-3cdb8ce93405bb47b021482e798944c2f00bc557.zip
start adding Java5 features to modules
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@755239 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-base')
-rw-r--r--archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/ArtifactConverter.java3
-rw-r--r--archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverter.java52
-rw-r--r--archiva-modules/archiva-base/archiva-artifact-converter/src/test/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverterTest.java59
3 files changed, 53 insertions, 61 deletions
diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/ArtifactConverter.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/ArtifactConverter.java
index 1c67d8d2a..fc61d16a0 100644
--- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/ArtifactConverter.java
+++ b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/ArtifactConverter.java
@@ -22,6 +22,7 @@ package org.apache.maven.archiva.converter.artifact;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
+import java.util.List;
import java.util.Map;
/**
@@ -48,7 +49,7 @@ public interface ArtifactConverter
*
* @return the {@link Map}&lt;{@link Artifact}, {@link String}&gt; warning messages.
*/
- Map getWarnings();
+ Map<Artifact, List<String>> getWarnings();
/**
* Clear the list of warning messages.
diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverter.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverter.java
index 8ce135b9f..f1f16601b 100644
--- a/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverter.java
+++ b/archiva-modules/archiva-base/archiva-artifact-converter/src/main/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverter.java
@@ -19,6 +19,19 @@ package org.apache.maven.archiva.converter.artifact;
* under the License.
*/
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Matcher;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.archiva.transaction.FileTransaction;
@@ -45,20 +58,6 @@ import org.codehaus.plexus.digest.Digester;
import org.codehaus.plexus.digest.DigesterException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.regex.Matcher;
-
/**
* LegacyToDefaultConverter
*
@@ -75,7 +74,7 @@ public class LegacyToDefaultConverter
*
* @plexus.requirement role="org.codehaus.plexus.digest.Digester"
*/
- private List digesters;
+ private List<Digester> digesters;
/**
* @plexus.requirement
@@ -102,7 +101,7 @@ public class LegacyToDefaultConverter
*/
private boolean dryrun;
- private Map warnings = new HashMap();
+ private Map<Artifact,List<String>> warnings = new HashMap<Artifact,List<String>>();
public void convert( Artifact artifact, ArtifactRepository targetRepository )
throws ArtifactConversionException
@@ -168,6 +167,7 @@ public class LegacyToDefaultConverter
}
}
+ @SuppressWarnings("unchecked")
private boolean copyPom( Artifact artifact, ArtifactRepository targetRepository, FileTransaction transaction )
throws ArtifactConversionException
{
@@ -250,11 +250,10 @@ public class LegacyToDefaultConverter
transaction.createFile( writer.toString(), targetFile, digesters );
- List warnings = translator.getWarnings();
+ List<String> warnings = translator.getWarnings();
- for ( Iterator i = warnings.iterator(); i.hasNext(); )
+ for ( String message : warnings )
{
- String message = (String) i.next();
addWarning( artifact, message );
}
}
@@ -289,10 +288,8 @@ public class LegacyToDefaultConverter
throws IOException
{
boolean result = true;
- Iterator it = digesters.iterator();
- while ( it.hasNext() )
+ for ( Digester digester : digesters )
{
- Digester digester = (Digester) it.next();
result &= verifyChecksum( file, file.getName() + "." + getDigesterFileExtension( digester ), digester, //$NON-NLS-1$
artifact, "failure.incorrect." + getDigesterFileExtension( digester ) ); //$NON-NLS-1$
}
@@ -441,6 +438,7 @@ public class LegacyToDefaultConverter
return result;
}
+ @SuppressWarnings("unchecked")
private boolean validateMetadata( Metadata metadata, RepositoryMetadata repositoryMetadata, Artifact artifact )
{
String groupIdKey;
@@ -488,12 +486,12 @@ public class LegacyToDefaultConverter
boolean foundVersion = false;
if ( metadata.getVersioning() != null )
{
- for ( Iterator i = metadata.getVersioning().getVersions().iterator(); i.hasNext() && !foundVersion; )
+ for ( String version : (List<String>) metadata.getVersioning().getVersions() )
{
- String version = (String) i.next();
if ( version.equals( artifact.getBaseVersion() ) )
{
foundVersion = true;
+ break;
}
}
}
@@ -668,10 +666,10 @@ public class LegacyToDefaultConverter
private void addWarning( Artifact artifact, String message )
{
- List messages = (List) warnings.get( artifact );
+ List<String> messages = warnings.get( artifact );
if ( messages == null )
{
- messages = new ArrayList();
+ messages = new ArrayList<String>();
}
messages.add( message );
warnings.put( artifact, messages );
@@ -682,7 +680,7 @@ public class LegacyToDefaultConverter
warnings.clear();
}
- public Map getWarnings()
+ public Map<Artifact, List<String>> getWarnings()
{
return warnings;
}
diff --git a/archiva-modules/archiva-base/archiva-artifact-converter/src/test/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverterTest.java b/archiva-modules/archiva-base/archiva-artifact-converter/src/test/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverterTest.java
index a305f1349..8ce2f2c8a 100644
--- a/archiva-modules/archiva-base/archiva-artifact-converter/src/test/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverterTest.java
+++ b/archiva-modules/archiva-base/archiva-artifact-converter/src/test/java/org/apache/maven/archiva/converter/artifact/LegacyToDefaultConverterTest.java
@@ -19,6 +19,15 @@ package org.apache.maven.archiva.converter.artifact;
* under the License.
*/
+import java.io.File;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.regex.Matcher;
+
import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
@@ -30,17 +39,6 @@ import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.regex.Matcher;
-
/**
* LegacyToDefaultConverterTest
*
@@ -736,19 +734,21 @@ public class LegacyToDefaultConverterTest
boolean found = false;
String pattern = "^" + Messages.getString( "invalid.source.pom" ).replaceFirst( "\\{0\\}", ".*" ) + "$";
- for ( Iterator it = artifactConverter.getWarnings().values().iterator(); it.hasNext() && !found; )
+ for ( List<String> messages : artifactConverter.getWarnings().values() )
{
- List messages = (List) it.next();
-
- for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
+ for ( String message : messages )
{
- String message = (String) itmsgs.next();
if ( message.matches( pattern ) )
{
found = true;
break;
}
}
+
+ if ( found )
+ {
+ break;
+ }
}
assertTrue( "Check failure message.", found );
@@ -763,22 +763,19 @@ public class LegacyToDefaultConverterTest
{
// test multiple artifacts are converted
- List artifacts = new ArrayList();
+ List<Artifact> artifacts = new ArrayList<Artifact>();
artifacts.add( createArtifact( "test", "artifact-one", "1.0.0" ) );
artifacts.add( createArtifact( "test", "artifact-two", "1.0.0" ) );
artifacts.add( createArtifact( "test", "artifact-three", "1.0.0" ) );
- for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+ for ( Artifact artifact : artifacts )
{
- Artifact arti = (Artifact) it.next();
- artifactConverter.convert( arti, targetRepository );
+ artifactConverter.convert( artifact, targetRepository );
checkSuccess( artifactConverter );
}
- for ( Iterator i = artifacts.iterator(); i.hasNext(); )
+ for ( Artifact artifact : artifacts )
{
- Artifact artifact = (Artifact) i.next();
-
File artifactFile = new File( targetRepository.getBasedir(), targetRepository.pathOf( artifact ) );
assertTrue( "Check artifact created", artifactFile.exists() );
assertTrue( "Check artifact matches", FileUtils.contentEquals( artifactFile, artifact.getFile() ) );
@@ -954,9 +951,8 @@ public class LegacyToDefaultConverterTest
private int countWarningMessages( ArtifactConverter converter )
{
int count = 0;
- for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
+ for ( List<String> values : converter.getWarnings().values() )
{
- List values = (List) it.next();
count += values.size();
}
return count;
@@ -967,28 +963,25 @@ public class LegacyToDefaultConverterTest
assertNotNull( "Warnings should never be null.", converter.getWarnings() );
assertTrue( "Expecting 1 or more Warnings", countWarningMessages( converter ) > 0 );
- for ( Iterator it = converter.getWarnings().values().iterator(); it.hasNext(); )
+ for ( List<String> messages : converter.getWarnings().values() )
{
- List messages = (List) it.next();
if ( messages.contains( reason ) )
{
- /* No need to check any furthor */
+ /* No need to check any further */
return;
}
}
/* didn't find it. */
- for ( Iterator it = converter.getWarnings().entrySet().iterator(); it.hasNext(); )
+ for ( Map.Entry<Artifact,List<String>> entry : converter.getWarnings().entrySet() )
{
- Map.Entry entry = (Entry) it.next();
Artifact artifact = (Artifact) entry.getKey();
System.out.println( "-Artifact: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":"
+ artifact.getVersion() );
- List messages = (List) entry.getValue();
- for ( Iterator itmsgs = messages.iterator(); itmsgs.hasNext(); )
+ List<String> messages = entry.getValue();
+ for ( String message : messages )
{
- String message = (String) itmsgs.next();
System.out.println( " " + message );
}
}