diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2011-06-10 00:15:37 +0200 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2011-06-10 00:15:37 +0200 |
commit | d574f6dd70fefa9b2e9818c71ae58a51e934697c (patch) | |
tree | 76a7df2dc3c794c02fff45e9a517ccf560cc2351 /sonar-plugin-api | |
parent | 39bca3376660b2ad6edbd4ec9fabf527a16ffe78 (diff) | |
download | sonarqube-d574f6dd70fefa9b2e9818c71ae58a51e934697c.tar.gz sonarqube-d574f6dd70fefa9b2e9818c71ae58a51e934697c.zip |
SONAR-2507 Batch must load plugins without connecting to database
Diffstat (limited to 'sonar-plugin-api')
5 files changed, 72 insertions, 2 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginMetadata.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginMetadata.java new file mode 100644 index 00000000000..7e898172770 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginMetadata.java @@ -0,0 +1,37 @@ +package org.sonar.api.platform; + +import java.io.File; +import java.util.List; + +/** + * @since 2.8 + */ +public interface PluginMetadata { + File getFile(); + + List<File> getDeployedFiles(); + + String getKey(); + + String getName(); + + String getMainClass(); + + String getDescription(); + + String getOrganization(); + + String getOrganizationUrl(); + + String getLicense(); + + String getVersion(); + + String getHomepage(); + + boolean isUseChildFirstClassLoader(); + + String getBasePlugin(); + + boolean isCore(); +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java index a9253821bf5..91556e7eb32 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/platform/PluginRepository.java @@ -32,4 +32,14 @@ public interface PluginRepository extends BatchComponent, ServerComponent { Plugin getPlugin(String key); Property[] getProperties(Plugin plugin); + + /** + * @since 2.9 + */ + Collection<PluginMetadata> getMetadata(); + + /** + * @since 2.9 + */ + PluginMetadata getMetadata(String pluginKey); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java index aba708165ed..a3893cd227c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/HttpDownloader.java @@ -159,6 +159,21 @@ public class HttpDownloader implements BatchComponent, ServerComponent { } } + public String downloadPlainText(URI uri, String encoding) { + InputStream input = null; + try { + HttpURLConnection connection = newHttpConnection(uri); + input = connection.getInputStream(); + return IOUtils.toString(input, encoding); + + } catch (Exception e) { + throw new SonarException("Fail to download the file: " + uri + " (" + getProxySynthesis(uri) + ")", e); + + } finally { + IOUtils.closeQuietly(input); + } + } + public InputStream openStream(URI uri) { try { HttpURLConnection connection = newHttpConnection(uri); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java index ef8703eb66a..21a7b3d7720 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/ZipUtils.java @@ -62,7 +62,7 @@ public final class ZipUtils { return toDir; } - public static void unzip(File zip, File toDir, ZipEntryFilter filter) throws IOException { + public static File unzip(File zip, File toDir, ZipEntryFilter filter) throws IOException { if (!toDir.exists()) { FileUtils.forceMkdir(toDir); } @@ -93,6 +93,8 @@ public final class ZipUtils { } } } + return toDir; + } finally { zipFile.close(); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java index 9378f5be342..9b1d470afef 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java @@ -43,7 +43,7 @@ import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@Ignore("Temporarily deactivated because it sometimes freezes on MS Windows") +@Ignore("Temporarily deactivated because it sometimes freezes on MS Windows") public class HttpDownloaderTest { private static ServletTester tester; @@ -162,6 +162,12 @@ public class HttpDownloaderTest { assertThat(bytes.length, greaterThan(10)); } + @Test + public void downloadPlainText() throws URISyntaxException { + String text = new HttpDownloader().downloadPlainText(new URI(baseUrl), "UTF-8"); + assertThat(text.length(), greaterThan(10)); + } + @Test(expected = SonarException.class) public void failIfServerDown() throws URISyntaxException { // I hope that the port 1 is not used ! |