Search in sources :

Example 16 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class FileView method setOutput.

private void setOutput(boolean needToZip, File file, HttpServletResponse response) throws IOException {
    ServletOutputStream out = response.getOutputStream();
    if (needToZip) {
        new ZipUtil().zip(file, out, Deflater.NO_COMPRESSION);
    } else {
        IOUtils.copy(new FileInputStream(file), out);
    }
    out.flush();
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) ServletOutputStream(javax.servlet.ServletOutputStream) FileInputStream(java.io.FileInputStream)

Example 17 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class DatabaseFixture method copyH2Db.

public void copyH2Db(String oldDb) throws IOException {
    File h2DbDir = new File(tmpDb, "h2db");
    if (h2DbDir.exists()) {
        h2DbDir.delete();
        h2DbDir.mkdirs();
    }
    new ZipUtil().unzip(new File(templatesDir(), oldDb), h2DbDir);
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File)

Example 18 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PluginsZipTest method setUp.

@Before
public void setUp() throws Exception {
    temporaryFolder.create();
    systemEnvironment = mock(SystemEnvironment.class);
    File bundledPluginsDir = temporaryFolder.newFolder("plugins-bundled");
    expectedZipPath = temporaryFolder.newFile("go-plugins-all.zip").getAbsolutePath();
    externalPluginsDir = temporaryFolder.newFolder("plugins-external");
    when(systemEnvironment.get(SystemEnvironment.PLUGIN_FRAMEWORK_ENABLED)).thenReturn(true);
    when(systemEnvironment.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath());
    when(systemEnvironment.get(ALL_PLUGINS_ZIP_PATH)).thenReturn(expectedZipPath);
    pluginsZip = new PluginsZip(systemEnvironment, new ZipUtil());
    FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled1.jar"), "Bundled1");
    FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled2.jar"), "Bundled2");
    FileUtils.writeStringToFile(new File(externalPluginsDir, "external1.jar"), "External1");
    FileUtils.writeStringToFile(new File(externalPluginsDir, "external2.jar"), "External2");
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) ZipFile(java.util.zip.ZipFile) Before(org.junit.Before)

Example 19 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PluginsZipTest method shouldFailGracefullyWhenExternalFileCannotBeRead.

@Test(expected = FileAccessRightsCheckException.class)
public void shouldFailGracefullyWhenExternalFileCannotBeRead() throws Exception {
    File bundledPluginsDir = temporaryFolder.newFolder("plugins-bundled-ext");
    SystemEnvironment systemEnvironmentFail = mock(SystemEnvironment.class);
    when(systemEnvironmentFail.get(SystemEnvironment.PLUGIN_FRAMEWORK_ENABLED)).thenReturn(true);
    when(systemEnvironmentFail.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn(bundledPluginsDir.getAbsolutePath());
    when(systemEnvironmentFail.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn("");
    when(systemEnvironmentFail.get(ALL_PLUGINS_ZIP_PATH)).thenReturn("");
    FileUtils.writeStringToFile(new File(bundledPluginsDir, "bundled1.jar"), "Bundled1");
    PluginsZip pluginsZipFail = new PluginsZip(systemEnvironmentFail, new ZipUtil());
    pluginsZipFail.create();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 20 with ZipUtil

use of com.thoughtworks.go.util.ZipUtil in project gocd by gocd.

the class PackageLevelClassWithPublicInnerClass method explodeBundleIntoDirectory.

private File explodeBundleIntoDirectory(ZipInputStream src, String destinationDir) throws IOException, URISyntaxException {
    File destinationPluginBundleLocation = new File(TMP_DIR, destinationDir);
    destinationPluginBundleLocation.mkdirs();
    new ZipUtil().unzip(src, destinationPluginBundleLocation);
    return destinationPluginBundleLocation;
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File)

Aggregations

ZipUtil (com.thoughtworks.go.util.ZipUtil)27 File (java.io.File)21 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)8 Before (org.junit.Before)7 Test (org.junit.Test)6 ZipInputStream (java.util.zip.ZipInputStream)5 ZipFile (java.util.zip.ZipFile)4 FileInputStream (java.io.FileInputStream)3 TempFiles (com.thoughtworks.go.util.TempFiles)2 IOException (java.io.IOException)2 TestStreamConsumer (com.thoughtworks.go.helper.TestStreamConsumer)1 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)1 ArtifactsDirHolder (com.thoughtworks.go.server.service.ArtifactsDirHolder)1 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)1 ArtifactFolder (com.thoughtworks.go.server.web.ArtifactFolder)1 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)1 TestingClock (com.thoughtworks.go.util.TestingClock)1 URLService (com.thoughtworks.go.util.URLService)1 ChecksumValidator (com.thoughtworks.go.validation.ChecksumValidator)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1