From f2b39ccc3223c71b741b443ebc36999352958080 Mon Sep 17 00:00:00 2001
From: Simon Brandhof <simon.brandhof@gmail.com>
Date: Sun, 16 Mar 2014 14:06:00 +0100
Subject: Refactor plugin management for better maintainability

---
 .../batch/bootstrap/BatchPluginInstallerTest.java  |  77 ---------------------
 .../bootstrap/BatchPluginJarInstallerTest.java     |  77 +++++++++++++++++++++
 .../batch/bootstrap/BatchPluginRepositoryTest.java |   6 +-
 .../sonar-checkstyle-plugin-2.8.jar                | Bin 1026947 -> 0 bytes
 .../sonar-checkstyle-plugin-2.8.jar                | Bin 0 -> 1026947 bytes
 5 files changed, 80 insertions(+), 80 deletions(-)
 delete mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
 create mode 100644 sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest.java
 delete mode 100644 sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginInstallerTest/sonar-checkstyle-plugin-2.8.jar
 create mode 100644 sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/sonar-checkstyle-plugin-2.8.jar

(limited to 'sonar-batch/src/test')

diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
deleted file mode 100644
index de903420e73..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginInstallerTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.batch.bootstrap;
-
-import org.apache.commons.io.FileUtils;
-import org.junit.Before;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.core.plugins.DefaultPluginMetadata;
-import org.sonar.home.cache.FileCacheBuilder;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class BatchPluginInstallerTest {
-
-  private BatchPluginInstaller extractor;
-
-  @ClassRule
-  public static TemporaryFolder temporaryFolder = new TemporaryFolder();
-
-  private File userHome;
-
-  @Before
-  public void setUp() throws IOException {
-    userHome = temporaryFolder.newFolder();
-    extractor = new BatchPluginInstaller(new FileCacheBuilder().setUserHome(userHome).build());
-  }
-
-  @Test
-  public void should_copy_and_extract_dependencies() throws IOException {
-    File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
-    DefaultPluginMetadata metadata = extractor.installToCache(fileFromCache, true);
-
-    assertThat(metadata.getKey()).isEqualTo("checkstyle");
-    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
-    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
-  }
-
-  @Test
-  public void should_extract_only_dependencies() throws IOException {
-    File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
-    extractor.installToCache(fileFromCache, true);
-
-    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
-    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist();
-    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/org/sonar/plugins/checkstyle/CheckstyleVersion.class")).doesNotExist();
-  }
-
-  File getFileFromCache(String filename) throws IOException {
-    File src = FileUtils.toFile(BatchPluginInstallerTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginInstallerTest/" + filename));
-    File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
-    FileUtils.copyFile(src, destFile);
-    return destFile;
-  }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest.java
new file mode 100644
index 00000000000..52b80a87d5d
--- /dev/null
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest.java
@@ -0,0 +1,77 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.batch.bootstrap;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.core.plugins.DefaultPluginMetadata;
+import org.sonar.home.cache.FileCacheBuilder;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+public class BatchPluginJarInstallerTest {
+
+  private BatchPluginJarInstaller extractor;
+
+  @ClassRule
+  public static TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  private File userHome;
+
+  @Before
+  public void setUp() throws IOException {
+    userHome = temporaryFolder.newFolder();
+    extractor = new BatchPluginJarInstaller(new FileCacheBuilder().setUserHome(userHome).build());
+  }
+
+  @Test
+  public void should_copy_and_extract_dependencies() throws IOException {
+    File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
+    DefaultPluginMetadata metadata = extractor.installToCache(fileFromCache, true);
+
+    assertThat(metadata.getKey()).isEqualTo("checkstyle");
+    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
+    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
+  }
+
+  @Test
+  public void should_extract_only_dependencies() throws IOException {
+    File fileFromCache = getFileFromCache("sonar-checkstyle-plugin-2.8.jar");
+    extractor.installToCache(fileFromCache, true);
+
+    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
+    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/MANIFEST.MF")).doesNotExist();
+    assertThat(new File(fileFromCache.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/org/sonar/plugins/checkstyle/CheckstyleVersion.class")).doesNotExist();
+  }
+
+  File getFileFromCache(String filename) throws IOException {
+    File src = FileUtils.toFile(BatchPluginJarInstallerTest.class.getResource("/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/" + filename));
+    File destFile = new File(new File(userHome, "" + filename.hashCode()), filename);
+    FileUtils.copyFile(src, destFile);
+    return destFile;
+  }
+
+}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
index 84f92b7eab6..41a6d0048d5 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchPluginRepositoryTest.java
@@ -71,7 +71,7 @@ public class BatchPluginRepositoryTest {
     PluginDownloader downloader = mock(PluginDownloader.class);
     when(downloader.downloadPlugin(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
 
-    repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginInstaller(cache));
+    repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
 
     repository.doStart(Arrays.asList(checkstyle));
 
@@ -90,7 +90,7 @@ public class BatchPluginRepositoryTest {
     when(downloader.downloadPlugin(checkstyle)).thenReturn(fileFromCache("sonar-checkstyle-plugin-2.8.jar"));
     when(downloader.downloadPlugin(checkstyleExt)).thenReturn(fileFromCache("sonar-checkstyle-extensions-plugin-0.1-SNAPSHOT.jar"));
 
-    repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginInstaller(cache));
+    repository = new BatchPluginRepository(downloader, new Settings(), mode, new BatchPluginJarInstaller(cache));
 
     repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
 
@@ -112,7 +112,7 @@ public class BatchPluginRepositoryTest {
 
     Settings settings = new Settings();
     settings.setProperty(CoreProperties.BATCH_EXCLUDE_PLUGINS, "checkstyle");
-    repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginInstaller(cache));
+    repository = new BatchPluginRepository(downloader, settings, mode, new BatchPluginJarInstaller(cache));
 
     repository.doStart(Arrays.asList(checkstyle, checkstyleExt));
 
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginInstallerTest/sonar-checkstyle-plugin-2.8.jar b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginInstallerTest/sonar-checkstyle-plugin-2.8.jar
deleted file mode 100644
index f937399bec5..00000000000
Binary files a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginInstallerTest/sonar-checkstyle-plugin-2.8.jar and /dev/null differ
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/sonar-checkstyle-plugin-2.8.jar b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/sonar-checkstyle-plugin-2.8.jar
new file mode 100644
index 00000000000..f937399bec5
Binary files /dev/null and b/sonar-batch/src/test/resources/org/sonar/batch/bootstrap/BatchPluginJarInstallerTest/sonar-checkstyle-plugin-2.8.jar differ
-- 
cgit v1.2.3