[java-idp-plugin-scripting] 04/15: Make description work
Ian Young
ian at iay.org.uk
Mon Jun 22 13:03:40 UTC 2020
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch master
in repository java-idp-plugin-scripting.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=commit;h=8a3501da528c73fb44c37f02a49b9ca1fbd980ea
commit 8a3501da528c73fb44c37f02a49b9ca1fbd980ea
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed May 13 15:00:43 2020 +0100
Make description work
Add a download location too.
---
nashorn-impl/pom.xml | 29 ++++++--
.../scripting/nashorn/InstallerDetails.java | 42 ------------
.../scripting/nashorn/NashornDescription.java | 79 ++++++++++++++++++++++
.../0.0.1/version.details.properties | 3 +
.../versions.properties | 1 +
...utilities.java.support.plugin.PluginDescription | 1 +
.../plugins/scripting/nashorn/PluginTest.java | 77 +++++++++++++++++++++
nashorn-impl/src/test/resources/logback-test.xml | 19 ++++++
pom.xml | 26 +++++--
9 files changed, 224 insertions(+), 53 deletions(-)
diff --git a/nashorn-impl/pom.xml b/nashorn-impl/pom.xml
index f7421c4..f692b95 100644
--- a/nashorn-impl/pom.xml
+++ b/nashorn-impl/pom.xml
@@ -20,26 +20,42 @@
</description>
<dependencies>
- <dependency>
+ <dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
</dependency>
-
- <dependency>
+ <dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>${graalvm.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-beans</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>${idp.groupId}</groupId>
+ <artifactId>idp-installer</artifactId>
+ <version>${idp.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.graalvm.js</groupId>
+ <artifactId>js</artifactId>
+ <version>${graalvm.version}</version>
+ <scope>test</scope>
</dependency>
-
</dependencies>
<build>
<plugins>
- <plugin>
+ <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
-
<executions>
<execution>
<id>copy-dependencies</id>
@@ -48,7 +64,6 @@
<goal>copy-dependencies</goal>
</goals>
<configuration>
- <!-- <excludeTransitive>true</excludeTransitive> -->
<outputDirectory>target/dependency</outputDirectory>
</configuration>
</execution>
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/InstallerDetails.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/InstallerDetails.java
deleted file mode 100644
index 681874c..0000000
--- a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/InstallerDetails.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- *
- */
-package net.shibboleth.plugins.scripting.nashorn;
-
-import java.util.List;
-
-import net.shibboleth.utilities.java.support.plugin.PluginInstaller;
-import net.shibboleth.utilities.java.support.resource.Resource;
-
-/**
- * Details about the nashorn scripting plugin
- *
- */
-public class InstallerDetails extends PluginInstaller {
-
- @Override
- public String getPluginId() {
- return "net.shibboleth.plugins.scripting.nashorn";
- }
-
- @Override
- public List<Resource> getUpdateResources() {
- return ;
- }
-
- @Override
- public int getMajorVersion() {
- return 0;
- }
-
- @Override
- public int getMinorVersion() {
- return 0;
- }
-
- @Override
- public int getPatchVersion() {
- return 1;
- }
-
-}
diff --git a/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/NashornDescription.java b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/NashornDescription.java
new file mode 100644
index 0000000..4ae3d40
--- /dev/null
+++ b/nashorn-impl/src/main/java/net/shibboleth/plugins/scripting/nashorn/NashornDescription.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting.nashorn;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.List;
+
+import org.springframework.core.io.ClassPathResource;
+
+import net.shibboleth.ext.spring.resource.HTTPResource;
+import net.shibboleth.ext.spring.resource.ResourceHelper;
+import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
+import net.shibboleth.utilities.java.support.plugin.PluginDescription;
+import net.shibboleth.utilities.java.support.resource.Resource;
+
+/**
+ * Details about the nashorn scripting plugin
+ *
+ */
+public class NashornDescription extends PluginDescription {
+
+ @Override
+ public String getPluginId() {
+ return "net.shibboleth.plugins.scripting.nashorn";
+ }
+
+ @Override
+ public List<Resource> getUpdateResources() {
+ return List.of(ResourceHelper.of(new ClassPathResource("META-INF/plugins/")));
+ }
+
+ @Override
+ public List<Pair<Resource, Path>> getExternalFilePathsToCopy() throws IOException {
+
+ final HttpClientBuilder builder = new HttpClientBuilder();
+ HTTPResource resource ;
+ try {
+ resource = new HTTPResource(builder.buildClient(), "https://repo1.maven.org/maven2/org/graalvm/sdk/graal-sdk/20.0.0/graal-sdk-20.0.0.jar");
+ } catch (Exception e) {
+ throw new IOException("Construction client failed:", e);
+ }
+ final Path to = Path.of("dist", "edit-webapp-" + getPluginId(), "WEB-INF", "lib");
+ final Pair<Resource, Path> pair = new Pair<>(resource, to);
+ return List.of(pair);
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return 0;
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public int getPatchVersion() {
+ return 1;
+ }
+
+}
diff --git a/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/0.0.1/version.details.properties b/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/0.0.1/version.details.properties
new file mode 100644
index 0000000..ccce079
--- /dev/null
+++ b/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/0.0.1/version.details.properties
@@ -0,0 +1,3 @@
+idp.version.max=5.0.0
+idp.version.min=4.1.0
+support.level = 2
diff --git a/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/versions.properties b/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/versions.properties
new file mode 100644
index 0000000..60529b0
--- /dev/null
+++ b/nashorn-impl/src/main/resources/META-INF/plugins/net.shibboleth.plugins.scripting.nashorn/versions.properties
@@ -0,0 +1 @@
+net.shibboleth.plugins.scripting.nashorn.versions=0.0.1
\ No newline at end of file
diff --git a/nashorn-impl/src/main/resources/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription b/nashorn-impl/src/main/resources/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription
new file mode 100644
index 0000000..755ecaa
--- /dev/null
+++ b/nashorn-impl/src/main/resources/META-INF/services/net.shibboleth.utilities.java.support.plugin.PluginDescription
@@ -0,0 +1 @@
+net.shibboleth.plugins.scripting.nashorn.NashornDescription
diff --git a/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/PluginTest.java b/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/PluginTest.java
new file mode 100644
index 0000000..e90af19
--- /dev/null
+++ b/nashorn-impl/src/test/java/net/shibboleth/plugins/scripting/nashorn/PluginTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.plugins.scripting.nashorn;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.util.ServiceLoader;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.installer.plugin.impl.PluginState;
+import net.shibboleth.utilities.java.support.collection.Pair;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.plugin.PluginDescription;
+import net.shibboleth.utilities.java.support.resource.Resource;
+
+/** basic sanity tests */
+ at SuppressWarnings("javadoc")
+public class PluginTest {
+
+ private PluginDescription nashorn;
+
+ @BeforeClass
+ public void SetupPlugin() {
+ final ServiceLoader<PluginDescription> loader = ServiceLoader.load(PluginDescription.class);
+ for (final PluginDescription service:loader) {
+ if ("net.shibboleth.plugins.scripting.nashorn".contentEquals(service.getPluginId())) {
+ nashorn = service;
+ break;
+ }
+ }
+ assertNotNull(nashorn);
+ }
+
+ @Test
+ public void testState() throws ComponentInitializationException {
+
+ final PluginState state = new PluginState(nashorn);
+ state.initialize();
+
+ }
+
+ @Test
+ public void testDownload() throws IOException {
+ for (Pair<Resource, Path> p:nashorn.getExternalFilePathsToCopy()) {
+
+ final InputStream stream = p.getFirst().getInputStream();
+ byte[] buffer;
+ int count = 0;
+ do {
+ buffer = stream.readNBytes(10240);
+ count += buffer.length;
+ } while (buffer.length >= 10240);
+ assertEquals(count, 539904);
+ }
+ }
+}
diff --git a/nashorn-impl/src/test/resources/logback-test.xml b/nashorn-impl/src/test/resources/logback-test.xml
new file mode 100644
index 0000000..f72c166
--- /dev/null
+++ b/nashorn-impl/src/test/resources/logback-test.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration>
+
+ <logger name="org.apache.http.wire" level="INFO"/>
+
+ <logger name="PROTOCOL_MESSAGE" level="DEBUG"/>
+
+ <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
+ <charset>UTF-8</charset>
+ <Pattern>%date{HH:mm:ss.SSS} - %level [%logger:%line] - %msg%n</Pattern>
+ </encoder>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="CONSOLE"/>
+ </root>
+
+</configuration>
diff --git a/pom.xml b/pom.xml
index 1990026..e12b5fb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,9 +22,10 @@
</description>
<properties>
- <java-support-version>8.1.0-SNAPSHOT</java-support-version>
- <graalvm.version>20.0.0</graalvm.version>
- <automatic.module.name>net.shibboleth.plugins.scripting.nashorn</automatic.module.name>
+ <java-support-version>8.1.0-SNAPSHOT</java-support-version>
+ <graalvm.version>20.0.0</graalvm.version>
+ <idp.groupId>net.shibboleth.idp</idp.groupId>
+ <idp.version>4.0.1-SNAPSHOT</idp.version>
</properties>
<dependencies>
@@ -33,7 +34,24 @@
<groupId>net.shibboleth.utilities</groupId>
<artifactId>java-support</artifactId>
<version>${java-support-version}</version>
- <scope>provided</scope>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.shibboleth.ext</groupId>
+ <artifactId>spring-extensions</artifactId>
+ <version>${spring-extensions.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.shibboleth.ext</groupId>
+ <artifactId>spring-extensions</artifactId>
+ <version>${spring-extensions.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>${spring.groupId}</groupId>
+ <artifactId>spring-core</artifactId>
+ <scope>provided</scope>
</dependency>
</dependencies>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list