-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Supports OkBuck build #4133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zaki50
wants to merge
1
commit into
main
Choose a base branch
from
my/support_okbuck
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Supports OkBuck build #4133
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,6 @@ import io.realm.annotations.Ignore | |
| import io.realm.annotations.RealmClass | ||
| import javassist.ClassPool | ||
| import javassist.CtClass | ||
| import javassist.LoaderClassPath | ||
| import org.gradle.api.Project | ||
| import org.slf4j.Logger | ||
| import org.slf4j.LoggerFactory | ||
|
|
||
|
|
@@ -44,10 +42,54 @@ import static com.android.build.api.transform.QualifiedContent.* | |
| class RealmTransformer extends Transform { | ||
|
|
||
| private Logger logger = LoggerFactory.getLogger('realm-logger') | ||
| private Project project | ||
| TransformerConfigProvider provider | ||
|
|
||
| public RealmTransformer(Project project) { | ||
| this.project = project | ||
| public RealmTransformer(TransformerConfigProvider provider) { | ||
| this.provider = provider | ||
| } | ||
|
|
||
| // constructor for OkBuck | ||
| public RealmTransformer(File configFile) { | ||
| if (!configFile.exists()) { | ||
| throw new FileNotFoundException(configFile.absolutePath) | ||
| } | ||
|
|
||
| Properties properties = new Properties() | ||
| configFile.withInputStream { | ||
| properties.load(it) | ||
| } | ||
| boolean syncEnabled = Boolean.valueOf(properties.getProperty("realm.syncEnabled", "false")) | ||
| boolean targetSdkVersion = properties.getProperty('android.targetSdkVersion', '25') | ||
| boolean minSdkVersion = properties.getProperty('android.minSdkVersion', '19') | ||
|
|
||
| def bootClassPath = properties.getProperty("realm.bootClassPath") | ||
| List<String> bootClassPathList = [] | ||
| if (!(bootClassPath == null || bootClassPath.empty)) { | ||
| bootClassPath.split(',').each { | ||
| bootClassPathList.add(it.trim()) | ||
| } | ||
| } | ||
| provider = new TransformerConfigProvider() { | ||
| @Override | ||
| boolean getSyncEnabled() { | ||
| return syncEnabled | ||
| } | ||
|
|
||
| @Override | ||
| List<String> getBootClassPathList() { | ||
| return bootClassPathList | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The boot classpaths are already passed in the transform invocation as referenced input jar, so you just need to add those to your class loader. |
||
| } | ||
|
|
||
| @Override | ||
| String getTargetSdkVersion() { | ||
| return targetSdkVersion | ||
| } | ||
|
|
||
| @Override | ||
| String getMinSdkVersion() { | ||
| return minSdkVersion | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -174,14 +216,13 @@ class RealmTransformer extends Transform { | |
| it.getPackageName() | ||
| } | ||
|
|
||
| def targetSdk = project?.android?.defaultConfig?.targetSdkVersion?.mApiLevel as String; | ||
| def minSdk = project?.android?.defaultConfig?.minSdkVersion?.mApiLevel as String; | ||
|
|
||
| def env = System.getenv() | ||
| def disableAnalytics = env["REALM_DISABLE_ANALYTICS"] | ||
| if (disableAnalytics == null || disableAnalytics != "true") { | ||
| boolean sync = project?.realm?.syncEnabled != null && project.realm.syncEnabled | ||
| def analytics = new RealmAnalytics(packages as Set, containsKotlin, sync, targetSdk, minSdk) | ||
| def analytics = new RealmAnalytics(packages as Set, containsKotlin, | ||
| provider.syncEnabled, | ||
| provider.targetSdkVersion, | ||
| provider.minSdkVersion) | ||
| analytics.execute() | ||
| } | ||
| } | ||
|
|
@@ -225,10 +266,10 @@ class RealmTransformer extends Transform { | |
| private static Set<String> getClassNames(Collection<TransformInput> inputs) { | ||
| Set<String> classNames = new HashSet<String>() | ||
|
|
||
| inputs.each { | ||
| it.directoryInputs.each { | ||
| def dirPath = it.file.absolutePath | ||
| it.file.eachFileRecurse(FileType.FILES) { | ||
| for (TransformInput input : inputs) { | ||
| for (DirectoryInput directoryInput : input.directoryInputs) { | ||
| def dirPath = directoryInput.file.absolutePath | ||
| directoryInput.file.eachFileRecurse(FileType.FILES) { | ||
| if (it.absolutePath.endsWith(SdkConstants.DOT_CLASS)) { | ||
| def className = | ||
| it.absolutePath.substring( | ||
|
|
@@ -240,8 +281,8 @@ class RealmTransformer extends Transform { | |
| } | ||
| } | ||
|
|
||
| it.jarInputs.each { | ||
| def jarFile = new JarFile(it.file) | ||
| for (JarInput jarInput : input.jarInputs) { | ||
| def jarFile = new JarFile(jarInput.file) | ||
| jarFile.entries().findAll { | ||
| !it.directory && it.name.endsWith(SdkConstants.DOT_CLASS) | ||
| }.each { | ||
|
|
@@ -294,8 +335,8 @@ class RealmTransformer extends Transform { | |
| // See https://code.google.com/p/android/issues/detail?id=209426 | ||
| private void addBootClassesToClassPool(ClassPool classPool) { | ||
| try { | ||
| project.android.bootClasspath.each { | ||
| String path = it.absolutePath | ||
| provider.bootClassPathList.each { | ||
| String path = it | ||
| logger.debug "Add boot class " + path + " to class pool." | ||
| classPool.appendClassPath(path) | ||
| } | ||
|
|
||
26 changes: 26 additions & 0 deletions
26
realm-transformer/src/main/groovy/io/realm/transformer/TransformerConfigProvider.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright 2017 Realm Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package io.realm.transformer | ||
|
|
||
| interface TransformerConfigProvider { | ||
| boolean getSyncEnabled() | ||
| List<String> getBootClassPathList() | ||
|
|
||
| String getTargetSdkVersion() | ||
| String getMinSdkVersion() | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can expect this to always exist. Transform-cli does that check if a config file is specified: uber/okbuck@ebcea6f#diff-10fc19e7dd1e6127839942575e0a0ba1R59