Skip to content

Commit

Permalink
Improve error message when addon version resolution fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Aug 2, 2013
1 parent 6353532 commit 46009f4
Showing 1 changed file with 18 additions and 9 deletions.
Expand Up @@ -65,8 +65,10 @@ private Collection<DeploymentDescription> generateDependencyDeployments(Class<?>
version = resolveVersionFromPOM(classUnderTest, addon.name());
if (version == null)
{
throw new IllegalStateException("Could not resolve the version for " + addon.name()
+ ". Either specify the version for this test or add it to pom.xml");
throw new IllegalStateException("Could not resolve the version for [" + addon.name()
+ "]. Either specify the version for this @" + AddonDependency.class.getSimpleName()
+ " in [" + classUnderTest.getName() + "] or add it to pom.xml located at ["
+ getPomFileFor(classUnderTest) + "]");
}
}
else
Expand Down Expand Up @@ -100,13 +102,7 @@ private String resolveVersionFromPOM(Class<?> classUnderTest, String name)
if (dependencyMap == null)
{
dependencyMap = new HashMap<String, String>();
URL resource = classUnderTest.getClassLoader().getResource("");
if (resource == null)
{
throw new IllegalStateException("Could not find the pom.xml for class " + classUnderTest.getName());
}
String directory = resource.getFile();
File pomFile = findBuildDescriptor(directory);
File pomFile = getPomFileFor(classUnderTest);
try
{
List<Dependency> dependencies = ProjectHelper.INSTANCE.resolveDependenciesFromPOM(pomFile);
Expand All @@ -120,12 +116,25 @@ private String resolveVersionFromPOM(Class<?> classUnderTest, String name)
}
catch (Exception e)
{
// TODO log this instead?
e.printStackTrace();
}
}
return dependencyMap.get(name);
}

private File getPomFileFor(Class<?> classUnderTest)
{
URL resource = classUnderTest.getClassLoader().getResource("");
if (resource == null)
{
throw new IllegalStateException("Could not find the pom.xml for class " + classUnderTest.getName());
}
String directory = resource.getFile();
File pomFile = findBuildDescriptor(directory);
return pomFile;
}

private File findBuildDescriptor(String classLocation)
{
File pom = null;
Expand Down

0 comments on commit 46009f4

Please sign in to comment.