@Test public void testRewritePOMs() 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.writeStringToFile( targetFile, FileUtils.readFileToString( pom, StandardCharsets.UTF_8 ) .replaceAll( "dospom", "newdospom" ), StandardCharsets.UTF_8 ); FileUtils.copyFile( pom, targetFile ); List<Project> projects = pomIO.parseProject( targetFile ); Model model = projects.get( 0 ).getModel(); 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 ); HashSet<Project> changed = new HashSet<>(); changed.add( p ); pomIO.rewritePOMs( changed ); assertTrue( FileUtils.contentEqualsIgnoreEOL( pom, targetFile, StandardCharsets.UTF_8.toString() ) ); assertTrue( FileUtils.contentEquals( targetFile, pom ) ); }
public ProjectVersionRef rewritePOMs( final Set<Project> changed ) throws ManipulationException { ProjectVersionRef result = null; manifestComment = "Modified by POM Manipulation Extension for Maven " + ManifestUtils.getManifestInformation(PomIO.class); for ( final Project project : changed ) { if ( project.isExecutionRoot() ) { result = project.getKey(); } if (logger.isDebugEnabled()) { logger.debug( "{} modified! Rewriting.", project ); } File pom = project.getPom(); final Model model = project.getModel(); logger.trace( "Rewriting: {} in place of: {}{} to POM: {}", model.getId(), project.getKey(), System.lineSeparator(), pom ); write( project, pom, model ); 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; }
PomIO { public ProjectVersionRef rewritePOMs( final Set<Project> changed ) throws ManipulationException { ProjectVersionRef result = null; manifestComment = "Modified by POM Manipulation Extension for Maven " + ManifestUtils.getManifestInformation(PomIO.class); for ( final Project project : changed ) { if ( project.isExecutionRoot() ) { result = project.getKey(); } if (logger.isDebugEnabled()) { logger.debug( "{} modified! Rewriting.", project ); } File pom = project.getPom(); final Model model = project.getModel(); logger.trace( "Rewriting: {} in place of: {}{} to POM: {}", model.getId(), project.getKey(), System.lineSeparator(), pom ); write( project, pom, model ); 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; } }
PomIO { public ProjectVersionRef rewritePOMs( final Set<Project> changed ) throws ManipulationException { ProjectVersionRef result = null; manifestComment = "Modified by POM Manipulation Extension for Maven " + ManifestUtils.getManifestInformation(PomIO.class); for ( final Project project : changed ) { if ( project.isExecutionRoot() ) { result = project.getKey(); } if (logger.isDebugEnabled()) { logger.debug( "{} modified! Rewriting.", project ); } File pom = project.getPom(); final Model model = project.getModel(); logger.trace( "Rewriting: {} in place of: {}{} to POM: {}", model.getId(), project.getKey(), System.lineSeparator(), pom ); write( project, pom, model ); 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; }  }
PomIO { public ProjectVersionRef rewritePOMs( final Set<Project> changed ) throws ManipulationException { ProjectVersionRef result = null; manifestComment = "Modified by POM Manipulation Extension for Maven " + ManifestUtils.getManifestInformation(PomIO.class); for ( final Project project : changed ) { if ( project.isExecutionRoot() ) { result = project.getKey(); } if (logger.isDebugEnabled()) { logger.debug( "{} modified! Rewriting.", project ); } File pom = project.getPom(); final Model model = project.getModel(); logger.trace( "Rewriting: {} in place of: {}{} to POM: {}", model.getId(), project.getKey(), System.lineSeparator(), pom ); write( project, pom, model ); 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; }  List<Project> parseProject( final File pom ); ProjectVersionRef rewritePOMs( final Set<Project> changed ); void writeModel( final Model model, final File target); }
PomIO { public ProjectVersionRef rewritePOMs( final Set<Project> changed ) throws ManipulationException { ProjectVersionRef result = null; manifestComment = "Modified by POM Manipulation Extension for Maven " + ManifestUtils.getManifestInformation(PomIO.class); for ( final Project project : changed ) { if ( project.isExecutionRoot() ) { result = project.getKey(); } if (logger.isDebugEnabled()) { logger.debug( "{} modified! Rewriting.", project ); } File pom = project.getPom(); final Model model = project.getModel(); logger.trace( "Rewriting: {} in place of: {}{} to POM: {}", model.getId(), project.getKey(), System.lineSeparator(), pom ); write( project, pom, model ); 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; }  List<Project> parseProject( final File pom ); ProjectVersionRef rewritePOMs( final Set<Project> changed ); void writeModel( final Model model, final File target);  }