[isis] 02/03: ISIS-1948: Introduce -legacy module for 'unittestsupport'
This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git commit daee0d9c1fc2035b483cb86990528edb9ee7fa74 Author: Andi HuberAuthorDate: Sun May 20 07:23:30 2018 +0200 ISIS-1948: Introduce -legacy module for 'unittestsupport' in order to move deprecated classes out Task-Url: https://issues.apache.org/jira/browse/ISIS-1948 --- core/unittestsupport-legacy/.gitignore | 1 + .../pom.xml| 26 -- core/unittestsupport/pom.xml | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/core/unittestsupport-legacy/.gitignore b/core/unittestsupport-legacy/.gitignore new file mode 100644 index 000..a48e45b --- /dev/null +++ b/core/unittestsupport-legacy/.gitignore @@ -0,0 +1 @@ +/target-ide diff --git a/core/unittestsupport/pom.xml b/core/unittestsupport-legacy/pom.xml similarity index 82% copy from core/unittestsupport/pom.xml copy to core/unittestsupport-legacy/pom.xml index fecf2db..5c5ab3e 100644 --- a/core/unittestsupport/pom.xml +++ b/core/unittestsupport-legacy/pom.xml @@ -20,12 +20,12 @@ ${revision} - isis-core-unittestsupport - Apache Isis Unit Test Support + isis-core-unittestsupport-legacy + Apache Isis Unit Test Support (Legacy) - org.apache.isis.core.unittestsupport - org/apache/isis/core/unittestsupport + org.apache.isis.core.unittestsupport-legacy + org/apache/isis/core/unittestsupport-legacy @@ -35,10 +35,22 @@ + + -org.apache.isis.core -isis-core-commons - + org.apache.isis.core + isis-core-unittestsupport + compile + + + org.apache.isis.core + isis-core-unittestsupport + test-jar + test + + + + junit diff --git a/core/unittestsupport/pom.xml b/core/unittestsupport/pom.xml index fecf2db..69a5511 100644 --- a/core/unittestsupport/pom.xml +++ b/core/unittestsupport/pom.xml @@ -35,6 +35,7 @@ + org.apache.isis.core isis-core-commons -- To stop receiving notification emails like this one, please contact ahu...@apache.org.
[isis] 03/03: ISIS-1948: provides a means to load plugins not initially on classpath
This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git commit 2792d6e819cc8417f241fc7857988e1a7b3ec7e3 Author: Andi HuberAuthorDate: Sun May 20 10:00:03 2018 +0200 ISIS-1948: provides a means to load plugins not initially on classpath Task-Url: https://issues.apache.org/jira/browse/ISIS-1948 --- .../isis/commons/internal/context/_Plugin.java | 50 core/plugins/codegen-javassist/pom.xml | 2 +- .../codegen/ProxyFactoryPluginUsingJavassist.java | 5 +- .../jmocking/JavassistImposteriser.java| 0 .../jmocking/JavassistImposteriserTest.java| 0 core/unittestsupport/pom.xml | 21 --- .../jmocking/JUnitRuleMockery2.java| 2 +- ...riserTest.java => DefaultImposteriserTest.java} | 69 -- 8 files changed, 118 insertions(+), 31 deletions(-) diff --git a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java index c2ac726..d9c5152 100644 --- a/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java +++ b/core/commons/src/main/java/org/apache/isis/commons/internal/context/_Plugin.java @@ -19,13 +19,18 @@ package org.apache.isis.commons.internal.context; +import java.io.File; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Objects; import java.util.ServiceLoader; import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.apache.isis.commons.internal.base._Casts; import org.apache.isis.commons.internal.base._NullSafe; import org.apache.isis.commons.internal.collections._Sets; import org.apache.isis.core.plugins.PluginResolveException; @@ -142,6 +147,51 @@ public final class _Plugin { pluginInterfaceClass.getName() )); } + // -- JUNIT TEST SUPPORT + /** +* TODO will break with java 9+ +* @return file-system path, where the frameworks core classes reside (after a build). +*/ + public static URL getCoreCommonsTargetFolder() { + return Stream.of(((URLClassLoader )_Plugin.class.getClassLoader()).getURLs()) + .filter(url->url.toString().contains("/core/commons/")) + .findFirst() + .orElseThrow(()->new RuntimeException("Failed to find file-system path, where the frameworks core classes reside.")) + ; + } + + /** +* Loads a plugin by name and class-path. (Most likely used by JUnit Tests.) +* @param pluginClass +* @param classPath +* @param pluginFullyQualifiedClassName +* @return +*/ + public static S load(Class pluginInterfaceClass, File classPath, String pluginFullyQualifiedClassName) { + + try { + + ClassLoader parentCL = pluginInterfaceClass.getClassLoader(); + URL[] urls = {classPath.toURI().toURL()}; + ClassLoader cl = URLClassLoader.newInstance(urls, parentCL); + Class pluginClass = _Casts.uncheckedCast( + cl.loadClass(pluginFullyQualifiedClassName)); + S plugin = pluginClass.newInstance(); + + _Context.putSingleton(pluginInterfaceClass, plugin); + + return plugin; + + } catch (Exception e) { + throw new PluginResolveException( + String.format("Failed to load plugin '%s' implementing '%s' from path '%s'.", + pluginFullyQualifiedClassName, + pluginInterfaceClass.getName(), + classPath.getAbsolutePath() + ), e); + } + + } } diff --git a/core/plugins/codegen-javassist/pom.xml b/core/plugins/codegen-javassist/pom.xml index a0f7382..2e5cf62 100644 --- a/core/plugins/codegen-javassist/pom.xml +++ b/core/plugins/codegen-javassist/pom.xml @@ -67,7 +67,7 @@ org.apache.isis.core - isis-core-runtime + isis-core-commons compile diff --git a/core/plugins/codegen-javassist/src/main/java/org/apache/isis/core/plugins/codegen/ProxyFactoryPluginUsingJavassist.java
[isis] 01/03: ISIS-1948: setting the new 'plugin-driven' Imposteriser as default
This is an automated email from the ASF dual-hosted git repository. ahuber pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/isis.git commit 7daacd943fd3133befee1300e7c44816d7d48ce6 Author: Andi HuberAuthorDate: Sun May 20 07:21:59 2018 +0200 ISIS-1948: setting the new 'plugin-driven' Imposteriser as default Task-Url: https://issues.apache.org/jira/browse/ISIS-1948 --- .../scenarios/DomainServiceProviderMockery.java| 11 .../jmocking/ImposteriserUsingCodegenPlugin.java | 2 +- .../unittestsupport/jmocking/Imposterisers.java| 32 ++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java index e79a19e..6ec6588 100644 --- a/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java +++ b/core/specsupport/src/main/java/org/apache/isis/core/specsupport/scenarios/DomainServiceProviderMockery.java @@ -19,17 +19,16 @@ package org.apache.isis.core.specsupport.scenarios; import java.util.Map; import java.util.Set; -import com.google.common.collect.Maps; - +import org.apache.isis.applib.services.factory.FactoryService; +import org.apache.isis.applib.services.repository.RepositoryService; +import org.apache.isis.core.unittestsupport.jmocking.Imposterisers; import org.hamcrest.Description; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.api.Action; import org.jmock.api.Invocation; -import org.apache.isis.applib.services.factory.FactoryService; -import org.apache.isis.applib.services.repository.RepositoryService; -import org.apache.isis.core.unittestsupport.jmocking.JavassistImposteriser; +import com.google.common.collect.Maps; /** * @deprecated - with no replacement @@ -51,7 +50,7 @@ class DomainServiceProviderMockery implements DomainServiceProvider { private void init() { context = new Mockery() {{ -setImposteriser(JavassistImposteriser.INSTANCE); +setImposteriser(Imposterisers.getDefault()); }}; mocks.clear(); } diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserUsingCodegenPlugin.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserUsingCodegenPlugin.java index 17b901f..48540d1 100644 --- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserUsingCodegenPlugin.java +++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/ImposteriserUsingCodegenPlugin.java @@ -25,7 +25,7 @@ import org.jmock.api.Invocation; import org.jmock.api.Invokable; import org.jmock.lib.JavaReflectionImposteriser; -public class ImposteriserUsingCodegenPlugin implements Imposteriser { +class ImposteriserUsingCodegenPlugin implements Imposteriser { public static final Imposteriser INSTANCE = new ImposteriserUsingCodegenPlugin(); diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/Imposterisers.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/Imposterisers.java new file mode 100644 index 000..836218d --- /dev/null +++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/Imposterisers.java @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 org.apache.isis.core.unittestsupport.jmocking; + +import org.jmock.api.Imposteriser; + +public final class Imposterisers { + + private Imposterisers() {} + + /** +* @return framework's default Imposteriser instance +*/ + public static Imposteriser getDefault() { + return ImposteriserUsingCodegenPlugin.INSTANCE; + } + +} -- To stop receiving notification emails like this one, please contact ahu...@apache.org.