org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader Java Examples
The following examples show how to use
org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UseReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private void noRangeMatching( ModifiedPomXMLEventReader pom, Dependency dep, String version, String releaseVersion, ArtifactVersions versions ) throws XMLStreamException { if ( versions.containsVersion( releaseVersion ) ) { if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, releaseVersion, getProject().getModel() ) ) { getLog().info( "Updated " + toString( dep ) + " to version " + releaseVersion ); } } else if ( failIfNotReplaced ) { throw new NoSuchElementException( "No matching release of " + toString( dep ) + " found for update." ); } }
Example #2
Source File: LockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws MojoExecutionException when things go wrong * @throws MojoFailureException when things go wrong in a very bad way * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { lockSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { lockSnapshots( pom, getProject().getDependencies() ); } if ( getProject().getParent() != null && isProcessingParent() ) { lockParentSnapshot( pom, getProject().getParent() ); } }
Example #3
Source File: UseNextSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useNextSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextSnapshots( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #4
Source File: PomHelperTest.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Tests what happens when changing a long property substitution pattern, e.g. * <a href="http://jira.codehaus.org/browse/MVERSIONS-44">MVERSIONS-44</a> * * @throws Exception if the test fails. */ @Test public void testLongProperties() throws Exception { URL url = getClass().getResource( "PomHelperTest.testLongProperties.pom.xml" ); File file = new File( url.getPath() ); StringBuilder input = PomHelper.readXmlFile( file ); XMLInputFactory inputFactory = XMLInputFactory2.newInstance(); inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE ); ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory, file.getAbsolutePath() ); String oldVersion = PomHelper.getProjectVersion( pom ); String newVersion = "1"; assertTrue( "The pom has been modified", PomHelper.setProjectVersion( pom, newVersion ) ); assertEquals( newVersion, PomHelper.getProjectVersion( pom ) ); assertNotSame( oldVersion, newVersion ); }
Example #5
Source File: UseReactorMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( isProcessingParent() && getProject().hasParent() ) { useReactor( pom, getProject().getParent() ); } if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useReactor( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReactor( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #6
Source File: UseNextVersionsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useNextVersions( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextVersions( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #7
Source File: UseReactorMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private void useReactor( ModifiedPomXMLEventReader pom, MavenProject parent ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { for ( Object reactorProject : reactorProjects ) { MavenProject project = (MavenProject) reactorProject; if ( StringUtils.equals( project.getGroupId(), parent.getGroupId() ) && StringUtils.equals( project.getArtifactId(), parent.getArtifactId() ) && !StringUtils.equals( project.getVersion(), parent.getVersion() ) ) { if ( PomHelper.setProjectParentVersion( pom, project.getVersion() ) ) { getLog().info( "Updated parent " + toString( parent ) + " to version " + project.getVersion() ); } } } }
Example #8
Source File: ForceReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useReleases( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReleases( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #9
Source File: PomHelperTest.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Tests if imported POMs are properly read from dependency management section. Such logic is required to resolve * <a href="https://github.com/mojohaus/versions-maven-plugin/issues/134">bug #134</a> * * @throws Exception if the test fails. */ @Test public void testImportedPOMsRetrievedFromDependencyManagement() throws Exception { URL url = getClass().getResource( "PomHelperTest.dependencyManagementBOMs.pom.xml" ); File file = new File( url.getPath() ); StringBuilder input = PomHelper.readXmlFile( file ); XMLInputFactory inputFactory = XMLInputFactory2.newInstance(); inputFactory.setProperty( XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE ); ModifiedPomXMLEventReader pom = new ModifiedPomXMLEventReader( input, inputFactory, file.getAbsolutePath() ); List<Dependency> dependencies = PomHelper.readImportedPOMsFromDependencyManagementSection( pom ); assertNotNull( dependencies ); assertEquals( 1, dependencies.size() ); Dependency dependency = dependencies.get( 0 ); assertEquals( "org.group1", dependency.getGroupId() ); assertEquals( "artifact-pom", dependency.getArtifactId() ); assertEquals( "1.0-SNAPSHOT", dependency.getVersion() ); assertEquals( "import", dependency.getScope() ); assertEquals( "pom", dependency.getType() ); }
Example #10
Source File: AbstractVersionsUpdaterMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
protected void updatePropertyToNewestVersion( ModifiedPomXMLEventReader pom, Property property, PropertyVersions version, String currentVersion, boolean allowDowngrade, int segment ) throws MojoExecutionException, XMLStreamException { ArtifactVersion winner = version.getNewestVersion( currentVersion, property, this.allowSnapshots, this.reactorProjects, this.getHelper(), allowDowngrade, segment ); if ( winner == null || currentVersion.equals( winner.toString() ) ) { getLog().info( "Property ${" + property.getName() + "}: Leaving unchanged as " + currentVersion ); } else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.getName(), winner.toString() ) ) { getLog().info( "Updated ${" + property.getName() + "} from " + currentVersion + " to " + winner ); } }
Example #11
Source File: SetScmTagMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
@Override protected void update(ModifiedPomXMLEventReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { try { Model model = PomHelper.getRawModel( pom ); Scm scm = model.getScm(); if (scm == null) { throw new MojoFailureException( "No <scm> was present" ); } getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag ); boolean success = PomHelper.setProjectValue(pom, "/project/scm/tag", newTag ); if ( !success ) { throw new MojoFailureException( "Could not update the SCM tag" ); } } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #12
Source File: UnlockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws MojoExecutionException when things go wrong * @throws MojoFailureException when things go wrong in a very bad way * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { unlockSnapshots( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { unlockSnapshots( pom, getProject().getDependencies() ); } if ( getProject().getParent() != null && isProcessingParent() ) { unlockParentSnapshot( pom, getProject().getParent() ); } }
Example #13
Source File: ResolveRangesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private void resolvePropertyRanges( ModifiedPomXMLEventReader pom ) throws XMLStreamException, MojoExecutionException { Map<Property, PropertyVersions> propertyVersions = this.getHelper().getVersionPropertiesMap( getProject(), null, includeProperties, excludeProperties, true ); for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() ) { Property property = entry.getKey(); PropertyVersions version = entry.getValue(); final String currentVersion = getProject().getProperties().getProperty( property.getName() ); if ( currentVersion == null || !matchRangeRegex.matcher( currentVersion ).find() ) { continue; } property.setVersion( currentVersion ); int segment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); // TODO: Check if we could add allowDowngrade ? updatePropertyToNewestVersion( pom, property, version, currentVersion, false, segment ); } }
Example #14
Source File: UseReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( getProject().getParent() != null && isProcessingParent() ) { useReleases( pom, getProject().getParent() ); } if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useReleases( pom, PomHelper.readImportedPOMsFromDependencyManagementSection( pom ) ); useReleases( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useReleases( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #15
Source File: LockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void lockParentSnapshot( ModifiedPomXMLEventReader pom, MavenProject parent ) throws XMLStreamException, MojoExecutionException { if ( parent == null ) { getLog().info( "Project does not have a parent" ); return; } if ( reactorProjects.contains( parent ) ) { getLog().info( "Project's parent is part of the reactor" ); return; } Artifact parentArtifact = parent.getArtifact(); String parentVersion = parentArtifact.getVersion(); Matcher versionMatcher = matchSnapshotRegex.matcher( parentVersion ); if ( versionMatcher.find() && versionMatcher.end() == parentVersion.length() ) { String lockedParentVersion = resolveSnapshotVersion( parentArtifact ); if ( !parentVersion.equals( lockedParentVersion ) ) { if ( PomHelper.setProjectParentVersion( pom, lockedParentVersion ) ) { getLog().info( "Locked parent " + parentArtifact.toString() + " to version " + lockedParentVersion ); } } } }
Example #16
Source File: LockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void lockSnapshots( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies ) throws XMLStreamException, MojoExecutionException { for ( Dependency dep : dependencies ) { if ( isExcludeReactor() && isProducedByReactor( dep ) ) { getLog().info( "Ignoring reactor dependency: " + toString( dep ) ); continue; } if ( isHandledByProperty( dep ) ) { getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) ); continue; } if ( !isIncluded( this.toArtifact( dep ) ) ) { continue; } String version = dep.getVersion(); Matcher versionMatcher = matchSnapshotRegex.matcher( version ); if ( versionMatcher.find() && versionMatcher.end() == version.length() ) { String lockedVersion = resolveSnapshotVersion( dep ); if ( !version.equals( lockedVersion ) ) { if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, lockedVersion, getProject().getModel() ) ) { getLog().info( "Locked " + toString( dep ) + " to version " + lockedVersion ); } } } } }
Example #17
Source File: UseNextReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useNextReleases( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useNextReleases( pom, getProject().getDependencies() ); } }
Example #18
Source File: UseLatestReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * @param pom the pom to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong * @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way * @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { try { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useLatestReleases( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useLatestReleases( pom, getProject().getDependencies() ); } if ( getProject().getParent() != null && isProcessingParent() ) { Dependency dependency = new Dependency(); dependency.setArtifactId(getProject().getParent().getArtifactId()); dependency.setGroupId(getProject().getParent().getGroupId()); dependency.setVersion(getProject().getParent().getVersion()); dependency.setType("pom"); List list = new ArrayList(); list.add(dependency); useLatestReleases( pom, list); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #19
Source File: UnlockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void unlockSnapshots( ModifiedPomXMLEventReader pom, List<Dependency> dependencies ) throws XMLStreamException, MojoExecutionException { for ( Dependency dep : dependencies ) { if ( isExcludeReactor() && isProducedByReactor( dep ) ) { getLog().info( "Ignoring reactor dependency: " + toString( dep ) ); continue; } if ( isHandledByProperty( dep ) ) { getLog().debug( "Ignoring dependency with property as version: " + toString( dep ) ); continue; } if ( !isIncluded( this.toArtifact( dep ) ) ) { continue; } String version = dep.getVersion(); Matcher versionMatcher = matchSnapshotRegex.matcher( version ); if ( versionMatcher.find() && versionMatcher.end() == version.length() ) { String unlockedVersion = versionMatcher.replaceFirst( "-SNAPSHOT" ); if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), unlockedVersion, getProject().getModel() ) ) { getLog().info( "Unlocked " + toString( dep ) + " to version " + unlockedVersion ); } } } }
Example #20
Source File: PomHelper.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Retrieves the project version from the pom. * * @param pom The pom. * @return the project version or <code>null</code> if the project version is not defined (i.e. inherited from * parent version). * @throws XMLStreamException if something went wrong. */ public static String getProjectVersion( final ModifiedPomXMLEventReader pom ) throws XMLStreamException { Stack<String> stack = new Stack<String>(); String path = ""; final Pattern matchScopeRegex = Pattern.compile( "/project/version" ); pom.rewind(); while ( pom.hasNext() ) { XMLEvent event = pom.nextEvent(); if ( event.isStartElement() ) { stack.push( path ); path = path + "/" + event.asStartElement().getName().getLocalPart(); if ( matchScopeRegex.matcher( path ).matches() ) { pom.mark( 0 ); } } if ( event.isEndElement() ) { if ( matchScopeRegex.matcher( path ).matches() ) { pom.mark( 1 ); if ( pom.hasMark( 0 ) && pom.hasMark( 1 ) ) { return pom.getBetween( 0, 1 ).trim(); } pom.clearMark( 0 ); pom.clearMark( 1 ); } path = stack.pop(); } } return null; }
Example #21
Source File: ResolveRangesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * @param pom the pom to update. * @throws MojoExecutionException when things go wrong * @throws MojoFailureException when things go wrong in a very bad way * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { // Note we have to get the dependencies from the model because the dependencies in the // project may have already had their range resolved [MNG-4138] if ( hasDependencyManagement() && hasDependenciesInDependencyManagement() && isProcessingDependencyManagement() ) { getLog().debug( "processing dependencyManagement of " + getProject().getId() ); resolveRanges( pom, getProject().getModel().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { getLog().debug( "processing dependencies of " + getProject().getId() ); resolveRanges( pom, getProject().getModel().getDependencies() ); } if ( hasParent() && isProcessingParent() ) { getLog().debug( "processing parent " + getProject().getId() ); resolveRangesInParent( pom ); } if ( processProperties ) { getLog().debug( "processing properties of " + getProject().getId() ); resolvePropertyRanges( pom ); } }
Example #22
Source File: UseDepVersionMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
@SuppressWarnings( "unchecked" ) @Override protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException { if ( depVersion == null || depVersion.equals( "" ) ) { throw new IllegalArgumentException( "depVersion must be supplied with use-specific-version, and cannot be blank." ); } if ( !forceVersion && !hasIncludes() ) { throw new IllegalArgumentException( "The use-specific-version goal is intended to be used with a single artifact. Please specify a value for the 'includes' parameter, or use -DforceVersion=true to override this check." ); } try { if ( getProject().getDependencyManagement() != null && isProcessingDependencyManagement() ) { useDepVersion( pom, getProject().getDependencyManagement().getDependencies() ); } if ( getProject().getDependencies() != null && isProcessingDependencies() ) { useDepVersion( pom, getProject().getDependencies() ); } } catch ( ArtifactMetadataRetrievalException e ) { throw new MojoExecutionException( e.getMessage(), e ); } }
Example #23
Source File: CompareDependenciesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Updates the properties holding a version if necessary. */ private List<String> updatePropertyVersions( ModifiedPomXMLEventReader pom, Map<Property, PropertyVersions> versionProperties, Map<String, Dependency> remoteDependencies ) throws XMLStreamException { List<String> result = new ArrayList<>(); for ( Map.Entry<Property, PropertyVersions> entry : versionProperties.entrySet() ) { Property property = entry.getKey(); PropertyVersions version = entry.getValue(); String candidateVersion = computeCandidateVersion( remoteDependencies, property, version ); if ( candidateVersion != null ) { String originalVersion = version.getAssociations()[0].getArtifact().getVersion(); // Yekes if ( !candidateVersion.equals( originalVersion ) ) // Update needed { result.add( writeDiffMessage( property.getName(), originalVersion, candidateVersion ).toString() ); if ( !reportMode && PomHelper.setPropertyVersion( pom, null, property.getName(), candidateVersion ) ) { getLog().info( "Updated ${" + property.getName() + "} from " + originalVersion + " to " + candidateVersion ); } } } } return result; }
Example #24
Source File: SeparatePatternsForIncludesAnExcludesTest.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { mojo = new AbstractVersionsDependencyUpdaterMojo() { protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { } }; }
Example #25
Source File: UpdatePropertiesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * @param pom the pom to update. * @throws MojoExecutionException when things go wrong * @throws MojoFailureException when things go wrong in a very bad way * @throws XMLStreamException when things go wrong with XML streaming * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader) * @since 1.0-alpha-1 */ protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { Map<Property, PropertyVersions> propertyVersions = this.getHelper().getVersionPropertiesMap( getProject(), properties, includeProperties, excludeProperties, autoLinkItems ); for ( Map.Entry<Property, PropertyVersions> entry : propertyVersions.entrySet() ) { Property property = entry.getKey(); PropertyVersions version = entry.getValue(); final String currentVersion = getProject().getProperties().getProperty( property.getName() ); if ( currentVersion == null ) { continue; } boolean canUpdateProperty = true; for ( ArtifactAssociation association : version.getAssociations() ) { if ( !( isIncluded( association.getArtifact() ) ) ) { getLog().info( "Not updating the property ${" + property.getName() + "} because it is used by artifact " + association.getArtifact().toString() + " and that artifact is not included in the list of " + " allowed artifacts to be updated." ); canUpdateProperty = false; break; } } if ( canUpdateProperty ) { int segment = determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates ); updatePropertyToNewestVersion( pom, property, version, currentVersion, allowDowngrade, segment ); } } }
Example #26
Source File: POM.java From pomutils with Apache License 2.0 | 5 votes |
private void initialize() throws IOException, XMLStreamException { StringBuilder input = new StringBuilder(FileUtils.fileRead(pomFile)); pom = new ModifiedPomXMLEventReader(input, XML_INPUT_FACTORY); rawModel = PomHelper.getRawModel(pom); projectIdentifier = calculateProjectIdentifier(); projectVersion = rawModel.getVersion(); parentVersion = rawModel.getParent() != null ? rawModel.getParent().getVersion() : null; scmTag = rawModel.getScm() != null ? rawModel.getScm().getTag() : null; }
Example #27
Source File: PomUpdater.java From spring-cloud-release-tools with Apache License 2.0 | 5 votes |
void write(ModelWrapper wrapper, VersionsFromBom versionsFromBom, File pom) { try { VersionChangerFactory versionChangerFactory = new VersionChangerFactory(); StringBuilder input = PomHelper.readXmlFile(pom); ModifiedPomXMLEventReader parsedPom = newModifiedPomXER(input); versionChangerFactory.setPom(parsedPom); LoggerToMavenLog loggerToMavenLog = new LoggerToMavenLog(PomWriter.log); versionChangerFactory.setLog(loggerToMavenLog); versionChangerFactory.setModel(wrapper.model); log.info( "Applying version / parent / plugin / project changes to the pom [{}]", pom); VersionChanger changer = versionChangerFactory.newVersionChanger(true, true, true, true); for (VersionChange versionChange : wrapper.sourceChanges) { changer.apply(versionChange); } log.debug("Applying properties changes to the pom [{}]", pom); new PropertyVersionChanger(wrapper, versionsFromBom, parsedPom, loggerToMavenLog).apply(null); try (BufferedWriter bw = new BufferedWriter(new FileWriter(pom))) { bw.write(input.toString()); } log.debug("Flushed changes to the pom file [{}]", pom); } catch (Exception e) { log.error("Exception occurred while trying to apply changes to the POM", e); } }
Example #28
Source File: UseReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void rangeMatching( ModifiedPomXMLEventReader pom, Dependency dep, String version, String releaseVersion, ArtifactVersions versions ) throws XMLStreamException { ArtifactVersion finalVersion = null; for ( ArtifactVersion proposedVersion : versions.getVersions( false ) ) { if ( proposedVersion.toString().startsWith( releaseVersion ) ) { getLog().debug( "Found matching version for " + toString( dep ) + " to version " + releaseVersion ); finalVersion = proposedVersion; } } if ( finalVersion != null ) { if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, finalVersion.toString(), getProject().getModel() ) ) { getLog().info( "Updated " + toString( dep ) + " to version " + finalVersion.toString() ); } } else { getLog().info( "No matching release of " + toString( dep ) + " to update via rangeMatching." ); if ( failIfNotReplaced ) { throw new NoSuchElementException( "No matching release of " + toString( dep ) + " found for update via rangeMatching." ); } } }
Example #29
Source File: UseReactorMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void useReactor( ModifiedPomXMLEventReader pom, Collection<Dependency> dependencies ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { for ( Dependency dep : dependencies ) { Artifact artifact = this.toArtifact( dep ); if ( !isIncluded( artifact ) ) { continue; } for ( Object reactorProject : reactorProjects ) { MavenProject project = (MavenProject) reactorProject; if ( StringUtils.equals( project.getGroupId(), dep.getGroupId() ) && StringUtils.equals( project.getArtifactId(), dep.getArtifactId() ) && !StringUtils.equals( project.getVersion(), dep.getVersion() ) ) { if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), project.getVersion(), getProject().getModel() ) ) { getLog().info( "Updated " + toString( dep ) + " to version " + project.getVersion() ); } break; } } } }
Example #30
Source File: SetMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
/** * Updates the pom file. * * @param pom The pom file to update. * @throws org.apache.maven.plugin.MojoExecutionException when things go wrong. * @throws org.apache.maven.plugin.MojoFailureException when things go wrong. * @throws javax.xml.stream.XMLStreamException when things go wrong. */ protected synchronized void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException { ContextualLog log = new DelegatingContextualLog( getLog() ); try { Model model = PomHelper.getRawModel( pom ); log.setContext( "Processing " + PomHelper.getGroupId( model ) + ":" + PomHelper.getArtifactId( model ) ); VersionChangerFactory versionChangerFactory = new VersionChangerFactory(); versionChangerFactory.setPom( pom ); versionChangerFactory.setLog( log ); versionChangerFactory.setModel( model ); VersionChanger changer = versionChangerFactory.newVersionChanger( processParent, processProject, processDependencies, processPlugins ); for ( VersionChange versionChange : sourceChanges ) { changer.apply( versionChange ); } } catch ( IOException e ) { throw new MojoExecutionException( e.getMessage(), e ); } log.clearContext(); }