brett 2005/04/12 17:27:55
Modified: maven-core/src/main/java/org/apache/maven/project
MavenProject.java
Added: maven-core/src/main/java/org/apache/maven/artifact
DependencyResolutionRequiredException.java
Log:
PR: MNG-291
improved error reporting related to not properly resolving dependencies
before trying to get the classpath
Revision Changes Path
1.1
maven-components/maven-core/src/main/java/org/apache/maven/artifact/DependencyResolutionRequiredException.java
Index: DependencyResolutionRequiredException.java
===================================================================
package org.apache.maven.artifact;
/*
* 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.
*/
/**
* Exception that occurs when an artifact file is used, but has not been
resolved.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Brett Porter</a>
* @version $Id: DependencyResolutionRequiredException.java,v 1.1 2005/04/13
00:27:55 brett Exp $
* @todo it may be better for this to move to maven-artifact, and
artifact.getFile() to throw it - perhaps it is a runtime exception?
*/
public class DependencyResolutionRequiredException
extends Exception
{
public DependencyResolutionRequiredException( Artifact artifact )
{
super( "Attempted to access the artifact " + artifact + "; which has
not yet been resolved" );
}
}
1.40 +22 -6
maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java
Index: MavenProject.java
===================================================================
RCS file:
/home/cvs/maven-components/maven-core/src/main/java/org/apache/maven/project/MavenProject.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- MavenProject.java 31 Mar 2005 09:32:43 -0000 1.39
+++ MavenProject.java 13 Apr 2005 00:27:55 -0000 1.40
@@ -18,6 +18,7 @@
*/
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.artifact.construction.ArtifactConstructionSupport;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.model.Build;
@@ -228,6 +229,7 @@
}
public List getCompileClasspathElements()
+ throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() );
@@ -238,14 +240,19 @@
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) )
{
- // TODO: this assumes resolution, which may not have been
the case - improve error reporting in that instance
- list.add( a.getFile().getPath() );
+ File file = a.getFile();
+ if ( file == null )
+ {
+ throw new DependencyResolutionRequiredException( a );
+ }
+ list.add( file.getPath() );
}
}
return list;
}
public List getTestClasspathElements()
+ throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() + 1 );
@@ -261,8 +268,12 @@
if ( Artifact.SCOPE_TEST.equals( a.getScope() ) ||
Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
- // TODO: this assumes resolution, which may not have
been the case - improve error reporting in that instance
- list.add( a.getFile().getPath() );
+ File file = a.getFile();
+ if ( file == null )
+ {
+ throw new DependencyResolutionRequiredException( a );
+ }
+ list.add( file.getPath() );
}
}
}
@@ -270,6 +281,7 @@
}
public List getRuntimeClasspathElements()
+ throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() + 1 );
@@ -284,8 +296,12 @@
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_COMPILE.equals( a.getScope() ) ||
Artifact.SCOPE_RUNTIME.equals( a.getScope() ) )
{
- // TODO: this assumes resolution, which may not have
been the case - improve error reporting in that instance
- list.add( a.getFile().getPath() );
+ File file = a.getFile();
+ if ( file == null )
+ {
+ throw new DependencyResolutionRequiredException( a );
+ }
+ list.add( file.getPath() );
}
}
}