Skip to content

Commit

Permalink
Remove usages of StringUtils (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Feb 11, 2022
1 parent eab9593 commit 5654ce4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jenkinsci.maven.plugins.hpi;

import hudson.util.VersionNumber;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -85,7 +84,7 @@ protected String findJenkinsVersion() throws MojoExecutionException {
&& (a.getArtifactId().equals("jenkins-core") || a.getArtifactId().equals("hudson-core"));

if (match) {
if (StringUtils.isNotBlank(jenkinsCoreVersionOverride)) {
if (jenkinsCoreVersionOverride != null && !jenkinsCoreVersionOverride.trim().isEmpty()) {
VersionNumber v1 = new VersionNumber(a.getVersion());
VersionNumber v2 = new VersionNumber(jenkinsCoreVersionOverride);
if (v1.compareTo(v2) == -1) {
Expand All @@ -98,7 +97,7 @@ protected String findJenkinsVersion() throws MojoExecutionException {
return a.getVersion();
}
}
if (StringUtils.isNotBlank(jenkinsCoreVersionOverride)) {
if (jenkinsCoreVersionOverride != null && !jenkinsCoreVersionOverride.trim().isEmpty()) {
return jenkinsCoreVersionOverride;
}
throw new MojoExecutionException("Failed to determine Jenkins version this plugin depends on.");
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/HpiMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.File;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
import java.util.Objects;
import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.Artifact;
Expand Down Expand Up @@ -109,16 +109,16 @@ private void performPackaging()
Manifest manifest = loadManifest(manifestFile);

getLog().info("Checking for attached .jar artifact "
+ (StringUtils.isBlank(jarClassifier) ? "..." : "with classifier " + jarClassifier + "..."));
+ (jarClassifier == null || jarClassifier.trim().isEmpty() ? "..." : "with classifier " + jarClassifier + "..."));
File jarFile = null;
for (Artifact artifact: project.getAttachedArtifacts()) {
if (StringUtils.equals(project.getGroupId(), artifact.getGroupId())
&& StringUtils.equals(project.getArtifactId(), artifact.getArtifactId())
if (Objects.equals(project.getGroupId(), artifact.getGroupId())
&& Objects.equals(project.getArtifactId(), artifact.getArtifactId())
&& project.getArtifact().getVersionRange().equals(artifact.getVersionRange())
&& StringUtils.equals("jar", artifact.getType())
&& (StringUtils.isBlank(jarClassifier)
&& Objects.equals("jar", artifact.getType())
&& (jarClassifier == null || jarClassifier.trim().isEmpty()
? !artifact.hasClassifier()
: StringUtils.equals(jarClassifier, artifact.getClassifier()))
: Objects.equals(jarClassifier, artifact.getClassifier()))
&& artifact.getFile() != null && artifact.getFile().isFile()) {
jarFile = artifact.getFile();
getLog().info("Found attached .jar artifact: " + jarFile.getAbsolutePath());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/HplMojo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.maven.plugins.hpi;

import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
import org.apache.maven.model.Resource;
Expand Down Expand Up @@ -93,7 +92,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {

buildLibraries(paths);

mainSection.addAttributeAndCheck(new Attribute("Libraries", StringUtils.join(paths, ",")));
mainSection.addAttributeAndCheck(new Attribute("Libraries", String.join(",", paths)));

// compute Resource-Path entry
if (webappDirectory != null && webappDirectory.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jenkinsci.maven.plugins.hpi;

import hudson.util.VersionNumber;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.repository.ArtifactRepository;
Expand Down Expand Up @@ -242,7 +241,7 @@ private String getResolvedType() throws IOException {
return type;
}
// also ignore core-assets, tests, etc.
if (!StringUtils.isEmpty(artifact.getClassifier())) {
if (artifact.getClassifier() != null && !artifact.getClassifier().isEmpty()) {
return type;
}

Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/jenkinsci/maven/plugins/hpi/RunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import hudson.util.VersionNumber;
import io.jenkins.lib.support_log_formatter.SupportLogFormatter;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
Expand Down Expand Up @@ -769,12 +768,12 @@ private boolean isPostJava8() {

@Override
public void startJetty() throws MojoExecutionException {
if (httpConnector == null && (defaultPort != 0 || StringUtils.isNotEmpty(defaultHost))) {
if (httpConnector == null && (defaultPort != 0 || (defaultHost != null && !defaultHost.isEmpty()))) {
httpConnector = new MavenServerConnector();
if (defaultPort != 0) {
httpConnector.setPort(defaultPort);
}
if (StringUtils.isNotEmpty(defaultHost)) {
if (defaultHost != null && !defaultHost.isEmpty()) {
httpConnector.setHost(defaultHost);
}
String browserHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.sun.codemodel.writer.FilterCodeWriter;
import groovy.lang.Closure;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -114,7 +113,8 @@ private void walk(File dir,JPackage pkg,String dirName) throws JClassAlreadyExis
}

if (isTagLibDir(dir)) {
JDefinedClass c = pkg.parent()._interface(StringUtils.capitalize(h2j(dir.getName())) + "TagLib");
String taglib = h2j(dir.getName());
JDefinedClass c = pkg.parent()._interface(taglib.substring(0, 1).toUpperCase() + taglib.substring(1) + "TagLib");
c._implements(TypedTagLibrary.class);
c.annotate(TagLibraryUri.class).param("value",dirName);

Expand Down

0 comments on commit 5654ce4

Please sign in to comment.