Skip to content

Commit

Permalink
Releasing version 1.1.1
Browse files Browse the repository at this point in the history
@OnBackground and @OnUIThread now work on static methods.

Method search can now find private methods and looks for compatible, not exact matches.

Updated gradle files to latest dependencies.
  • Loading branch information
jmartinesp committed Oct 28, 2014
1 parent a21003a commit 064c1af
Show file tree
Hide file tree
Showing 49 changed files with 385 additions and 66 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog:

### Versions:
* **1.1.0** - New @SaveInstance annotation to automatically save and restore variables on configuration changes.
* **1.1.1** - @OnBackground and @OnUIThread now can be used with static methods. Solved several method search problems, too.
* **1.1.0** - New @SaveInstance annotation to automatically save and restore variables on configuration changes.
* **1.0.4** - Fixed bug in @InjectViews annotation which didn't recognize "List" as a valid container.
* **1.0.3** - Fixed bug in ``@OnLongClick`` annotation.
* **1.0.2** - Fixed bug that prevented anything but an Activity from injection. Disabled type checking for auto-generated methods, so users won't have to type ``@CompileStatic(TypeCheckingMethod.SKIP)``.
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class MyActivity extends Activity {
}
```

## Colaborators

I'd really want to thank:

* [Dexafree](https://github.com/dexafree) for adding `@SaveInstance` annotation and helping with the testing.
* [Eugene Kamenev](https://github.com/eugene-kamenev) for adding DSL functionality to *android-dsl* branch.

## Documentation

For more info, please [read the wiki pages](https://github.com/Arasthel/SwissKnife/wiki). They contain explanations about how to use the library and the available annotations:
Expand Down Expand Up @@ -77,7 +84,7 @@ Once your project App Module is configured to use Groovy you can add this librar
```groovy
dependencies {
...
compile 'com.arasthel:swissknife:1.1.0'
compile 'com.arasthel:swissknife:1.1.1'
...
}
Expand Down
19 changes: 11 additions & 8 deletions SwissKnife/SwissKnife.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.0.4" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.1.1" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -10,9 +10,10 @@
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -38,23 +39,25 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/groovy" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/groovy" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand All @@ -79,11 +82,11 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 21 Platform (1)" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.0" level="project" />
<orderEntry type="library" exported="" name="groovy-2.4.0-beta-3-grooid" level="project" />
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-20.0.0" level="project" />
</component>
</module>

20 changes: 4 additions & 16 deletions SwissKnife/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.0'
}
}

apply plugin: 'com.android.library'
apply plugin: 'me.champeau.gradle.groovy-android'

android {
compileSdkVersion 19
compileSdkVersion 21
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "com.arasthel.swissknife"
minSdkVersion 8
targetSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0.1"
versionName "1.1.1"
}
buildTypes {
release {
Expand All @@ -42,9 +31,8 @@ repositories {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'org.codehaus.groovy:groovy:2.4.0-beta-3:grooid'
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:support-v4:21.0.0'
}

// Script to upload plugin to Maven
apply from: '../maven_push.gradle'

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class SwissKnife {

public static void inject(Object target) {
Method method = null;
Method[] methods = null;
try {
method = SwissKnife.searchMethod(target, "injectViews", [Object.class]);
} catch (NoSuchMethodException e) {
Expand Down Expand Up @@ -414,10 +413,40 @@ public class SwissKnife {

Method method = null;

try {
method = currentObject.class.getMethod(name, parameters);
} catch (NoSuchMethodException e) {
return null;
// We use a set so methods can't appear twice in here
Set<Method> methods = new HashSet<>()
if(currentObject instanceof Class) {
methods.addAll(currentObject.getMethods())
// Search for private methods, too
methods.addAll(currentObject.getDeclaredMethods())
} else {
methods.addAll(currentObject.class.getMethods())
// Search for private methods, too
methods.addAll(currentObject.class.getDeclaredMethods())
}

// As getMethod(...) doesn't search for a compatible but an exact match, we have to search manually
for(Method m : methods) {
if(m.getName() == name) {
if(m.getParameterTypes().length == parameters.length) {
boolean found = true
for(int i = 0; i < m.getParameterTypes().length; i++) {
Class parameter = m.getParameterTypes()[i]
if(!parameter.isAssignableFrom(parameters[i])) {
found = false
}
}
if(found == true) {
method = m
break
}
}
}
}

// If method is private (shouldn't be), we make it accessible
if(!method.isAccessible()) {
method.setAccessible(true)
}

return method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OnBackgroundTransformation implements ASTTransformation, Opcodes {
}

private MethodNode createNewMethod(MethodNode annotatedMethod, BlockStatement originalCode) {
return new MethodNode(annotatedMethod.name+"\$background", ACC_PUBLIC, ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode);
return new MethodNode(annotatedMethod.name+"\$background", annotatedMethod.getModifiers(), ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode);
}

private void createRunnable(MethodNode annotatedMethod) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OnUIThreadTransformation implements ASTTransformation, Opcodes {
}

private MethodNode createNewMethod(MethodNode annotatedMethod, BlockStatement originalCode) {
return new MethodNode(annotatedMethod.name+"\$uithread", ACC_PUBLIC, ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode);
return new MethodNode(annotatedMethod.name+"\$uithread", annotatedMethod.getModifiers(), ClassHelper.VOID_TYPE, annotatedMethod.parameters, null, originalCode);
}

private void createRunnable(MethodNode annotatedMethod) {
Expand Down
2 changes: 1 addition & 1 deletion SwissKnifeProject.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.0.4" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.1.1" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.android.tools.build:gradle:0.13.+'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

VERSION_NAME=1.1.0
VERSION_CODE=6
VERSION_NAME=1.1.1
VERSION_CODE=7
GROUP=com.arasthel

POM_DESCRIPTION=Android library for View Injection and Async processing
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Tue Oct 28 12:47:37 CET 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.12-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip
23 changes: 3 additions & 20 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
classpath 'me.champeau.gradle:gradle-groovy-android-plugin:0.3.0'
}
}

apply plugin: 'com.android.application'
apply plugin: 'me.champeau.gradle.groovy-android'

android {
compileSdkVersion 19
compileSdkVersion 21
buildToolsVersion "20.0.0"

defaultConfig {
applicationId "com.dexafree.sample"
minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
Expand All @@ -29,16 +18,10 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

packagingOptions {
// workaround for http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/groovy-release-info.properties'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':SwissKnife')
compile 'org.codehaus.groovy:groovy:2.4.0-beta-2:grooid'
compile 'org.codehaus.groovy:groovy:2.4.0-beta-3:grooid'
}
17 changes: 10 additions & 7 deletions sample/sample.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.0.4" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.arasthel" external.system.module.version="1.1.1" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -10,9 +10,10 @@
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -37,23 +38,25 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/groovy" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/groovy" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand All @@ -78,10 +81,10 @@
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="jdk" jdkName="Android API 21 Platform (1)" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-annotations-21.0.0" level="project" />
<orderEntry type="library" exported="" name="groovy-2.4.0-beta-3-grooid" level="project" />
<orderEntry type="library" exported="" name="support-annotations-20.0.0" level="project" />
<orderEntry type="module" module-name="SwissKnife" exported="" />
</component>
</module>
Expand Down
Loading

0 comments on commit 064c1af

Please sign in to comment.