mirror of https://github.com/apache/archiva.git
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
This commit is contained in:
parent
b6dd4adbe6
commit
18f031c774
|
@ -73,17 +73,19 @@ public abstract class AbstractArtifactDiscoverer
|
||||||
{
|
{
|
||||||
String path = artifactPaths[i];
|
String path = artifactPaths[i];
|
||||||
|
|
||||||
Artifact artifact = buildArtifactFromPath( path, repository );
|
Artifact artifact = null;
|
||||||
if ( artifact != null )
|
try
|
||||||
{
|
{
|
||||||
|
artifact = buildArtifactFromPath( path, repository );
|
||||||
|
|
||||||
if ( includeSnapshots || !artifact.isSnapshot() )
|
if ( includeSnapshots || !artifact.isSnapshot() )
|
||||||
{
|
{
|
||||||
artifacts.add( artifact );
|
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 path = artifactPaths[i];
|
||||||
|
|
||||||
|
String filename = repositoryBase.getAbsolutePath() + "/" + path;
|
||||||
|
|
||||||
if ( path.toLowerCase().endsWith( POM ) )
|
if ( path.toLowerCase().endsWith( POM ) )
|
||||||
{
|
{
|
||||||
Artifact pomArtifact = buildArtifactFromPath( path, repository );
|
|
||||||
|
|
||||||
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
|
|
||||||
String filename = repositoryBase.getAbsolutePath() + "/" + path;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Artifact pomArtifact = buildArtifactFromPath( path, repository );
|
||||||
|
|
||||||
|
MavenXpp3Reader mavenReader = new MavenXpp3Reader();
|
||||||
|
|
||||||
Model model = mavenReader.read( new FileReader( filename ) );
|
Model model = mavenReader.read( new FileReader( filename ) );
|
||||||
if ( pomArtifact != null && "pom".equals( model.getPackaging() ) )
|
if ( pomArtifact != null && "pom".equals( model.getPackaging() ) )
|
||||||
{
|
{
|
||||||
|
@ -134,6 +138,10 @@ public abstract class AbstractArtifactDiscoverer
|
||||||
getLogger().error(
|
getLogger().error(
|
||||||
"Parse error reading file during POM discovery: " + filename + ": " + e.getMessage() );
|
"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 )
|
public Artifact buildArtifactFromPath( String path, ArtifactRepository repository )
|
||||||
|
throws DiscovererException
|
||||||
{
|
{
|
||||||
Artifact artifact = buildArtifact( path );
|
Artifact artifact = buildArtifact( path );
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,8 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for the artifact and metadata discoverers.
|
* Base class for the artifact and metadata discoverers.
|
||||||
|
@ -34,8 +36,9 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDiscoverer
|
public abstract class AbstractDiscoverer
|
||||||
extends AbstractLogEnabled
|
extends AbstractLogEnabled
|
||||||
|
implements Discoverer
|
||||||
{
|
{
|
||||||
private List kickedOutPaths = new ArrayList();
|
private Map kickedOutPaths = new HashMap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @plexus.requirement
|
* @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.
|
* Add a path to the list of files that were kicked out due to being invalid.
|
||||||
*
|
*
|
||||||
* @param path the path to add
|
* @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()
|
public Iterator getKickedOutPathsIterator()
|
||||||
{
|
{
|
||||||
return kickedOutPaths.iterator();
|
return kickedOutPaths.keySet().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,7 +19,6 @@ package org.apache.maven.repository.discovery;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +28,7 @@ import java.util.List;
|
||||||
* @author Brett Porter
|
* @author Brett Porter
|
||||||
*/
|
*/
|
||||||
public interface ArtifactDiscoverer
|
public interface ArtifactDiscoverer
|
||||||
|
extends Discoverer
|
||||||
{
|
{
|
||||||
String ROLE = ArtifactDiscoverer.class.getName();
|
String ROLE = ArtifactDiscoverer.class.getName();
|
||||||
|
|
||||||
|
@ -58,20 +58,6 @@ public interface ArtifactDiscoverer
|
||||||
*/
|
*/
|
||||||
List discoverStandalonePoms( ArtifactRepository repository, String blacklistedPatterns, boolean includeSnapshots );
|
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
|
* Build an artifact from a path in the repository
|
||||||
*
|
*
|
||||||
|
@ -79,5 +65,6 @@ public interface ArtifactDiscoverer
|
||||||
* @return the artifact
|
* @return the artifact
|
||||||
* @todo this should be in maven-artifact
|
* @todo this should be in maven-artifact
|
||||||
*/
|
*/
|
||||||
Artifact buildArtifact( String path );
|
Artifact buildArtifact( String path )
|
||||||
|
throws DiscovererException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ public class DefaultArtifactDiscoverer
|
||||||
extends AbstractArtifactDiscoverer
|
extends AbstractArtifactDiscoverer
|
||||||
{
|
{
|
||||||
public Artifact buildArtifact( String path )
|
public Artifact buildArtifact( String path )
|
||||||
|
throws DiscovererException
|
||||||
{
|
{
|
||||||
List pathParts = new ArrayList();
|
List pathParts = new ArrayList();
|
||||||
StringTokenizer st = new StringTokenizer( path, "/\\" );
|
StringTokenizer st = new StringTokenizer( path, "/\\" );
|
||||||
|
@ -64,11 +65,7 @@ public class DefaultArtifactDiscoverer
|
||||||
String groupId = StringUtils.join( pathParts.iterator(), "." );
|
String groupId = StringUtils.join( pathParts.iterator(), "." );
|
||||||
|
|
||||||
String remainingFilename = filename;
|
String remainingFilename = filename;
|
||||||
if ( !remainingFilename.startsWith( artifactId + "-" ) )
|
if ( remainingFilename.startsWith( artifactId + "-" ) )
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
|
remainingFilename = remainingFilename.substring( artifactId.length() + 1 );
|
||||||
|
|
||||||
|
@ -97,87 +94,92 @@ public class DefaultArtifactDiscoverer
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int index = remainingFilename.lastIndexOf( "." );
|
int index = remainingFilename.lastIndexOf( "." );
|
||||||
if ( index < 0 )
|
if ( index >= 0 )
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
type = remainingFilename.substring( index + 1 );
|
type = remainingFilename.substring( index + 1 );
|
||||||
remainingFilename = remainingFilename.substring( 0, index );
|
remainingFilename = remainingFilename.substring( 0, index );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new DiscovererException( "Path filename does not have an extension" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( type != null )
|
Artifact result;
|
||||||
|
if ( classifier == null )
|
||||||
{
|
{
|
||||||
Artifact result;
|
result = artifactFactory.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
|
||||||
|
type );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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,
|
classifier = remainingFilename.substring( classifierIndex + 1 );
|
||||||
type );
|
remainingFilename = remainingFilename.substring( 0, classifierIndex );
|
||||||
|
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId,
|
||||||
|
remainingFilename, type,
|
||||||
|
classifier );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
|
result = artifactFactory.createArtifact( groupId, artifactId, remainingFilename,
|
||||||
classifier );
|
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
|
throw new DiscovererException( "Failed to create a snapshot artifact" );
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 ) )
|
|
||||||
{
|
|
||||||
if ( remainingFilename.charAt( version.length() ) != '-' )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
classifier = remainingFilename.substring( version.length() + 1 );
|
|
||||||
artifact = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version, type,
|
|
||||||
classifier );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
artifact = result;
|
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
|
||||||
|
{
|
||||||
|
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;
|
return artifact;
|
||||||
|
|
|
@ -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.SnapshotArtifactRepositoryMetadata;
|
||||||
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -67,15 +68,14 @@ public class DefaultMetadataDiscoverer
|
||||||
|
|
||||||
for ( int i = 0; i < metadataPaths.length; i++ )
|
for ( int i = 0; i < metadataPaths.length; i++ )
|
||||||
{
|
{
|
||||||
RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
|
try
|
||||||
|
|
||||||
if ( metadata != null )
|
|
||||||
{
|
{
|
||||||
|
RepositoryMetadata metadata = buildMetadata( repositoryBase.getPath(), metadataPaths[i] );
|
||||||
metadataFiles.add( metadata );
|
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
|
* @return the metadata
|
||||||
*/
|
*/
|
||||||
private RepositoryMetadata buildMetadata( String repo, String metadataPath )
|
private RepositoryMetadata buildMetadata( String repo, String metadataPath )
|
||||||
|
throws DiscovererException
|
||||||
{
|
{
|
||||||
Metadata m = null;
|
Metadata m = null;
|
||||||
String repoPath = repo + "/" + metadataPath;
|
String repoPath = repo + "/" + metadataPath;
|
||||||
|
@ -104,23 +105,26 @@ public class DefaultMetadataDiscoverer
|
||||||
}
|
}
|
||||||
catch ( XmlPullParserException e )
|
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 )
|
catch ( MalformedURLException e )
|
||||||
{
|
{
|
||||||
// shouldn't happen
|
// 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 )
|
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;
|
RepositoryMetadata repositoryMetadata = buildMetadata( m, metadataPath );
|
||||||
if ( m != null )
|
|
||||||
|
if ( repositoryMetadata == null )
|
||||||
{
|
{
|
||||||
repositoryMetadata = buildMetadata( m, metadataPath );
|
throw new DiscovererException( "Unable to build a repository metadata from path" );
|
||||||
}
|
}
|
||||||
|
|
||||||
return repositoryMetadata;
|
return repositoryMetadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,14 +150,8 @@ public class DefaultMetadataDiscoverer
|
||||||
Iterator it = pathParts.iterator();
|
Iterator it = pathParts.iterator();
|
||||||
String tmpDir = (String) it.next();
|
String tmpDir = (String) it.next();
|
||||||
|
|
||||||
//ArtifactHandler handler = new DefaultArtifactHandler( "jar" );
|
|
||||||
//if( metaVersion != null && !metaVersion.equals( "" ) )
|
|
||||||
//{
|
|
||||||
// VersionRange version = VersionRange.createFromVersion( metaVersion );
|
|
||||||
//}
|
|
||||||
|
|
||||||
Artifact artifact = null;
|
Artifact artifact = null;
|
||||||
if ( metaVersion != null && !"".equals( metaVersion ) )
|
if ( !StringUtils.isEmpty( metaVersion ) )
|
||||||
{
|
{
|
||||||
artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
|
artifact = artifactFactory.createBuildArtifact( metaGroupId, metaArtifactId, metaVersion, "jar" );
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
|
@ -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 );
|
||||||
|
}
|
||||||
|
}
|
|
@ -38,10 +38,11 @@ public class LegacyArtifactDiscoverer
|
||||||
extends AbstractArtifactDiscoverer
|
extends AbstractArtifactDiscoverer
|
||||||
{
|
{
|
||||||
public Artifact buildArtifact( String path )
|
public Artifact buildArtifact( String path )
|
||||||
|
throws DiscovererException
|
||||||
{
|
{
|
||||||
StringTokenizer tokens = new StringTokenizer( path, "/\\" );
|
StringTokenizer tokens = new StringTokenizer( path, "/\\" );
|
||||||
|
|
||||||
Artifact result = null;
|
Artifact result;
|
||||||
|
|
||||||
int numberOfTokens = tokens.countTokens();
|
int numberOfTokens = tokens.countTokens();
|
||||||
|
|
||||||
|
@ -69,8 +70,6 @@ public class LegacyArtifactDiscoverer
|
||||||
|
|
||||||
String lastAvceToken = (String) avceTokenList.removeLast();
|
String lastAvceToken = (String) avceTokenList.removeLast();
|
||||||
|
|
||||||
boolean valid = true;
|
|
||||||
|
|
||||||
// TODO: share with other discoverer, use artifact handlers instead
|
// TODO: share with other discoverer, use artifact handlers instead
|
||||||
if ( lastAvceToken.endsWith( ".tar.gz" ) )
|
if ( lastAvceToken.endsWith( ".tar.gz" ) )
|
||||||
{
|
{
|
||||||
|
@ -111,157 +110,168 @@ public class LegacyArtifactDiscoverer
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//type does not match extension
|
throw new DiscovererException( "Path type does not match the extension" );
|
||||||
valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// no extension
|
throw new DiscovererException( "Path filename does not have an extension" );
|
||||||
valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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(); )
|
||||||
{
|
{
|
||||||
// let's discover the version, and whatever's leftover will be either
|
String token = (String) it.next();
|
||||||
// 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?
|
boolean tokenIsVersionPart = token.matches( validVersionParts );
|
||||||
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 bufferToUpdate;
|
||||||
StringBuffer versionBuffer = new StringBuffer();
|
|
||||||
|
|
||||||
boolean firstVersionTokenEncountered = false;
|
// NOTE: logic in code is reversed, since we're peeling off the back
|
||||||
boolean firstToken = true;
|
// Any token after the last versionPart will be in the classifier.
|
||||||
|
// Any token UP TO first non-versionPart is part of the version.
|
||||||
int tokensIterated = 0;
|
if ( !tokenIsVersionPart )
|
||||||
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
|
||||||
{
|
{
|
||||||
String token = (String) it.next();
|
if ( firstVersionTokenEncountered )
|
||||||
|
|
||||||
boolean tokenIsVersionPart = token.matches( validVersionParts );
|
|
||||||
|
|
||||||
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 )
|
//noinspection BreakStatement
|
||||||
{
|
break;
|
||||||
//noinspection BreakStatement
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bufferToUpdate = classifierBuffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
firstVersionTokenEncountered = true;
|
bufferToUpdate = classifierBuffer;
|
||||||
|
|
||||||
bufferToUpdate = versionBuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( firstToken )
|
|
||||||
{
|
|
||||||
firstToken = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bufferToUpdate.insert( 0, '-' );
|
|
||||||
}
|
|
||||||
|
|
||||||
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 ( avceTokenList.size() > 1 )
|
|
||||||
{
|
|
||||||
int lastIdx = avceTokenList.size() - 1;
|
|
||||||
|
|
||||||
versionBuffer.append( avceTokenList.get( lastIdx ) );
|
|
||||||
avceTokenList.remove( lastIdx );
|
|
||||||
}
|
|
||||||
|
|
||||||
classifierBuffer.setLength( 0 );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if everything is kosher, then pop off all the classifier and
|
firstVersionTokenEncountered = true;
|
||||||
// version tokens, leaving the naked artifact id in the list.
|
|
||||||
avceTokenList =
|
bufferToUpdate = versionBuffer;
|
||||||
new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - tokensIterated ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer artifactIdBuffer = new StringBuffer();
|
if ( firstToken )
|
||||||
|
|
||||||
firstToken = true;
|
|
||||||
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
|
||||||
{
|
{
|
||||||
String token = (String) it.next();
|
firstToken = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bufferToUpdate.insert( 0, '-' );
|
||||||
|
}
|
||||||
|
|
||||||
if ( firstToken )
|
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 ( avceTokenList.size() > 1 )
|
||||||
|
{
|
||||||
|
int lastIdx = avceTokenList.size() - 1;
|
||||||
|
|
||||||
|
versionBuffer.append( avceTokenList.get( lastIdx ) );
|
||||||
|
avceTokenList.remove( lastIdx );
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
artifactIdBuffer.append( '-' );
|
||||||
|
}
|
||||||
|
|
||||||
|
artifactIdBuffer.append( token );
|
||||||
|
}
|
||||||
|
|
||||||
|
String artifactId = artifactIdBuffer.toString();
|
||||||
|
|
||||||
|
if ( artifactId.length() > 0 )
|
||||||
|
{
|
||||||
|
int lastVersionCharIdx = versionBuffer.length() - 1;
|
||||||
|
if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
|
||||||
|
{
|
||||||
|
versionBuffer.setLength( lastVersionCharIdx );
|
||||||
|
}
|
||||||
|
|
||||||
|
String version = versionBuffer.toString();
|
||||||
|
|
||||||
|
if ( version.length() > 0 )
|
||||||
|
{
|
||||||
|
if ( classifierBuffer.length() > 0 )
|
||||||
{
|
{
|
||||||
firstToken = false;
|
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
|
||||||
|
type,
|
||||||
|
classifierBuffer.toString() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
artifactIdBuffer.append( '-' );
|
result = artifactFactory.createArtifact( groupId, artifactId, version,
|
||||||
|
Artifact.SCOPE_RUNTIME, type );
|
||||||
}
|
}
|
||||||
|
|
||||||
artifactIdBuffer.append( token );
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
String artifactId = artifactIdBuffer.toString();
|
|
||||||
|
|
||||||
if ( artifactId.length() > 0 )
|
|
||||||
{
|
{
|
||||||
int lastVersionCharIdx = versionBuffer.length() - 1;
|
throw new DiscovererException( "Path filename version is empty" );
|
||||||
if ( lastVersionCharIdx > -1 && versionBuffer.charAt( lastVersionCharIdx ) == '-' )
|
|
||||||
{
|
|
||||||
versionBuffer.setLength( lastVersionCharIdx );
|
|
||||||
}
|
|
||||||
|
|
||||||
String version = versionBuffer.toString();
|
|
||||||
|
|
||||||
if ( version.length() >= 1 )
|
|
||||||
{
|
|
||||||
if ( classifierBuffer.length() > 0 )
|
|
||||||
{
|
|
||||||
result = artifactFactory.createArtifactWithClassifier( groupId, artifactId, version,
|
|
||||||
type,
|
|
||||||
classifierBuffer.toString() );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = artifactFactory.createArtifact( groupId, artifactId, version,
|
|
||||||
Artifact.SCOPE_RUNTIME, type );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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;
|
return result;
|
||||||
|
|
|
@ -17,13 +17,13 @@ package org.apache.maven.repository.discovery;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for discovering metadata files.
|
* Interface for discovering metadata files.
|
||||||
*/
|
*/
|
||||||
public interface MetadataDiscoverer
|
public interface MetadataDiscoverer
|
||||||
|
extends Discoverer
|
||||||
{
|
{
|
||||||
String ROLE = MetadataDiscoverer.class.getName();
|
String ROLE = MetadataDiscoverer.class.getName();
|
||||||
|
|
||||||
|
@ -34,18 +34,4 @@ public interface MetadataDiscoverer
|
||||||
* @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
|
* @param blacklistedPatterns Patterns that are to be excluded from the discovery process.
|
||||||
*/
|
*/
|
||||||
List discoverMetadata( File repositoryBase, String blacklistedPatterns );
|
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();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -565,7 +565,14 @@ public class DefaultArtifactDiscovererTest
|
||||||
|
|
||||||
private Artifact getArtifactFromPath( String path )
|
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 )
|
private Artifact createArtifact( String groupId, String artifactId, String version )
|
||||||
|
|
|
@ -406,7 +406,14 @@ public class LegacyArtifactDiscovererTest
|
||||||
|
|
||||||
private Artifact getArtifactFromPath( String path )
|
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 )
|
private Artifact createArtifact( String groupId, String artifactId, String version )
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepositoryFactory;
|
||||||
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
|
||||||
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
|
||||||
import org.apache.maven.repository.discovery.ArtifactDiscoverer;
|
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.configuration.ProxyConfiguration;
|
||||||
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
import org.apache.maven.repository.proxy.repository.ProxyRepository;
|
||||||
import org.apache.maven.wagon.ConnectionException;
|
import org.apache.maven.wagon.ConnectionException;
|
||||||
|
@ -150,11 +151,26 @@ public class DefaultProxyManager
|
||||||
}
|
}
|
||||||
else
|
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 )
|
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 )
|
if ( artifact != null )
|
||||||
|
|
Loading…
Reference in New Issue