├── gradle.properties
├── sample
├── gradle.properties
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── layout
│ │ │ │ └── main_activity.xml
│ │ │ └── drawable
│ │ │ │ └── android.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── io
│ │ │ └── michaelrocks
│ │ │ └── databindingcompat
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── io
│ │ └── michaelrocks
│ │ └── databindingcompat
│ │ └── sample
│ │ └── MainActivityTest.java
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── plugin
├── src
│ └── main
│ │ ├── resources
│ │ └── META-INF
│ │ │ └── gradle-plugins
│ │ │ └── io.michaelrocks.databindingcompat.properties
│ │ └── java
│ │ └── io
│ │ └── michaelrocks
│ │ └── databindingcompat
│ │ ├── PluginVersion.kt
│ │ ├── logging
│ │ └── LoggerExtensions.kt
│ │ ├── transform
│ │ ├── TransformUnit.kt
│ │ ├── Changes.kt
│ │ ├── TransformSet.kt
│ │ └── DataBindingCompatTransform.kt
│ │ ├── processor
│ │ ├── Types.kt
│ │ ├── StandaloneClassWriter.kt
│ │ ├── ViewDataBindingClassPatcher.kt
│ │ └── DataBindingCompatProcessor.kt
│ │ └── DataBindingCompatPlugin.kt
└── build.gradle
├── .gitignore
├── .travis.yml
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/gradle.properties:
--------------------------------------------------------------------------------
1 | bootstrap=false
2 |
--------------------------------------------------------------------------------
/sample/gradle.properties:
--------------------------------------------------------------------------------
1 | android.useAndroidX=true
2 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DataBindingCompat
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'databindingcompat'
2 |
3 | include ':plugin'
4 | if (!properties['bootstrap'].toBoolean()) {
5 | include ':sample'
6 | }
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MichaelRocks/DataBindingCompat/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/plugin/src/main/resources/META-INF/gradle-plugins/io.michaelrocks.databindingcompat.properties:
--------------------------------------------------------------------------------
1 | implementation-class=io.michaelrocks.databindingcompat.DataBindingCompatPlugin
--------------------------------------------------------------------------------
/sample/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Gradle files
2 | .gradle/
3 | build/
4 |
5 | # IntelliJ IDEA and Android Studio files
6 | .idea/
7 | *.iml
8 |
9 | # Android files
10 | local.properties
11 |
12 | # Gradle Wrapper
13 | !gradle/wrapper/gradle-wrapper.jar
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/main_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/PluginVersion.kt:
--------------------------------------------------------------------------------
1 | package io.michaelrocks.databindingcompat
2 |
3 | import com.android.builder.model.Version
4 |
5 | object PluginVersion {
6 | val major: Int
7 | val minor: Int
8 | val patch: Int
9 | val suffix: String
10 |
11 | init {
12 | val version = Version.ANDROID_GRADLE_PLUGIN_VERSION
13 | suffix = version.substringAfter('-', "")
14 | val prefix = version.substringBefore('-')
15 | val parts = prefix.split('.', limit = 3)
16 | major = parts.getOrNull(0)?.toIntOrNull() ?: 0
17 | minor = parts.getOrNull(1)?.toIntOrNull() ?: 0
18 | patch = parts.getOrNull(2)?.toIntOrNull() ?: 0
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - tools
7 | - platform-tools
8 | - build-tools-28.0.3
9 | - android-28
10 |
11 | licenses:
12 | - 'android-sdk-license-.+'
13 |
14 | jdk: oraclejdk8
15 |
16 | sudo: false
17 |
18 | before_cache:
19 | - rm -rf $HOME/.m2/repository/io/michaelrocks/databindingcompat
20 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
21 |
22 | cache:
23 | directories:
24 | - $HOME/.m2
25 | - $HOME/.gradle/caches/
26 | - $HOME/.gradle/wrapper/
27 |
28 | before_install:
29 | - yes | sdkmanager "platforms;android-28"
30 |
31 | install:
32 | - ./gradlew assemble publishToMavenLocal -Pbootstrap=true --no-daemon --rerun-tasks
33 |
34 | script:
35 | - ./gradlew check --no-daemon
36 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/android.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'kotlin'
2 | apply plugin: 'io.michaelrocks.pablo'
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_8
5 | targetCompatibility = JavaVersion.VERSION_1_8
6 |
7 | dependencies {
8 | compileOnly gradleApi()
9 | compileOnly "com.android.tools.build:gradle:$androidToolsVersion"
10 | compileOnly "com.android.tools.build:gradle-api:$androidToolsVersion"
11 |
12 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
13 | implementation "ch.qos.logback:logback-classic:$logbackVersion"
14 |
15 | relocate "org.ow2.asm:asm:$asmVersion"
16 | relocate "org.ow2.asm:asm-commons:$asmVersion"
17 | relocate "io.michaelrocks:grip:$gripVersion"
18 | }
19 |
20 | pablo {
21 | artifactName = 'databindingcompat'
22 | repackage true
23 | }
24 |
25 | shadowJar {
26 | relocate 'io.michaelrocks.databindingcompat', 'io.michaelrocks.databindingcompat'
27 | relocate 'io.michaelrocks.grip', 'io.michaelrocks.databindingcompat.grip'
28 | relocate 'org.objectweb.asm', 'io.michaelrocks.databindingcompat.asm'
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/logging/LoggerExtensions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.logging
18 |
19 | import org.slf4j.Logger
20 | import org.slf4j.LoggerFactory
21 |
22 | fun T.getLogger(): Logger = getLogger(javaClass)
23 | fun getLogger(name: String): Logger = LoggerFactory.getLogger(name)
24 | fun getLogger(type: Class<*>): Logger = LoggerFactory.getLogger(type)
25 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/transform/TransformUnit.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.transform
18 |
19 | import java.io.File
20 |
21 | data class TransformUnit(
22 | val input: File,
23 | val output: File,
24 | val format: Format,
25 | val changes: Changes
26 | ) {
27 |
28 | enum class Format {
29 | DIRECTORY,
30 | JAR
31 | }
32 |
33 | enum class Status {
34 | UNKNOWN,
35 | UNCHANGED,
36 | ADDED,
37 | CHANGED,
38 | REMOVED
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | dependencies {
3 | classpath "com.android.tools.build:gradle:$androidToolsVersion"
4 | classpath "io.michaelrocks:databindingcompat:$version"
5 | }
6 | }
7 |
8 | apply plugin: 'com.android.application'
9 | apply plugin: 'io.michaelrocks.databindingcompat'
10 |
11 | android {
12 | compileSdkVersion 28
13 | buildToolsVersion "28.0.3"
14 |
15 | defaultConfig {
16 | applicationId "io.michaelrocks.databindingcompat.sample"
17 | minSdkVersion 16
18 | targetSdkVersion 28
19 | versionCode 1
20 | versionName version
21 |
22 | vectorDrawables.useSupportLibrary = true
23 |
24 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
25 | }
26 |
27 | buildTypes {
28 | release {
29 | minifyEnabled false
30 | proguardFiles getDefaultProguardFile('proguard-android.txt')
31 | }
32 | }
33 |
34 | dataBinding {
35 | enabled true
36 | }
37 | }
38 |
39 | dependencies {
40 | implementation 'androidx.appcompat:appcompat:1.0.2'
41 |
42 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
43 | androidTestImplementation 'androidx.test:runner:1.2.0'
44 | androidTestImplementation 'androidx.test:rules:1.2.0'
45 | }
46 |
--------------------------------------------------------------------------------
/sample/src/main/java/io/michaelrocks/databindingcompat/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.sample;
18 |
19 | import android.os.Bundle;
20 |
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import androidx.databinding.DataBindingUtil;
23 | import io.michaelrocks.databindingcompat.sample.databinding.MainActivityBinding;
24 |
25 | public class MainActivity extends AppCompatActivity {
26 | @Override
27 | protected void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | final MainActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.main_activity);
30 | binding.executePendingBindings();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/processor/Types.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.processor
18 |
19 | import io.michaelrocks.grip.mirrors.getObjectTypeByInternalName
20 |
21 | object Types {
22 | val ANDROIDX_APP_COMPAT_RESOURCES = getObjectTypeByInternalName("androidx/appcompat/content/res/AppCompatResources")
23 | val ANDROIDX_VIEW_DATA_BINDING = getObjectTypeByInternalName("androidx/databinding/ViewDataBinding")
24 | val SUPPORT_APP_COMPAT_RESOURCES = getObjectTypeByInternalName("android/support/v7/content/res/AppCompatResources")
25 | val SUPPORT_VIEW_DATA_BINDING = getObjectTypeByInternalName("android/databinding/ViewDataBinding")
26 | val VIEW = getObjectTypeByInternalName("android/view/View")
27 | }
28 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/DataBindingCompatPlugin.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat
18 |
19 | import com.android.build.gradle.BaseExtension
20 | import io.michaelrocks.databindingcompat.transform.DataBindingCompatTransform
21 | import org.gradle.api.GradleException
22 | import org.gradle.api.Plugin
23 | import org.gradle.api.Project
24 | import org.gradle.api.UnknownDomainObjectException
25 |
26 | class DataBindingCompatPlugin : Plugin {
27 | override fun apply(project: Project) {
28 | try {
29 | val android = project.extensions.getByName("android") as BaseExtension
30 | android.registerTransform(DataBindingCompatTransform(android))
31 | } catch (exception: UnknownDomainObjectException) {
32 | throw GradleException("DataBindingCompat plugin must be applied *AFTER* Android plugin", exception)
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/transform/Changes.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.transform
18 |
19 | import com.android.build.api.transform.Status
20 | import java.io.File
21 |
22 | interface Changes {
23 | val status: TransformUnit.Status
24 |
25 | val hasFileStatuses: Boolean
26 | val files: Collection
27 |
28 | fun getFileStatus(file: File): TransformUnit.Status
29 |
30 | class ForDirectory(
31 | private val changes: Map,
32 | private val incremental: Boolean
33 | ) : Changes {
34 |
35 | override val status get() = if (incremental) TransformUnit.Status.UNKNOWN else TransformUnit.Status.CHANGED
36 |
37 | override val hasFileStatuses get() = incremental
38 | override val files get() = changes.keys
39 |
40 | override fun getFileStatus(file: File): TransformUnit.Status {
41 | return changes[file]?.toTransformUnitStatus() ?: TransformUnit.Status.UNKNOWN
42 | }
43 | }
44 |
45 | class ForJar(
46 | private val jarStatus: Status,
47 | private val incremental: Boolean
48 | ) : Changes {
49 |
50 | override val status get() = if (incremental) jarStatus.toTransformUnitStatus() else TransformUnit.Status.CHANGED
51 |
52 | override val hasFileStatuses get() = false
53 | override val files get() = emptyList()
54 |
55 | override fun getFileStatus(file: File): TransformUnit.Status {
56 | return TransformUnit.Status.UNKNOWN
57 | }
58 | }
59 |
60 | companion object {
61 | private fun Status.toTransformUnitStatus(): TransformUnit.Status {
62 | return when (this) {
63 | Status.NOTCHANGED -> TransformUnit.Status.UNCHANGED
64 | Status.ADDED -> TransformUnit.Status.ADDED
65 | Status.CHANGED -> TransformUnit.Status.CHANGED
66 | Status.REMOVED -> TransformUnit.Status.REMOVED
67 | }
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/processor/StandaloneClassWriter.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.processor
18 |
19 | import io.michaelrocks.databindingcompat.logging.getLogger
20 | import io.michaelrocks.grip.ClassRegistry
21 | import io.michaelrocks.grip.mirrors.ClassMirror
22 | import io.michaelrocks.grip.mirrors.Type
23 | import io.michaelrocks.grip.mirrors.getObjectType
24 | import io.michaelrocks.grip.mirrors.getObjectTypeByInternalName
25 | import org.objectweb.asm.ClassReader
26 | import org.objectweb.asm.ClassWriter
27 | import java.util.HashSet
28 |
29 | class StandaloneClassWriter : ClassWriter {
30 | private val logger = getLogger()
31 | private val classRegistry: ClassRegistry
32 |
33 | constructor(flags: Int, classRegistry: ClassRegistry) : super(flags) {
34 | this.classRegistry = classRegistry
35 | }
36 |
37 | constructor(classReader: ClassReader, flags: Int, classRegistry: ClassRegistry) : super(classReader, flags) {
38 | this.classRegistry = classRegistry
39 | }
40 |
41 | override fun getCommonSuperClass(type1: String, type2: String): String {
42 | val hierarchy = HashSet()
43 | for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type1))) {
44 | hierarchy.add(mirror.type)
45 | }
46 |
47 | for (mirror in classRegistry.findClassHierarchy(getObjectTypeByInternalName(type2))) {
48 | if (mirror.type in hierarchy) {
49 | return mirror.type.internalName
50 | }
51 | }
52 |
53 | logger.warn("[getCommonSuperClass]: {} & {} = NOT FOUND ", type1, type2)
54 | return OBJECT_INTERNAL_NAME
55 | }
56 |
57 | private fun ClassRegistry.findClassHierarchy(type: Type.Object): Sequence {
58 | return generateSequence(getClassMirror(type)) {
59 | it.superType?.let { getClassMirror(it) }
60 | }
61 | }
62 |
63 | companion object {
64 | private val OBJECT_INTERNAL_NAME = getObjectType().internalName
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/io/michaelrocks/databindingcompat/sample/MainActivityTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.sample;
18 |
19 | import android.graphics.drawable.Drawable;
20 | import android.graphics.drawable.VectorDrawable;
21 | import android.os.Build;
22 | import android.view.View;
23 | import android.widget.ImageView;
24 |
25 | import org.hamcrest.Description;
26 | import org.hamcrest.Matcher;
27 | import org.junit.Rule;
28 | import org.junit.Test;
29 | import org.junit.runner.RunWith;
30 |
31 | import androidx.test.espresso.matcher.BoundedMatcher;
32 | import androidx.test.filters.LargeTest;
33 | import androidx.test.rule.ActivityTestRule;
34 | import androidx.test.runner.AndroidJUnit4;
35 | import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;
36 |
37 |
38 | import static androidx.test.espresso.Espresso.onView;
39 | import static androidx.test.espresso.assertion.ViewAssertions.matches;
40 | import static androidx.test.espresso.matcher.ViewMatchers.withId;
41 |
42 | @RunWith(AndroidJUnit4.class)
43 | @LargeTest
44 | public class MainActivityTest {
45 | @Rule
46 | public ActivityTestRule rule = new ActivityTestRule<>(MainActivity.class);
47 |
48 | @Test
49 | public void checkImageViewContainsVectorDrawable() {
50 | onView(withId(R.id.image))
51 | .check(matches(withVectorDrawable()));
52 | }
53 |
54 | private static Matcher withVectorDrawable() {
55 | return new BoundedMatcher(ImageView.class) {
56 | public void describeTo(Description description) {
57 | description.appendText("with vector drawable");
58 | }
59 |
60 | public boolean matchesSafely(ImageView imageView) {
61 | final Drawable drawable = imageView.getDrawable();
62 | if (drawable instanceof VectorDrawableCompat) {
63 | return true;
64 | }
65 |
66 | //noinspection SimplifiableIfStatement
67 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
68 | return drawable instanceof VectorDrawable;
69 | }
70 |
71 | return false;
72 | }
73 | };
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/processor/ViewDataBindingClassPatcher.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.processor
18 |
19 | import io.michaelrocks.grip.mirrors.Type
20 | import io.michaelrocks.grip.mirrors.toAsmType
21 | import org.objectweb.asm.ClassVisitor
22 | import org.objectweb.asm.MethodVisitor
23 | import org.objectweb.asm.Opcodes
24 | import org.objectweb.asm.commons.GeneratorAdapter
25 | import org.objectweb.asm.commons.Method
26 |
27 | class ViewDataBindingClassPatcher(
28 | visitor: ClassVisitor?,
29 | private val appCompatResourcesType: Type.Object
30 | ) : ClassVisitor(Opcodes.ASM5, visitor) {
31 |
32 | override fun visitMethod(
33 | access: Int,
34 | name: String,
35 | desc: String,
36 | signature: String?,
37 | exceptions: Array?
38 | ): MethodVisitor? {
39 | val visitor = super.visitMethod(access, name, desc, signature, exceptions)
40 | if (name == "getDrawableFromResource" && desc == "(Landroid/view/View;I)Landroid/graphics/drawable/Drawable;") {
41 | replaceImplementation(visitor, access, name, desc, APP_COMPAT_RESOURCES_GET_DRAWABLE_METHOD)
42 | return null
43 | }
44 |
45 | if (name == "getColorStateListFromResource" && desc == "(Landroid/view/View;I)Landroid/content/res/ColorStateList;") {
46 | replaceImplementation(visitor, access, name, desc, APP_COMPAT_RESOURCES_GET_COLOR_STATE_LIST_METHOD)
47 | return null
48 | }
49 |
50 | return visitor
51 | }
52 |
53 | private fun replaceImplementation(visitor: MethodVisitor?, access: Int, name: String, desc: String, method: Method) {
54 | GeneratorAdapter(visitor, access, name, desc).apply {
55 | visitCode()
56 | loadArg(0)
57 | invokeVirtual(Types.VIEW.toAsmType(), VIEW_GET_CONTEXT_METHOD)
58 | loadArg(1)
59 | invokeStatic(appCompatResourcesType.toAsmType(), method)
60 | returnValue()
61 | endMethod()
62 | }
63 | }
64 |
65 | companion object {
66 | val APP_COMPAT_RESOURCES_GET_DRAWABLE_METHOD =
67 | Method("getDrawable", "(Landroid/content/Context;I)Landroid/graphics/drawable/Drawable;")
68 | val APP_COMPAT_RESOURCES_GET_COLOR_STATE_LIST_METHOD =
69 | Method("getColorStateList", "(Landroid/content/Context;I)Landroid/content/res/ColorStateList;")
70 | val VIEW_GET_CONTEXT_METHOD =
71 | Method("getContext", "()Landroid/content/Context;")
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem http://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/transform/TransformSet.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.transform
18 |
19 | import com.android.build.api.transform.DirectoryInput
20 | import com.android.build.api.transform.Format
21 | import com.android.build.api.transform.JarInput
22 | import com.android.build.api.transform.QualifiedContent
23 | import com.android.build.api.transform.TransformInput
24 | import com.android.build.api.transform.TransformInvocation
25 | import java.io.File
26 |
27 | class TransformSet private constructor(
28 | val units: List,
29 | val referencedUnits: List,
30 | val bootClasspath: List
31 | ) {
32 |
33 | companion object {
34 | fun create(invocation: TransformInvocation, bootClasspath: List): TransformSet {
35 | val units = createTransformUnits(invocation, invocation.inputs)
36 | val referencedUnits = createTransformUnits(invocation, invocation.referencedInputs)
37 | return TransformSet(units, referencedUnits, bootClasspath)
38 | }
39 |
40 | private fun createTransformUnits(
41 | invocation: TransformInvocation,
42 | inputs: Collection
43 | ): List {
44 | return inputs.flatMap { input ->
45 | val units = ArrayList(input.directoryInputs.size + input.jarInputs.size)
46 | input.directoryInputs.mapTo(units) { directory ->
47 | createTransformUnit(invocation, directory, Format.DIRECTORY)
48 | }
49 | input.jarInputs.mapTo(units) { jar ->
50 | createTransformUnit(invocation, jar, Format.JAR)
51 | }
52 | }
53 | }
54 |
55 | private fun createTransformUnit(
56 | invocation: TransformInvocation,
57 | input: QualifiedContent,
58 | format: Format
59 | ): TransformUnit {
60 | val output = invocation.outputProvider.getContentLocation(input.name, input.contentTypes, input.scopes, format)
61 | val statusProvider = input.createStatusProvider(invocation.isIncremental)
62 | return TransformUnit(input.file, output, format.toTransformUnitFormat(), statusProvider)
63 | }
64 |
65 | private fun Format.toTransformUnitFormat(): TransformUnit.Format {
66 | return when (this) {
67 | Format.JAR -> TransformUnit.Format.JAR
68 | Format.DIRECTORY -> TransformUnit.Format.DIRECTORY
69 | }
70 | }
71 |
72 | private fun QualifiedContent.createStatusProvider(incremental: Boolean): Changes {
73 | return when (this) {
74 | is DirectoryInput -> Changes.ForDirectory(changedFiles, incremental)
75 | is JarInput -> Changes.ForJar(status, incremental)
76 | else -> error("Unknown content $this")
77 | }
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/MichaelRocks/DataBindingCompat)
2 |
3 | Deprecated
4 | ==========
5 |
6 | `VectorDrawable`s are supported in DataBinding natively since [AGP 4.0.0](https://issuetracker.google.com/issues/123427765).
7 |
8 | DataBindingCompat
9 | =================
10 |
11 | A Gradle plugin that adds support for
12 | [`VectorDrawableCompat`](https://developer.android.com/reference/android/support/graphics/drawable/VectorDrawableCompat.html)
13 | to the [Data Binding Library](https://developer.android.com/topic/libraries/data-binding/index.html).
14 |
15 | Why?
16 | ----
17 |
18 | The Data Binding Library supports
19 | [resources in binding expressions](https://developer.android.com/topic/libraries/data-binding/index.html#resources),
20 | and drawable resources in particular.
21 |
22 | ```xml
23 |
27 | ```
28 |
29 | But if your project uses support vector drawables you're in a big trouble.
30 |
31 | ```groovy
32 | android {
33 | defaultConfig {
34 | vectorDrawables.useSupportLibrary = true
35 | }
36 | }
37 | ```
38 |
39 | Unfortunately, the Data Binding Library doesn't call `AppCompatResources.getDrawable()` when loading drawables, so the
40 | binding above will throw an exception at runtime on pre-Lollipop devices. DataBindingCompat solves this issue and all
41 | you need to do is just to apply the Gradle plugin.
42 |
43 | Usage
44 | -----
45 |
46 | ```groovy
47 | buildscript {
48 | repositories {
49 | jcenter()
50 | }
51 |
52 | dependencies {
53 | classpath 'io.michaelrocks:databindingcompat:1.1.7'
54 | }
55 | }
56 |
57 | apply plugin: 'com.android.application'
58 | apply plugin: 'io.michaelrocks.databindingcompat'
59 | ```
60 |
61 | How it works
62 | ------------
63 |
64 | When you use a drawable resource in a binding expression the Data Binding Library inflates this drawable by calling
65 | the `ViewDataBinding.getDrawableFromResource()` method. The DataBindingCompat plugin patches `ViewDataBinding` class at
66 | compile time and replaces the implementation of `getDrawableFromResource()` with an invocation of
67 | `AppCompatResources.getDrawable()`. The same transformation the plugin does with the
68 | `ViewDataBinding.getColorStateListFromResource()` method. And that's it.
69 |
70 | `ViewDataBinding` *before* patching:
71 | ```java
72 | protected static Drawable getDrawableFromResource(View view, int resourceId) {
73 | if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
74 | return view.getContext().getDrawable(resourceId);
75 | } else {
76 | return view.getResources().getDrawable(resourceId);
77 | }
78 | }
79 |
80 | protected static ColorStateList getColorStateListFromResource(View view, int resourceId) {
81 | if (VERSION.SDK_INT >= VERSION_CODES.M) {
82 | return view.getContext().getColorStateList(resourceId);
83 | } else {
84 | return view.getResources().getColorStateList(resourceId);
85 | }
86 | }
87 | ```
88 |
89 | `ViewDataBinding` *after* patching:
90 | ```java
91 | protected static Drawable getDrawableFromResource(View view, int resourceId) {
92 | return AppCompatResources.getDrawable(view.getContext(), resourceId));
93 | }
94 |
95 | protected static ColorStateList getColorStateListFromResource(View view, int resourceId) {
96 | return AppCompatResources.getColorStateList(view.getContext(), resourceId));
97 | }
98 | ```
99 |
100 | License
101 | -------
102 |
103 | Copyright 2017 Michael Rozumyanskiy
104 |
105 | Licensed under the Apache License, Version 2.0 (the "License");
106 | you may not use this file except in compliance with the License.
107 | You may obtain a copy of the License at
108 |
109 | http://www.apache.org/licenses/LICENSE-2.0
110 |
111 | Unless required by applicable law or agreed to in writing, software
112 | distributed under the License is distributed on an "AS IS" BASIS,
113 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
114 | See the License for the specific language governing permissions and
115 | limitations under the License.
116 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/transform/DataBindingCompatTransform.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.transform
18 |
19 | import com.android.build.api.transform.QualifiedContent
20 | import com.android.build.api.transform.Transform
21 | import com.android.build.api.transform.TransformException
22 | import com.android.build.api.transform.TransformInvocation
23 | import com.android.build.gradle.BaseExtension
24 | import io.michaelrocks.databindingcompat.PluginVersion
25 | import io.michaelrocks.databindingcompat.logging.getLogger
26 | import io.michaelrocks.databindingcompat.processor.DataBindingCompatProcessor
27 | import io.michaelrocks.databindingcompat.transform.TransformUnit.Format
28 | import io.michaelrocks.databindingcompat.transform.TransformUnit.Status
29 | import java.io.File
30 | import java.util.EnumSet
31 |
32 | class DataBindingCompatTransform(private val android: BaseExtension) : Transform() {
33 | private val logger = getLogger()
34 |
35 | override fun transform(invocation: TransformInvocation) {
36 | if (!invocation.isIncremental) {
37 | invocation.outputProvider.deleteAll()
38 | }
39 |
40 | val transformationSet = TransformSet.create(invocation, android.bootClasspath)
41 | transformationSet.copyInputsToOutputs()
42 |
43 | DataBindingCompatProcessor(transformationSet).use { processor ->
44 | try {
45 | processor.process()
46 | } catch (exception: Exception) {
47 | throw TransformException(exception)
48 | }
49 | }
50 | }
51 |
52 | override fun getName(): String {
53 | return "dataBindingCompat"
54 | }
55 |
56 | override fun getInputTypes(): Set {
57 | return EnumSet.of(QualifiedContent.DefaultContentType.CLASSES)
58 | }
59 |
60 | override fun getScopes(): MutableSet {
61 | return EnumSet.of(QualifiedContent.Scope.EXTERNAL_LIBRARIES)
62 | }
63 |
64 | override fun getReferencedScopes(): MutableSet {
65 | if (PluginVersion.major >= 3) {
66 | return EnumSet.of(
67 | QualifiedContent.Scope.PROJECT,
68 | QualifiedContent.Scope.SUB_PROJECTS,
69 | QualifiedContent.Scope.PROVIDED_ONLY
70 | )
71 | } else {
72 | @Suppress("DEPRECATION")
73 | return EnumSet.of(
74 | QualifiedContent.Scope.PROJECT,
75 | QualifiedContent.Scope.PROJECT_LOCAL_DEPS,
76 | QualifiedContent.Scope.SUB_PROJECTS,
77 | QualifiedContent.Scope.SUB_PROJECTS_LOCAL_DEPS,
78 | QualifiedContent.Scope.PROVIDED_ONLY
79 | )
80 | }
81 | }
82 |
83 | override fun isIncremental(): Boolean {
84 | return true
85 | }
86 |
87 | private fun TransformSet.copyInputsToOutputs() {
88 | units.forEach { unit ->
89 | when (unit.format) {
90 | Format.DIRECTORY -> unit.input.copyDirectoryTo(unit.output, unit.changes)
91 | Format.JAR -> unit.input.copyJarTo(unit.output, unit.changes)
92 | }
93 | }
94 | }
95 |
96 | private fun File.copyDirectoryTo(target: File, changes: Changes) {
97 | if (!changes.hasFileStatuses) {
98 | logger.info("Non-incremental directory change: {} -> {}", this, target)
99 | target.deleteRecursively()
100 | if (exists()) {
101 | copyRecursively(target)
102 | }
103 | return
104 | }
105 |
106 | logger.info("Incremental directory change: {} -> {}", this, target)
107 | target.mkdirs()
108 | changes.files.forEach { file ->
109 | val status = changes.getFileStatus(file)
110 | val relativePath = file.toRelativeString(this)
111 | val targetFile = File(target, relativePath)
112 | file.applyChangesTo(targetFile, status)
113 | }
114 | }
115 |
116 | private fun File.copyJarTo(target: File, changes: Changes) {
117 | logger.info("Jar change: {} -> {}", this, target)
118 | applyChangesTo(target, changes.status)
119 | }
120 |
121 | private fun File.applyChangesTo(target: File, status: Status) {
122 | logger.debug("Incremental file change ({}): {} -> {}", status, this, target)
123 | when (status) {
124 | Status.UNCHANGED -> return
125 | Status.REMOVED -> target.deleteRecursively()
126 | Status.ADDED -> replaceRecursively(target)
127 | Status.CHANGED -> replaceRecursively(target)
128 | Status.UNKNOWN -> applyChangesTo(target, if (exists()) Status.CHANGED else Status.REMOVED)
129 | }
130 | }
131 |
132 | private fun File.replaceRecursively(target: File) {
133 | target.deleteRecursively()
134 | copyRecursively(target, false)
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin, switch paths to Windows format before running java
129 | if $cygwin ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=$((i+1))
158 | done
159 | case $i in
160 | (0) set -- ;;
161 | (1) set -- "$args0" ;;
162 | (2) set -- "$args0" "$args1" ;;
163 | (3) set -- "$args0" "$args1" "$args2" ;;
164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=$(save "$@")
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/plugin/src/main/java/io/michaelrocks/databindingcompat/processor/DataBindingCompatProcessor.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 Michael Rozumyanskiy
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package io.michaelrocks.databindingcompat.processor
18 |
19 | import io.michaelrocks.databindingcompat.logging.getLogger
20 | import io.michaelrocks.databindingcompat.transform.TransformSet
21 | import io.michaelrocks.databindingcompat.transform.TransformUnit
22 | import io.michaelrocks.grip.GripFactory
23 | import io.michaelrocks.grip.mirrors.Type
24 | import org.objectweb.asm.ClassReader
25 | import org.objectweb.asm.ClassWriter
26 | import java.io.Closeable
27 | import java.io.File
28 | import java.io.InputStream
29 | import java.io.OutputStream
30 | import java.util.jar.JarEntry
31 | import java.util.jar.JarInputStream
32 | import java.util.jar.JarOutputStream
33 | import java.util.jar.Manifest
34 |
35 | class DataBindingCompatProcessor(private val transformSet: TransformSet) : Closeable {
36 | private val logger = getLogger()
37 | private val grip = GripFactory.create(transformSet.getClasspath())
38 |
39 | fun process() {
40 | logger.info("Starting DataBindingCompat")
41 |
42 | if (logger.isDebugEnabled) {
43 | transformSet.dump()
44 | logger.debug("Classpath:\n {}", grip.fileRegistry.classpath().joinToString(separator = "\n "))
45 | }
46 |
47 | if (Types.ANDROIDX_APP_COMPAT_RESOURCES in grip.fileRegistry) {
48 | if (Patch(Types.ANDROIDX_VIEW_DATA_BINDING, Types.ANDROIDX_APP_COMPAT_RESOURCES).maybeApply()) {
49 | logger.info("Patched {} successfully", Types.ANDROIDX_VIEW_DATA_BINDING.className)
50 | return
51 | }
52 | }
53 |
54 | if (Types.SUPPORT_APP_COMPAT_RESOURCES in grip.fileRegistry) {
55 | if (Patch(Types.SUPPORT_VIEW_DATA_BINDING, Types.SUPPORT_APP_COMPAT_RESOURCES).maybeApply()) {
56 | logger.info("Patched {} successfully", Types.SUPPORT_VIEW_DATA_BINDING.className)
57 | return
58 | }
59 | }
60 |
61 | logger.info("AppCompatResources class not found. Aborting...")
62 | }
63 |
64 | private fun TransformSet.dump() {
65 | logger.debug("Transform set:")
66 | logger.debug(" Units:\n {}", units.joinToString(separator = "\n "))
67 | logger.debug(" Referenced units:\n {}", referencedUnits.joinToString(separator = "\n "))
68 | logger.debug(" Boot classpath:\n {}", bootClasspath.joinToString(separator = "\n "))
69 | }
70 |
71 | override fun close() {
72 | grip.close()
73 | }
74 |
75 | private inner class Patch(
76 | private val viewDataBindingType: Type.Object,
77 | private val appCompatResourcesType: Type.Object
78 | ) {
79 |
80 | fun maybeApply(): Boolean {
81 | val input = findViewDataBindingClassFile()
82 | if (input == null) {
83 | logger.info("ViewDataBinding class not found. Aborting...")
84 | return false
85 | }
86 |
87 | val unit = findTransformUnitForInputFile(input)
88 | if (unit == null) {
89 | logger.info("ViewDataBinding class cannot be transformed. Aborting...")
90 | return false
91 | }
92 |
93 | logger.info("Patching ViewDataBinding.class: {}", unit)
94 | val data = createPatchedViewDataBindingClass()
95 | savePatchedViewDataBindingClass(unit, data)
96 | return true
97 | }
98 |
99 | private fun createPatchedViewDataBindingClass(): ByteArray {
100 | val data = grip.fileRegistry.readClass(viewDataBindingType)
101 | val reader = ClassReader(data)
102 | val writer = StandaloneClassWriter(reader, ClassWriter.COMPUTE_MAXS or ClassWriter.COMPUTE_FRAMES, grip.classRegistry)
103 | val patcher = ViewDataBindingClassPatcher(writer, appCompatResourcesType)
104 | reader.accept(patcher, ClassReader.SKIP_FRAMES)
105 | return writer.toByteArray()
106 | }
107 |
108 | private fun findViewDataBindingClassFile(): File? {
109 | return grip.fileRegistry.findFileForType(viewDataBindingType)
110 | }
111 |
112 | private fun findTransformUnitForInputFile(input: File): TransformUnit? {
113 | val canonicalInput = input.canonicalFile
114 | val units = transformSet.units.filter { it.changes.status != TransformUnit.Status.REMOVED }
115 | return units.firstOrNull { it.input.canonicalFile == canonicalInput }
116 | }
117 |
118 | private fun savePatchedViewDataBindingClass(unit: TransformUnit, data: ByteArray) {
119 | when (unit.format) {
120 | TransformUnit.Format.DIRECTORY -> savePatchedViewDataBindingClassToDirectory(unit.output, data)
121 | TransformUnit.Format.JAR -> savePatchedViewDataBindingClassToJar(unit.output, data)
122 | }
123 | }
124 |
125 | private fun savePatchedViewDataBindingClassToDirectory(directory: File, data: ByteArray) {
126 | logger.info("Save patched ViewDataBinding to directory {}", directory)
127 | val file = File(directory, viewDataBindingType.toFilePath())
128 | file.mkdirs()
129 | file.writeBytes(data)
130 | }
131 |
132 | private fun savePatchedViewDataBindingClassToJar(jar: File, data: ByteArray) {
133 | logger.info("Save patched ViewDataBinding to jar {}", jar)
134 | val temporary = createTempFile(jar.name, "tmp")
135 | try {
136 | savePatchedViewDataBindingClassToJar(jar, temporary, data)
137 | temporary.inputStream().buffered().use { jarInputStream ->
138 | jar.outputStream().buffered().use { jarOutputStream ->
139 | jarInputStream.copyTo(jarOutputStream)
140 | }
141 | }
142 | } finally {
143 | if (!temporary.delete()) {
144 | logger.warn("Cannot delete a temporary file {}", temporary)
145 | }
146 | }
147 | }
148 |
149 | private fun savePatchedViewDataBindingClassToJar(source: File, target: File, data: ByteArray) {
150 | source.inputStream().buffered().jar().use { jarInputStream ->
151 | target.outputStream().buffered().jar(jarInputStream.manifest).use { jarOutputStream ->
152 | val path = viewDataBindingType.toFilePath()
153 | jarInputStream.entries().filterNot { it.name == path }.forEach { jarEntry ->
154 | jarOutputStream.putNextEntry(jarEntry)
155 | jarInputStream.copyTo(jarOutputStream)
156 | jarInputStream.closeEntry()
157 | jarOutputStream.closeEntry()
158 | }
159 |
160 | jarOutputStream.putNextEntry(JarEntry(path))
161 | jarOutputStream.write(data)
162 | jarOutputStream.closeEntry()
163 | }
164 | }
165 | }
166 |
167 | private fun Type.Object.toFilePath(): String {
168 | return "$internalName.class"
169 | }
170 |
171 | private fun InputStream.jar(verify: Boolean = true): JarInputStream {
172 | return JarInputStream(this, verify)
173 | }
174 |
175 | private fun OutputStream.jar(manifest: Manifest? = null): JarOutputStream {
176 | return if (manifest != null) JarOutputStream(this, manifest) else JarOutputStream(this)
177 | }
178 |
179 | private fun JarInputStream.entries(): Sequence {
180 | return generateSequence { nextJarEntry }
181 | }
182 | }
183 |
184 | companion object {
185 | private fun TransformSet.getClasspath(): List {
186 | val classpath = ArrayList(units.size + referencedUnits.size + bootClasspath.size)
187 | units.mapTo(classpath) { it.input }
188 | referencedUnits.mapTo(classpath) { it.input }
189 | classpath += bootClasspath
190 | return classpath
191 | }
192 | }
193 | }
194 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------