Skip to content

Commit eb093c4

Browse files
committed
Simplify how we workaround EOFException and ZipException.
1 parent a32bbfc commit eb093c4

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

atplug-plugin-gradle/src/main/java/com/diffplug/atplug/tooling/PlugGenerator.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class PlugGenerator internal constructor(toSearches: List<File>, toLinkAgainst:
4343
private val metadataGeneratorFor: KFunction<Function<Any, String>>
4444

4545
init {
46-
System.setProperty("atplug.generate", "true")
4746
// create a classloader which looks in toSearch first, then each of the jars in toLinkAgainst
4847
val urls = (toSearches + toLinkAgainst).map { it.toURI().toURL() }.toTypedArray()
4948
val parent: ClassLoader? =
@@ -54,8 +53,8 @@ class PlugGenerator internal constructor(toSearches: List<File>, toLinkAgainst:
5453
metadataGeneratorFor =
5554
socketOwnerCompanionObject::class.memberFunctions.find {
5655
it.name == "metadataGeneratorFor"
57-
}!! as
58-
KFunction<Function<Any, String>>
56+
}!!
57+
as KFunction<Function<Any, String>>
5958
try {
6059
val parser = PlugParser()
6160
// walk toSearch, passing each classfile to load()

atplug-runtime/src/main/java/com/diffplug/atplug/PlugRegistry.kt

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ interface PlugRegistry {
5858
// do the parsing again but this time disable caching
5959
// https://stackoverflow.com/questions/36517604/closing-a-jarurlconnection
6060
parseManifest(manifestUrl, false)
61+
} catch (e: ZipException) {
62+
// When a JVM loads a jar, it mmaps the jar. If that jar changes
63+
// (as it does when generating plugin metadata in a Gradle daemon)
64+
// then you sometimes get ZipException after the change.
65+
parseManifest(manifestUrl, false)
6166
}
6267
}
6368
}
@@ -77,26 +82,12 @@ interface PlugRegistry {
7782
for (service in
7883
services.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
7984
val servicePath = service.trim { it <= ' ' }
80-
try {
81-
if (servicePath.isNotEmpty()) {
82-
val asString = manifestUrl.toExternalForm()
83-
val component = parseComponent(asString, servicePath, allowCaching)
84-
synchronized(this) {
85-
data.putDescriptor(component.provides, component)
86-
owners[component.provides]?.doRegister(component)
87-
}
88-
}
89-
} catch (e: ZipException) {
90-
// When a JVM loads a jar, it mmaps the jar. If that jar changes
91-
// (as it does when generating plugin metadata in a Gradle daemon)
92-
// then you get ZipException after the change. The accuracy of the
93-
// registry is irrelevant during metadata generation - the registry
94-
// exists during metadata generation only because the `SocketOwner`s
95-
// register themselves in their constructors. Therefore, it is safe to
96-
// ignore these errors during metadata generation.
97-
val prop = System.getProperty("atplug.generate")
98-
if (prop != "true") {
99-
throw e
85+
if (servicePath.isNotEmpty()) {
86+
val asString = manifestUrl.toExternalForm()
87+
val component = parseComponent(asString, servicePath, allowCaching)
88+
synchronized(this) {
89+
data.putDescriptor(component.provides, component)
90+
owners[component.provides]?.doRegister(component)
10091
}
10192
}
10293
}

0 commit comments

Comments
 (0)