Skip to content

Commit

Permalink
#35 - Added command to trigger builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed Nov 24, 2016
1 parent 1ddf103 commit 37ea4bb
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@
import lombok.experimental.FieldDefaults;

import java.io.IOException;
import java.util.Optional;

import org.springframework.data.release.CliComponent;
import org.springframework.data.release.TimedCommand;
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.TrainIteration;
import org.springframework.data.release.utils.Logger;
import org.springframework.shell.core.annotation.CliCommand;
import org.springframework.shell.core.annotation.CliOption;
import org.springframework.util.Assert;

/**
* @author Oliver Gierke
Expand All @@ -38,6 +45,7 @@ class BuildCommands extends TimedCommand {

@NonNull BuildOperations build;
@NonNull Workspace workspace;
@NonNull GitOperations git;
@NonNull Logger logger;

/**
Expand All @@ -54,4 +62,25 @@ public void purge() throws IOException {
workspace.purge(build.getLocalRepository(),
path -> build.getLocalRepository().relativize(path).startsWith("org/springframework/data"));
}

/**
* Triggers a build for all modules of the given {@link TrainIteration}.
*
* @param iteration must not be {@literal null}.
* @param projectKey can be {@literal null} or empty.
*/
@CliCommand("build")
public void build(@CliOption(key = "", mandatory = true) TrainIteration iteration, //
@CliOption(key = "module") String projectKey) {

Assert.notNull(iteration, "Train iteration must not be null!");
Optional<Project> project = Projects.byName(projectKey);

project.ifPresent(it -> build.triggerBuild(iteration.getModule(it)));

if (!project.isPresent()) {
git.prepare(iteration);
iteration.forEach(module -> build.triggerBuild(module));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ public DeploymentInformation buildAndDeployRelease(ModuleIteration module) {
return doWithBuildSystem(module, BuildSystem::deploy);
}

public ModuleIteration triggerBuild(ModuleIteration module) {
return doWithBuildSystem(module, BuildSystem::triggerBuild);
}

/**
* Selects the build system for each {@link ModuleIteration} contained in the given {@link TrainIteration} and
* executes the given function for it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ interface BuildSystem extends Plugin<Project> {
* @return
*/
ModuleIteration triggerDistributionBuild(ModuleIteration module);

ModuleIteration triggerBuild(ModuleIteration module);
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ public ModuleIteration prepareVersion(ModuleIteration module, Phase phase) {
"-DnewVersion=".concat(information.getReleaseTrainVersion()), //
"-DgroupId=org.springframework.data", //
"-DartifactId=spring-data-releasetrain");

mvn.execute(project, "install");
}

return module;
Expand All @@ -243,6 +245,26 @@ public DeploymentInformation deploy(ModuleIteration module) {
return information;
}

/*
* (non-Javadoc)
* @see org.springframework.data.release.build.BuildSystem#triggerBuild(org.springframework.data.release.model.ModuleIteration)
*/
@Override
public ModuleIteration triggerBuild(ModuleIteration module) {

List<String> arguments = new ArrayList<>();
arguments.add("clean");
arguments.add("install");

if (module.getProject().skipTests()) {
arguments.add("-DskipTests");
}

mvn.execute(module.getProject(), arguments);

return module;
}

/**
* Triggers Maven commands to deploy module artifacts to Spring Artifactory.
*
Expand Down

0 comments on commit 37ea4bb

Please sign in to comment.