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

Commit 43cd307

Browse files
committed
Support to maintain insalled matlab products
1 parent dcf47b6 commit 43cd307

File tree

1 file changed

+54
-5
lines changed

1 file changed

+54
-5
lines changed

src/main/java/com/mathworks/ci/tools/MatlabInstaller.java

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,28 @@
1515
import hudson.FilePath;
1616
import hudson.Launcher;
1717
import hudson.Launcher.ProcStarter;
18+
1819
import hudson.model.Node;
1920
import hudson.model.TaskListener;
2021
import hudson.tools.DownloadFromUrlInstaller;
2122
import hudson.tools.ToolInstallation;
2223
import hudson.tools.ToolInstallerDescriptor;
24+
2325
import hudson.util.ArgumentListBuilder;
2426
import hudson.util.FormValidation;
2527

28+
import java.io.BufferedReader;
2629
import java.io.IOException;
30+
import java.io.InputStreamReader;
2731
import java.net.URL;
32+
2833
import java.nio.charset.StandardCharsets;
34+
35+
import java.util.Arrays;
36+
import java.util.HashSet;
2937
import java.util.Locale;
3038

39+
import java.util.Set;
3140
import jenkins.model.Jenkins;
3241
import org.apache.commons.io.IOUtils;
3342

@@ -77,11 +86,23 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe
7786

7887
getFreshCopyOfExecutables (installable, expectedPath);
7988

80-
int result = installUsingMpm (node, expectedPath, log);
81-
if (result == 0) {
82-
log.getLogger ().println (
83-
"MATLAB installation for version " + this.getVersion ()
84-
+ " using mpm is completed successfully !");
89+
FilePath versionInfo = new FilePath (expectedPath,"VersionInfo.xml");
90+
FilePath installedProducts = new FilePath (expectedPath,"installed_matlab_product_list.txt");
91+
if (versionInfo.exists () && isSameProduct(installedProducts)) {
92+
return expectedPath;
93+
} else {
94+
int result = installUsingMpm (node, expectedPath, log);
95+
if (result == 0) {
96+
log.getLogger ().println (
97+
"MATLAB installation for version " + this.getVersion ()
98+
+ " using mpm is completed successfully !");
99+
String productList = this.getProducts ();
100+
if(productList.isEmpty ()){
101+
installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name());
102+
} else {
103+
installedProducts.write ("MATLAB "+ this.getProducts (), StandardCharsets.UTF_8.name());
104+
}
105+
}
85106
}
86107
return expectedPath;
87108
}
@@ -109,6 +130,34 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log)
109130
return result;
110131
}
111132

133+
private boolean isSameProduct (FilePath installedProducts)
134+
throws IOException, InterruptedException {
135+
if (installedProducts.exists ()) {
136+
Set<String> productSet;
137+
if (this.getProducts().isEmpty ()) {
138+
// Add default product if no products are provided
139+
productSet = new HashSet<>(Arrays.asList("MATLAB"));
140+
} else {
141+
productSet = new HashSet<>(Arrays.asList(this.getProducts().trim().split(" ")));
142+
}
143+
144+
try (BufferedReader reader = new BufferedReader (
145+
new InputStreamReader (installedProducts.read ()))) {
146+
String line;
147+
Set<String> foundProducts = new HashSet<> ();
148+
while ((line = reader.readLine()) != null) {
149+
for (String product : productSet) {
150+
if (line.trim().contains (product)) {
151+
foundProducts.add (product);
152+
}
153+
}
154+
}
155+
return foundProducts.containsAll(productSet);
156+
}
157+
}
158+
return false;
159+
}
160+
112161
private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) {
113162
try {
114163
String trimmedRelease = this.getVersion ().trim ();

0 commit comments

Comments
 (0)