[java-idp-plugin-scripting] 02/02: IDP-1595 Clean up version reporting, add better tests
Rod Widdowson
rdw at steadingsoftware.com
Thu Aug 27 10:27:51 UTC 2020
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-idp-plugin-scripting.
View the commit online:
http://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=commit;h=13b0ce42d1d57e980f5bd62c23304aff04087af4
commit 13b0ce42d1d57e980f5bd62c23304aff04087af4
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Thu Aug 27 10:37:46 2020 +0100
IDP-1595 Clean up version reporting, add better tests
https://issues.shibboleth.net/jira/browse/IDP-1595
- Put Version information into the -api jar and add a
new class to report this.
- Use this to feed into the version reporting in the descirptions.
- Fix the fallout in the tests because this doesn't work
inside eclipse
- Add extra extra tests against other Foot-in-Mouth issues
encountered durinng test
---
.../scripting/nashorn/NashornDescription.java | 62 ++++++++++++--------
.../idp/plugin/scripting/nashorn/PluginTest.java | 66 ++++++++++++++++++----
rhino-impl/pom.xml | 16 ++++++
.../plugin/scripting/rhino/RhinoDescription.java | 33 +++++++++--
.../idp/plugin/scripting/rhino/PluginTest.java | 60 +++++++++++++++++---
scripting-api/pom.xml | 21 ++++++-
.../shibboleth/idp/plugin/scripting/Version.java | 49 ++++++++++++++++
7 files changed, 260 insertions(+), 47 deletions(-)
diff --git a/nashorn-impl/src/main/java/net/shibboleth/idp/plugin/scripting/nashorn/NashornDescription.java b/nashorn-impl/src/main/java/net/shibboleth/idp/plugin/scripting/nashorn/NashornDescription.java
index acefd8d..cc79c0f 100644
--- a/nashorn-impl/src/main/java/net/shibboleth/idp/plugin/scripting/nashorn/NashornDescription.java
+++ b/nashorn-impl/src/main/java/net/shibboleth/idp/plugin/scripting/nashorn/NashornDescription.java
@@ -23,20 +23,39 @@ import java.net.URL;
import java.nio.file.Path;
import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import net.shibboleth.idp.plugin.AbstractPluginDescription;
+import net.shibboleth.idp.plugin.PluginVersion;
+import net.shibboleth.idp.plugin.scripting.Version;
import net.shibboleth.utilities.java.support.collection.Pair;
-
/**
* Details about the nashorn scripting plugin
*
*/
public class NashornDescription extends AbstractPluginDescription {
- static final String GRAAL_VERSION = "20.0.0";
- static final String MAVEN_REPO = "https://repo1.maven.org/maven2/";
+ static final String GRAAL_VERSION = "20.0.0";
+ static final String MAVEN_REPO = "https://repo1.maven.org/maven2/";
- @Override
+ /** the version pof this plugin. */
+ final private PluginVersion myVersion;
+
+ /** Constructor. */
+ public NashornDescription() {
+ final String versionAsString = Version.getVersion();
+ if (versionAsString == null) {
+ final Logger log = LoggerFactory.getLogger(NashornDescription.class);
+ log.warn("{} must be run from a jar, taking a version of 0.1.2", NashornDescription.class);
+ myVersion = new PluginVersion(0,1,2);
+ } else {
+ myVersion = new PluginVersion(versionAsString);
+ }
+ }
+
+ @Override
public String getPluginId() {
return "net.shibboleth.idp.plugin.nashorn";
}
@@ -44,7 +63,7 @@ public class NashornDescription extends AbstractPluginDescription {
@Override
public List<URL> getUpdateURLs() throws IOException {
return List.of(
- new URL("https://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=blob_plain;f=src/resources/main/plugins.props;hb=HEAD"));
+ new URL("https://git.shibboleth.net/view/?p=java-idp-plugin-scripting.git;a=blob_plain;f=src/resources/main/plugins.props;hb=HEAD"));
}
/** Create a {@link Pair } as needed.
@@ -57,17 +76,17 @@ public class NashornDescription extends AbstractPluginDescription {
private Pair<URL,Path> downloadPair(final String dirPath, final String jar, final Path parent) throws MalformedURLException {
// example graal-sdk-20.0.0.jar
final String jarName = new StringBuilder(jar)
- .append('-')
- .append(GRAAL_VERSION)
- .append(".jar")
- .toString();
+ .append('-')
+ .append(GRAAL_VERSION)
+ .append(".jar")
+ .toString();
// example https://repo1.maven.org/maven2/org/graalvm/sdk/graal-sdk/20.0.0/graal-sdk-20.0.0.jar
final URL url = new URL(new StringBuilder(MAVEN_REPO)
- .append(dirPath)
- .append(GRAAL_VERSION)
- .append('/')
- .append(jarName)
- .toString());
+ .append(dirPath)
+ .append(GRAAL_VERSION)
+ .append('/')
+ .append(jarName)
+ .toString());
return new Pair<URL, Path>(url, parent.resolve(jarName));
}
@@ -75,29 +94,28 @@ public class NashornDescription extends AbstractPluginDescription {
public List<Pair<URL, Path>> getExternalFilePathsToCopy() throws IOException {
final Path to = Path.of("dist", "edit-webapp-" + getPluginId(), "WEB-INF", "lib");
return List.of(downloadPair("org/graalvm/sdk/graal-sdk/", "graal-sdk", to),
- downloadPair("org/graalvm/js/js/", "js", to),
- downloadPair("org/graalvm/regex/regex/", "regex", to),
- downloadPair("org/graalvm/truffle/truffle-api/", "truffle-api", to));
+ downloadPair("org/graalvm/js/js/", "js", to),
+ downloadPair("org/graalvm/regex/regex/", "regex", to),
+ downloadPair("org/graalvm/truffle/truffle-api/", "truffle-api", to));
}
@Override
public List<Path> getFilePathsToCopy() {
- return List.of(Path.of("doc", "nashorn-plugin"));
+ return List.of(Path.of("doc", "nashorn-plugin.txt"));
}
@Override
public int getMajorVersion() {
- return 0;
+ return myVersion.getMajor();
}
@Override
public int getMinorVersion() {
- return 1;
+ return myVersion.getMinor();
}
@Override
public int getPatchVersion() {
- return 2;
+ return myVersion.getPatch();
}
-
}
diff --git a/nashorn-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/PluginTest.java b/nashorn-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/PluginTest.java
index cd35abc..4afbf46 100644
--- a/nashorn-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/PluginTest.java
+++ b/nashorn-impl/src/test/java/net/shibboleth/idp/plugin/scripting/nashorn/PluginTest.java
@@ -22,8 +22,15 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Properties;
import java.util.ServiceLoader;
import org.testng.annotations.BeforeClass;
@@ -35,17 +42,22 @@ import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
import net.shibboleth.idp.plugin.PluginVersion;
import net.shibboleth.idp.plugin.impl.PluginState;
import net.shibboleth.idp.plugin.impl.PluginState.VersionInfo;
+import net.shibboleth.idp.plugin.scripting.Version;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.utilities.java.support.httpclient.HttpClientBuilder;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
/** basic sanity tests */
@SuppressWarnings("javadoc")
public class PluginTest {
private PluginDescription nashorn;
+ private PluginVersion version;
+ private PluginState state;
+
@BeforeClass
- public void SetupPlugin() {
+ public void SetupPlugin() throws ComponentInitializationException {
final ServiceLoader<PluginDescription> loader = ServiceLoader.load(PluginDescription.class);
for (final PluginDescription service:loader) {
if ("net.shibboleth.idp.plugin.nashorn".contentEquals(service.getPluginId())) {
@@ -54,13 +66,17 @@ public class PluginTest {
}
}
assertNotNull(nashorn);
+ state = new PluginState(nashorn);
+ state.initialize();
+ if (null == Version.getVersion()) {
+ version = new PluginVersion("0.1.2");
+ } else {
+ version = new PluginVersion(nashorn.getMajorVersion(),nashorn.getMinorVersion(), nashorn.getPatchVersion());
+ }
}
@Test
public void testState() throws ComponentInitializationException {
- final PluginState state = new PluginState(nashorn);
- state.initialize();
- final PluginVersion version = new PluginVersion(nashorn.getMajorVersion(), nashorn.getMinorVersion(), nashorn.getPatchVersion());
assertTrue(state.getAvailableVersions().containsKey(version));
assertEquals(state.getCurrentInfo().getSupportLevel(), SupportLevel.Current);
assertTrue(state.isSupportedWithIdPVersion(version, new PluginVersion("4.1.0")));
@@ -69,14 +85,12 @@ public class PluginTest {
@Test
public void testStateOld() throws ComponentInitializationException {
- final PluginState state = new PluginState(nashorn);
- state.initialize();
- final PluginVersion version = new PluginVersion("0.1.0");
- assertTrue(state.getAvailableVersions().containsKey(version));
- final VersionInfo info = state.getAvailableVersions().get(version);
+ final PluginVersion oldVers = new PluginVersion(0,1,0);
+ assertTrue(state.getAvailableVersions().containsKey(oldVers));
+ final VersionInfo info = state.getAvailableVersions().get(oldVers);
assertEquals(info.getSupportLevel(), SupportLevel.OutOfDate);
- assertTrue(state.isSupportedWithIdPVersion(version, new PluginVersion("4.1.0")));
- assertFalse(state.isSupportedWithIdPVersion(version, new PluginVersion("5.0.0")));
+ assertTrue(state.isSupportedWithIdPVersion(oldVers, new PluginVersion("4.1.0")));
+ assertFalse(state.isSupportedWithIdPVersion(oldVers, new PluginVersion("5.0.0")));
}
@Test
@@ -95,4 +109,34 @@ public class PluginTest {
} while (buffer.length >= 10240);
assertEquals(count, 539904);
}
+
+ @Test
+ public void testFiles() throws IOException {
+ final Path distDir = Path.of("../nashorn-dist/src/main/resources");
+ assertTrue(Files.exists(distDir));
+ for (final Path p : nashorn.getFilePathsToCopy()) {
+ assertTrue(Files.exists(distDir.resolve(p)));
+ }
+ final File propFile = distDir.resolve("bootstrap").resolve("id.property").toFile();
+ assertTrue(propFile.exists());
+ Properties props = new Properties(2);
+ try(final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(propFile))) {
+ props.load(stream);
+ assertEquals(StringSupport.trimOrNull(props.getProperty("pluginid")), nashorn.getPluginId());
+ }
+ }
+
+ @Test
+ public void testVersions() {
+ if (null == Version.getVersion()) {
+ // inside eclipse
+ assertEquals(nashorn.getMajorVersion(), 0);
+ assertEquals(nashorn.getMinorVersion(), 1);
+ assertEquals(nashorn.getPatchVersion(), 2);
+ } else {
+ assertEquals(nashorn.getMajorVersion(), 0);
+ assertEquals(nashorn.getMinorVersion(), 1);
+ assertTrue(nashorn.getPatchVersion()== 2 || nashorn.getPatchVersion() ==3);
+ }
+ }
}
diff --git a/rhino-impl/pom.xml b/rhino-impl/pom.xml
index 58dd0ad..ebd6f40 100644
--- a/rhino-impl/pom.xml
+++ b/rhino-impl/pom.xml
@@ -36,6 +36,11 @@
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>${slf4j.groupId}</groupId>
<artifactId>slf4j-api</artifactId>
@@ -110,9 +115,20 @@
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
+ <index>true</index>
<manifestEntries>
<Automatic-Module-Name>${automatic.module.name}</Automatic-Module-Name>
</manifestEntries>
+ <manifestSections>
+ <manifestSection>
+ <name>net/shibboleth/idp/plugin/scripting/rhino</name>
+ <manifestEntries>
+ <Implementation-Title>${project.artifactId}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>shibboleth.net</Implementation-Vendor>
+ </manifestEntries>
+ </manifestSection>
+ </manifestSections>
</archive>
</configuration>
</plugin>
diff --git a/rhino-impl/src/main/java/net/shibboleth/idp/plugin/scripting/rhino/RhinoDescription.java b/rhino-impl/src/main/java/net/shibboleth/idp/plugin/scripting/rhino/RhinoDescription.java
index 3affb79..68af1dd 100644
--- a/rhino-impl/src/main/java/net/shibboleth/idp/plugin/scripting/rhino/RhinoDescription.java
+++ b/rhino-impl/src/main/java/net/shibboleth/idp/plugin/scripting/rhino/RhinoDescription.java
@@ -23,15 +23,36 @@ import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
+import javax.annotation.Nonnull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import net.shibboleth.idp.plugin.AbstractPluginDescription;
+import net.shibboleth.idp.plugin.PluginVersion;
+import net.shibboleth.idp.plugin.scripting.Version;
import net.shibboleth.utilities.java.support.collection.Pair;
/**
- * Details about the nashorn scripting plugin
- *
+ * Details about the Rhino scripting plugin.
*/
public class RhinoDescription extends AbstractPluginDescription {
+ /** the version pof this plugin. */
+ @Nonnull final private PluginVersion myVersion;
+
+ /** Constructor. */
+ public RhinoDescription() {
+ final String versionAsString = Version.getVersion();
+ if (versionAsString == null) {
+ final Logger log = LoggerFactory.getLogger(RhinoDescription.class);
+ log.warn("{} must be run from a jar, taking a version of 0.1.2", RhinoDescription.class);
+ myVersion = new PluginVersion(0,1,2);
+ } else {
+ myVersion = new PluginVersion(versionAsString);
+ }
+ }
+
@Override
public String getPluginId() {
return "net.shibboleth.idp.plugin.rhino";
@@ -50,21 +71,21 @@ public class RhinoDescription extends AbstractPluginDescription {
@Override
public List<Path> getFilePathsToCopy() {
- return List.of(Path.of("doc", "rhino-plugin"));
+ return List.of(Path.of("doc", "rhino-plugin.txt"));
}
@Override
public int getMajorVersion() {
- return 0;
+ return myVersion.getMajor();
}
@Override
public int getMinorVersion() {
- return 1;
+ return myVersion.getMinor();
}
@Override
public int getPatchVersion() {
- return 2;
+ return myVersion.getPatch();
}
}
diff --git a/rhino-impl/src/test/java/net/shibboleth/idp/plugin/scripting/rhino/PluginTest.java b/rhino-impl/src/test/java/net/shibboleth/idp/plugin/scripting/rhino/PluginTest.java
index 5895821..9b51008 100644
--- a/rhino-impl/src/test/java/net/shibboleth/idp/plugin/scripting/rhino/PluginTest.java
+++ b/rhino-impl/src/test/java/net/shibboleth/idp/plugin/scripting/rhino/PluginTest.java
@@ -22,26 +22,37 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Properties;
import java.util.ServiceLoader;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import net.shibboleth.idp.plugin.impl.PluginState;
-import net.shibboleth.idp.plugin.impl.PluginState.VersionInfo;
-import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
import net.shibboleth.idp.plugin.PluginDescription;
import net.shibboleth.idp.plugin.PluginSupport.SupportLevel;
import net.shibboleth.idp.plugin.PluginVersion;
+import net.shibboleth.idp.plugin.impl.PluginState;
+import net.shibboleth.idp.plugin.impl.PluginState.VersionInfo;
+import net.shibboleth.idp.plugin.scripting.Version;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
/** basic sanity tests */
@SuppressWarnings("javadoc")
public class PluginTest {
private PluginDescription rhino;
+ private PluginVersion version;
+ private PluginState state;
@BeforeClass
- public void SetupPlugin() {
+ public void SetupPlugin() throws ComponentInitializationException {
final ServiceLoader<PluginDescription> loader = ServiceLoader.load(PluginDescription.class);
for (final PluginDescription service:loader) {
if ("net.shibboleth.idp.plugin.rhino".contentEquals(service.getPluginId())) {
@@ -50,11 +61,17 @@ public class PluginTest {
}
}
assertNotNull(rhino);
+ state = new PluginState(rhino);
+ state.initialize();
+ if (null == Version.getVersion()) {
+ version = new PluginVersion("0.1.2");
+ } else {
+ version = new PluginVersion(rhino.getMajorVersion(),rhino.getMinorVersion(), rhino.getPatchVersion());
+ }
}
@Test
public void testStateOld() throws ComponentInitializationException {
- final PluginState state = new PluginState(rhino);
state.initialize();
final PluginVersion version = new PluginVersion("0.1.0");
assertTrue(state.getAvailableVersions().containsKey(version));
@@ -66,13 +83,42 @@ public class PluginTest {
@Test
public void testState() throws ComponentInitializationException {
- final PluginState state = new PluginState(rhino);
state.initialize();
- final PluginVersion version = new PluginVersion(rhino.getMajorVersion(),rhino.getMinorVersion(), rhino.getPatchVersion());
assertTrue(state.getAvailableVersions().containsKey(version));
assertEquals(state.getCurrentInfo().getSupportLevel(), SupportLevel.Current);
assertTrue(state.isSupportedWithIdPVersion(version, new PluginVersion("4.1.0")));
assertFalse(state.isSupportedWithIdPVersion(version, new PluginVersion("5.0.0")));
}
+ @Test
+ public void testFiles() throws IOException {
+ final Path distDir = Path.of("../rhino-dist/src/main/resources");
+ assertTrue(Files.exists(distDir));
+ for (final Path p : rhino.getFilePathsToCopy()) {
+ assertTrue(Files.exists(distDir.resolve(p)));
+ }
+ final File propFile = distDir.resolve("bootstrap").resolve("id.property").toFile();
+ assertTrue(propFile.exists());
+ Properties props = new Properties(2);
+ try(final BufferedInputStream stream = new BufferedInputStream(new FileInputStream(propFile))) {
+ props.load(stream);
+ assertEquals(StringSupport.trimOrNull(props.getProperty("pluginid")), rhino.getPluginId());
+ }
+ }
+
+ // Remove soon
+ @Test
+ public void testVersions() {
+ if (null == Version.getVersion()) {
+ // inside eclipse
+ assertEquals(rhino.getMajorVersion(), 0);
+ assertEquals(rhino.getMinorVersion(), 1);
+ assertEquals(rhino.getPatchVersion(), 2);
+ } else {
+ assertEquals(rhino.getMajorVersion(), 0);
+ assertEquals(rhino.getMinorVersion(), 1);
+ assertTrue(rhino.getPatchVersion()== 2 || rhino.getPatchVersion() ==3);
+ }
+ }
}
+
diff --git a/scripting-api/pom.xml b/scripting-api/pom.xml
index e5cf258..234b4ad 100644
--- a/scripting-api/pom.xml
+++ b/scripting-api/pom.xml
@@ -23,6 +23,14 @@
A project to build a jar file that ECMAScript plugins depend upon.
</description>
+ <dependencies>
+ <dependency>
+ <groupId>com.google.code.findbugs</groupId>
+ <artifactId>jsr305</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
<build>
<plugins>
<plugin>
@@ -35,8 +43,19 @@
<configuration>
<archive>
<manifestEntries>
- <Automatic-Module-Name>${automatic.module.name}</Automatic-Module-Name>
+ <Main-Class>net.shibboleth.idp.plugin.scripting.Version</Main-Class>
+ <Automatic-Module-Name>${automatic.module.name}</Automatic-Module-Name>
</manifestEntries>
+ <manifestSections>
+ <manifestSection>
+ <name>net/shibboleth/idp/plugin/scripting</name>
+ <manifestEntries>
+ <Implementation-Title>${project.artifactId}</Implementation-Title>
+ <Implementation-Version>${project.version}</Implementation-Version>
+ <Implementation-Vendor>shibboleth.net</Implementation-Vendor>
+ </manifestEntries>
+ </manifestSection>
+ </manifestSections>
</archive>
</configuration>
</plugin>
diff --git a/scripting-api/src/main/java/net/shibboleth/idp/plugin/scripting/Version.java b/scripting-api/src/main/java/net/shibboleth/idp/plugin/scripting/Version.java
new file mode 100644
index 0000000..70e48d7
--- /dev/null
+++ b/scripting-api/src/main/java/net/shibboleth/idp/plugin/scripting/Version.java
@@ -0,0 +1,49 @@
+/*
+ * 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.idp.plugin.scripting;
+
+import javax.annotation.Nullable;
+
+/** Class for getting and printing the version of the IdP. */
+public final class Version {
+
+ /** IdP version. */
+ @Nullable private static final String VERSION = Version.class.getPackage().getImplementationVersion();
+
+ /** Constructor. */
+ private Version() {
+ }
+
+ /**
+ * Main entry point to program.
+ *
+ * @param args command line arguments
+ */
+ public static void main(final String[] args) {
+ System.out.println(VERSION);
+ }
+
+ /**
+ * Get the version of the IdP.
+ *
+ * @return version of the IdP
+ */
+ @Nullable public static String getVersion() {
+ return VERSION;
+ }
+}
\ No newline at end of file
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list