#69 - Add command to build and deploy release train snapshot documentation.

Added build-distribute <Train> command to run a distribution build for the train using latest sources.
This commit is contained in:
Mark Paluch
2018-03-21 10:43:53 +01:00
parent 88e7436dbb
commit 860f1841dc
5 changed files with 127 additions and 41 deletions

View File

@@ -25,10 +25,13 @@ import java.util.Optional;
import org.springframework.data.release.CliComponent; import org.springframework.data.release.CliComponent;
import org.springframework.data.release.TimedCommand; import org.springframework.data.release.TimedCommand;
import org.springframework.data.release.cli.TrainIterationConverter;
import org.springframework.data.release.git.GitOperations; import org.springframework.data.release.git.GitOperations;
import org.springframework.data.release.io.Workspace; import org.springframework.data.release.io.Workspace;
import org.springframework.data.release.model.Project; import org.springframework.data.release.model.Project;
import org.springframework.data.release.model.Projects; import org.springframework.data.release.model.Projects;
import org.springframework.data.release.model.ReleaseTrains;
import org.springframework.data.release.model.Train;
import org.springframework.data.release.model.TrainIteration; import org.springframework.data.release.model.TrainIteration;
import org.springframework.data.release.utils.Logger; import org.springframework.data.release.utils.Logger;
import org.springframework.shell.core.annotation.CliCommand; import org.springframework.shell.core.annotation.CliCommand;
@@ -86,14 +89,30 @@ class BuildCommands extends TimedCommand {
} }
/** /**
* @param iteration must not be {@literal null}. * @param trainOrIteration must not be {@literal null}. Accepts release train names and train iterations.
*/ */
@CliCommand("build-distribute") @CliCommand("build-distribute")
public void buildDistribute(@CliOption(key = "", mandatory = true) TrainIteration iteration) { public void buildDistribute(@CliOption(key = "", mandatory = true) String trainOrIteration) {
Assert.notNull(iteration, "Train iteration must not be null!"); Assert.hasText(trainOrIteration, "Train or iteration must not be null or empty!");
git.prepare(iteration); if (trainOrIteration.contains(" ")) {
build.distributeResources(iteration);
TrainIteration trainIteration = new TrainIterationConverter().convertFromText(trainOrIteration,
TrainIteration.class, null);
Assert.notNull(trainIteration, "TrainIteration must not be null!");
git.prepare(trainIteration);
build.distributeResources(trainIteration);
return;
}
Train train = ReleaseTrains.getTrainByName(trainOrIteration);
Assert.notNull(train, "Train must not be null!");
git.checkout(train);
build.distributeResources(train);
} }
} }

View File

@@ -25,9 +25,11 @@ import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.springframework.data.release.deployment.DeploymentInformation; import org.springframework.data.release.deployment.DeploymentInformation;
import org.springframework.data.release.model.Module;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.Phase; import org.springframework.data.release.model.Phase;
import org.springframework.data.release.model.Project; import org.springframework.data.release.model.Project;
import org.springframework.data.release.model.Train;
import org.springframework.data.release.model.TrainIteration; import org.springframework.data.release.model.TrainIteration;
import org.springframework.plugin.core.PluginRegistry; import org.springframework.plugin.core.PluginRegistry;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -35,6 +37,7 @@ import org.springframework.util.Assert;
/** /**
* @author Oliver Gierke * @author Oliver Gierke
* @author Mark Paluch
*/ */
@Component @Component
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -45,7 +48,7 @@ public class BuildOperations {
/** /**
* Updates all inter-project dependencies based on the given {@link TrainIteration} and release {@link Phase}. * Updates all inter-project dependencies based on the given {@link TrainIteration} and release {@link Phase}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @param phase must not be {@literal null}. * @param phase must not be {@literal null}.
* @throws Exception * @throws Exception
@@ -62,19 +65,31 @@ public class BuildOperations {
/** /**
* Triggers the distribution builds for all modules participating in the given {@link TrainIteration}. * Triggers the distribution builds for all modules participating in the given {@link TrainIteration}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
*/ */
public void distributeResources(TrainIteration iteration) { public void distributeResources(TrainIteration iteration) {
Assert.notNull(iteration, "Train iteration must not be null!"); Assert.notNull(iteration, "Train iteration must not be null!");
doWithBuildSystem(iteration, BuildSystem::triggerDistributionBuild); distributeResources(iteration.getTrain());
}
/**
* Triggers the distribution builds for all modules participating in the given {@link Train}.
*
* @param iteration must not be {@literal null}.
*/
public void distributeResources(Train train) {
Assert.notNull(train, "Train must not be null!");
doWithBuildSystem(train, BuildSystem::triggerDistributionBuild);
} }
/** /**
* Performs the release build for all modules in the given {@link TrainIteration}. * Performs the release build for all modules in the given {@link TrainIteration}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @return * @return
*/ */
@@ -84,7 +99,7 @@ public class BuildOperations {
/** /**
* Performs the release build for the given {@link ModuleIteration}. * Performs the release build for the given {@link ModuleIteration}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
@@ -94,7 +109,7 @@ public class BuildOperations {
/** /**
* Prepares the versions of the given {@link TrainIteration} depending on the given {@link Phase}. * Prepares the versions of the given {@link TrainIteration} depending on the given {@link Phase}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @param phase must not be {@literal null}. * @param phase must not be {@literal null}.
*/ */
@@ -108,7 +123,7 @@ public class BuildOperations {
/** /**
* Prepares the version of the given {@link ModuleIteration} depending on the given {@link Phase}. * Prepares the version of the given {@link ModuleIteration} depending on the given {@link Phase}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @param phase must not be {@literal null}. * @param phase must not be {@literal null}.
* @return * @return
@@ -123,7 +138,7 @@ public class BuildOperations {
/** /**
* Returns the {@link Path} of the local artifact repository. * Returns the {@link Path} of the local artifact repository.
* *
* @return * @return
*/ */
public Path getLocalRepository() { public Path getLocalRepository() {
@@ -132,7 +147,7 @@ public class BuildOperations {
/** /**
* Builds the release for the given {@link ModuleIteration} and deploys it to the staging repository. * Builds the release for the given {@link ModuleIteration} and deploys it to the staging repository.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
@@ -142,7 +157,7 @@ public class BuildOperations {
/** /**
* Triggers a nomarl build for the given {@link ModuleIteration}. * Triggers a nomarl build for the given {@link ModuleIteration}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
@@ -152,7 +167,7 @@ public class BuildOperations {
/** /**
* Triggers the pre-release checks for all modules of the given {@link TrainIteration}. * Triggers the pre-release checks for all modules of the given {@link TrainIteration}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
*/ */
public void runPreReleaseChecks(TrainIteration iteration) { public void runPreReleaseChecks(TrainIteration iteration) {
@@ -165,7 +180,7 @@ public class BuildOperations {
/** /**
* Selects the build system for each {@link ModuleIteration} contained in the given {@link TrainIteration} and * Selects the build system for each {@link ModuleIteration} contained in the given {@link TrainIteration} and
* executes the given function for it. * executes the given function for it.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @param function must not be {@literal null}. * @param function must not be {@literal null}.
* @return * @return
@@ -178,10 +193,25 @@ public class BuildOperations {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
/**
* Selects the build system for each {@link Module} contained in the given {@link Train} and executes the given
* function for it.
*
* @param train must not be {@literal null}.
* @param function must not be {@literal null}.
* @return
*/
private <T> List<T> doWithBuildSystem(Train train, BiFunction<BuildSystem, Module, T> function) {
return train.stream()//
.map(module -> doWithBuildSystem(module, function))//
.collect(Collectors.toList());
}
/** /**
* Selects the build system for the module contained in the given {@link ModuleIteration} and executes the given * Selects the build system for the module contained in the given {@link ModuleIteration} and executes the given
* function with it. * function with it.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @param function must not be {@literal null}. * @param function must not be {@literal null}.
* @return * @return
@@ -195,4 +225,22 @@ public class BuildOperations {
return function.apply(buildSystems.getPluginFor(module.getProject(), exception), module); return function.apply(buildSystems.getPluginFor(module.getProject(), exception), module);
} }
/**
* Selects the build system for the module contained in the given {@link Module} and executes the given function with
* it.
*
* @param module must not be {@literal null}.
* @param function must not be {@literal null}.
* @return
*/
private <T> T doWithBuildSystem(Module module, BiFunction<BuildSystem, Module, T> function) {
Assert.notNull(module, "ModuleIteration must not be null!");
Supplier<IllegalStateException> exception = () -> new IllegalStateException(
String.format("No build system plugin found for project %s!", module.getProject()));
return function.apply(buildSystems.getPluginFor(module.getProject(), exception), module);
}
} }

View File

@@ -16,6 +16,7 @@
package org.springframework.data.release.build; package org.springframework.data.release.build;
import org.springframework.data.release.deployment.DeploymentInformation; import org.springframework.data.release.deployment.DeploymentInformation;
import org.springframework.data.release.model.Module;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.Phase; import org.springframework.data.release.model.Phase;
import org.springframework.data.release.model.Project; import org.springframework.data.release.model.Project;
@@ -23,14 +24,15 @@ import org.springframework.plugin.core.Plugin;
/** /**
* Plugin interface to back different build systems. * Plugin interface to back different build systems.
* *
* @author Oliver Gierke * @author Oliver Gierke
* @author Mark Paluch
*/ */
interface BuildSystem extends Plugin<Project> { interface BuildSystem extends Plugin<Project> {
/** /**
* Updates the project descriptors for the given {@link ModuleIteration} using the given {@link UpdateInformation}. * Updates the project descriptors for the given {@link ModuleIteration} using the given {@link UpdateInformation}.
* *
* @param iteration must not be {@literal null}. * @param iteration must not be {@literal null}.
* @param updateInformation must not be {@literal null}. * @param updateInformation must not be {@literal null}.
*/ */
@@ -38,7 +40,7 @@ interface BuildSystem extends Plugin<Project> {
/** /**
* Prepares the project descriptor of the {@link ModuleIteration} for the given release {@link Phase}. * Prepares the project descriptor of the {@link ModuleIteration} for the given release {@link Phase}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @param phase must not be {@literal null}. * @param phase must not be {@literal null}.
* @return * @return
@@ -47,7 +49,7 @@ interface BuildSystem extends Plugin<Project> {
/** /**
* Deploy artifacts for the given {@link ModuleIteration} and return the {@link DeploymentInformation}. * Deploy artifacts for the given {@link ModuleIteration} and return the {@link DeploymentInformation}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
@@ -55,17 +57,17 @@ interface BuildSystem extends Plugin<Project> {
/** /**
* Runs the distribution build. * Runs the distribution build.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
ModuleIteration triggerDistributionBuild(ModuleIteration module); Module triggerDistributionBuild(Module module);
ModuleIteration triggerBuild(ModuleIteration module); ModuleIteration triggerBuild(ModuleIteration module);
/** /**
* Triggers the pre-release checks for the given {@link ModuleIteration}. * Triggers the pre-release checks for the given {@link ModuleIteration}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */

View File

@@ -37,6 +37,7 @@ import org.springframework.data.release.deployment.DeploymentProperties;
import org.springframework.data.release.deployment.DeploymentProperties.Gpg; import org.springframework.data.release.deployment.DeploymentProperties.Gpg;
import org.springframework.data.release.io.Workspace; import org.springframework.data.release.io.Workspace;
import org.springframework.data.release.model.ArtifactVersion; import org.springframework.data.release.model.ArtifactVersion;
import org.springframework.data.release.model.Module;
import org.springframework.data.release.model.ModuleIteration; import org.springframework.data.release.model.ModuleIteration;
import org.springframework.data.release.model.Phase; import org.springframework.data.release.model.Phase;
import org.springframework.data.release.model.Project; import org.springframework.data.release.model.Project;
@@ -51,6 +52,7 @@ import org.xmlbeam.io.XBFileIO;
/** /**
* @author Oliver Gierke * @author Oliver Gierke
* @author Mark Paluch
*/ */
@Component @Component
@Order(100) @Order(100)
@@ -66,7 +68,7 @@ class MavenBuildSystem implements BuildSystem {
MavenRuntime mvn; MavenRuntime mvn;
DeploymentProperties properties; DeploymentProperties properties;
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.release.build.BuildSystem#updateProjectDescriptors(org.springframework.data.release.model.ModuleIteration, org.springframework.data.release.model.TrainIteration, org.springframework.data.release.model.Phase) * @see org.springframework.data.release.build.BuildSystem#updateProjectDescriptors(org.springframework.data.release.model.ModuleIteration, org.springframework.data.release.model.TrainIteration, org.springframework.data.release.model.Phase)
*/ */
@@ -93,12 +95,12 @@ class MavenBuildSystem implements BuildSystem {
return module; return module;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.release.build.BuildSystem#triggerDistributionBuild(org.springframework.data.release.model.ModuleIteration) * @see org.springframework.data.release.build.BuildSystem#triggerDistributionBuild(org.springframework.data.release.model.Module)
*/ */
@Override @Override
public ModuleIteration triggerDistributionBuild(ModuleIteration module) { public Module triggerDistributionBuild(Module module) {
Project project = module.getProject(); Project project = module.getProject();
@@ -192,7 +194,7 @@ class MavenBuildSystem implements BuildSystem {
/** /**
* Triggers building the distribution artifacts for all Maven projects of the given {@link Train}. * Triggers building the distribution artifacts for all Maven projects of the given {@link Train}.
* *
* @param iteration * @param iteration
* @throws Exception * @throws Exception
*/ */
@@ -246,7 +248,7 @@ class MavenBuildSystem implements BuildSystem {
return module; return module;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.release.build.BuildSystem#deploy(org.springframework.data.release.model.ModuleIteration) * @see org.springframework.data.release.build.BuildSystem#deploy(org.springframework.data.release.model.ModuleIteration)
*/ */
@@ -263,7 +265,7 @@ class MavenBuildSystem implements BuildSystem {
return information; return information;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.data.release.build.BuildSystem#triggerBuild(org.springframework.data.release.model.ModuleIteration) * @see org.springframework.data.release.build.BuildSystem#triggerBuild(org.springframework.data.release.model.ModuleIteration)
*/ */
@@ -289,7 +291,7 @@ class MavenBuildSystem implements BuildSystem {
return module; return module;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* @see org.springframework.plugin.core.Plugin#supports(java.lang.Object) * @see org.springframework.plugin.core.Plugin#supports(java.lang.Object)
*/ */
@@ -300,7 +302,7 @@ class MavenBuildSystem implements BuildSystem {
/** /**
* Triggers Maven commands to deploy module artifacts to Spring Artifactory. * Triggers Maven commands to deploy module artifacts to Spring Artifactory.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @param information must not be {@literal null}. * @param information must not be {@literal null}.
*/ */
@@ -332,7 +334,7 @@ class MavenBuildSystem implements BuildSystem {
/** /**
* Triggers Maven commands to deploy to Sonatype's OSS Nexus if the given {@link ModuleIteration} refers to a version * Triggers Maven commands to deploy to Sonatype's OSS Nexus if the given {@link ModuleIteration} refers to a version
* that has to be publicly released. * that has to be publicly released.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
*/ */
private void deployToMavenCentral(ModuleIteration module) { private void deployToMavenCentral(ModuleIteration module) {
@@ -392,7 +394,7 @@ class MavenBuildSystem implements BuildSystem {
/** /**
* Creates a new {@link ReleaseVersion} for the given {@link ModuleIteration}. * Creates a new {@link ReleaseVersion} for the given {@link ModuleIteration}.
* *
* @param module must not be {@literal null}. * @param module must not be {@literal null}.
* @return * @return
*/ */
@@ -408,7 +410,7 @@ class MavenBuildSystem implements BuildSystem {
/** /**
* Returns the Maven profiles to be used during the distribution build. * Returns the Maven profiles to be used during the distribution build.
* *
* @return * @return
*/ */
public Argument getDistributionProfiles() { public Argument getDistributionProfiles() {

View File

@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@@ -103,10 +104,9 @@ public class GitOperations {
} }
/** /**
* Checks out all projects of the given {@link TrainIteration}. * Checks out all projects of the given {@link Train}.
* *
* @param train * @param train
* @throws Exception
*/ */
public void checkout(Train train) { public void checkout(Train train) {
@@ -114,6 +114,7 @@ public class GitOperations {
update(train); update(train);
AtomicBoolean masterSwitch = new AtomicBoolean();
ExecutionUtils.run(train, module -> { ExecutionUtils.run(train, module -> {
Project project = module.getProject(); Project project = module.getProject();
@@ -121,6 +122,15 @@ public class GitOperations {
doWithGit(project, git -> { doWithGit(project, git -> {
Branch branch = Branch.from(module); Branch branch = Branch.from(module);
if (!branchExists(project, branch) && !branchExists(project, Branch.from("origin/" + branch.toString()))) {
logger.warn(project, "Branch %s does not exist. Using %s.", branch, Branch.MASTER);
masterSwitch.set(true);
branch = Branch.MASTER;
}
CheckoutCommand command = git.checkout().setName(branch.toString()); CheckoutCommand command = git.checkout().setName(branch.toString());
if (!branchExists(project, branch)) { if (!branchExists(project, branch)) {
@@ -129,7 +139,6 @@ public class GitOperations {
command.setCreateBranch(true)// command.setCreateBranch(true)//
.setStartPoint("origin/".concat(branch.toString()))// .setStartPoint("origin/".concat(branch.toString()))//
.call(); .call();
} else { } else {
logger.log(project, "git checkout %s", branch); logger.log(project, "git checkout %s", branch);
@@ -140,7 +149,13 @@ public class GitOperations {
}); });
}); });
logger.log(train, "Successfully checked out projects."); if (masterSwitch.get()) {
logger.warn(train,
"Successfully checked out projects. There were switches to master for certain projects. This happens if the train has no branches yet.");
} else {
logger.log(train, "Successfully checked out projects.");
}
} }
/** /**