2
0
Fork 0
mirror of https://github.com/ethauvin/bld.git synced 2025-04-25 00:07:12 -07:00

Merge pull request #11 from ethauvin/main

Moderate Code Cleanup
This commit is contained in:
Geert Bevin 2023-10-01 13:55:12 -04:00 committed by GitHub
commit 4e64675bdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 72 additions and 95 deletions

View file

@ -1546,22 +1546,22 @@ public class BaseProject extends BuildExecutor {
var finger_print = new StringBuilder();
for (var repository : repositories()) {
finger_print.append(repository.toString());
finger_print.append("\n");
finger_print.append('\n');
}
for (var entry : dependencies().entrySet()) {
finger_print.append(entry.getKey());
finger_print.append("\n");
finger_print.append('\n');
if (entry.getValue() != null) {
for (var dependency : entry.getValue()) {
finger_print.append(dependency.toString());
finger_print.append("\n");
finger_print.append('\n');
}
}
}
finger_print.append(downloadSources());
finger_print.append("\n");
finger_print.append(downloadJavadoc());
finger_print.append("\n");
finger_print.append(downloadSources())
.append('\n')
.append(downloadJavadoc())
.append('\n');
try {
var digest = MessageDigest.getInstance("SHA-1");

View file

@ -399,7 +399,7 @@ public class BuildExecutor {
fuzzy_regexp.append(ch);
fuzzy_regexp.append("\\E.*");
}
fuzzy_regexp.append("$");
fuzzy_regexp.append('$');
var fuzzy_pattern = Pattern.compile(fuzzy_regexp.toString());
matches.addAll(buildCommands().keySet().stream()
.filter(c -> fuzzy_pattern.matcher(c.toLowerCase()).matches())

View file

@ -13,7 +13,6 @@ import java.util.List;
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
import static rife.bld.dependencies.Repository.SONATYPE_SNAPSHOTS;
import static rife.bld.dependencies.Scope.test;
/**
* Provides the dependency information required to create a new base project.

View file

@ -130,25 +130,25 @@ public record Dependency(String groupId, String artifactId, VersionNumber versio
*/
public String toFileName() {
var result = new StringBuilder(artifactId());
result.append("-").append(version());
result.append('-').append(version());
if (!classifier().isEmpty()) {
result.append("-").append(classifier());
result.append('-').append(classifier());
}
result.append(".").append(type());
result.append('.').append(type());
return result.toString();
}
public String toString() {
var result = new StringBuilder(groupId).append(":").append(artifactId);
var result = new StringBuilder(groupId).append(':').append(artifactId);
if (!version.equals(VersionNumber.UNKNOWN)) {
result.append(":").append(version);
result.append(':').append(version);
}
if (!classifier.isEmpty()) {
result.append(":").append(classifier);
result.append(':').append(classifier);
}
if (!type.isEmpty() && !type.equals("jar")) {
result.append("@").append(type);
if (!type.isEmpty() && !"jar".equals(type)) {
result.append('@').append(type);
}
return result.toString();
}

View file

@ -25,10 +25,10 @@ public record DependencyExclusion(String groupId, String artifactId) {
}
boolean matches(PomDependency dependency) {
return (groupId().equals("*") && artifactId().equals("*")) ||
(groupId().equals("*") && artifactId().equals(dependency.artifactId())) ||
(groupId().equals(dependency.groupId()) && artifactId().equals("*")) ||
(groupId().equals(dependency.groupId()) && artifactId().equals(dependency.artifactId()));
return ("*".equals(groupId()) && "*".equals(artifactId())) ||
("*".equals(groupId()) && artifactId().equals(dependency.artifactId())) ||
(groupId().equals(dependency.groupId()) && "*".equals(artifactId())) ||
(groupId().equals(dependency.groupId()) && dependency.artifactId().equals(artifactId()));
}
}

View file

@ -315,15 +315,15 @@ public class DependencyResolver {
return getArtifactLocations().stream().map(a -> {
var result = new StringBuilder();
result.append(version).append("/").append(dependency_.artifactId()).append("-").append(pom_version);
result.append(version).append('/').append(dependency_.artifactId()).append('-').append(pom_version);
if (!dependency_.classifier().isEmpty()) {
result.append("-").append(dependency_.classifier());
result.append('-').append(dependency_.classifier());
}
var type = dependency_.type();
if (type == null) {
type = "jar";
}
result.append(".").append(type);
result.append('.').append(type);
return a.appendPath(result.toString());
}).toList();

View file

@ -26,6 +26,7 @@ public record Repository(String location, String username, String password) {
public static final Repository GOOGLE = new Repository("https://maven.google.com/");
public static final Repository MAVEN_CENTRAL = new Repository("https://repo1.maven.org/maven2/");
public static final Repository SONATYPE_RELEASES = new Repository("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/");
public static final Repository SONATYPE_RELEASES_LEGACY = new Repository("https://oss.sonatype.org/service/local/staging/deploy/maven2/");
public static final Repository SONATYPE_SNAPSHOTS = new Repository("https://s01.oss.sonatype.org/content/repositories/snapshots/");
public static final Repository SONATYPE_SNAPSHOTS_LEGACY = new Repository("https://oss.sonatype.org/content/repositories/snapshots/");
public static final Repository APACHE = new Repository("https://repo.maven.apache.org/maven2/");
@ -83,9 +84,11 @@ public record Repository(String location, String username, String password) {
}
return switch (locationOrName) {
case "GOOGLE" -> Repository.GOOGLE;
case "MAVEN_LOCAL" -> Repository.MAVEN_LOCAL;
case "MAVEN_CENTRAL" -> Repository.MAVEN_CENTRAL;
case "SONATYPE_RELEASES" -> Repository.SONATYPE_RELEASES;
case "SONATYPE_RELEASES_LEGACY" -> Repository.SONATYPE_RELEASES_LEGACY;
case "SONATYPE_SNAPSHOTS" -> Repository.SONATYPE_SNAPSHOTS;
case "SONATYPE_SNAPSHOTS_LEGACY" -> Repository.SONATYPE_SNAPSHOTS_LEGACY;
case "APACHE" -> Repository.APACHE;
@ -191,11 +194,11 @@ public record Repository(String location, String username, String password) {
public String toString() {
var result = new StringBuilder(location);
if (username() != null) {
result.append(":");
result.append(':');
try {
result.append(StringEncryptor.MD5HLO.performEncryption(username(), null));
if (password() != null) {
result.append(":");
result.append(':');
result.append(StringEncryptor.MD5HLO.performEncryption(password(), null));
}
} catch (NoSuchAlgorithmException e) {

View file

@ -219,11 +219,11 @@ public record VersionNumber(Integer major, Integer minor, Integer revision, Stri
var version = new StringBuilder();
version.append(majorInt());
if (minor != null || revision != null) {
version.append(".");
version.append('.');
version.append(minorInt());
}
if (revision != null) {
version.append(".");
version.append('.');
version.append(revisionInt());
}
if (qualifier != null && !qualifier.isEmpty()) {

View file

@ -89,20 +89,19 @@ public class Xml2MavenMetadata extends Xml2Data implements MavenMetadata {
public void endDocument()
throws SAXException {
// determine latest stable version by removing pre-release qualifiers
var filtered_versions = new TreeSet<VersionNumber>();
filtered_versions.addAll(versions_.stream()
.filter(v -> {
if (v.qualifier() == null) return true;
var q = v.qualifier().toLowerCase();
return !q.startsWith("rc") &&
!q.startsWith("cr") &&
!q.contains("milestone") &&
!MILESTONE.matcher(q).matches() &&
!q.contains("beta") &&
!BETA.matcher(q).matches() &&
!q.contains("alpha") &&
!ALPHA.matcher(q).matches();
}).toList());
var filtered_versions = new TreeSet<>(versions_.stream()
.filter(v -> {
if (v.qualifier() == null) return true;
var q = v.qualifier().toLowerCase();
return !q.startsWith("rc") &&
!q.startsWith("cr") &&
!q.contains("milestone") &&
!MILESTONE.matcher(q).matches() &&
!q.contains("beta") &&
!BETA.matcher(q).matches() &&
!q.contains("alpha") &&
!ALPHA.matcher(q).matches();
}).toList());
// only replace the stable version from the metadata when
// something remained from the filtering, then use the

View file

@ -287,19 +287,19 @@ class Xml2MavenPom extends Xml2Data {
}
private boolean isChildOfProject() {
return elementStack_.peek().equals("project");
return "project".equals(elementStack_.peek());
}
private boolean isChildOfParent() {
return elementStack_.peek().equals("parent");
return "parent".equals(elementStack_.peek());
}
private boolean isChildOfDependency() {
return elementStack_.peek().equals("dependency");
return "dependency".equals(elementStack_.peek());
}
private boolean isChildOfExclusion() {
return elementStack_.peek().equals("exclusion");
return "exclusion".equals(elementStack_.peek());
}
private void addProjectProperty(String name) {

View file

@ -220,13 +220,17 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
for (var entry : project_.dependencies().entrySet()) {
build_template.blankValue("dependencies");
var version_string = new StringBuilder(0);
for (var dependency : entry.getValue()) {
build_template.setValue("groupId", dependency.groupId());
build_template.setValue("artifactId", dependency.artifactId());
var version = dependency.version();
var version_string = version.major() + "," + version.minor() + "," + version.revision();
version_string.setLength(0);
version_string.append(version.major()).append(',')
.append(version.minor()).append(',')
.append(version.revision());
if (!version.qualifier().isEmpty()) {
version_string += ",\"" + version.qualifier() + "\"";
version_string.append(",\"" ).append(version.qualifier()).append('"');
}
build_template.setValue("version", version_string);
build_template.appendBlock("dependencies", "dependency");
@ -364,10 +368,10 @@ public abstract class AbstractCreateOperation<T extends AbstractCreateOperation<
public T fromArguments(List<String> arguments) {
String package_name = null;
String project_name = null;
if (arguments.size() > 0) {
if (!arguments.isEmpty()) {
package_name = arguments.remove(0);
}
if (arguments.size() > 0) {
if (!arguments.isEmpty()) {
project_name = arguments.remove(0);
}
if ((package_name == null || project_name == null) && System.console() == null) {

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils;

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import rife.bld.Project;
import rife.bld.blueprints.BaseProjectBlueprint;
import rife.bld.blueprints.LibProjectBlueprint;
import java.io.File;

View file

@ -27,13 +27,13 @@ public class CreateOperation {
String type = null;
String package_name = null;
String project_name = null;
if (arguments.size() > 0) {
if (!arguments.isEmpty()) {
type = arguments.remove(0);
}
if (arguments.size() > 0) {
if (!arguments.isEmpty()) {
package_name = arguments.remove(0);
}
if (arguments.size() > 0) {
if (!arguments.isEmpty()) {
project_name = arguments.remove(0);
}
if ((type == null || package_name == null || project_name == null) && System.console() == null) {

View file

@ -34,7 +34,7 @@ public class JUnitOperation extends TestOperation<JUnitOperation, JUnitOptions>
}
// add the default JUnit options if none were specified
if (testToolOptions().isEmpty() && mainClass().equals(DEFAULT_TEST_TOOL_JUNIT5)) {
if (testToolOptions().isEmpty() && DEFAULT_TEST_TOOL_JUNIT5.equals(mainClass())) {
testToolOptions().defaultOptions();
}
@ -45,9 +45,9 @@ public class JUnitOperation extends TestOperation<JUnitOperation, JUnitOptions>
var argument = arguments.get(0);
if (argument.startsWith("-")) {
arguments.remove(0);
if (argument.equals("--junit-help")) {
if ("--junit-help".equals(argument)) {
testToolOptions().add("--help");
} else if (argument.equals("--junit-clear")) {
} else if ("--junit-clear".equals(argument)) {
testToolOptions().clear();
} else {
testToolOptions().add(argument);

View file

@ -6,7 +6,6 @@ package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.NamedFile;
import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.StringUtils;
@ -95,6 +94,7 @@ public class JarOperation extends AbstractOperation<JarOperation> {
// don't use putAll since Attributes does an instanceof check
// on the map being passed in, causing it to fail if it's not
// and instance of Attributes
//noinspection UseBulkOperation
attributes.put(entry.getKey(), entry.getValue());
// ^^^ READ above, don't use putAll
}

View file

@ -8,7 +8,6 @@ import rife.tools.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils;
import rife.tools.StringUtils;

View file

@ -165,15 +165,15 @@ public class PublishOperation extends AbstractOperation<PublishOperation> {
protected void executePublishArtifacts(Repository repository, VersionNumber actualVersion) {
// upload artifacts
for (var artifact : artifacts()) {
var artifact_name = new StringBuilder(info().artifactId()).append("-").append(actualVersion);
var artifact_name = new StringBuilder(info().artifactId()).append('-').append(actualVersion);
if (!artifact.classifier().isEmpty()) {
artifact_name.append("-").append(artifact.classifier());
artifact_name.append('-').append(artifact.classifier());
}
var type = artifact.type();
if (type == null) {
type = "jar";
}
artifact_name.append(".").append(type);
artifact_name.append('.').append(type);
executePublishFileArtifact(repository, artifact.file(), info().version() + "/" + artifact_name);
}

View file

@ -5,12 +5,10 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.tools.FileUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* Tests a Java application.

View file

@ -6,7 +6,6 @@ package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.NamedFile;
import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.dependencies.*;
import java.util.ArrayList;

View file

@ -4,8 +4,6 @@
*/
package rife.bld.operations.exceptions;
import rife.tools.HttpUtils;
import java.io.File;
import java.io.Serial;

View file

@ -151,7 +151,7 @@ public class PomBuilder {
t.blankValue("dependency-type");
t.blankValue("dependency-type-tag");
if (!dependency.type().equals("jar")) {
if (!"jar".equals(dependency.type())) {
t.setValueEncoded("dependency-type", dependency.type());
t.setBlock("dependency-type-tag");
}

View file

@ -364,7 +364,7 @@ public class Wrapper {
var location = getWrapperDownloadLocation(version);
var result = new StringBuilder(location);
if (!location.endsWith("/")) {
result.append("/");
result.append('/');
}
result.append(fileName);
return result.toString();
@ -496,7 +496,7 @@ public class Wrapper {
private int launchMain(File jarFile, List<String> arguments)
throws IOException, InterruptedException, FileUtilsErrorException {
if (arguments.isEmpty() || !arguments.get(0).equals("--build")) {
if (arguments.isEmpty() || !"--build".equals(arguments.get(0))) {
return launchMainCli(jarFile, arguments);
}
return launchMainBuild(jarFile, arguments);

View file

@ -134,7 +134,7 @@ public class WrapperExtensionResolver {
contents.append(fingerPrintHash_);
for (var file : localArtifacts_) {
if (file.exists() && file.canRead()) {
contents.append("\n").append(file.lastModified()).append(":").append(file.getAbsolutePath());
contents.append("\n").append(file.lastModified()).append(':').append(file.getAbsolutePath());
}
}

View file

@ -11,7 +11,6 @@ import rife.tools.FileUtils;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;

View file

@ -5,16 +5,9 @@
package rife.bld.operations;
import org.junit.jupiter.api.Test;
import rife.bld.dependencies.LocalDependency;
import rife.bld.dependencies.Scope;
import rife.bld.operations.exceptions.ExitStatusException;
import rife.tools.FileUtils;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.*;

View file

@ -5,14 +5,9 @@
package rife.bld.operations;
import org.junit.jupiter.api.Test;
import rife.bld.dependencies.LocalDependency;
import rife.bld.dependencies.Scope;
import rife.tools.FileUtils;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.*;

View file

@ -14,7 +14,6 @@ import java.util.List;
import java.util.function.Function;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertNull;
public class TestJUnitOperation {
@Test

View file

@ -161,7 +161,7 @@ public class TestJarOperation {
while (e.hasMoreElements()) {
var jar_entry = e.nextElement();
content.append(jar_entry.getName());
content.append("\n");
content.append('\n');
}
}
@ -203,7 +203,7 @@ public class TestJarOperation {
while (e.hasMoreElements()) {
var jar_entry = e.nextElement();
content.append(jar_entry.getName());
content.append("\n");
content.append('\n');
}
}

View file

@ -19,7 +19,6 @@ import java.util.concurrent.TimeUnit;
import java.util.jar.JarFile;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestUberJarOperation {
@Test

View file

@ -5,7 +5,6 @@
package rife.bld.operations;
import org.junit.jupiter.api.Test;
import rife.bld.dependencies.DependencyScopes;
import rife.bld.WebProject;
import rife.bld.dependencies.*;
import rife.tools.FileUtils;

View file

@ -15,7 +15,6 @@ import java.util.jar.JarFile;
import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestWarOperation {
@Test
@ -138,7 +137,7 @@ public class TestWarOperation {
while (e.hasMoreElements()) {
var jar_entry = e.nextElement();
content.append(jar_entry.getName());
content.append("\n");
content.append('\n');
}
}