Uses releaser properties of a given project for certain tasks

This commit is contained in:
Marcin Grzejszczak
2020-02-03 16:32:39 +01:00
parent 7497446dfe
commit aadd5baaf0
28 changed files with 221 additions and 489 deletions

View File

@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
/**
* @author Marcin Grzejszczak
*/
public class Releaser implements ReleaserPropertiesAware {
public class Releaser {
private static final Logger log = LoggerFactory.getLogger(Releaser.class);
@@ -118,9 +118,9 @@ public class Releaser implements ReleaserPropertiesAware {
return ExecutionResult.success();
}
public ExecutionResult buildProject(ProjectVersion originalVersion,
ProjectVersion versionFromBom) {
this.projectCommandExecutor.build(originalVersion, versionFromBom);
public ExecutionResult buildProject(ReleaserProperties properties,
ProjectVersion originalVersion, ProjectVersion versionFromBom) {
this.projectCommandExecutor.build(properties, originalVersion, versionFromBom);
log.info("\nProject was successfully built");
return ExecutionResult.success();
}
@@ -132,16 +132,17 @@ public class Releaser implements ReleaserPropertiesAware {
return ExecutionResult.success();
}
public ExecutionResult deploy(ProjectVersion originalVersion,
ProjectVersion versionFromBom) {
this.projectCommandExecutor.deploy(originalVersion, versionFromBom);
public ExecutionResult deploy(ReleaserProperties properties,
ProjectVersion originalVersion, ProjectVersion versionFromBom) {
this.projectCommandExecutor.deploy(properties, originalVersion, versionFromBom);
log.info("\nThe artifact was deployed successfully");
return ExecutionResult.success();
}
public ExecutionResult publishDocs(ProjectVersion originalVersion,
ProjectVersion changedVersion) {
this.projectCommandExecutor.publishDocs(originalVersion, changedVersion);
public ExecutionResult publishDocs(ReleaserProperties properties,
ProjectVersion originalVersion, ProjectVersion changedVersion) {
this.projectCommandExecutor.publishDocs(properties, originalVersion,
changedVersion);
log.info("\nThe docs were published successfully");
return ExecutionResult.success();
}
@@ -439,9 +440,4 @@ public class Releaser implements ReleaserPropertiesAware {
return ExecutionResult.skipped();
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.releaserProperties = properties;
}
}

View File

@@ -1,26 +0,0 @@
/*
* Copyright 2013-2019 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
*
* https://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 releaser.internal;
/**
* @author Marcin Grzejszczak
*/
public interface ReleaserPropertiesAware {
void setReleaserProperties(ReleaserProperties properties);
}

View File

@@ -14,56 +14,46 @@
* limitations under the License.
*/
package releaser.internal.spring;
package releaser.internal;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.MapConfigurationPropertySource;
import org.springframework.context.ApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.util.StringUtils;
/**
* @author Marcin Grzejszczak
*/
class ReleaserPropertiesUpdater {
public class ReleaserPropertiesUpdater implements Closeable {
private static final Logger log = LoggerFactory
.getLogger(ReleaserPropertiesUpdater.class);
private final ApplicationContext context;
private static final Map<File, ReleaserProperties> CACHE = new ConcurrentHashMap<>();
ReleaserPropertiesUpdater(ApplicationContext context) {
this.context = context;
}
ReleaserProperties updateProperties(ReleaserProperties properties,
public ReleaserProperties updateProperties(ReleaserProperties properties,
File clonedProjectFromOrg) {
ReleaserProperties props = updatePropertiesFromFile(properties,
clonedProjectFromOrg);
props.setWorkingDir(clonedProjectFromOrg.getAbsolutePath());
log.trace("Updated properties [\n\n{}\n\n]", props);
updateProperties(props);
return props;
}
void updateProperties(ReleaserProperties props) {
Map<String, ReleaserPropertiesAware> beans = this.context
.getBeansOfType(ReleaserPropertiesAware.class);
beans.values().forEach(aware -> aware.setReleaserProperties(props));
return CACHE.computeIfAbsent(clonedProjectFromOrg, file -> {
ReleaserProperties props = updatePropertiesFromFile(properties.copy(), file);
props.setWorkingDir(clonedProjectFromOrg.getAbsolutePath());
log.trace("Updated properties [\n\n{}\n\n]", props);
return props;
});
}
private ReleaserProperties updatePropertiesFromFile(ReleaserProperties copy,
@@ -160,4 +150,9 @@ class ReleaserPropertiesUpdater {
return new File(clonedProjectFromOrg, "config/releaser.yml");
}
@Override
public void close() throws IOException {
CACHE.clear();
}
}

View File

@@ -35,18 +35,17 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
/**
* @author Marcin Grzejszczak
*/
public class GradleUpdater implements ReleaserPropertiesAware {
public class GradleUpdater {
private static final Logger log = LoggerFactory.getLogger(GradleUpdater.class);
private ReleaserProperties properties;
private final ReleaserProperties properties;
public GradleUpdater(ReleaserProperties properties) {
this.properties = properties;
@@ -78,11 +77,6 @@ public class GradleUpdater implements ReleaserPropertiesAware {
}
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
private final class GradlePropertiesWalker extends SimpleFileVisitor<Path> {
private static final String GRADLE_PROPERTIES = "gradle.properties";

View File

@@ -36,7 +36,6 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.git.ProjectGitHandler;
import releaser.internal.project.Project;
import releaser.internal.project.ProjectVersion;
@@ -45,7 +44,7 @@ import releaser.internal.project.Projects;
/**
* @author Marcin Grzejszczak
*/
public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable {
public class ProjectPomUpdater implements Closeable {
private static final List<String> IGNORED_SNAPSHOT_LINE_PATTERNS = Arrays.asList(
"^.*replace=.*$",
@@ -64,7 +63,7 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable {
private final List<BomParser> bomParsers;
private ReleaserProperties properties;
private final ReleaserProperties properties;
public ProjectPomUpdater(ReleaserProperties properties, List<BomParser> bomParsers) {
this.properties = properties;
@@ -173,11 +172,6 @@ public class ProjectPomUpdater implements ReleaserPropertiesAware, Closeable {
}
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
@Override
public void close() throws IOException {
CACHE.clear();

View File

@@ -20,7 +20,6 @@ import java.io.File;
import java.util.List;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.git.ProjectGitHandler;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
@@ -29,28 +28,23 @@ import releaser.internal.template.TemplateGenerator;
/**
* @author Marcin Grzejszczak
*/
public class DocumentationUpdater implements ReleaserPropertiesAware {
public class DocumentationUpdater {
private final ProjectDocumentationUpdater projectDocumentationUpdater;
private final ReleaseTrainContentsUpdater releaseTrainContentsUpdater;
private ReleaserProperties properties;
public DocumentationUpdater(ProjectGitHandler gitHandler,
ReleaserProperties properties, TemplateGenerator templateGenerator,
List<CustomProjectDocumentationUpdater> updaters) {
this.properties = properties;
this.projectDocumentationUpdater = new ProjectDocumentationUpdater(properties,
gitHandler, updaters);
this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(
this.properties, gitHandler, templateGenerator);
this.releaseTrainContentsUpdater = new ReleaseTrainContentsUpdater(properties,
gitHandler, templateGenerator);
}
DocumentationUpdater(ReleaserProperties properties,
ProjectDocumentationUpdater updater,
DocumentationUpdater(ProjectDocumentationUpdater updater,
ReleaseTrainContentsUpdater contentsUpdater) {
this.properties = properties;
this.projectDocumentationUpdater = updater;
this.releaseTrainContentsUpdater = contentsUpdater;
}
@@ -94,11 +88,4 @@ public class DocumentationUpdater implements ReleaserPropertiesAware {
return this.releaseTrainContentsUpdater.updateReleaseTrainWiki(projects);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
this.releaseTrainContentsUpdater.setReleaserProperties(properties);
this.projectDocumentationUpdater.setReleaserProperties(properties);
}
}

View File

@@ -22,7 +22,6 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.git.ProjectGitHandler;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
@@ -30,7 +29,7 @@ import releaser.internal.project.Projects;
/**
* @author Marcin Grzejszczak
*/
class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
class ProjectDocumentationUpdater {
private static final Logger log = LoggerFactory
.getLogger(ProjectDocumentationUpdater.class);
@@ -39,7 +38,7 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
private final List<CustomProjectDocumentationUpdater> updaters;
private ReleaserProperties properties;
private final ReleaserProperties properties;
ProjectDocumentationUpdater(ReleaserProperties properties,
ProjectGitHandler gitHandler,
@@ -91,9 +90,4 @@ class ProjectDocumentationUpdater implements ReleaserPropertiesAware {
return true;
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}

View File

@@ -26,7 +26,6 @@ import java.util.StringJoiner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.git.ProjectGitHandler;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
@@ -38,7 +37,7 @@ import org.springframework.util.StringUtils;
* @author Marcin Grzejszczak
*/
// TODO: [SPRING-CLOUD]
class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
class ReleaseTrainContentsUpdater {
private static final Logger log = LoggerFactory
.getLogger(ReleaseTrainContentsUpdater.class);
@@ -49,7 +48,7 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
private final TemplateGenerator templateGenerator;
private ReleaserProperties properties;
private final ReleaserProperties properties;
ReleaseTrainContentsUpdater(ReleaserProperties properties, ProjectGitHandler handler,
TemplateGenerator templateGenerator) {
@@ -166,11 +165,6 @@ class ReleaseTrainContentsUpdater implements ReleaserPropertiesAware {
return releaseTrainDocFile;
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
class ReleaseTrainContentsGitHandler {

View File

@@ -30,7 +30,6 @@ import org.eclipse.jgit.transport.URIish;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.project.ProjectVersion;
import releaser.internal.tech.TemporaryFileStorage;
@@ -41,7 +40,7 @@ import org.springframework.util.StringUtils;
*
* @author Marcin Grzejszczak
*/
public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable {
public class ProjectGitHandler implements Closeable {
private static final Map<URIish, File> CACHE = new ConcurrentHashMap<>();
@@ -55,7 +54,7 @@ public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable {
private static final String POST_RELEASE_BUMP_MSG = "Bumping versions to %s after release";
private ReleaserProperties properties;
private final ReleaserProperties properties;
public ProjectGitHandler(ReleaserProperties properties) {
this.properties = properties;
@@ -314,11 +313,6 @@ public class ProjectGitHandler implements ReleaserPropertiesAware, Closeable {
return new GitRepo(workingDir, this.properties);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
@Override
public void close() {
CACHE.clear();

View File

@@ -21,7 +21,6 @@ import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
import releaser.internal.tech.TemporaryFileStorage;
@@ -31,7 +30,7 @@ import releaser.internal.tech.TemporaryFileStorage;
*
* @author Marcin Grzejszczak
*/
public class ProjectGitHubHandler implements ReleaserPropertiesAware {
public class ProjectGitHubHandler {
private static final Logger log = LoggerFactory.getLogger(ProjectGitHubHandler.class);
@@ -39,7 +38,7 @@ public class ProjectGitHubHandler implements ReleaserPropertiesAware {
private final GithubIssues githubIssues;
private ReleaserProperties properties;
private final ReleaserProperties properties;
public ProjectGitHubHandler(ReleaserProperties properties,
List<CustomGithubIssues> customGithubIssues) {
@@ -87,9 +86,4 @@ public class ProjectGitHubHandler implements ReleaserPropertiesAware {
return this.githubMilestones.milestoneUrl(releaseVersion);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}

View File

@@ -31,6 +31,7 @@ import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesUpdater;
import releaser.internal.buildsystem.GradleUpdater;
import releaser.internal.buildsystem.ProjectPomUpdater;
import releaser.internal.git.ProjectGitHandler;
@@ -65,16 +66,20 @@ public class PostReleaseActions implements Closeable {
private final VersionsFetcher versionsFetcher;
private final ReleaserPropertiesUpdater releaserPropertiesUpdater;
public PostReleaseActions(ProjectGitHandler projectGitHandler,
ProjectPomUpdater projectPomUpdater, GradleUpdater gradleUpdater,
ProjectCommandExecutor projectCommandExecutor, ReleaserProperties properties,
VersionsFetcher versionsFetcher) {
VersionsFetcher versionsFetcher,
ReleaserPropertiesUpdater releaserPropertiesUpdater) {
this.projectGitHandler = projectGitHandler;
this.projectPomUpdater = projectPomUpdater;
this.gradleUpdater = gradleUpdater;
this.projectCommandExecutor = projectCommandExecutor;
this.properties = properties;
this.versionsFetcher = versionsFetcher;
this.releaserPropertiesUpdater = releaserPropertiesUpdater;
}
/**
@@ -116,16 +121,21 @@ public class PostReleaseActions implements Closeable {
return ExecutionResult.skipped();
}
File file = this.projectGitHandler.cloneTestSamplesProject();
ReleaserProperties projectProps = projectProps(file);
ProjectVersion projectVersion = newProjectVersion(file);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
String releaseTrainVersion = projects.releaseTrain(projectProps).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion,
releaseTrainVersion);
updateWithVersions(file, newProjects);
this.projectCommandExecutor.build(projectVersion, projectVersion,
this.projectCommandExecutor.build(projectProps, projectVersion, projectVersion,
file.getAbsolutePath());
return ExecutionResult.success();
}
ReleaserProperties projectProps(File file) {
return this.releaserPropertiesUpdater.updateProperties(this.properties, file);
}
/**
* Clones all samples for the given project. For each of them, checks out the proper
* branch, updates all the poms with the new, bumped versions of release train
@@ -180,6 +190,7 @@ public class PostReleaseActions implements Closeable {
.cloneProjectFromOrg(processedProject.projectName());
this.projectGitHandler.checkout(clonedProject, tagName);
projectBuilder(processedProject).deployGuides(
processedProject.propertiesForProject,
processedProject.originalProjectVersion,
processedProject.newProjectVersion);
})))
@@ -187,7 +198,7 @@ public class PostReleaseActions implements Closeable {
}
ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) {
return new ProjectCommandExecutor(processedProject.propertiesForProject);
return new ProjectCommandExecutor();
}
private Future<List<ProjectUrlAndException>> updateAllProjects(Projects projects,
@@ -300,13 +311,14 @@ public class PostReleaseActions implements Closeable {
return ExecutionResult.skipped();
}
File file = this.projectGitHandler.cloneReleaseTrainDocumentationProject();
ReleaserProperties projectProps = projectProps(file);
ProjectVersion projectVersion = newProjectVersion(file);
String releaseTrainVersion = projects.releaseTrain(this.properties).version;
Projects newProjects = addVersionForTestsProject(projects, projectVersion,
releaseTrainVersion);
updateWithVersions(file, newProjects);
this.projectCommandExecutor.generateReleaseTrainDocs(releaseTrainVersion,
file.getAbsolutePath());
this.projectCommandExecutor.generateReleaseTrainDocs(projectProps,
releaseTrainVersion, file.getAbsolutePath());
return ExecutionResult.success();
}

View File

@@ -40,14 +40,13 @@ import org.zeroturnaround.exec.ProcessExecutor;
import org.zeroturnaround.exec.ProcessResult;
import org.zeroturnaround.exec.stream.slf4j.Slf4jStream;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import org.springframework.util.StringUtils;
/**
* @author Marcin Grzejszczak
*/
public class ProjectCommandExecutor implements ReleaserPropertiesAware {
public class ProjectCommandExecutor {
private static final Logger log = LoggerFactory
.getLogger(ProjectCommandExecutor.class);
@@ -58,39 +57,28 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
private static final String NEXT_VERSION_MUSTACHE = "{{nextVersion}}";
private ReleaserProperties properties;
public ProjectCommandExecutor(ReleaserProperties properties) {
this.properties = properties;
}
// If you want to call commands that are not parameterized via the props
public ProjectCommandExecutor() {
this.properties = new ReleaserProperties();
}
public void build(ProjectVersion originalVersion,
public void build(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromReleaseTrain) {
build(originalVersion, versionFromReleaseTrain, this.properties.getWorkingDir());
build(properties, originalVersion, versionFromReleaseTrain,
properties.getWorkingDir());
}
public String version() {
return executeCommandWithOutput(
new CommandPicker(this.properties, this.properties.getWorkingDir())
.version());
public String version(ReleaserProperties properties) {
return executeCommandWithOutput(properties,
new CommandPicker(properties, properties.getWorkingDir()).version());
}
public String groupId() {
return executeCommandWithOutput(
new CommandPicker(this.properties, this.properties.getWorkingDir())
.groupId());
public String groupId(ReleaserProperties properties) {
return executeCommandWithOutput(properties,
new CommandPicker(properties, properties.getWorkingDir()).groupId());
}
private String executeCommandWithOutput(String command) {
private String executeCommandWithOutput(ReleaserProperties properties,
String command) {
try {
String projectRoot = this.properties.getWorkingDir();
String projectRoot = properties.getWorkingDir();
String[] commands = command.split(" ");
return captureCommandOutput(projectRoot, commands).trim();
return captureCommandOutput(properties, projectRoot, commands).trim();
}
catch (IllegalStateException e) {
throw e;
@@ -100,14 +88,14 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
}
}
public void build(ProjectVersion originalVersion,
public void build(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion versionFromReleaseTrain, String projectRoot) {
try {
String command = new CommandPicker(this.properties, projectRoot)
String command = new CommandPicker(properties, projectRoot)
.buildCommand(versionFromReleaseTrain);
String[] commands = replaceAllPlaceHolders(originalVersion,
versionFromReleaseTrain, command).split(" ");
runCommand(projectRoot, commands);
runCommand(properties, projectRoot, commands);
assertNoHtmlFilesInDocsContainUnresolvedTags(projectRoot);
log.info("No HTML files from docs contain unresolved tags");
}
@@ -116,14 +104,15 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
}
}
public void generateReleaseTrainDocs(String version, String projectRoot) {
public void generateReleaseTrainDocs(ReleaserProperties properties, String version,
String projectRoot) {
try {
String updatedCommand = new CommandPicker(properties, projectRoot)
.generateReleaseTrainDocsCommand(
new ProjectVersion(new File(projectRoot)))
.replace(VERSION_MUSTACHE, version);
runCommand(projectRoot, updatedCommand.split(" "));
assertNoHtmlFilesInDocsContainUnresolvedTags(this.properties.getWorkingDir());
runCommand(properties, projectRoot, updatedCommand.split(" "));
assertNoHtmlFilesInDocsContainUnresolvedTags(properties.getWorkingDir());
log.info("No HTML files from docs contain unresolved tags");
}
catch (Exception e) {
@@ -144,25 +133,27 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
}
}
public void deploy(ProjectVersion originalVersion, ProjectVersion version) {
doDeploy(originalVersion, version,
new CommandPicker(properties, this.properties.getWorkingDir())
public void deploy(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion version) {
doDeploy(properties, originalVersion, version,
new CommandPicker(properties, properties.getWorkingDir())
.deployCommand(version));
}
public void deployGuides(ProjectVersion originalVersion, ProjectVersion version) {
doDeploy(originalVersion, version,
new CommandPicker(properties, this.properties.getWorkingDir())
public void deployGuides(ReleaserProperties properties,
ProjectVersion originalVersion, ProjectVersion version) {
doDeploy(properties, originalVersion, version,
new CommandPicker(properties, properties.getWorkingDir())
.deployGuidesCommand(version));
}
private void doDeploy(ProjectVersion originalVersion, ProjectVersion changedVersion,
String command) {
private void doDeploy(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion changedVersion, String command) {
try {
String replacedCommand = replaceAllPlaceHolders(originalVersion,
changedVersion, command);
String[] commands = replacedCommand.split(" ");
runCommand(commands);
runCommand(properties, commands);
log.info("The project has successfully been deployed");
}
catch (Exception e) {
@@ -170,19 +161,21 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
}
}
private void runCommand(String[] commands) {
runCommand(this.properties.getWorkingDir(), commands);
private void runCommand(ReleaserProperties properties, String[] commands) {
runCommand(properties, properties.getWorkingDir(), commands);
}
private void runCommand(String projectRoot, String[] commands) {
String[] substitutedCommands = substituteSystemProps(commands);
private void runCommand(ReleaserProperties properties, String projectRoot,
String[] commands) {
String[] substitutedCommands = substituteSystemProps(properties, commands);
long waitTimeInMinutes = new CommandPicker(properties, projectRoot)
.waitTimeInMinutes();
executor(projectRoot).runCommand(substitutedCommands, waitTimeInMinutes);
}
private String captureCommandOutput(String projectRoot, String[] commands) {
String[] substitutedCommands = substituteSystemProps(commands);
private String captureCommandOutput(ReleaserProperties properties, String projectRoot,
String[] commands) {
String[] substitutedCommands = substituteSystemProps(properties, commands);
long waitTimeInMinutes = new CommandPicker(properties, projectRoot)
.waitTimeInMinutes();
return executor(projectRoot).runCommandWithOutput(substitutedCommands,
@@ -193,14 +186,14 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
return new ReleaserProcessExecutor(workDir);
}
public void publishDocs(ProjectVersion originalVersion,
public void publishDocs(ReleaserProperties properties, ProjectVersion originalVersion,
ProjectVersion changedVersion) {
try {
for (String command : new CommandPicker(properties).publishDocsCommands()) {
command = replaceAllPlaceHolders(originalVersion, changedVersion,
command);
String[] commands = command.split(" ");
runCommand(commands);
runCommand(properties, commands);
}
log.info("The docs got published successfully");
}
@@ -220,9 +213,10 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
* We need to insert the system properties as a list of -Dkey=value entries instead of
* just pasting the String that contains these values.
*/
private String[] substituteSystemProps(String... commands) {
String systemProperties = new CommandPicker(this.properties).systemProperties();
String systemPropertiesPlaceholder = new CommandPicker(this.properties)
private String[] substituteSystemProps(ReleaserProperties properties,
String... commands) {
String systemProperties = new CommandPicker(properties).systemProperties();
String systemPropertiesPlaceholder = new CommandPicker(properties)
.systemPropertiesPlaceholder();
boolean containsSystemProps = systemProperties.contains("-D");
String[] splitSystemProps = StringUtils
@@ -267,14 +261,9 @@ public class ProjectCommandExecutor implements ReleaserPropertiesAware {
return commandsList.toArray(new String[commandsList.size()]);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
class ReleaserProcessExecutor implements ReleaserPropertiesAware {
class ReleaserProcessExecutor {
private static final Logger log = LoggerFactory
.getLogger(ReleaserProcessExecutor.class);
@@ -345,11 +334,6 @@ class ReleaserProcessExecutor implements ReleaserPropertiesAware {
return new String[] { "/bin/bash", "-c", lastArg };
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.workingDir = properties.getWorkingDir();
}
}
class CommandPicker {

View File

@@ -96,7 +96,7 @@ public class ProjectVersion implements Comparable<ProjectVersion>, Serializable
ProjectVersion projectVersion = gradleProject(buildGradle);
this.projectName = projectVersion.projectName;
this.version = projectVersion.version;
this.groupId = new ProjectCommandExecutor(properties).groupId();
this.groupId = new ProjectCommandExecutor().groupId(properties);
this.artifactId = projectName;
}
else {
@@ -130,7 +130,7 @@ public class ProjectVersion implements Comparable<ProjectVersion>, Serializable
String name = parentFolder.getName();
ReleaserProperties properties = new ReleaserProperties();
properties.setWorkingDir(parentFolder.getAbsolutePath());
String version = new ProjectCommandExecutor(properties).version();
String version = new ProjectCommandExecutor().version(properties);
return new ProjectVersion(nameWithoutParent(name), version);
}

View File

@@ -21,7 +21,6 @@ import java.io.IOException;
import com.github.jknack.handlebars.Template;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.github.ProjectGitHubHandler;
import releaser.internal.project.Projects;
import releaser.internal.tech.HandlebarsHelper;
@@ -29,7 +28,7 @@ import releaser.internal.tech.HandlebarsHelper;
/**
* @author Marcin Grzejszczak
*/
public class TemplateGenerator implements ReleaserPropertiesAware {
public class TemplateGenerator {
private static final String EMAIL_TEMPLATE = "email";
@@ -49,7 +48,7 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
private final ProjectGitHubHandler handler;
private ReleaserProperties props;
private final ReleaserProperties props;
public TemplateGenerator(ReleaserProperties props, ProjectGitHubHandler handler) {
this.props = props;
@@ -133,9 +132,4 @@ public class TemplateGenerator implements ReleaserPropertiesAware {
template);
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.props = properties;
}
}

View File

@@ -34,7 +34,6 @@ import io.spring.initializr.metadata.InitializrProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import releaser.internal.buildsystem.ProjectPomUpdater;
import releaser.internal.project.ProjectVersion;
import releaser.internal.project.Projects;
@@ -51,7 +50,7 @@ import org.springframework.util.StringUtils;
*
* @author Marcin Grzejszczak
*/
public class VersionsFetcher implements ReleaserPropertiesAware, Closeable {
public class VersionsFetcher implements Closeable {
private static final Logger log = LoggerFactory.getLogger(VersionsFetcher.class);
@@ -59,7 +58,7 @@ public class VersionsFetcher implements ReleaserPropertiesAware, Closeable {
private final ToPropertiesConverter toPropertiesConverter;
private ReleaserProperties properties;
private final ReleaserProperties properties;
public VersionsFetcher(ReleaserProperties properties,
ProjectPomUpdater projectPomUpdater) {
@@ -140,11 +139,6 @@ public class VersionsFetcher implements ReleaserPropertiesAware, Closeable {
return springCloudVersion;
}
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
@Override
public void close() {
this.toPropertiesConverter.close();

View File

@@ -39,6 +39,7 @@ import org.mockito.BDDMockito;
import releaser.SpringCloudReleaserProperties;
import releaser.internal.PomUpdateAcceptanceTests;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesUpdater;
import releaser.internal.buildsystem.GradleUpdater;
import releaser.internal.buildsystem.ProjectPomUpdater;
import releaser.internal.buildsystem.TestUtils;
@@ -78,7 +79,9 @@ public class PostReleaseActionsTests {
VersionsFetcher versionsFetcher = fetcher(this.properties);
ProjectCommandExecutor builder = commandExecutor(this.properties);
ReleaserPropertiesUpdater releaserPropertiesUpdater = new ReleaserPropertiesUpdater();
ProjectCommandExecutor commandExecutor = new ProjectCommandExecutor();
private ProjectGitHandler projectGitHandler(ReleaserProperties properties) {
return new ProjectGitHandler(properties) {
@@ -111,10 +114,6 @@ public class PostReleaseActionsTests {
return new VersionsFetcher(properties, updater);
}
private ProjectCommandExecutor commandExecutor(ReleaserProperties properties) {
return new ProjectCommandExecutor(properties);
}
@Before
public void setup() throws Exception {
this.temporaryFolder = this.tmp.newFolder();
@@ -126,8 +125,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_is_not_meta_release_and_update_test_is_called() {
this.properties.getMetaRelease().setEnabled(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.runUpdatedTests(currentGa());
@@ -139,8 +138,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_the_switch_for_sample_check_is_off_and_update_test_is_called() {
this.properties.getGit().setRunUpdatedSamples(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.runUpdatedTests(currentGa());
@@ -158,8 +157,13 @@ public class PostReleaseActionsTests {
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
properties.getMaven().setBuildCommand("touch build.log");
PostReleaseActions actions = new PostReleaseActions(projectGitHandler(properties),
projectPomUpdater(properties), this.gradleUpdater,
commandExecutor(properties), properties, fetcher(properties));
projectPomUpdater(properties), this.gradleUpdater, commandExecutor,
properties, fetcher(properties), releaserPropertiesUpdater) {
@Override
ReleaserProperties projectProps(File file) {
return properties;
}
};
actions.runUpdatedTests(currentGa());
@@ -181,8 +185,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_is_not_meta_release_and_release_train_docs_generation_is_called() {
this.properties.getMetaRelease().setEnabled(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.generateReleaseTrainDocumentation(currentGa());
@@ -193,8 +197,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_the_switch_for_sample_check_is_off_and_release_train_docs_generation_is_called() {
this.properties.getGit().setUpdateReleaseTrainDocs(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.generateReleaseTrainDocumentation(currentGa());
@@ -209,8 +213,8 @@ public class PostReleaseActionsTests {
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/");
this.properties.getMaven().setGenerateReleaseTrainDocsCommand("./test.sh");
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.generateReleaseTrainDocumentation(currentGa());
@@ -226,8 +230,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_is_not_meta_release_and_test_samples_update_is_called() {
this.properties.getMetaRelease().setEnabled(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.updateAllTestSamples(currentGa());
@@ -239,8 +243,8 @@ public class PostReleaseActionsTests {
public void should_do_nothing_when_the_switch_for_test_samples_update_check_is_off_and_update_is_called() {
this.properties.getGit().setUpdateReleaseTrainDocs(false);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.updateAllTestSamples(currentGa());
@@ -260,8 +264,8 @@ public class PostReleaseActionsTests {
tmpFile("spring-cloud-core-tests/").getAbsolutePath() + "/"));
AtomicReference<Projects> postReleaseProjects = new AtomicReference<>();
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, properties,
versionsFetcher) {
this.updater, this.gradleUpdater, this.commandExecutor, properties,
versionsFetcher, releaserPropertiesUpdater) {
@Override
Projects getPostReleaseProjects(Projects projects) {
postReleaseProjects.set(super.getPostReleaseProjects(projects));
@@ -304,8 +308,8 @@ public class PostReleaseActionsTests {
.singletonList(tmpFile("spring-cloud-static/").getAbsolutePath() + "/"));
AtomicReference<Projects> postReleaseProjects = new AtomicReference<>();
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, properties,
versionsFetcher) {
this.updater, this.gradleUpdater, this.commandExecutor, properties,
versionsFetcher, releaserPropertiesUpdater) {
@Override
Projects getPostReleaseProjects(Projects projects) {
postReleaseProjects.set(super.getPostReleaseProjects(projects));
@@ -325,8 +329,8 @@ public class PostReleaseActionsTests {
this.properties.getGit().setUpdateSpringGuides(false);
VersionsFetcher versionsFetcher = BDDMockito.mock(VersionsFetcher.class);
PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
this.updater, this.gradleUpdater, this.builder, this.properties,
versionsFetcher);
this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater);
actions.deployGuides(Collections.emptyList());
@@ -346,7 +350,8 @@ public class PostReleaseActionsTests {
ProjectCommandExecutor projectCommandExecutor = BDDMockito
.mock(ProjectCommandExecutor.class);
PostReleaseActions actions = new PostReleaseActions(handler, this.updater,
this.gradleUpdater, this.builder, this.properties, versionsFetcher) {
this.gradleUpdater, this.commandExecutor, this.properties,
versionsFetcher, releaserPropertiesUpdater) {
@Override
ProjectCommandExecutor projectBuilder(ProcessedProject processedProject) {
projectBuilderStub.set(projectCommandExecutor);
@@ -362,7 +367,7 @@ public class PostReleaseActionsTests {
Awaitility.await().untilAsserted(() -> {
BDDAssertions.then(projectBuilderStub.get()).isNotNull();
BDDMockito.then(projectBuilderStub.get()).should()
.deployGuides(projectVersion, projectVersion);
.deployGuides(this.properties, projectVersion, projectVersion);
});
}

View File

@@ -64,7 +64,7 @@ public class ProjectCommandExecutorTests {
}
ProjectCommandExecutor projectBuilder(ReleaserProperties properties) {
return new ProjectCommandExecutor(properties) {
return new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return testExecutor(workingDir);
@@ -80,7 +80,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("resolved.log");
@@ -94,7 +95,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(new File("/foo/bar").getAbsolutePath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
tmpFile("/builder/resolved").getPath());
then(asString(tmpFile("/builder/resolved/resolved.log")))
@@ -109,7 +111,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.M1"));
builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -122,7 +124,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.RC1"));
builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo")
.doesNotContain("-Pguides");
@@ -136,7 +138,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.RELEASE"));
builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -149,7 +151,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.SR1"));
builder.build(properties, original(), new ProjectVersion("foo", "1.0.0.SR1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -163,7 +165,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=world -Dfoo=bar");
@@ -177,7 +180,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -191,7 +195,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("hello=world foo=bar");
@@ -206,7 +211,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=world -Dfoo=bar bar");
@@ -221,7 +227,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.build(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("bar -Dhello=world -Dfoo=bar");
@@ -234,7 +241,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
thenThrownBy(() -> builder.build(original(),
thenThrownBy(() -> builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining(
"contains a tag that wasn't resolved properly");
}
@@ -247,7 +254,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
thenThrownBy(() -> builder.build(original(),
thenThrownBy(() -> builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining(
"Process waiting time of [0] minutes exceeded");
}
@@ -259,7 +266,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("resolved.log");
@@ -273,7 +281,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.M1"));
builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo")
.doesNotContain("-Pguides");
@@ -289,7 +297,7 @@ public class ProjectCommandExecutorTests {
.runCommand(new String[] { "touch", "pom.xml" }, 1);
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.M1"));
builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.M1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone").doesNotContain("-Pguides");
@@ -303,7 +311,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RC1"));
builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo")
.doesNotContain("-Pguides");
@@ -319,7 +327,7 @@ public class ProjectCommandExecutorTests {
.runCommand(new String[] { "touch", "pom.xml" }, 1);
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RC1"));
builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.RC1"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pmilestone").doesNotContain("-Pguides");
@@ -333,7 +341,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RELEASE"));
builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -348,7 +357,8 @@ public class ProjectCommandExecutorTests {
.runCommand(new String[] { "touch", "pom.xml" }, 1);
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.RELEASE"));
builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("foo -Pcentral");
@@ -362,7 +372,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.SR1"));
builder.deploy(properties, original(), new ProjectVersion("foo", "1.0.0.SR1"));
then(asString(tmpFile("/builder/resolved/resolved.log"))).contains("foo");
}
@@ -376,7 +386,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=hello-world");
@@ -391,7 +402,8 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
builder.deploy(original(), new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=hello-world");
@@ -405,7 +417,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
thenThrownBy(() -> builder.deploy(original(),
thenThrownBy(() -> builder.deploy(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining(
"Process waiting time of [0] minutes exceeded");
}
@@ -417,14 +429,15 @@ public class ProjectCommandExecutorTests {
"echo {{version}} {{oldVersion}} {{nextVersion}}" });
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) {
ProjectCommandExecutor builder = new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return executor;
}
};
builder.publishDocs(original(), new ProjectVersion("foo", "1.0.0.RELEASE"));
builder.publishDocs(properties, original(),
new ProjectVersion("foo", "1.0.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("1.0.0.RELEASE 0.100.0.BUILD-SNAPSHOT 1.0.1.RELEASE");
@@ -440,14 +453,15 @@ public class ProjectCommandExecutorTests {
properties.getBash().setSystemProperties("-Dhello=world -Dfoo=bar");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) {
ProjectCommandExecutor builder = new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return executor;
}
};
builder.publishDocs(original(), new ProjectVersion("foo", "Finchley.RELEASE"));
builder.publishDocs(properties, original(),
new ProjectVersion("foo", "Finchley.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("-Dhello=world -Dfoo=bar 2");
@@ -462,14 +476,15 @@ public class ProjectCommandExecutorTests {
.setPublishDocsCommands(new String[] { "echo '{{version}}'" });
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) {
ProjectCommandExecutor builder = new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return executor;
}
};
builder.publishDocs(original(), new ProjectVersion("foo", "1.1.0.RELEASE"));
builder.publishDocs(properties, original(),
new ProjectVersion("foo", "1.1.0.RELEASE"));
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("1.1.0.RELEASE");
@@ -483,14 +498,15 @@ public class ProjectCommandExecutorTests {
File resolved = tmpFile("/builder/resolved");
properties.setWorkingDir(resolved.getPath());
TestReleaserProcessExecutor executor = testExecutor(properties.getWorkingDir());
ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) {
ProjectCommandExecutor builder = new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return executor;
}
};
builder.generateReleaseTrainDocs("1.1.0.RELEASE", resolved.getAbsolutePath());
builder.generateReleaseTrainDocs(properties, "1.1.0.RELEASE",
resolved.getAbsolutePath());
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("1.1.0.RELEASE");
@@ -505,7 +521,7 @@ public class ProjectCommandExecutorTests {
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectCommandExecutor builder = projectBuilder(properties);
thenThrownBy(() -> builder.publishDocs(original(),
thenThrownBy(() -> builder.publishDocs(properties, original(),
new ProjectVersion("foo", "1.0.0.RELEASE"))).hasMessageContaining(
"Process waiting time of [0] minutes exceeded");
}
@@ -515,7 +531,7 @@ public class ProjectCommandExecutorTests {
ReleaserProperties properties = new ReleaserProperties();
properties.getBash().setBuildCommand("exit 1");
properties.setWorkingDir(tmpFile("/builder/unresolved").getPath());
ProjectCommandExecutor builder = new ProjectCommandExecutor(properties) {
ProjectCommandExecutor builder = new ProjectCommandExecutor() {
@Override
ReleaserProcessExecutor executor(String workingDir) {
return new ReleaserProcessExecutor(properties.getWorkingDir()) {
@@ -528,7 +544,7 @@ public class ProjectCommandExecutorTests {
}
};
thenThrownBy(() -> builder.build(original(),
thenThrownBy(() -> builder.build(properties, original(),
new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"))).hasMessageContaining(
"The process has exited with exit code [1]");
}

View File

@@ -27,6 +27,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import releaser.internal.Releaser;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesUpdater;
import releaser.internal.options.Options;
import releaser.internal.project.ProjectVersion;

View File

@@ -21,6 +21,7 @@ import java.util.List;
import releaser.internal.Releaser;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesUpdater;
import releaser.internal.buildsystem.GradleUpdater;
import releaser.internal.buildsystem.ProjectPomUpdater;
import releaser.internal.docs.CustomProjectDocumentationUpdater;
@@ -88,8 +89,8 @@ class ReleaserConfiguration {
@Bean
@ConditionalOnMissingBean
ProjectCommandExecutor projectBuilder(ReleaserProperties properties) {
return new ProjectCommandExecutor(properties);
ProjectCommandExecutor projectBuilder() {
return new ProjectCommandExecutor();
}
@Bean
@@ -139,9 +140,11 @@ class ReleaserConfiguration {
PostReleaseActions postReleaseActions(ProjectGitHandler handler,
ProjectPomUpdater pomUpdater, GradleUpdater gradleUpdater,
ProjectCommandExecutor projectCommandExecutor,
ReleaserProperties releaserProperties, VersionsFetcher versionsFetcher) {
ReleaserProperties releaserProperties, VersionsFetcher versionsFetcher,
ReleaserPropertiesUpdater releaserPropertiesUpdater) {
return new PostReleaseActions(handler, pomUpdater, gradleUpdater,
projectCommandExecutor, releaserProperties, versionsFetcher);
projectCommandExecutor, releaserProperties, versionsFetcher,
releaserPropertiesUpdater);
}
@Bean
@@ -172,8 +175,8 @@ class ReleaserConfiguration {
@Bean
@ConditionalOnMissingBean
ReleaserPropertiesUpdater releaserPropertiesUpdater(ApplicationContext context) {
return new ReleaserPropertiesUpdater(context);
ReleaserPropertiesUpdater releaserPropertiesUpdater() {
return new ReleaserPropertiesUpdater();
}
@Bean

View File

@@ -56,7 +56,8 @@ public class BuildProjectReleaseTask implements DryRunReleaseReleaserTask {
@Override
public ExecutionResult runTask(Arguments args) {
return this.releaser.buildProject(args.originalVersion, args.versionFromBom);
return this.releaser.buildProject(args.properties, args.originalVersion,
args.versionFromBom);
}
@Override

View File

@@ -56,7 +56,8 @@ public class DeployArtifactsReleaseTask implements ReleaseReleaserTask {
@Override
public ExecutionResult runTask(Arguments args) {
return this.releaser.deploy(args.originalVersion, args.versionFromBom);
return this.releaser.deploy(args.properties, args.originalVersion,
args.versionFromBom);
}
@Override

View File

@@ -56,7 +56,8 @@ public class PublishDocsReleaseTask implements ReleaseReleaserTask {
@Override
public ExecutionResult runTask(Arguments args) {
return this.releaser.publishDocs(args.originalVersion, args.versionFromBom);
return this.releaser.publishDocs(args.properties, args.originalVersion,
args.versionFromBom);
}
@Override

View File

@@ -28,7 +28,7 @@ public class TestDocumentationUpdater extends DocumentationUpdater {
public TestDocumentationUpdater(ReleaserProperties properties,
CustomProjectDocumentationUpdater updater, ProjectGitHandler handler,
TestReleaseContentsUpdater testRelease) {
super(properties, new ProjectDocumentationUpdater(properties, handler,
super(new ProjectDocumentationUpdater(properties, handler,
Collections.singletonList(updater)), testRelease);
}

View File

@@ -1,133 +0,0 @@
/*
* Copyright 2013-2019 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
*
* https://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 releaser.internal.spring;
import java.io.File;
import java.net.URL;
import java.util.List;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Marcin Grzejszczak
*/
@RunWith(SpringRunner.class)
@Import(ReleaserPropertiesIntegrationTests.Config.class)
public class ReleaserPropertiesIntegrationTests {
@Autowired
List<ReleaserPropertiesAware> propertiesAware;
@Autowired
ApplicationContext context;
@Test
public void should_update_properties() {
ReleaserProperties properties = new ReleaserProperties();
properties.getPom().setBranch("fooooo");
new ReleaserPropertiesUpdater(this.context).updateProperties(properties,
new File("."));
BDDAssertions.then(this.propertiesAware).hasSize(2);
this.propertiesAware.forEach(aware -> BDDAssertions
.then(((ReleaserPropertiesHaving) aware).properties.getPom().getBranch())
.isEqualTo("fooooo"));
}
@Test
public void should_update_properties_including_existing_releaser_config() {
ReleaserProperties properties = new ReleaserProperties();
properties.getPom().setBranch("barrrr");
URL resource = ReleaserPropertiesIntegrationTests.class
.getResource("/projects/project-with-config");
new ReleaserPropertiesUpdater(this.context).updateProperties(properties,
new File(resource.getFile()));
BDDAssertions.then(this.propertiesAware).hasSize(2);
this.propertiesAware.forEach(aware -> {
ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware);
BDDAssertions.then(having.properties.getPom().getBranch())
.isEqualTo("barrrr");
BDDAssertions.then(having.properties.getMaven().getBuildCommand())
.isEqualTo("./scripts/noIntegration.sh");
});
}
@Test
public void should_update_properties_including_existing_releaser_config_for_netflix() {
ReleaserProperties properties = new ReleaserProperties();
properties.getPom().setBranch("bazzzz");
URL resource = ReleaserPropertiesIntegrationTests.class
.getResource("/projects/project-with-netflix-config");
new ReleaserPropertiesUpdater(this.context).updateProperties(properties,
new File(resource.getFile()));
BDDAssertions.then(this.propertiesAware).hasSize(2);
this.propertiesAware.forEach(aware -> {
ReleaserPropertiesHaving having = ((ReleaserPropertiesHaving) aware);
BDDAssertions.then(having.properties.getPom().getBranch())
.isEqualTo("bazzzz");
BDDAssertions.then(having.properties.getMaven().getBuildCommand())
.isEqualTo("./scripts/build.sh {{systemProps}}");
});
}
@Configuration
static class Config {
@Bean
ReleaserPropertiesAware aware1() {
return new ReleaserPropertiesHaving();
}
@Bean
ReleaserPropertiesAware aware2() {
return new ReleaserPropertiesHaving();
}
}
static class ReleaserPropertiesHaving implements ReleaserPropertiesAware {
ReleaserProperties properties;
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
ReleaserProperties getProps() {
return this.properties;
}
}
}

View File

@@ -18,24 +18,17 @@ package releaser.internal.spring;
import java.io.File;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.assertj.core.api.BDDAssertions;
import org.junit.Test;
import org.mockito.BDDMockito;
import releaser.internal.ReleaserProperties;
import releaser.internal.ReleaserPropertiesAware;
import org.springframework.context.ApplicationContext;
import releaser.internal.ReleaserPropertiesUpdater;
/**
* @author Marcin Grzejszczak
*/
public class ReleaserPropertiesUpdaterTests {
ApplicationContext context = BDDMockito.mock(ApplicationContext.class);
File relaserUpdater;
public ReleaserPropertiesUpdaterTests() throws URISyntaxException {
@@ -46,15 +39,11 @@ public class ReleaserPropertiesUpdaterTests {
@Test
public void should_update_properties() {
ReleaserProperties original = originalReleaserProperties();
Aware aware = new Aware();
BDDMockito.given(this.context.getBeansOfType(BDDMockito.any(Class.class)))
.willReturn(beansOfType(aware));
ReleaserPropertiesUpdater updater = new ReleaserPropertiesUpdater(this.context);
ReleaserPropertiesUpdater updater = new ReleaserPropertiesUpdater();
ReleaserProperties props = updater.updateProperties(original,
this.relaserUpdater);
BDDAssertions.then(aware.properties).isNotNull();
BDDAssertions.then(props.getMaven().getBuildCommand()).isEqualTo("maven_build");
BDDAssertions.then(props.getGradle().getBuildCommand()).isEqualTo("gradle_build");
BDDAssertions.then(props.getBash().getBuildCommand()).isEqualTo("bash_build");
@@ -67,21 +56,4 @@ public class ReleaserPropertiesUpdaterTests {
return props;
}
private Map<String, Object> beansOfType(Aware aware) {
Map<String, Object> map = new HashMap<>();
map.put("foo", aware);
return map;
}
class Aware implements ReleaserPropertiesAware {
ReleaserProperties properties;
@Override
public void setReleaserProperties(ReleaserProperties properties) {
this.properties = properties;
}
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright 2013-2019 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
*
* https://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 releaser.internal.docs;
import edu.emory.mathcs.backport.java.util.Collections;
import releaser.internal.ReleaserProperties;
import releaser.internal.git.ProjectGitHandler;
/**
* @author Marcin Grzejszczak
*/
public class TestDocumentationUpdater extends DocumentationUpdater {
public TestDocumentationUpdater(ReleaserProperties properties,
CustomProjectDocumentationUpdater updater, ProjectGitHandler handler,
TestReleaseContentsUpdater testRelease) {
super(properties, new ProjectDocumentationUpdater(properties, handler,
Collections.singletonList(updater)), testRelease);
}
}