|
15 | 15 | import hudson.FilePath; |
16 | 16 | import hudson.Launcher; |
17 | 17 | import hudson.Launcher.ProcStarter; |
| 18 | + |
18 | 19 | import hudson.model.Node; |
19 | 20 | import hudson.model.TaskListener; |
20 | 21 | import hudson.tools.DownloadFromUrlInstaller; |
21 | 22 | import hudson.tools.ToolInstallation; |
22 | 23 | import hudson.tools.ToolInstallerDescriptor; |
| 24 | + |
23 | 25 | import hudson.util.ArgumentListBuilder; |
24 | 26 | import hudson.util.FormValidation; |
25 | 27 |
|
| 28 | +import java.io.BufferedReader; |
26 | 29 | import java.io.IOException; |
| 30 | +import java.io.InputStreamReader; |
27 | 31 | import java.net.URL; |
| 32 | + |
28 | 33 | import java.nio.charset.StandardCharsets; |
| 34 | + |
| 35 | +import java.util.Arrays; |
| 36 | +import java.util.HashSet; |
29 | 37 | import java.util.Locale; |
30 | 38 |
|
| 39 | +import java.util.Set; |
31 | 40 | import jenkins.model.Jenkins; |
32 | 41 | import org.apache.commons.io.IOUtils; |
33 | 42 |
|
@@ -77,11 +86,23 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe |
77 | 86 |
|
78 | 87 | getFreshCopyOfExecutables (installable, expectedPath); |
79 | 88 |
|
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 | + } |
85 | 106 | } |
86 | 107 | return expectedPath; |
87 | 108 | } |
@@ -109,6 +130,34 @@ private int installUsingMpm (Node node, FilePath expectedPath, TaskListener log) |
109 | 130 | return result; |
110 | 131 | } |
111 | 132 |
|
| 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 | + |
112 | 161 | private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) { |
113 | 162 | try { |
114 | 163 | String trimmedRelease = this.getVersion ().trim (); |
|
0 commit comments