Skip to content

Commit

Permalink
Add Instant App Support
Browse files Browse the repository at this point in the history
Update copyright
Set version to 1.0.0-beta2
Rename DelayedTasks to ScheduledTasks
Separate app and library scopes for transformation
  • Loading branch information
Can Elmas authored and Can Elmas committed Feb 11, 2018
1 parent b029712 commit d52c032
Show file tree
Hide file tree
Showing 55 changed files with 356 additions and 109 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Change Log
==========

Version 1.0.0-beta2 *(2018-02-11)*
----------------------------------
* Add `FeaturePlugin` and `InstantAppPlugin` support [#28](https://github.com/canelmas/let/issues/28)
* Rename `Delayed Tasks` to `ScheduledTasks`
* Update copyright

Version 1.0.0-beta1 *(2017-09-04)*
----------------------------------
* Use Transform API for weaving [#23](https://github.com/canelmas/let/issues/23)
Expand All @@ -18,5 +24,4 @@ Version 0.1.10 *(2016-03-20)*

Version 0.1.9 *(2015-11-12)*
----------------------------

initial release
* initial release
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
buildscript {

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

Expand Down
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=1.0.0-beta1
VERSION_NAME=1.0.0-beta2
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 let-annotations/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions let-annotations/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# Copyright (C) 2015 Can Elmas
# Copyright (C) 2018 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
#
# Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion let-plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions let-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# Copyright (C) 2015 Can Elmas
# Copyright (C) 2018 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
#
# Unless required by applicable law or agreed to in writing, software
Expand Down
25 changes: 15 additions & 10 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) 2017 Can Elmas
* Copyright (C) 2018 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 @@ -17,6 +17,8 @@
package com.canelmas.let

import com.android.build.gradle.AppPlugin
import com.android.build.gradle.FeaturePlugin
import com.android.build.gradle.InstantAppPlugin
import com.android.build.gradle.LibraryPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand All @@ -26,23 +28,26 @@ class LetPlugin implements Plugin<Project> {
@Override
void apply(Project project) {

makeSureProjectIsAndroidAppOrLib(project)
makeSureProjectIsCompatible(project)

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

project.dependencies {
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'
implementation 'com.canelmas.let:let-runtime:1.0.0-beta2'
implementation 'com.canelmas.let:let-annotations:1.0.0-beta2'
}
}

private void makeSureProjectIsAndroidAppOrLib(Project project) {
def hasApp = project.plugins.withType(AppPlugin)
def hasLib = project.plugins.withType(LibraryPlugin)
private void makeSureProjectIsCompatible(Project project) {
def hasAppPlugin = project.plugins.withType(AppPlugin)
def hasLibPlugin = project.plugins.withType(LibraryPlugin)
def hasFeaturePlugin = project.plugins.withType(FeaturePlugin)
def hasInstantAppPlugin = project.plugins.withType(InstantAppPlugin)

if (!hasApp && !hasLib) {
throw new IllegalStateException("'android' or 'android-library' plugin required.")
if (!hasAppPlugin && !hasLibPlugin && !hasFeaturePlugin && !hasInstantAppPlugin) {
throw new IllegalStateException("Project must have one the following plugins applied " +
": 'android', 'android-library', 'feature', 'instantapp'")
}
}

Expand Down
18 changes: 14 additions & 4 deletions let-plugin/src/main/groovy/com/canelmas/let/LetTransform.groovy
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright (C) 2017 Can Elmas
* Copyright (C) 2018 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,6 +18,7 @@ package com.canelmas.let

import com.android.annotations.NonNull
import com.android.build.api.transform.*
import com.android.build.gradle.LibraryPlugin
import com.google.common.base.Joiner
import com.google.common.base.Strings
import com.google.common.collect.Lists
Expand All @@ -32,9 +33,19 @@ import org.gradle.api.logging.Logger
class LetTransform extends Transform {

private Project project
private boolean isLibrary

private static final Set<QualifiedContent.Scope> LIBRARY_SCOPE = Sets.immutableEnumSet(
QualifiedContent.Scope.PROJECT)

private static final Set<QualifiedContent.Scope> APP_SCOPE = Sets.immutableEnumSet(
QualifiedContent.Scope.PROJECT,
QualifiedContent.Scope.SUB_PROJECTS,
QualifiedContent.Scope.EXTERNAL_LIBRARIES)

LetTransform(Project project) {
this.project = project
this.isLibrary = project.plugins.hasPlugin(LibraryPlugin)
}

@Override
Expand Down Expand Up @@ -129,8 +140,7 @@ class LetTransform extends Transform {
@NonNull
@Override
Set<QualifiedContent.Scope> getScopes() {
return Sets.immutableEnumSet(QualifiedContent.Scope.PROJECT,
QualifiedContent.Scope.EXTERNAL_LIBRARIES)
return isLibrary ? LIBRARY_SCOPE : APP_SCOPE
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (C) 2015 Can Elmas
# Copyright (C) 2018 Can Elmas
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
42 changes: 1 addition & 41 deletions let-runtime/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main

/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,40 +50,4 @@ android {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

android.libraryVariants.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", android.bootClasspath.join(File.pathSeparator)
]

MessageHandler handler = new MessageHandler(true);
new Main().run(args, handler)

def log = project.logger
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:
case IMessage.INFO:
log.info message.message, message.thrown
break;
case IMessage.DEBUG:
log.debug message.message, message.thrown
break;
}
}
}
}
4 changes: 2 additions & 2 deletions let-runtime/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#
# Copyright (C) 2015 Can Elmas
# Copyright (C) 2018 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
#
# Unless required by applicable law or agreed to in writing, software
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion let-runtime/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (C) 2015 Can Elmas
~ Copyright (C) 2018 Can Elmas
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions let-runtime/src/main/java/com/canelmas/let/Let.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@ public final class Let {
*/
public static void handle(Object source, int requestCode, String[] permissions, int[] grantResults) {

final DelayedTasks.Task delayedTask = DelayedTasks.get(requestCode);
final ScheduledTasks.Task delayedTask = ScheduledTasks.get(requestCode);

if (null != delayedTask) {

Expand Down
2 changes: 1 addition & 1 deletion let-runtime/src/main/java/com/canelmas/let/LetAspect.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion let-runtime/src/main/java/com/canelmas/let/LetContext.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -109,7 +109,7 @@ private Object proceed(final boolean retry) {

final int requestCode = PERMISSIONS_REQUEST_CODE.getAndIncrement() & 0xff;

DelayedTasks.add(new DelayedTasks.Task(permissionsToAsk, requestCode, joinPoint));
ScheduledTasks.add(new ScheduledTasks.Task(permissionsToAsk, requestCode, joinPoint));

letContext.requestPermissions(permissionsToAsk.toArray(new String[]{}), requestCode);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2015 Can Elmas
* Copyright (C) 2018 Can Elmas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,7 @@
import java.util.Map;
import java.util.concurrent.Callable;

final class DelayedTasks {
final class ScheduledTasks {

@SuppressLint("UseSparseArrays")
private static Map<Integer, Task> tasks = Collections.synchronizedMap(new HashMap<Integer, Task>());
Expand Down Expand Up @@ -67,7 +67,7 @@ public Object call() throws Exception {
} catch (Throwable t) {
throw new LetException("Future Task execution failed!", t);
} finally {
DelayedTasks.remove(this);
ScheduledTasks.remove(this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion let-runtime/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (C) 2015 Can Elmas
~ Copyright (C) 2018 Can Elmas
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit d52c032

Please sign in to comment.