From 18f031c774a88a3ea934da79947a81718f25a769 Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Tue, 13 Jun 2006 06:53:38 +0000 Subject: [PATCH] Added reason parameter in kickedOutPaths. Also, added an interface with the kickedOutPaths which two other interfaces extends git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@413818 13f79535-47bb-0310-9956-ffa450edef68 --- .../discovery/AbstractArtifactDiscoverer.java | 25 +- .../discovery/AbstractDiscoverer.java | 13 +- .../discovery/ArtifactDiscoverer.java | 19 +- .../discovery/DefaultArtifactDiscoverer.java | 122 ++++----- .../discovery/DefaultMetadataDiscoverer.java | 34 ++- .../repository/discovery/Discoverer.java | 39 +++ .../discovery/DiscovererException.java | 39 +++ .../discovery/LegacyArtifactDiscoverer.java | 232 +++++++++--------- .../discovery/MetadataDiscoverer.java | 16 +- .../DefaultArtifactDiscovererTest.java | 9 +- .../LegacyArtifactDiscovererTest.java | 9 +- .../repository/proxy/DefaultProxyManager.java | 20 +- 12 files changed, 340 insertions(+), 237 deletions(-) create mode 100644 maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java create mode 100644 maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java 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 22b463ac2..63d916fd6 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 @@ -73,17 +73,19 @@ public abstract class AbstractArtifactDiscoverer { String path = artifactPaths[i]; - Artifact artifact = buildArtifactFromPath( path, repository ); - if ( artifact != null ) + Artifact artifact = null; + try { + artifact = buildArtifactFromPath( path, repository ); + if ( includeSnapshots || !artifact.isSnapshot() ) { artifacts.add( artifact ); } } - else + catch ( DiscovererException e ) { - addKickedOutPath( path ); + addKickedOutPath( path, e.getMessage() ); } } @@ -103,14 +105,16 @@ public abstract class AbstractArtifactDiscoverer { String path = artifactPaths[i]; + String filename = repositoryBase.getAbsolutePath() + "/" + path; + if ( path.toLowerCase().endsWith( POM ) ) { - Artifact pomArtifact = buildArtifactFromPath( path, repository ); - - MavenXpp3Reader mavenReader = new MavenXpp3Reader(); - String filename = repositoryBase.getAbsolutePath() + "/" + path; try { + Artifact pomArtifact = buildArtifactFromPath( path, repository ); + + MavenXpp3Reader mavenReader = new MavenXpp3Reader(); + Model model = mavenReader.read( new FileReader( filename ) ); if ( pomArtifact != null && "pom".equals( model.getPackaging() ) ) { @@ -134,6 +138,10 @@ public abstract class AbstractArtifactDiscoverer getLogger().error( "Parse error reading file during POM discovery: " + filename + ": " + e.getMessage() ); } + catch ( DiscovererException e ) + { + getLogger().error( e.getMessage() ); + } } } @@ -141,6 +149,7 @@ public abstract class AbstractArtifactDiscoverer } public Artifact buildArtifactFromPath( String path, ArtifactRepository repository ) + throws DiscovererException { Artifact artifact = buildArtifact( path ); diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java index 65db8a50d..3fbc87788 100644 --- a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/AbstractDiscoverer.java @@ -26,6 +26,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; +import java.util.Map; +import java.util.HashMap; /** * Base class for the artifact and metadata discoverers. @@ -34,8 +36,9 @@ import java.util.List; */ public abstract class AbstractDiscoverer extends AbstractLogEnabled + implements Discoverer { - private List kickedOutPaths = new ArrayList(); + private Map kickedOutPaths = new HashMap(); /** * @plexus.requirement @@ -50,16 +53,16 @@ public abstract class AbstractDiscoverer * Add a path to the list of files that were kicked out due to being invalid. * * @param path the path to add - * @todo add a reason + * @param reason the reason why the path is being kicked out */ - protected void addKickedOutPath( String path ) + protected void addKickedOutPath( String path, String reason ) { - kickedOutPaths.add( path ); + kickedOutPaths.put( path, reason ); } public Iterator getKickedOutPathsIterator() { - return kickedOutPaths.iterator(); + return kickedOutPaths.keySet().iterator(); } /** 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 52b011b77..19e008d34 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 @@ -19,7 +19,6 @@ package org.apache.maven.repository.discovery; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; -import java.util.Iterator; import java.util.List; /** @@ -29,6 +28,7 @@ import java.util.List; * @author Brett Porter */ public interface ArtifactDiscoverer + extends Discoverer { String ROLE = ArtifactDiscoverer.class.getName(); @@ -58,20 +58,6 @@ public interface ArtifactDiscoverer */ List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots ); - /** - * 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(); - /** * Build an artifact from a path in the repository * @@ -79,5 +65,6 @@ public interface ArtifactDiscoverer * @return the artifact * @todo this should be in maven-artifact */ - Artifact buildArtifact( String path ); + Artifact buildArtifact( String path ) + throws DiscovererException; } 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 4ec84f66d..5d7e32a6a 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 @@ -35,6 +35,7 @@ public class DefaultArtifactDiscoverer extends AbstractArtifactDiscoverer { public Artifact buildArtifact( String path ) + throws DiscovererException { List pathParts = new ArrayList(); StringTokenizer st = new StringTokenizer( path, "/\\" ); @@ -64,11 +65,7 @@ public class DefaultArtifactDiscoverer String groupId = StringUtils.join( pathParts.iterator(), "." ); String remainingFilename = filename; - if ( !remainingFilename.startsWith( artifactId + "-" ) ) - { - return null; - } - else + if ( remainingFilename.startsWith( artifactId + "-" ) ) { remainingFilename = remainingFilename.substring( artifactId.length() + 1 ); @@ -97,87 +94,92 @@ public class DefaultArtifactDiscoverer else { int index = remainingFilename.lastIndexOf( "." ); - if ( index < 0 ) + if ( index >= 0 ) { - return null; + type = remainingFilename.substring( index + 1 ); + remainingFilename = remainingFilename.substring( 0, index ); } else { - type = remainingFilename.substring( index + 1 ); - remainingFilename = remainingFilename.substring( 0, index ); + throw new DiscovererException( "Path filename does not have an extension" ); } } - if ( type != null ) + Artifact result; + if ( classifier == null ) + { + result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, + type ); + } + else { - Artifact result; + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, + classifier ); + } - if ( classifier == null ) + if ( result.isSnapshot() ) + { + // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b + int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 ); + if ( classifierIndex >= 0 ) { - result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME, - type ); + classifier = remainingFilename.substring( classifierIndex + 1 ); + remainingFilename = remainingFilename.substring( 0, classifierIndex ); + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, + remainingFilename, type, + classifier ); } else { - result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, - classifier ); + result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, + Artifact.SCOPE_RUNTIME, type ); } - if ( result.isSnapshot() ) + // poor encapsulation requires we do this to populate base version + if ( !result.isSnapshot() ) { - // version is *-SNAPSHOT, filename is *-yyyyMMdd.hhmmss-b - int classifierIndex = remainingFilename.indexOf( '-', version.length() + 8 ); - if ( classifierIndex >= 0 ) - { - classifier = remainingFilename.substring( classifierIndex + 1 ); - remainingFilename = remainingFilename.substring( 0, classifierIndex ); - result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, - remainingFilename, type, - classifier ); - } - else - { - result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename, - Artifact.SCOPE_RUNTIME, type ); - } - - // poor encapsulation requires we do this to populate base version - if ( !result.isSnapshot() ) - { - return null; - } - else if ( !result.getBaseVersion().equals( version ) ) - { - return null; - } - else - { - artifact = result; - } + throw new DiscovererException( "Failed to create a snapshot artifact" ); } - else if ( !remainingFilename.startsWith( version ) ) + else if ( !result.getBaseVersion().equals( version ) ) { - return null; + throw new DiscovererException( "Built snapshot artifact base version does not match " + + "path version" ); } - else if ( !remainingFilename.equals( version ) ) + else { - if ( remainingFilename.charAt( version.length() ) != '-' ) - { - return null; - } - else - { - classifier = remainingFilename.substring( version.length() + 1 ); - artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, - classifier ); - } + artifact = result; + } + } + else if ( !remainingFilename.startsWith( version ) ) + { + throw new DiscovererException( "Built artifact version does not match path version" ); + } + else if ( !remainingFilename.equals( version ) ) + { + if ( remainingFilename.charAt( version.length() ) == '-' ) + { + classifier = remainingFilename.substring( version.length() + 1 ); + artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type, + classifier ); } else { - artifact = result; + throw new DiscovererException( "Path version does not corresspond to an artifact version" ); } } + else + { + artifact = result; + } } + else + { + throw new DiscovererException( "Path filename does not correspond to an artifact" ); + } + } + else + { + throw new DiscovererException( "Path is too short to build an artifact from" ); } return artifact; 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 e07cd14d3..8dd3bf7fa 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 @@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.metadata.RepositoryMetadata; import org.apache.maven.artifact.repository.metadata.SnapshotArtifactRepositoryMetadata; import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.codehaus.plexus.util.StringUtils; import java.io.File; import java.io.IOException; @@ -67,15 +68,14 @@ public class DefaultMetadataDiscoverer for ( int i = 0; i < metadataPaths.length; i++ ) { - RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] ); - - if ( metadata != null ) + try { + RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] ); metadataFiles.add( metadata ); } - else + catch ( DiscovererException e ) { - addKickedOutPath( metadataPaths[i] ); + addKickedOutPath( metadataPaths[i], e.getMessage() ); } } @@ -90,6 +90,7 @@ public class DefaultMetadataDiscoverer * @return the metadata */ private RepositoryMetadata buildMetadata( String repo, String metadataPath ) + throws DiscovererException { Metadata m = null; String repoPath = repo + "/" + metadataPath; @@ -104,23 +105,26 @@ public class DefaultMetadataDiscoverer } catch ( XmlPullParserException e ) { - getLogger().error( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e ); + throw new DiscovererException( "Error parsing metadata file '" + repoPath + "': " + e.getMessage(), e ); } catch ( MalformedURLException e ) { // shouldn't happen - getLogger().error( "Error constructing metadata file '" + repoPath + "': " + e.getMessage(), e ); + throw new DiscovererException( "Error constructing metadata file '" + repoPath + "': " + + e.getMessage(), e ); } catch ( IOException e ) { - getLogger().error( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e ); + throw new DiscovererException( "Error reading metadata file '" + repoPath + "': " + e.getMessage(), e ); } - RepositoryMetadata repositoryMetadata = null; - if ( m != null ) + RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath ); + + if ( repositoryMetadata == null ) { - repositoryMetadata = buildMetadata( m, metadataPath ); + throw new DiscovererException( "Unable to build a repository metadata from path" ); } + return repositoryMetadata; } @@ -146,14 +150,8 @@ public class DefaultMetadataDiscoverer Iterator it = pathParts.iterator(); String tmpDir = (String) it.next(); - //ArtifactHandler handler = new DefaultArtifactHandler( "jar" ); - //if( metaVersion != null && !metaVersion.equals( "" ) ) - //{ - // VersionRange version = VersionRange.createFromVersion( metaVersion ); - //} - Artifact artifact = null; - if ( metaVersion != null && !"".equals( metaVersion ) ) + if ( !StringUtils.isEmpty( metaVersion ) ) { artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" ); } diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java new file mode 100644 index 000000000..9a9b6151c --- /dev/null +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/Discoverer.java @@ -0,0 +1,39 @@ +package org.apache.maven.repository.discovery; + +import java.util.Iterator; + +/* + * 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. + */ + +/** + * @author Edwin Punzalan + */ +public interface Discoverer +{ + /** + * 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(); +} diff --git a/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java new file mode 100644 index 000000000..937e1780c --- /dev/null +++ b/maven-repository-discovery/src/main/java/org/apache/maven/repository/discovery/DiscovererException.java @@ -0,0 +1,39 @@ +package org.apache.maven.repository.discovery; + +/* + * 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. + */ + +/** + * @author Edwin Punzalan + */ +public class DiscovererException + extends Exception +{ + public DiscovererException( Throwable cause ) + { + super( cause ); + } + + public DiscovererException( String message ) + { + super( message ); + } + + public DiscovererException( String message, Throwable cause ) + { + super( message, cause ); + } +} 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 a5092c1bd..1040d580a 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 @@ -38,10 +38,11 @@ public class LegacyArtifactDiscoverer extends AbstractArtifactDiscoverer { public Artifact buildArtifact( String path ) + throws DiscovererException { StringTokenizer tokens = new StringTokenizer( path, "/\\" ); - Artifact result = null; + Artifact result; int numberOfTokens = tokens.countTokens(); @@ -69,8 +70,6 @@ public class LegacyArtifactDiscoverer String lastAvceToken = (String) avceTokenList.removeLast(); - boolean valid = true; - // TODO: share with other discoverer, use artifact handlers instead if ( lastAvceToken.endsWith( ".tar.gz" ) ) { @@ -111,157 +110,168 @@ public class LegacyArtifactDiscoverer } else { - //type does not match extension - valid = false; + throw new DiscovererException( "Path type does not match the extension" ); } } else { - // no extension - valid = false; + throw new DiscovererException( "Path filename does not have an extension" ); } } - if ( valid ) - { - // let's discover the version, and whatever's leftover will be either - // a classifier, or part of the artifactId, depending on position. - // Since version is at the end, we have to move in from the back. - Collections.reverse( avceTokenList ); - - // TODO: this is obscene - surely a better way? - String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + - "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" + - "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + - "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + - "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + - "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + - "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)"; - - StringBuffer classifierBuffer = new StringBuffer(); - StringBuffer versionBuffer = new StringBuffer(); - - boolean firstVersionTokenEncountered = false; - boolean firstToken = true; - - int tokensIterated = 0; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); + // let's discover the version, and whatever's leftover will be either + // a classifier, or part of the artifactId, depending on position. + // Since version is at the end, we have to move in from the back. + Collections.reverse( avceTokenList ); - boolean tokenIsVersionPart = token.matches( validVersionParts ); + // TODO: this is obscene - surely a better way? + String validVersionParts = "([Dd][Ee][Vv][_.0-9]*)|" + "([Ss][Nn][Aa][Pp][Ss][Hh][Oo][Tt])|" + + "([0-9][_.0-9a-zA-Z]*)|" + "([Gg]?[_.0-9ab]*([Pp][Rr][Ee]|[Rr][Cc]|[Gg]|[Mm])[_.0-9]*)|" + + "([Aa][Ll][Pp][Hh][Aa][_.0-9]*)|" + "([Bb][Ee][Tt][Aa][_.0-9]*)|" + "([Rr][Cc][_.0-9]*)|" + + "([Tt][Ee][Ss][Tt][_.0-9]*)|" + "([Dd][Ee][Bb][Uu][Gg][_.0-9]*)|" + + "([Uu][Nn][Oo][Ff][Ff][Ii][Cc][Ii][Aa][Ll][_.0-9]*)|" + "([Cc][Uu][Rr][Rr][Ee][Nn][Tt])|" + + "([Ll][Aa][Tt][Ee][Ss][Tt])|" + "([Ff][Cc][Ss])|" + "([Rr][Ee][Ll][Ee][Aa][Ss][Ee][_.0-9]*)|" + + "([Nn][Ii][Gg][Hh][Tt][Ll][Yy])|" + "[Ff][Ii][Nn][Aa][Ll]|" + "([AaBb][_.0-9]*)"; - StringBuffer bufferToUpdate; + StringBuffer classifierBuffer = new StringBuffer(); + StringBuffer versionBuffer = new StringBuffer(); - // NOTE: logic in code is reversed, since we're peeling off the back - // Any token after the last versionPart will be in the classifier. - // Any token UP TO first non-versionPart is part of the version. - if ( !tokenIsVersionPart ) - { - if ( firstVersionTokenEncountered ) - { - //noinspection BreakStatement - break; - } - else - { - bufferToUpdate = classifierBuffer; - } - } - else - { - firstVersionTokenEncountered = true; + boolean firstVersionTokenEncountered = false; + boolean firstToken = true; - bufferToUpdate = versionBuffer; - } + int tokensIterated = 0; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) + { + String token = (String) it.next(); + + boolean tokenIsVersionPart = token.matches( validVersionParts ); - if ( firstToken ) + StringBuffer bufferToUpdate; + + // NOTE: logic in code is reversed, since we're peeling off the back + // Any token after the last versionPart will be in the classifier. + // Any token UP TO first non-versionPart is part of the version. + if ( !tokenIsVersionPart ) + { + if ( firstVersionTokenEncountered ) { - firstToken = false; + //noinspection BreakStatement + break; } else { - bufferToUpdate.insert( 0, '-' ); + bufferToUpdate = classifierBuffer; } + } + else + { + firstVersionTokenEncountered = true; - bufferToUpdate.insert( 0, token ); + bufferToUpdate = versionBuffer; + } - tokensIterated++; + if ( firstToken ) + { + firstToken = false; + } + else + { + bufferToUpdate.insert( 0, '-' ); } - // Now, restore the proper ordering so we can build the artifactId. - Collections.reverse( avceTokenList ); + bufferToUpdate.insert( 0, token ); + + tokensIterated++; + } + + // Now, restore the proper ordering so we can build the artifactId. + Collections.reverse( avceTokenList ); - // if we didn't find a version, then punt. Use the last token - // as the version, and set the classifier empty. - if ( versionBuffer.length() < 1 ) + // if we didn't find a version, then punt. Use the last token + // as the version, and set the classifier empty. + if ( versionBuffer.length() < 1 ) + { + if ( avceTokenList.size() > 1 ) { - if ( avceTokenList.size() > 1 ) - { - int lastIdx = avceTokenList.size() - 1; + int lastIdx = avceTokenList.size() - 1; - versionBuffer.append( avceTokenList.get( lastIdx ) ); - avceTokenList.remove( lastIdx ); - } + versionBuffer.append( avceTokenList.get( lastIdx ) ); + avceTokenList.remove( lastIdx ); + } - classifierBuffer.setLength( 0 ); + classifierBuffer.setLength( 0 ); + } + else + { + // if everything is kosher, then pop off all the classifier and + // version tokens, leaving the naked artifact id in the list. + avceTokenList = + new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) ); + } + + StringBuffer artifactIdBuffer = new StringBuffer(); + + firstToken = true; + for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) + { + String token = (String) it.next(); + + if ( firstToken ) + { + firstToken = false; } else { - // if everything is kosher, then pop off all the classifier and - // version tokens, leaving the naked artifact id in the list. - avceTokenList = - new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) ); + artifactIdBuffer.append( '-' ); } - StringBuffer artifactIdBuffer = new StringBuffer(); - - firstToken = true; - for ( Iterator it = avceTokenList.iterator(); it.hasNext(); ) - { - String token = (String) it.next(); + artifactIdBuffer.append( token ); + } - if ( firstToken ) - { - firstToken = false; - } - else - { - artifactIdBuffer.append( '-' ); - } + String artifactId = artifactIdBuffer.toString(); - artifactIdBuffer.append( token ); + if ( artifactId.length() > 0 ) + { + int lastVersionCharIdx = versionBuffer.length() - 1; + if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) + { + versionBuffer.setLength( lastVersionCharIdx ); } - String artifactId = artifactIdBuffer.toString(); + String version = versionBuffer.toString(); - if ( artifactId.length() > 0 ) + if ( version.length() > 0 ) { - int lastVersionCharIdx = versionBuffer.length() - 1; - if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' ) + if ( classifierBuffer.length() > 0 ) { - versionBuffer.setLength( lastVersionCharIdx ); + result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, + type, + classifierBuffer.toString() ); } - - String version = versionBuffer.toString(); - - if ( version.length() >= 1 ) + else { - if ( classifierBuffer.length() > 0 ) - { - result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, - type, - classifierBuffer.toString() ); - } - else - { - result = artifactFactory.createArtifact( groupId, artifactId, version, - Artifact.SCOPE_RUNTIME, type ); - } + result = artifactFactory.createArtifact( groupId, artifactId, version, + Artifact.SCOPE_RUNTIME, type ); } } + else + { + throw new DiscovererException( "Path filename version is empty" ); + } + } + else + { + throw new DiscovererException( "Path filename artifactId is empty" ); } } + else + { + throw new DiscovererException( "Path artifact type does not corresspond to an artifact type" ); + } + } + else + { + throw new DiscovererException( "Path does not match a legacy repository path for an artifact" ); } return result; 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 0eea23b8a..01cedac66 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 @@ -17,13 +17,13 @@ package org.apache.maven.repository.discovery; */ import java.io.File; -import java.util.Iterator; import java.util.List; /** * Interface for discovering metadata files. */ public interface MetadataDiscoverer + extends Discoverer { String ROLE = MetadataDiscoverer.class.getName(); @@ -34,18 +34,4 @@ public interface MetadataDiscoverer * @param blacklistedPatterns Patterns that are to be excluded from the discovery process. */ 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 excluded during the discovery process. - * - * @return the paths as Strings. - */ - Iterator getExcludedPathsIterator(); } 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 ea37a7b23..8d62a8790 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 @@ -565,7 +565,14 @@ public class DefaultArtifactDiscovererTest private Artifact getArtifactFromPath( String path ) { - return discoverer.buildArtifact( path ); + try + { + return discoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + return null; + } } private Artifact createArtifact( String groupId, String artifactId, String version ) 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 7eb5d1da4..1e35aaefa 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 @@ -406,7 +406,14 @@ public class LegacyArtifactDiscovererTest private Artifact getArtifactFromPath( String path ) { - return discoverer.buildArtifact( path ); + try + { + return discoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + return null; + } } private Artifact createArtifact( String groupId, String artifactId, String version ) diff --git a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java index 5afe0d9b7..06e172669 100644 --- a/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java +++ b/maven-repository-proxy/src/main/java/org/apache/maven/repository/proxy/DefaultProxyManager.java @@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.repository.discovery.ArtifactDiscoverer; +import org.apache.maven.repository.discovery.DiscovererException; import org.apache.maven.repository.proxy.configuration.ProxyConfiguration; import org.apache.maven.repository.proxy.repository.ProxyRepository; import org.apache.maven.wagon.ConnectionException; @@ -150,11 +151,26 @@ public class DefaultProxyManager } else { - Artifact artifact = defaultArtifactDiscoverer.buildArtifact( path ); + Artifact artifact = null; + try + { + artifact = defaultArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using default layout with message: " + e.getMessage() ); + } if ( artifact == null ) { - artifact = legacyArtifactDiscoverer.buildArtifact( path ); + try + { + artifact = legacyArtifactDiscoverer.buildArtifact( path ); + } + catch ( DiscovererException e ) + { + getLogger().debug( "Failed to build artifact using legacy layout with message: " + e.getMessage() ); + } } if ( artifact != null ) -- 2.39.5