#133 - Polishing.

Use Commons IO IOUtils for OS-specific line separator instead of Spring Shell. Remove Credentials in favor of HttpBasicCredentials.
This commit is contained in:
Mark Paluch
2019-11-20 14:18:51 +01:00
parent d44614b50e
commit de03b62ee1
6 changed files with 23 additions and 51 deletions

View File

@@ -15,12 +15,13 @@
*/
package org.springframework.data.release.cli;
import org.apache.commons.io.IOUtils;
import org.springframework.boot.SpringBootVersion;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.shell.plugin.BannerProvider;
import org.springframework.shell.support.util.FileUtils;
import org.springframework.shell.support.util.OsUtils;
import org.springframework.stereotype.Component;
@Order(Ordered.HIGHEST_PRECEDENCE)
@@ -46,8 +47,8 @@ class SpringDataReleaseCliBannerProvider implements BannerProvider {
StringBuilder builder = new StringBuilder();
builder.append(FileUtils.readBanner(SpringDataReleaseCliBannerProvider.class, "banner.txt"));
builder.append(getVersion()).append(OsUtils.LINE_SEPARATOR);
builder.append(OsUtils.LINE_SEPARATOR);
builder.append(getVersion()).append(IOUtils.LINE_SEPARATOR);
builder.append(IOUtils.LINE_SEPARATOR);
return builder.toString();
}

View File

@@ -21,10 +21,11 @@ import lombok.RequiredArgsConstructor;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.springframework.data.release.model.ArtifactVersion;
import org.springframework.data.release.model.ModuleIteration;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.shell.support.util.OsUtils;
/**
* @author Oliver Gierke
@@ -36,7 +37,7 @@ public class Changelog {
private final ModuleIteration module;
private final Tickets tickets;
/*
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@@ -48,13 +49,13 @@ public class Changelog {
String headline = String.format("Changes in version %s (%s)", version,
new DateFormatter("YYYY-MM-dd").print(new Date(), Locale.US));
StringBuilder builder = new StringBuilder(headline).append(OsUtils.LINE_SEPARATOR);
StringBuilder builder = new StringBuilder(headline).append(IOUtils.LINE_SEPARATOR);
for (int i = 0; i < headline.length(); i++) {
builder.append("-");
}
builder.append(OsUtils.LINE_SEPARATOR);
builder.append(IOUtils.LINE_SEPARATOR);
for (Ticket ticket : tickets) {
@@ -66,7 +67,7 @@ public class Changelog {
builder.append(".");
}
builder.append(OsUtils.LINE_SEPARATOR);
builder.append(IOUtils.LINE_SEPARATOR);
}
return builder.toString();

View File

@@ -1,33 +0,0 @@
/*
* Copyright 2014-2016 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 org.springframework.data.release.issues.jira;
import lombok.Value;
import javax.xml.bind.DatatypeConverter;
/**
* @author Oliver Gierke
*/
@Value
class Credentials {
String username, password;
public String asBase64() {
return DatatypeConverter.printBase64Binary(String.format("%s:%s", username, password).getBytes());
}
}

View File

@@ -702,7 +702,7 @@ class Jira implements JiraConnector {
private HttpHeaders newUserScopedHttpHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", String.format("Basic %s", jiraProperties.getCredentials().asBase64()));
headers.set("Authorization", jiraProperties.getCredentials().toString());
return headers;
}

View File

@@ -23,6 +23,8 @@ import lombok.Getter;
import javax.annotation.PostConstruct;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.release.model.Password;
import org.springframework.data.release.utils.HttpBasicCredentials;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
@@ -36,23 +38,23 @@ import org.springframework.util.Assert;
@ConfigurationProperties(prefix = "jira")
class JiraProperties {
private @Getter(AccessLevel.PRIVATE) String password;
private @Getter(AccessLevel.PRIVATE) Password password;
private String username, apiUrl;
@PostConstruct
public void init() {
Assert.hasText(username, "No Jira username (jira.username) configured!");
Assert.hasText(password, "No Jira password (jira.password) configured!");
Assert.notNull(password, "No Jira password (jira.password) configured!");
Assert.hasText(apiUrl, "No Jira url (jira.api-url) configured!");
}
/**
* Returns the {@link Credentials} to be used.
* Returns the {@link HttpBasicCredentials} to be used.
*
* @return
*/
public Credentials getCredentials() {
return new Credentials(username, password);
public HttpBasicCredentials getCredentials() {
return new HttpBasicCredentials(username, password);
}
}

View File

@@ -33,8 +33,9 @@ import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
import org.springframework.data.release.Streamable;
import org.springframework.shell.support.util.OsUtils;
import org.springframework.util.Assert;
/**
@@ -165,12 +166,12 @@ public class Train implements Streamable<Module> {
StringBuilder builder = new StringBuilder();
builder.append(name).//
append(OsUtils.LINE_SEPARATOR).//
append(OsUtils.LINE_SEPARATOR);
append(IOUtils.LINE_SEPARATOR).//
append(IOUtils.LINE_SEPARATOR);
builder.append(modules.stream().//
map(Module::toString).//
collect(Collectors.joining(OsUtils.LINE_SEPARATOR)));
collect(Collectors.joining(IOUtils.LINE_SEPARATOR)));
return builder.toString();
}