use of org.commonjava.maven.ext.common.model.GAV in project pom-manipulation-ext by release-engineering.
the class PomIOTest method testGAVReturnPOMs.
@Test
public void testGAVReturnPOMs() throws Exception {
URL resource = PomIOTest.class.getResource(filename);
assertNotNull(resource);
File pom = new File(resource.getFile());
assertTrue(pom.exists());
File targetFile = folder.newFile("target.xml");
FileUtils.copyFile(pom, targetFile);
Model model = new Model();
model.setGroupId("org.commonjava.maven.ext.versioning.test");
model.setArtifactId("dospom");
model.setVersion("1.0");
model.setPackaging("pom");
model.setModelVersion("4.0.0");
Project p = new Project(targetFile, model);
p.setExecutionRoot();
HashSet<Project> changed = new HashSet<>();
changed.add(p);
GAV gav = pomIO.rewritePOMs(changed);
assertTrue(gav.version.equals("1.0"));
assertTrue(gav.groupId.equals("org.commonjava.maven.ext.versioning.test"));
assertTrue(gav.artifactId.equals("dospom"));
}
use of org.commonjava.maven.ext.common.model.GAV in project pom-manipulation-ext by release-engineering.
the class ManipulationManager method scanAndApply.
/**
* Encapsulates {@link #applyManipulations(List)}
*
* @param session the container session for manipulation.
* @throws ManipulationException if an error occurs.
*/
public void scanAndApply(final ManipulationSession session) throws ManipulationException {
final List<Project> projects = pomIO.parseProject(session.getPom());
session.setProjects(projects);
for (final Project project : projects) {
logger.debug("Got " + project + " (POM: " + project.getPom() + ")");
}
Set<Project> changed = applyManipulations(projects);
// Create a marker file if we made some changes to prevent duplicate runs.
if (!changed.isEmpty()) {
logger.info("Maven-Manipulation-Extension: Rewrite changed: " + projects);
GAV gav = pomIO.rewritePOMs(changed);
try {
final VersioningState state = session.getState(VersioningState.class);
state.setExecutionRootModified(gav);
new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_PATH).mkdirs();
new File(session.getTargetDir().getParentFile(), ManipulationManager.MARKER_FILE).createNewFile();
try (FileWriter writer = new FileWriter(new File(session.getTargetDir().getParentFile(), RESULT_FILE))) {
writer.write(collectResults(session));
}
} catch (IOException e) {
logger.error("Unable to create marker or result file", e);
throw new ManipulationException("Marker/result file creation failed", e);
}
}
// Ensure shutdown of GalleyInfrastructure Executor Service
for (ExtensionInfrastructure e : infrastructure.values()) {
e.finish();
}
logger.info("Maven-Manipulation-Extension: Finished.");
}
use of org.commonjava.maven.ext.common.model.GAV in project pom-manipulation-ext by release-engineering.
the class PomIO method rewritePOMs.
/**
* For any project listed as changed (tracked by GA in the session), write the modified model out to disk.
* Uses JDOM {@link ModelWriter} and {@link MavenJDOMWriter} to preserve as much formatting as possible.
*
* @param changed the modified Projects to write out.
* @return gav execution root GAV
* @throws ManipulationException if an error occurs.
*/
public GAV rewritePOMs(final Set<Project> changed) throws ManipulationException {
GAV result = null;
for (final Project project : changed) {
if (project.isExecutionRoot()) {
result = new GAV(Project.modelKey(project.getModel()));
}
logger.debug(String.format("%s modified! Rewriting.", project));
File pom = project.getPom();
final Model model = project.getModel();
logger.trace("Rewriting: " + model.toString() + " in place of: " + project.getId() + "\n to POM: " + pom);
write(project, pom, model);
// This is a total hack, but the alternative seems to be adding complexity through a custom model processor.
if (pom.getName().equals("interpolated-pom.xml")) {
final File dir = pom.getParentFile();
pom = dir == null ? new File("pom.xml") : new File(dir, "pom.xml");
write(project, pom, model);
}
}
return result;
}
Aggregations