diff options
author | Jenkins CI <ci@sonarsource.com> | 2015-10-14 08:01:18 +0200 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2015-10-14 08:01:18 +0200 |
commit | e51e9c9eb0145ea5e9d40453554c456585b79936 (patch) | |
tree | 8b1adf27c56a12e762cdd304f09311cc7fff77bb /sonar-core | |
parent | 8350b39ed0563e9beb354fe27524c95ea4692b67 (diff) | |
parent | 3afe7a9001453a7106c488a1429e3bff91c8545f (diff) | |
download | sonarqube-e51e9c9eb0145ea5e9d40453554c456585b79936.tar.gz sonarqube-e51e9c9eb0145ea5e9d40453554c456585b79936.zip |
Automatic merge from branch-5.1
* origin/branch-5.2:
Improve message when trying to install a non-plugin JAR
Fix enforcer rule about size of zip
Fix reliability of NetworkUtils#freePort()
Fix Maven warnings
SONAR-6219 Fix ruby warning "don't put space before argument parentheses"
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java | 9 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java | 19 |
2 files changed, 26 insertions, 2 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java index 5d2759332eb..3ae4dc4543c 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java @@ -27,6 +27,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ComparisonChain; import com.google.common.collect.Ordering; import java.io.File; +import java.io.IOException; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -34,6 +35,7 @@ import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; +import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.Loggers; import org.sonar.updatecenter.common.PluginManifest; import org.sonar.updatecenter.common.Version; @@ -137,7 +139,7 @@ public class PluginInfo implements Comparable<PluginInfo> { private final Set<RequiredPlugin> requiredPlugins = new HashSet<>(); public PluginInfo(String key) { - Preconditions.checkNotNull(key); + Preconditions.checkNotNull(key, "Plugin key is missing from manifest"); this.key = key; this.name = key; } @@ -364,13 +366,16 @@ public class PluginInfo implements Comparable<PluginInfo> { PluginManifest manifest = new PluginManifest(jarFile); return create(jarFile, manifest); - } catch (Exception e) { + } catch (IOException e) { throw new IllegalStateException("Fail to extract plugin metadata from file: " + jarFile, e); } } @VisibleForTesting static PluginInfo create(File jarFile, PluginManifest manifest) { + if (StringUtils.isBlank(manifest.getKey())) { + throw MessageException.of(String.format("File is not a plugin. Please delete it and restart: %s", jarFile.getAbsolutePath())); + } PluginInfo info = new PluginInfo(manifest.getKey()); info.setJarFile(jarFile); diff --git a/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java b/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java index 35893ede34e..1472639b0c6 100644 --- a/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/platform/PluginInfoTest.java @@ -28,7 +28,10 @@ import org.apache.commons.io.FileUtils; import org.assertj.core.api.Assertions; import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.sonar.api.utils.MessageException; +import org.sonar.api.utils.ZipUtils; import org.sonar.updatecenter.common.PluginManifest; import org.sonar.updatecenter.common.Version; @@ -41,6 +44,9 @@ public class PluginInfoTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); + @Rule + public ExpectedException expectedException = ExpectedException.none(); + @Test public void test_RequiredPlugin() throws Exception { PluginInfo.RequiredPlugin plugin = PluginInfo.RequiredPlugin.parse("java:1.1"); @@ -212,7 +218,20 @@ public class PluginInfoTest { public void l10n_plugins_should_not_extend_english_plugin() { PluginInfo pluginInfo = new PluginInfo("l10nfr").setBasePlugin("l10nen"); assertThat(pluginInfo.getBasePlugin()).isNull(); + } + + @Test + public void fail_when_jar_is_not_a_plugin() throws IOException { + // this JAR has a manifest but is not a plugin + File jarRootDir = temp.newFolder(); + FileUtils.write(new File(jarRootDir, "META-INF/MANIFEST.MF"), "Build-Jdk: 1.6.0_15"); + File jar = temp.newFile(); + ZipUtils.zipDir(jarRootDir, jar); + + expectedException.expect(MessageException.class); + expectedException.expectMessage("File is not a plugin. Please delete it and restart: " + jar.getAbsolutePath()); + PluginInfo.create(jar); } PluginInfo withMinSqVersion(@Nullable String version) { |