From 9c1ce457c32984a1e888202218a554fae589cb08 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Fri, 2 May 2014 13:21:00 +0200 Subject: [PATCH] Added functionality to fix the static resources Zip version in the parent pom.xml. --- .../data/release/maven/MavenOperations.java | 32 +++++++++++++------ .../data/release/maven/ParentPom.java | 29 +++++++++++++++++ 2 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/springframework/data/release/maven/ParentPom.java diff --git a/src/main/java/org/springframework/data/release/maven/MavenOperations.java b/src/main/java/org/springframework/data/release/maven/MavenOperations.java index febd8ef..e2ba3b7 100644 --- a/src/main/java/org/springframework/data/release/maven/MavenOperations.java +++ b/src/main/java/org/springframework/data/release/maven/MavenOperations.java @@ -24,6 +24,7 @@ import java.io.IOException; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.GenericTypeResolver; import org.springframework.data.release.io.CommandResult; import org.springframework.data.release.io.OsCommandOperations; import org.springframework.data.release.io.Workspace; @@ -84,7 +85,19 @@ public class MavenOperations { final Repository repository = new Repository(iteration.getIteration()); final ArtifactVersion commonsVersion = iteration.getModuleVersion(COMMONS); + final ArtifactVersion nextCommonsVersion = commonsVersion.getNextDevelopmentVersion(); final ArtifactVersion buildVersion = iteration.getModuleVersion(BUILD); + final ArtifactVersion nextBuildVersion = buildVersion.getNextDevelopmentVersion(); + + // Fix version of shared resources to to-be-released version. + execute(workspace.getFile("parent/pom.xml", BUILD), new PomCallback() { + + @Override + public ParentPom doWith(ParentPom pom) { + pom.setSharedResourcesVersion(phase.equals(PREPARE) ? buildVersion : nextBuildVersion); + return pom; + } + }); for (ModuleIteration module : iteration.getModulesExcept(BUILD)) { @@ -95,21 +108,20 @@ public class MavenOperations { continue; } - execute(workspace.getFile(POM_XML, project), new PomCallback() { + execute(workspace.getFile(POM_XML, project), new PomCallback() { @Override public Pom doWith(Pom pom) { if (project.dependsOn(Projects.COMMONS)) { - ArtifactVersion version = CLEANUP.equals(phase) ? commonsVersion.getNextDevelopmentVersion() - : commonsVersion; + ArtifactVersion version = CLEANUP.equals(phase) ? nextCommonsVersion : commonsVersion; logger.log(project, "Updating Spring Data Commons version dependecy to %s (setting property %s).", version, COMMONS_VERSION_PROPERTY); pom.setProperty(COMMONS_VERSION_PROPERTY, version); } - ArtifactVersion version = CLEANUP.equals(phase) ? buildVersion.getNextDevelopmentVersion() : buildVersion; + ArtifactVersion version = CLEANUP.equals(phase) ? nextBuildVersion : buildVersion; logger.log(project, "Updating Spring Data Build Parent version to %s.", version); pom.setParentVersion(version); @@ -176,7 +188,7 @@ public class MavenOperations { logger.log(BUILD, "Updating BOM pom.xml…"); - execute(bomPomFile, new PomCallback() { + execute(bomPomFile, new PomCallback() { @Override public Pom doWith(Pom pom) { @@ -217,18 +229,20 @@ public class MavenOperations { } } - private void execute(File file, PomCallback callback) throws Exception { + @SuppressWarnings("unchecked") + private void execute(File file, PomCallback callback) throws Exception { XBFileIO io = projectionFactory.io().file(file); - Pom pom = io.read(Pom.class); + Class typeArgument = GenericTypeResolver.resolveTypeArgument(callback.getClass(), PomCallback.class); + T pom = (T) io.read(typeArgument); pom = callback.doWith(pom); io.write(pom); } - private interface PomCallback { + private interface PomCallback { - public Pom doWith(Pom pom); + public T doWith(T pom); } } diff --git a/src/main/java/org/springframework/data/release/maven/ParentPom.java b/src/main/java/org/springframework/data/release/maven/ParentPom.java new file mode 100644 index 0000000..9704594 --- /dev/null +++ b/src/main/java/org/springframework/data/release/maven/ParentPom.java @@ -0,0 +1,29 @@ +/* + * Copyright 2014 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.release.maven; + +import org.springframework.data.release.model.ArtifactVersion; +import org.xmlbeam.annotation.XBValue; +import org.xmlbeam.annotation.XBWrite; + +/** + * @author Oliver Gierke + */ +public interface ParentPom extends Pom { + + @XBWrite("/project/profiles/profile[id=''distribute'']/dependencies/dependency/version") + void setSharedResourcesVersion(@XBValue ArtifactVersion value); +}