I've added a simple utility class to perform formatting preserving modifications to POM files. This code lives in org.eclipse.iam.pom.util.PomModifier. An example of usage is below:
final Collection<Dependency> dependencies = getDependencies();
PomModifier.modifyPom( pomFile, new PomModificationAction() {
public boolean modify( Model model, IProgressMonitor progressMonitor )
{
model.getDependencies().clear();
for( Dependency d : dependencies )
{
org.eclipse.iam.pom.Dependency dep = PomFactory.eINSTANCE.createDependency();
dep.setArtifactId( d.getArtifactId() );
dep.setClassifier( d.getClassifier() );
dep.setGroupId( d.getGroupId() );
dep.setOptional( d.isOptional() );
dep.setScope( d.getScope() );
dep.setSystemPath( d.getSystemPath() );
dep.setType( d.getType() );
dep.setVersion( d.getVersion() );
model.getDependencies().add( dep );
}
return true;
}
}, new NullProgressMonitor() );
This example would rewrite the <dependencies> section of the pom with a new set of dependencies while leaving the rest of the XML untouched. Any thoughts on this?
Mike