You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2020/01/30 17:03:30 UTC

[isis] 05/08: ISIS-2192: porsts ExceptionRecognizerTranslate

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 011f207266fe3f17cdc08e3dec67ae890c8848ec
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 30 16:25:47 2020 +0000

    ISIS-2192: porsts ExceptionRecognizerTranslate
    
    from junit 4 MethodRule to junit 5 extension
---
 README.adoc                                        |  4 +-
 .../modules/comguide/pages/cutting-a-release.adoc  | 58 ++++----------------
 api/adoc/userguide/modules/btb/pages/i18n.adoc     |  2 +-
 .../applib/ExceptionRecognizerTranslate.java       | 61 ++++++----------------
 .../applib/IsisIntegrationTestAbstract.java        |  2 +
 5 files changed, 31 insertions(+), 96 deletions(-)

diff --git a/README.adoc b/README.adoc
index e0e76b7..ccf0ae4 100644
--- a/README.adoc
+++ b/README.adoc
@@ -261,8 +261,8 @@ Indeed, the example todoapp demonstrates this.
 
 The Apache Isis http://isis.apache.org[website] has lots of useful information and is being continually updated.
 
-Or, you can just start coding using one of the http://isis.apache.org/arch/helloworld/about.html[Maven archetype]s.
+Or, you can just start coding using the https:github.com/apache/isis-app-simpleapp[SimpleApp] starter app.
 
-And if you need help or support, join the http://isis.apache.org/support.html[mailing lists].
+And if you need help or support, join our https://cwiki.apache.org/confluence/display/ISIS/Signing+up+to+Slack[ASF Slack channel] or our http://isis.apache.org/support.html[mailing list].
 
 
diff --git a/antora/toc/modules/comguide/pages/cutting-a-release.adoc b/antora/toc/modules/comguide/pages/cutting-a-release.adoc
index 97377ed..795dc79 100644
--- a/antora/toc/modules/comguide/pages/cutting-a-release.adoc
+++ b/antora/toc/modules/comguide/pages/cutting-a-release.adoc
@@ -12,13 +12,9 @@ The release process consists of:
 * Members of the Apache Isis PMC xref:toc:comguide:about.adoc#verifying-releases[verifying] and voting on the release
 * the release manager performing post-release tasks, for either a xref:toc:comguide:about.adoc#post-release-successful.adoc[successful] or an xref:toc:comguide:post-release-unsuccessful[unsuccessful] vote.
 
-Apache Isis itself consists of three separately releasable modules; relative to the link:https://github.com/apache/isis[source code root] there are:
+Apache Isis itself is released in one go, everything is ultimately a child of `core-parent/pom.xml` (relative to the link:https://github.com/apache/isis[source code root])
+This section details the process for formally releasing this module.
 
-* `core`
-* `component/example/archetypes/helloworld`
-* `component/example/archetypes/simpleapp`
-
-This section details the process for formally releasing Isis modules.  It describes the process for both `core` and then the archetypes.
 The subsequent sections describe how other committers can xref:toc:comguide:about.adoc#verifying-releases.adoc[verify a release] and how the release manager can then perform xref:toc:comguide:post-release[post-release] activities and set up for the next development iteration.
 
 If you've not performed a release before, then note that there are some configuration xref:toc:comguide:about.adoc#release-process-prereqs[prerequisites] that must be configured first.
@@ -27,9 +23,6 @@ In particular, you'll need signed public/private keys, and the ASF Nexus staging
 These release notes using bash command line tools.
 They should work on Linux and MacOS; for Windows, use mSysGit.
 
-
-
-
 == Obtain Consensus
 
 Before releasing `core`, ensure there is consensus on the xref:toc:ROOT:support.adoc#[dev mailing list] that this is the right time for a release.
@@ -38,12 +31,9 @@ The discussion should include confirming the version number to be used, and to c
 These discussions should also confirm the version number of the module being released.
 This should be in line with our xref:toc:comguide:about.adoc#versioning-policy[semantic versioning policy].
 
-
 Make sure you have a JIRA ticket open against which to perform all commits.
 In most cases a JIRA ticket will have been created at the beginning of the previous release cycle.
 
-
-
 == Set environment variables
 
 We use environment variables to parameterize as many of the steps as possible.
@@ -72,8 +62,6 @@ Obviously, alter ``$ISISREL`` as required, and bump ``$ISISRC`` for re-releasing
 Note that the branch name is intentionally *not* the same any of the eventual tag names (eg `isis-{isisnext}` or `simpleapp-archetype-{isisnext}`).
 ====
 
-
-
 == Pull down code to release
 
 Set the HEAD of your local git repo to the commit to be released.
@@ -89,7 +77,6 @@ git checkout -b $ISISBRANCH
 
 The release is performed on a branch; if we are successful, this branch will be merged back into master.
 
-
 Check that there are no snapshot dependencies:
 
 [source,bash,subs="attributes+"]
@@ -99,8 +86,6 @@ grep SNAPSHOT `/bin/find . -name pom.xml | grep -v target | grep -v mothball | s
 
 The only mention of `SNAPSHOT` should be in the `revision` property of the root `core/pom.xml` file.
 
-
-
 == Bump `revision` property to `$ISISREL`
 
 Previously we used the `maven-release-plugin` which took responsibility for bumping the `<version>` from -SNAPSHOT to release, and then onto the next -SNAPSHOT.
@@ -125,11 +110,8 @@ so that they should read:
 </properties>
 ----
 
-
 After release, there is a xref:toc:comguide:cutting-a-release.adoc#reset-revision[similar step at the end] to reset back to `1.0.0-SNAPSHOT`.
 
-
-
 == Releasing Core
 
 First, we release `core`.
@@ -151,8 +133,6 @@ export ISISART=isis
 env | grep ISIS | sort
 ----
 
-
-
 === License headers
 
 The Apache Release Audit Tool `RAT` (from the http://creadur.apache.org[Apache Creadur] project) checks for missing license header files.
@@ -167,9 +147,8 @@ for a in `/bin/find . -name rat.txt -print`; do grep '!???' $a; done || \
 for a in `/bin/find . -name rat.txt -print`; do grep '!AL' $a; done
 ----
 
-where `rat.numUnapprovedLicenses` property is set to a high figure, temporarily overriding the default value of 0.
-This will allow the command to run over all submodules, rather than failing after the first one.
-The command writes out a `target\rat.txt` for each submodule.  missing license notes are indicated using the key `!???`.
+where `rat.numUnapprovedLicenses` property is set to a high figure, temporarily overriding the default value of 0. This will allow the command to run over all submodules, rather than failing after the first one.
+The command writes out a `target\rat.txt` for each submodule. missing license notes are indicated using the key `!???`.
 The `for` command collates all the errors.
 
 Investigate and fix any reported violations, typically by either:
@@ -186,7 +165,6 @@ mvn org.apache.rat:apache-rat-plugin:check -D rat.numUnapprovedLicenses=0 -o &&
 for a in `find . -name rat.txt -print`; do grep '!???' $a; done
 ----
 
-
 === Missing License Check
 
 Although Apache Isis has no dependencies on artifacts with incompatible licenses, the POMs for some of these dependencies (in the Maven central repo) do not necessarily contain the required license information.
@@ -229,9 +207,6 @@ licenses to remove from supplemental-models.xml (are spurious):
 
 If any missing entries are listed or are spurious, then update `supplemental-models.xml` and try again.
 
-
-
-
 === Commit changes
 
 Commit any changes from the preceding steps:
@@ -243,7 +218,6 @@ mvn versions:set -DnewVersion=$ISISVER
 git commit -am "$ISISJIRA: updates to pom.xml etc for release"
 ----
 
-
 === Sanity check
 
 Perform one last sanity check on the codebase.
@@ -255,7 +229,6 @@ rm -rf ~/.m2/repository/org/apache/isis
 mvn clean install -o
 ----
 
-
 === Deploy
 
 Since the `<version>` has already been updated, we just use `mvn deploy` to upload the artifacts.
@@ -276,16 +249,11 @@ git tag $ISISART-$ISISREL-$ISISRC
 
 using your own GPG passphrase, of course.
 
-
 [IMPORTANT]
 ====
 This requires `gpg` v2.1 or later.
 ====
 
-
-
-
-
 == Check/Close Staging Repo
 
 The `mvn deploy` commands will have uploaded release artifacts for both `core` and the `simpleapp` archetype into a newly created staging repository on the ASF Nexus repository server.
@@ -300,10 +268,11 @@ image::release-process/nexus-staging-1.png[width="600px",link="{imagesdir}/relea
 
 If nothing appears in a staging repo you should stop here and work out why.
 
-Assuming that the repo has been populated, make a note of its repo id; this is needed for the voting thread. In the screenshot above the id is `org.apache.isis-008`.
+Assuming that the repo has been populated, make a note of its repo id; this is needed for the voting thread.
+In the screenshot above the id is `org.apache.isis-008`.
 
-
-After checking that the staging repository contains the artifacts that you expect you should close the staging repository. This will make it available so that people can check the release.
+After checking that the staging repository contains the artifacts that you expect you should close the staging repository.
+This will make it available so that people can check the release.
 
 Press the Close button and complete the dialog:
 
@@ -325,16 +294,12 @@ image::release-process/nexus-staging-4.png[width="600px",link="{imagesdir}/relea
 
 Use `gpg --keyserver hkp://pgp.mit.edu --recv-keys nnnnnnnn` to confirm that the key is available.
 
-
 [NOTE]
 ====
-Unfortunately, Nexus does not seem to allow subkeys to be used for signing. See xref:toc:comguide:about.adoc#key-generation[Key Generation] for more details.
+Unfortunately, Nexus does not seem to allow subkeys to be used for signing.
+See xref:toc:comguide:about.adoc#key-generation[Key Generation] for more details.
 ====
 
-
-
-
-
 == Reset `revision` property
 
 At the beginning of the release process we bumped the `revision` property to the release version, ie `$ISISREL`.
@@ -353,7 +318,6 @@ In the root of the Apache Isis repo, we do this for all three ``pom.xml``s with:
 sh scripts/version-reset.sh $ISISJIRA
 ----
 
-
 == Push branches
 
 Push the release branch to origin:
@@ -378,8 +342,6 @@ git fetch
 The remote tags aren't visible locally but can be seen link:https://github.com/apache/isis/tags[online].
 ====
 
-
-
 == Voting
 
 Once the artifacts have been uploaded, you can call a vote.
diff --git a/api/adoc/userguide/modules/btb/pages/i18n.adoc b/api/adoc/userguide/modules/btb/pages/i18n.adoc
index f826aa7..a20e385 100644
--- a/api/adoc/userguide/modules/btb/pages/i18n.adoc
+++ b/api/adoc/userguide/modules/btb/pages/i18n.adoc
@@ -533,7 +533,7 @@ To ensure your app is fully internationalized app, you must therefore:
 ====
 We make no apologies for this requirement: one of the reasons that we decided to implement Apache Isis' i18n support in this way is because it encourages/requires the app to be properly tested.
 
-Behind the scenes Apache Isis uses a JUnit rule (`ExceptionRecognizerTranslate`) to intercept any exceptions that are thrown.
+Behind the scenes Apache Isis uses a JUnit 5 extension (`ExceptionRecognizerTranslate`) to intercept any exceptions that are thrown.
 These are simply passed through to the registered xref:refguide:applib-svc:presentation-layer-spi/ExceptionRecognizer.adoc[`ExceptionRecognizer`]s so that any messages are recorded as requiring translation.
 ====
 
diff --git a/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/ExceptionRecognizerTranslate.java b/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/ExceptionRecognizerTranslate.java
index fa74414..4c969ae 100644
--- a/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/ExceptionRecognizerTranslate.java
+++ b/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/ExceptionRecognizerTranslate.java
@@ -18,60 +18,31 @@
  */
 package org.apache.isis.testing.integtestsupport.applib;
 
-import org.junit.rules.MethodRule;
-import org.junit.runners.model.FrameworkMethod;
-import org.junit.runners.model.Statement;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
 
 import org.apache.isis.applib.services.exceprecog.ExceptionRecognizer;
 import org.apache.isis.applib.services.registry.ServiceRegistry;
+import org.apache.isis.core.runtime.context.IsisContext;
+import org.apache.isis.core.runtime.context.session.RuntimeContextBase;
 import org.apache.isis.core.runtime.session.IsisSessionFactory;
 
 import lombok.RequiredArgsConstructor;
 
-@RequiredArgsConstructor
-public class ExceptionRecognizerTranslate implements MethodRule {
+public class ExceptionRecognizerTranslate implements TestExecutionExceptionHandler {
     
-    private final ServiceRegistry serviceRegistry;
-
     @Override
-    public Statement apply(final Statement statement, final FrameworkMethod frameworkMethod, final Object o) {
-        return new TranslationStatement(statement);
-    }
-
-    private class TranslationStatement extends Statement {
-        private final Statement next;
-
-        public TranslationStatement(final Statement base) {
-            this.next = base;
-        }
-
-        @Override
-        public void evaluate() throws Throwable {
-            try {
-                this.next.evaluate();
-            } catch (final Throwable ex) {
-                recognize(ex);
-                throw ex;
-            }
-        }
-    }
-
-    /**
-     * Simply invokes {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer#recognize(Throwable)} 
-     * for all registered {@link org.apache.isis.applib.services.exceprecog.ExceptionRecognizer}s 
-     * for the provided exception, so that the message will be translated.
-     */
-    private void recognize(final Throwable ex) {
-        serviceRegistry
-        .select(ExceptionRecognizer.class)
-        .stream()
-        .forEach(exceptionRecognizer->{
-            exceptionRecognizer.recognize(ex);
-        });
-    }
-
-    IsisSessionFactory getIsisSessionFactory() {
-        return serviceRegistry.lookupServiceElseFail(IsisSessionFactory.class);
+    public void handleTestExecutionException(ExtensionContext extensionContext, Throwable throwable) throws Throwable {
+        IsisContext.getCurrentIsisSession()
+                .map(RuntimeContextBase::getServiceRegistry).
+                ifPresent(serviceRegistry ->
+                        serviceRegistry.select(ExceptionRecognizer.class)
+                                        .stream()
+                                        .forEach(exceptionRecognizer->{
+                                            exceptionRecognizer.recognize(throwable);
+                                        })
+                );
+        throw throwable;
     }
 
 }
diff --git a/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/IsisIntegrationTestAbstract.java b/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/IsisIntegrationTestAbstract.java
index 473b4bf..067bf2f 100644
--- a/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/IsisIntegrationTestAbstract.java
+++ b/testing/integtestsupport/applib/src/main/java/org/apache/isis/testing/integtestsupport/applib/IsisIntegrationTestAbstract.java
@@ -20,6 +20,7 @@ package org.apache.isis.testing.integtestsupport.applib;
 
 import javax.inject.Inject;
 
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.springframework.context.event.EventListener;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
@@ -44,6 +45,7 @@ import org.apache.isis.core.runtime.persistence.transaction.events.TransactionAf
  *  
  * @since 2.0
  */
+@ExtendWith(ExceptionRecognizerTranslate.class)
 public abstract class IsisIntegrationTestAbstract {
 
     /**