|
1 |
| -// Copyright (c) 2020, 2021, Oracle and/or its affiliates. |
| 1 | +// Copyright (c) 2020, 2022, Oracle and/or its affiliates. |
2 | 2 | // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
3 | 3 |
|
4 | 4 | package oracle.weblogic.kubernetes.utils;
|
@@ -327,12 +327,22 @@ public static void replaceStringInFile(String filePath, String regex, String rep
|
327 | 327 | throws IOException {
|
328 | 328 | LoggingFacade logger = getLogger();
|
329 | 329 | Path src = Paths.get(filePath);
|
330 |
| - logger.info("Replacing {0}", src.toString()); |
| 330 | + logger.info("Replacing {0} in {1} with {2}", regex, src.toString(), replacement); |
331 | 331 | Charset charset = StandardCharsets.UTF_8;
|
332 |
| - String content = new String(Files.readAllBytes(src), charset); |
333 |
| - content = content.replaceAll(regex, replacement); |
334 |
| - logger.info("with {0}", replacement); |
335 |
| - Files.write(src, content.getBytes(charset)); |
| 332 | + // String content = new String(Files.readAllBytes(src), charset); |
| 333 | + // content = content.replaceAll(regex, replacement); |
| 334 | + // Files.write(src, content.getBytes(charset)); |
| 335 | + |
| 336 | + String content = |
| 337 | + new String(Files.readAllBytes(src), StandardCharsets.UTF_8); |
| 338 | + if (!content.contains(regex)) { |
| 339 | + logger.info("search string {0} not found to replace with {1}", regex, replacement); |
| 340 | + } |
| 341 | + long oldModified = src.toFile().lastModified(); |
| 342 | + Files.write(src, content.replaceAll(regex, replacement).getBytes(StandardCharsets.UTF_8)); |
| 343 | + if (oldModified == src.toFile().lastModified()) { |
| 344 | + logger.info("No modification was done to the file"); |
| 345 | + } |
336 | 346 | }
|
337 | 347 |
|
338 | 348 | /**
|
|
0 commit comments