From 308e826f135fc52416371905c500fac2de701a5a Mon Sep 17 00:00:00 2001 From: Advay Mengle Date: Wed, 26 Aug 2015 23:35:46 -0700 Subject: [PATCH] Build external Java libs into standalone native libs. Rename the old `j2objcTranslation` to `j2objcTranslationClosure` Add a new dependency type `j2objcTranslation` that allows you to convert an entire source jar into a standalone library as a separate Gradle project. You then depend on that project instead of the external library when you want to use the functionality elsewhere. This causes the external library to be translated and compiled only once, and not partially and duplicatively as with --build-closure. Fixes #429; fixes #419 TESTED=yes --- CHANGELOG.md | 1 + .../j2objcgradle/DependencyConverter.groovy | 17 +++-- .../j2objcgradle/DependencyResolver.groovy | 74 +++++++++++++++++-- .../j2objcgradle/J2objcConfig.groovy | 8 +- .../j2objcgradle/J2objcPlugin.groovy | 20 ++++- .../externalLibrary1/base/build.gradle | 36 +++++++++ .../base/src/main/java/com/example/Cube.java | 44 +++++++++++ .../src/test/java/com/example/CubeTest.java | 38 ++++++++++ systemTests/externalLibrary1/build.gradle | 36 +++++++++ .../externalLibrary1/extended/build.gradle | 37 ++++++++++ .../main/java/com/example/ExtendedCube.java | 42 +++++++++++ .../java/com/example/ExtendedCubeTest.java | 33 +++++++++ systemTests/externalLibrary1/gradlew | 1 + systemTests/externalLibrary1/local.properties | 1 + systemTests/externalLibrary1/settings.gradle | 16 ++++ .../third_party_gson/build.gradle | 37 ++++++++++ systemTests/run-all.sh | 8 +- 17 files changed, 433 insertions(+), 16 deletions(-) create mode 100644 systemTests/externalLibrary1/base/build.gradle create mode 100644 systemTests/externalLibrary1/base/src/main/java/com/example/Cube.java create mode 100644 systemTests/externalLibrary1/base/src/test/java/com/example/CubeTest.java create mode 100644 systemTests/externalLibrary1/build.gradle create mode 100644 systemTests/externalLibrary1/extended/build.gradle create mode 100644 systemTests/externalLibrary1/extended/src/main/java/com/example/ExtendedCube.java create mode 100644 systemTests/externalLibrary1/extended/src/test/java/com/example/ExtendedCubeTest.java create mode 120000 systemTests/externalLibrary1/gradlew create mode 120000 systemTests/externalLibrary1/local.properties create mode 100644 systemTests/externalLibrary1/settings.gradle create mode 100644 systemTests/externalLibrary1/third_party_gson/build.gradle diff --git a/CHANGELOG.md b/CHANGELOG.md index ece279d4..1ff6cd99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ https://github.com/j2objc-contrib/j2objc-gradle/compare/vA.B.C...vX.Y.Z ## vNext (HEAD) Functionality: * Automatic dependency resolution for Maven jars and Gradle projects #420 +* Build external Java libraries (with source) into standalone native libraries #431 * Proper limitation of functionality on non-Mac platforms #396 * Embedded docs and versioning info for easier debugging #395 diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyConverter.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyConverter.groovy index 0ba1b747..4c6e1015 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyConverter.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyConverter.groovy @@ -26,8 +26,15 @@ import org.gradle.api.artifacts.SelfResolvingDependency /** * Converts `[test]compile` dependencies to their - * `j2objcTranslation` and/or `j2objcLinkage` equivalents, depending on the type - * of dependency and whether or not they are already provided in native code. + * `j2objcTranslationClosure` and/or `j2objcLinkage` equivalents, depending on the type + * of dependency and whether or not they are already provided in native code: + *

+ * External classfile .jar libraries you depend on via `compile` or `testCompile` will be + * converted to `j2objcTranslationClosure` dependencies of the corresponding source .jar libraries. + * Gradle projects you depend on via `compile` or `testCompile` will be converted to + * `j2objcLinkage` dependencies of the corresponding generated Objective C include headers + * and static library. See {@link DependencyResolver} for details on the differences + * between these configurations. *

* They will be resolved to appropriate `j2objc` constructs using DependencyResolver. */ @@ -79,7 +86,7 @@ class DependencyConverter { protected void visitSelfResolvingDependency( SelfResolvingDependency dep) { project.logger.debug("j2objc dependency converter: Translating file dep: $dep") - project.configurations.getByName('j2objcTranslation').dependencies.add( + project.configurations.getByName('j2objcTranslationClosure').dependencies.add( dep.copy()) } @@ -103,12 +110,12 @@ class DependencyConverter { String group = dep.group == null ? '' : dep.group String version = dep.version == null ? '' : dep.version // TODO: Make this less fragile. What if sources don't exist for this artifact? - project.dependencies.add('j2objcTranslation', "${group}:${dep.name}:${version}:sources") + project.dependencies.add('j2objcTranslationClosure', "${group}:${dep.name}:${version}:sources") } protected void visitGenericDependency(Dependency dep) { project.logger.warn("j2objc dependency converter: Unknown dependency type: $dep; copying naively") - project.configurations.getByName('j2objcTranslation').dependencies.add( + project.configurations.getByName('j2objcTranslationClosure').dependencies.add( dep.copy()) } } diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyResolver.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyResolver.groovy index 9a5823e8..aa80c245 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyResolver.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/DependencyResolver.groovy @@ -15,7 +15,6 @@ */ package com.github.j2objccontrib.j2objcgradle - import groovy.transform.CompileStatic import groovy.transform.PackageScope import org.gradle.api.InvalidUserDataException @@ -23,11 +22,37 @@ import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ProjectDependency import org.gradle.api.artifacts.SelfResolvingDependency +import org.gradle.api.file.DuplicatesStrategy import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginConvention +import org.gradle.api.tasks.Copy +import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.bundling.AbstractArchiveTask - +import org.gradle.api.tasks.util.PatternSet /** - * Resolves `j2objcTranslation` and 'j2objcLinkage' dependencies into their `j2objc` constructs. + * Resolves `j2objc*` dependencies into their `j2objc` constructs: + *

+ *

*/ @PackageScope @CompileStatic @@ -42,20 +67,59 @@ class DependencyResolver { } void configureAll() { + project.configurations.getByName('j2objcTranslationClosure').each { File it -> + // These are the resolved files, NOT the dependencies themselves. + // Usually source jars. + visitTranslationClosureFile(it) + } project.configurations.getByName('j2objcTranslation').each { File it -> // These are the resolved files, NOT the dependencies themselves. - visitTranslateFile(it) + // Usually source jars. + visitTranslationSourceJar(it) } project.configurations.getByName('j2objcLinkage').dependencies.each { visitLink(it) } } - protected void visitTranslateFile(File depFile) { + protected void visitTranslationClosureFile(File depFile) { j2objcConfig.translateSourcepaths(depFile.absolutePath) j2objcConfig.enableBuildClosure() } + private static final String EXTRACTION_TASK_NAME = 'j2objcTranslatedLibraryExtraction' + + /** + * Adds to the main java sourceSet a to-be-generated directory that contains the contents + * of `j2objcTranslation` dependency libraries (if any). + */ + static void configureSourceSets(Project project) { + JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention) + SourceSet sourceSet = javaConvention.sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME) + String dir = "${project.buildDir}/translationExtraction" + sourceSet.java.srcDirs(project.file(dir)) + Copy copy = project.tasks.create(EXTRACTION_TASK_NAME, Copy, + {Copy task -> + task.into(project.file(dir)) + // If two libraries define the same file, fail early. + task.duplicatesStrategy = DuplicatesStrategy.FAIL + }) + project.tasks.getByName(sourceSet.compileJavaTaskName).dependsOn(copy) + } + + // Copy contents of sourceJarFile to build/translationExtraction + protected void visitTranslationSourceJar(File sourceJarFile) { + if (!sourceJarFile.absolutePath.endsWith('.jar')) { + String msg = "`j2objcTranslation` dependencies can only handle " + + "source jar files, not ${sourceJarFile.absolutePath}" + throw new InvalidUserDataException(msg) + } + PatternSet pattern = new PatternSet() + pattern.include('**/*.java') + Copy copy = project.tasks.getByName(EXTRACTION_TASK_NAME) as Copy + copy.from(project.zipTree(sourceJarFile).matching(pattern)) + } + protected void visitLink(Dependency dep) { if (dep instanceof ProjectDependency) { visitLinkProjectDependency((ProjectDependency) dep) diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy index a526321c..e4dea9a1 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcConfig.groovy @@ -323,11 +323,12 @@ class J2objcConfig { /** * @see #dependsOnJ2objcLib(org.gradle.api.Project) * @deprecated Use `dependencies { j2objcLinkage project(':beforeProjectName') }` or - * `autoConfigDeps = true` instead. + * `autoConfigureDeps = true` instead. */ // TODO: Do this automatically based on project dependencies. @Deprecated void dependsOnJ2objcLib(String beforeProjectName) { + //noinspection GrDeprecatedAPIUsage dependsOnJ2objcLib(project.project(beforeProjectName)) } @@ -346,10 +347,10 @@ class J2objcConfig { * is preferable and sufficient. * * @deprecated Use `dependencies { j2objcLinkage project(':beforeProjectName') }` or - * `autoConfigDeps=true` instead. + * `autoConfigureDeps=true` instead. */ // TODO: Phase this API out, and have J2ObjC-applied project dependencies controlled - // solely via `j2objcLink` configuration. + // solely via `j2objcLinkage` configuration. @CompileStatic(TypeCheckingMode.SKIP) @Deprecated void dependsOnJ2objcLib(Project beforeProject) { @@ -671,6 +672,7 @@ class J2objcConfig { void testingOnlyPrepConfigurations() { // When testing we don't always want to apply the entire plugin // before calling finalConfigure. + project.configurations.create('j2objcTranslationClosure') project.configurations.create('j2objcTranslation') project.configurations.create('j2objcLinkage') } diff --git a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy index daf83412..874db7f2 100644 --- a/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy +++ b/src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy @@ -91,10 +91,24 @@ class J2objcPlugin implements Plugin { // When j2objcConfig.autoConfigureDeps is true, this configuration // will have source paths automatically added to it. You can add // *source* JARs/directories yourself as well. - j2objcTranslation { + j2objcTranslationClosure { description = 'J2ObjC Java source dependencies that need to be ' + - 'transitively translated via --build-closure' + 'partially translated via --build-closure' + } + + // If you want to translate an entire source library, regardless of which parts of the + // library code your own code depends on, use this configuration. This + // will also cause the library to be Java compiled, since you cannot translate + // a library with j2objc that does not successfully compile in Java. + // So for example: + // dependencies { j2objcTranslation 'com.google.code.gson:gson:2.3.1:sources' } + // will cause your project to produce a full gson Java classfile Jar AND a + // j2objc-translated static native library. + j2objcTranslation { + description = 'J2ObjC Java source libraries that should be fully translated ' + + 'and built as stand-alone native libraries' } + // Currently, we can only handle Project dependencies already translated to Objective-C. j2objcLinkage { description = 'J2ObjC native library dependencies that need to be ' + @@ -102,6 +116,8 @@ class J2objcPlugin implements Plugin { } } + DependencyResolver.configureSourceSets(project) + // Produces a modest amount of output logging.captureStandardOutput LogLevel.INFO diff --git a/systemTests/externalLibrary1/base/build.gradle b/systemTests/externalLibrary1/base/build.gradle new file mode 100644 index 00000000..4fc1f242 --- /dev/null +++ b/systemTests/externalLibrary1/base/build.gradle @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +apply plugin: 'java' +apply plugin: 'com.github.j2objccontrib.j2objcgradle' + +repositories { + jcenter() +} + +dependencies { + // Intentionally testing e2e use of a built-in j2objc library, Guava. + compile 'com.google.guava:guava:17.0' + // Normally we would reference this as compile "com.google.code.gson:gson:2.3.1" + compile project(':third_party_gson') + testCompile 'junit:junit:4.12' +} + +j2objcConfig { + autoConfigureDeps true + + finalConfigure() +} diff --git a/systemTests/externalLibrary1/base/src/main/java/com/example/Cube.java b/systemTests/externalLibrary1/base/src/main/java/com/example/Cube.java new file mode 100644 index 00000000..a8d4bb28 --- /dev/null +++ b/systemTests/externalLibrary1/base/src/main/java/com/example/Cube.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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 com.example; + +import com.google.common.base.Joiner; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +public class Cube { + + protected final int dimension; + + public Cube(int dimension) { + this.dimension = dimension; + } + + @Override + public String toString() { + return String.format("[Cube %d]", dimension); + } + + public String exerciseGuava() { + return Joiner.on(' ').join('a', 'b', 'c'); + } + + public String exerciseGson() { + Gson gson = new GsonBuilder().create(); + return gson.toJson(new String[]{"a", "b", "c"}); + } +} diff --git a/systemTests/externalLibrary1/base/src/test/java/com/example/CubeTest.java b/systemTests/externalLibrary1/base/src/test/java/com/example/CubeTest.java new file mode 100644 index 00000000..3ac07d35 --- /dev/null +++ b/systemTests/externalLibrary1/base/src/test/java/com/example/CubeTest.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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 com.example; + +import org.junit.Assert; +import org.junit.Test; + +public class CubeTest { + + @Test + public void testToString() { + Assert.assertEquals("[Cube 7]", new Cube(7).toString()); + } + + @Test + public void testExerciseGuava() { + Assert.assertEquals("a b c", new Cube(7).exerciseGuava()); + } + + @Test + public void testExerciseGson() { + Assert.assertEquals("[\"a\",\"b\",\"c\"]", new Cube(7).exerciseGson()); + } +} diff --git a/systemTests/externalLibrary1/build.gradle b/systemTests/externalLibrary1/build.gradle new file mode 100644 index 00000000..0282b5b1 --- /dev/null +++ b/systemTests/externalLibrary1/build.gradle @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +buildscript { + repositories { + jcenter() + } + dependencies { + // This is the build output of the plugin itself. + classpath fileTree(dir: '../../build/libs', include: ['*.jar']) + } +} + +allprojects { + apply plugin: 'java' + test { + testLogging { + // Provide full exception info on failure, instead + // of just pointing to an HTML file. + exceptionFormat = 'full' + } + } +} diff --git a/systemTests/externalLibrary1/extended/build.gradle b/systemTests/externalLibrary1/extended/build.gradle new file mode 100644 index 00000000..f1865f78 --- /dev/null +++ b/systemTests/externalLibrary1/extended/build.gradle @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +apply plugin: 'java' +apply plugin: 'com.github.j2objccontrib.j2objcgradle' + +repositories { + jcenter() +} + +dependencies { + compile project(':base') + // Intentionally testing e2e use of a built-in j2objc library, Guava. + compile 'com.google.guava:guava:17.0' + // Normally we would reference this as compile "com.google.code.gson:gson:2.3.1" + compile project(':third_party_gson') + testCompile 'junit:junit:4.12' +} + +j2objcConfig { + autoConfigureDeps true + + finalConfigure() +} diff --git a/systemTests/externalLibrary1/extended/src/main/java/com/example/ExtendedCube.java b/systemTests/externalLibrary1/extended/src/main/java/com/example/ExtendedCube.java new file mode 100644 index 00000000..87a9b0e6 --- /dev/null +++ b/systemTests/externalLibrary1/extended/src/main/java/com/example/ExtendedCube.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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 com.example; + +import java.lang.Override; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + +import com.google.common.base.Joiner; + +public class ExtendedCube extends Cube { + + public ExtendedCube(int dimension) { + super(dimension); + } + + @Override + public String toString() { + Gson gson = new GsonBuilder().create(); + return gson.toJson(this); + } + + @Override + public String exerciseGuava() { + return Joiner.on(';').join('a', 'b', 'c'); + } +} diff --git a/systemTests/externalLibrary1/extended/src/test/java/com/example/ExtendedCubeTest.java b/systemTests/externalLibrary1/extended/src/test/java/com/example/ExtendedCubeTest.java new file mode 100644 index 00000000..b2722145 --- /dev/null +++ b/systemTests/externalLibrary1/extended/src/test/java/com/example/ExtendedCubeTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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 com.example; + +import org.junit.Assert; +import org.junit.Test; + +public class ExtendedCubeTest { + + @Test + public void testToString() { + Assert.assertEquals("{\"dimension\":7}", new ExtendedCube(7).toString()); + } + + @Test + public void testExerciseGuava() { + Assert.assertEquals("a;b;c", new ExtendedCube(7).exerciseGuava()); + } +} diff --git a/systemTests/externalLibrary1/gradlew b/systemTests/externalLibrary1/gradlew new file mode 120000 index 00000000..343e0d2c --- /dev/null +++ b/systemTests/externalLibrary1/gradlew @@ -0,0 +1 @@ +../../gradlew \ No newline at end of file diff --git a/systemTests/externalLibrary1/local.properties b/systemTests/externalLibrary1/local.properties new file mode 120000 index 00000000..217624b1 --- /dev/null +++ b/systemTests/externalLibrary1/local.properties @@ -0,0 +1 @@ +../common/local.properties \ No newline at end of file diff --git a/systemTests/externalLibrary1/settings.gradle b/systemTests/externalLibrary1/settings.gradle new file mode 100644 index 00000000..fb599281 --- /dev/null +++ b/systemTests/externalLibrary1/settings.gradle @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ +include ':third_party_gson', ':base', ':extended' diff --git a/systemTests/externalLibrary1/third_party_gson/build.gradle b/systemTests/externalLibrary1/third_party_gson/build.gradle new file mode 100644 index 00000000..888d6bc4 --- /dev/null +++ b/systemTests/externalLibrary1/third_party_gson/build.gradle @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +apply plugin: 'java' +apply plugin: 'com.github.j2objccontrib.j2objcgradle' + +repositories { + jcenter() +} + +dependencies { + // j2objcTranslation causes the entire specified library + // to be translated and built into a standalone Objective C library. + // j2objcTranslation must always be passed a *source* jar, + // therefore, note the ':sources' classifier. + j2objcTranslation 'com.google.code.gson:gson:2.3.1:sources' +} + +j2objcConfig { + filenameCollisionCheck false + // Almost always there are no tests provided in an external source jar. + testMinExpectedTests 0 + finalConfigure() +} diff --git a/systemTests/run-all.sh b/systemTests/run-all.sh index 618bb88e..20dfadab 100755 --- a/systemTests/run-all.sh +++ b/systemTests/run-all.sh @@ -34,5 +34,11 @@ function runTest { runTest simple1 # Two gradle projects, `extended` depends on `base`. They also both test -# dependency on built-in j2objc libraries, like Guava. +# dependency on built-in j2objc libraries, like Guava, and build-closure +# based translation of an external library, Gson. runTest multiProject1 + +# Two gradle projects, `extended` depends on `base`. Both of them depend +# on project `third_party_gson`, which fully translates and compiles an +# external library (Google's Gson). This library is used in both `extended` and `base`. +runTest externalLibrary1