]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10661 Use ZipUtils from Orchestrator in integration tests
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Fri, 11 May 2018 08:21:52 +0000 (10:21 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 14 May 2018 18:20:48 +0000 (20:20 +0200)
tests/src/test/java/org/sonarqube/tests/source/NoScmThenScmTest.java
tests/src/test/java/org/sonarqube/tests/source/ScmThenNoScmTest.java
tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java [deleted file]

index f44fc83c68a5843e757b4cc9d9a5526b8079a01b..0edc2048d54e858bb675ac9c2f31aee305256126 100644 (file)
@@ -33,11 +33,11 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonarqube.qa.util.Tester;
 
+import static com.sonar.orchestrator.util.ZipUtils.unzip;
 import static org.apache.commons.io.FileUtils.copyDirectory;
 import static org.apache.commons.io.FileUtils.moveFile;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonarqube.tests.source.SourceSuite.ORCHESTRATOR;
-import static org.sonarqube.tests.source.ZipUtils.unzip;
 import static util.ItUtils.projectDir;
 
 public class NoScmThenScmTest {
@@ -77,7 +77,7 @@ public class NoScmThenScmTest {
     assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
 
     // Restore SCM Repository
-    unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+    unzip(new File(source, "scm-repository.zip"), source);
 
     // 2nd run
     orchestrator.executeBuild(newScannerWithSCM(source));
@@ -104,7 +104,7 @@ public class NoScmThenScmTest {
     assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
 
     // Restore SCM Repository
-    unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+    unzip(new File(source, "scm-repository.zip"), source);
 
     // Swap analysed fo to a modified one
     File sample = new File(source, PATH_TO_SAMPLE);
@@ -140,7 +140,7 @@ public class NoScmThenScmTest {
     assertThat(scmData.get(1).date).isInSameMinuteWindowAs(new Date());
 
     // Restore SCM Repository
-    unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+    unzip(new File(source, "scm-repository.zip"), source);
 
     // Swap analysed fo to a modified one
     File sample = new File(source, PATH_TO_SAMPLE);
index 2a61e74dd3720002ee90eaa6ac2580a81983af88..5e035e9e5cb958e4a9bd7ebb67f6371a2f007cfd 100644 (file)
@@ -35,12 +35,12 @@ import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
 import org.sonarqube.qa.util.Tester;
 
+import static com.sonar.orchestrator.util.ZipUtils.unzip;
 import static org.apache.commons.io.FileUtils.copyDirectory;
 import static org.apache.commons.io.FileUtils.deleteDirectory;
 import static org.apache.commons.io.FileUtils.moveFile;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.sonarqube.tests.source.SourceSuite.ORCHESTRATOR;
-import static org.sonarqube.tests.source.ZipUtils.unzip;
 import static util.ItUtils.projectDir;
 
 public class ScmThenNoScmTest {
@@ -64,7 +64,7 @@ public class ScmThenNoScmTest {
   public void with_and_then_without_scm_on_same_file() throws ParseException, IOException {
 
     File source = disposableWorkspaceFor("xoo-sample-with-then-without-scm");
-    unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+    unzip(new File(source, "scm-repository.zip"), source);
 
     // First run
     SonarScanner scanner = SonarScanner.create(source)
@@ -99,7 +99,7 @@ public class ScmThenNoScmTest {
   public void with_and_then_without_scm_on_modified_file() throws ParseException, IOException {
 
     File source = disposableWorkspaceFor("xoo-sample-with-then-without-scm");
-    unzip(new File(source, "scm-repository.zip"), source.getAbsolutePath());
+    unzip(new File(source, "scm-repository.zip"), source);
 
     // First run
     SonarScanner scanner = SonarScanner.create(source)
diff --git a/tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java b/tests/src/test/java/org/sonarqube/tests/source/ZipUtils.java
deleted file mode 100644 (file)
index 258cc38..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2018 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program 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.
- *
- * This program 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.sonarqube.tests.source;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-public class ZipUtils {
-
-  // I see that we have apache commons compress in the path so it should be possible to reduce the boiler plate
-  // -- but nothing out of the box : still have to walk the tree and uncompress file by file.
-
-  static void unzip(File archive, String directory) throws IOException {
-    try (ZipInputStream zis = new ZipInputStream(new FileInputStream(archive))) {
-
-      ZipEntry entry = zis.getNextEntry();
-      while (entry != null) {
-
-        File file = new File(directory, entry.getName());
-
-        if (entry.isDirectory()) {
-          file.mkdirs();
-        } else {
-
-          File parent = file.getParentFile();
-          if (!parent.exists()) {
-            parent.mkdirs();
-          }
-
-          try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
-            long size = entry.getSize();
-            byte[] buffer = new byte[Math.toIntExact(size)];
-            if (size > 0) {
-              int location;
-              while ((location = zis.read(buffer)) != -1) {
-                bos.write(buffer, 0, location);
-              }
-            }
-          }
-
-        }
-
-        entry = zis.getNextEntry();
-      }
-    }
-  }
-
-}