#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
@@ -69,7 +72,19 @@ public class BuildOperations {
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);
} }
/** /**
@@ -178,6 +193,21 @@ 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.
@@ -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;
@@ -25,6 +26,7 @@ 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> {
@@ -59,7 +61,7 @@ interface BuildSystem extends Plugin<Project> {
* @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);

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)
@@ -95,10 +97,10 @@ class MavenBuildSystem implements BuildSystem {
/* /*
* (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();

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.");
}
} }
/** /**