From 3ba670a52f104083ebb6c2845f688a4c66b07b2d Mon Sep 17 00:00:00 2001 From: Walter Oggioni Date: Sun, 24 Sep 2017 19:31:02 +0200 Subject: [PATCH] updated build scripts to sbt 1.0 added service returning a tar archive with all the requested packages --- build.sbt | 24 +++++---- project/build.properties | 2 +- project/plugins.sbt | 2 +- .../jpacrepo/service/PacmanWebService.java | 52 +++++++++++++++++-- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/build.sbt b/build.sbt index 62fdd49..3f9bdaa 100644 --- a/build.sbt +++ b/build.sbt @@ -54,15 +54,17 @@ wildflyURL := "localhost:1234" val deploy2Wildfly = TaskKey[Unit]("deploy2Wildfly", "Deploy to a wildfly server instance", KeyRanks.ATask) -deploy2Wildfly <<= (packagedArtifact in(Compile, Keys.`package`), wildflyURL, wildflyUsername, wildflyPassword) map + +deploy2Wildfly := { + val cmd = s"/opt/wildfly/bin/jboss-cli.sh " + + s"--controller='${wildflyURL.value}' " + + s"--connect --user='${wildflyUsername.value}' " + + s"--password='${wildflyPassword.value}' " + + s"--command=\'deploy ${(packagedArtifact in(Compile, Keys.`package`)).value._2} --force\'" + println(cmd) + sys.process.stringToProcess(cmd).! match { - case ((art: Artifact, warFile: File), url: String, username: String, password: String) => - //val warFile = (artifactPath in Keys.`package` in Compile).value//(artifactPath in `package`).value.absolutePath //(packageBin in Compile).value //(artifactPath in (Compile, package)).value - val cmd = s"/opt/wildfly/bin/jboss-cli.sh --controller='${url}' --connect --user='${username}' --password='${password}' --command=\'deploy ${warFile.absolutePath} --force\'" - println(cmd) - sys.process.stringToProcess(cmd).! match - { - case 0 => "OK" - case _ => throw new RuntimeException("Error occurred during deploy") - } - } \ No newline at end of file + case 0 => "OK" + case _ => throw new RuntimeException("Error occurred during deploy") + } +} diff --git a/project/build.properties b/project/build.properties index 5f32afe..7b6213b 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.13.13 \ No newline at end of file +sbt.version=1.0.1 diff --git a/project/plugins.sbt b/project/plugins.sbt index 550f547..fa93a14 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1 +1 @@ -addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "2.1.0") \ No newline at end of file +addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.0.0") diff --git a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java index be1f773..0d1c257 100644 --- a/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java +++ b/src/main/java/com/oggio88/jpacrepo/service/PacmanWebService.java @@ -9,7 +9,8 @@ import com.oggio88.jpacrepo.model.PkgName; import com.oggio88.jpacrepo.model.StringList; import com.oggio88.jpacrepo.pacbase.Parser; import com.oggio88.jpacrepo.persistence.QueryEngine; -import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import javax.annotation.Resource; import javax.ejb.*; @@ -354,9 +355,54 @@ public class PacmanWebService } @POST - public Response foo() + @Path("/downloadTar") + @Produces("application/x-tar") + public Response downloadTar(List files) { - TarArchiveouputStream tais = new TarArchiveOutputStream(); + for(String fname : files) + { + if(!ctx.getFile(fname).exists()) throw new NotFoundException(String.format("Package file '%s' does not exist", fname)); + } + StreamingOutput stream = new StreamingOutput() + { + @Override + public void write(OutputStream output) throws IOException, WebApplicationException + { + TarArchiveOutputStream taos = new TarArchiveOutputStream(output); + try + { + for (String fname : files) + { + File file = ctx.getFile(fname); + FileInputStream input = new FileInputStream(file); + + TarArchiveEntry entry = new TarArchiveEntry(fname); + entry.setSize(file.length()); + taos.putArchiveEntry(entry); + byte[] bytes = new byte[1024]; + while (true) + { + int size = input.read(bytes); + if (size < 0) break; + else taos.write(bytes, 0, size); + } + taos.closeArchiveEntry(); + } + taos.close(); + output.close(); + } + catch (Exception e) + { + throw new WebApplicationException(e); + } + finally + { + taos.close(); + output.close(); + } + } + }; + return Response.ok(stream).build(); } private Response manageQueryResult(List list)