Skip to content

Commit

Permalink
Build Java sources during integration tests (#176)
Browse files Browse the repository at this point in the history
- Add Bazel configuration for examples
- Add dependencies for gson / android support annotations
- Fix small errors in generated code
- Update CI to build with the Android SDK and Bazel
- Fix issue with visibilty of ADT classes, potentially move to inner
- Update Travis Scripts (latest android build tools / platform tools)
- Add Makefile command to unify test targets for CI
- Update integration testing script to run tests if `$ANDROID_HOME` is
- Add flow to brew packages, build / test objc example on macOS only defined
- Use bazelisk to manage bazel version, update scripts to use it
  • Loading branch information
rahul-malik authored Mar 13, 2019
1 parent 47ad603 commit efe3c84
Show file tree
Hide file tree
Showing 12 changed files with 525 additions and 137 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.23.2
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
language: generic
osx_image: xcode10
android:
components:
- tools
- platform-tools
- build-tools-28.0.3
- android-28

addons:
homebrew:
packages:
- swiftlint
- flow
jobs:
include:
- stage: "lint"
script: "make lint"
os: osx
- stage: "test"
script: "make test"
script: "make ci_tests"
os: osx
- stage: "test linux"
script: "make test"
script: "make ci_tests"
language: android
sudo: required
dist: trusty
install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
os: linux
- stage: "integration"
script: "make integration_test output_stability_test"
os: osx
8 changes: 8 additions & 0 deletions Examples/Java/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
android_library(
name = "JavaExample",
srcs = glob(["Sources/*.java"], exclude=["Sources/Everything.java"]),
deps = [
"@gson_maven//jar",
"@android_support_annotations//jar",
]
)
180 changes: 92 additions & 88 deletions Examples/Java/Sources/Everything.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,97 +30,27 @@
import java.util.Set;

interface EverythingMapPolymorphicValuesMatcher<R> {
R match(@Nullable User);
R match(@Nullable Board);
R match(@Nullable Image);
R match(@Nullable Pin);
R match(@Nullable Everything);
R match(@Nullable List<Object>);
R match(@Nullable Map<String, Object>);
}

public final class EverythingMapPolymorphicValues<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.USER, InternalStorage.BOARD, InternalStorage.IMAGE, InternalStorage.PIN, InternalStorage.EVERYTHING, InternalStorage.LISTOBJECT, InternalStorage.MAPSTRING_OBJECT})
public @interface InternalStorage {
int USER = 0;
int BOARD = 1;
int IMAGE = 2;
int PIN = 3;
int EVERYTHING = 4;
int LISTOBJECT = 5;
int MAPSTRING_OBJECT = 6;
}

private @Nullable User value0;
private @Nullable Board value1;
private @Nullable Image value2;
private @Nullable Pin value3;
private @Nullable Everything value4;
private @Nullable List<Object> value5;
private @Nullable Map<String, Object> value6;

private @InternalStorage int internalStorage;

private EverythingMapPolymorphicValues() {
}

public R match EverythingMapPolymorphicValues(EverythingMapPolymorphicValuesMatcher<R>) {
}
R match(@Nullable User value0);
R match(@Nullable Board value1);
R match(@Nullable Image value2);
R match(@Nullable Pin value3);
R match(@Nullable Everything value4);
R match(@Nullable List<Object> value5);
R match(@Nullable Map<String, Object> value6);
}

interface EverythingPolymorphicPropMatcher<R> {
R match(@Nullable User);
R match(@Nullable Board);
R match(@Nullable Image);
R match(@Nullable Pin);
R match(@Nullable Everything);
R match(@Nullable String);
R match(@Nullable Boolean);
R match(@Nullable Integer);
R match(@Nullable Double);
R match(@Nullable Date);
R match(@Nullable String);
}

public final class EverythingPolymorphicProp<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.USER, InternalStorage.BOARD, InternalStorage.IMAGE, InternalStorage.PIN, InternalStorage.EVERYTHING, InternalStorage.STRING, InternalStorage.BOOLEAN, InternalStorage.INTEGER, InternalStorage.DOUBLE, InternalStorage.DATE, InternalStorage.STRING})
public @interface InternalStorage {
int USER = 0;
int BOARD = 1;
int IMAGE = 2;
int PIN = 3;
int EVERYTHING = 4;
int STRING = 5;
int BOOLEAN = 6;
int INTEGER = 7;
int DOUBLE = 8;
int DATE = 9;
int STRING = 10;
}

private @Nullable User value0;
private @Nullable Board value1;
private @Nullable Image value2;
private @Nullable Pin value3;
private @Nullable Everything value4;
private @Nullable String value5;
private @Nullable Boolean value6;
private @Nullable Integer value7;
private @Nullable Double value8;
private @Nullable Date value9;
private @Nullable String value10;

private @InternalStorage int internalStorage;

private EverythingPolymorphicProp() {
}

public R match EverythingPolymorphicProp(EverythingPolymorphicPropMatcher<R>) {
}
R match(@Nullable User value0);
R match(@Nullable Board value1);
R match(@Nullable Image value2);
R match(@Nullable Pin value3);
R match(@Nullable Everything value4);
R match(@Nullable String value5);
R match(@Nullable Boolean value6);
R match(@Nullable Integer value7);
R match(@Nullable Double value8);
R match(@Nullable Date value9);
R match(@Nullable String value10);
}

public class Everything {
Expand Down Expand Up @@ -1199,4 +1129,78 @@ public Everything read(JsonReader reader) throws IOException {
return model;
}
}

public static final class EverythingMapPolymorphicValues<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.USER, InternalStorage.BOARD, InternalStorage.IMAGE, InternalStorage.PIN, InternalStorage.EVERYTHING, InternalStorage.LISTOBJECT, InternalStorage.MAPSTRING_OBJECT})
public @interface InternalStorage {
int USER = 0;
int BOARD = 1;
int IMAGE = 2;
int PIN = 3;
int EVERYTHING = 4;
int LISTOBJECT = 5;
int MAPSTRING_OBJECT = 6;
}

private @Nullable User value0;
private @Nullable Board value1;
private @Nullable Image value2;
private @Nullable Pin value3;
private @Nullable Everything value4;
private @Nullable List<Object> value5;
private @Nullable Map<String, Object> value6;

static private @InternalStorage int internalStorage;

private EverythingMapPolymorphicValues() {
}

public R matchEverythingMapPolymorphicValues(EverythingMapPolymorphicValuesMatcher<R> matcher) {
// TODO: Implement this!
return null;
}
}

public static final class EverythingPolymorphicProp<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.USER, InternalStorage.BOARD, InternalStorage.IMAGE, InternalStorage.PIN, InternalStorage.EVERYTHING, InternalStorage.STRING, InternalStorage.BOOLEAN, InternalStorage.INTEGER, InternalStorage.DOUBLE, InternalStorage.DATE, InternalStorage.STRING})
public @interface InternalStorage {
int USER = 0;
int BOARD = 1;
int IMAGE = 2;
int PIN = 3;
int EVERYTHING = 4;
int STRING = 5;
int BOOLEAN = 6;
int INTEGER = 7;
int DOUBLE = 8;
int DATE = 9;
int STRING = 10;
}

private @Nullable User value0;
private @Nullable Board value1;
private @Nullable Image value2;
private @Nullable Pin value3;
private @Nullable Everything value4;
private @Nullable String value5;
private @Nullable Boolean value6;
private @Nullable Integer value7;
private @Nullable Double value8;
private @Nullable Date value9;
private @Nullable String value10;

static private @InternalStorage int internalStorage;

private EverythingPolymorphicProp() {
}

public R matchEverythingPolymorphicProp(EverythingPolymorphicPropMatcher<R> matcher) {
// TODO: Implement this!
return null;
}
}
}
48 changes: 25 additions & 23 deletions Examples/Java/Sources/Pin.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,8 @@
import java.util.Set;

interface PinAttributionObjectsMatcher<R> {
R match(@Nullable Board);
R match(@Nullable User);
}

public final class PinAttributionObjects<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.BOARD, InternalStorage.USER})
public @interface InternalStorage {
int BOARD = 0;
int USER = 1;
}

private @Nullable Board value0;
private @Nullable User value1;

private @InternalStorage int internalStorage;

private PinAttributionObjects() {
}

public R match PinAttributionObjects(PinAttributionObjectsMatcher<R>) {
}
R match(@Nullable Board value0);
R match(@Nullable User value1);
}

public class Pin {
Expand Down Expand Up @@ -727,4 +706,27 @@ public Pin read(JsonReader reader) throws IOException {
return model;
}
}

public static final class PinAttributionObjects<R> {

@Retention(RetentionPolicy.SOURCE)
@IntDef({InternalStorage.BOARD, InternalStorage.USER})
public @interface InternalStorage {
int BOARD = 0;
int USER = 1;
}

private @Nullable Board value0;
private @Nullable User value1;

static private @InternalStorage int internalStorage;

private PinAttributionObjects() {
}

public R matchPinAttributionObjects(PinAttributionObjectsMatcher<R> matcher) {
// TODO: Implement this!
return null;
}
}
}
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This makefile exposes targets that unify building, testing and archiving of
# Plank

.PHONY: all clean lint build test integration_test archive upload_pipeline build_test_index_linux archive_linux install
.PHONY: all clean lint build test integration_test archive upload_pipeline build_test_index_linux archive_linux install output_stability_test ci_tests

PREFIX := /usr/local

Expand All @@ -28,6 +28,8 @@ integration_test: build
output_stability_test: build
./Utility/stable-output-test.sh

ci_tests: test integration_test output_stability_test

archive:
swift build -c release -Xswiftc -static-stdlib --disable-sandbox

Expand Down
16 changes: 9 additions & 7 deletions Sources/Core/JavaADTRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@ extension JavaModelRenderer {
}
*/
func adtRootsForSchema(property: String, schemas: [SchemaObjectProperty]) -> [JavaIR.Root] {
// Open Q: How should AutoValue/GSON work with this?
// Do we need to create a custom runtime type adapter factory?
let adtName = "\(rootSchema.name)_\(property)"
let formattedADTName = adtName.snakeCaseToCamelCase()
let privateInit = JavaIR.method([.private], "\(formattedADTName)()") { [] }

func interfaceMethods() -> [JavaIR.Method] {
return schemas
.map { typeFromSchema("", $0) }
.map { JavaIR.method([], "R match(\($0))") { [] } }
return schemas.enumerated()
.map { (typeFromSchema("", $0.element), $0.offset) }
.map { JavaIR.method([], "R match(\($0.0) value\($0.1))") { [] } }
}

let matcherInterface = JavaIR.Interface(modifiers: [],
extends: nil,
name: "\(formattedADTName)Matcher<R>",
methods: interfaceMethods())

let matcherMethod = JavaIR.method([.public], "R match \(formattedADTName)(\(formattedADTName)Matcher<R>)") { [] }
let matcherMethod = JavaIR.method([.public], "R match\(formattedADTName)(\(formattedADTName)Matcher<R> matcher)") { [
"// TODO: Implement this!",
"return null;",
] }

let internalProperties = schemas.enumerated()
.map { (typeFromSchema("", $0.element), $0.offset) }
Expand All @@ -58,9 +60,9 @@ extension JavaModelRenderer {

let internalStorageEnum = JavaIR.Enum(name: "InternalStorage", values: .integer(enumOptions))

let internalStorageProp = JavaIR.Property(annotations: [], modifiers: [.private], type: "@InternalStorage int", name: "internalStorage", initialValue: "")
let internalStorageProp = JavaIR.Property(annotations: [], modifiers: [.private, .static], type: "@InternalStorage int", name: "internalStorage", initialValue: "")
let cls = JavaIR.Class(annotations: [],
modifiers: [.public, .final],
modifiers: [.public, .static, .final],
extends: nil,
implements: nil,
name: "\(formattedADTName)<R>",
Expand Down
Loading

0 comments on commit efe3c84

Please sign in to comment.