@@ -12,6 +12,7 @@ import java.net.URL
1212import java.nio.charset.StandardCharsets
1313import java.util.*
1414import java.util.jar.Manifest
15+ import java.util.zip.ZipException
1516
1617interface PlugRegistry {
1718 fun <T > registerSocket (socketClass : Class <T >, socketOwner : SocketOwner <T >)
@@ -70,12 +71,26 @@ interface PlugRegistry {
7071 for (service in
7172 services.split(" ," .toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()) {
7273 val servicePath = service.trim { it <= ' ' }
73- if (servicePath.isNotEmpty()) {
74- val asString = manifestUrl.toExternalForm()
75- val component = parseComponent(asString, servicePath)
76- synchronized(this ) {
77- data.putDescriptor(component.provides, component)
78- owners.get(component.provides)?.doRegister(component)
74+ try {
75+ if (servicePath.isNotEmpty()) {
76+ val asString = manifestUrl.toExternalForm()
77+ val component = parseComponent(asString, servicePath)
78+ synchronized(this ) {
79+ data.putDescriptor(component.provides, component)
80+ owners.get(component.provides)?.doRegister(component)
81+ }
82+ }
83+ } catch (e: ZipException ) {
84+ // When a JVM loads a jar, it mmaps the jar. If that jar changes
85+ // (as it does when generating plugin metadata in a Gradle daemon)
86+ // then you get ZipException after the change. The accuracy of the
87+ // registry is irrelevant during metadata generation - the registry
88+ // exists during metadata generation only because the `SocketOwner`s
89+ // register themselves in their constructors. Therefore, it is safe to
90+ // ignore these errors during metadata generation.
91+ val prop = System .getProperty(" atplug.generate" )
92+ if (prop != " true" ) {
93+ throw e
7994 }
8095 }
8196 }
0 commit comments