Permalink
Browse files

[NEXUS-2200] when parsing a bad artifact coordinate, change the Runti…

…meException to IllegalArtifactCoordinateException

git-svn-id: file:///opt/svn/repositories/sonatype.org/nexus/branches/nexus-indexer-1.2.X@4465 2aa8b3fc-8ebb-4439-a84f-95066eaea8ab
  • Loading branch information...
1 parent 50c2e29 commit bcf196d555ae3ba18a90ed2825fe9be7daced16b juven committed Jun 24, 2009
@@ -76,6 +76,7 @@ public String toString()
public Gav( String groupId, String artifactId, String version, String classifier, String extension,
Integer snapshotBuildNumber, Long snapshotTimeStamp, String name, boolean snapshot, boolean hash,
HashType hashType, boolean signature, SignatureType signatureType )
+ throws IllegalArtifactCoordinateException
{
this.groupId = groupId;
this.artifactId = artifactId;
@@ -89,7 +90,7 @@ public Gav( String groupId, String artifactId, String version, String classifier
{
if ( !VersionUtils.isSnapshot( version ) )
{
- throw new IllegalArgumentException( "GAV marked as snapshot but the supplied version '" + version
+ throw new IllegalArtifactCoordinateException( "GAV marked as snapshot but the supplied version '" + version
+ "' is not!" );
}
@@ -14,7 +14,13 @@
*/
public interface GavCalculator
{
- Gav pathToGav( String path );
+ /**
+ * @param path
+ * @return a Gav based on the path
+ * @throws IllegalArtifactCoordinateException if the path is illegal
+ */
+ Gav pathToGav( String path )
+ throws IllegalArtifactCoordinateException;
String gavToPath( Gav gav );
}
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2007-2008 Sonatype, Inc. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
+ * which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
+ */
+package org.sonatype.nexus.artifact;
+
+/**
+ * Thrown if was provided an illegal artifact coordinate
+ *
+ * @author juven
+ */
+public class IllegalArtifactCoordinateException
+ extends Exception
+{
+ private static final long serialVersionUID = 7137593998855995199L;
+
+ public IllegalArtifactCoordinateException( String message )
+ {
+ super( message );
+ }
+
+ public IllegalArtifactCoordinateException( String message, Throwable throwable )
+ {
+ super( message, throwable );
+ }
+}
@@ -27,6 +27,7 @@
private static final Pattern pat2 = Pattern.compile( "^([a-z0-9-_]+)-([0-9-].+)\\.([^0-9]+)(\\.md5|\\.sha1){0,1}$" );
public Gav pathToGav( String str )
+ throws IllegalArtifactCoordinateException
{
try
{
@@ -22,6 +22,7 @@
extends AbstractGavCalculator
{
public Gav pathToGav( String str )
+ throws IllegalArtifactCoordinateException
{
try
{
@@ -105,10 +106,9 @@ else if ( s.endsWith( ".sha1" ) )
}
}
- private Gav getReleaseGav(String s, int vEndPos, String groupId,
- String artifactId, String version, String fileName, boolean checksum,
- boolean signature, Gav.HashType checksumType,
- Gav.SignatureType signatureType)
+ private Gav getReleaseGav( String s, int vEndPos, String groupId, String artifactId, String version,
+ String fileName, boolean checksum, boolean signature, Gav.HashType checksumType, Gav.SignatureType signatureType )
+ throws IllegalArtifactCoordinateException
{
if ( !fileName.startsWith( artifactId + "-" + version + "." )
&& !fileName.startsWith( artifactId + "-" + version + "-" ) )
@@ -148,9 +148,9 @@ private Gav getReleaseGav(String s, int vEndPos, String groupId,
signatureType );
}
- private Gav getSnapshotGav(String s, int vEndPos, String groupId,
- String artifactId, String version, String fileName, boolean checksum,
- boolean signature, Gav.HashType checksumType, Gav.SignatureType signatureType)
+ private Gav getSnapshotGav( String s, int vEndPos, String groupId, String artifactId, String version,
+ String fileName, boolean checksum, boolean signature, Gav.HashType checksumType, Gav.SignatureType signatureType )
+ throws IllegalArtifactCoordinateException
{
Integer snapshotBuildNo = null;
@@ -16,6 +16,7 @@
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
import org.sonatype.nexus.artifact.Gav;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.context.IndexCreator;
import org.sonatype.nexus.index.context.IndexingContext;
@@ -45,12 +46,13 @@
private final List<Exception> errors = new ArrayList<Exception>();
public ArtifactContext( File pom, File artifact, File metadata, ArtifactInfo artifactInfo, Gav gav )
+ throws IllegalArtifactCoordinateException
{
- if( artifactInfo == null )
+ if ( artifactInfo == null )
{
- throw new IllegalArgumentException( "Parameter artifactInfo must not be null");
+ throw new IllegalArtifactCoordinateException( "Parameter artifactInfo must not be null." );
}
-
+
this.pom = pom;
this.artifact = artifact;
this.metadata = metadata;
@@ -8,6 +8,7 @@
import java.io.File;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.context.IndexingContext;
/**
@@ -19,6 +20,7 @@
{
String ROLE = ArtifactContextProducer.class.getName();
- public ArtifactContext getArtifactContext( IndexingContext context, File file );
+ public ArtifactContext getArtifactContext( IndexingContext context, File file )
+ throws IllegalArtifactCoordinateException;
}
@@ -17,6 +17,7 @@
import org.apache.maven.mercury.artifact.version.DefaultArtifactVersion;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.nexus.artifact.Gav;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.artifact.VersionUtils;
/**
@@ -276,7 +277,8 @@ public String getRootGroup()
return groupId;
}
- public Gav calculateGav()
+ public Gav calculateGav()
+ throws IllegalArtifactCoordinateException
{
return new Gav(
groupId,
@@ -11,6 +11,7 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.StringUtils;
import org.sonatype.nexus.artifact.Gav;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.context.IndexingContext;
import org.sonatype.nexus.index.locator.ArtifactLocator;
import org.sonatype.nexus.index.locator.GavHelpedLocator;
@@ -36,6 +37,7 @@
* Get ArtifactContext for given pom or artifact (jar, war, etc). A file can be
*/
public ArtifactContext getArtifactContext( IndexingContext context, File file )
+ throws IllegalArtifactCoordinateException
{
// TODO shouldn't this use repository layout instead?
@@ -132,9 +134,10 @@ private boolean isIndexable( File file )
}
private Gav getGavFromPath( IndexingContext context, String repositoryPath, String artifactPath )
+ throws IllegalArtifactCoordinateException
{
String path = artifactPath.substring( repositoryPath.length() + 1 ).replace( '\\', '/' );
-
+
return context.getGavCalculator().pathToGav( path );
}
@@ -14,6 +14,7 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.context.IndexingContext;
/**
@@ -83,11 +84,20 @@ private void processFile( File file, ScanningRequest request )
{
IndexingContext context = request.getIndexingContext();
- ArtifactContext ac = artifactContextProducer.getArtifactContext( context, file );
+ try
+ {
+ ArtifactContext ac = artifactContextProducer.getArtifactContext( context, file );
- if ( ac != null )
+ if ( ac != null )
+ {
+ request.getArtifactScanningListener().artifactDiscovered( ac );
+ }
+ }
+ catch ( IllegalArtifactCoordinateException e )
{
- request.getArtifactScanningListener().artifactDiscovered( ac );
+ getLogger().warn(
+ "Failed to process file: '" + file.getAbsolutePath() + "' while scanning a maven 2 directory.",
+ e );
}
}
}
@@ -18,15 +18,18 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.TermQuery;
+import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.context.IndexingContext;
/**
* A default scanning listener
*
* @author Eugene Kuleshov
*/
-class DefaultScannerListener implements
- ArtifactScanningListener
+class DefaultScannerListener
+ extends AbstractLogEnabled
+ implements ArtifactScanningListener
{
private final IndexingContext context;
private final IndexerEngine indexerEngine;
@@ -237,13 +240,20 @@ private void removeDeletedArtifacts( IndexingContext context, ScanningResult res
}
// minimal ArtifactContext for removal
- ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() );
-
- for ( int i = 0; i < hits.length(); i++ )
+ try
{
- indexerEngine.remove( context, ac );
-
- deleted++;
+ ArtifactContext ac = new ArtifactContext( null, null, null, ai, ai.calculateGav() );
+
+ for ( int i = 0; i < hits.length(); i++ )
+ {
+ indexerEngine.remove( context, ac );
+
+ deleted++;
+ }
+ }
+ catch ( IllegalArtifactCoordinateException e )
+ {
+ getLogger().warn( "Failed to remove deleted artifact from Search Engine.", e );
}
}
}
@@ -559,6 +559,7 @@ public void testGavExtreme()
}
public void testIssueNexus57()
+ throws Exception
{
Gav gav;
// broken path, baseVersion and version mismatch (2.0-SNAPSHOT vs 2.0-alpha-1...)
@@ -26,6 +26,7 @@
import org.jmock.api.Invocation;
import org.jmock.lib.action.VoidAction;
import org.sonatype.nexus.artifact.Gav;
+import org.sonatype.nexus.artifact.IllegalArtifactCoordinateException;
import org.sonatype.nexus.index.ArtifactContext;
import org.sonatype.nexus.index.ArtifactInfo;
import org.sonatype.nexus.index.FlatSearchRequest;
@@ -596,6 +597,7 @@ Properties getProperties()
private ArtifactContext createArtifactContext( String repositoryId, String groupId, String artifactId,
String version, String classifier )
+ throws IllegalArtifactCoordinateException
{
String path = createPath( groupId, artifactId, version, classifier );
File pomFile = new File( path + ".pom" );

0 comments on commit bcf196d

Please sign in to comment.