use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class Project method modelKey.
public static ProjectVersionRef modelKey(final Model model) throws ManipulationException {
String g = model.getGroupId();
String v = model.getVersion();
if (g == null || v == null) {
final Parent p = model.getParent();
if (p == null) {
throw new ManipulationException("Invalid model: " + model + " Cannot find groupId and/or version!");
}
if (g == null) {
g = p.getGroupId();
}
if (v == null) {
v = p.getVersion();
}
}
final String a = model.getArtifactId();
return new SimpleProjectVersionRef(g, a, v);
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ManifestUtils method getManifestInformation.
/**
* Retrieves the SHA this was built with.
*
* @return the GIT sha of this codebase.
* @throws ManipulationException if an error occurs.
*/
public static String getManifestInformation() throws ManipulationException {
String result = "";
try {
final Enumeration<URL> resources = ManifestUtils.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (resources.hasMoreElements()) {
final URL jarUrl = resources.nextElement();
if (jarUrl.getFile().contains("pom-manipulation-")) {
final Manifest manifest = new Manifest(jarUrl.openStream());
result = manifest.getMainAttributes().getValue("Implementation-Version");
result += " ( SHA: " + manifest.getMainAttributes().getValue("Scm-Revision") + " ) ";
break;
}
}
} catch (final IOException e) {
throw new ManipulationException("Error retrieving information from manifest", e);
}
return result;
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class PomIO method readModelsForManipulation.
/**
* Read {@link Model} instances by parsing the POM directly. This is useful to escape some post-processing that happens when the
* {@link MavenProject#getOriginalModel()} instance is set.
*
* @param executionRoot the top level pom file.
* @param peeked a collection of poms resolved from the top level file.
* @return a collection of Projects
* @throws ManipulationException if an error occurs.
*/
private List<Project> readModelsForManipulation(File executionRoot, final List<PomPeek> peeked) throws ManipulationException {
final List<Project> projects = new ArrayList<>();
final HashMap<Project, ProjectVersionRef> projectToParent = new HashMap<>();
for (final PomPeek peek : peeked) {
final File pom = peek.getPom();
// Sucks, but we have to brute-force reading in the raw model.
// The effective-model building, below, has a tantalizing getRawModel()
// method on the result, BUT this seems to return models that have
// the plugin versions set inside profiles...so they're not entirely
// raw.
Model raw = null;
InputStream in = null;
try {
in = new FileInputStream(pom);
raw = new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, pom, e.getMessage());
} finally {
closeQuietly(in);
}
if (raw == null) {
continue;
}
final Project project = new Project(pom, raw);
projectToParent.put(project, peek.getParentKey());
project.setInheritanceRoot(peek.isInheritanceRoot());
if (executionRoot.equals(pom)) {
logger.debug("Setting execution root to {} with file {}" + (project.isInheritanceRoot() ? " and is the inheritance root. " : ""), project, pom);
project.setExecutionRoot();
try {
if (FileUtils.readFileToString(pom).contains(MODIFIED_BY)) {
project.setIncrementalPME(true);
}
} catch (final IOException e) {
throw new ManipulationException("Failed to read POM: %s", e, pom);
}
}
projects.add(project);
}
// Fill out inheritance info for every project we have created.
for (Project p : projects) {
ProjectVersionRef pvr = projectToParent.get(p);
p.setProjectParent(getParent(projects, pvr));
}
return projects;
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class XMLIO method convert.
public String convert(Document contents) throws ManipulationException {
StringWriter outWriter = new StringWriter();
try {
StreamResult streamResult = new StreamResult(outWriter);
transformer.transform(new DOMSource(contents), streamResult);
} catch (TransformerException e) {
logger.error("XML transformer failure", e);
throw new ManipulationException("XML transformer failure", e);
}
return outWriter.toString();
}
use of org.commonjava.maven.ext.common.ManipulationException in project pom-manipulation-ext by release-engineering.
the class ModelIO method resolveRawModel.
/**
* Read the raw model (equivalent to the pom file on disk) from a given GAV.
*
* @param ref the ProjectVersion to read.
* @return the Maven Model for the GAV
* @throws ManipulationException if an error occurs.
*/
public Model resolveRawModel(final ProjectVersionRef ref) throws ManipulationException {
Transfer transfer;
try {
transfer = galleyWrapper.resolveArtifact(ref.asPomArtifact());
} catch (final TransferException e) {
throw new ManipulationException("Failed to resolve POM: %s.\n--> %s", e, ref, e.getMessage());
}
if (transfer == null) {
throw new ManipulationException("Failed to resolve POM: " + ref.asPomArtifact());
}
InputStream in = null;
try {
in = transfer.openInputStream();
return new MavenXpp3Reader().read(in);
} catch (final IOException | XmlPullParserException e) {
throw new ManipulationException("Failed to build model for POM: %s.\n--> %s", e, ref, e.getMessage());
} finally {
closeQuietly(in);
}
}
Aggregations