Skip to content

Commit

Permalink
Merge pull request #11 from ethauvin/main
Browse files Browse the repository at this point in the history
Moderate Code Cleanup
  • Loading branch information
gbevin authored Oct 1, 2023
2 parents e7c7144 + 7ceb6e3 commit 4e64675
Show file tree
Hide file tree
Showing 35 changed files with 72 additions and 95 deletions.
14 changes: 7 additions & 7 deletions src/main/java/rife/bld/BaseProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -1546,22 +1546,22 @@ private String createHash() {
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");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/BuildExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ public boolean executeCommand(String command)
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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

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.
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/rife/bld/dependencies/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,25 @@ public Dependency withClassifier(String classifier) {
*/
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();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/rife/bld/dependencies/DependencyExclusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public int hashCode() {
}

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()));

}
}
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/dependencies/DependencyResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,15 +315,15 @@ private List<RepositoryArtifact> getTransferArtifacts() {

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();
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/rife/bld/dependencies/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
Expand Down Expand Up @@ -83,9 +84,11 @@ public static Repository resolveRepository(HierarchicalProperties properties, St
}

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;
Expand Down Expand Up @@ -191,11 +194,11 @@ public String getMetadataName() {
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/rife/bld/dependencies/VersionNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,11 @@ public String toString() {
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()) {
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/rife/bld/dependencies/Xml2MavenMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,19 @@ public void endElement(String uri, String localName, String qName) {
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
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/rife/bld/dependencies/Xml2MavenPom.java
Original file line number Diff line number Diff line change
Expand Up @@ -287,19 +287,19 @@ public void endElement(String uri, String localName, String qName) {
}

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) {
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/rife/bld/operations/AbstractCreateOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,17 @@ protected void executePopulateProjectStructure()
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");
Expand Down Expand Up @@ -364,10 +368,10 @@ protected void executeDownloadDependencies() {
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) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/CleanOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/CompileOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/CreateLibOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/operations/CreateOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/operations/JUnitOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public JUnitOperation fromProject(BaseProject project) {
}

// 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();
}

Expand All @@ -45,9 +45,9 @@ public JUnitOperation fromProject(BaseProject project) {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/rife/bld/operations/JarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import rife.bld.BaseProject;
import rife.bld.NamedFile;
import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.StringUtils;

Expand Down Expand Up @@ -95,6 +94,7 @@ protected Manifest executeCreateManifest() {
// 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
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/JavaOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/JavadocOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/rife/bld/operations/PublishOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@ protected VersionNumber executePublishSnapshotMetadata(Repository repository, Zo
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);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/rife/bld/operations/TestOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/UberJarOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import rife.bld.BaseProject;
import rife.bld.NamedFile;
import rife.bld.Project;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/rife/bld/operations/UpdatesOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package rife.bld.operations;

import rife.bld.BaseProject;
import rife.bld.Project;
import rife.bld.dependencies.*;

import java.util.ArrayList;
Expand Down
Loading

0 comments on commit 4e64675

Please sign in to comment.