diff options
author | Godin <mandrikov@gmail.com> | 2010-11-01 14:05:02 +0000 |
---|---|---|
committer | Godin <mandrikov@gmail.com> | 2010-11-01 14:05:02 +0000 |
commit | e22ca92f752d628a2371d7a95a50e71dfabcfc69 (patch) | |
tree | 8975a6ede7bc3312629e3dbb6978254f32236ee8 /subprojects | |
parent | 18f5954e4f29173ca675df8a7f2d800d18aec283 (diff) | |
download | sonarqube-e22ca92f752d628a2371d7a95a50e71dfabcfc69.tar.gz sonarqube-e22ca92f752d628a2371d7a95a50e71dfabcfc69.zip |
Add a more meaningful error message when a plugin manifest can't be read
Diffstat (limited to 'subprojects')
2 files changed, 19 insertions, 10 deletions
diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java index 3090793fca3..4934978abba 100644 --- a/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/main/java/org/sonar/updatecenter/common/PluginManifest.java @@ -19,8 +19,6 @@ */ package org.sonar.updatecenter.common; -import static org.sonar.updatecenter.common.FormatUtils.toDate; - import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ReflectionToStringBuilder; @@ -31,6 +29,8 @@ import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; +import static org.sonar.updatecenter.common.FormatUtils.toDate; + /** * This class loads Sonar plugin metadata from JAR manifest. * @@ -78,14 +78,18 @@ public final class PluginManifest { * Load the manifest from a JAR file. */ public PluginManifest(File file) throws IOException { - JarFile jar = new JarFile(file); + JarFile jar = null; try { + jar = new JarFile(file); if (jar.getManifest() != null) { loadManifest(jar.getManifest()); } - + } catch (Exception e) { + throw new RuntimeException("Unable to read plugin manifest from jar : " + file.getAbsolutePath(), e); } finally { - jar.close(); + if (jar != null) { + jar.close(); + } } } diff --git a/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginManifestTest.java b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginManifestTest.java index 70d3dd666a4..6be112ae20c 100644 --- a/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginManifestTest.java +++ b/subprojects/sonar-update-center/sonar-update-center-common/src/test/java/org/sonar/updatecenter/common/PluginManifestTest.java @@ -19,11 +19,6 @@ */ package org.sonar.updatecenter.common; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.hamcrest.number.OrderingComparisons.greaterThan; -import static org.junit.Assert.assertThat; - import org.junit.Test; import java.io.File; @@ -31,8 +26,18 @@ import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.nullValue; +import static org.hamcrest.number.OrderingComparisons.greaterThan; +import static org.junit.Assert.assertThat; + public class PluginManifestTest { + @Test(expected = RuntimeException.class) + public void test() throws Exception { + new PluginManifest(new File("fake.jar")); + } + @Test public void testCreateManifest() throws URISyntaxException, IOException { URL jar = getClass().getResource("/org/sonar/updatecenter/common/PluginManifestTest/checkstyle-plugin.jar"); |