Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit bc36eed

Browse files
Fix open issues for next release (#387)
* Add help text for MATLAB root and add error for failed installations * add fixes * remove spotbugs exceptions and fix most findings. still one finding to fix * fix remaining spotbugs finding * fix stdout typo * address feedback and remove dead imports. reran formatters * fix spotbugs finding * add back stdout to jenkins log
1 parent 40f2e0c commit bc36eed

File tree

11 files changed

+147
-103
lines changed

11 files changed

+147
-103
lines changed

pom.xml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
35
<modelVersion>4.0.0</modelVersion>
46
<parent>
57
<groupId>org.jenkins-ci.plugins</groupId>
@@ -56,8 +58,6 @@
5658
<!-- https://www.jenkins.io/doc/developer/plugin-development/choosing-jenkins-baseline/ -->
5759
<jenkins.baseline>2.387</jenkins.baseline>
5860
<jenkins.version>${jenkins.baseline}.3</jenkins.version>
59-
<!-- TODO fix violations -->
60-
<spotbugs.threshold>High</spotbugs.threshold>
6161
</properties>
6262

6363
<dependencyManagement>
@@ -132,8 +132,7 @@
132132
<groupId>org.jenkins-ci.tools</groupId>
133133
<artifactId>maven-hpi-plugin</artifactId>
134134
</plugin>
135-
<!-- Plugin to download the matlab run scripts and keep it under class
136-
resource folder -->
135+
<!-- Plugin to download the matlab run scripts and keep it under class resource folder -->
137136
<plugin>
138137
<groupId>com.googlecode.maven-download-plugin</groupId>
139138
<artifactId>download-maven-plugin</artifactId>
@@ -146,7 +145,8 @@
146145
<goal>wget</goal>
147146
</goals>
148147
<configuration>
149-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command</url>
148+
<url>
149+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/glnxa64/run-matlab-command</url>
150150
<unpack>false</unpack>
151151
<outputDirectory>${basedir}/src/main/resources/glnxa64</outputDirectory>
152152
<skipCache>true</skipCache>
@@ -160,7 +160,8 @@
160160
<goal>wget</goal>
161161
</goals>
162162
<configuration>
163-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maci64/run-matlab-command</url>
163+
<url>
164+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maci64/run-matlab-command</url>
164165
<unpack>false</unpack>
165166
<outputDirectory>${basedir}/src/main/resources/maci64</outputDirectory>
166167
<skipCache>true</skipCache>
@@ -174,7 +175,8 @@
174175
<goal>wget</goal>
175176
</goals>
176177
<configuration>
177-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maca64/run-matlab-command</url>
178+
<url>
179+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/maca64/run-matlab-command</url>
178180
<unpack>false</unpack>
179181
<outputDirectory>${basedir}/src/main/resources/maca64</outputDirectory>
180182
<skipCache>true</skipCache>
@@ -188,7 +190,8 @@
188190
<goal>wget</goal>
189191
</goals>
190192
<configuration>
191-
<url>https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/win64/run-matlab-command.exe</url>
193+
<url>
194+
https://ssd.mathworks.com/supportfiles/ci/run-matlab-command/v2/win64/run-matlab-command.exe</url>
192195
<unpack>false</unpack>
193196
<outputDirectory>${basedir}/src/main/resources/win64</outputDirectory>
194197
<skipCache>true</skipCache>
@@ -202,7 +205,8 @@
202205
<goal>wget</goal>
203206
</goals>
204207
<configuration>
205-
<url>https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip</url>
208+
<url>
209+
https://ssd.mathworks.com/supportfiles/ci/matlab-script-generator/v0/matlab-script-generator.zip</url>
206210
<unpack>false</unpack>
207211
<outputDirectory>${basedir}/src/main/resources</outputDirectory>
208212
<skipCache>true</skipCache>
@@ -214,8 +218,8 @@
214218
</plugins>
215219
<pluginManagement>
216220
<plugins>
217-
<!--This plugin's configuration is used to store Eclipse m2e settings
218-
only. It has no influence on the Maven build itself. -->
221+
<!-- This plugin's configuration is used to store Eclipse m2e settings only. It has
222+
no influence on the Maven build itself. -->
219223
<plugin>
220224
<groupId>org.eclipse.m2e</groupId>
221225
<artifactId>lifecycle-mapping</artifactId>
@@ -282,4 +286,4 @@
282286
</plugins>
283287
</pluginManagement>
284288
</build>
285-
</project>
289+
</project>

src/main/java/com/mathworks/ci/BuildTargetNote.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
import com.google.common.annotations.VisibleForTesting;
8-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
98
import hudson.Extension;
109
import hudson.MarkupText;
1110
import hudson.console.ConsoleAnnotationDescriptor;
@@ -15,7 +14,6 @@
1514

1615
public class BuildTargetNote extends ConsoleNote {
1716
@VisibleForTesting
18-
@SuppressFBWarnings(value = "MS_SHOULD_BE_FINAL", justification = "Visible for testing")
1917
public static boolean ENABLED = !Boolean.getBoolean(BuildTargetNote.class.getName() + ".disabled");
2018

2119
public BuildTargetNote() {

src/main/java/com/mathworks/ci/MatlabInstallation.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Describable class for adding MATLAB installations in Jenkins Global Tool configuration.
77
*/
88

9-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
109
import hudson.CopyOnWrite;
1110
import hudson.EnvVars;
1211
import hudson.Extension;
@@ -15,15 +14,12 @@
1514
import hudson.model.EnvironmentSpecific;
1615
import hudson.model.Node;
1716
import hudson.model.TaskListener;
18-
import hudson.remoting.VirtualChannel;
1917
import hudson.slaves.NodeSpecific;
2018
import hudson.tools.ToolDescriptor;
2119
import hudson.tools.ToolInstallation;
2220
import hudson.tools.ToolProperty;
2321
import java.io.File;
2422
import java.io.IOException;
25-
import java.nio.file.Path;
26-
import java.nio.file.Paths;
2723
import java.util.Arrays;
2824
import java.util.List;
2925
import javax.annotation.CheckForNull;
@@ -62,21 +58,18 @@ public MatlabInstallation forNode(@Nonnull Node node, TaskListener log) throws I
6258
return new MatlabInstallation(getName(), translateFor(node, log), getProperties().toList());
6359
}
6460

65-
@SuppressFBWarnings(value = {
66-
"NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" }, justification = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE: Its false positive scenario for sport bug which is fixed in later versions "
67-
+ "https://github.com/spotbugs/spotbugs/issues/1843")
6861
@Override
6962
public void buildEnvVars(EnvVars env) {
70-
String pathToExecutable = getHome() + "/bin";
71-
env.put("PATH+matlabroot", pathToExecutable);
72-
Jenkins jenkinsInstance = Jenkins.getInstanceOrNull();
73-
if (jenkinsInstance != null) {
74-
if (jenkinsInstance.getChannel() != null) {
75-
FilePath batchExecutablePath = new FilePath(jenkinsInstance.getChannel(), getHome());
76-
if (batchExecutablePath.getParent() != null) {
77-
env.put("PATH+matlab_batch", batchExecutablePath.getParent().getRemote());
78-
}
79-
}
63+
String home = getHome();
64+
if (home == null) {
65+
return;
66+
}
67+
FilePath matlabHome = new FilePath(new File(home));
68+
FilePath matlabBin = new FilePath(matlabHome, "bin");
69+
env.put("PATH+matlabroot", matlabBin.getRemote());
70+
FilePath matlabBatchFolder = matlabHome.getParent();
71+
if (matlabBatchFolder != null) {
72+
env.put("PATH+matlabbatch", matlabBatchFolder.getRemote());
8073
}
8174
}
8275

src/main/java/com/mathworks/ci/MatlabReleaseInfo.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
import java.io.InputStream;
1111
import java.io.InputStreamReader;
12+
import java.io.IOException;
1213
import java.io.BufferedReader;
14+
import java.lang.InterruptedException;
1315
import java.nio.charset.StandardCharsets;
1416
import java.nio.file.NotDirectoryException;
1517
import java.util.HashMap;
@@ -25,7 +27,7 @@
2527
import org.w3c.dom.Element;
2628
import org.w3c.dom.Node;
2729
import org.w3c.dom.NodeList;
28-
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
30+
import org.xml.sax.SAXException;
2931
import hudson.FilePath;
3032

3133
public class MatlabReleaseInfo {
@@ -74,11 +76,6 @@ public boolean verLessThan(double version) throws MatlabVersionNotFoundException
7476
}
7577
}
7678

77-
@SuppressFBWarnings(value = { "REC_CATCH_EXCEPTION",
78-
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE" }, justification = "REC_CATCH_EXCEPTION: Irrespective of exception type, intention is to handle it in same way."
79-
+
80-
" Also, there is no intention to propagate any runtime exception up in the hierarchy." +
81-
"RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE: This is a false positive reported by spotbugs for JDK 11 for try-with-resources block.")
8279
private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoundException {
8380
if (MapUtils.isEmpty(versionInfoCache)) {
8481
try {
@@ -139,7 +136,7 @@ private Map<String, String> getVersionInfoFromFile() throws MatlabVersionNotFoun
139136
// Update the versionInfoCache with actual version extracted from Contents.m
140137
versionInfoCache.put(VERSION_TAG, actualVersion);
141138
}
142-
} catch (Exception e) {
139+
} catch (InterruptedException | IOException | ParserConfigurationException | SAXException e) {
143140
throw new MatlabVersionNotFoundException(
144141
Message.getValue("Releaseinfo.matlab.version.not.found.error"), e);
145142
}

src/main/java/com/mathworks/ci/MatlabVersionNotFoundException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ public class MatlabVersionNotFoundException extends Exception {
1111
MatlabVersionNotFoundException(String errorMessage, Throwable err) {
1212
super(errorMessage, err);
1313
}
14+
15+
MatlabVersionNotFoundException(String errorMessage) {
16+
super(errorMessage);
17+
}
1418
}

src/main/java/com/mathworks/ci/UseMatlabVersionBuildWrapper.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,20 +197,24 @@ public void setUp(Context context, Run<?, ?> build, FilePath workspace, Launcher
197197
if (!matlabExecutablePath.exists()) {
198198
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
199199
}
200+
FilePath matlabBinDir = matlabExecutablePath.getParent();
201+
if (matlabBinDir == null) {
202+
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
203+
}
200204
// Add matlab-batch executable in path
201205
FilePath batchExecutable = getNthParentFilePath(matlabExecutablePath, 3);
202206
if (batchExecutable != null && batchExecutable.exists()) {
203-
context.env("PATH+matlab_batch", batchExecutable.getRemote());
207+
context.env("PATH+matlabbatch", batchExecutable.getRemote());
204208
}
205209

206210
// Add "matlabroot" without bin as env variable which will be available across
207211
// the build.
208212
context.env("matlabroot", nodeSpecificMatlab);
209213
// Add matlab bin to path to invoke MATLAB directly on command line.
210-
context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());
214+
context.env("PATH+matlabroot", matlabBinDir.getRemote());
211215
;
212216
listener.getLogger().println("\n" + String.format(Message.getValue("matlab.added.to.path.from"),
213-
matlabExecutablePath.getParent().getRemote()) + "\n");
217+
matlabBinDir.getRemote()) + "\n");
214218
}
215219

216220
private String getNodeSpecificExecutable(Launcher launcher) {

src/main/java/com/mathworks/ci/Utilities.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ public static void addMatlabToEnvPathFromAxis(Computer cmp, TaskListener listene
4343
FilePath matlabRoot = getNodeSpecificHome(name,
4444
cmp.getNode(), listener, env);
4545

46-
if (matlabRoot != null && matlabRoot.getParent().exists()) {
47-
env.put("PATH+matlab_batch", matlabRoot.getParent().getRemote());
46+
FilePath toolHome = matlabRoot.getParent();
47+
if (toolHome == null) {
48+
return;
49+
}
50+
if (matlabRoot != null && toolHome.exists()) {
51+
env.put("PATH+matlabbatch", toolHome.getRemote());
4852
}
4953

5054
String matlabExecutablePath = getNodeSpecificHome(name,

0 commit comments

Comments
 (0)