From ce46a15d47310f6beb0f21645e1a313c468c3917 Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Thu, 29 Dec 2016 15:31:13 +0700 Subject: [PATCH 1/6] [feature] Initial commit of memory leaks test --- .../mvp/memory_leak_test/MemoryLeakTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java new file mode 100644 index 00000000..98c7f983 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java @@ -0,0 +1,11 @@ +package com.arellomobile.mvp.memory_leak_test; + +/** + * Date: 29.12.2016 + * Time: 14:29 + * + * @author Yuri Shmakov + */ + +public class MemoryLeakTest { +} \ No newline at end of file From 8f4a432ca68d1c7d927508b46f5dd1e70d027fec Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Thu, 29 Dec 2016 19:03:46 +0700 Subject: [PATCH 2/6] [feature] Test memory leaks --- .../mvp/memory_leak_test/MemoryLeakTest.java | 61 ++++++++++++++++++- .../resources/TestPresenter.java | 12 ++++ .../memory_leak_test/resources/TestView.java | 12 ++++ .../resources/TestViewImplementation.java | 18 ++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestPresenter.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestView.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestViewImplementation.java diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java index 98c7f983..b2401e15 100644 --- a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java @@ -1,11 +1,70 @@ package com.arellomobile.mvp.memory_leak_test; +import java.lang.ref.WeakReference; +import java.util.concurrent.TimeUnit; + +import android.os.Bundle; + +import com.arellomobile.mvp.MvpDelegate; +import com.arellomobile.mvp.memory_leak_test.resources.TestViewImplementation; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * Date: 29.12.2016 * Time: 14:29 * * @author Yuri Shmakov */ - +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) public class MemoryLeakTest { + @Test + public void test() { + TestViewImplementation viewImplementation = new TestViewImplementation(); + + viewImplementation.delegate = new MvpDelegate<>(viewImplementation); + + viewImplementation.delegate.onCreate(new Bundle()); + + assertNotNull(viewImplementation.presenter); + + viewImplementation.delegate.onDestroy(); + + WeakReference viewImplementationReference = new WeakReference(viewImplementation); + WeakReference presenterReference = new WeakReference(viewImplementation.presenter); + + /** + * Remove local reference to this object. Test will been failed if reference to the implemented view or + * to presenter was being saved in Moxy + */ + //noinspection UnusedAssignment + viewImplementation = null; + + long delay = 0; + + while (delay < TimeUnit.SECONDS.toMillis(2)) { + System.gc(); + + if (viewImplementationReference.get() == null && presenterReference.get() == null) { + return; + } + + try { + TimeUnit.MILLISECONDS.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + delay += 100; + } + + assertTrue(false); + } } \ No newline at end of file diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestPresenter.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestPresenter.java new file mode 100644 index 00000000..6e46dbb1 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestPresenter.java @@ -0,0 +1,12 @@ +package com.arellomobile.mvp.memory_leak_test.resources; + +import com.arellomobile.mvp.MvpPresenter; + +/** + * Date: 29.12.2016 + * Time: 14:32 + * + * @author Yuri Shmakov + */ +public class TestPresenter extends MvpPresenter { +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestView.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestView.java new file mode 100644 index 00000000..050b49e8 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestView.java @@ -0,0 +1,12 @@ +package com.arellomobile.mvp.memory_leak_test.resources; + +import com.arellomobile.mvp.MvpView; + +/** + * Date: 29.12.2016 + * Time: 14:31 + * + * @author Yuri Shmakov + */ +public interface TestView extends MvpView { +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestViewImplementation.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestViewImplementation.java new file mode 100644 index 00000000..82b6c7a7 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/resources/TestViewImplementation.java @@ -0,0 +1,18 @@ +package com.arellomobile.mvp.memory_leak_test.resources; + +import com.arellomobile.mvp.MvpDelegate; +import com.arellomobile.mvp.presenter.InjectPresenter; + +/** + * Date: 29.12.2016 + * Time: 14:33 + * + * @author Yuri Shmakov + */ + +public class TestViewImplementation implements TestView { + @InjectPresenter + public TestPresenter presenter; + + public MvpDelegate delegate; +} From c416bc4d503a9a4d03d67c11ecc989713ca4283a Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Fri, 30 Dec 2016 01:07:24 +0700 Subject: [PATCH 3/6] [aritfact] Remove no-actual test --- .../com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java index b2401e15..0494b6b4 100644 --- a/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java +++ b/moxy/src/test/java/com/arellomobile/mvp/memory_leak_test/MemoryLeakTest.java @@ -14,7 +14,6 @@ import org.robolectric.annotation.Config; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** @@ -34,8 +33,6 @@ public void test() { viewImplementation.delegate.onCreate(new Bundle()); - assertNotNull(viewImplementation.presenter); - viewImplementation.delegate.onDestroy(); WeakReference viewImplementationReference = new WeakReference(viewImplementation); From ad08ff566063487fec41595dbfef652570c54e24 Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Fri, 30 Dec 2016 01:13:42 +0700 Subject: [PATCH 4/6] [feature] Allowed inheritance without inject presenter in child class --- .../com/arellomobile/mvp/MvpProcessor.java | 8 ++- .../mvp/inheritance_test/InheritanceTest.java | 56 +++++++++++++++++++ .../resources/ChildViewWithoutInject.java | 10 ++++ .../resources/SuperViewWithInject.java | 14 +++++ .../resources/TestPresenter.java | 13 +++++ .../inheritance_test/resources/TestView.java | 12 ++++ .../resources/ViewWithoutInject.java | 13 +++++ 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/InheritanceTest.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ChildViewWithoutInject.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/SuperViewWithInject.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestPresenter.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestView.java create mode 100644 moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ViewWithoutInject.java diff --git a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java index 2236f2da..ab391965 100644 --- a/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java +++ b/moxy/src/main/java/com/arellomobile/mvp/MvpProcessor.java @@ -76,7 +76,13 @@ private MvpPresenter getMvpPresenter(Delegated ta List> getMvpPresenters(Delegated delegated, String delegateTag) { @SuppressWarnings("unchecked") Class aClass = (Class) delegated.getClass(); - List presenterBinders = MoxyReflector.getPresenterBinders(aClass); + List presenterBinders = null; + + while (aClass != Object.class && presenterBinders == null) { + presenterBinders = MoxyReflector.getPresenterBinders(aClass); + + aClass = aClass.getSuperclass(); + } if (presenterBinders == null || presenterBinders.isEmpty()) { return Collections.emptyList(); diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/InheritanceTest.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/InheritanceTest.java new file mode 100644 index 00000000..2d94bef7 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/InheritanceTest.java @@ -0,0 +1,56 @@ +package com.arellomobile.mvp.inheritance_test; + +import android.os.Bundle; + +import com.arellomobile.mvp.MvpDelegate; +import com.arellomobile.mvp.inheritance_test.resources.ChildViewWithoutInject; +import com.arellomobile.mvp.inheritance_test.resources.SuperViewWithInject; +import com.arellomobile.mvp.inheritance_test.resources.ViewWithoutInject; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +/** + * Date: 30.12.2016 + * Time: 00:29 + * + * @author Yuri Shmakov + */ +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class InheritanceTest { + + @Test + public void testWithoutInject() { + ViewWithoutInject view = new ViewWithoutInject(); + + view.delegate = new MvpDelegate<>(view); + + view.delegate.onCreate(new Bundle()); + } + + @Test + public void testInjectInInherited() { + SuperViewWithInject view = new SuperViewWithInject(); + + view.delegate = new MvpDelegate<>(view); + + view.delegate.onCreate(new Bundle()); + + Assert.assertNotNull(view.presenter); + } + + @Test + public void testInjectOnlyInSuper() { + ChildViewWithoutInject view = new ChildViewWithoutInject(); + + view.delegate = new MvpDelegate<>(view); + + view.delegate.onCreate(); + + Assert.assertNotNull(view.presenter); + } +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ChildViewWithoutInject.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ChildViewWithoutInject.java new file mode 100644 index 00000000..c6d2a583 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ChildViewWithoutInject.java @@ -0,0 +1,10 @@ +package com.arellomobile.mvp.inheritance_test.resources; + +/** + * Date: 30.12.2016 + * Time: 00:13 + * + * @author Yuri Shmakov + */ +public class ChildViewWithoutInject extends SuperViewWithInject implements TestView { +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/SuperViewWithInject.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/SuperViewWithInject.java new file mode 100644 index 00000000..bdf04d57 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/SuperViewWithInject.java @@ -0,0 +1,14 @@ +package com.arellomobile.mvp.inheritance_test.resources; + +import com.arellomobile.mvp.presenter.InjectPresenter; + +/** + * Date: 30.12.2016 + * Time: 00:11 + * + * @author Yuri Shmakov + */ +public class SuperViewWithInject extends ViewWithoutInject implements TestView { + @InjectPresenter + public TestPresenter presenter; +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestPresenter.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestPresenter.java new file mode 100644 index 00000000..806d6462 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestPresenter.java @@ -0,0 +1,13 @@ +package com.arellomobile.mvp.inheritance_test.resources; + +import com.arellomobile.mvp.MvpPresenter; + +/** + * Date: 29.12.2016 + * Time: 14:32 + * + * @author Yuri Shmakov + */ +@SuppressWarnings("WeakerAccess") +public class TestPresenter extends MvpPresenter { +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestView.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestView.java new file mode 100644 index 00000000..1a933847 --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/TestView.java @@ -0,0 +1,12 @@ +package com.arellomobile.mvp.inheritance_test.resources; + +import com.arellomobile.mvp.MvpView; + +/** + * Date: 29.12.2016 + * Time: 14:31 + * + * @author Yuri Shmakov + */ +public interface TestView extends MvpView { +} diff --git a/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ViewWithoutInject.java b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ViewWithoutInject.java new file mode 100644 index 00000000..f72090dd --- /dev/null +++ b/moxy/src/test/java/com/arellomobile/mvp/inheritance_test/resources/ViewWithoutInject.java @@ -0,0 +1,13 @@ +package com.arellomobile.mvp.inheritance_test.resources; + +import com.arellomobile.mvp.MvpDelegate; + +/** + * Date: 30.12.2016 + * Time: 00:09 + * + * @author Yuri Shmakov + */ +public class ViewWithoutInject { + public MvpDelegate delegate; +} From 8806997f17344d5c9219b8a061c9ebc78bf648c1 Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Fri, 30 Dec 2016 01:42:56 +0700 Subject: [PATCH 5/6] [feature] Fixed some annotation processor warning --- .../java/com/arellomobile/mvp/compiler/MvpCompiler.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java index ee5550da..04020835 100644 --- a/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java +++ b/moxy-compiler/src/main/java/com/arellomobile/mvp/compiler/MvpCompiler.java @@ -80,6 +80,10 @@ public SourceVersion getSupportedSourceVersion() { @Override public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (annotations.isEmpty()) { + return false; + } + try { return throwableProcess(roundEnv); } catch (RuntimeException e) { @@ -88,7 +92,7 @@ public boolean process(Set annotations, RoundEnvironment getMessager().printMessage(Diagnostic.Kind.ERROR, "Moxy compilation failed; see the compiler error output for details (" + e + ")"); } - return false; + return true; } private boolean throwableProcess(RoundEnvironment roundEnv) { From 852f30dd58806002436a4027d8a7cf150df5f95f Mon Sep 17 00:00:00 2001 From: Yuri Shmakov Date: Fri, 30 Dec 2016 01:51:32 +0700 Subject: [PATCH 6/6] [artifact] Prepare version 1.4.3 --- README.md | 14 +++++++------- build.gradle | 4 ++-- sample-github/build.gradle | 6 +++--- sample-kotlin/build.gradle | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 2013d9bc..c1eeee44 100644 --- a/README.md +++ b/README.md @@ -76,36 +76,36 @@ Base modules integration: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy:1.4.2' - provided 'com.arello-mobile:moxy-compiler:1.4.2' + compile 'com.arello-mobile:moxy:1.4.3' + provided 'com.arello-mobile:moxy-compiler:1.4.3' } ``` If you want to see generated code, use `apt` instead of `provided` dependency type: ```groovy dependencies { ... - apt 'com.arello-mobile:moxy-compiler:1.4.2' + apt 'com.arello-mobile:moxy-compiler:1.4.3' } ``` Note: if you use gradle plugin verion 2.2.2 and above, so you can use `annotationProcessor` instead of `apt`: ```groovy dependencies { ... - annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.2' + annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.3' } ``` For additional base view classes `MvpActivity` and `MvpFragment` add this: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy-android:1.4.2' + compile 'com.arello-mobile:moxy-android:1.4.3' } ``` If you are planing to use AppCompat, then you can use `MvpAppCompatActivity` and `MvpAppCompatFragment`. Then add this: ```groovy dependencies { ... - compile 'com.arello-mobile:moxy-app-compat:1.4.2' + compile 'com.arello-mobile:moxy-app-compat:1.4.3' compile 'com.android.support:appcompat-v7:$support_version' } ``` @@ -114,7 +114,7 @@ If you are using kotlin, use `kapt` instead of `provided`/`apt` dependency type ```groovy dependencies { ... - kapt 'com.arello-mobile:moxy-compiler:1.4.2' + kapt 'com.arello-mobile:moxy-compiler:1.4.3' } kapt { generateStubs = true diff --git a/build.gradle b/build.gradle index 0702bf24..1470a485 100644 --- a/build.gradle +++ b/build.gradle @@ -19,8 +19,8 @@ allprojects { } ext { - targetVersionCode = 35 - targetVersionName = "1.4.2" + targetVersionCode = 36 + targetVersionName = "1.4.3" } task clean(type: Delete) { diff --git a/sample-github/build.gradle b/sample-github/build.gradle index 59411a21..c5b63688 100644 --- a/sample-github/build.gradle +++ b/sample-github/build.gradle @@ -68,7 +68,7 @@ dependencies { testCompile "org.hamcrest:hamcrest-all:1.3" testCompile "org.robolectric:robolectric:3.1-rc1" - compile 'com.arello-mobile:moxy:1.4.2' - compile 'com.arello-mobile:moxy-app-compat:1.4.2' - annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.2' + compile 'com.arello-mobile:moxy:1.4.3' + compile 'com.arello-mobile:moxy-app-compat:1.4.3' + annotationProcessor 'com.arello-mobile:moxy-compiler:1.4.3' } \ No newline at end of file diff --git a/sample-kotlin/build.gradle b/sample-kotlin/build.gradle index 2f1ff2f9..74e859ad 100644 --- a/sample-kotlin/build.gradle +++ b/sample-kotlin/build.gradle @@ -40,9 +40,9 @@ android { dependencies { compile 'com.android.support:appcompat-v7:25.0.0' - compile 'com.arello-mobile:moxy:1.4.2' - compile 'com.arello-mobile:moxy-app-compat:1.4.2' - kapt 'com.arello-mobile:moxy-compiler:1.4.2' + compile 'com.arello-mobile:moxy:1.4.3' + compile 'com.arello-mobile:moxy-app-compat:1.4.3' + kapt 'com.arello-mobile:moxy-compiler:1.4.3' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }