Skip to content

Commit

Permalink
Merge pull request #24 from canelmas/kotlin-support
Browse files Browse the repository at this point in the history
Kotlin support
  • Loading branch information
canelmas authored Sep 4, 2017
2 parents 3d3fbb9 + b029712 commit 88b53ef
Show file tree
Hide file tree
Showing 19 changed files with 251 additions and 201 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Change Log
==========

Version 1.0.0-beta1 *(2017-09-04)*
----------------------------------
* Use Transform API for weaving [#23](https://github.com/canelmas/let/issues/23)
* Support Kotlin [#17](https://github.com/canelmas/let/issues/17)
* Remove logger [#20](https://github.com/canelmas/let/issues/20)

Version 0.1.11 *(2016-06-07)*
-----------------------------
* Fix the potential java.lang.IllegalArgumentException: Can only use lower
8 bits for requestCode [#11](https://github.com/canelmas/let/issues/11)

Version 0.1.10 *(2016-03-20)*
-----------------------------
* Change: Set `@AskPermission` retention policy to `RUNTIME` (again)
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Let
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Let-green.svg?style=true)](https://android-arsenal.com/details/1/2843) [![](https://img.shields.io/badge/AndroidWeekly-%23182-red.svg)](http://androidweekly.net/issues/issue-182)
[![Join the chat at https://gitter.im/canelmas/let](https://badges.gitter.im/canelmas/let.svg)](https://gitter.im/canelmas/let?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Annotation based simple API flavoured with [AOP] (https://en.wikipedia.org/wiki/Aspect-oriented_programming) to handle new Android runtime permission model.
Annotation based simple API flavoured with [AOP](https://en.wikipedia.org/wiki/Aspect-oriented_programming) to handle new Android runtime permission model.

If you check [Google's Samples] (https://github.com/googlesamples/android-RuntimePermissions/blob/master/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java)
If you check [Google's Samples](https://github.com/googlesamples/android-RuntimePermissions/blob/master/Application/src/main/java/com/example/android/system/runtimepermissions/MainActivity.java)
about the new permission model, you'll see a lot of boiler plate code for requesting, handling
and retrying the request for required permissions.

Expand Down Expand Up @@ -106,7 +106,6 @@ buildscript {
}
}
apply plugin: 'com.android.application'
apply plugin: 'let'
Expand All @@ -115,28 +114,28 @@ repositories {
}
```

For SNAPSHOT version :

For kotlin :
```groovy
buildscript {
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
repositories {
jcenter()
}
dependencies {
classpath 'com.canelmas.let:let-plugin:0.1.11-SNAPSHOT'
dependencies {
classpath 'com.canelmas.let:let-plugin:1.0.0-beta1'
}
}
apply plugin: 'com.android.application'
apply plugin: 'let'
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
repositories {
jcenter()
}
```


Proguard
====

Expand Down
42 changes: 27 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
buildscript {

ext.versions = [
compileSdkVersion : 26,
buildToolsVersion : '26.0.1',
minSdkVersion : 14,
targetSdkVersion : 26,
supportLibrary : '26.0.1',
aspectjrt : '1.8.9',
aspectjtools : '1.8.9',
androidPlugin : '3.0.0-beta4',
androidMavenPlugin: '1.2'
]

ext.deps = [
supportAnnotations : "com.android.support:support-annotations:${versions.supportLibrary}",
supportDesign : "com.android.support:design:${versions.supportLibrary}",
appCompatv7 : "com.android.support:appcompat-v7:${versions.supportLibrary}",
aspectjrt : "org.aspectj:aspectjrt:${versions.aspectjrt}",
aspectjtools : "org.aspectj:aspectjtools:${versions.aspectjtools}",
androidGradlePlugin: "com.android.tools.build:gradle:${versions.androidPlugin}",
androidMavenPlugin : "com.github.dcendents:android-maven-plugin:${versions.androidMavenPlugin}",
junit : 'junit:junit:4.12'
]

repositories {
jcenter()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath deps.androidGradlePlugin
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}

allprojects {
repositories {
jcenter()
google()
}

group = GROUP
version = VERSION_NAME
}

ext {
compileSdkVersion = 23
buildToolsVersion = '22.0.1'
minSdkVersion = 10
targetSdkVersion = 23
}

ext.deps = [
supportAnnotations : 'com.android.support:support-annotations:23.0.1',
supportDesign : 'com.android.support:design:23.0.1',
appCompatv7 : 'com.android.support:appcompat-v7:23.0.1',
]
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# org.gradle.parallel=true
#Tue Sep 22 16:15:19 EEST 2015

VERSION_NAME=0.1.11
VERSION_NAME=1.0.0-beta1
GROUP=com.canelmas.let

POM_DESCRIPTION=Annotation based simple API flavoured with AOP to handle new Android runtime permission model
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
6 changes: 3 additions & 3 deletions let-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ sourceCompatibility = JavaVersion.VERSION_1_7
dependencies {
compile gradleApi()
compile localGroovy()
compile 'com.android.tools.build:gradle:1.3.0'
compile 'org.aspectj:aspectjtools:1.8.6'
compile 'org.aspectj:aspectjrt:1.8.6'
compile deps.androidGradlePlugin
compile deps.aspectjtools
compile deps.aspectjrt
}

modifyPom {
Expand Down
73 changes: 17 additions & 56 deletions let-plugin/src/main/groovy/com/canelmas/let/LetPlugin.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2017 Can Elmas
*
* 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
* 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,
Expand All @@ -18,71 +18,32 @@ package com.canelmas.let

import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.compile.JavaCompile

class LetPlugin implements Plugin<Project> {

@Override void apply(Project project) {
def hasApp = project.plugins.withType(AppPlugin)
def hasLib = project.plugins.withType(LibraryPlugin)
if (!hasApp && !hasLib) {
throw new IllegalStateException("'android' or 'android-library' plugin required.")
}
@Override
void apply(Project project) {

final def log = project.logger
final def variants
if (hasApp) {
variants = project.android.applicationVariants
} else {
variants = project.android.libraryVariants
}
makeSureProjectIsAndroidAppOrLib(project)

project.android.registerTransform(new LetTransform(project))

project.dependencies {
compile 'com.canelmas.let:let-runtime:0.1.11'
compile 'org.aspectj:aspectjrt:1.8.6'
compile 'com.canelmas.let:let-annotations:0.1.11'
implementation 'org.aspectj:aspectjrt:1.8.9'
implementation 'com.canelmas.let:let-runtime:1.0.0-beta1'
implementation 'com.canelmas.let:let-annotations:1.0.0-beta1'
}
}

variants.all { variant ->
JavaCompile javaCompile = variant.javaCompile
javaCompile.doLast {
String[] args = [
"-showWeaveInfo",
"-1.5",
"-inpath", javaCompile.destinationDir.toString(),
"-aspectpath", javaCompile.classpath.asPath,
"-d", javaCompile.destinationDir.toString(),
"-classpath", javaCompile.classpath.asPath,
"-bootclasspath", project.android.bootClasspath.join(File.pathSeparator)
]
log.debug "ajc args: " + Arrays.toString(args)
private void makeSureProjectIsAndroidAppOrLib(Project project) {
def hasApp = project.plugins.withType(AppPlugin)
def hasLib = project.plugins.withType(LibraryPlugin)

MessageHandler handler = new MessageHandler(true);
new Main().run(args, handler);
for (IMessage message : handler.getMessages(null, true)) {
switch (message.getKind()) {
case IMessage.ABORT:
case IMessage.ERROR:
case IMessage.FAIL:
log.error message.message, message.thrown
break;
case IMessage.WARNING:
log.warn message.message, message.thrown
break;
case IMessage.INFO:
log.info message.message, message.thrown
break;
case IMessage.DEBUG:
log.debug message.message, message.thrown
break;
}
}
}
if (!hasApp && !hasLib) {
throw new IllegalStateException("'android' or 'android-library' plugin required.")
}
}

}
Loading

0 comments on commit 88b53ef

Please sign in to comment.