use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.
the class PomPeekTest method findGAVDirectlyInProjectBelowProperties.
@Test
public void findGAVDirectlyInProjectBelowProperties() {
final File pom = getResourceFile(BASE + "direct-gav-below-props.pom");
final PomPeek peek = new PomPeek(pom);
assertThat(peek.getKey(), notNullValue());
final ProjectVersionRef key = peek.getKey();
assertThat(key.getGroupId(), equalTo("test"));
assertThat(key.getArtifactId(), equalTo("direct-gav-below-props"));
assertThat(key.getVersionString(), equalTo("1"));
}
use of org.commonjava.maven.galley.maven.parse.PomPeek in project pom-manipulation-ext by release-engineering.
the class PomIO method peekAtPomHierarchy.
private List<PomPeek> peekAtPomHierarchy(final File topPom) throws ManipulationException {
final List<PomPeek> peeked = new ArrayList<>();
try {
final LinkedList<File> pendingPoms = new LinkedList<>();
pendingPoms.add(topPom.getCanonicalFile());
final String topDir = topPom.getAbsoluteFile().getParentFile().getCanonicalPath();
final Set<File> seen = new HashSet<>();
File topLevelParent = topPom;
while (!pendingPoms.isEmpty()) {
final File pom = pendingPoms.removeFirst();
seen.add(pom);
logger.debug("PEEK: " + pom);
final PomPeek peek = new PomPeek(pom);
final ProjectVersionRef key = peek.getKey();
if (key != null) {
peeked.add(peek);
final File dir = pom.getParentFile();
final String relPath = peek.getParentRelativePath();
if (relPath != null) {
logger.debug("Found parent relativePath: " + relPath + " in pom: " + pom);
File parent = new File(dir, relPath);
if (parent.isDirectory()) {
parent = new File(parent, "pom.xml");
}
parent = parent.getCanonicalFile();
if (parent.getParentFile().getCanonicalPath().startsWith(topDir) && parent.exists() && !seen.contains(parent) && !pendingPoms.contains(parent)) {
topLevelParent = parent;
logger.debug("Possible top level parent " + parent);
pendingPoms.add(parent);
} else {
logger.debug("Skipping reference to non-existent parent relativePath: '" + relPath + "' in: " + pom);
}
}
final Set<String> modules = peek.getModules();
if (modules != null && !modules.isEmpty()) {
for (final String module : modules) {
logger.debug("Found module: " + module + " in pom: " + pom);
File modPom = new File(dir, module);
if (modPom.isDirectory()) {
modPom = new File(modPom, "pom.xml");
}
if (modPom.exists() && !seen.contains(modPom) && !pendingPoms.contains(modPom)) {
pendingPoms.addLast(modPom);
} else {
logger.debug("Skipping reference to non-existent module: '" + module + "' in: " + pom);
}
}
}
} else {
logger.debug("Skipping " + pom + " as its a template file.");
}
}
final HashSet<ProjectVersionRef> projectrefs = new HashSet<>();
for (final PomPeek p : peeked) {
projectrefs.add(p.getKey());
if (p.getPom().equals(topLevelParent)) {
logger.debug("Setting top level parent to " + p.getPom() + " :: " + p.getKey());
p.setInheritanceRoot(true);
}
}
for (final PomPeek p : peeked) {
if (p.getParentKey() == null || !seenThisParent(projectrefs, p.getParentKey())) {
logger.debug("Found a standalone pom " + p.getPom() + " :: " + p.getKey());
p.setInheritanceRoot(true);
}
}
} catch (final IOException e) {
throw new ManipulationException("Problem peeking at POMs.", e);
}
return peeked;
}
use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.
the class PomPeekTest method findGAVDirectlyInProjectAtTop.
@Test
public void findGAVDirectlyInProjectAtTop() {
final File pom = getResourceFile(BASE + "direct-gav-at-top.pom");
final PomPeek peek = new PomPeek(pom);
assertThat(peek.getKey(), notNullValue());
final ProjectVersionRef key = peek.getKey();
assertThat(key.getGroupId(), equalTo("test"));
assertThat(key.getArtifactId(), equalTo("direct-gav-at-top"));
assertThat(key.getVersionString(), equalTo("1"));
}
use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.
the class PomPeekTest method findGAVInheritedFromParentWithGroupAndVersionOverrideAtTop.
@Test
public void findGAVInheritedFromParentWithGroupAndVersionOverrideAtTop() throws Exception {
final File pom = getResourceFile(BASE + "inherited-gav-with-group-override-at-top.pom");
final PomPeek peek = new PomPeek(pom);
final ProjectVersionRef key = peek.getKey();
assertThat(key, notNullValue());
assertThat(key.getGroupId(), equalTo("a-different-test-group"));
assertThat(key.getArtifactId(), equalTo("inherited-gav-with-group-override-at-top"));
assertThat(key.getVersionString(), equalTo("1"));
}
use of org.commonjava.maven.galley.maven.parse.PomPeek in project galley by Commonjava.
the class PomPeekTest method findGAVInheritedFromParentWithVersionOverrideAtTop.
@Test
public void findGAVInheritedFromParentWithVersionOverrideAtTop() {
final File pom = getResourceFile(BASE + "inherited-gav-with-override-at-top.pom");
final PomPeek peek = new PomPeek(pom);
assertThat(peek.getKey(), notNullValue());
final ProjectVersionRef key = peek.getKey();
assertThat(key.getGroupId(), equalTo("test"));
assertThat(key.getArtifactId(), equalTo("inherited-gav-with-override-at-top"));
assertThat(key.getVersionString(), equalTo("2"));
}
Aggregations