Skip to content

Commit 7a4fbe8

Browse files
authored
Backport the change on PR3713 into release/3.4 (#3719)
* backport pr3713 * modify FileUtils.java
1 parent 52b03d0 commit 7a4fbe8

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItWlsSamples.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO;
4747
import static oracle.weblogic.kubernetes.TestConstants.TEST_IMAGES_REPO_SECRET_NAME;
4848
import static oracle.weblogic.kubernetes.TestConstants.TEST_NGINX_IMAGE_NAME;
49-
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TAG;
49+
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TAG_DEFAULT;
5050
import static oracle.weblogic.kubernetes.TestConstants.WEBLOGIC_IMAGE_TO_USE_IN_SPEC;
5151
import static oracle.weblogic.kubernetes.actions.ActionConstants.ITTESTS_DIR;
5252
import static oracle.weblogic.kubernetes.actions.ActionConstants.MODEL_DIR;
@@ -208,7 +208,7 @@ void testSampleDomainInImage(String model) {
208208
// update domainHomeImageBase with right values in create-domain-inputs.yaml
209209
assertDoesNotThrow(() -> {
210210
replaceStringInFile(get(sampleBase.toString(), "create-domain-inputs.yaml").toString(),
211-
"domainHomeImageBase: container-registry.oracle.com/middleware/weblogic:" + WEBLOGIC_IMAGE_TAG,
211+
"domainHomeImageBase: container-registry.oracle.com/middleware/weblogic:" + WEBLOGIC_IMAGE_TAG_DEFAULT,
212212
"domainHomeImageBase: " + WEBLOGIC_IMAGE_TO_USE_IN_SPEC);
213213
replaceStringInFile(get(sampleBase.toString(), "create-domain-inputs.yaml").toString(),
214214
"#image:",
@@ -281,7 +281,7 @@ void testSampleDomainInPv(String model) {
281281
replaceStringInFile(get(sampleBase.toString(), "create-domain-inputs.yaml").toString(),
282282
"createDomainFilesDir: wlst", "createDomainFilesDir: " + script);
283283
replaceStringInFile(get(sampleBase.toString(), "create-domain-inputs.yaml").toString(),
284-
"image: container-registry.oracle.com/middleware/weblogic:" + WEBLOGIC_IMAGE_TAG,
284+
"image: container-registry.oracle.com/middleware/weblogic:" + WEBLOGIC_IMAGE_TAG_DEFAULT,
285285
"image: " + WEBLOGIC_IMAGE_TO_USE_IN_SPEC);
286286
});
287287

integration-tests/src/test/java/oracle/weblogic/kubernetes/utils/FileUtils.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2020, 2021, Oracle and/or its affiliates.
1+
// Copyright (c) 2020, 2022, Oracle and/or its affiliates.
22
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
33

44
package oracle.weblogic.kubernetes.utils;
@@ -327,12 +327,22 @@ public static void replaceStringInFile(String filePath, String regex, String rep
327327
throws IOException {
328328
LoggingFacade logger = getLogger();
329329
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);
331331
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+
}
336346
}
337347

338348
/**

0 commit comments

Comments
 (0)