Search in sources :

Example 1 with ZipUtil

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

the class UrlBasedArtifactsRepositoryTest method setUp.

@Before
public void setUp() throws Exception {
    artifactFolder = TestFileUtil.createTempFolder("artifact_folder");
    tempFile = TestFileUtil.createTestFile(artifactFolder, "file.txt");
    console = new TestStreamConsumer();
    artifactsRepository = new UrlBasedArtifactsRepository(httpService, "http://baseurl/artifacts/", "http://baseurl/properties/", new ZipUtil());
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) TestStreamConsumer(com.thoughtworks.go.helper.TestStreamConsumer) Before(org.junit.Before)

Example 2 with ZipUtil

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

the class DownloadDirCommandExecutorTest method downloadDirWithChecksum.

@Test
public void downloadDirWithChecksum() throws Exception {
    File folder = TestFileUtil.createTempFolder("log");
    Files.write(Paths.get(folder.getPath(), "a"), "content for a".getBytes());
    Files.write(Paths.get(folder.getPath(), "b"), "content for b".getBytes());
    File zip = new ZipUtil().zip(folder, TestFileUtil.createUniqueTempFile(folder.getName()), Deflater.NO_COMPRESSION);
    httpService.setupDownload("http://far.far.away/log.zip", zip);
    httpService.setupDownload("http://far.far.away/log.zip.md5", "s/log/a=524ebd45bd7de3616317127f6e639bd6\ns/log/b=83c0aa3048df233340203c74e8a93d7d");
    runBuild(downloadDir(map("url", "http://far.far.away/log.zip", "dest", "dest", "src", "s/log", "checksumUrl", "http://far.far.away/log.zip.md5")), Passed);
    File dest = new File(sandbox, "dest");
    assertThat(console.output(), containsString(String.format("Saved artifact to [%s] after verifying the integrity of its contents", dest.getPath())));
    assertThat(FileUtil.readContentFromFile(new File(dest, "log/a")), is("content for a"));
    assertThat(FileUtil.readContentFromFile(new File(dest, "log/b")), is("content for b"));
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) File(java.io.File) Test(org.junit.Test)

Example 3 with ZipUtil

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

the class FetchArtifactBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    File folder = TestFileUtil.createTempFolder("log");
    File consolelog = new File(folder, "console.log");
    folder.mkdirs();
    consolelog.createNewFile();
    zip = new ZipUtil().zip(folder, TestFileUtil.createUniqueTempFile(folder.getName()), Deflater.NO_COMPRESSION);
    toClean.add(folder);
    toClean.add(zip);
    dest = new File("dest");
    dest.mkdirs();
    toClean.add(dest);
    clock = new TestingClock();
    publisher = new StubGoPublisher();
    checksumFileHandler = mock(ChecksumFileHandler.class);
    urlService = mock(URLService.class);
    downloadAction = mock(DownloadAction.class);
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) URLService(com.thoughtworks.go.util.URLService) File(java.io.File) TestingClock(com.thoughtworks.go.util.TestingClock) Before(org.junit.Before)

Example 4 with ZipUtil

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

the class DefaultPluginJarChangeListener method explodePluginJarToBundleDir.

void explodePluginJarToBundleDir(File file, File location) {
    try {
        wipePluginBundleDirectory(location);
        ZipUtil zipUtil = new ZipUtil();
        zipUtil.unzip(file, location);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Failed to copy plugin jar %s to bundle location %s", file, location), e);
    }
}
Also used : ZipUtil(com.thoughtworks.go.util.ZipUtil) IOException(java.io.IOException)

Example 5 with ZipUtil

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

the class PluginsZipTest method shouldFailGracefullyWhenBundledFileCannotBeRead.

@Test(expected = FileAccessRightsCheckException.class)
public void shouldFailGracefullyWhenBundledFileCannotBeRead() throws Exception {
    SystemEnvironment systemEnvironmentFail = mock(SystemEnvironment.class);
    when(systemEnvironmentFail.get(SystemEnvironment.PLUGIN_FRAMEWORK_ENABLED)).thenReturn(true);
    when(systemEnvironmentFail.get(PLUGIN_GO_PROVIDED_PATH)).thenReturn("");
    when(systemEnvironmentFail.get(PLUGIN_EXTERNAL_PROVIDED_PATH)).thenReturn(externalPluginsDir.getAbsolutePath());
    when(systemEnvironmentFail.get(ALL_PLUGINS_ZIP_PATH)).thenReturn("");
    FileUtils.writeStringToFile(new File(externalPluginsDir, "external1.jar"), "External1");
    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)

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