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

Check plist array for duplication during manifest merge phase. #336

Merged
merged 1 commit into from
Jan 11, 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 @@ -59,7 +59,6 @@ private static void mergePlists(XMLPropertyListConfiguration base, XMLPropertyLi
if (baseValue == null) {
base.addProperty(key, libValue);
} else {

if (baseValue.getClass().equals(libValue.getClass())) {

if (!baseValue.getClass().equals(ArrayList.class)) {
Expand Down Expand Up @@ -100,7 +99,11 @@ else if (baseValue.getClass().equals(ArrayList.class)) {
ArrayList<String> baseArray = (ArrayList<String>)baseValue;
@SuppressWarnings("unchecked")
ArrayList<String> libArray = (ArrayList<String>)libValue;
baseArray.addAll((ArrayList<String>)libArray);
for (String val : libArray) {
if (!baseArray.contains(val)) {
baseArray.add(val);
}
}
}
else {
throw new PlistMergeException(String.format("Plist contains unknown type for key '%s': %s", key, baseValue.getClass().getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.defold.manifestmergetool.test;
package com.defold.manifestmergetool;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -18,11 +18,8 @@
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import com.defold.manifestmergetool.ManifestMergeTool;
import com.defold.manifestmergetool.ManifestMergeTool.Platform;

import java.net.URL;

@RunWith(Parameterized.class)
public class ManifestMergeToolTest {
private String contentRoot;
Expand Down Expand Up @@ -383,6 +380,79 @@ public void testMergeIOSMergeMarkers() throws IOException {
assertEquals(expected, merged);
}

@Test
public void testMergeIOSArrayDuplication() throws IOException {
if (platform != Platform.IOS) {
return;
}

createDefaultFiles();

String builtinsManifest = ""
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\" [ <!ATTLIST key merge (keep) #IMPLIED> ]> \n"
+ "<plist version=\"1.0\">\n"
+ "<dict>\n"
+ " <key merge='keep'>BASE64</key>\n"
+ " <data>SEVMTE8gV09STEQ=</data>\n"
+ " <key>INT</key>\n"
+ " <integer>8</integer>\n"
+ " <key>CFBundleSupportedPlatforms</key>\n"
+ " <array>\n"
+ " <string>iPhoneOS</string>\n"
+ " <string>iPhoneSimulator</string>\n"
+ " </array>\n"
+ "</dict>\n"
+ "</plist>\n";
createFile(contentRoot, "builtins/manifests/ios/Info.plist", builtinsManifest);

String libManifest = ""
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n"
+ "<plist version=\"1.0\">\n"
+ "<dict>\n"
+ " <key>BASE64</key>\n"
+ " <data>foobar</data>\n"
+ " <key>INT</key>\n"
+ " <integer>42</integer>\n"
+ " <key>CFBundleSupportedPlatforms</key>\n"
+ " <array>\n"
+ " <string>iPhoneOS</string>\n"
+ " </array>\n"
+ "</dict>\n"
+ "</plist>\n";
createFile(contentRoot, "builtins/manifests/ios/InfoLib.plist", libManifest);

String expected = ""
+ "<?xml version=\"1.0\"?>\n"
+ "<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">\n"
+ "<plist version=\"1.0\">\n"
+ " <dict>\n"
+ " <key>BASE64</key>\n"
+ " <data>SEVMTE8gV09STEQ=</data>\n"
+ "\n"
+ " <key>INT</key>\n"
+ " <integer>8</integer>\n"
+ "\n"
+ " <key>CFBundleSupportedPlatforms</key>\n"
+ " <array>\n"
+ " <string>iPhoneOS</string>\n"
+ " <string>iPhoneSimulator</string>\n"
+ " </array>\n"
+ "\n"
+ " <key>INT</key>\n"
+ " <integer>42</integer>\n"
+ " </dict>\n"
+ "</plist>\n";

createFile(contentRoot, "builtins/manifests/ios/InfoExpected.plist", expected);

ManifestMergeTool.merge(ManifestMergeTool.Platform.IOS, this.main, this.target, this.libraries);

String merged = readFile(this.target);
assertEquals(expected, merged);
}

@Test
public void testMergeIOSMixedTypes() throws IOException {
if (platform != Platform.IOS) {
Expand Down
Loading