Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If the provisioning configuration is the same as saved copy, the file is not overwritten (fix duplicate code) #549

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.wildfly.channel.ChannelManifestMapper;
import org.wildfly.channel.ChannelMapper;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -206,14 +207,32 @@ public static void recordProvisioningDefinition(Path sourceServer) throws IOExce
final String content = Files.readString(provisioningFile);
final String lineEndings = content.replaceAll("\\r\\n?", "\n");
Files.writeString(provisioningRecordFile, lineEndings);
} else {
} else if (!isFileContentEquals(provisioningFile, provisioningRecordFile)) {
final String content = Files.readString(provisioningFile);
final String lineEndings = content.replaceAll("\\r\\n?", "\n");
Files.writeString(provisioningRecordFile, lineEndings);
}

}

static boolean isFileContentEquals(Path path1, Path path2) throws IOException {
try (BufferedReader bf1 = Files.newBufferedReader(path1);
BufferedReader bf2 = Files.newBufferedReader(path2)) {
String line1 = "", line2 = "";
while ((line1 = bf1.readLine()) != null) {
line2 = bf2.readLine();
if (!line1.equals(line2)) {
return false;
}
}
if (bf2.readLine() == null) {
return true;
} else {
return false;
}
}
}

protected static void writeToFile(Path path, String text) throws IOException {
if (!text.endsWith("\n")) {
text += "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ public void recordProvisioningConfigurationIfExists() throws Exception {
.hasContent("<provisioning></provisioning>");
}

@Test
public void overrideProvisioningConfigurationIfContentNotEquals() throws Exception {
Files.createDirectory(server.resolve(Constants.PROVISIONED_STATE_DIR));
Files.writeString(server.resolve(Constants.PROVISIONED_STATE_DIR).resolve(Constants.PROVISIONING_XML), "<provisioning></provisioning>");
Files.createDirectory(server.resolve(METADATA_DIR));
Files.writeString(server.resolve(METADATA_DIR).resolve(PROVISIONING_RECORD_XML), "<provisioning>content</provisioning>");

ProsperoMetadataUtils.generate(server, List.of(A_CHANNEL), A_MANIFEST, null);

Assertions.assertThat(server.resolve(METADATA_DIR).resolve(PROVISIONING_RECORD_XML))
.hasContent("<provisioning></provisioning>");
}

private void assertMetadataWritten() throws MalformedURLException {
final Channel channel = ChannelMapper.from(channelPath.toUri().toURL());
final ChannelManifest manifest = ChannelManifestMapper.from(manifestPath.toUri().toURL());
Expand Down
Loading