Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous code cleanup #30

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public BatchCommandInstaller(String label, String command, String toolHome, bool
private static String fixCrLf(String s) {
// eliminate CR
int idx;
while((idx=s.indexOf("\r\n"))!=-1)
s = s.substring(0,idx)+s.substring(idx+1);
while ((idx = s.indexOf("\r\n")) != -1) {
s = s.substring(0, idx) + s.substring(idx + 1);
}
return s;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ private EnvStringParseHelper() {}
* @since 0.3
*/
public static String substituteEnvVars(String macroString, EnvVars environment) {
if (macroString == null) return null;
if (macroString == null) {
return null;
}
if (!macroString.contains("${")) {
return macroString;
}
Expand All @@ -57,7 +59,9 @@ public static String substituteEnvVars(String macroString, EnvVars environment)
*/
@Nullable
public static String substituteNodeVariables(@CheckForNull String macroString, @NonNull Node node) {
if (macroString == null) return null;
if (macroString == null) {
return null;
}
if (!macroString.contains("${")) {
return macroString;
}
Expand All @@ -69,7 +73,7 @@ public static String substituteNodeVariables(@CheckForNull String macroString, @
}

// Substitute global variables
final Jenkins jenkinsInstance = Jenkins.getInstance();
final Jenkins jenkinsInstance = Jenkins.get();
for (NodeProperty<?> entry : jenkinsInstance.getGlobalNodeProperties()) {
substitutedString = substituteNodeProperty(substitutedString, entry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AuthenticatedDownloadCallable extends MasterToSlaveFileCallable<Date> {
this.logOrNull = logOrNull;
}

@Override
public Date invoke(@NonNull File d, VirtualChannel channel) throws IOException, InterruptedException {
final FilePath whereToDownloadTo = new FilePath(d);
return downloadAndUnpack(uri, usernameOrNull, passwordOrNull, timestampOfLocalContents, nodeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.URI;
Expand Down Expand Up @@ -285,7 +286,7 @@ protected Date downloadOnRemoteNode(@NonNull final URI uri, @CheckForNull final
private static @CheckForNull StandardCredentials getCredentialsOrNull(@NonNull final String credentialsId,
@CheckForNull final String urlHostOrNullOrEmpty) {
final List<DomainRequirement> forOurUrl = getDomainRequirements(urlHostOrNullOrEmpty);
final ItemGroup<?> allOfJenkins = Jenkins.getInstance();
final ItemGroup<?> allOfJenkins = Jenkins.getInstanceOrNull();
final CredentialsMatcher onlyOurCredentials = CredentialsMatchers.allOf(CREDENTIAL_TYPES_WE_CAN_HANDLE,
CredentialsMatchers.withId(credentialsId));
final List<StandardCredentials> allJenkinsCredentialsForOurUrl = CredentialsProvider
Expand Down Expand Up @@ -328,19 +329,21 @@ protected Date downloadOnRemoteNode(@NonNull final URI uri, @CheckForNull final
private static @NonNull List<DomainRequirement> getDomainRequirements(
@CheckForNull final String urlHostOrNullOrEmpty) {
if (Util.fixEmpty(urlHostOrNullOrEmpty) != null) {
return Collections.<DomainRequirement>singletonList(new HostnameRequirement(urlHostOrNullOrEmpty));
return Collections.singletonList(new HostnameRequirement(urlHostOrNullOrEmpty));
} else {
return Collections.<DomainRequirement>emptyList();
return Collections.emptyList();
}
}

/** Copy of hudson.tools.ZipExtractionInstaller.ChmodRecAPlusX */
static class ChmodRecAPlusX extends MasterToSlaveFileCallable<Void> {
private static final long serialVersionUID = 1L;

@Override
public Void invoke(File d, VirtualChannel channel) throws IOException {
if (!Functions.isWindows())
if (!Functions.isWindows()) {
process(d);
}
return null;
}

Expand All @@ -363,11 +366,13 @@ private void process(File f) {
*/
@Extension @Symbol("authenticatedzip")
public static class DescriptorImpl extends ToolInstallerDescriptor<AuthenticatedZipExtractionInstaller> {
@Override
public String getDisplayName() {
return Messages.AuthenticatedZipExtractionInstaller_DescriptorImpl_displayName();
}

/* List credentials that can be used on the specified URL */
@SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "TODO needs triage")
public ListBoxModel doFillCredentialsIdItems(@QueryParameter String credentialsId, @QueryParameter String url) {
/*
* System.out.println("doFillCredentialsIdItems(" + item + "," +
Expand All @@ -391,7 +396,7 @@ public ListBoxModel doFillCredentialsIdItems(@QueryParameter String credentialsI
// suppress exception as url is validated elsewhere
}
/* System.out.println(" urlHost = " + urlHost); */
final ItemGroup<?> allOfJenkins = Jenkins.getInstance();
final ItemGroup<?> allOfJenkins = Jenkins.getInstanceOrNull();
final List<DomainRequirement> domainRequirements = getDomainRequirements(urlHostOrNullOrEmpty);
result.includeMatchingAs(ACL.SYSTEM, allOfJenkins, StandardCredentials.class, domainRequirements,
CREDENTIAL_TYPES_WE_CAN_HANDLE);
Expand Down Expand Up @@ -454,7 +459,7 @@ public FormValidation doCheckUrl(@QueryParameter String credentialsId, @QueryPar
*/
private static @NonNull FormValidation checkUrlAndCredentialsId(final boolean checkUrl,
@CheckForNull final String credentialsIdOrNull, @CheckForNull final String urlOrNull) {
if (!(hasPermissionToConfigure())) {
if (!hasPermissionToConfigure()) {
/*
* System.out.println(
* "checkUrlAndCredentialsId: NOT hasPermissionToConfigure");
Expand Down Expand Up @@ -558,7 +563,7 @@ public FormValidation doCheckUrl(@QueryParameter String credentialsId, @QueryPar
}

private static boolean hasPermissionToConfigure() {
return Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER);
return Jenkins.get().hasPermission(Jenkins.ADMINISTER);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FindOnPathCallable extends MasterToSlaveFileCallable<String> {
this.logOrNull = logOrNull;
}

@Override
public String invoke(@NonNull File d, VirtualChannel channel) throws IOException, InterruptedException {
return findOnPath(executableName, getPath(), logOrNull);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;

import com.google.common.base.Joiner;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
Expand Down Expand Up @@ -132,7 +130,7 @@ public String getVersionCmdString() {
if (v == null) {
return "";
}
return Joiner.on('\n').join(v);
return String.join("\n", v);
}

/**
Expand Down Expand Up @@ -337,6 +335,7 @@ FindOnPathCallable mkCallable(@NonNull final String exeName, @CheckForNull final
@Extension
@Symbol("findonpath")
public static class DescriptorImpl extends ToolInstallerDescriptor<IsAlreadyOnPath> {
@Override
public String getDisplayName() {
return Messages.IsAlreadyOnPath_DescriptorImpl_displayName();
}
Expand Down