Skip to content

Commit

Permalink
Merge branch 'release/1.0.1'
Browse files Browse the repository at this point in the history
# Conflicts:
#	green-annotations-api/pom.xml
#	green-annotations-test/pom.xml
#	green-annotations/pom.xml
#	pom.xml
  • Loading branch information
tmtron committed Oct 7, 2016
2 parents dd8c84a + 9c31b35 commit c4ebb71
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 11 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/tmtron.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An [Android Annotations](http://androidannotations.org/) plugin to support the [
<!--
![] is the markdown syntax to add an image and this is surounded by a link to the travis-ci builds page
-->
[![Build Status](https://travis-ci.org/tmtron/green-annotations.svg)](https://travis-ci.org/tmtron/green-annotations/builds)
[![Build Status](https://travis-ci.org/tmtron/green-annotations.svg?label=travis)](https://travis-ci.org/tmtron/green-annotations/builds) [![Maven Central](https://img.shields.io/maven-central/v/com.tmtron/green-annotations.svg?maxAge=2592000)](https://maven-badges.herokuapp.com/maven-central/com.tmtron/green-annotations) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-green--annotations-green.svg?style=true)](https://android-arsenal.com/details/1/4405) [![Javadoc](https://javadoc-emblem.rhcloud.com/doc/com.tmtron/green-annotations/badge.svg)](http://www.javadoc.io/doc/com.tmtron/green-annotations/) [![license](https://img.shields.io/github/license/tmtron/green-annotations.svg?maxAge=2592000)](https://raw.githubusercontent.com/tmtron/green-annotations/develop/LICENSE) [![Join the chat at https://gitter.im/green-annotations/Lobby](https://badges.gitter.im/green-annotations/Lobby.svg)](https://gitter.im/green-annotations/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

## Usage in your Android Studio project:

Expand All @@ -14,8 +14,8 @@ In the `build.gradle` file of the module project:
```gradle
dependencies {
// Android Annotations for Greenrobot
apt 'com.tmtron:green-annotations:1.0.0'
compile 'com.tmtron:green-annotations-api:1.0.0'
apt 'com.tmtron:green-annotations:1.0.1'
compile 'com.tmtron:green-annotations-api:1.0.1'
}
```

Expand Down
3 changes: 3 additions & 0 deletions green-annotations-test/lint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
http://stackoverflow.com/questions/39685618/intellij-idea-element-ignore-is-not-allowed-here
-->
<ignore regexp=".*GreenEventBusActivity.*" />
<ignore regexp=".*ActivityAfter.*" />
<ignore regexp=".*ActivityBefore.*" />
<ignore regexp=".*Service4EventTest.*" />
</issue>
</lint>
1 change: 1 addition & 0 deletions green-annotations-test/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

<activity android:name=".GreenEventBusActivity_" />
<activity android:name=".ActivityAfter_" />
<service android:name=".Service4EventTest_" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.tmtron.greenannotations.test;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.widget.Toast;
import com.tmtron.greenannotations.EventBusGreenRobot;
Expand All @@ -27,13 +28,16 @@
/**
* test class to show how to use EventBus with GreenAnnotations
*/
@SuppressLint("Registered")
@SuppressWarnings({"WeakerAccess"})
@EActivity
public class ActivityAfter extends Activity {

@SuppressWarnings("CanBeFinal")
@EventBusGreenRobot
EventBus eventBus;

void fireEvent(String message) {
void fireEvent(@SuppressWarnings("SameParameterValue") String message) {
eventBus.post(new MessageEvent(message));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/**
* test class to show how to use EventBus without GreenAnnotations
*/
@SuppressWarnings({"WeakerAccess"})
public class ActivityBefore extends Activity {

EventBus eventBus;
Expand All @@ -48,7 +49,7 @@ public void onStop() {
super.onStop();
}

void fireEvent(String message) {
void fireEvent(@SuppressWarnings("SameParameterValue") String message) {
eventBus.post(new MessageEvent(message));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright © 2016 Martin Trummer (martin.trummer@tmtron.com)
*
* Licensed 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 com.tmtron.greenannotations.test;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import com.tmtron.greenannotations.EventBusGreenRobot;
import org.androidannotations.annotations.EService;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@SuppressWarnings({"WeakerAccess"})
@EService
public class Service4EventTest extends Service {
static final String EVENT_IDENTIFIER = "service4EventTest-id";

@SuppressWarnings("all")
@EventBusGreenRobot
EventBus eventBus;

void fireEvent() {
eventBus.post(new Event4Tests(EVENT_IDENTIFIER));
}

int startId = 0;
String eventIdentifier;

@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(Event4Tests event4Tests) {
eventIdentifier = event4Tests.identifier;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.startId = startId;
return START_STICKY_COMPATIBILITY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.util.ServiceController;

import static org.fest.assertions.api.Assertions.assertThat;

@RunWith(RobolectricTestRunner.class)
public class GreenEventBusActivityTest {

private static final int START_ID = 17;

@Test
public void testEventBusAssigned() {
GreenEventBusActivity activity = Robolectric.setupActivity(GreenEventBusActivity_.class);
Expand Down Expand Up @@ -54,4 +57,23 @@ public void testEventFired() {
assertThat(activity.eventIdentifier).isEqualTo(Bean4EventTest.EVENT_IDENTIFIER);
}

@Test
public void testServiceEventFired() {
ServiceController<Service4EventTest_> serviceController = Robolectric.buildService(Service4EventTest_.class).attach().create();
Service4EventTest service = serviceController.get();

assertThat(service.eventBus).isNotNull();

assertThat(service.startId).isEqualTo(0);
serviceController.startCommand(0, START_ID);
assertThat(service.startId).isEqualTo(START_ID);

assertThat(service.eventIdentifier).isNullOrEmpty();
service.fireEvent();
assertThat(service.eventIdentifier).isEqualTo(Service4EventTest.EVENT_IDENTIFIER);

serviceController.destroy();
}


}
2 changes: 1 addition & 1 deletion green-annotations/green-annotations.iml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
<orderEntry type="module" module-name="green-annotations-api" />
<orderEntry type="library" name="Maven: org.androidannotations:androidannotations:4.1.0" level="project" />
<orderEntry type="library" name="Maven: org.androidannotations:androidannotations-api:4.1.0" level="project" />
<orderEntry type="library" name="Maven: com.helger:jcodemodel:2.8.5" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.androidannotations:androidannotations-testutils:4.1.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.greenrobot:eventbus:3.0.0" level="project" />
<orderEntry type="library" name="Maven: com.helger:jcodemodel:2.8.5" level="project" />
<orderEntry type="library" name="Maven: com.google.code.findbugs:annotations:2.0.3" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.android:android:2.3.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: commons-logging:commons-logging:1.1.1" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.androidannotations.handler.MethodInjectionHandler;
import org.androidannotations.helper.InjectHelper;
import org.androidannotations.holder.EComponentHolder;
import org.androidannotations.holder.EServiceHolder;
import org.androidannotations.holder.HasLifecycleMethods;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
Expand Down Expand Up @@ -166,8 +167,15 @@ private boolean hasSubscribeAnnotation(Element element) {
private void handleEventBusRegistration(IJAssignmentTarget fieldRef
, HasLifecycleMethods holderWithLifecycleMethods) {

JBlock onStartBlock = holderWithLifecycleMethods.getOnStartAfterSuperBlock();
JBlock onStopBlock = holderWithLifecycleMethods.getOnStopBeforeSuperBlock();
JBlock onStartBlock;
JBlock onStopBlock;
if (holderWithLifecycleMethods instanceof EServiceHolder) {
onStartBlock = holderWithLifecycleMethods.getOnCreateAfterSuperBlock();
onStopBlock = holderWithLifecycleMethods.getOnDestroyBeforeSuperBlock();
} else {
onStartBlock = holderWithLifecycleMethods.getOnStartAfterSuperBlock();
onStopBlock = holderWithLifecycleMethods.getOnStopBeforeSuperBlock();
}
onStartBlock.invoke(fieldRef, "register").arg(JExpr._this());
onStopBlock.invoke(fieldRef, "unregister").arg(JExpr._this());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.IOException;

@SuppressWarnings({"WeakerAccess"})
public class EventBusGreenRobotTest extends ProcessorTestHelper {

@Before
Expand Down Expand Up @@ -86,4 +87,17 @@ public void eBeanCompilationFails() throws IOException {
assertCompilationErrorOn(SomeEbeanError.class, "@EventBusGreenRobot", compileResult);
}

/**
* testcase for <a href="https://github.com/tmtron/green-annotations/issues/12">issue 12</a>
*/
@Test
public void eServiceCompiles() {
CompileResult compileResult = compileFiles(
SomeEService.class
);
assertCompilationSuccessful(compileResult);
assertGeneratedClassContainsBusInitialisation(SomeEService.class);
assertGeneratedClassContainsBusRegistration(SomeEService.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ void assertGeneratedClassContainsBusInitialisation(Class sourceClass) {
}

private final String[] codeBusRegister = new String[]{
" super.onStart();",
" this.eventBus.register(this);"};

private final String[] codeBusUnregister = new String[]{
" this.eventBus.unregister(this);",
" super.onStop();"};
" this.eventBus.unregister(this);"};

void assertGeneratedClassDoesNotContainBusRegistration(Class sourceClass) {
assertGeneratedClassDoesNotContain(sourceClass, codeBusRegister);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright © 2016 Martin Trummer (martin.trummer@tmtron.com)
*
* Licensed 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 com.tmtron.greenannotations;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import org.androidannotations.annotations.EService;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

@EService
class SomeEService extends Service {

// used for testing only
@SuppressWarnings("unused")
@EventBusGreenRobot
public EventBus eventBus;

@SuppressWarnings("EmptyMethod")
@Subscribe
public void handleEvent(final SomeEvent event) { }

@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<application>
<activity android:name="com.tmtron.greenannotations.SomeActivity_"/>
<service android:name=".SomeEService_" />
</application>

</manifest>

0 comments on commit c4ebb71

Please sign in to comment.