From 2df87ca73f55e7f4e1c91aa3a7365a8bb39e3bf9 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Fri, 30 Dec 2005 04:37:28 +0000 Subject: [PATCH] reformat git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@359986 13f79535-47bb-0310-9956-ffa450edef68 --- maven-repository-discovery/pom.xml | 16 + .../discovery/AbstractArtifactDiscoverer.java | 2 +- .../discovery/ArtifactDiscoverer.java | 2 +- .../discovery/DefaultArtifactDiscoverer.java | 2 +- .../discovery/DefaultMetadataDiscoverer.java | 386 +++++++++--------- .../discovery/LegacyArtifactDiscoverer.java | 2 +- .../discovery/MetadataDiscoverer.java | 50 ++- .../resources/META-INF/plexus/components.xml | 26 +- .../DefaultArtifactDiscovererTest.java | 6 +- .../DefaultMetadataDiscovererTest.java | 6 +- .../LegacyArtifactDiscovererTest.java | 6 +- .../javax/maven-metadata-repository.xml | 16 + .../jdbc/2.0/maven-metadata-repository.xml | 16 + .../sql/jdbc/maven-metadata-repository.xml | 16 + .../javax/sql/maven-metadata-repository.xml | 16 + .../1.0/maven-metadata-repository.xml | 16 + maven-repository-indexer/pom.xml | 16 + .../indexing/AbstractRepositoryIndex.java | 34 +- .../indexing/ArtifactRepositoryIndex.java | 66 +-- .../ArtifactRepositoryIndexAnalyzer.java | 28 +- .../ArtifactRepositoryIndexSearcher.java | 75 ++-- .../repository/indexing/RepositoryIndex.java | 22 +- .../indexing/RepositoryIndexException.java | 8 +- .../indexing/RepositoryIndexSearcher.java | 28 +- .../resources/META-INF/plexus/components.xml | 16 + .../ArtifactRepositoryIndexingTest.java | 3 +- maven-repository-reports-standard/pom.xml | 28 +- .../AbstractRepositoryQueryLayer.java | 17 +- .../reporting/ArtifactReportProcessor.java | 31 +- .../reporting/ArtifactReporter.java | 36 +- .../repository/reporting/ArtifactResult.java | 2 +- .../reporting/BadMetadataReportProcessor.java | 31 +- .../maven/repository/reporting/Cache.java | 59 +-- .../reporting/CachedRepositoryQueryLayer.java | 23 +- .../reporting/ChecksumArtifactReporter.java | 67 +-- .../DefaultArtifactReportProcessor.java | 10 +- .../reporting/DefaultArtifactReporter.java | 6 +- .../DefaultRepositoryQueryLayer.java | 12 +- .../DefaultRepositoryQueryLayerFactory.java | 2 +- .../InvalidPomArtifactReportProcessor.java | 136 +++--- .../LocationArtifactReportProcessor.java | 77 ++-- .../reporting/MetadataReportProcessor.java | 27 +- .../reporting/ReportProcessorException.java | 2 +- .../reporting/RepositoryMetadataResult.java | 2 +- .../reporting/RepositoryQueryLayer.java | 36 +- .../RepositoryQueryLayerException.java | 5 +- .../RepositoryQueryLayerFactory.java | 2 +- .../resources/META-INF/plexus/components.xml | 52 ++- .../AbstractChecksumArtifactReporterTest.java | 100 +++-- .../AbstractRepositoryQueryLayerTest.java | 44 +- .../AbstractRepositoryReportsTestCase.java | 9 +- .../ArtifactReportProcessorTest.java | 6 +- .../reporting/ArtifactReporterTest.java | 4 +- .../BadMetadataReportProcessorTest.java | 71 ++-- .../maven/repository/reporting/CacheTest.java | 45 +- .../CachedRepositoryQueryLayerTest.java | 14 +- .../ChecksumArtifactReporterTest.java | 67 ++- .../DefaultArtifactReporterTest.java | 34 +- .../reporting/GenericMockObject.java | 29 +- ...InvalidPomArtifactReportProcessorTest.java | 140 ++++--- .../LocationArtifactReportProcessorTest.java | 85 ++-- .../repository/reporting/MockArtifact.java | 14 +- .../reporting/MockArtifactFactory.java | 4 +- .../MockArtifactReportProcessor.java | 35 +- .../reporting/MockArtifactReporter.java | 2 +- .../reporting/MockRepositoryQueryLayer.java | 6 +- .../repository/reporting/ReportCondition.java | 6 +- .../groupId/artifactId/maven-metadata.xml | 26 +- .../repository/groupId/unexpectedfile.xml | 18 +- .../repository/maven-metadata-repository.xml | 22 +- pom.xml | 53 ++- 71 files changed, 1363 insertions(+), 1014 deletions(-) diff --git a/maven-repository-discovery/pom.xml b/maven-repository-discovery/pom.xml index 8426562e3..32f8a525d 100755 --- a/maven-repository-discovery/pom.xml +++ b/maven-repository-discovery/pom.xml @@ -1,3 +1,19 @@ + + diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java index f7c94612b..f55154c17 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractArtifactDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java index cd51ee015..5383fdae3 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/ArtifactDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java index 00fe863d4..d88ed4f52 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultArtifactDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java index 9431ae032..e7948f226 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DefaultMetadataDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,20 +16,6 @@ package org.apache.maven.repository.discovery; * limitations under the License. */ -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -45,175 +31,211 @@ import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.StringTokenizer; + /** * This class gets all the paths that contain the metadata files. - * */ -public class DefaultMetadataDiscoverer implements MetadataDiscoverer { - - /** - * Standard patterns to exclude from discovery as they are not artifacts. - */ - private static final String[] STANDARD_DISCOVERY_EXCLUDES = { "bin/**", - "reports/**", ".maven/**", "**/*.md5", "**/*.MD5", "**/*.sha1", - "**/*.SHA1", "**/*snapshot-version", "*/website/**", - "*/licenses/**", "*/licences/**", "**/.htaccess", "**/*.html", - "**/*.asc", "**/*.txt", "**/README*", "**/CHANGELOG*", "**/KEYS*" }; - - /** - * Standard patterns to include in discovery of metadata files. - */ - private static final String[] STANDARD_DISCOVERY_INCLUDES = { - "**/*-metadata.xml", "**/*/*-metadata.xml", - "**/*/*/*-metadata.xml", "**/*-metadata-*.xml", - "**/*/*-metadata-*.xml", "**/*/*/*-metadata-*.xml" }; - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private List excludedPaths = new ArrayList(); - - private List kickedOutPaths = new ArrayList(); - - /** - * Search the repository for metadata files. - * - * @param repositoryBase - * @param blacklistedPatterns - */ - public List discoverMetadata(File repositoryBase, String blacklistedPatterns) { - List metadataFiles = new ArrayList(); - String[] metadataPaths = scanForMetadataPaths(repositoryBase, - blacklistedPatterns); - - for (int i = 0; i < metadataPaths.length; i++) { - RepositoryMetadata metadata = buildMetadata(repositoryBase - .getPath(), metadataPaths[i]); - - if (metadata != null) - metadataFiles.add(metadata); - else - kickedOutPaths.add(metadataPaths[i]); - } - - return metadataFiles; - } - - /** - * Create RepositoryMetadata object. - * - * @param repo - * The path to the repository. - * @param metadataPath - * The path to the metadata file. - * @return - */ - private RepositoryMetadata buildMetadata(String repo, String metadataPath) { - - RepositoryMetadata metadata = null; - - try { - URL url = new File(repo + "/" + metadataPath).toURL(); - InputStream is = url.openStream(); - Reader reader = new InputStreamReader(is); - MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); - - Metadata m = metadataReader.read(reader); - String metaGroupId = m.getGroupId(); - String metaArtifactId = m.getArtifactId(); - String metaVersion = m.getVersion(); - - // check if the groupId, artifactId and version is in the - // metadataPath - // parse the path, in reverse order - List pathParts = new ArrayList(); - StringTokenizer st = new StringTokenizer(metadataPath, "/\\"); - while (st.hasMoreTokens()) { - pathParts.add(st.nextToken()); - } - - Collections.reverse(pathParts); - // remove the metadata file - pathParts.remove(0); - Iterator it = pathParts.iterator(); - String tmpDir = (String) it.next(); - - ArtifactHandler handler = new DefaultArtifactHandler("jar"); - VersionRange version = VersionRange.createFromVersion(metaVersion); - Artifact artifact = new DefaultArtifact(metaGroupId, - metaArtifactId, version, "compile", "jar", "", handler); - - // snapshotMetadata - if (tmpDir.equals(metaVersion)) { - metadata = new SnapshotArtifactRepositoryMetadata(artifact); - } else if (tmpDir.equals(metaArtifactId)) { - // artifactMetadata - metadata = new ArtifactRepositoryMetadata(artifact); - } else { - - String groupDir = ""; - int ctr = 0; - for (it = pathParts.iterator(); it.hasNext();) { - if (ctr == 0) - groupDir = (String) it.next(); - else - groupDir = (String) it.next() + "." + groupDir; - ctr++; - } - - // groupMetadata - if (metaGroupId.equals(groupDir)) - metadata = new GroupRepositoryMetadata(metaGroupId); - } - - } catch (FileNotFoundException fe) { - return null; - } catch (XmlPullParserException xe) { - return null; - } catch (IOException ie) { - return null; - } - - return metadata; - } - - /** - * Scan or search for metadata files. - * - * @param repositoryBase - * The repository directory. - * @param blacklistedPatterns - * The patterns to be exluded from the search. - * @return - */ - private String[] scanForMetadataPaths(File repositoryBase, - String blacklistedPatterns) { - - List allExcludes = new ArrayList(); - allExcludes.addAll(FileUtils.getDefaultExcludesAsList()); - allExcludes.addAll(Arrays.asList(STANDARD_DISCOVERY_EXCLUDES)); - - if (blacklistedPatterns != null && blacklistedPatterns.length() > 0) { - allExcludes.addAll(Arrays.asList(blacklistedPatterns.split(","))); - } - - DirectoryScanner scanner = new DirectoryScanner(); - scanner.setBasedir(repositoryBase); - scanner.setIncludes(STANDARD_DISCOVERY_INCLUDES); - scanner.setExcludes((String[]) allExcludes.toArray(EMPTY_STRING_ARRAY)); - scanner.scan(); - - excludedPaths.addAll(Arrays.asList(scanner.getExcludedFiles())); - - return scanner.getIncludedFiles(); - - } - - public Iterator getExcludedPathsIterator() { - return excludedPaths.iterator(); - } - - public Iterator getKickedOutPathsIterator() { - return kickedOutPaths.iterator(); - } +public class DefaultMetadataDiscoverer + implements MetadataDiscoverer +{ + + /** + * Standard patterns to exclude from discovery as they are not artifacts. + */ + private static final String[] STANDARD_DISCOVERY_EXCLUDES = {"bin/**", "reports/**", ".maven/**", "**/*.md5", + "**/*.MD5", "**/*.sha1", "**/*.SHA1", "**/*snapshot-version", "*/website/**", "*/licenses/**", "*/licences/**", + "**/.htaccess", "**/*.html", "**/*.asc", "**/*.txt", "**/README*", "**/CHANGELOG*", "**/KEYS*"}; + + /** + * Standard patterns to include in discovery of metadata files. + */ + private static final String[] STANDARD_DISCOVERY_INCLUDES = {"**/*-metadata.xml", "**/*/*-metadata.xml", + "**/*/*/*-metadata.xml", "**/*-metadata-*.xml", "**/*/*-metadata-*.xml", "**/*/*/*-metadata-*.xml"}; + + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + + private List excludedPaths = new ArrayList(); + + private List kickedOutPaths = new ArrayList(); + + /** + * Search the repository for metadata files. + * + * @param repositoryBase + * @param blacklistedPatterns + */ + public List discoverMetadata( File repositoryBase, String blacklistedPatterns ) + { + List metadataFiles = new ArrayList(); + String[] metadataPaths = scanForMetadataPaths( repositoryBase, blacklistedPatterns ); + + for ( int i = 0; i < metadataPaths.length; i++ ) + { + RepositoryMetadata metadata = buildMetadata( repositoryBase + .getPath(), metadataPaths[i] ); + + if ( metadata != null ) + { + metadataFiles.add( metadata ); + } + else + { + kickedOutPaths.add( metadataPaths[i] ); + } + } + + return metadataFiles; + } + + /** + * Create RepositoryMetadata object. + * + * @param repo The path to the repository. + * @param metadataPath The path to the metadata file. + * @return + */ + private RepositoryMetadata buildMetadata( String repo, String metadataPath ) + { + + RepositoryMetadata metadata = null; + + try + { + URL url = new File( repo + "/" + metadataPath ).toURL(); + InputStream is = url.openStream(); + Reader reader = new InputStreamReader( is ); + MetadataXpp3Reader metadataReader = new MetadataXpp3Reader(); + + Metadata m = metadataReader.read( reader ); + String metaGroupId = m.getGroupId(); + String metaArtifactId = m.getArtifactId(); + String metaVersion = m.getVersion(); + + // check if the groupId, artifactId and version is in the + // metadataPath + // parse the path, in reverse order + List pathParts = new ArrayList(); + StringTokenizer st = new StringTokenizer( metadataPath, "/\\" ); + while ( st.hasMoreTokens() ) + { + pathParts.add( st.nextToken() ); + } + + Collections.reverse( pathParts ); + // remove the metadata file + pathParts.remove( 0 ); + Iterator it = pathParts.iterator(); + String tmpDir = (String) it.next(); + + ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); + VersionRange version = VersionRange.createFromVersion( metaVersion ); + Artifact artifact = + new DefaultArtifact( metaGroupId, metaArtifactId, version, "compile", "jar", "", handler ); + + // snapshotMetadata + if ( tmpDir.equals( metaVersion ) ) + { + metadata = new SnapshotArtifactRepositoryMetadata( artifact ); + } + else if ( tmpDir.equals( metaArtifactId ) ) + { + // artifactMetadata + metadata = new ArtifactRepositoryMetadata( artifact ); + } + else + { + + String groupDir = ""; + int ctr = 0; + for ( it = pathParts.iterator(); it.hasNext(); ) + { + if ( ctr == 0 ) + { + groupDir = (String) it.next(); + } + else + { + groupDir = (String) it.next() + "." + groupDir; + } + ctr++; + } + + // groupMetadata + if ( metaGroupId.equals( groupDir ) ) + { + metadata = new GroupRepositoryMetadata( metaGroupId ); + } + } + + } + catch ( FileNotFoundException fe ) + { + return null; + } + catch ( XmlPullParserException xe ) + { + return null; + } + catch ( IOException ie ) + { + return null; + } + + return metadata; + } + + /** + * Scan or search for metadata files. + * + * @param repositoryBase The repository directory. + * @param blacklistedPatterns The patterns to be exluded from the search. + * @return + */ + private String[] scanForMetadataPaths( File repositoryBase, String blacklistedPatterns ) + { + + List allExcludes = new ArrayList(); + allExcludes.addAll( FileUtils.getDefaultExcludesAsList() ); + allExcludes.addAll( Arrays.asList( STANDARD_DISCOVERY_EXCLUDES ) ); + + if ( blacklistedPatterns != null && blacklistedPatterns.length() > 0 ) + { + allExcludes.addAll( Arrays.asList( blacklistedPatterns.split( "," ) ) ); + } + + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir( repositoryBase ); + scanner.setIncludes( STANDARD_DISCOVERY_INCLUDES ); + scanner.setExcludes( (String[]) allExcludes.toArray( EMPTY_STRING_ARRAY ) ); + scanner.scan(); + + excludedPaths.addAll( Arrays.asList( scanner.getExcludedFiles() ) ); + + return scanner.getIncludedFiles(); + + } + + public Iterator getExcludedPathsIterator() + { + return excludedPaths.iterator(); + } + + public Iterator getKickedOutPathsIterator() + { + return kickedOutPaths.iterator(); + } } diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java index a9e0eb82e..b41cef553 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/LegacyArtifactDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java index a5ed87588..516123cea 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/MetadataDiscoverer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -22,33 +22,31 @@ import java.util.List; /** * Interface for discovering metadata files. - * */ -public interface MetadataDiscoverer { - String ROLE = MetadataDiscoverer.class.getName(); +public interface MetadataDiscoverer +{ + String ROLE = MetadataDiscoverer.class.getName(); - /** - * Search for metadata files in the repository. - * - * @param repositoryBase - * The repository directory. - * @param blacklistedPatterns - * Patterns that are to be excluded from the discovery process. - * @return - */ - List discoverMetadata(File repositoryBase, String blacklistedPatterns); + /** + * Search for metadata files in the repository. + * + * @param repositoryBase The repository directory. + * @param blacklistedPatterns Patterns that are to be excluded from the discovery process. + * @return + */ + List discoverMetadata( File repositoryBase, String blacklistedPatterns ); - /** - * Get the list of paths kicked out during the discovery process. - * - * @return the paths as Strings. - */ - Iterator getKickedOutPathsIterator(); + /** + * Get the list of paths kicked out during the discovery process. + * + * @return the paths as Strings. + */ + Iterator getKickedOutPathsIterator(); - /** - * Get the list of paths excluded during the discovery process. - * - * @return the paths as Strings. - */ - Iterator getExcludedPathsIterator(); + /** + * Get the list of paths excluded during the discovery process. + * + * @return the paths as Strings. + */ + Iterator getExcludedPathsIterator(); } diff --git a/maven-repository-discovery/src/main/resources/META-INF/plexus/components.xml b/maven-repository-discovery/src/main/resources/META-INF/plexus/components.xml index 3e8ef2c39..4bda86fe2 100644 --- a/maven-repository-discovery/src/main/resources/META-INF/plexus/components.xml +++ b/maven-repository-discovery/src/main/resources/META-INF/plexus/components.xml @@ -1,11 +1,27 @@ + + - org.apache.maven.repository.discovery.MetadataDiscoverer - default - org.apache.maven.repository.discovery.DefaultMetadataDiscoverer - per-lookup - + org.apache.maven.repository.discovery.MetadataDiscoverer + default + org.apache.maven.repository.discovery.DefaultMetadataDiscoverer + per-lookup + org.apache.maven.repository.discovery.ArtifactDiscoverer legacy diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java index 6d2ef2427..9de8ce7ae 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultArtifactDiscovererTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -275,8 +275,8 @@ public class DefaultArtifactDiscovererTest List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); assertNotNull( "Check artifacts not null", artifacts ); - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); + assertTrue( "Check normal included", artifacts.contains( + createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); } public void testDistributionInclusion() diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java index f4df65bbf..fa1965417 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/DefaultMetadataDiscovererTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,12 +16,12 @@ package org.apache.maven.repository.discovery; * limitations under the License. */ +import org.codehaus.plexus.PlexusTestCase; + import java.io.File; import java.util.Iterator; import java.util.List; -import org.codehaus.plexus.PlexusTestCase; - /** * This class tests the DefaultMetadataDiscoverer class. */ diff --git a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java index cf33067d6..b28a30551 100644 --- a/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java +++ b/maven-repository-discovery/src/test/java/org/apache/maven/repository/discovery/LegacyArtifactDiscovererTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.discovery; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -260,8 +260,8 @@ public class LegacyArtifactDiscovererTest List artifacts = discoverer.discoverArtifacts( repositoryLocation, null, true ); assertNotNull( "Check artifacts not null", artifacts ); - assertTrue( "Check normal included", - artifacts.contains( createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); + assertTrue( "Check normal included", artifacts.contains( + createArtifact( "org.apache.maven", "testing", "1.0", "java-source", "sources" ) ) ); } public void testDistributionInclusion() diff --git a/maven-repository-discovery/src/test/repository/javax/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/maven-metadata-repository.xml index 96d11ff31..17775863b 100644 --- a/maven-repository-discovery/src/test/repository/javax/maven-metadata-repository.xml +++ b/maven-repository-discovery/src/test/repository/javax/maven-metadata-repository.xml @@ -1,3 +1,19 @@ + + javax.sql jdbc diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml index 96d11ff31..17775863b 100644 --- a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml +++ b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/2.0/maven-metadata-repository.xml @@ -1,3 +1,19 @@ + + javax.sql jdbc diff --git a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml index 78ab1f9ee..214b7dc28 100644 --- a/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml +++ b/maven-repository-discovery/src/test/repository/javax/sql/jdbc/maven-metadata-repository.xml @@ -1,3 +1,19 @@ + + javax.sql jdbc diff --git a/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml index 96d11ff31..17775863b 100644 --- a/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml +++ b/maven-repository-discovery/src/test/repository/javax/sql/maven-metadata-repository.xml @@ -1,3 +1,19 @@ + + javax.sql jdbc diff --git a/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata-repository.xml b/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata-repository.xml index e69de29bb..f94756148 100644 --- a/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata-repository.xml +++ b/maven-repository-discovery/src/test/repository/org/apache/maven/some-ejb/1.0/maven-metadata-repository.xml @@ -0,0 +1,16 @@ + + diff --git a/maven-repository-indexer/pom.xml b/maven-repository-indexer/pom.xml index 7d1fc5fd9..09d2d5481 100644 --- a/maven-repository-indexer/pom.xml +++ b/maven-repository-indexer/pom.xml @@ -1,3 +1,19 @@ + + diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java index 1ab604622..9d5e304c3 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.indexing; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -17,13 +16,13 @@ package org.apache.maven.repository.indexing; * limitations under the License. */ +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.IndexWriter; + import java.io.File; import java.io.IOException; import java.util.Collection; -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.index.IndexWriter; - /** * Abstract class for RepositoryIndexers * @@ -33,10 +32,13 @@ public abstract class AbstractRepositoryIndex implements RepositoryIndex { protected String indexPath; + protected boolean indexOpen; + protected IndexReader indexReader; + protected IndexWriter indexWriter; - + /** * method to encapsulate the optimize() method for lucene */ @@ -67,11 +69,11 @@ public abstract class AbstractRepositoryIndex { return indexOpen; } - + /** * method used to close all open streams to the index directory */ - public void close() + public void close() throws RepositoryIndexException { try @@ -112,7 +114,7 @@ public abstract class AbstractRepositoryIndex throw new RepositoryIndexException( e ); } } - + public String getIndexPath() { return indexPath; @@ -135,10 +137,10 @@ public abstract class AbstractRepositoryIndex indexReader = IndexReader.open( indexPath ); } } - + /** * method for validating an index directory - * + * * @throws RepositoryIndexException if the given indexPath is not valid for this type of RepositoryIndex */ protected void validateIndex() @@ -152,18 +154,18 @@ public abstract class AbstractRepositoryIndex { Collection fields = indexReader.getFieldNames(); String[] indexFields = getIndexFields(); - for( int idx=0; idx " + hits.length()); + //System.out.println("HITS SIZE --> " + hits.length()); - for ( int i = 0; i < hits.length(); i++ ) + for ( int i = 0; i < hits.length(); i++ ) { - Document doc = hits.doc( i ); + Document doc = hits.doc( i ); String groupId = doc.get( GROUPID ); String artifactId = doc.get( ARTIFACTID ); String version = doc.get( VERSION ); - String name = doc.get( NAME); + String name = doc.get( NAME ); String packaging = name.substring( name.lastIndexOf( '.' ) + 1 ); Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging ); - + artifactList.add( artifact ); - } - } + } + } catch ( Exception e ) { - e.printStackTrace(); - } + e.printStackTrace(); + } - return artifactList; - } + return artifactList; + } } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java index 39de6e6cc..29b8bc514 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.indexing; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -20,26 +19,29 @@ package org.apache.maven.repository.indexing; import org.apache.lucene.analysis.Analyzer; /** - * * @author Edwin Punzalan */ public interface RepositoryIndex { String ROLE = RepositoryIndex.class.getName(); - + String[] getIndexFields(); - + boolean isOpen(); - void index( Object obj ) throws RepositoryIndexException; + void index( Object obj ) + throws RepositoryIndexException; - void close() throws RepositoryIndexException; + void close() + throws RepositoryIndexException; - void open( String indexPath ) throws RepositoryIndexException; + void open( String indexPath ) + throws RepositoryIndexException; - void optimize() throws RepositoryIndexException; + void optimize() + throws RepositoryIndexException; Analyzer getAnalyzer(); - + String getIndexPath(); } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java index b323b9671..c9dd41e7f 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexException.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.indexing; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -18,7 +17,6 @@ package org.apache.maven.repository.indexing; */ /** - * * @author Edwin Punzalan */ public class RepositoryIndexException @@ -28,12 +26,12 @@ public class RepositoryIndexException { super( message, cause ); } - + public RepositoryIndexException( Throwable cause ) { super( cause ); } - + public RepositoryIndexException( String message ) { super( message ); diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java index 76309ba90..81ca498d5 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.indexing; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -22,18 +21,19 @@ import java.util.List; /** * */ -public interface RepositoryIndexSearcher { +public interface RepositoryIndexSearcher +{ - String ROLE = RepositoryIndexSearcher.class.getName(); - - /** - * Search the artifact that contains the query string in the specified - * search field. - * + String ROLE = RepositoryIndexSearcher.class.getName(); + + /** + * Search the artifact that contains the query string in the specified + * search field. + * * @param index - * @param queryString - * @param searchField - * @return - */ - public List search( RepositoryIndex index, String queryString, String searchField ); + * @param queryString + * @param searchField + * @return + */ + public List search( RepositoryIndex index, String queryString, String searchField ); } diff --git a/maven-repository-indexer/src/main/resources/META-INF/plexus/components.xml b/maven-repository-indexer/src/main/resources/META-INF/plexus/components.xml index 483ca418b..4cc04b397 100644 --- a/maven-repository-indexer/src/main/resources/META-INF/plexus/components.xml +++ b/maven-repository-indexer/src/main/resources/META-INF/plexus/components.xml @@ -1,3 +1,19 @@ + + diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java index 254fa1ddb..742545a94 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.indexing; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -9,7 +9,6 @@ package org.apache.maven.repository.indexing; * * 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. diff --git a/maven-repository-reports-standard/pom.xml b/maven-repository-reports-standard/pom.xml index 007fd95b7..02d2de17b 100755 --- a/maven-repository-reports-standard/pom.xml +++ b/maven-repository-reports-standard/pom.xml @@ -1,3 +1,19 @@ + + @@ -41,12 +57,12 @@ org.apache.maven maven-artifact-manager - + diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java index 7f2d4e43c..d024a934d 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayer.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -17,10 +16,6 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.io.File; -import java.io.FileReader; -import java.util.List; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; @@ -28,6 +23,10 @@ import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Snapshot; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; +import java.io.File; +import java.io.FileReader; +import java.util.List; + /** * */ @@ -53,15 +52,15 @@ public abstract class AbstractRepositoryQueryLayer throws RepositoryQueryLayerException { Metadata metadata = getMetadata( artifact ); - + return metadata.getVersioning().getVersions(); } protected String getSnapshotArtifactRepositoryPath( Artifact artifact, Snapshot snapshot ) { File f = new File( repository.getBasedir(), repository.pathOf( artifact ) ); - String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" + - snapshot.getBuildNumber() + ".pom" ); + String snapshotInfo = artifact.getVersion().replaceFirst( "SNAPSHOT", snapshot.getTimestamp() + "-" + + snapshot.getBuildNumber() + ".pom" ); File snapshotFile = new File( f.getParentFile(), artifact.getArtifactId() + "-" + snapshotInfo ); return snapshotFile.getAbsolutePath(); } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java index b965c537d..d7fad91c9 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReportProcessor.java @@ -1,20 +1,19 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.Artifact; @@ -22,8 +21,8 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Model; /** - * This interface will be called by the main system for each artifact as it is discovered. This is how each of the - * different types of reports are implemented. + * This interface will be called by the main system for each artifact as it is discovered. This is how each of the + * different types of reports are implemented. */ public interface ArtifactReportProcessor { diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java index 5b19ccdbc..4dfb93297 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactReporter.java @@ -1,19 +1,19 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.Artifact; @@ -33,15 +33,25 @@ public interface ArtifactReporter String ROLE = ArtifactReporter.class.getName(); public static String NULL_MODEL = "Provided model was null"; + public static String NULL_ARTIFACT = "Provided artifact was null"; + public static String EMPTY_GROUP_ID = "Group id was empty or null"; + public static String EMPTY_ARTIFACT_ID = "Artifact id was empty or null"; + public static String EMPTY_VERSION = "Version was empty or null"; + public static String EMPTY_DEPENDENCY_GROUP_ID = "Group id was empty or null"; + public static String EMPTY_DEPENDENCY_ARTIFACT_ID = "Artifact id was empty or null"; + public static String EMPTY_DEPENDENCY_VERSION = "Version was empty or null"; + public static String NO_DEPENDENCIES = "Artifact has no dependencies"; + public static String ARTIFACT_NOT_FOUND = "Artifact does not exist in the repository"; + public static String DEPENDENCY_NOT_FOUND = "Artifact's dependency does not exist in the repository"; void addFailure( Artifact artifact, String reason ); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java index fd91b9f6a..6c0aba900 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ArtifactResult.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java index 18e7c0e8c..645468d44 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/BadMetadataReportProcessor.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -46,14 +46,13 @@ public class BadMetadataReportProcessor private RepositoryQueryLayerFactory repositoryQueryLayerFactory; - + /** * Process the metadata encountered in the repository and report all errors found, if any. * * @param metadata the metadata to be processed. * @param repository the repository where the metadata was encountered * @param reporter the ArtifactReporter to receive processing results - * * @throws ReportProcessorException if an error was occurred while processing the metadata */ public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) @@ -105,7 +104,7 @@ public class BadMetadataReportProcessor } } } - + if ( !hasFailures ) { reporter.addSuccess( metadata ); @@ -120,7 +119,7 @@ public class BadMetadataReportProcessor * @param reporter the ArtifactReporter to receive processing results */ protected boolean checkPluginMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + ArtifactReporter reporter ) throws IOException { boolean hasFailures = false; @@ -144,7 +143,7 @@ public class BadMetadataReportProcessor String prefix = plugin.getPrefix(); if ( prefix == null || prefix.length() == 0 ) { - reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "."); + reporter.addFailure( metadata, "Missing or empty plugin prefix for artifactId " + artifactId + "." ); hasFailures = true; } else @@ -174,10 +173,10 @@ public class BadMetadataReportProcessor } } } - + if ( pluginDirs.size() > 0 ) { - for( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); ) + for ( Iterator plugins = pluginDirs.iterator(); plugins.hasNext(); ) { File plugin = (File) plugins.next(); reporter.addFailure( metadata, "Plugin " + plugin.getName() + " is present in the repository but " + @@ -197,7 +196,7 @@ public class BadMetadataReportProcessor * @param reporter the ArtifactReporter to receive processing results */ protected boolean checkSnapshotMetadata( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + ArtifactReporter reporter ) { RepositoryQueryLayer repositoryQueryLayer = repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); @@ -226,7 +225,7 @@ public class BadMetadataReportProcessor * @param reporter the ArtifactReporter to receive processing results */ protected boolean checkMetadataVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + ArtifactReporter reporter ) { RepositoryQueryLayer repositoryQueryLayer = repositoryQueryLayerFactory.createRepositoryQueryLayer( repository ); @@ -258,7 +257,7 @@ public class BadMetadataReportProcessor * @param reporter the ArtifactReporter to receive processing results */ protected boolean checkRepositoryVersions( RepositoryMetadata metadata, ArtifactRepository repository, - ArtifactReporter reporter ) + ArtifactReporter reporter ) throws IOException { boolean hasFailures = false; @@ -297,7 +296,7 @@ public class BadMetadataReportProcessor { return artifactFactory.createBuildArtifact( metadata.getGroupId(), metadata.getArtifactId(), version, "pom" ); } - + /** * Used to gather artifactIds from a groupId directory */ @@ -305,12 +304,12 @@ public class BadMetadataReportProcessor throws IOException { List artifactIdFiles = new ArrayList(); - + List fileArray = new ArrayList( Arrays.asList( groupIdDir.listFiles() ) ); - for( Iterator files=fileArray.iterator(); files.hasNext(); ) + for ( Iterator files = fileArray.iterator(); files.hasNext(); ) { File artifactDir = (File) files.next(); - + if ( artifactDir.isDirectory() ) { List versions = FileUtils.getFileNames( artifactDir, "*/*.pom", null, false ); @@ -320,7 +319,7 @@ public class BadMetadataReportProcessor } } } - + return artifactIdFiles; } } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java index 8c0e88d49..bb748b75d 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/Cache.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -22,17 +21,19 @@ import java.util.Map; /** * Class to implement caching - * */ public class Cache { private Map cache; private DblLinkedList mostRecent; + private double cacheHitRatio = 0; + private long cacheMaxSize = 0; - + private long cacheHits = 0; + private long cacheMiss = 0; /** @@ -53,27 +54,26 @@ public class Cache /** * Caches all data and expires only the oldest data when either the specified cache hit rate is reached - * or the maximum cache size is reached. + * or the maximum cache size is reached. */ public Cache( double cacheHitRatio, long cacheMaxSize ) { this.cacheHitRatio = cacheHitRatio; this.cacheMaxSize = cacheMaxSize; - + cache = new HashMap(); } - + /** * Check if the specified key is already mapped to an object. * * @param key the key used to map the cached object - * * @returns true if the cache contains an object associated with the given key */ public boolean containsKey( Object key ) { boolean contains = cache.containsKey( key ); - + if ( contains ) { cacheHits++; @@ -82,29 +82,28 @@ public class Cache { cacheMiss++; } - + return contains; } - + /** * Check for a cached object and return it if it exists. Returns null when the keyed object is not found * * @param key the key used to map the cached object - * * @returns the object mapped to the given key, or null if no cache object is mapped to the given key */ public Object get( Object key ) { Object retValue = null; - + if ( cache.containsKey( key ) ) { DblLinkedList cacheEntry = (DblLinkedList) cache.get( key ); - + makeMostRecent( cacheEntry ); - + retValue = cacheEntry.cacheValue; - + cacheHits++; } else @@ -147,7 +146,7 @@ public class Cache { return ( cacheHits == 0 && cacheMiss == 0 ) ? 0 : ( (double) cacheHits ) / (double) ( cacheHits + cacheMiss ); } - + /** * Get the total number of cache objects currently cached. */ @@ -155,14 +154,16 @@ public class Cache { return cache.size(); } - + /** * Empty the cache and reset the cache hit rate */ public void flush() { while ( cache.size() > 0 ) + { trimCache(); + } cacheHits = 0; cacheMiss = 0; cache = new HashMap(); @@ -186,10 +187,14 @@ public class Cache private void removeFromLinks( DblLinkedList list ) { if ( list.prev != null ) + { list.prev.next = list.next; + } if ( list.next != null ) + { list.next.prev = list.prev; - + } + list.prev = null; list.next = null; } @@ -207,7 +212,7 @@ public class Cache else if ( cache.size() > cacheMaxSize ) { // maximum cache size is reached - while( cache.size() > cacheMaxSize ) + while ( cache.size() > cacheMaxSize ) { trimCache(); } @@ -236,23 +241,29 @@ public class Cache mostRecent = null; } } - + private DblLinkedList getLeastRecent() { DblLinkedList trail = mostRecent; - while( trail.next != null ) + while ( trail.next != null ) + { trail = trail.next; + } return trail; } - private class DblLinkedList { + private class DblLinkedList + { Object cacheKey; + Object cacheValue; + DblLinkedList prev; + DblLinkedList next; - + public DblLinkedList( Object key, Object value ) { this.cacheKey = key; diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java index d1637cdd3..73e774320 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayer.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -17,18 +16,12 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.io.File; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.Map; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.metadata.Metadata; import org.apache.maven.artifact.repository.metadata.Snapshot; - /** * */ @@ -37,23 +30,23 @@ public class CachedRepositoryQueryLayer { private Cache cache; - + public CachedRepositoryQueryLayer( ArtifactRepository repository ) { this.repository = repository; - + cache = new Cache( 0.5 ); } - + public double getCacheHitRate() { return cache.getHitRate(); } - + public boolean containsArtifact( Artifact artifact ) { boolean artifactFound = true; - + // @todo should check for snapshot artifacts String artifactPath = repository.getBasedir() + "/" + repository.pathOf( artifact ); @@ -94,13 +87,13 @@ public class CachedRepositoryQueryLayer throws RepositoryQueryLayerException { Metadata metadata = (Metadata) cache.get( artifact.getId() ); - + if ( metadata == null ) { metadata = super.getMetadata( artifact ); cache.put( artifact.getId(), metadata ); } - + return metadata; } } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java index 44eebf136..ed77edd88 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ChecksumArtifactReporter.java @@ -1,22 +1,26 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import org.apache.maven.model.Model; + import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -27,13 +31,8 @@ import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; -import org.apache.maven.model.Model; -import org.apache.maven.artifact.repository.*; - /** - * This class reports invalid and mismatched checksums of artifacts and metadata files. + * This class reports invalid and mismatched checksums of artifacts and metadata files. * It validates MD5 and SHA-1 checksums. */ public class ChecksumArtifactReporter @@ -49,13 +48,14 @@ public class ChecksumArtifactReporter /** * Validate the checksum of the specified artifact. + * * @param model * @param artifact * @param reporter * @param repository */ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) + ArtifactRepository repository ) { //System.out.println( " " ); //System.out @@ -74,9 +74,9 @@ public class ChecksumArtifactReporter repositoryUrl = repository.getBasedir(); } - artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" - + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." - + artifact.getType(); + artifactUrl = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + + artifact.getType(); //check if checksum files exist boolean md5Exists = getMD5File( artifactUrl ); @@ -116,7 +116,7 @@ public class ChecksumArtifactReporter } /** - * Validate the checksums of the metadata. Get the metadata file from the + * Validate the checksums of the metadata. Get the metadata file from the * repository then validate the checksum. */ public void processMetadata( RepositoryMetadata metadata, ArtifactRepository repository, ArtifactReporter reporter ) @@ -141,8 +141,8 @@ public class ChecksumArtifactReporter if ( metadata.storedInArtifactVersionDirectory() == true && metadata.storedInGroupDirectory() == false ) { //version metadata - metadataUrl = repositoryUrl + metadata.getGroupId() + "/" + metadata.getArtifactId() + "/" - + metadata.getBaseVersion() + "/"; + metadataUrl = repositoryUrl + metadata.getGroupId() + "/" + metadata.getArtifactId() + "/" + + metadata.getBaseVersion() + "/"; } else if ( metadata.storedInArtifactVersionDirectory() == false && metadata.storedInGroupDirectory() == true ) { @@ -198,6 +198,7 @@ public class ChecksumArtifactReporter /** * Get the MD5 Checksum file. If not found, return false. + * * @param filename The name of the artifact whose MD5 Checksum file will be retrieved. * @return */ @@ -226,6 +227,7 @@ public class ChecksumArtifactReporter /** * Get the SHA1 Checksum file. If not found, return false. + * * @param filename The name of the artifact whose SHA-1 Checksum file will be retrieved. * @return */ @@ -253,8 +255,9 @@ public class ChecksumArtifactReporter /** * Validate the checksum of the file. + * * @param fileUrl The file to be validated. - * @param algo The checksum algorithm used. + * @param algo The checksum algorithm used. * @return */ protected boolean validateChecksum( String fileUrl, String algo ) @@ -267,7 +270,9 @@ public class ChecksumArtifactReporter //Create checksum for jar file String ext = ".md5"; if ( algo.equals( "SHA-1" ) ) + { ext = ".sha1"; + } chk1 = createChecksum( fileUrl, algo ); if ( chk1 != null ) { @@ -320,8 +325,9 @@ public class ChecksumArtifactReporter /** * Create a checksum from the specified metadata file. + * * @param filename The file that will be created a checksum. - * @param algo The algorithm to be used (MD5, SHA-1) + * @param algo The algorithm to be used (MD5, SHA-1) * @return * @throws FileNotFoundException * @throws NoSuchAlgorithmException @@ -364,6 +370,7 @@ public class ChecksumArtifactReporter /** * Convert an incoming array of bytes into a string that represents each of * the bytes as two hex characters. + * * @param data * @return */ @@ -383,7 +390,9 @@ public class ChecksumArtifactReporter //Append a leading 0 if necessary so that each hex string will contain 2 characters. if ( tempStr.length() == 1 ) + { tempStr = "0" + tempStr; + } //Concatenate the two characters to the output string. output = output + tempStr; diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java index cad66e62d..8af45d652 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReportProcessor.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,14 +16,14 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.apache.maven.model.Model; -import org.apache.maven.model.Dependency; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; -import java.util.List; import java.util.Iterator; +import java.util.List; /** * diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java index 18dac5ced..a0c167fea 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultArtifactReporter.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -20,9 +19,9 @@ package org.apache.maven.repository.reporting; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.ArrayList; /** * @@ -101,6 +100,7 @@ public class DefaultArtifactReporter { return metadataWarnings.iterator(); } + public int getFailures() { return artifactFailures.size() + metadataFailures.size(); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java index 73a0b9f4d..5570666dd 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,17 +16,7 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.metadata.Snapshot; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.util.List; -import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; -import org.apache.maven.artifact.repository.metadata.Metadata; -import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; /** * diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java index 32e3b79e9..204363768 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/DefaultRepositoryQueryLayerFactory.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java index 865ba7d64..620450dc6 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessor.java @@ -1,22 +1,27 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; @@ -26,70 +31,81 @@ import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - /** * This class validates well-formedness of pom xml file. */ public class InvalidPomArtifactReportProcessor implements ArtifactReportProcessor { - + /** * @param model - * @param artifact The pom xml file to be validated, passed as an artifact object. - * @param reporter The artifact reporter object. + * @param artifact The pom xml file to be validated, passed as an artifact object. + * @param reporter The artifact reporter object. * @param repository the repository where the artifact is located. */ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) + ArtifactRepository repository ) { - InputStream is = null; - - if((artifact.getType().toLowerCase()).equals("pom")){ - - if(repository.getProtocol().equals("file")){ - try{ - is = new FileInputStream(repository.getBasedir() + artifact.getGroupId() + "/" + - artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + - artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + - artifact.getType()); - }catch(FileNotFoundException fe){ - reporter.addFailure(artifact, "Artifact not found."); + InputStream is = null; + + if ( ( artifact.getType().toLowerCase() ).equals( "pom" ) ) + { + + if ( repository.getProtocol().equals( "file" ) ) + { + try + { + is = new FileInputStream( repository.getBasedir() + artifact.getGroupId() + "/" + + artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + + "-" + artifact.getBaseVersion() + "." + artifact.getType() ); } - }else{ - try{ - URL url = new URL(repository.getUrl() + artifact.getGroupId() + "/" + - artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + - artifact.getArtifactId() + "-" + artifact.getBaseVersion() + "." + - artifact.getType()); + catch ( FileNotFoundException fe ) + { + reporter.addFailure( artifact, "Artifact not found." ); + } + } + else + { + try + { + URL url = new URL( repository.getUrl() + artifact.getGroupId() + "/" + artifact.getArtifactId() + + "/" + artifact.getBaseVersion() + "/" + artifact.getArtifactId() + "-" + + artifact.getBaseVersion() + "." + artifact.getType() ); is = url.openStream(); - - }catch(MalformedURLException me){ - reporter.addFailure(artifact, "Error retrieving artifact from remote repository."); - }catch(IOException ie){ - reporter.addFailure(artifact, "Error retrieving artifact from remote repository."); + + } + catch ( MalformedURLException me ) + { + reporter.addFailure( artifact, "Error retrieving artifact from remote repository." ); + } + catch ( IOException ie ) + { + reporter.addFailure( artifact, "Error retrieving artifact from remote repository." ); } } - - Reader reader = new InputStreamReader(is); + + Reader reader = new InputStreamReader( is ); MavenXpp3Reader pomReader = new MavenXpp3Reader(); - - try{ - Model pomModel = pomReader.read(reader); - reporter.addSuccess(artifact); - }catch(XmlPullParserException xe){ - reporter.addFailure(artifact, "The pom xml file is not well-formed. Error while parsing."); - }catch(IOException oe){ - reporter.addFailure(artifact, "Error while reading the pom xml file."); + + try + { + Model pomModel = pomReader.read( reader ); + reporter.addSuccess( artifact ); + } + catch ( XmlPullParserException xe ) + { + reporter.addFailure( artifact, "The pom xml file is not well-formed. Error while parsing." ); } - - }else{ - reporter.addWarning(artifact, "The artifact is not a pom xml file."); + catch ( IOException oe ) + { + reporter.addFailure( artifact, "Error while reading the pom xml file." ); + } + + } + else + { + reporter.addWarning( artifact, "The artifact is not a pom xml file." ); } } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java index 2dd314396..fa5b847f6 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessor.java @@ -1,22 +1,27 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.FileUtils; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -28,12 +33,6 @@ import java.net.URL; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.util.FileUtils; - /** * Validate the location of the artifact based on the values indicated * in its pom (both the pom packaged with the artifact & the pom in the @@ -49,18 +48,18 @@ public class LocationArtifactReportProcessor /** * Check whether the artifact is in its proper location. The location of the artifact * is validated first against the groupId, artifactId and versionId in the specified model - * object (pom in the file system). Then unpack the artifact (jar file) and get the model (pom) - * included in the package. If a model exists inside the package, then check if the artifact's + * object (pom in the file system). Then unpack the artifact (jar file) and get the model (pom) + * included in the package. If a model exists inside the package, then check if the artifact's * location is valid based on the location specified in the pom. Check if the both the location * specified in the file system pom and in the pom included in the package is the same. - * - * @param model Represents the pom in the file system. - * @param artifact + * + * @param model Represents the pom in the file system. + * @param artifact * @param reporter * @param repository */ public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, - ArtifactRepository repository ) + ArtifactRepository repository ) { boolean fsPomLocation = false, pkgPomLocation = false; String repositoryUrl = "", modelArtifactLocation = ""; @@ -77,27 +76,27 @@ public class LocationArtifactReportProcessor //check if the artifact is located in its proper location based on the info //specified in the model object/pom - modelArtifactLocation = repositoryUrl + model.getGroupId() + "/" + model.getArtifactId() + "/" - + model.getVersion() + "/" + model.getArtifactId() + "-" + model.getVersion() + "." + model.getPackaging(); + modelArtifactLocation = repositoryUrl + model.getGroupId() + "/" + model.getArtifactId() + "/" + + model.getVersion() + "/" + model.getArtifactId() + "-" + model.getVersion() + "." + model.getPackaging(); fsPomLocation = validateArtifactLocation( modelArtifactLocation ); //get the location of the artifact itself - String artifactLocation = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" - + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." - + artifact.getType(); + String artifactLocation = repositoryUrl + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + + artifact.getVersion() + "/" + artifact.getArtifactId() + "-" + artifact.getVersion() + "." + + artifact.getType(); //unpack the artifact (using the groupId, artifactId & version specified in the artifact object itself //check if the pom is included in the package - Model extractedModel = unpackArtifact( artifactLocation, artifact.getGroupId(), artifact.getArtifactId(), - artifact.getVersion() ); + Model extractedModel = + unpackArtifact( artifactLocation, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); if ( extractedModel != null ) { - String pkgPomArtifactLocation = repositoryUrl + extractedModel.getGroupId() + "/" - + extractedModel.getArtifactId() + "/" + extractedModel.getVersion() + "/" - + extractedModel.getArtifactId() + "-" + extractedModel.getVersion() + "." - + extractedModel.getPackaging(); + String pkgPomArtifactLocation = repositoryUrl + extractedModel.getGroupId() + "/" + + extractedModel.getArtifactId() + "/" + extractedModel.getVersion() + "/" + + extractedModel.getArtifactId() + "-" + extractedModel.getVersion() + "." + + extractedModel.getPackaging(); pkgPomLocation = validateArtifactLocation( pkgPomArtifactLocation ); //check the conditions @@ -143,7 +142,7 @@ public class LocationArtifactReportProcessor /** * Validate the if the artifact exists in the specified location. - * + * * @param filename * @return */ @@ -172,7 +171,7 @@ public class LocationArtifactReportProcessor /** * Extract the contents of the artifact/jar file. - * + * * @param filename * @param groupId * @param artifactId diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java index aecfdfd35..0431a8adf 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/MetadataReportProcessor.java @@ -1,20 +1,19 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.artifact.repository.ArtifactRepository; diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java index 5c1fa2a81..5f73dbdc0 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/ReportProcessorException.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java index 0d10ea4f5..4c962986a 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryMetadataResult.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java index f6b92fb7a..942b052fe 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayer.java @@ -1,26 +1,26 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.metadata.Snapshot; +import java.util.List; + /** * The transitive and metadata validation reports will need to query the repository for artifacts. */ @@ -29,11 +29,13 @@ public interface RepositoryQueryLayer String ROLE = RepositoryQueryLayer.class.getName(); public final static boolean ARTIFACT_FOUND = true; + public final static boolean ARTIFACT_NOT_FOUND = false; boolean containsArtifact( Artifact artifact ); boolean containsArtifact( Artifact artifact, Snapshot snapshot ); - - List getVersions( Artifact artifact ) throws RepositoryQueryLayerException; + + List getVersions( Artifact artifact ) + throws RepositoryQueryLayerException; } diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java index bdfd2b368..ae7f77947 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerException.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -27,7 +26,7 @@ public class RepositoryQueryLayerException { super( message, cause ); } - + public RepositoryQueryLayerException( String message ) { super( message ); diff --git a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java index e001c32fa..00f42b30d 100644 --- a/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java +++ b/maven-repository-reports-standard/src/main/java/org/apache/maven/repository/reporting/RepositoryQueryLayerFactory.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml b/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml index 5c8112e0b..f7e3e17cd 100644 --- a/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml +++ b/maven-repository-reports-standard/src/main/resources/META-INF/plexus/components.xml @@ -1,3 +1,19 @@ + + @@ -18,28 +34,28 @@ - org.apache.maven.repository.reporting.ArtifactReportProcessor - checksum - org.apache.maven.repository.reporting.ChecksumArtifactReporter - per-lookup + org.apache.maven.repository.reporting.ArtifactReportProcessor + checksum + org.apache.maven.repository.reporting.ChecksumArtifactReporter + per-lookup - org.apache.maven.repository.reporting.MetadataReportProcessor - checksum-metadata - org.apache.maven.repository.reporting.ChecksumArtifactReporter - per-lookup + org.apache.maven.repository.reporting.MetadataReportProcessor + checksum-metadata + org.apache.maven.repository.reporting.ChecksumArtifactReporter + per-lookup - org.apache.maven.repository.reporting.ArtifactReportProcessor - artifact-location - org.apache.maven.repository.reporting.LocationArtifactReportProcessor - per-lookup - + org.apache.maven.repository.reporting.ArtifactReportProcessor + artifact-location + org.apache.maven.repository.reporting.LocationArtifactReportProcessor + per-lookup + - org.apache.maven.repository.reporting.ArtifactReportProcessor - invalid-pom - org.apache.maven.repository.reporting.InvalidPomArtifactReportProcessor - per-lookup - + org.apache.maven.repository.reporting.ArtifactReportProcessor + invalid-pom + org.apache.maven.repository.reporting.InvalidPomArtifactReportProcessor + per-lookup + diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java index 74c823bc8..17e98347c 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractChecksumArtifactReporterTest.java @@ -1,22 +1,23 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.codehaus.plexus.util.FileUtils; + import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.File; @@ -32,7 +33,6 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; -import org.codehaus.plexus.util.FileUtils; /** * This class creates the artifact and metadata files used for testing the ChecksumArtifactReporter. @@ -41,9 +41,9 @@ import org.codehaus.plexus.util.FileUtils; public class AbstractChecksumArtifactReporterTest extends AbstractRepositoryReportsTestCase { - protected static final String[] validArtifactChecksumJars = { "validArtifact-1.0" }; + protected static final String[] validArtifactChecksumJars = {"validArtifact-1.0"}; - protected static final String[] invalidArtifactChecksumJars = { "invalidArtifact-1.0" }; + protected static final String[] invalidArtifactChecksumJars = {"invalidArtifact-1.0"}; protected static final String metadataChecksumFilename = "maven-metadata-repository"; @@ -65,6 +65,7 @@ public class AbstractChecksumArtifactReporterTest /** * Create checksum files. + * * @param type The type of checksum file to be created. * @return */ @@ -101,6 +102,7 @@ public class AbstractChecksumArtifactReporterTest /** * Create checksum files for metadata. + * * @param type The type of checksum to be created. (Valid or invalid) * @return */ @@ -126,10 +128,11 @@ public class AbstractChecksumArtifactReporterTest /** * Create artifact together with its checksums. + * * @param relativePath The groupId - * @param filename The filename of the artifact to be created. - * @param type The file type (JAR) - * @param isValid Indicates whether the checksum to be created is valid or not. + * @param filename The filename of the artifact to be created. + * @param type The file type (JAR) + * @param isValid Indicates whether the checksum to be created is valid or not. * @return */ private boolean writeChecksumFile( String relativePath, String filename, String type, boolean isValid ) @@ -182,9 +185,13 @@ public class AbstractChecksumArtifactReporterTest OutputStream os = new FileOutputStream( file ); OutputStreamWriter osw = new OutputStreamWriter( os ); if ( !isValid ) + { osw.write( byteArrayToHexStr( md5chk ) + "1" ); + } else + { osw.write( byteArrayToHexStr( md5chk ) ); + } osw.close(); } @@ -194,9 +201,13 @@ public class AbstractChecksumArtifactReporterTest OutputStream os = new FileOutputStream( file ); OutputStreamWriter osw = new OutputStreamWriter( os ); if ( !isValid ) + { osw.write( byteArrayToHexStr( sha1chk ) + "2" ); + } else + { osw.write( byteArrayToHexStr( sha1chk ) ); + } osw.close(); } } @@ -210,10 +221,11 @@ public class AbstractChecksumArtifactReporterTest /** * Create metadata file together with its checksums. + * * @param relativePath The groupId - * @param filename The filename of the artifact to be created. - * @param type The file type (JAR) - * @param isValid Indicates whether the checksum to be created is valid or not. + * @param filename The filename of the artifact to be created. + * @param type The file type (JAR) + * @param isValid Indicates whether the checksum to be created is valid or not. * @return */ private boolean writeMetadataFile( String relativePath, String filename, String type, boolean isValid ) @@ -242,9 +254,13 @@ public class AbstractChecksumArtifactReporterTest OutputStream os = new FileOutputStream( file ); OutputStreamWriter osw = new OutputStreamWriter( os ); if ( !isValid ) + { osw.write( byteArrayToHexStr( md5chk ) + "1" ); + } else + { osw.write( byteArrayToHexStr( md5chk ) ); + } osw.close(); } @@ -254,9 +270,13 @@ public class AbstractChecksumArtifactReporterTest OutputStream os = new FileOutputStream( file ); OutputStreamWriter osw = new OutputStreamWriter( os ); if ( !isValid ) + { osw.write( byteArrayToHexStr( sha1chk ) + "2" ); + } else + { osw.write( byteArrayToHexStr( sha1chk ) ); + } osw.close(); } } @@ -271,6 +291,7 @@ public class AbstractChecksumArtifactReporterTest /** * Create the sample file that will be included in the jar. + * * @param filename * @return */ @@ -293,7 +314,7 @@ public class AbstractChecksumArtifactReporterTest /** * Create a checksum from the specified metadata file. - * + * * @param metadataUrl * @return * @throws FileNotFoundException @@ -326,6 +347,7 @@ public class AbstractChecksumArtifactReporterTest /** * Convert an incoming array of bytes into a string that represents each of * the bytes as two hex characters. + * * @param data * @return */ @@ -341,7 +363,9 @@ public class AbstractChecksumArtifactReporterTest tempStr = Integer.toHexString( tempInt ); if ( tempStr.length() == 1 ) + { tempStr = "0" + tempStr; + } output = output + tempStr; } @@ -350,6 +374,7 @@ public class AbstractChecksumArtifactReporterTest /** * Delete the test directory created in the repository. + * * @param dirname The directory to be deleted. * @return */ @@ -377,7 +402,6 @@ public class AbstractChecksumArtifactReporterTest } /** - * * @return */ protected boolean deleteChecksumFiles( String type ) @@ -388,29 +412,39 @@ public class AbstractChecksumArtifactReporterTest //delete valid checksum files of artifacts created for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) { - b = deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) - + "/" + validArtifactChecksumJars[i] + "." + type + ".md5" ); + b = deleteFile( repository.getBasedir() + "checksumTest/" + + validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + validArtifactChecksumJars[i] + "." + type + + ".md5" ); if ( b == false ) + { return b; + } - b = deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) - + "/" + validArtifactChecksumJars[i] + "." + type + ".sha1" ); + b = deleteFile( repository.getBasedir() + "checksumTest/" + + validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + validArtifactChecksumJars[i] + "." + type + + ".sha1" ); if ( b == false ) + { return b; + } } //delete valid checksum files of metadata file for ( int i = 0; i < validArtifactChecksumJars.length; i++ ) { - b = deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) - + "/" + metadataChecksumFilename + ".xml.md5" ); + b = deleteFile( repository.getBasedir() + "checksumTest/" + + validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + metadataChecksumFilename + ".xml.md5" ); if ( b == false ) + { return b; + } - b = deleteFile( repository.getBasedir() + "checksumTest/" + validArtifactChecksumJars[i].replace( '-', '/' ) - + "/" + metadataChecksumFilename + ".xml.sha1" ); + b = deleteFile( repository.getBasedir() + "checksumTest/" + + validArtifactChecksumJars[i].replace( '-', '/' ) + "/" + metadataChecksumFilename + ".xml.sha1" ); if ( b == false ) + { return b; + } } return b; } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java index b1633a826..79cf227d3 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryQueryLayerTest.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -17,18 +16,17 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import java.io.File; -import java.util.List; - import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.repository.metadata.Snapshot; - import org.codehaus.plexus.PlexusTestCase; +import java.io.File; +import java.util.List; + /** * */ @@ -36,12 +34,13 @@ public abstract class AbstractRepositoryQueryLayerTest extends PlexusTestCase { protected ArtifactFactory artifactFactory; - + protected ArtifactRepository repository; - + protected CachedRepositoryQueryLayer queryLayer; - - protected void setUp() throws Exception + + protected void setUp() + throws Exception { super.setUp(); File repositoryDirectory = getTestFile( "src/test/repository" ); @@ -57,14 +56,14 @@ public abstract class AbstractRepositoryQueryLayerTest public void testContainsArtifactTrue() { Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-alpha-1" ); - + assertTrue( "check artifact", queryLayer.containsArtifact( artifact ) ); } public void testContainsArtifactFalse() { Artifact artifact = getArtifact( "groupId", "artifactId", "1.0-beta-1" ); - + assertFalse( "check non-existent artifact", queryLayer.containsArtifact( artifact ) ); } @@ -73,7 +72,7 @@ public abstract class AbstractRepositoryQueryLayerTest Snapshot snapshot = new Snapshot(); snapshot.setTimestamp( "20050611.202024" ); snapshot.setBuildNumber( 1 ); - + Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); assertTrue( "check for snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); } @@ -83,18 +82,18 @@ public abstract class AbstractRepositoryQueryLayerTest Snapshot snapshot = new Snapshot(); snapshot.setTimestamp( "20050611.202024" ); snapshot.setBuildNumber( 2 ); - + Artifact artifact = getArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT" ); assertFalse( "check for non-existent snapshot artifact", queryLayer.containsArtifact( artifact, snapshot ) ); } - + public void testArtifactVersionsTrue() throws Exception { Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); - + List versions = queryLayer.getVersions( artifact ); - + assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); @@ -104,18 +103,18 @@ public abstract class AbstractRepositoryQueryLayerTest throws Exception { Artifact artifact = getArtifact( "groupId", "artifactId", "ignored" ); - + List versions = queryLayer.getVersions( artifact ); - + assertTrue( "check version 1.0-alpha-1", versions.contains( "1.0-alpha-1" ) ); assertTrue( "check version 1.0-alpha-2", versions.contains( "1.0-alpha-2" ) ); assertFalse( "check version 1.0-alpha-3", versions.contains( "1.0-alpha-3" ) ); } - + public void testArtifactVersionsError() { Artifact artifact = getArtifact( "groupId", "none", "ignored" ); - + try { queryLayer.getVersions( artifact ); @@ -132,7 +131,8 @@ public abstract class AbstractRepositoryQueryLayerTest return artifactFactory.createBuildArtifact( groupId, artifactId, version, "pom" ); } - protected void tearDown() throws Exception + protected void tearDown() + throws Exception { release( artifactFactory ); super.tearDown(); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java index 8d71ea4cb..45f12964e 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/AbstractRepositoryReportsTestCase.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -48,7 +47,7 @@ public abstract class AbstractRepositoryReportsTestCase protected static final String remoteArtifactType = "jar"; protected static final String remoteRepoId = "remote-repo"; - + protected void setUp() throws Exception { @@ -58,8 +57,8 @@ public abstract class AbstractRepositoryReportsTestCase ArtifactRepositoryFactory factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE ); ArtifactRepositoryLayout layout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" ); - repository = - factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout, null, null ); + repository = factory.createArtifactRepository( "repository", repositoryDirectory.toURL().toString(), layout, + null, null ); } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java index ffb915d39..cd6bd7869 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReportProcessorTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,9 +16,9 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.apache.maven.model.Model; -import org.apache.maven.model.Dependency; import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; import java.util.Iterator; diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java index a5d3b7094..91c9015ad 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ArtifactReporterTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,8 +16,8 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.repository.metadata.Versioning; import org.apache.maven.model.Model; diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java index df6fa3bcc..a3368e5a4 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/BadMetadataReportProcessorTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -29,7 +29,7 @@ import org.apache.maven.artifact.repository.metadata.Versioning; import java.util.Iterator; /** - * @todo??? should use MetadataXpp3Reader instead ? + * @todo??? should use MetadataXpp3Reader instead ? */ public class BadMetadataReportProcessorTest extends AbstractRepositoryReportsTestCase @@ -47,7 +47,7 @@ public class BadMetadataReportProcessorTest badMetadataReportProcessor = (MetadataReportProcessor) lookup( MetadataReportProcessor.ROLE ); } - + public void testMetadataMissingLastUpdated() throws ReportProcessorException { @@ -67,12 +67,10 @@ public class BadMetadataReportProcessorTest assertTrue( "check there is a failure", failures.hasNext() ); RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); assertEquals( "check metadata", metadata, result.getMetadata() ); - assertEquals( "check reason", - "Missing lastUpdated element inside the metadata.", - result.getReason() ); + assertEquals( "check reason", "Missing lastUpdated element inside the metadata.", result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testMetadataValidVersions() throws ReportProcessorException { @@ -118,7 +116,7 @@ public class BadMetadataReportProcessorTest result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testMetadataInvalidArtifactVersion() throws ReportProcessorException { @@ -146,7 +144,7 @@ public class BadMetadataReportProcessorTest result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testMoreThanOneMetadataVersionErrors() throws ReportProcessorException { @@ -188,13 +186,13 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); assertFalse( "check there are no failures", failures.hasNext() ); } - + public void testMissingMetadataPlugin() throws ReportProcessorException { @@ -204,14 +202,15 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "missing-plugin", "default3" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); Iterator failures = reporter.getRepositoryMetadataFailureIterator(); assertTrue( "check there is a failure", failures.hasNext() ); RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); // TODO: should be more robust - assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository", result.getReason() ); + assertEquals( "check reason", "Metadata plugin missing-plugin not found in the repository", + result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } @@ -222,18 +221,19 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); Iterator failures = reporter.getRepositoryMetadataFailureIterator(); assertTrue( "check there is a failure", failures.hasNext() ); RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); // TODO: should be more robust - assertEquals( "check reason", "Plugin snapshot-artifact is present in the repository but " + - "missing in the metadata.", result.getReason() ); + assertEquals( "check reason", + "Plugin snapshot-artifact is present in the repository but " + "missing in the metadata.", + result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testInvalidPluginArtifactId() throws ReportProcessorException { @@ -244,7 +244,7 @@ public class BadMetadataReportProcessorTest metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default2" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( null, "default3" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "", "default4" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); Iterator failures = reporter.getRepositoryMetadataFailureIterator(); @@ -258,7 +258,7 @@ public class BadMetadataReportProcessorTest assertEquals( "check reason", "Missing or empty artifactId in group metadata.", result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testInvalidPluginPrefix() throws ReportProcessorException { @@ -267,7 +267,7 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", null ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); Iterator failures = reporter.getRepositoryMetadataFailureIterator(); @@ -278,10 +278,11 @@ public class BadMetadataReportProcessorTest assertTrue( "check there is a 2nd failure", failures.hasNext() ); result = (RepositoryMetadataResult) failures.next(); // TODO: should be more robust - assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.", result.getReason() ); + assertEquals( "check reason", "Missing or empty plugin prefix for artifactId snapshot-artifact.", + result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + public void testDuplicatePluginPrefixes() throws ReportProcessorException { @@ -290,7 +291,7 @@ public class BadMetadataReportProcessorTest RepositoryMetadata metadata = new GroupRepositoryMetadata( "groupId" ); metadata.getMetadata().addPlugin( createMetadataPlugin( "artifactId", "default" ) ); metadata.getMetadata().addPlugin( createMetadataPlugin( "snapshot-artifact", "default" ) ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); Iterator failures = reporter.getRepositoryMetadataFailureIterator(); @@ -305,18 +306,18 @@ public class BadMetadataReportProcessorTest throws ReportProcessorException { ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", - "1.0-alpha-1-SNAPSHOT", "type" ); + + Artifact artifact = + artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); Snapshot snapshot = new Snapshot(); snapshot.setBuildNumber( 1 ); snapshot.setTimestamp( "20050611.202024" ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); assertFalse( "check there are no failures", failures.hasNext() ); } @@ -325,18 +326,18 @@ public class BadMetadataReportProcessorTest throws ReportProcessorException { ArtifactReporter reporter = new MockArtifactReporter(); - - Artifact artifact = artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", - "1.0-alpha-1-SNAPSHOT", "type" ); + + Artifact artifact = + artifactFactory.createBuildArtifact( "groupId", "snapshot-artifact", "1.0-alpha-1-SNAPSHOT", "type" ); Snapshot snapshot = new Snapshot(); snapshot.setBuildNumber( 2 ); snapshot.setTimestamp( "20050611.202024" ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact, snapshot ); - + badMetadataReportProcessor.processMetadata( metadata, repository, reporter ); - + Iterator failures = reporter.getRepositoryMetadataFailureIterator(); assertTrue( "check there is a failure", failures.hasNext() ); RepositoryMetadataResult result = (RepositoryMetadataResult) failures.next(); @@ -345,7 +346,7 @@ public class BadMetadataReportProcessorTest assertEquals( "check reason", "Snapshot artifact 20050611.202024-2 does not exist.", result.getReason() ); assertFalse( "check no more failures", failures.hasNext() ); } - + private Plugin createMetadataPlugin( String artifactId, String prefix ) { Plugin plugin = new Plugin(); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java index deebd0c9b..16698ffdf 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CacheTest.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -31,19 +30,19 @@ public class CacheTest { cache = new Cache( 0.5 ); newCacheObjectTests(); - + String key = "key"; String value = "value"; - for( int ctr=1; ctr<10; ctr++ ) + for ( int ctr = 1; ctr < 10; ctr++ ) { cache.put( key + ctr, value + ctr ); } - + while ( cache.getHitRate() < 0.75 ) { cache.get( "key2" ); } - cache.put( "key10", "value10"); + cache.put( "key10", "value10" ); assertNull( "first key must be expired", cache.get( "key1" ) ); } @@ -51,15 +50,15 @@ public class CacheTest { cache = new Cache( 9 ); newCacheObjectTests(); - + String key = "key"; String value = "value"; - for( int ctr=1; ctr<10; ctr++ ) + for ( int ctr = 1; ctr < 10; ctr++ ) { cache.put( key + ctr, value + ctr ); } - - cache.put( "key10", "value10"); + + cache.put( "key10", "value10" ); assertNull( "first key must be expired", cache.get( "key1" ) ); assertEquals( "check cache size to be max size", 9, cache.size() ); } @@ -68,10 +67,10 @@ public class CacheTest { cache = new Cache( 0.5, 9 ); newCacheObjectTests(); - + String key = "key"; String value = "value"; - for( int ctr=1; ctr<5; ctr++ ) + for ( int ctr = 1; ctr < 5; ctr++ ) { cache.put( key + ctr, value + ctr ); } @@ -80,21 +79,21 @@ public class CacheTest { cache.get( "key3" ); } - - cache.put( "key10", "value10"); + + cache.put( "key10", "value10" ); assertNull( "first key must be expired", cache.get( "key1" ) ); while ( cache.getHitRate() >= 0.5 ) { cache.get( "key11" ); } - - for( int ctr=5; ctr<10; ctr++ ) + + for ( int ctr = 5; ctr < 10; ctr++ ) { cache.put( key + ctr, value + ctr ); } - - cache.put( "key11", "value11"); + + cache.put( "key11", "value11" ); assertNull( "second key must be expired", cache.get( "key2" ) ); assertEquals( "check cache size to be max size", 9, cache.size() ); } @@ -103,16 +102,16 @@ public class CacheTest { cache = new Cache( 0.5, 9 ); newCacheObjectTests(); - + String key = "key"; String value = "value"; - for( int ctr=1; ctr<10; ctr++ ) + for ( int ctr = 1; ctr < 10; ctr++ ) { cache.put( key + ctr, value + ctr ); } - - cache.put( "key1", "value1"); - cache.put( "key10", "value10"); + + cache.put( "key1", "value1" ); + cache.put( "key10", "value10" ); assertNull( "second key must be gone", cache.get( "key2" ) ); assertEquals( "check cache size to be max size", 9, cache.size() ); } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java index 984f07ddd..de18378a7 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/CachedRepositoryQueryLayerTest.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -23,13 +22,14 @@ package org.apache.maven.repository.reporting; public class CachedRepositoryQueryLayerTest extends AbstractRepositoryQueryLayerTest { - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); - + queryLayer = new CachedRepositoryQueryLayer( repository ); } - + public void testUseFileCache() { testContainsArtifactTrue(); @@ -37,7 +37,7 @@ public class CachedRepositoryQueryLayerTest testContainsArtifactTrue(); assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 ); } - + public void testUseMetadataCache() throws Exception { @@ -46,7 +46,7 @@ public class CachedRepositoryQueryLayerTest testArtifactVersionsTrue(); assertEquals( 0.50, queryLayer.getCacheHitRate(), 0 ); } - + public void testUseFileCacheOnSnapshot() { testContainsSnapshotArtifactTrue(); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java index 190576998..6225dc05d 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ChecksumArtifactReporterTest.java @@ -1,39 +1,36 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.File; -import java.util.Iterator; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.GroupRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.versioning.VersionRange; -/** - * This class tests the ChecksumArtifactReporter. +import java.io.File; +import java.util.Iterator; + +/** + * This class tests the ChecksumArtifactReporter. * It extends the AbstractChecksumArtifactReporterTest class. */ public class ChecksumArtifactReporterTest @@ -91,8 +88,8 @@ public class ChecksumArtifactReporterTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); assertTrue( reporter.getSuccesses() == 2 ); @@ -115,8 +112,8 @@ public class ChecksumArtifactReporterTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); assertTrue( reporter.getFailures() == 2 ); @@ -129,7 +126,7 @@ public class ChecksumArtifactReporterTest } /** - * Test the valid checksum of a metadata file. + * Test the valid checksum of a metadata file. * The reporter should report 2 success validation. */ public void testChecksumMetadataReporterSuccess() @@ -139,8 +136,8 @@ public class ChecksumArtifactReporterTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); //Version level metadata RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); @@ -166,7 +163,7 @@ public class ChecksumArtifactReporterTest } /** - * Test the corrupted checksum of a metadata file. + * Test the corrupted checksum of a metadata file. * The reporter must report 2 failures. */ public void testChecksumMetadataReporterFailure() @@ -176,8 +173,8 @@ public class ChecksumArtifactReporterTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "invalidArtifact", version, "compile", "jar", "", handler ); RepositoryMetadata metadata = new SnapshotArtifactRepositoryMetadata( artifact ); metadataReportProcessor.processMetadata( metadata, repository, reporter ); @@ -198,7 +195,7 @@ public class ChecksumArtifactReporterTest /** * Test the checksum of an artifact located in a remote location. */ - /* public void testChecksumArtifactRemote() + /* public void testChecksumArtifactRemote() { ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); @@ -220,7 +217,7 @@ public class ChecksumArtifactReporterTest /** * Test the checksum of a metadata file located in a remote location. */ - /* public void testChecksumMetadataRemote() + /* public void testChecksumMetadataRemote() { try @@ -280,8 +277,8 @@ public class ChecksumArtifactReporterTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0" ); - Artifact artifact = new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "checksumTest", "validArtifact", version, "compile", "jar", "", handler ); artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); //System.out.println( "5 - ART FAILURE ---> " + reporter.getFailures() ); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java index 89296b8e3..eabf37e48 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/DefaultArtifactReporterTest.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -28,14 +28,14 @@ import java.util.Iterator; * */ public class DefaultArtifactReporterTest - extends AbstractRepositoryReportsTestCase + extends AbstractRepositoryReportsTestCase { private ArtifactReporter reporter; - + private Artifact artifact; - + private RepositoryMetadata metadata; - + public void testEmptyArtifactReporter() { assertEquals( "No failures", 0, reporter.getFailures() ); @@ -48,7 +48,7 @@ public class DefaultArtifactReporterTest assertFalse( "No metadata warnings", reporter.getRepositoryMetadataWarningIterator().hasNext() ); assertFalse( "No metadata successes", reporter.getRepositoryMetadataSuccessIterator().hasNext() ); } - + public void testMetadataSingleFailure() { reporter.addFailure( metadata, "Single Failure Reason" ); @@ -63,7 +63,7 @@ public class DefaultArtifactReporterTest assertEquals( "check failure reason", "Single Failure Reason", result.getReason() ); assertFalse( "no more failures", results.hasNext() ); } - + public void testMetadataMultipleFailures() { reporter.addFailure( metadata, "First Failure Reason" ); @@ -98,7 +98,7 @@ public class DefaultArtifactReporterTest assertEquals( "check failure reason", "Single Warning Message", result.getReason() ); assertFalse( "no more failures", results.hasNext() ); } - + public void testMetadataMultipleWarnings() { reporter.addWarning( metadata, "First Warning" ); @@ -133,14 +133,14 @@ public class DefaultArtifactReporterTest assertNull( "check no reason", result.getReason() ); assertFalse( "no more failures", results.hasNext() ); } - + public void testMetadataMultipleSuccesses() { Versioning versioning = new Versioning(); versioning.addVersion( "1.0-beta-1" ); - versioning.addVersion( "1.0-beta-2" ); + versioning.addVersion( "1.0-beta-2" ); RepositoryMetadata metadata2 = new ArtifactRepositoryMetadata( artifact, versioning ); - + reporter.addSuccess( metadata ); reporter.addSuccess( metadata2 ); assertEquals( "failures count", 0, reporter.getFailures() ); @@ -159,24 +159,26 @@ public class DefaultArtifactReporterTest assertFalse( "no more successes", results.hasNext() ); } - protected void setUp() throws Exception + protected void setUp() + throws Exception { super.setUp(); - + reporter = new DefaultArtifactReporter(); ArtifactFactory artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); artifact = artifactFactory.createBuildArtifact( "groupId", "artifactId", "1.0-alpha-1", "type" ); Versioning versioning = new Versioning(); versioning.addVersion( "1.0-alpha-1" ); - versioning.addVersion( "1.0-alpha-2" ); + versioning.addVersion( "1.0-alpha-2" ); RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact, versioning ); } - protected void tearDown() throws Exception + protected void tearDown() + throws Exception { super.tearDown(); - + reporter = null; metadata = null; } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java index a07034b72..9e9bfc759 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/GenericMockObject.java @@ -1,14 +1,13 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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, @@ -19,42 +18,46 @@ package org.apache.maven.repository.reporting; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** - * * @author Edwin Punzalan */ -public class GenericMockObject implements InvocationHandler +public class GenericMockObject + implements InvocationHandler { Map invocations = new HashMap(); - + public GenericMockObject() { //default constructor } - + public GenericMockObject( Map returnMap ) { invocations = returnMap; } - + public void setExpectedReturns( Method method, List returnList ) { invocations.put( method, returnList ); } - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable + public Object invoke( Object proxy, Method method, Object[] args ) + throws Throwable { - if ( !invocations.containsKey( method ) ) + if ( !invocations.containsKey( method ) ) + { throw new UnsupportedOperationException( "No expected return values defined." ); - + } + List returnList = (List) invocations.get( method ); - if ( returnList.size() < 1 ) throw new UnsupportedOperationException( "Too few expected return values defined." ); + if ( returnList.size() < 1 ) + { + throw new UnsupportedOperationException( "Too few expected return values defined." ); + } return returnList.remove( 0 ); } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java index 2da65de80..e03d8f172 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/InvalidPomArtifactReportProcessorTest.java @@ -1,117 +1,127 @@ package org.apache.maven.repository.reporting; +/* + * Copyright 2005-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.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.versioning.VersionRange; -/* - * Copyright 2001-2005 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. - */ - /** * This class tests the InvalidPomArtifactReportProcessor class. */ -public class InvalidPomArtifactReportProcessorTest +public class InvalidPomArtifactReportProcessorTest extends AbstractRepositoryReportsTestCase { private ArtifactReportProcessor artifactReportProcessor; private ArtifactReporter reporter = new MockArtifactReporter(); - - public void setUp() throws Exception{ + + public void setUp() + throws Exception + { super.setUp(); artifactReportProcessor = (ArtifactReportProcessor) lookup( ArtifactReportProcessor.ROLE, "invalid-pom" ); } - - public void tearDown() throws Exception{ + + public void tearDown() + throws Exception + { super.tearDown(); } - + /** * Test the InvalidPomArtifactReportProcessor when the artifact is an invalid pom. */ - public void testInvalidPomArtifactReportProcessorFailure(){ - - try{ + public void testInvalidPomArtifactReportProcessorFailure() + { + + try + { ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); VersionRange version = VersionRange.createFromVersion( "1.0-alpha-3" ); - Artifact artifact = new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", - handler ); - - artifactReportProcessor.processArtifact(null, artifact, reporter, repository); - assertTrue(reporter.getFailures() == 1); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "artifactId", version, "compile", "pom", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertTrue( reporter.getFailures() == 1 ); //System.out.println("INVALID POM ARTIFACT FAILURES --->> " + reporter.getFailures()); - - }catch(Exception e){ - + + } + catch ( Exception e ) + { + } } - - + + /** * Test the InvalidPomArtifactReportProcessor when the artifact is a valid pom. */ - public void testInvalidPomArtifactReportProcessorSuccess(){ - - try{ + public void testInvalidPomArtifactReportProcessorSuccess() + { + + try + { ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", - handler ); - - artifactReportProcessor.processArtifact(null, artifact, reporter, repository); - assertTrue(reporter.getSuccesses() == 1); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "pom", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertTrue( reporter.getSuccesses() == 1 ); //System.out.println("VALID POM ARTIFACT SUCCESS --->> " + reporter.getSuccesses()); - - }catch(Exception e){ - + + } + catch ( Exception e ) + { + } } - - + + /** * Test the InvalidPomArtifactReportProcessor when the artifact is not a pom. */ - public void testNotAPomArtifactReportProcessorSuccess(){ - - try{ + public void testNotAPomArtifactReportProcessorSuccess() + { + + try + { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); - Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", - handler ); - - artifactReportProcessor.processArtifact(null, artifact, reporter, repository); - assertTrue(reporter.getWarnings() == 1); + Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); + + artifactReportProcessor.processArtifact( null, artifact, reporter, repository ); + assertTrue( reporter.getWarnings() == 1 ); //System.out.println("NOT A POM ARTIFACT WARNINGS --->> " + reporter.getWarnings()); - - }catch(Exception e){ - + + } + catch ( Exception e ) + { + } } - + /** * Test the InvalidPomArtifactReportProcessor when the pom is located in * a remote repository. */ - /* public void testRemotePomArtifactReportProcessorSuccess(){ + /* public void testRemotePomArtifactReportProcessorSuccess(){ try{ ArtifactHandler handler = new DefaultArtifactHandler( "pom" ); VersionRange version = VersionRange.createFromVersion( remoteArtifactVersion ); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java index 08b9e6576..fcffd36fa 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/LocationArtifactReportProcessorTest.java @@ -1,41 +1,36 @@ package org.apache.maven.repository.reporting; -/* - * Copyright 2001-2005 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 - * +/* + * Copyright 2005-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. + * + * 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.FileInputStream; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.net.URL; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.DefaultArtifactRepository; -import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; + /** * This class tests the LocationArtifactReportProcessor. - * */ public class LocationArtifactReportProcessorTest extends AbstractRepositoryReportsTestCase @@ -74,11 +69,11 @@ public class LocationArtifactReportProcessorTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "2.0" ); - Artifact artifact = new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", - handler ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-model", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "org.apache.maven/maven-model/2.0/maven-model-2.0.pom" ); + InputStream is = + new FileInputStream( repository.getBasedir() + "org.apache.maven/maven-model/2.0/maven-model-2.0.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -107,8 +102,8 @@ public class LocationArtifactReportProcessorTest VersionRange version = VersionRange.createFromVersion( "1.0-alpha-1" ); Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom" ); + InputStream is = new FileInputStream( + repository.getBasedir() + "groupId/artifactId/1.0-alpha-1/artifactId-1.0-alpha-1.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -124,7 +119,7 @@ public class LocationArtifactReportProcessorTest /** * Test the LocationArtifactReporter when the artifact is not in the location specified - * in the file system pom. + * in the file system pom. */ public void testLocationArtifactReporterFailure() { @@ -137,8 +132,8 @@ public class LocationArtifactReportProcessorTest VersionRange version = VersionRange.createFromVersion( "1.0-alpha-2" ); Artifact artifact = new DefaultArtifact( "groupId", "artifactId", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom" ); + InputStream is = new FileInputStream( + repository.getBasedir() + "groupId/artifactId/1.0-alpha-2/artifactId-1.0-alpha-2.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -165,11 +160,11 @@ public class LocationArtifactReportProcessorTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "2.0" ); - Artifact artifact = new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", - "", handler ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-archiver", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "org.apache.maven/maven-archiver/2.0/maven-archiver-2.0.pom" ); + InputStream is = new FileInputStream( + repository.getBasedir() + "org.apache.maven/maven-archiver/2.0/maven-archiver-2.0.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -197,11 +192,11 @@ public class LocationArtifactReportProcessorTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "2.1" ); - Artifact artifact = new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", - "", handler ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-monitor", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "org.apache.maven/maven-monitor/2.1/maven-monitor-2.1.pom" ); + InputStream is = new FileInputStream( + repository.getBasedir() + "org.apache.maven/maven-monitor/2.1/maven-monitor-2.1.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -228,11 +223,11 @@ public class LocationArtifactReportProcessorTest { ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); VersionRange version = VersionRange.createFromVersion( "2.1" ); - Artifact artifact = new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", - "", handler ); + Artifact artifact = + new DefaultArtifact( "org.apache.maven", "maven-project", version, "compile", "jar", "", handler ); - InputStream is = new FileInputStream( repository.getBasedir() - + "org.apache.maven/maven-project/2.1/maven-project-2.1.pom" ); + InputStream is = new FileInputStream( + repository.getBasedir() + "org.apache.maven/maven-project/2.1/maven-project-2.1.pom" ); Reader reader = new InputStreamReader( is ); Model model = pomReader.read( reader ); @@ -249,7 +244,7 @@ public class LocationArtifactReportProcessorTest /** * Test the LocationArtifactReportProcessor when the artifact is located in the remote repository. */ - /* public void testRemoteArtifactReportProcessorFailure() + /* public void testRemoteArtifactReportProcessorFailure() { ArtifactHandler handler = new DefaultArtifactHandler( remoteArtifactType ); diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java index e95ec8bc5..1f2ccbddc 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifact.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -17,13 +17,13 @@ package org.apache.maven.repository.reporting; */ import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.artifact.versioning.OverConstrainedVersionException; import org.apache.maven.artifact.handler.ArtifactHandler; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; import java.io.File; import java.util.Collection; @@ -36,7 +36,9 @@ public class MockArtifact implements Artifact { private String groupId; + private String artifactId; + private String version; public String getGroupId() diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java index 3d4d72b96..44abcef9a 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactFactory.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -16,8 +16,8 @@ package org.apache.maven.repository.reporting; * limitations under the License. */ -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.versioning.VersionRange; /** diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java index c14289bf1..38ed0124d 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReportProcessor.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -20,9 +20,9 @@ import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.model.Model; -import java.util.List; -import java.util.Iterator; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * @@ -39,7 +39,8 @@ public class MockArtifactReportProcessor reportConditions = new ArrayList(); } - public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, ArtifactRepository artifactRepository ) + public void processArtifact( Model model, Artifact artifact, ArtifactReporter reporter, + ArtifactRepository artifactRepository ) { if ( iterator == null || !iterator.hasNext() ) // not initialized or reached end of the list. start again { @@ -47,26 +48,26 @@ public class MockArtifactReportProcessor } if ( !reportConditions.isEmpty() ) { - while(iterator.hasNext()) + while ( iterator.hasNext() ) { ReportCondition reportCondition = (ReportCondition) iterator.next(); switch ( reportCondition.getResult() ) { case ReportCondition.SUCCESS: - { - reporter.addSuccess( reportCondition.getArtifact() ); - break; - } + { + reporter.addSuccess( reportCondition.getArtifact() ); + break; + } case ReportCondition.WARNING: - { - reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() ); - break; - } + { + reporter.addWarning( reportCondition.getArtifact(), reportCondition.getReason() ); + break; + } case ReportCondition.FAILURE: - { - reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() ); - break; - } + { + reporter.addFailure( reportCondition.getArtifact(), reportCondition.getReason() ); + break; + } } } } diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java index 443812238..93b446fef 100755 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockArtifactReporter.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java index 543212b5b..abe725522 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/MockRepositoryQueryLayer.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -71,11 +71,11 @@ public class MockRepositoryQueryLayer return containsArtifact( artifact ); } - public boolean containsArtifactVersion(Artifact artifact, String version) + public boolean containsArtifactVersion( Artifact artifact, String version ) { return false; } - + public List getVersions( Artifact artifact ) { return null; diff --git a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java index e1d51f1da..6cdfcec69 100644 --- a/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java +++ b/maven-repository-reports-standard/src/test/java/org/apache/maven/repository/reporting/ReportCondition.java @@ -1,7 +1,7 @@ package org.apache.maven.repository.reporting; /* - * Copyright 2001-2005 The Apache Software Foundation. + * Copyright 2005-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. @@ -24,11 +24,15 @@ import org.apache.maven.artifact.Artifact; public class ReportCondition { public final static int SUCCESS = 0; + public final static int FAILURE = -1; + public final static int WARNING = 1; private int result; + private Artifact artifact; + private String reason; public ReportCondition( int result, Artifact artifact, String reason ) diff --git a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml index 6b20d3b4b..a8ea6e7e0 100644 --- a/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml +++ b/maven-repository-reports-standard/src/test/repository/groupId/artifactId/maven-metadata.xml @@ -1,11 +1,27 @@ + + - groupId - artifactId - 1.0-alpha-1 + groupId + artifactId + 1.0-alpha-1 - 1.0-alpha-1 - 1.0-alpha-2 + 1.0-alpha-1 + 1.0-alpha-2 diff --git a/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml b/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml index 791dac1b5..44c9d51ff 100644 --- a/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml +++ b/maven-repository-reports-standard/src/test/repository/groupId/unexpectedfile.xml @@ -1 +1,17 @@ -This file is here to make sure that it will not be processed during unit test. \ No newline at end of file +This file is here to make sure that it will not be processed during unit + + test. \ No newline at end of file diff --git a/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml b/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml index 7fdf6a91a..9efaee38c 100644 --- a/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml +++ b/maven-repository-reports-standard/src/test/repository/maven-metadata-repository.xml @@ -1,5 +1,21 @@ + + -checksumTest -invalidArtifact -1.0 + checksumTest + invalidArtifact + 1.0 diff --git a/pom.xml b/pom.xml index 9bcb1c09c..bdc1ef322 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,19 @@ + + 4.0.0 org.apache.maven.repository @@ -6,7 +22,8 @@ Maven Repository Manager 1.0-SNAPSHOT - The Maven Repository Manager is an application for managing one or more remote repositories, including administration, artifact handling, + The Maven Repository Manager is an application for managing one or more remote repositories, including + administration, artifact handling, browsing and searching. http://maven.apache.org/repository-manager @@ -105,11 +122,11 @@ - + apache.snapshots Apache Development Repository http://cvs.apache.org/maven-snapshot-repository @@ -193,13 +210,13 @@ - + apache.snapshots Apache Development Repository @@ -217,11 +234,11 @@ org.codehaus.mojo cobertura-maven-plugin - + org.codehaus.mojo -- 2.39.5