Skip to content

Commit

Permalink
Adding automated release and fixing spotbugs issues
Browse files Browse the repository at this point in the history
  • Loading branch information
coreydaley committed May 8, 2023
1 parent 9e60555 commit 466cb81
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 33 deletions.
10 changes: 10 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
See the documentation for more options:
https://github.com/jenkins-infra/pipeline-library/
*/
buildPlugin(
useContainerAgent: true,
configurations: [
[platform: 'linux', jdk: 11],
[platform: 'windows', jdk: 11],
])
9 changes: 4 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<revision>1.1.0</revision>
<changelist>999999-SNAPSHOT</changelist>
<jenkins.version>2.387.2</jenkins.version>
<java.level>11</java.level>
<log.level>INFO</log.level>
</properties>

Expand All @@ -40,9 +39,9 @@

<scm>
<connection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
<developerConnection>scm:git:https://github.com/jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin/</url>
<tag>${scmTag}</tag>
</scm>

<repositories>
Expand Down Expand Up @@ -153,7 +152,7 @@
<goal>generate</goal>
</goals>
<configuration>
<fileMask>Messages.properties</fileMask>
<fileMask>FileLocations.properties</fileMask>
<outputDirectory>target/generated-sources/localizer</outputDirectory>
</configuration>
</execution>
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/openshift/jenkins/plugins/OpenShift.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ public class OpenShift extends AbstractDescribableImpl<OpenShift> {

@Extension
public static class DescriptorImpl extends Descriptor<OpenShift> {

// Store a config version so we're able to migrate config.
public Long configVersion;

public List<ClusterConfig> clusterConfigs;

public String ocTool = "oc"; // TODO: Make this configurable for
// kubectl?

public DescriptorImpl() {
configVersion = 1L;
load();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,14 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.*;

import static com.openshift.jenkins.plugins.util.ClientCommandOutputCleaner.redactSensitiveData;

public abstract class BaseStep extends Builder {

public static final String DEFAULT_LOGLEVEL = "0";

public static final String SERVICE_ACCOUNT_NAMESPACE_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/namespace";
public static final String SERVICE_ACCOUNT_TOKEN_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/token";
public static final String SERVICE_ACCOUNT_CA_PATH = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt";

private String clusterName;

private String project;
Expand Down Expand Up @@ -147,6 +140,8 @@ protected boolean runOcCommand(final AbstractBuild build,

ArrayList<String> advArgs = new ArrayList<String>();

ResourceBundle bundle = ResourceBundle.getBundle("io.fabric8.jenkins.plugins.FileLocations");

if (advancedArguments != null) {
for (AdvancedArgument advArg : advancedArguments) {
advArgs.add(advArg.getValue(overrides));
Expand All @@ -156,6 +151,7 @@ protected boolean runOcCommand(final AbstractBuild build,
if (c == null) { // if null, we assume the cluster is running the
// Jenkins node.
server = ClusterConfig.getHostClusterApiServerUrl();
String SERVICE_ACCOUNT_CA_PATH = bundle.getString("SERVICE_ACCOUNT_CA_PATH");
selectedCAPath = SERVICE_ACCOUNT_CA_PATH;
caContent = null;
} else {
Expand All @@ -178,6 +174,7 @@ protected boolean runOcCommand(final AbstractBuild build,
+ getClusterName(overrides));
}
} else {
String SERVICE_ACCOUNT_NAMESPACE_PATH = bundle.getString("SERVICE_ACCOUNT_NAMESPACE_PATH");
project = new String(Files.readAllBytes(Paths
.get(SERVICE_ACCOUNT_NAMESPACE_PATH)),
StandardCharsets.UTF_8);
Expand Down Expand Up @@ -213,6 +210,7 @@ protected boolean runOcCommand(final AbstractBuild build,
}
token = tokenSecret.getToken();
} else {
String SERVICE_ACCOUNT_TOKEN_PATH = bundle.getString("SERVICE_ACCOUNT_TOKEN_PATH");
// We are running within a host cluster, so use mounted secret
token = new String(Files.readAllBytes(Paths
.get(SERVICE_ACCOUNT_TOKEN_PATH)), StandardCharsets.UTF_8);
Expand Down Expand Up @@ -261,7 +259,7 @@ public boolean perform(ProcessBuilder pb)
@Override
public void run() {
StringBuffer sb = new StringBuffer();
try (Reader reader = new InputStreamReader(output)) {
try (Reader reader = new InputStreamReader(output, StandardCharsets.UTF_8)) {
LineIterator it = IOUtils.lineIterator(reader);
while (it.hasNext()) {
String line = it.nextLine();
Expand Down Expand Up @@ -348,7 +346,7 @@ public static String getOverride(String key, Map<String, String> overrides) {
// try override when the key is the entire parameter ... we don't just
// use
// replaceMacro cause we also support PARM with $ or ${}
if (overrides != null && overrides.containsKey(val)) {
if (overrides.containsKey(val)) {
val = overrides.get(val);
} else {
// see if it is a mix used key (i.e. myapp-${VERSION}) or ${val}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void printToConsole(String line) {

@Override
protected OcActionResult run() throws IOException, InterruptedException, ExecutionException {
if (filePath != null && !filePath.exists()) {
if (!filePath.exists()) {
filePath.mkdirs();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static final class Execution extends AbstractSynchronousNonBlockingStepEx
private transient TaskListener listener;

public Void run() throws IOException, InterruptedException {
if (filePath != null && !filePath.exists()) {
if (!filePath.exists()) {
filePath.mkdirs();
}
getContext().saveState();
Expand Down Expand Up @@ -145,7 +145,7 @@ public Void run() throws IOException, InterruptedException {
if (t.getCause() != null) {
exceptionMsgs = exceptionMsgs + "; " + t.getCause().getMessage();
}
listener.getLogger().println(String.format("\nwatch closure threw an exception: \"%s\".\n", exceptionMsgs));
listener.getLogger().println(String.format("%nwatch closure threw an exception: \"%s\".%n", exceptionMsgs));
throw new IOException(t);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static enum OsType {
DARWIN, UNIX, WINDOWS, ZOS
}

public static final class getOsType extends MasterToSlaveCallable<OsType, RuntimeException> {
public static final class GetOsType extends MasterToSlaveCallable<OsType, RuntimeException> {
@Override
public OsType call() throws RuntimeException {
return getOsFromPlatform();
Expand Down Expand Up @@ -80,24 +80,21 @@ public static String[] fixPathInCommandArray(String[] command, EnvVars envVars,
* var and do 1)
*/

OsType targetType = filePath.act(new getOsType());
OsType targetType = filePath.act(new GetOsType());
String path = envVars.get("PATH");
List<String> foundOcs = new ArrayList<String>();
List<String> foundOcs;
FindOC finder = new FindOC(path);
try {
foundOcs = filePath.act(finder);
} catch (Throwable t) {
t.printStackTrace(listener.getLogger());
return command;
}
if (foundOcs == null || foundOcs.size() == 0) {
if (foundOcs.size() == 0) {
if (verbose)
listener.getLogger()
.println("could not find oc binary on the target computer of OS type " + targetType);
if (!(launcher instanceof RemoteLauncher) || !(launcher instanceof LocalLauncher)) {
if (verbose)
listener.getLogger().println("but your launcher is of a type that might have hindered out scan");
}

} else {
if (verbose)
listener.getLogger().println("found the following oc executables on the target computer of OS type "
Expand Down Expand Up @@ -158,7 +155,7 @@ private List<String> toStringArray(List list) {
ArrayList<String> listCopy = new ArrayList<String>(list);
for (int i = 0; i < listCopy.size(); i++) {
String element = listCopy.get(i);
if (element != null && element.trim().length() == 0) {
if ( element.trim().length() == 0) {
// skip entry presumably blanked by our -f processing below
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.openshift.jenkins.plugins.util;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
Expand All @@ -11,6 +12,7 @@

import javax.annotation.Nonnull;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand All @@ -21,6 +23,7 @@
/***
* {@link ClientCommandRunner} runs `oc` on a slave
*/
@SuppressFBWarnings("SE_BAD_FIELD")
public class ClientCommandRunner implements Serializable {
private static final long serialVersionUID = 42L;
private static final Logger LOGGER = Logger.getLogger(ClientCommandRunner.class.getName());
Expand Down Expand Up @@ -75,6 +78,7 @@ public ClientCommandRunner(@Nonnull String[] command, @Nonnull FilePath filePath
this.stderrOutputObserver = stderrOutputObserver;
}


private static class OcOutputConsumer implements Callable<Object> {
private InputStream in;
private OutputObserver outputObserver;
Expand All @@ -86,7 +90,7 @@ public OcOutputConsumer(InputStream in, OutputObserver outputObserver) {

@Override
public Boolean call() throws IOException, InterruptedException {
try (Reader reader = new InputStreamReader(in)) {
try (Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) {
LineIterator it = IOUtils.lineIterator(reader);
while (it.hasNext()) {
String line = it.nextLine();
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/FileLocations.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SERVICE_ACCOUNT_NAMESPACE_PATH=/var/run/secrets/kubernetes.io/serviceaccount/namespace
SERVICE_ACCOUNT_TOKEN_PATH=/var/run/secrets/kubernetes.io/serviceaccount/token
SERVICE_ACCOUNT_CA_PATH=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt

0 comments on commit 466cb81

Please sign in to comment.