Skip to content

Commit 0e63b75

Browse files
committed
fix exportList bug in rewriteContribution(), clean up install() method
1 parent 969701a commit 0e63b75

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

app/src/processing/app/contrib/AvailableContribution.java

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -96,43 +96,40 @@ static ContributionType matchContribType(String path) {
9696
}
9797

9898

99-
static public LocalContribution install(Base base, File contribArchive) throws IOException {
100-
AvailableContribution ac = null;
101-
102-
ZipFile zf = new ZipFile(contribArchive);
103-
Enumeration<? extends ZipEntry> entries = zf.entries();
104-
while (entries.hasMoreElements()) {
105-
ZipEntry entry = entries.nextElement();
106-
String name = entry.getName();
107-
if (name.endsWith(".properties")) {
108-
ContributionType type = matchContribType(name);
109-
if (type != null) {
110-
StringDict params = new StringDict();
111-
String[] lines = PApplet.loadStrings(zf.getInputStream(entry));
112-
if (lines != null) {
113-
for (String line : lines) {
114-
if (!line.startsWith("#")) {
115-
int equals = line.indexOf('=');
116-
if (equals != -1) {
117-
String key = line.substring(0, equals).trim();
118-
String value = line.substring(equals + 1).trim();
119-
params.set(key, value);
120-
}
121-
}
99+
/**
100+
* Create an AvailableContribution object from the .properties file
101+
* found in the specified zip file. Or return null if no match.
102+
*/
103+
static private AvailableContribution findContrib(File contribArchive) throws IOException {
104+
try (ZipFile zf = new ZipFile(contribArchive)) {
105+
Enumeration<? extends ZipEntry> entries = zf.entries();
106+
while (entries.hasMoreElements()) {
107+
ZipEntry entry = entries.nextElement();
108+
String entryPath = entry.getName();
109+
if (entryPath.endsWith(".properties")) {
110+
ContributionType type = matchContribType(entryPath);
111+
if (type != null) {
112+
String[] lines = PApplet.loadStrings(zf.getInputStream(entry));
113+
if (lines != null) {
114+
String filename = contribArchive.getAbsolutePath() + ":" + entryPath;
115+
StringDict params = Util.readSettings(filename, lines, false);
116+
return new AvailableContribution(type, params);
117+
118+
} else {
119+
System.err.println("Could parse properties from " + entryPath);
122120
}
123-
ac = new AvailableContribution(type, params);
124-
break; // found, let's get outta here
125-
126121
} else {
127-
System.err.println("Could parse properties from " + name);
122+
System.err.println("Could not find a matching .properties file");
128123
}
129-
} else {
130-
System.err.println("Could not find a matching .properties file");
131124
}
132125
}
133126
}
134-
zf.close();
127+
return null;
128+
}
129+
135130

131+
static public LocalContribution install(Base base, File contribArchive) throws IOException {
132+
AvailableContribution ac = findContrib(contribArchive);
136133
if (ac != null) {
137134
return ac.install(base, contribArchive, false, null);
138135
}
@@ -160,8 +157,9 @@ public LocalContribution install(Base base, File contribArchive,
160157
try {
161158
tempFolder = type.createTempFolder();
162159
} catch (IOException e) {
163-
if (status != null)
160+
if (status != null) {
164161
status.setErrorMessage(Language.text("contrib.errors.temporary_directory"));
162+
}
165163
return null;
166164
}
167165
Util.unzip(contribArchive, tempFolder);
@@ -271,6 +269,9 @@ public ContributionType getType() {
271269
*/
272270
private boolean rewritePropertiesFile(File propFile) {
273271
StringDict properties = Util.readSettings(propFile, false);
272+
if (properties == null) {
273+
return false;
274+
}
274275

275276
String name = properties.get("name");
276277
if (name == null || name.isEmpty()) {
@@ -379,7 +380,7 @@ private boolean rewritePropertiesFile(File propFile) {
379380
writer.println("imports=" + importList.join(","));
380381
}
381382
if (exportList != null) {
382-
writer.println("exports=" + importList.join(","));
383+
writer.println("exports=" + exportList.join(","));
383384
}
384385

385386
if (getType() == ContributionType.EXAMPLES) {

0 commit comments

Comments
 (0)