Skip to content

Commit 4a86d86

Browse files
committed
Fix VelocityPresentationProvider throwing errors
This happens when non-zip files are in the scanned class roots, and was somehow triggered when opening the projects wizard
1 parent b08ad18 commit 4a86d86

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/main/kotlin/com/demonwav/mcdev/platform/velocity/framework/VelocityPresentationProvider.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ import com.intellij.framework.library.LibraryVersionProperties
1616
import com.intellij.openapi.roots.libraries.LibraryPresentationProvider
1717
import com.intellij.openapi.vfs.VirtualFile
1818
import java.io.BufferedReader
19+
import java.io.IOException
1920
import java.util.jar.JarFile
2021

2122
class VelocityPresentationProvider : LibraryPresentationProvider<LibraryVersionProperties>(VELOCITY_LIBRARY_KIND) {
2223
override fun getIcon(properties: LibraryVersionProperties?) = PlatformAssets.VELOCITY_ICON
2324

2425
override fun detect(classesRoots: MutableList<VirtualFile>): LibraryVersionProperties? {
2526
for (classesRoot in classesRoots) {
26-
// Velocity API jar has no Manifest entries, so we search for their annotation processor instead
27-
val registeredAPs = JarFile(classesRoot.localFile).use { jar ->
28-
val aps = jar.getEntry("META-INF/services/javax.annotation.processing.Processor")
29-
?: return@use null
30-
jar.getInputStream(aps).bufferedReader().use(BufferedReader::readLines)
31-
} ?: continue
27+
try {
28+
// Velocity API jar has no Manifest entries, so we search for their annotation processor instead
29+
val registeredAPs = JarFile(classesRoot.localFile).use { jar ->
30+
val aps = jar.getEntry("META-INF/services/javax.annotation.processing.Processor")
31+
?: return@use null
32+
jar.getInputStream(aps).bufferedReader().use(BufferedReader::readLines)
33+
} ?: continue
3234

33-
if (registeredAPs.contains("com.velocitypowered.api.plugin.ap.PluginAnnotationProcessor")) {
34-
return LibraryVersionProperties()
35+
if (registeredAPs.contains("com.velocitypowered.api.plugin.ap.PluginAnnotationProcessor")) {
36+
return LibraryVersionProperties()
37+
}
38+
} catch (ignored: IOException) {
3539
}
3640
}
3741
return null

0 commit comments

Comments
 (0)