Skip to content

Commit

Permalink
FORGE-820: Placing a fixed xpath factory in resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Mar 12, 2013
1 parent 8ed6057 commit 0f09b6f
Showing 1 changed file with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;

import org.jboss.shrinkwrap.resolver.impl.maven.util.Validate;
import org.sonatype.aether.artifact.Artifact;
Expand Down Expand Up @@ -182,6 +183,7 @@ public File findArtifact(final Artifact artifact)
&& foundArtifact.getArtifactId().equals(artifact.getArtifactId())
&& foundArtifact.getVersion().equals(artifact.getVersion()))
{
// System.out.println("################################# Artifact: " + artifact + " File: " + pomFile);
return pomFile;
}
}
Expand All @@ -202,6 +204,7 @@ else if (fileInfo.isFile())
final File pomFile = new File(file.getParentFile().getParentFile(), "pom.xml");
if (pomFile.isFile())
{
// System.out.println("################################# Artifact: " + artifact + " File: " + pomFile);
return pomFile;
}
}
Expand All @@ -216,6 +219,7 @@ else if (fileInfo.isFile())
if (file.getAbsolutePath().endsWith(name.toString()))
{
// return raw file
// System.out.println("################################# Artifact: " + artifact + " File: " + file);
return file;
}
}
Expand Down Expand Up @@ -253,12 +257,9 @@ public List<String> findVersions(final Artifact artifact)
// this is needed for Surefire when runned as 'mvn package'
else if (fileInfo.isFile())
{
final StringBuilder name = new StringBuilder(artifact.getArtifactId()).append("-").append(
artifact.getVersion());

// TODO: This is nasty
// we need to get a a pom.xml file to be sure we fetch transitive deps as well
if (file.getAbsolutePath().contains(name.toString()))
if (file.getAbsolutePath().contains(artifact.getArtifactId()))
{
if ("pom".equals(artifact.getExtension()))
{
Expand All @@ -278,6 +279,7 @@ else if (fileInfo.isFile())
}
}
}
// System.out.println("################################# Artifact: " + artifact + " Versions: " + versions);
return versions;
}

Expand All @@ -287,7 +289,7 @@ private Set<String> getClassPathEntries(final String classPath)
{
return Collections.emptySet();
}
return new LinkedHashSet<String>(Arrays.asList(classPath.split(String.valueOf(File.pathSeparatorChar))));
return new LinkedHashSet<String>(Arrays.asList(classPath.split(File.pathSeparator)));
}

private FileInfo getClasspathFileInfo(final String classpathEntry)
Expand Down Expand Up @@ -394,7 +396,21 @@ private XPath getXPath()
{
if (xPath == null)
{
final XPathFactory factory = XPathFactory.newInstance();
XPathFactory factory;
try
{
factory = XPathFactory.newInstance(XPathFactory.DEFAULT_OBJECT_MODEL_URI,
"com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl", getClass()
.getClassLoader());
}
catch (XPathFactoryConfigurationException e)
{
throw new RuntimeException(
"XPathFactory#newInstance() failed to create an XPathFactory for the default object model: "
+ XPathFactory.DEFAULT_OBJECT_MODEL_URI
+ " with the XPathFactoryConfigurationException: "
+ e.toString());
}
xPath = factory.newXPath();
}
return xPath;
Expand Down

0 comments on commit 0f09b6f

Please sign in to comment.