Skip to content

Commit

Permalink
MIDletLoader: JAD properties should take precedence over manifest
Browse files Browse the repository at this point in the history
Previously the jar's manifest would take precedence, which could
cause issues if, for example, the main class name is only correct
in the JAD file. And since it is the one that's easier to edit,
it should take precedence anyway.
  • Loading branch information
AShiningRay committed Dec 3, 2024
1 parent a575727 commit 8caa14f
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/org/recompile/mobile/MIDletLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public MIDletLoader(URL urls[], Map<String, String> descriptorProperties)
Mobile.log(Mobile.LOG_ERROR, MIDletLoader.class.getPackage().getName() + "." + MIDletLoader.class.getSimpleName() + ": " + "Can't add CLDC System Properties");
}

// Integrate properties retrieved from JAD file, if any.
properties.putAll(descriptorProperties);

try { loadManifest(); }
catch (Exception e)
{
Expand All @@ -115,11 +118,7 @@ public MIDletLoader(URL urls[], Map<String, String> descriptorProperties)
properties.put("wireless.messaging.sms.smsc", "+8613800010000");
properties.put("device.imei", "000000000000000");


if (className == null) { className = findMainClassInJars(urls); }

// Integrate properties retrieved from JAD file, if any.
properties.putAll(descriptorProperties);
}

public static String findMainClassInJars(URL[] urls)
Expand Down Expand Up @@ -261,7 +260,9 @@ public static void parseDescriptorInto(InputStream is, Map<String, String> keyVa
{
if (currentKey != null)
{
keyValueMap.put(currentKey, currentValue.toString().trim());
// Only add a new key-value pair if the key doesn't already exist (set by the JAD file)
if(!keyValueMap.containsKey(currentKey)) { keyValueMap.put(currentKey, currentValue.toString().trim()); }
else { Mobile.log(Mobile.LOG_DEBUG, MIDletLoader.class.getPackage().getName() + "." + MIDletLoader.class.getSimpleName() + ": " + "properties already contain " + currentKey + "! Maintaining current value: " + keyValueMap.get(currentKey)); }
currentValue.setLength(0);
}

Expand All @@ -274,11 +275,15 @@ public static void parseDescriptorInto(InputStream is, Map<String, String> keyVa
}
}
}
if (currentKey != null) { keyValueMap.put(currentKey, currentValue.toString().trim()); }
if (currentKey != null)
{
if(!keyValueMap.containsKey(currentKey)) { keyValueMap.put(currentKey, currentValue.toString().trim()); }
else { Mobile.log(Mobile.LOG_DEBUG, MIDletLoader.class.getPackage().getName() + "." + MIDletLoader.class.getSimpleName() + ": " + "properties already contain " + currentKey + "! Maintaining current value: " + keyValueMap.get(currentKey)); }
}
}
catch (IOException e)
{
Mobile.log(Mobile.LOG_ERROR, MIDletLoader.class.getPackage().getName() + "." + MIDletLoader.class.getSimpleName() + ": " + "Failed to parse JAD:" + e.getMessage());
Mobile.log(Mobile.LOG_ERROR, MIDletLoader.class.getPackage().getName() + "." + MIDletLoader.class.getSimpleName() + ": " + "Failed to parse descriptor:" + e.getMessage());
}
}

Expand Down Expand Up @@ -314,6 +319,8 @@ private void loadManifest()
suitename = name;
suitename = suitename.replace(":","");
}

Mobile.log(Mobile.LOG_INFO, "Loading MIDlet: " + suitename +" | Main Class: " + className);
}
}

Expand Down

0 comments on commit 8caa14f

Please sign in to comment.