mirror of https://github.com/apache/jclouds.git
Using plexus-archiver to make the WAR file for testing
This commit is contained in:
parent
eb5d50762e
commit
da23bfae1a
|
@ -60,6 +60,12 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-archiver</artifactId>
|
||||||
|
<version>2.1.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
|
@ -21,7 +21,7 @@ package org.jclouds.demo.tweetstore.integration;
|
||||||
import static com.google.common.collect.Iterables.find;
|
import static com.google.common.collect.Iterables.find;
|
||||||
import static com.google.common.io.Closeables.closeQuietly;
|
import static com.google.common.io.Closeables.closeQuietly;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import static org.jclouds.demo.tweetstore.integration.util.Zips.zipFile;
|
import static org.jclouds.demo.tweetstore.integration.util.Zips.zipDir;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
@ -88,7 +88,7 @@ public class RhcloudServer {
|
||||||
|
|
||||||
protected ServerDeploymentActionResult deploy(String explodedWar)
|
protected ServerDeploymentActionResult deploy(String explodedWar)
|
||||||
throws IOException, InterruptedException, ExecutionException {
|
throws IOException, InterruptedException, ExecutionException {
|
||||||
File war = zipFile(explodedWar, format("%s-rhcloud.war", explodedWar), true);
|
File war = zipDir(explodedWar, format("%s-rhcloud.war", explodedWar));
|
||||||
final String deploymentName = war.getName();
|
final String deploymentName = war.getName();
|
||||||
|
|
||||||
DeploymentPlan plan =
|
DeploymentPlan plan =
|
||||||
|
|
|
@ -19,55 +19,18 @@
|
||||||
package org.jclouds.demo.tweetstore.integration.util;
|
package org.jclouds.demo.tweetstore.integration.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
import org.codehaus.plexus.archiver.zip.ZipArchiver;
|
||||||
|
|
||||||
public class Zips {
|
public class Zips {
|
||||||
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
|
|
||||||
|
|
||||||
public static File zipFile(String fileToZip, String zipFile,
|
|
||||||
boolean excludeToplevelFolder) throws IOException {
|
|
||||||
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
|
|
||||||
try {
|
|
||||||
File srcFile = new File(fileToZip);
|
|
||||||
if (excludeToplevelFolder && srcFile.isDirectory()) {
|
|
||||||
for (String fileName : srcFile.list()) {
|
|
||||||
addToZip("", fileToZip + "/" + fileName, zipOut);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addToZip("", fileToZip, zipOut);
|
|
||||||
}
|
|
||||||
zipOut.flush();
|
|
||||||
} finally {
|
|
||||||
zipOut.close();
|
|
||||||
}
|
|
||||||
return new File(zipFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void addToZip(String path, String srcFile,
|
public static File zipDir(String dirToZip, String zipFile) throws IOException {
|
||||||
ZipOutputStream zipOut) throws IOException {
|
ZipArchiver archiver = new ZipArchiver();
|
||||||
File file = new File(srcFile);
|
archiver.addDirectory(new File(dirToZip));
|
||||||
String filePath = ("".equals(path) ? file.getName()
|
File zip = new File(zipFile);
|
||||||
: path + "/" + file.getName());
|
archiver.setDestFile(zip);
|
||||||
if (file.isDirectory()) {
|
archiver.createArchive();
|
||||||
for (String fileName : file.list()) {
|
return zip;
|
||||||
addToZip(filePath, srcFile + "/" + fileName, zipOut);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
zipOut.putNextEntry(new ZipEntry(filePath));
|
|
||||||
FileInputStream in = new FileInputStream(srcFile);
|
|
||||||
try {
|
|
||||||
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
|
||||||
int len;
|
|
||||||
while ((len = in.read(buffer)) != -1) {
|
|
||||||
zipOut.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue