PR: MNG-291

improved error reporting related to not properly resolving dependencies before trying to get the classpath


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163919 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-04-13 00:27:55 +00:00
parent ce944b2a40
commit ce968a2dd9
2 changed files with 55 additions and 6 deletions

View File

@ -0,0 +1,33 @@
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:brett@apache.org">Brett Porter</a>
* @version $Id$
* @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" );
}
}

View File

@ -18,6 +18,7 @@ package org.apache.maven.project;
*/
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 class MavenProject
}
public List getCompileClasspathElements()
throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() );
@ -238,14 +240,19 @@ public class MavenProject
// 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 @@ public class MavenProject
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 class MavenProject
}
public List getRuntimeClasspathElements()
throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() + 1 );
@ -284,8 +296,12 @@ public class MavenProject
// 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() );
}
}
}