[java-idp-jetty-base] 01/02: JJETTY-13 Implement Jetty-base plugin V2
Rod Widdowson
rdw at steadingsoftware.com
Tue Jul 15 09:57:00 UTC 2025
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch dev/JJETTY-13
in repository java-idp-jetty-base.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-jetty-base.git;a=commit;h=db67b8a8ec02873e328d389cc6546eeaa2a1c2a2
commit db67b8a8ec02873e328d389cc6546eeaa2a1c2a2
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Tue Jul 15 10:45:45 2025 +0100
JJETTY-13 Implement Jetty-base plugin V2
https://shibboleth.atlassian.net/browse/JJETTY-13
Unpacking
---
jetty-cli/pom.xml | 11 +--
.../jetty/cli/impl/JettyDownloadArguments.java | 1 -
.../plugin/jetty/cli/impl/JettyDownloadCLI.java | 82 +++++++++++++++++++++-
.../jetty/cli/impl/JettyDownloadCLITest.java | 3 +
jetty-cli/src/test/resources/logback-test.xml | 7 +-
5 files changed, 96 insertions(+), 8 deletions(-)
diff --git a/jetty-cli/pom.xml b/jetty-cli/pom.xml
index 34c0393..4a96ca1 100644
--- a/jetty-cli/pom.xml
+++ b/jetty-cli/pom.xml
@@ -68,20 +68,23 @@
<artifactId>bcpg-jdk18on</artifactId>
<scope>provided</scope>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-compress</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Test Dependencies -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
-
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
-
-
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
diff --git a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
index eea348a..c582e6e 100644
--- a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
+++ b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadArguments.java
@@ -77,7 +77,6 @@ public class JettyDownloadArguments extends AbstractIdPHomeAwareCommandLineArgum
@Parameter(names= {"--nounpack"})
@Nonnull private boolean noUnpack;
-
/** {@inheritDoc} */
@Override
public Logger getLog() {
diff --git a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
index 78eb5fe..0e6e2ca 100644
--- a/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
+++ b/jetty-cli/src/main/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLI.java
@@ -14,9 +14,11 @@
package net.shibboleth.idp.plugin.jetty.cli.impl;
import java.io.BufferedInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.Security;
@@ -25,6 +27,12 @@ import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.io.IOUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.opensaml.security.httpclient.HttpClientSecurityContextHandler;
import org.opensaml.security.httpclient.HttpClientSecurityParameters;
@@ -232,7 +240,6 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
return RC_OK;
}
-
/** Check the signature on the downloaded files.
* @param args the {@link JettyDownloadArguments} we were given.
* @return an RC result
@@ -266,11 +273,84 @@ public class JettyDownloadCLI extends AbstractIdPHomeAwareCommandLine<JettyDownl
return RC_OK;
}
+ /** Build an appropriate {@link ArchiveInputStream}.
+ * @param fullName The file to unpack
+ * @param isZip whether is a zip file or a tar.gz
+ * @return The {@link ArchiveInputStream}.
+ * @throws IOException if badness occurrs
+ */
+ private static ArchiveInputStream<?> getStreamFor(@Nonnull final Path fullName, final boolean isZip)
+ throws IOException {
+ final InputStream inStream = new BufferedInputStream(new FileInputStream(fullName.toFile()));
+ if (isZip) {
+ return new ZipArchiveInputStream(inStream);
+ }
+ return new TarArchiveInputStream(new GzipCompressorInputStream(inStream));
+ }
+
/** Unpack the downloaded file.
* @param args the {@link JettyDownloadArguments} we were given.
* @return an RC result
*/
private int unpack(JettyDownloadArguments args) {
+
+ if (args.isNoUnpack()) {
+ return RC_OK;
+ }
+
+ final boolean isZip;
+ if (args.getType().equalsIgnoreCase("zip")) {
+ isZip = true;
+ } else if (args.getType().equalsIgnoreCase("tar.gz")) {
+ isZip = false;
+ } else {
+ log.error("Unexpected type {}", args.getType());
+ return RC_IO;
+ }
+
+ final Path downloadfilePath = downloadsDir.resolve(downloadFileName);
+ //
+ // The zip files start with the stuff we need so we add the dirname
+ // The tar.gz files have the dir name as the top level
+ //
+ final Path downloadDirPath;
+ if (isZip) {
+ downloadDirPath = downloadsDir.resolve(downloadDirName);
+ } else {
+ downloadDirPath = downloadsDir;
+ }
+
+ try (final ArchiveInputStream<?> inStream = getStreamFor(downloadfilePath, isZip)) {
+ ArchiveEntry entry = null;
+ while ((entry = inStream.getNextEntry()) != null) {
+ if (!inStream.canReadEntryData(entry)) {
+ log.warn("Could not read next entry from {}", inStream);
+ continue;
+ }
+
+ final File output = downloadDirPath.resolve(entry.getName()).toFile();
+ log.trace("Unpacking {} to {}", entry.getName(), output);
+ if (entry.isDirectory()) {
+ if (!output.isDirectory() && !output.mkdirs()) {
+ log.error("Failed to create directory {}", output);
+ return RC_IO;
+ }
+ } else {
+ final File parent = output.getParentFile();
+ if (!parent.isDirectory() && !parent.mkdirs()) {
+ log.error("Failed to create directory {}", parent);
+ return RC_IO;
+ }
+ try (OutputStream outStream = Files.newOutputStream(output.toPath())) {
+ IOUtils.copy(inStream, outStream);
+ }
+ }
+ }
+ } catch (final IOException e) {
+ log.error("Could not unpack ", downloadFileName, e);
+ return RC_IO;
+ }
+
return RC_OK;
}
diff --git a/jetty-cli/src/test/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLITest.java b/jetty-cli/src/test/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLITest.java
index 1372ca2..30efc30 100644
--- a/jetty-cli/src/test/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLITest.java
+++ b/jetty-cli/src/test/java/net/shibboleth/idp/plugin/jetty/cli/impl/JettyDownloadCLITest.java
@@ -15,6 +15,7 @@
package net.shibboleth.idp.plugin.jetty.cli.impl;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.nio.file.FileVisitResult;
@@ -78,6 +79,7 @@ public class JettyDownloadCLITest {
@Test public void TestDownloadJetty() {
assertEquals(JettyDownloadCLI.runMain(new String[] {"-v", "12.0.23"}), AbstractCommandLine.RC_OK);
+ assertTrue(idpHome.resolve("jetty-downloads/jetty-home-12.0.23/jetty-home-12.0.23-cyclonedx.json").toFile().exists());
}
@Test public void TestDownloadProcrun() {
@@ -87,6 +89,7 @@ public class JettyDownloadCLITest {
"--groupId", "commons-daemon",
"--artifactId","commons-daemon"
}), AbstractCommandLine.RC_OK);
+ assertTrue(idpHome.resolve("jetty-downloads/commons-daemon-1.4.1/LICENSE.txt").toFile().exists());
}
}
diff --git a/jetty-cli/src/test/resources/logback-test.xml b/jetty-cli/src/test/resources/logback-test.xml
index 042bb58..a868ddb 100644
--- a/jetty-cli/src/test/resources/logback-test.xml
+++ b/jetty-cli/src/test/resources/logback-test.xml
@@ -13,8 +13,11 @@
</appender>
<root>
- <level value="DEBUG" />
+ <level value="INFO" />
<appender-ref ref="STDOUT" />
</root>
-</configuration>
\ No newline at end of file
+ <logger name="net.shibboleth.idp.plugin.jetty" level="TRACE" />
+ <logger name="net.shibboleth.idp.installer" level="DEBUG" />
+
+</configuration>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list