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,
|
public static File zipDir(String dirToZip, String zipFile) throws IOException {
|
||||||
boolean excludeToplevelFolder) throws IOException {
|
ZipArchiver archiver = new ZipArchiver();
|
||||||
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
|
archiver.addDirectory(new File(dirToZip));
|
||||||
try {
|
File zip = new File(zipFile);
|
||||||
File srcFile = new File(fileToZip);
|
archiver.setDestFile(zip);
|
||||||
if (excludeToplevelFolder && srcFile.isDirectory()) {
|
archiver.createArchive();
|
||||||
for (String fileName : srcFile.list()) {
|
return zip;
|
||||||
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,
|
|
||||||
ZipOutputStream zipOut) throws IOException {
|
|
||||||
File file = new File(srcFile);
|
|
||||||
String filePath = ("".equals(path) ? file.getName()
|
|
||||||
: path + "/" + file.getName());
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
for (String fileName : file.list()) {
|
|
||||||
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