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

Commit 028510f

Browse files
committed
Fixed spotbug
1 parent 43cd307 commit 028510f

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,7 @@ public FilePath performInstallation (ToolInstallation tool, Node node, TaskListe
9696
log.getLogger ().println (
9797
"MATLAB installation for version " + this.getVersion ()
9898
+ " 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-
}
99+
updateProductList (installedProducts);
105100
}
106101
}
107102
return expectedPath;
@@ -142,7 +137,7 @@ private boolean isSameProduct (FilePath installedProducts)
142137
}
143138

144139
try (BufferedReader reader = new BufferedReader (
145-
new InputStreamReader (installedProducts.read ()))) {
140+
new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) {
146141
String line;
147142
Set<String> foundProducts = new HashSet<> ();
148143
while ((line = reader.readLine()) != null) {
@@ -158,6 +153,31 @@ private boolean isSameProduct (FilePath installedProducts)
158153
return false;
159154
}
160155

156+
private void updateProductList (FilePath installedProducts)
157+
throws IOException, InterruptedException {
158+
String productList = this.getProducts ();
159+
if (installedProducts.exists ()) {
160+
try (BufferedReader reader = new BufferedReader (
161+
new InputStreamReader (installedProducts.read (), StandardCharsets.UTF_8.name ()))) {
162+
String line;
163+
Set<String> productSet;
164+
while ((line = reader.readLine ()) != null) {
165+
productSet = new HashSet<> (
166+
Arrays.asList (line.trim () + " " + this.getProducts ().trim ()));
167+
installedProducts.write (String.join (" ", productSet),
168+
StandardCharsets.UTF_8.name ());
169+
}
170+
}
171+
} else {
172+
if (productList.isEmpty ()) {
173+
installedProducts.write ("MATLAB", StandardCharsets.UTF_8.name ());
174+
} else {
175+
installedProducts.write ("MATLAB " + this.getProducts (),
176+
StandardCharsets.UTF_8.name ());
177+
}
178+
}
179+
}
180+
161181
private void appendReleaseToArguments (ArgumentListBuilder args, TaskListener log) {
162182
try {
163183
String trimmedRelease = this.getVersion ().trim ();

0 commit comments

Comments
 (0)