|
|
|
|
@@ -32,18 +32,14 @@ import java.io.InputStream;
|
|
|
|
|
import java.io.StringWriter;
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.zip.ZipEntry;
|
|
|
|
|
import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
|
|
|
|
import javax.xml.transform.TransformerException;
|
|
|
|
|
import javax.xml.transform.dom.DOMSource;
|
|
|
|
|
import javax.xml.transform.stream.StreamResult;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
|
import org.springframework.data.release.build.CommandLine.Argument;
|
|
|
|
|
@@ -62,7 +58,6 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import org.xmlbeam.ProjectionFactory;
|
|
|
|
|
import org.xmlbeam.XBProjector;
|
|
|
|
|
import org.xmlbeam.dom.DOMAccess;
|
|
|
|
|
@@ -85,19 +80,18 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
ProjectionFactory projectionFactory;
|
|
|
|
|
Logger logger;
|
|
|
|
|
MavenRuntime mvn;
|
|
|
|
|
MavenProperties mavenProperties;
|
|
|
|
|
DeploymentProperties properties;
|
|
|
|
|
Gpg gpg;
|
|
|
|
|
|
|
|
|
|
Environment env;
|
|
|
|
|
DeploymentProperties deploymentProperties;
|
|
|
|
|
|
|
|
|
|
static final String REPO_OPENING_TAG = "<repository>";
|
|
|
|
|
static final String REPO_CLOSING_TAG = "</repository>";
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BuildSystem withJavaVersion(JavaVersion javaVersion) {
|
|
|
|
|
return new MavenBuildSystem(workspace, projectionFactory, logger, mvn.withJavaVersion(javaVersion), mavenProperties,
|
|
|
|
|
properties, gpg, env, deploymentProperties);
|
|
|
|
|
return new MavenBuildSystem(workspace, projectionFactory, logger, mvn.withJavaVersion(javaVersion), properties, gpg,
|
|
|
|
|
env);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -192,30 +186,14 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
@Override
|
|
|
|
|
public StagingRepository open(Train train) {
|
|
|
|
|
|
|
|
|
|
MavenCentral properties = this.properties.getMavenCentral();
|
|
|
|
|
Assert.notNull(properties, "Maven Central properties must not be null");
|
|
|
|
|
Assert.hasText(properties.getStagingProfileId(), "Staging Profile Identifier must not be empty");
|
|
|
|
|
|
|
|
|
|
if (properties.getProcess() == MavenCentral.Publishing.OSSRH) {
|
|
|
|
|
return openRemoteStagingRepository(train, properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String instance = UUID.randomUUID().toString();
|
|
|
|
|
|
|
|
|
|
File stagingRoot = new File(mavenProperties.getLocalStaging(), instance);
|
|
|
|
|
stagingRoot.mkdirs();
|
|
|
|
|
|
|
|
|
|
return StagingRepository.ofFile(stagingRoot.getPath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private StagingRepository openRemoteStagingRepository(Train train, MavenCentral properties) {
|
|
|
|
|
Assert.notNull(properties.getMavenCentral(), "Maven Central properties must not be null");
|
|
|
|
|
Assert.hasText(properties.getMavenCentral().getStagingProfileId(), "Staging Profile Identifier must not be empty");
|
|
|
|
|
|
|
|
|
|
CommandLine arguments = CommandLine.of(goal("nexus-staging:rc-open"), //
|
|
|
|
|
profile("central"), //
|
|
|
|
|
arg("stagingProfileId").withValue(properties.getStagingProfileId()), //
|
|
|
|
|
arg("stagingProfileId").withValue(properties.getMavenCentral().getStagingProfileId()), //
|
|
|
|
|
arg("openedRepositoryMessageFormat").withValue("'" + REPO_OPENING_TAG + "%s" + REPO_CLOSING_TAG + "'"))
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(this.properties.getSettingsXml()),
|
|
|
|
|
() -> settingsXml(this.properties.getSettingsXml()));
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), () -> settingsXml(properties.getSettingsXml()));
|
|
|
|
|
|
|
|
|
|
MavenRuntime.MavenInvocationResult invocationResult = mvn.execute(train.getSupportedProject(BUILD), arguments);
|
|
|
|
|
|
|
|
|
|
@@ -243,16 +221,12 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
Assert.notNull(stagingRepository, "StagingRepository must not be null");
|
|
|
|
|
Assert.isTrue(stagingRepository.isPresent(), "StagingRepository must be present");
|
|
|
|
|
|
|
|
|
|
if (deploymentProperties.getMavenCentral().getProcess() == MavenCentral.Publishing.OSSRH
|
|
|
|
|
&& stagingRepository.isRemote()) {
|
|
|
|
|
CommandLine arguments = CommandLine.of(goal("nexus-staging:rc-close"), //
|
|
|
|
|
profile("central"), //
|
|
|
|
|
arg("stagingRepositoryId").withValue(stagingRepository.getId()))
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), () -> settingsXml(properties.getSettingsXml()));
|
|
|
|
|
|
|
|
|
|
CommandLine arguments = CommandLine.of(goal("nexus-staging:rc-close"), //
|
|
|
|
|
profile("central"), //
|
|
|
|
|
arg("stagingRepositoryId").withValue(stagingRepository.getId()))
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), () -> settingsXml(properties.getSettingsXml()));
|
|
|
|
|
|
|
|
|
|
mvn.execute(train.getSupportedProject(BUILD), arguments);
|
|
|
|
|
}
|
|
|
|
|
mvn.execute(train.getSupportedProject(BUILD), arguments);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
@@ -353,8 +327,7 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
arg("gpg.keyname").withValue(gpg.getKeyname()), //
|
|
|
|
|
arg("gpg.passphrase").withValue(gpg.getPassphrase())) //
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), settingsXml(properties.getSettingsXml()))
|
|
|
|
|
.andIf(StringUtils.hasText(information.getProject()),
|
|
|
|
|
() -> arg("artifactory.project").withValue(information.getProject()));
|
|
|
|
|
.andIf(StringUtils.hasText(information.getProject()), () -> arg("artifactory.project").withValue(information.getProject()));
|
|
|
|
|
|
|
|
|
|
mvn.execute(module.getSupportedProject(), arguments);
|
|
|
|
|
}
|
|
|
|
|
@@ -380,7 +353,6 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
|
|
|
|
|
Gpg gpg = getGpg();
|
|
|
|
|
|
|
|
|
|
StagingRepository stagingRepository = deploymentInformation.getStagingRepositoryId();
|
|
|
|
|
CommandLine arguments = CommandLine.of(Goal.CLEAN, Goal.DEPLOY, //
|
|
|
|
|
profile("ci,release,central"), //
|
|
|
|
|
SKIP_TESTS, //
|
|
|
|
|
@@ -388,10 +360,8 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
arg("gpg.keyname").withValue(gpg.getKeyname()), //
|
|
|
|
|
arg("gpg.passphrase").withValue(gpg.getPassphrase())) //
|
|
|
|
|
.andIf(!ObjectUtils.isEmpty(properties.getSettingsXml()), settingsXml(properties.getSettingsXml()))
|
|
|
|
|
.andIf(stagingRepository.isPresent() && stagingRepository.isRemote(),
|
|
|
|
|
() -> arg("stagingRepositoryId").withValue(stagingRepository.getId()))
|
|
|
|
|
.andIf(stagingRepository.isPresent() && stagingRepository.isFile(),
|
|
|
|
|
() -> arg("altDeploymentRepository").withValue("staging::default::file:" + stagingRepository.getId()))
|
|
|
|
|
.andIf(deploymentInformation.getStagingRepositoryId().isPresent(),
|
|
|
|
|
() -> arg("stagingRepositoryId").withValue(deploymentInformation.getStagingRepositoryId()))
|
|
|
|
|
.andIf(gpg.hasSecretKeyring(), () -> arg("gpg.secretKeyring").withValue(gpg.getSecretKeyring()));
|
|
|
|
|
|
|
|
|
|
mvn.execute(module.getSupportedProject(), arguments);
|
|
|
|
|
@@ -415,17 +385,16 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
doWithProjection(workspace.getFile(POM_XML, smokeTests), pom -> {
|
|
|
|
|
|
|
|
|
|
Version version = module.getVersion();
|
|
|
|
|
String targetBootVersion = version.getMajor() == 2 ? "2.7.8" : "3.2.2";
|
|
|
|
|
String targetBootVersion = version.getMajor() == 2 ? "2.7.8" : "3.0.2";
|
|
|
|
|
|
|
|
|
|
pom.setParentVersion(ArtifactVersion.of(Version.parse(targetBootVersion), true));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
CommandLine arguments = CommandLine.of(Goal.CLEAN, VERIFY, //
|
|
|
|
|
profile(profile), //
|
|
|
|
|
settingsXml("settings.xml"), //
|
|
|
|
|
arg("s").withValue("settings.xml"), //
|
|
|
|
|
arg("spring-data-bom.version").withValue(iteration.getReleaseTrainNameAndVersion())) //
|
|
|
|
|
.andIf(mavenCentral && stagingRepository.isPresent() && stagingRepository.isRemote(),
|
|
|
|
|
arg("stagingRepository").withValue(stagingRepository.getId()));
|
|
|
|
|
.andIf(mavenCentral, arg("stagingRepository").withValue(stagingRepository.getId()));
|
|
|
|
|
|
|
|
|
|
mvn.execute(smokeTests, arguments);
|
|
|
|
|
|
|
|
|
|
@@ -441,84 +410,6 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
Assert.notNull(stagingRepository, "StagingRepository must not be null");
|
|
|
|
|
Assert.isTrue(stagingRepository.isPresent(), "StagingRepository must be present");
|
|
|
|
|
|
|
|
|
|
MavenCentral.Publishing process = deploymentProperties.getMavenCentral().getProcess();
|
|
|
|
|
|
|
|
|
|
if (process == MavenCentral.Publishing.OSSRH && stagingRepository.isRemote()) {
|
|
|
|
|
releaseRemoteRepository(train, stagingRepository);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (process == MavenCentral.Publishing.PUBLISHER && stagingRepository.isFile()) {
|
|
|
|
|
publishRelease(stagingRepository);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new UnsupportedOperationException(
|
|
|
|
|
String.format("Cannot release train using %s and staging repository %s", process, stagingRepository));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void publishRelease(StagingRepository stagingRepository) {
|
|
|
|
|
|
|
|
|
|
File root = new File(mavenProperties.getLocalStaging(), stagingRepository.getId());
|
|
|
|
|
|
|
|
|
|
Assert.isTrue(root.exists(), "StagingRepository " + root + " does not exist");
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
File releaseBundle = createReleaseBundle(root);
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private File createReleaseBundle(File root) throws IOException {
|
|
|
|
|
|
|
|
|
|
String deploymentIdentifier = root.getName();
|
|
|
|
|
String deploymentBundle = deploymentIdentifier + ".zip";
|
|
|
|
|
|
|
|
|
|
File zip = new File(root, deploymentBundle);
|
|
|
|
|
File[] files = root.listFiles();
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(files, "StagingRepository " + root + " is empty");
|
|
|
|
|
|
|
|
|
|
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip))) {
|
|
|
|
|
|
|
|
|
|
// consider only directories on the root level.
|
|
|
|
|
for (File file : files) {
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
zipRecursively("", file, zos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return zip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void zipRecursively(String prefix, File file, ZipOutputStream zos) throws IOException {
|
|
|
|
|
|
|
|
|
|
String prefixToUse = (StringUtils.hasText(prefix) ? prefix + "/" : "");
|
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
|
|
|
|
|
|
File[] files = file
|
|
|
|
|
.listFiles((dir, name) -> !name.startsWith(".") && !name.startsWith("_") && !name.endsWith(".lastUpdated"));
|
|
|
|
|
if (!ObjectUtils.isEmpty(files)) {
|
|
|
|
|
|
|
|
|
|
for (File nested : files) {
|
|
|
|
|
zipRecursively(prefixToUse + file.getName(), nested, zos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ZipEntry entry = new ZipEntry(prefixToUse + file.getName());
|
|
|
|
|
zos.putNextEntry(entry);
|
|
|
|
|
|
|
|
|
|
FileInputStream in = new FileInputStream(file);
|
|
|
|
|
IOUtils.copy(in, zos);
|
|
|
|
|
IOUtils.closeQuietly(in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void releaseRemoteRepository(Train train, StagingRepository stagingRepository) {
|
|
|
|
|
CommandLine arguments = CommandLine.of(goal("nexus-staging:rc-release"), //
|
|
|
|
|
profile("central"), //
|
|
|
|
|
arg("stagingRepositoryId").withValue(stagingRepository.getId()))
|
|
|
|
|
@@ -693,9 +584,9 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
@Override
|
|
|
|
|
public void verifyStagingAuthentication(Train train) {
|
|
|
|
|
|
|
|
|
|
if (train.isOpenSource() && properties.getMavenCentral().getProcess() == MavenCentral.Publishing.OSSRH) {
|
|
|
|
|
if (train.isOpenSource()) {
|
|
|
|
|
|
|
|
|
|
logger.log(BUILD, "Verifying Maven OSSRH Staging Authentication…");
|
|
|
|
|
logger.log(BUILD, "Verifying Maven Staging Authentication…");
|
|
|
|
|
|
|
|
|
|
mvn.execute(train.getSupportedProject(BUILD), //
|
|
|
|
|
CommandLine.of(goal("nexus-staging:rc-list-profiles"), //
|
|
|
|
|
@@ -705,6 +596,7 @@ class MavenBuildSystem implements BuildSystem {
|
|
|
|
|
"Maven Central properties are not set (deployment.maven-central.staging-profile-id=…)");
|
|
|
|
|
Assert.hasText(properties.getMavenCentral().getStagingProfileId(),
|
|
|
|
|
"Staging Profile Id is not set (deployment.maven-central.staging-profile-id=…)");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|