added statement to rebase dist packages

This commit is contained in:
Adrian Cole 2012-08-13 14:20:27 -07:00
parent 758e01a4d2
commit cd98f16408
2 changed files with 35 additions and 0 deletions

View File

@ -171,6 +171,26 @@ public class Statements {
return new PipeHttpResponseToTarxpzfIntoDirectory(method, endpoint, headers, directory);
}
/**
* like {@link #extractTargzIntoDirectory(URI, String)} except that it
* flattens the first directory in the archive
*
* For example, {@code apache-maven-3.0.4-bin.tar.gz} normally extracts
* directories like {@code ./apache-maven-3.0.4/bin}. This command eliminates
* the intermediate directory, in the example {@code ./apache-maven-3.0.4/}
*
* @param tgz remote ref to download
* @param dest path where the files in the intermediate directory will end
*/
public static Statement extractTargzAndFlattenIntoDirectory(URI tgz, String dest) {
return new StatementList(ImmutableSet.<Statement> builder()
.add(exec("mkdir /tmp/$$"))
.add(extractTargzIntoDirectory(tgz, "/tmp/$$"))
.add(exec("mkdir -p " + dest))
.add(exec("mv /tmp/$$/*/* " + dest))
.add(exec("rm -rf /tmp/$$")).build());
}
public static Statement extractTargzIntoDirectory(URI targz, String directory) {
return extractTargzIntoDirectory("GET", targz, ImmutableMultimap.<String, String> of(), directory);
}

View File

@ -48,5 +48,20 @@ public class StatementsTest {
save.render(OsFamily.UNIX),
"curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.tar.gz |(mkdir -p /opt/minecraft &&cd /opt/minecraft &&tar -xpzf -)\n");
}
public void testExtractTargzAndFlattenIntoDirectoryUNIX() {
Statement save = Statements
.extractTargzAndFlattenIntoDirectory(
URI.create("http://www.us.apache.org/dist/maven/binaries/apache-maven-3.0.4-bin.tar.gz"),
"/usr/local/maven");
assertEquals(
save.render(OsFamily.UNIX),
"mkdir /tmp/$$\n" +
"curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://www.us.apache.org/dist/maven/binaries/apache-maven-3.0.4-bin.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -)\n" +
"mkdir -p /usr/local/maven\n" +
"mv /tmp/$$/*/* /usr/local/maven\n" +
"rm -rf /tmp/$$\n");
}
}