#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:
@@ -25,10 +25,13 @@ import java.util.Optional;
|
||||
|
||||
import org.springframework.data.release.CliComponent;
|
||||
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.io.Workspace;
|
||||
import org.springframework.data.release.model.Project;
|
||||
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.utils.Logger;
|
||||
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")
|
||||
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);
|
||||
build.distributeResources(iteration);
|
||||
if (trainOrIteration.contains(" ")) {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,11 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.Phase;
|
||||
import org.springframework.data.release.model.Project;
|
||||
import org.springframework.data.release.model.Train;
|
||||
import org.springframework.data.release.model.TrainIteration;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -35,6 +37,7 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@@ -45,7 +48,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Updates all inter-project dependencies based on the given {@link TrainIteration} and release {@link Phase}.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
* @param phase must not be {@literal null}.
|
||||
* @throws Exception
|
||||
@@ -62,19 +65,31 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Triggers the distribution builds for all modules participating in the given {@link TrainIteration}.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
*/
|
||||
public void distributeResources(TrainIteration iteration) {
|
||||
|
||||
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}.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -84,7 +99,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Performs the release build for the given {@link ModuleIteration}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -94,7 +109,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Prepares the versions of the given {@link TrainIteration} depending on the given {@link Phase}.
|
||||
*
|
||||
*
|
||||
* @param iteration 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}.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
* @param phase must not be {@literal null}.
|
||||
* @return
|
||||
@@ -123,7 +138,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Returns the {@link Path} of the local artifact repository.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
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.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -142,7 +157,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Triggers a nomarl build for the given {@link ModuleIteration}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -152,7 +167,7 @@ public class BuildOperations {
|
||||
|
||||
/**
|
||||
* Triggers the pre-release checks for all modules of the given {@link TrainIteration}.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
*/
|
||||
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
|
||||
* executes the given function for it.
|
||||
*
|
||||
*
|
||||
* @param iteration must not be {@literal null}.
|
||||
* @param function must not be {@literal null}.
|
||||
* @return
|
||||
@@ -178,10 +193,25 @@ public class BuildOperations {
|
||||
.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
|
||||
* function with it.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @param function must not be {@literal null}.
|
||||
* @return
|
||||
@@ -195,4 +225,22 @@ public class BuildOperations {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.data.release.build;
|
||||
|
||||
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.Phase;
|
||||
import org.springframework.data.release.model.Project;
|
||||
@@ -23,14 +24,15 @@ import org.springframework.plugin.core.Plugin;
|
||||
|
||||
/**
|
||||
* Plugin interface to back different build systems.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
interface BuildSystem extends Plugin<Project> {
|
||||
|
||||
/**
|
||||
* Updates the project descriptors for the given {@link ModuleIteration} using the given {@link UpdateInformation}.
|
||||
*
|
||||
*
|
||||
* @param iteration 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}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @param phase must not be {@literal null}.
|
||||
* @return
|
||||
@@ -47,7 +49,7 @@ interface BuildSystem extends Plugin<Project> {
|
||||
|
||||
/**
|
||||
* Deploy artifacts for the given {@link ModuleIteration} and return the {@link DeploymentInformation}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -55,17 +57,17 @@ interface BuildSystem extends Plugin<Project> {
|
||||
|
||||
/**
|
||||
* Runs the distribution build.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
ModuleIteration triggerDistributionBuild(ModuleIteration module);
|
||||
Module triggerDistributionBuild(Module module);
|
||||
|
||||
ModuleIteration triggerBuild(ModuleIteration module);
|
||||
|
||||
/**
|
||||
* Triggers the pre-release checks for the given {@link ModuleIteration}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.data.release.deployment.DeploymentProperties;
|
||||
import org.springframework.data.release.deployment.DeploymentProperties.Gpg;
|
||||
import org.springframework.data.release.io.Workspace;
|
||||
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.Phase;
|
||||
import org.springframework.data.release.model.Project;
|
||||
@@ -51,6 +52,7 @@ import org.xmlbeam.io.XBFileIO;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Component
|
||||
@Order(100)
|
||||
@@ -66,7 +68,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
MavenRuntime mvn;
|
||||
DeploymentProperties properties;
|
||||
|
||||
/*
|
||||
/*
|
||||
* (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)
|
||||
*/
|
||||
@@ -93,12 +95,12 @@ class MavenBuildSystem implements BuildSystem {
|
||||
return module;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (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
|
||||
public ModuleIteration triggerDistributionBuild(ModuleIteration module) {
|
||||
public Module triggerDistributionBuild(Module module) {
|
||||
|
||||
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}.
|
||||
*
|
||||
*
|
||||
* @param iteration
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -246,7 +248,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
return module;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.release.build.BuildSystem#deploy(org.springframework.data.release.model.ModuleIteration)
|
||||
*/
|
||||
@@ -263,7 +265,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
return information;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.release.build.BuildSystem#triggerBuild(org.springframework.data.release.model.ModuleIteration)
|
||||
*/
|
||||
@@ -289,7 +291,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
return module;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @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.
|
||||
*
|
||||
*
|
||||
* @param module 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
|
||||
* that has to be publicly released.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
*/
|
||||
private void deployToMavenCentral(ModuleIteration module) {
|
||||
@@ -392,7 +394,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ReleaseVersion} for the given {@link ModuleIteration}.
|
||||
*
|
||||
*
|
||||
* @param module must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@@ -408,7 +410,7 @@ class MavenBuildSystem implements BuildSystem {
|
||||
|
||||
/**
|
||||
* Returns the Maven profiles to be used during the distribution build.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Argument getDistributionProfiles() {
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
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
|
||||
* @throws Exception
|
||||
*/
|
||||
public void checkout(Train train) {
|
||||
|
||||
@@ -114,6 +114,7 @@ public class GitOperations {
|
||||
|
||||
update(train);
|
||||
|
||||
AtomicBoolean masterSwitch = new AtomicBoolean();
|
||||
ExecutionUtils.run(train, module -> {
|
||||
|
||||
Project project = module.getProject();
|
||||
@@ -121,6 +122,15 @@ public class GitOperations {
|
||||
doWithGit(project, git -> {
|
||||
|
||||
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());
|
||||
|
||||
if (!branchExists(project, branch)) {
|
||||
@@ -129,7 +139,6 @@ public class GitOperations {
|
||||
command.setCreateBranch(true)//
|
||||
.setStartPoint("origin/".concat(branch.toString()))//
|
||||
.call();
|
||||
|
||||
} else {
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user