From f22cf908cb697cefed8e32b4bfe54f8063a16a9d Mon Sep 17 00:00:00 2001 From: Tim Jacomb <21194782+timja@users.noreply.github.com> Date: Fri, 2 Apr 2021 15:58:16 +0100 Subject: [PATCH] Sort regions and update azure-commons (#261) --- pom.xml | 2 +- .../azure/vmagent/AzureVMAgentTemplate.java | 4 +++- .../microsoft/azure/vmagent/AzureVMCloud.java | 5 ++--- .../azure/vmagent/util/AzureClientUtil.java | 17 ++++------------- 4 files changed, 10 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 86e16b9f..6e32358c 100644 --- a/pom.xml +++ b/pom.xml @@ -56,7 +56,7 @@ findbugs-exclude.xml true 1.6.1 - 1.1.0 + 1.1.2 24.1.1-jre diff --git a/src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java b/src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java index edc40125..639295d8 100644 --- a/src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java +++ b/src/main/java/com/microsoft/azure/vmagent/AzureVMAgentTemplate.java @@ -75,6 +75,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; @@ -1309,7 +1310,8 @@ public ListBoxModel doFillLocationItems(@RelativePath("..") @QueryParameter Stri Set locations = AzureClientHolder.getDelegate(azureCredentialsId) .getVirtualMachineLocations(managementEndpoint != null ? managementEndpoint : envName); if (locations != null) { - for (String location : locations) { + Set sortedLocations = new TreeSet<>(locations); + for (String location : sortedLocations) { model.add(location); } } diff --git a/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java b/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java index 689dc748..4af307e8 100644 --- a/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java +++ b/src/main/java/com/microsoft/azure/vmagent/AzureVMCloud.java @@ -1115,7 +1115,7 @@ public FormValidation doVerifyConfiguration( @QueryParameter String resourceGroupReferenceType, @QueryParameter String newResourceGroupName, @QueryParameter String existingResourceGroupName) { - Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); + Jenkins.get().checkPermission(Jenkins.ADMINISTER); String resourceGroupName = getResourceGroupName( resourceGroupReferenceType, newResourceGroupName, existingResourceGroupName); @@ -1166,9 +1166,8 @@ public ListBoxModel doFillExistingResourceGroupNameItems(@QueryParameter String } } catch (Exception e) { LOGGER.log(Level.WARNING, "Cannot list resource group name: ", e); - } finally { - return model; } + return model; } } } diff --git a/src/main/java/com/microsoft/azure/vmagent/util/AzureClientUtil.java b/src/main/java/com/microsoft/azure/vmagent/util/AzureClientUtil.java index 42ba443d..27c4e869 100644 --- a/src/main/java/com/microsoft/azure/vmagent/util/AzureClientUtil.java +++ b/src/main/java/com/microsoft/azure/vmagent/util/AzureClientUtil.java @@ -24,12 +24,8 @@ import com.microsoft.jenkins.azurecommons.core.credentials.TokenCredentialData; import org.apache.commons.lang.StringUtils; -import java.util.logging.Logger; - public final class AzureClientUtil { - private static final Logger LOGGER = Logger.getLogger(AzureClientUtil.class.getName()); - public static TokenCredentialData getToken(String credentialId) { AzureBaseCredentials credential = AzureCredentialUtil.getCredential2(credentialId); if (credential == null) { @@ -56,15 +52,10 @@ public static Azure getClient(String credentialId, String subscriptionId) throws } public static Azure getClient(TokenCredentialData token) { - return AzureClientFactory.getClient(token, new AzureClientFactory.Configurer() { - @Override - public Azure.Configurable configure(Azure.Configurable configurable) { - return configurable - .withInterceptor(new AzureVMAgentPlugin.AzureTelemetryInterceptor()) - .withUserAgent(AzureClientFactory.getUserAgent(Constants.PLUGIN_NAME, - AzureClientUtil.class.getPackage().getImplementationVersion())); - } - }); + return AzureClientFactory.getClient(token, configurable -> configurable + .withInterceptor(new AzureVMAgentPlugin.AzureTelemetryInterceptor()) + .withUserAgent(AzureClientFactory.getUserAgent(Constants.PLUGIN_NAME, + AzureClientUtil.class.getPackage().getImplementationVersion()))); } private AzureClientUtil() {