Revert "Prepare multipart upload."

This reverts commit 35439d59dd.
This commit is contained in:
Jens Schauder
2024-07-12 14:50:43 +02:00
parent 3e5b5ea722
commit 98565b49f3
5 changed files with 16 additions and 59 deletions

View File

@@ -21,7 +21,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.release.model.SupportedProject;
import org.springframework.plugin.core.PluginRegistry;
import org.xmlbeam.XBProjector;
import org.xmlbeam.XBProjector.Flags;
import org.xmlbeam.config.DefaultXMLFactoriesConfig;

View File

@@ -57,19 +57,11 @@ import org.springframework.data.release.deployment.DeploymentProperties.MavenCen
import org.springframework.data.release.deployment.StagingRepository;
import org.springframework.data.release.io.Workspace;
import org.springframework.data.release.model.*;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.data.release.utils.Logger;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import org.xmlbeam.ProjectionFactory;
import org.xmlbeam.XBProjector;
@@ -98,7 +90,6 @@ class MavenBuildSystem implements BuildSystem {
Gpg gpg;
Environment env;
DeploymentProperties deploymentProperties;
RestTemplate restTemplate;
static final String REPO_OPENING_TAG = "<repository>";
static final String REPO_CLOSING_TAG = "</repository>";
@@ -106,7 +97,7 @@ class MavenBuildSystem implements BuildSystem {
@Override
public BuildSystem withJavaVersion(JavaVersion javaVersion) {
return new MavenBuildSystem(workspace, projectionFactory, logger, mvn.withJavaVersion(javaVersion), mavenProperties,
properties, gpg, env, deploymentProperties, restTemplate);
properties, gpg, env, deploymentProperties);
}
/*
@@ -458,7 +449,7 @@ class MavenBuildSystem implements BuildSystem {
}
if (process == MavenCentral.Publishing.PUBLISHER && stagingRepository.isFile()) {
publishRelease(train, stagingRepository);
publishRelease(stagingRepository);
return;
}
@@ -466,34 +457,14 @@ class MavenBuildSystem implements BuildSystem {
String.format("Cannot release train using %s and staging repository %s", process, stagingRepository));
}
private void publishRelease(Train train, StagingRepository stagingRepository) {
private void publishRelease(StagingRepository stagingRepository) {
File root = new File(mavenProperties.getLocalStaging(), stagingRepository.getId());
Assert.isTrue(root.exists(), "StagingRepository " + root + " does not exist");
logger.log(train, "Creating release bundle from %s…", stagingRepository);
try {
File releaseBundle = createReleaseBundle(root);
logger.log(train, "Release bundle created. About to upload release bundle …");
MavenCentral mavenCentral = deploymentProperties.getMavenCentral();
HttpBasicCredentials httpCredentials = mavenCentral.getAuthentication().getHttpCredentials();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
headers.add(HttpHeaders.AUTHORIZATION, "Bearer " + httpCredentials.encode());
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("bundle", releaseBundle);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
ResponseEntity<String> response = restTemplate.postForEntity(mavenCentral.getPublisherApi() + "publisher/upload",
requestEntity, String.class);
logger.log(train, "Bundle published with deployment Id %s", response.getBody());
} catch (IOException e) {
throw new RuntimeException(e);
}

View File

@@ -19,6 +19,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.release.deployment.DeploymentProperties.Authentication;
import org.springframework.data.release.model.Password;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.data.release.utils.HttpComponentsClientHttpRequestFactoryBuilder;
import org.springframework.data.release.utils.Logger;
import org.springframework.web.client.RestOperations;
@@ -49,7 +51,10 @@ class DeploymentConfiguration {
String uri = authentication.getServer().getUri();
if (authentication.hasCredentials()) {
builder = builder.withAuthentication(uri, authentication.getHttpCredentials());
HttpBasicCredentials credentials = new HttpBasicCredentials(authentication.getUsername(),
Password.of(authentication.getApiKey()));
builder = builder.withAuthentication(uri, credentials);
} else {
logger.warn("Infrastructure", "No credentials configured for repository %s!", uri);

View File

@@ -24,7 +24,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.release.model.Gpg;
import org.springframework.data.release.model.Password;
import org.springframework.data.release.model.SupportStatusAware;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.data.util.Streamable;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@@ -104,25 +103,17 @@ public class DeploymentProperties implements InitializingBean {
private Publishing process;
private Authentication authentication;
private Gpg gpg;
private String publisherApi = "https://central.sonatype.com/api/v1/";
public boolean hasGpgConfiguration() {
return gpg != null && gpg.isGpgAvailable();
}
public void validate() {
if (process == Publishing.OSSRH && !StringUtils.hasText(stagingProfileId)) {
if (!StringUtils.hasText(stagingProfileId)) {
throw new IllegalArgumentException("No staging profile Id for Maven Central");
}
if (process == Publishing.PUBLISHER && (authentication == null || !authentication.hasCredentials())) {
throw new IllegalArgumentException("No publisher authentication for Maven Central");
}
}
public enum Publishing {
@@ -146,10 +137,6 @@ public class DeploymentProperties implements InitializingBean {
return StringUtils.hasText(username) && password != null;
}
public HttpBasicCredentials getHttpCredentials() {
return new HttpBasicCredentials(username, password);
}
public void validate() {
if (!StringUtils.hasText(stagingRepository)) {

View File

@@ -29,16 +29,8 @@ import org.springframework.data.release.model.Password;
@Value
public class HttpBasicCredentials {
@NonNull String username;
@NonNull Password password;
public String encode() {
String header = username.concat(":").concat(password.toString());
byte[] encodedAuth = Base64.getEncoder().encode(header.getBytes(StandardCharsets.US_ASCII));
return new String(encodedAuth);
}
private final @NonNull String username;
private final @NonNull Password password;
/*
* (non-Javadoc)
@@ -46,6 +38,9 @@ public class HttpBasicCredentials {
*/
public String toString() {
return "Basic ".concat(encode());
String header = username.concat(":").concat(password.toString());
byte[] encodedAuth = Base64.getEncoder().encode(header.getBytes(StandardCharsets.US_ASCII));
return "Basic ".concat(new String(encodedAuth));
}
}