use of org.commonjava.maven.ext.common.ManipulationException 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.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class PomIO method determineEOL.
private static LineSeparator determineEOL(File pom) throws ManipulationException {
try (BufferedInputStream bufferIn = new BufferedInputStream(new FileInputStream(pom))) {
int prev = -1;
int ch;
while ((ch = bufferIn.read()) != -1) {
if (ch == '\n') {
if (prev == '\r') {
return LineSeparator.CRNL;
} else {
return LineSeparator.NL;
}
} else if (prev == '\r') {
return LineSeparator.CR;
}
prev = ch;
}
throw new ManipulationException("Could not determine end-of-line marker mode");
} catch (IOException ioe) {
throw new ManipulationException("Could not determine end-of-line marker mode", ioe);
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class XMLIO method writeXML.
public void writeXML(File target, Document contents) throws ManipulationException {
try {
// TODO: https://stackoverflow.com/questions/24551962/adding-linebreak-in-xml-file-before-root-node
// TODO: Can't get a clean round trip due to newline differences.
// StreamResult result = new StreamResult( new FileWriter( target));
// transformer.transform( new DOMSource( contents ), result);
String result = convert(contents);
// Adjust for comment before root node and possibly insert a newline.
result = result.replaceFirst("(?s)(<!--.*-->)<", "$1\n<");
FileUtils.writeStringToFile(target, result);
} catch (IOException e) {
logger.error("XML transformer failure", e);
throw new ManipulationException("XML transformer failure", e);
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class JSONIOTest method countMatches.
@Test
public void countMatches() throws ManipulationException, IOException {
String pluginsPath = "$..plugins";
String reposURLPath = "$.repository.url";
try {
DocumentContext doc = jsonIO.parseJSON(pluginFile);
List o = doc.read(pluginsPath);
assertTrue(o.size() == 1);
o = doc.read(reposURLPath);
assertTrue(o.size() == 1);
} catch (JsonPathException e) {
throw new ManipulationException("Caught JsonPath", e);
}
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ManipulatingLifeCycleParticipant method afterProjectsRead.
@Override
public void afterProjectsRead(final MavenSession mavenSession) throws MavenExecutionException {
final ManipulationException error = session.getError();
if (error != null) {
throw new MavenExecutionException("POM Manipulation failed: " + error.getMessage(), error);
}
super.afterProjectsRead(mavenSession);
}
Aggregations