JAVA_KEYWORDS =
31 | new HashSet<>(
32 | Arrays.asList(
33 | "abstract",
34 | "assert",
35 | "boolean",
36 | "break",
37 | "byte",
38 | "case",
39 | "catch",
40 | "char",
41 | "class",
42 | "const",
43 | "continue",
44 | "enum",
45 | "default",
46 | "do",
47 | "double",
48 | "else",
49 | "extends",
50 | "while",
51 | "false",
52 | "final",
53 | "finally",
54 | "float",
55 | "for",
56 | "goto",
57 | "if",
58 | "implements",
59 | "import",
60 | "instanceof",
61 | "int",
62 | "interface",
63 | "long",
64 | "native",
65 | "new",
66 | "null",
67 | "package",
68 | "private",
69 | "protected",
70 | "public",
71 | "return",
72 | "short",
73 | "static",
74 | "strictfp",
75 | "super",
76 | "switch",
77 | "synchronized",
78 | "this",
79 | "throw",
80 | "throws",
81 | "transient",
82 | "true",
83 | "try",
84 | "void",
85 | "volatile"));
86 | // @formatter:on
87 |
88 | /**
89 | * Returns true if the string is null or 0-length.
90 | *
91 | * @param str the string to be examined
92 | * @return true if str is null or zero length
93 | */
94 | public static boolean isNullOrEmpty(String str) {
95 | return str == null || str.trim().length() == 0;
96 | }
97 |
98 | /**
99 | * Returns true if the string is a valid Java identifier. See Identifiers
101 | *
102 | * @param str the string to be examined
103 | * @return true if str is a valid Java identifier
104 | */
105 | public static boolean isValidJavaIdentifier(String str) {
106 | if (isNullOrEmpty(str)) {
107 | return false;
108 | }
109 | if (JAVA_KEYWORDS.contains(str)) {
110 | return false;
111 | }
112 | if (!Character.isJavaIdentifierStart(str.charAt(0))) {
113 | return false;
114 | }
115 | for (int i = 1; i < str.length(); i++) {
116 | if (!Character.isJavaIdentifierPart(str.charAt(i))) {
117 | return false;
118 | }
119 | }
120 | return true;
121 | }
122 |
123 | /**
124 | * Returns true if the string is a valid Java full qualified class name.
125 | *
126 | * @param str the string to be examined
127 | * @return true if str is a valid Java Fqcn
128 | */
129 | public static boolean isValidFqcn(String str) {
130 | if (isNullOrEmpty(str)) {
131 | return false;
132 | }
133 | final String[] parts = str.split("\\.");
134 | if (parts.length < 2) {
135 | return false;
136 | }
137 | for (String part : parts) {
138 | if (!isValidJavaIdentifier(part)) {
139 | return false;
140 | }
141 | }
142 | return true;
143 | }
144 |
145 | private StringUtil() {}
146 | }
147 |
--------------------------------------------------------------------------------
/dart-processor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_8
5 | targetCompatibility = JavaVersion.VERSION_1_8
6 |
7 |
8 | dependencies {
9 | implementation project(':dart-annotations')
10 | implementation project(':dart-common')
11 | implementation project(':dart')
12 | implementation deps.javapoet
13 | implementation deps.parceler.runtime
14 | compileOnly deps.android.runtime
15 |
16 | testImplementation files(org.gradle.internal.jvm.Jvm.current().getToolsJar())
17 | testImplementation deps.junit
18 | testImplementation deps.compiletesting
19 | testImplementation deps.truth
20 | testImplementation deps.fest
21 | testImplementation deps.android.runtime
22 | }
23 |
--------------------------------------------------------------------------------
/dart-processor/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=dart-processor
2 | POM_NAME=Dart Annotation Processor
3 | POM_PACKAGING=jar
--------------------------------------------------------------------------------
/dart-processor/src/main/java/dart/processor/ExtraBinderGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import static dart.common.util.DartModelUtil.DART_MODEL_SUFFIX;
21 |
22 | import com.squareup.javapoet.ClassName;
23 | import com.squareup.javapoet.JavaFile;
24 | import com.squareup.javapoet.MethodSpec;
25 | import com.squareup.javapoet.TypeName;
26 | import com.squareup.javapoet.TypeSpec;
27 | import dart.Dart;
28 | import dart.common.BaseGenerator;
29 | import dart.common.Binding;
30 | import dart.common.ExtraBindingTarget;
31 | import dart.common.ExtraInjection;
32 | import dart.common.FieldBinding;
33 | import java.util.Collection;
34 | import java.util.List;
35 | import javax.lang.model.element.Modifier;
36 | import javax.lang.model.type.TypeMirror;
37 |
38 | /**
39 | * Creates Java code to bind extras into an activity or a {@link android.os.Bundle}.
40 | *
41 | * {@link Dart} to use this code at runtime.
42 | */
43 | public class ExtraBinderGenerator extends BaseGenerator {
44 |
45 | private final ExtraBindingTarget target;
46 |
47 | public ExtraBinderGenerator(ExtraBindingTarget target) {
48 | this.target = target;
49 | }
50 |
51 | @Override
52 | public String brewJava() {
53 | TypeSpec.Builder binderTypeSpec =
54 | TypeSpec.classBuilder(binderClassName()).addModifiers(Modifier.PUBLIC);
55 | emitBind(binderTypeSpec);
56 | JavaFile javaFile =
57 | JavaFile.builder(target.classPackage, binderTypeSpec.build())
58 | .addFileComment("Generated code from Dart. Do not modify!")
59 | .build();
60 | return javaFile.toString();
61 | }
62 |
63 | @Override
64 | public String getFqcn() {
65 | return target.classPackage + "." + binderClassName();
66 | }
67 |
68 | private String binderClassName() {
69 | return target.className + DART_MODEL_SUFFIX + Dart.EXTRA_BINDER_SUFFIX;
70 | }
71 |
72 | private void emitBind(TypeSpec.Builder builder) {
73 | MethodSpec.Builder bindBuilder =
74 | MethodSpec.methodBuilder("bind")
75 | .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
76 | .addParameter(ClassName.get(Dart.Finder.class), "finder")
77 | .addParameter(ClassName.bestGuess(target.getFQN() + DART_MODEL_SUFFIX), "target")
78 | .addParameter(ClassName.get(Object.class), "source");
79 |
80 | if (target.parentPackage != null) {
81 | // Emit a call to the superclass binder, if any.
82 | bindBuilder.addStatement(
83 | "$T.bind(finder, target, source)",
84 | ClassName.bestGuess(
85 | target.getParentFQN() + DART_MODEL_SUFFIX + Dart.EXTRA_BINDER_SUFFIX));
86 | }
87 |
88 | // Local variable in which all extras will be temporarily stored.
89 | bindBuilder.addStatement("Object object");
90 |
91 | // Loop over each extras binding and emit it.
92 | for (ExtraInjection binding : target.bindingMap.values()) {
93 | emitExtraInjection(bindBuilder, binding);
94 | }
95 |
96 | builder.addMethod(bindBuilder.build());
97 | }
98 |
99 | private void emitExtraInjection(MethodSpec.Builder builder, ExtraInjection binding) {
100 | builder.addStatement("object = finder.getExtra(source, $S)", binding.getKey());
101 |
102 | List requiredBindings = binding.getRequiredBindings();
103 | if (!requiredBindings.isEmpty()) {
104 | builder
105 | .beginControlFlow("if (object == null)")
106 | .addStatement(
107 | "throw new IllegalStateException(\"Required extra with key '$L' for $L "
108 | + "was not found. If this extra is optional add '@Nullable' annotation.\")",
109 | binding.getKey(),
110 | emitHumanDescription(requiredBindings))
111 | .endControlFlow();
112 | emitFieldBindings(builder, binding);
113 | } else {
114 | // an optional extra, wrap it in a check to keep original value, if any
115 | builder.beginControlFlow("if (object != null)");
116 | emitFieldBindings(builder, binding);
117 | builder.endControlFlow();
118 | }
119 | }
120 |
121 | private void emitFieldBindings(MethodSpec.Builder builder, ExtraInjection binding) {
122 | Collection fieldBindings = binding.getFieldBindings();
123 | if (fieldBindings.isEmpty()) {
124 | return;
125 | }
126 |
127 | for (FieldBinding fieldBinding : fieldBindings) {
128 | builder.addCode("target.$L = ", fieldBinding.getName());
129 |
130 | if (fieldBinding.isParcel()) {
131 | builder.addCode("org.parceler.Parcels.unwrap((android.os.Parcelable) object);\n");
132 | } else {
133 | emitCast(builder, fieldBinding.getType());
134 | builder.addCode("object;\n");
135 | }
136 | }
137 | }
138 |
139 | private void emitCast(MethodSpec.Builder builder, TypeMirror fieldType) {
140 | builder.addCode("($T) ", TypeName.get(fieldType));
141 | }
142 |
143 | //TODO add android annotations dependency to get that annotation plus others.
144 |
145 | /** Visible for testing */
146 | String emitHumanDescription(List bindings) {
147 | StringBuilder builder = new StringBuilder();
148 | switch (bindings.size()) {
149 | case 1:
150 | builder.append(bindings.get(0).getDescription());
151 | break;
152 | case 2:
153 | builder
154 | .append(bindings.get(0).getDescription())
155 | .append(" and ")
156 | .append(bindings.get(1).getDescription());
157 | break;
158 | default:
159 | for (int i = 0, count = bindings.size(); i < count; i++) {
160 | Binding requiredField = bindings.get(i);
161 | if (i != 0) {
162 | builder.append(", ");
163 | }
164 | if (i == count - 1) {
165 | builder.append("and ");
166 | }
167 | builder.append(requiredField.getDescription());
168 | }
169 | break;
170 | }
171 | return builder.toString();
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/dart-processor/src/main/java/dart/processor/ExtraBinderProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import dart.common.ExtraBindingTarget;
21 | import dart.common.util.BindExtraUtil;
22 | import dart.common.util.CompilerUtil;
23 | import dart.common.util.DartModelUtil;
24 | import dart.common.util.ExtraBindingTargetUtil;
25 | import dart.common.util.FileUtil;
26 | import dart.common.util.LoggingUtil;
27 | import dart.common.util.ParcelerUtil;
28 | import java.io.IOException;
29 | import java.util.HashMap;
30 | import java.util.LinkedHashMap;
31 | import java.util.Map;
32 | import java.util.Set;
33 | import javax.annotation.processing.AbstractProcessor;
34 | import javax.annotation.processing.ProcessingEnvironment;
35 | import javax.annotation.processing.RoundEnvironment;
36 | import javax.annotation.processing.SupportedAnnotationTypes;
37 | import javax.lang.model.SourceVersion;
38 | import javax.lang.model.element.TypeElement;
39 |
40 | @SupportedAnnotationTypes({
41 | ExtraBinderProcessor.NAVIGATION_MODEL_ANNOTATION_CLASS_NAME,
42 | ExtraBinderProcessor.EXTRA_ANNOTATION_CLASS_NAME
43 | })
44 | public final class ExtraBinderProcessor extends AbstractProcessor {
45 |
46 | static final String NAVIGATION_MODEL_ANNOTATION_CLASS_NAME = "dart.DartModel";
47 | static final String EXTRA_ANNOTATION_CLASS_NAME = "dart.BindExtra";
48 |
49 | private LoggingUtil loggingUtil;
50 | private FileUtil fileUtil;
51 | private ExtraBindingTargetUtil extraBindingTargetUtil;
52 | private DartModelUtil dartModelUtil;
53 | private BindExtraUtil bindExtraUtil;
54 | private Map allRoundsGeneratedToTypeElement = new HashMap<>();
55 |
56 | private boolean usesParcelerOption = true;
57 |
58 | @Override
59 | public synchronized void init(ProcessingEnvironment processingEnv) {
60 | super.init(processingEnv);
61 |
62 | final CompilerUtil compilerUtil = new CompilerUtil(processingEnv);
63 | final ParcelerUtil parcelerUtil =
64 | new ParcelerUtil(compilerUtil, processingEnv, usesParcelerOption);
65 | loggingUtil = new LoggingUtil(processingEnv);
66 | fileUtil = new FileUtil(processingEnv);
67 | extraBindingTargetUtil = new ExtraBindingTargetUtil(compilerUtil, processingEnv, loggingUtil);
68 | dartModelUtil = new DartModelUtil(loggingUtil, extraBindingTargetUtil, compilerUtil);
69 | bindExtraUtil =
70 | new BindExtraUtil(
71 | compilerUtil, parcelerUtil, loggingUtil, extraBindingTargetUtil, dartModelUtil);
72 | }
73 |
74 | @Override
75 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
76 | dartModelUtil.setRoundEnvironment(roundEnv);
77 | bindExtraUtil.setRoundEnvironment(roundEnv);
78 |
79 | Map targetClassMap = findAndParseTargets();
80 | generateExtraBinders(targetClassMap);
81 |
82 | //return false here to let henson process the annotations too
83 | return false;
84 | }
85 |
86 | @Override
87 | public SourceVersion getSupportedSourceVersion() {
88 | return SourceVersion.latestSupported();
89 | }
90 |
91 | /**
92 | * Flag to force enabling/disabling Parceler. Used for testing.
93 | *
94 | * @param enable whether Parceler should be enable
95 | */
96 | public void enableParceler(boolean enable) {
97 | usesParcelerOption = enable;
98 | }
99 |
100 | private Map findAndParseTargets() {
101 | Map targetClassMap = new LinkedHashMap<>();
102 |
103 | dartModelUtil.parseDartModelAnnotatedTypes(targetClassMap);
104 | bindExtraUtil.parseBindExtraAnnotatedElements(targetClassMap);
105 | extraBindingTargetUtil.createBindingTargetTrees(targetClassMap);
106 |
107 | return targetClassMap;
108 | }
109 |
110 | private void generateExtraBinders(Map targetClassMap) {
111 | for (Map.Entry entry : targetClassMap.entrySet()) {
112 | TypeElement typeElement = entry.getKey();
113 | ExtraBindingTarget extraBindingTarget = entry.getValue();
114 |
115 | //we unfortunately can't test that nothing is generated in a TRUTH based test
116 | try {
117 | ExtraBinderGenerator generator = new ExtraBinderGenerator(extraBindingTarget);
118 | fileUtil.writeFile(generator, typeElement);
119 | allRoundsGeneratedToTypeElement.put(generator.getFqcn(), typeElement);
120 | } catch (IOException e) {
121 | loggingUtil.error(
122 | typeElement,
123 | "Unable to write extra binder for type %s: %s",
124 | typeElement,
125 | e.getMessage());
126 | }
127 | }
128 | }
129 |
130 | /*visible for testing*/
131 | TypeElement getOriginatingElement(String generatedQualifiedName) {
132 | return allRoundsGeneratedToTypeElement.get(generatedQualifiedName);
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/dart-processor/src/main/java/dart/processor/NavigationModelBinderGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import static com.squareup.javapoet.ClassName.bestGuess;
21 | import static com.squareup.javapoet.ClassName.get;
22 | import static dart.common.util.NavigationModelBindingTargetUtil.NAVIGATION_MODEL_BINDER_SUFFIX;
23 |
24 | import com.squareup.javapoet.JavaFile;
25 | import com.squareup.javapoet.MethodSpec;
26 | import com.squareup.javapoet.TypeSpec;
27 | import dart.Dart;
28 | import dart.common.BaseGenerator;
29 | import dart.common.NavigationModelBindingTarget;
30 | import javax.lang.model.element.Modifier;
31 |
32 | /**
33 | * Creates Java code to bind NavigationModel into an activity/services/fragment.
34 | *
35 | * {@link Dart} to use this code at runtime.
36 | */
37 | public class NavigationModelBinderGenerator extends BaseGenerator {
38 |
39 | private final NavigationModelBindingTarget target;
40 |
41 | public NavigationModelBinderGenerator(NavigationModelBindingTarget target) {
42 | this.target = target;
43 | }
44 |
45 | @Override
46 | public String brewJava() {
47 | TypeSpec.Builder binderTypeSpec =
48 | TypeSpec.classBuilder(binderClassName()).addModifiers(Modifier.PUBLIC);
49 |
50 | emitBind(binderTypeSpec);
51 | emitAssign(binderTypeSpec);
52 |
53 | JavaFile javaFile =
54 | JavaFile.builder(target.classPackage, binderTypeSpec.build())
55 | .addFileComment("Generated code from Dart. Do not modify!")
56 | .build();
57 | return javaFile.toString();
58 | }
59 |
60 | @Override
61 | public String getFqcn() {
62 | return target.classPackage + "." + binderClassName();
63 | }
64 |
65 | private String binderClassName() {
66 | return target.className + NAVIGATION_MODEL_BINDER_SUFFIX;
67 | }
68 |
69 | private void emitBind(TypeSpec.Builder builder) {
70 | MethodSpec.Builder bindBuilder =
71 | MethodSpec.methodBuilder("bind")
72 | .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
73 | .addParameter(get(Dart.Finder.class), "finder")
74 | .addParameter(bestGuess(target.getFQN()), "target");
75 |
76 | bindBuilder.addStatement(
77 | "target.$L = new $T()",
78 | target.navigationModelFieldName,
79 | get(target.navigationModelPackage, target.navigationModelClass));
80 |
81 | bindBuilder.addStatement(
82 | "$T.bind(finder, target.$L, target)",
83 | get(target.navigationModelPackage, target.navigationModelClass + Dart.EXTRA_BINDER_SUFFIX),
84 | target.navigationModelFieldName);
85 |
86 | if (target.parentPackage != null) {
87 | // Emit a call to the superclass binder, if any.
88 | bindBuilder.addStatement(
89 | "$T.assign(target, target.$L)",
90 | bestGuess(target.getParentFQN() + NAVIGATION_MODEL_BINDER_SUFFIX),
91 | target.navigationModelFieldName);
92 | }
93 |
94 | builder.addMethod(bindBuilder.build());
95 | }
96 |
97 | private void emitAssign(TypeSpec.Builder builder) {
98 | MethodSpec.Builder bindBuilder =
99 | MethodSpec.methodBuilder("assign")
100 | .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
101 | .addParameter(bestGuess(target.getFQN()), "target")
102 | .addParameter(
103 | get(target.navigationModelPackage, target.navigationModelClass), "navigationModel");
104 |
105 | bindBuilder.addStatement("target.$L = navigationModel", target.navigationModelFieldName);
106 |
107 | if (target.parentPackage != null) {
108 | // Emit a call to the superclass binder, if any.
109 | bindBuilder.addStatement(
110 | "$T.assign(target, navigationModel)",
111 | bestGuess(target.getParentFQN() + NAVIGATION_MODEL_BINDER_SUFFIX));
112 | }
113 |
114 | builder.addMethod(bindBuilder.build());
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/dart-processor/src/main/java/dart/processor/NavigationModelBinderProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import dart.common.NavigationModelBindingTarget;
21 | import dart.common.util.CompilerUtil;
22 | import dart.common.util.FileUtil;
23 | import dart.common.util.LoggingUtil;
24 | import dart.common.util.NavigationModelBindingTargetUtil;
25 | import dart.common.util.NavigationModelFieldUtil;
26 | import java.io.IOException;
27 | import java.util.HashMap;
28 | import java.util.LinkedHashMap;
29 | import java.util.Map;
30 | import java.util.Set;
31 | import javax.annotation.processing.AbstractProcessor;
32 | import javax.annotation.processing.ProcessingEnvironment;
33 | import javax.annotation.processing.RoundEnvironment;
34 | import javax.annotation.processing.SupportedAnnotationTypes;
35 | import javax.lang.model.SourceVersion;
36 | import javax.lang.model.element.TypeElement;
37 |
38 | @SupportedAnnotationTypes({
39 | NavigationModelBinderProcessor.NAVIGATION_MODEL_ANNOTATION_CLASS_NAME,
40 | })
41 | public final class NavigationModelBinderProcessor extends AbstractProcessor {
42 |
43 | static final String NAVIGATION_MODEL_ANNOTATION_CLASS_NAME = "dart.DartModel";
44 |
45 | private LoggingUtil loggingUtil;
46 | private FileUtil fileUtil;
47 | private NavigationModelBindingTargetUtil navigationModelBindingTargetUtil;
48 | private NavigationModelFieldUtil navigationModelFieldUtil;
49 | private Map allRoundsGeneratedToTypeElement = new HashMap<>();
50 |
51 | @Override
52 | public synchronized void init(ProcessingEnvironment processingEnv) {
53 | super.init(processingEnv);
54 |
55 | final CompilerUtil compilerUtil = new CompilerUtil(processingEnv);
56 | loggingUtil = new LoggingUtil(processingEnv);
57 | fileUtil = new FileUtil(processingEnv);
58 | navigationModelBindingTargetUtil =
59 | new NavigationModelBindingTargetUtil(compilerUtil, processingEnv);
60 | navigationModelFieldUtil =
61 | new NavigationModelFieldUtil(loggingUtil, navigationModelBindingTargetUtil);
62 | }
63 |
64 | @Override
65 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
66 | navigationModelFieldUtil.setRoundEnvironment(roundEnv);
67 |
68 | Map targetClassMap = findAndParseTargets();
69 | generateNavigationModelBinder(targetClassMap);
70 |
71 | //return false here to let henson process the annotations too
72 | return false;
73 | }
74 |
75 | @Override
76 | public SourceVersion getSupportedSourceVersion() {
77 | return SourceVersion.latestSupported();
78 | }
79 |
80 | private Map findAndParseTargets() {
81 | Map targetClassMap = new LinkedHashMap<>();
82 |
83 | navigationModelFieldUtil.parseDartModelAnnotatedFields(targetClassMap);
84 | navigationModelBindingTargetUtil.createBindingTargetTrees(targetClassMap);
85 |
86 | return targetClassMap;
87 | }
88 |
89 | private void generateNavigationModelBinder(
90 | Map targetClassMap) {
91 | for (Map.Entry entry : targetClassMap.entrySet()) {
92 | TypeElement typeElement = entry.getKey();
93 | NavigationModelBindingTarget navigationModelBindingTarget = entry.getValue();
94 |
95 | //we unfortunately can't test that nothing is generated in a TRUTH based test
96 | try {
97 | NavigationModelBinderGenerator generator =
98 | new NavigationModelBinderGenerator(navigationModelBindingTarget);
99 | fileUtil.writeFile(generator, typeElement);
100 | allRoundsGeneratedToTypeElement.put(generator.getFqcn(), typeElement);
101 | } catch (IOException e) {
102 | loggingUtil.error(
103 | typeElement,
104 | "Unable to write extra binder for type %s: %s",
105 | typeElement,
106 | e.getMessage());
107 | }
108 | }
109 | }
110 |
111 | /*visible for testing*/
112 | TypeElement getOriginatingElement(String generatedQualifiedName) {
113 | return allRoundsGeneratedToTypeElement.get(generatedQualifiedName);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/dart-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors:
--------------------------------------------------------------------------------
1 | dart.processor.ExtraBinderProcessor,isolating
2 | dart.processor.NavigationModelBinderProcessor,isolating
3 |
--------------------------------------------------------------------------------
/dart-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2013 Jake Wharton
3 | # Copyright 2014 Prateek Srivastava (@f2prateek)
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | dart.processor.ExtraBinderProcessor
19 | dart.processor.NavigationModelBinderProcessor
20 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/ExtraBinderGeneratorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import static java.util.Arrays.asList;
21 | import static org.fest.assertions.api.Assertions.assertThat;
22 |
23 | import dart.common.Binding;
24 | import dart.common.ExtraBindingTarget;
25 | import org.junit.Before;
26 | import org.junit.Test;
27 |
28 | public class ExtraBinderGeneratorTest {
29 |
30 | ExtraBinderGenerator extraBinderGenerator;
31 |
32 | @Before
33 | public void setup() {
34 | final ExtraBindingTarget extraBindingTarget =
35 | new ExtraBindingTarget("foo", "barNavigationModel");
36 | extraBinderGenerator = new ExtraBinderGenerator(extraBindingTarget);
37 | }
38 |
39 | @Test
40 | public void humanDescriptionJoinWorks() {
41 | Binding one = new TestBinding("one");
42 | Binding two = new TestBinding("two");
43 | Binding three = new TestBinding("three");
44 |
45 | String actual1 = extraBinderGenerator.emitHumanDescription(asList(one));
46 | assertThat(actual1).isEqualTo("one");
47 |
48 | String actual2 = extraBinderGenerator.emitHumanDescription(asList(one, two));
49 | assertThat(actual2).isEqualTo("one and two");
50 |
51 | String actual3 = extraBinderGenerator.emitHumanDescription(asList(one, two, three));
52 | assertThat(actual3).isEqualTo("one, two, and three");
53 | }
54 |
55 | private static class TestBinding implements Binding {
56 | private final String description;
57 |
58 | private TestBinding(String description) {
59 | this.description = description;
60 | }
61 |
62 | @Override
63 | public String getDescription() {
64 | return description;
65 | }
66 |
67 | @Override
68 | public boolean isRequired() {
69 | throw new AssertionError();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/ProcessorTestUtilities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor;
19 |
20 | import javax.lang.model.element.Element;
21 | import javax.lang.model.element.TypeElement;
22 |
23 | final class ProcessorTestUtilities {
24 | static ExtraBinderProcessor extraBinderProcessors() {
25 | return new ExtraBinderProcessor();
26 | }
27 |
28 | static ExtraBinderProcessor extraBinderProcessorsWithoutParceler() {
29 | ExtraBinderProcessor bindExtraProcessor = new ExtraBinderProcessor();
30 | bindExtraProcessor.enableParceler(false);
31 | return bindExtraProcessor;
32 | }
33 |
34 | static NavigationModelBinderProcessor navigationModelBinderProcessors() {
35 | return new NavigationModelBinderProcessor();
36 | }
37 |
38 | static TypeElement getMostEnclosingElement(Element element) {
39 | if (element == null) {
40 | return null;
41 | }
42 |
43 | while (element.getEnclosingElement() != null
44 | && element.getEnclosingElement().getKind().isClass()
45 | || element.getEnclosingElement().getKind().isInterface()) {
46 | element = element.getEnclosingElement();
47 | }
48 | return (TypeElement) element;
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/data/ActivityWithNavigationModelField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor.data;
19 |
20 | import dart.DartModel;
21 |
22 | public class ActivityWithNavigationModelField {
23 | @DartModel ActivityWithNavigationModelFieldNavigationModel navigationModel;
24 | }
25 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/data/ActivityWithNavigationModelFieldNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor.data;
19 |
20 | import dart.DartModel;
21 |
22 | @DartModel
23 | public class ActivityWithNavigationModelFieldNavigationModel {}
24 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/data/SubActivityWithNavigationModelField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor.data;
19 |
20 | import dart.DartModel;
21 |
22 | public class SubActivityWithNavigationModelField extends ActivityWithNavigationModelField {
23 | @DartModel SubActivityWithNavigationModelFieldNavigationModel subNavigationModel;
24 | }
25 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/data/SubActivityWithNavigationModelFieldNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor.data;
19 |
20 | import dart.DartModel;
21 |
22 | @DartModel
23 | public class SubActivityWithNavigationModelFieldNavigationModel
24 | extends ActivityWithNavigationModelFieldNavigationModel {}
25 |
--------------------------------------------------------------------------------
/dart-processor/src/test/java/dart/processor/data/SubActivityWithNoNavigationModelField.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.processor.data;
19 |
20 | public class SubActivityWithNoNavigationModelField extends ActivityWithNavigationModelField {}
21 |
--------------------------------------------------------------------------------
/dart-sample/app-navigation/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenLocal()
4 | jcenter()
5 | google()
6 | }
7 |
8 | dependencies {
9 | classpath deps.dart.gradlePlugin
10 | }
11 | }
12 |
13 | apply plugin: 'com.android.library'
14 |
15 | android {
16 | compileSdkVersion versions.compileSdk
17 |
18 | compileOptions {
19 | sourceCompatibility = JavaVersion.VERSION_1_8
20 | targetCompatibility = JavaVersion.VERSION_1_8
21 | }
22 |
23 | defaultConfig {
24 | minSdkVersion versions.minSdk
25 | targetSdkVersion versions.compileSdk
26 | versionCode 1
27 | versionName '1.0.0'
28 | }
29 |
30 | lintOptions {
31 | textReport true
32 | textOutput 'stdout'
33 | abortOnError false
34 | }
35 |
36 | buildTypes {
37 | debug {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40 | }
41 | }
42 | }
43 |
44 | dependencies {
45 | implementation deps.android.annotations
46 | implementation deps.dart.annotations
47 | implementation deps.dart.runtime
48 | implementation deps.henson.runtime
49 | implementation deps.parceler.runtime
50 | implementation project(':module1-navigation')
51 |
52 | annotationProcessor deps.henson.compiler
53 | annotationProcessor deps.dart.compiler
54 | }
55 |
--------------------------------------------------------------------------------
/dart-sample/app-navigation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
--------------------------------------------------------------------------------
/dart-sample/app-navigation/src/main/java/com/f2prateek/dart/example/SampleActivityNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.example;
19 |
20 | import android.support.annotation.Nullable;
21 | import android.util.SparseArray;
22 | import com.f2prateek.dart.model.ComplexParcelable;
23 | import com.f2prateek.dart.model.StringParcel;
24 | import dart.BindExtra;
25 | import java.util.List;
26 |
27 | public class SampleActivityNavigationModel {
28 |
29 | public static final String DEFAULT_EXTRA_VALUE = "a default value";
30 |
31 | private static final String EXTRA_STRING = "extraString";
32 | private static final String EXTRA_INT = "extraInt";
33 | private static final String EXTRA_PARCELABLE = "extraParcelable";
34 | private static final String EXTRA_PARCEL = "extraParcel";
35 | private static final String EXTRA_LIST_PARCELABLE = "extraListParcelable";
36 | private static final String EXTRA_SPARSE_ARRAY_PARCELABLE = "extraSparseArrayParcelable";
37 | private static final String EXTRA_OPTIONAL = "extraOptional";
38 | private static final String EXTRA_WITH_DEFAULT = "extraWithDefault";
39 |
40 | public @BindExtra(EXTRA_STRING) String stringExtra;
41 | public @BindExtra(EXTRA_INT) int intExtra;
42 | public @BindExtra(EXTRA_PARCELABLE) ComplexParcelable parcelableExtra;
43 | public @BindExtra(EXTRA_PARCEL) StringParcel parcelExtra;
44 | public @BindExtra(EXTRA_LIST_PARCELABLE) List listParcelExtra;
45 | public @BindExtra(EXTRA_SPARSE_ARRAY_PARCELABLE) SparseArray sparseArrayParcelExtra;
46 | public @BindExtra(EXTRA_OPTIONAL) @Nullable String optionalExtra;
47 | public @BindExtra(EXTRA_WITH_DEFAULT) @Nullable String defaultExtra = DEFAULT_EXTRA_VALUE;
48 | public @BindExtra String defaultKeyExtra;
49 | }
50 |
--------------------------------------------------------------------------------
/dart-sample/app/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | //this is used for development of the plugin
4 | mavenLocal()
5 | jcenter()
6 | google()
7 | }
8 |
9 | dependencies {
10 | classpath deps.dart.gradlePlugin
11 | }
12 |
13 | //this is used for development of the plugin
14 | configurations.classpath {
15 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
16 | }
17 | }
18 |
19 | apply plugin: 'com.android.application'
20 | apply plugin: 'dart.henson-plugin'
21 |
22 |
23 | android {
24 | compileSdkVersion versions.compileSdk
25 |
26 | compileOptions {
27 | sourceCompatibility = JavaVersion.VERSION_1_8
28 | targetCompatibility = JavaVersion.VERSION_1_8
29 | }
30 |
31 | defaultConfig {
32 | applicationId 'com.f2prateek.dart.example'
33 | minSdkVersion versions.minSdk
34 | targetSdkVersion versions.compileSdk
35 | versionCode 1
36 | versionName '1.0.0'
37 | }
38 |
39 | lintOptions {
40 | textReport true
41 | textOutput 'stdout'
42 | abortOnError false
43 | }
44 |
45 | buildTypes {
46 | debug {
47 | minifyEnabled false
48 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
49 | }
50 | }
51 | }
52 |
53 | dependencies {
54 | implementation deps.butterknife.runtime
55 | implementation deps.dart.annotations
56 | implementation deps.dart.runtime
57 | implementation deps.henson.runtime
58 | implementation project(':app-navigation')
59 | implementation project(':module1')
60 | implementation project(':module1-navigation')
61 |
62 | annotationProcessor deps.butterknife.compiler
63 | annotationProcessor deps.dart.compiler
64 | }
65 |
66 | henson.navigatorPackageName = 'com.f2prateek.dart.example'
67 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/java/com/f2prateek/dart/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.example;
19 |
20 | import android.app.Activity;
21 | import android.content.Intent;
22 | import android.os.Bundle;
23 | import android.util.SparseArray;
24 | import butterknife.ButterKnife;
25 | import butterknife.OnClick;
26 |
27 | import com.f2prateek.dart.model.ComplexParcelable;
28 | import com.f2prateek.dart.model.StringParcel;
29 | import java.util.ArrayList;
30 | import java.util.List;
31 |
32 | public class MainActivity extends Activity {
33 |
34 | @Override protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.activity_main);
37 |
38 | ButterKnife.bind(this);
39 | }
40 |
41 | // Launch Sample Activity residing in the same module
42 | @OnClick(R.id.navigateToSampleActivity)
43 | public void onSampleActivityCTAClick() {
44 | StringParcel parcel1 = new StringParcel("Andy");
45 | StringParcel parcel2 = new StringParcel("Tony");
46 |
47 | List parcelList = new ArrayList<>();
48 | parcelList.add(parcel1);
49 | parcelList.add(parcel2);
50 |
51 | SparseArray parcelSparseArray = new SparseArray<>();
52 | parcelSparseArray.put(0, parcel1);
53 | parcelSparseArray.put(2, parcel2);
54 |
55 | Intent intent = HensonNavigator.gotoSampleActivity(this)
56 | .defaultKeyExtra("defaultKeyExtra")
57 | .extraInt(4)
58 | .extraListParcelable(parcelList)
59 | .extraParcel(parcel1)
60 | .extraParcelable(ComplexParcelable.random())
61 | .extraSparseArrayParcelable(parcelSparseArray)
62 | .extraString("a string")
63 | .build();
64 |
65 | startActivity(intent);
66 | }
67 |
68 | // Launch Navigation Activity residing in the navigation module
69 | @OnClick(R.id.navigateToModule1Activity)
70 | public void onNavigationActivityCTAClick() {
71 | StringParcel parcel1 = new StringParcel("Andy");
72 | StringParcel parcel2 = new StringParcel("Tony");
73 |
74 | List parcelList = new ArrayList<>();
75 | parcelList.add(parcel1);
76 | parcelList.add(parcel2);
77 |
78 | SparseArray parcelSparseArray = new SparseArray<>();
79 | parcelSparseArray.put(0, parcel1);
80 | parcelSparseArray.put(2, parcel2);
81 |
82 | Intent intent = HensonNavigator.gotoModule1Activity(this)
83 | .defaultKeyExtra("defaultKeyExtra")
84 | .extraInt(4)
85 | .extraListParcelable(parcelList)
86 | .extraParcel(parcel1)
87 | .extraParcelable(ComplexParcelable.random())
88 | .extraSparseArrayParcelable(parcelSparseArray)
89 | .extraString("a string")
90 | .build();
91 |
92 | startActivity(intent);
93 | }
94 |
95 | // Launch Navigation Service residing in the navigation module
96 | @OnClick(R.id.navigateToModule1Service)
97 | public void onNavigationServiceCTAClick() {
98 | Intent intentService = HensonNavigator.gotoModule1Service(this)
99 | .stringExtra("foo")
100 | .build();
101 |
102 | startService(intentService);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/java/com/f2prateek/dart/example/SampleActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.example;
19 |
20 | import android.app.Activity;
21 | import android.os.Bundle;
22 | import android.widget.TextView;
23 | import butterknife.BindView;
24 | import butterknife.ButterKnife;
25 | import dart.Dart;
26 | import dart.DartModel;
27 |
28 | public class SampleActivity extends Activity {
29 |
30 | @BindView(R.id.default_key_extra) TextView defaultKeyExtraTextView;
31 | @BindView(R.id.string_extra) TextView stringExtraTextView;
32 | @BindView(R.id.int_extra) TextView intExtraTextView;
33 | @BindView(R.id.parcelable_extra) TextView parcelableExtraTextView;
34 | @BindView(R.id.optional_extra) TextView optionalExtraTextView;
35 | @BindView(R.id.parcel_extra) TextView parcelExtraTextView;
36 | @BindView(R.id.list_parcel_extra) TextView listParcelExtraTextView;
37 | @BindView(R.id.sparse_array_parcel_extra) TextView sparseArrayParcelExtraTextView;
38 | @BindView(R.id.default_extra) TextView defaultExtraTextView;
39 |
40 | @DartModel SampleActivityNavigationModel navigationModel;
41 |
42 | @Override protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_sample);
45 |
46 | ButterKnife.bind(this);
47 | Dart.bind(this);
48 |
49 | // Contrived code to use the "bound" extras.
50 | stringExtraTextView.setText(navigationModel.stringExtra);
51 | intExtraTextView.setText(String.valueOf(navigationModel.intExtra));
52 | parcelableExtraTextView.setText(String.valueOf(navigationModel.parcelableExtra));
53 | optionalExtraTextView.setText(String.valueOf(navigationModel.optionalExtra));
54 | parcelExtraTextView.setText(String.valueOf(navigationModel.parcelExtra.getName()));
55 | listParcelExtraTextView.setText(String.valueOf(navigationModel.listParcelExtra.size()));
56 | sparseArrayParcelExtraTextView.setText(
57 | String.valueOf(navigationModel.sparseArrayParcelExtra.size()));
58 | defaultExtraTextView.setText(String.valueOf(navigationModel.defaultExtra));
59 | defaultKeyExtraTextView.setText(navigationModel.defaultKeyExtra);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/java/com/f2prateek/dart/example/SampleApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.example;
19 |
20 | import android.app.Application;
21 | import butterknife.ButterKnife;
22 | import dart.Dart;
23 |
24 | public class SampleApp extends Application {
25 | @Override public void onCreate() {
26 | super.onCreate();
27 | ButterKnife.setDebug(BuildConfig.DEBUG);
28 | Dart.setDebug(BuildConfig.DEBUG);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
24 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/res/layout/activity_sample.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
25 |
32 |
39 |
46 |
53 |
60 |
67 |
74 |
81 |
88 |
89 |
--------------------------------------------------------------------------------
/dart-sample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
21 | Dart
22 | Launch Sample Activity
23 | Launch Module1 Activity
24 | Launch Module1 Service
25 | Sample Activity
26 |
27 |
--------------------------------------------------------------------------------
/dart-sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jakewharton.butterknife'
2 |
3 | buildscript {
4 | ext.versions = [
5 | 'minSdk': 14,
6 | 'compileSdk': 28,
7 |
8 | 'supportLibrary': '26.0.0',
9 | 'androidPlugin': '3.3.0',
10 | 'androidTools': '28.0.3',
11 | 'parceler' : '1.0.4',
12 | 'butterknife' : '9.0.0-SNAPSHOT',
13 | 'release': '3.0.0',
14 | ]
15 |
16 | ext.deps = [
17 | android: [
18 | 'runtime': 'com.google.android:android:4.1.1.4',
19 | 'gradlePlugin': "com.android.tools.build:gradle:${versions.androidPlugin}",
20 | 'annotations': "com.android.support:support-annotations:${versions.supportLibrary}",
21 | 'appCompat': "com.android.support:appcompat-v7:${versions.supportLibrary}"
22 | ],
23 | parceler: [
24 | 'runtime': "org.parceler:parceler-api:${versions.parceler}",
25 | 'compiler': "org.parceler:parceler:${versions.parceler}"
26 | ],
27 | dart: [
28 | 'annotations': "com.f2prateek.dart:dart-annotations:${versions.release}",
29 | 'runtime': "com.f2prateek.dart:dart:${versions.release}",
30 | 'compiler': "com.f2prateek.dart:dart-processor:${versions.release}",
31 | 'gradlePlugin': "com.f2prateek.dart:henson-plugin:${versions.release}"
32 | ],
33 | henson:[
34 | 'runtime': "com.f2prateek.dart:henson:${versions.release}",
35 | 'compiler': "com.f2prateek.dart:henson-processor:${versions.release}"
36 | ],
37 | butterknife:[
38 | 'runtime': "com.jakewharton:butterknife:${versions.butterknife}",
39 | 'compiler': "com.jakewharton:butterknife-compiler:${versions.butterknife}",
40 | 'annotations': "com.jakewharton:butterknife-annotations:${versions.butterknife}",
41 | 'gradlePlugin': "com.jakewharton:butterknife-gradle-plugin:${versions.butterknife}"
42 | ],
43 | ]
44 |
45 | repositories {
46 | jcenter()
47 | google()
48 | maven {
49 | url "https://plugins.gradle.org/m2/"
50 | }
51 | maven {
52 | url "https://oss.sonatype.org/content/repositories/snapshots"
53 | }
54 | }
55 |
56 | dependencies {
57 | classpath deps.android.gradlePlugin
58 | classpath deps.butterknife.gradlePlugin
59 | }
60 | }
61 |
62 | allprojects {
63 | repositories {
64 | jcenter()
65 | google()
66 | // TODO: Remove this
67 | mavenLocal()
68 | mavenCentral()
69 | maven {
70 | url "https://oss.sonatype.org/content/repositories/snapshots"
71 | }
72 | }
73 |
74 | tasks.withType(JavaCompile) { task ->
75 | task.options.compilerArgs << "-Xlint:deprecation"
76 | }
77 | }
78 |
79 | task check {
80 | dependsOn gradle.includedBuild('dart-parent').task(':install')
81 | }
82 |
--------------------------------------------------------------------------------
/dart-sample/gradle.properties:
--------------------------------------------------------------------------------
1 | enableAapt2=false
2 |
--------------------------------------------------------------------------------
/dart-sample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f2prateek/dart/ce582c1a217c436bb93924004dc1f5b1fe04f1e0/dart-sample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/dart-sample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 01 10:02:56 PDT 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
7 |
--------------------------------------------------------------------------------
/dart-sample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/dart-sample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | google()
5 | }
6 | }
7 |
8 | apply plugin: 'com.android.library'
9 |
10 | android {
11 | compileSdkVersion versions.compileSdk
12 |
13 | defaultConfig {
14 | minSdkVersion versions.minSdk
15 | }
16 |
17 | lintOptions {
18 | abortOnError false
19 | }
20 | }
21 |
22 | dependencies {
23 | implementation deps.android.annotations
24 | implementation deps.parceler.runtime
25 | implementation deps.dart.runtime
26 | implementation deps.dart.annotations
27 | implementation deps.henson.runtime
28 |
29 | annotationProcessor deps.parceler.compiler
30 | annotationProcessor deps.henson.compiler
31 | annotationProcessor deps.dart.compiler
32 | }
33 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/java/com/f2prateek/dart/model/ComplexParcelable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.model;
19 |
20 | import android.os.Parcel;
21 | import android.os.Parcelable;
22 |
23 | // A parcelable containing a parcelable
24 | public class ComplexParcelable implements Parcelable {
25 |
26 | SimpleParcelable parcelable;
27 |
28 | public ComplexParcelable(SimpleParcelable parcelable) {
29 | this.parcelable = parcelable;
30 | }
31 |
32 | public static ComplexParcelable random() {
33 | return new ComplexParcelable(SimpleParcelable.random());
34 | }
35 |
36 | protected ComplexParcelable(Parcel in) {
37 | parcelable = (SimpleParcelable) in.readValue(SimpleParcelable.class.getClassLoader());
38 | }
39 |
40 | @Override
41 | public int describeContents() {
42 | return 0;
43 | }
44 |
45 | @Override
46 | public void writeToParcel(Parcel dest, int flags) {
47 | dest.writeValue(parcelable);
48 | }
49 |
50 | @SuppressWarnings("unused")
51 | public static final Parcelable.Creator CREATOR =
52 | new Parcelable.Creator() {
53 | @Override
54 | public ComplexParcelable createFromParcel(Parcel in) {
55 | return new ComplexParcelable(in);
56 | }
57 |
58 | @Override
59 | public ComplexParcelable[] newArray(int size) {
60 | return new ComplexParcelable[size];
61 | }
62 | };
63 |
64 | @Override public String toString() {
65 | return "A parcelable with another parcelable.\n" + parcelable;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/java/com/f2prateek/dart/model/SimpleParcelable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.model;
19 |
20 | import android.os.Parcel;
21 | import android.os.Parcelable;
22 | import java.util.Random;
23 |
24 | // A parcelable of primitives
25 | public class SimpleParcelable implements Parcelable {
26 |
27 | int anInt;
28 | boolean aBoolean;
29 | float aFloat;
30 |
31 | public SimpleParcelable(int anInt, boolean aBoolean, float aFloat) {
32 | this.anInt = anInt;
33 | this.aBoolean = aBoolean;
34 | this.aFloat = aFloat;
35 | }
36 |
37 | static SimpleParcelable random() {
38 | Random random = new Random();
39 | int anInt = random.nextInt();
40 | boolean aBoolean = random.nextBoolean();
41 | float aFloat = random.nextFloat();
42 | return new SimpleParcelable(anInt, aBoolean, aFloat);
43 | }
44 |
45 | protected SimpleParcelable(Parcel in) {
46 | anInt = in.readInt();
47 | aBoolean = in.readByte() != 0x00;
48 | aFloat = in.readFloat();
49 | }
50 |
51 | @Override
52 | public int describeContents() {
53 | return 0;
54 | }
55 |
56 | @Override
57 | public void writeToParcel(Parcel dest, int flags) {
58 | dest.writeInt(anInt);
59 | dest.writeByte((byte) (aBoolean ? 0x01 : 0x00));
60 | dest.writeFloat(aFloat);
61 | }
62 |
63 | @SuppressWarnings("unused")
64 | public static final Parcelable.Creator CREATOR =
65 | new Parcelable.Creator() {
66 | @Override
67 | public SimpleParcelable createFromParcel(Parcel in) {
68 | return new SimpleParcelable(in);
69 | }
70 |
71 | @Override
72 | public SimpleParcelable[] newArray(int size) {
73 | return new SimpleParcelable[size];
74 | }
75 | };
76 |
77 | @Override public String toString() {
78 | return "A parcelable with " + anInt + ", " + aBoolean + " and " + aFloat;
79 | }
80 | }
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/java/com/f2prateek/dart/model/StringParcel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.model;
19 |
20 | import org.parceler.Parcel;
21 | import org.parceler.ParcelConstructor;
22 |
23 | @Parcel
24 | public class StringParcel {
25 |
26 | String name;
27 |
28 | @ParcelConstructor
29 | public StringParcel(String name) {
30 | this.name = name;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/java/com/f2prateek/dart/module1/Module1ActivityNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.module1;
19 |
20 | import android.support.annotation.Nullable;
21 | import android.util.SparseArray;
22 | import com.f2prateek.dart.model.ComplexParcelable;
23 | import com.f2prateek.dart.model.StringParcel;
24 | import dart.BindExtra;
25 | import java.util.List;
26 |
27 | public class Module1ActivityNavigationModel {
28 |
29 | public static final String DEFAULT_EXTRA_VALUE = "a default value";
30 |
31 | private static final String EXTRA_STRING = "extraString";
32 | private static final String EXTRA_INT = "extraInt";
33 | private static final String EXTRA_PARCELABLE = "extraParcelable";
34 | private static final String EXTRA_PARCEL = "extraParcel";
35 | private static final String EXTRA_LIST_PARCELABLE = "extraListParcelable";
36 | private static final String EXTRA_SPARSE_ARRAY_PARCELABLE = "extraSparseArrayParcelable";
37 | private static final String EXTRA_OPTIONAL = "extraOptional";
38 | private static final String EXTRA_WITH_DEFAULT = "extraWithDefault";
39 |
40 | public @BindExtra(EXTRA_STRING) String stringExtra;
41 | public @BindExtra(EXTRA_INT) int intExtra;
42 | public @BindExtra(EXTRA_PARCELABLE) ComplexParcelable parcelableExtra;
43 | public @BindExtra(EXTRA_PARCEL) StringParcel parcelExtra;
44 | public @BindExtra(EXTRA_LIST_PARCELABLE) List listParcelExtra;
45 | public @BindExtra(EXTRA_SPARSE_ARRAY_PARCELABLE) SparseArray sparseArrayParcelExtra;
46 | public @BindExtra(EXTRA_OPTIONAL) @Nullable String optionalExtra;
47 | public @BindExtra(EXTRA_WITH_DEFAULT) @Nullable String defaultExtra = DEFAULT_EXTRA_VALUE;
48 | public @BindExtra String defaultKeyExtra;
49 | }
50 |
--------------------------------------------------------------------------------
/dart-sample/module1-navigation/src/main/java/com/f2prateek/dart/module1/Module1ServiceNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.module1;
19 |
20 | import dart.BindExtra;
21 |
22 | public class Module1ServiceNavigationModel {
23 |
24 | @BindExtra String stringExtra;
25 | }
26 |
--------------------------------------------------------------------------------
/dart-sample/module1/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | //this is used for development of the plugin
4 | mavenLocal()
5 | jcenter()
6 | google()
7 | }
8 |
9 | dependencies {
10 | classpath deps.dart.gradlePlugin
11 | }
12 |
13 | //this is used for development of the plugin
14 | configurations.classpath {
15 | resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
16 | }
17 | }
18 |
19 | apply plugin: 'com.android.library'
20 | apply plugin: 'com.jakewharton.butterknife'
21 | apply plugin: 'dart.henson-plugin'
22 |
23 |
24 | android {
25 | compileSdkVersion versions.compileSdk
26 |
27 | defaultConfig {
28 | minSdkVersion versions.minSdk
29 | }
30 |
31 | lintOptions {
32 | abortOnError false
33 | }
34 | }
35 |
36 | dependencies {
37 | api project(':module1-navigation')
38 | api deps.android.appCompat
39 | api deps.dart.annotations
40 | api deps.dart.runtime
41 | api deps.henson.runtime
42 | api deps.butterknife.runtime
43 | api deps.butterknife.annotations
44 |
45 | annotationProcessor deps.butterknife.compiler
46 | annotationProcessor deps.dart.compiler
47 | }
48 |
49 | henson {
50 | navigatorPackageName = 'com.f2prateek.dart.sample'
51 | }
52 |
--------------------------------------------------------------------------------
/dart-sample/module1/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
7 |
8 |
10 |
11 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/dart-sample/module1/src/main/java/com/f2prateek/dart/module1/Module1Activity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.module1;
19 |
20 | import android.app.Activity;
21 | import android.os.Bundle;
22 | import android.widget.TextView;
23 | import butterknife.ButterKnife;
24 | import butterknife.BindView;
25 | import dart.Dart;
26 | import dart.DartModel;
27 |
28 | public class Module1Activity extends Activity {
29 |
30 | @BindView(R2.id.default_key_extra) TextView defaultKeyExtraTextView;
31 | @BindView(R2.id.string_extra) TextView stringExtraTextView;
32 | @BindView(R2.id.int_extra) TextView intExtraTextView;
33 | @BindView(R2.id.parcelable_extra) TextView parcelableExtraTextView;
34 | @BindView(R2.id.optional_extra) TextView optionalExtraTextView;
35 | @BindView(R2.id.parcel_extra) TextView parcelExtraTextView;
36 | @BindView(R2.id.list_parcel_extra) TextView listParcelExtraTextView;
37 | @BindView(R2.id.sparse_array_parcel_extra) TextView sparseArrayParcelExtraTextView;
38 | @BindView(R2.id.default_extra) TextView defaultExtraTextView;
39 |
40 | @DartModel Module1ActivityNavigationModel navigationModel;
41 |
42 | @Override protected void onCreate(Bundle savedInstanceState) {
43 | super.onCreate(savedInstanceState);
44 | setContentView(R.layout.activity_navigation);
45 |
46 | ButterKnife.bind(this);
47 | Dart.bind(this);
48 |
49 | // Contrived code to use the "bound" extras.
50 | stringExtraTextView.setText(navigationModel.stringExtra);
51 | intExtraTextView.setText(String.valueOf(navigationModel.intExtra));
52 | parcelableExtraTextView.setText(String.valueOf(navigationModel.parcelableExtra));
53 | optionalExtraTextView.setText(String.valueOf(navigationModel.optionalExtra));
54 | parcelExtraTextView.setText(String.valueOf(navigationModel.parcelExtra.getName()));
55 | listParcelExtraTextView.setText(String.valueOf(navigationModel.listParcelExtra.size()));
56 | sparseArrayParcelExtraTextView.setText(
57 | String.valueOf(navigationModel.sparseArrayParcelExtra.size()));
58 | defaultExtraTextView.setText(String.valueOf(navigationModel.defaultExtra));
59 | defaultKeyExtraTextView.setText(navigationModel.defaultKeyExtra);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/dart-sample/module1/src/main/java/com/f2prateek/dart/module1/Module1Service.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.f2prateek.dart.module1;
19 |
20 | import android.app.IntentService;
21 | import android.content.Intent;
22 | import android.util.Log;
23 | import dart.Dart;
24 |
25 | public class Module1Service extends IntentService {
26 |
27 | // We need to instantiate the navigation model for services.
28 | // The reason for this is that for activities and fragments Dart.bind(Activity/Fragment)
29 | // knows how to get intent or the arguments that the navigation model will be bound to.
30 | // In this case, Dart.bind will handle the creation of the navigation model instance.
31 | // In the case of a service, we cannot access the intent from the service, so we need
32 | // to use Dart.bindNavigationModel so we can pass the extras and it requires an instance
33 | // of the navigation model.
34 | private Module1ServiceNavigationModel navigationModel = new Module1ServiceNavigationModel();
35 |
36 | public Module1Service() {
37 | super("Module1Service");
38 | }
39 |
40 | @Override protected void onHandleIntent(Intent intent) {
41 | Dart.bindNavigationModel(navigationModel, intent.getExtras());
42 | Log.d("DH3", String.format("Module1Service onHandleIntent called with extra: %s", navigationModel.stringExtra));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/dart-sample/module1/src/main/res/layout/activity_navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
25 |
32 |
39 |
46 |
53 |
60 |
67 |
74 |
81 |
88 |
89 |
--------------------------------------------------------------------------------
/dart-sample/module1/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
21 | Dart
22 | Module1 Activity
23 |
24 |
--------------------------------------------------------------------------------
/dart-sample/settings.gradle:
--------------------------------------------------------------------------------
1 | // Dart sample with two modules
2 | include 'app'
3 | include 'app-navigation'
4 | include 'module1'
5 | include 'module1-navigation'
6 |
7 | rootProject.name = 'dart-sample'
8 |
9 | includeBuild '..'
10 |
--------------------------------------------------------------------------------
/dart/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_8
5 | targetCompatibility = JavaVersion.VERSION_1_8
6 |
7 |
8 | dependencies {
9 | implementation project(':dart-annotations')
10 | implementation project(':dart-common')
11 | compileOnly deps.android.runtime
12 |
13 | testImplementation deps.android.runtime
14 | testImplementation deps.junit
15 | testImplementation deps.fest
16 | testImplementation deps.robolectric
17 | }
18 |
--------------------------------------------------------------------------------
/dart/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=dart
2 | POM_NAME=Dart
3 | POM_PACKAGING=jar
--------------------------------------------------------------------------------
/dart/src/test/java/dart/DartTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart;
19 |
20 | import static dart.Dart.EXTRA_BINDERS;
21 | import static dart.Dart.NAVIGATION_MODEL_BINDERS;
22 | import static dart.Dart.NO_OP;
23 | import static dart.Dart.bind;
24 | import static dart.Dart.bindNavigationModel;
25 | import static org.fest.assertions.api.Assertions.assertThat;
26 | import static org.fest.assertions.api.Assertions.entry;
27 |
28 | import android.app.Activity;
29 | import org.junit.After;
30 | import org.junit.Before;
31 | import org.junit.Test;
32 | import org.junit.runner.RunWith;
33 | import org.robolectric.RobolectricTestRunner;
34 | import org.robolectric.annotation.Config;
35 |
36 | @RunWith(RobolectricTestRunner.class)
37 | @Config(manifest = Config.NONE)
38 | public class DartTest {
39 | @Before
40 | @After // Clear out cache of biners before and after each test.
41 | public void resetExtrasCache() {
42 | EXTRA_BINDERS.clear();
43 | NAVIGATION_MODEL_BINDERS.clear();
44 | }
45 |
46 | @Test
47 | public void zeroInjectionsInjectDoesNotThrowException() {
48 | class Example {}
49 |
50 | Example example = new Example();
51 | bind(example, null);
52 | bindNavigationModel(example, null, null);
53 | assertThat(EXTRA_BINDERS).contains(entry(Example.class, NO_OP));
54 | assertThat(NAVIGATION_MODEL_BINDERS).contains(entry(Example.class, NO_OP));
55 | }
56 |
57 | @Test
58 | public void bindingKnownPackagesIsNoOp() {
59 | bind(new Activity());
60 | bindNavigationModel(new Object(), new Activity());
61 | assertThat(EXTRA_BINDERS).isEmpty();
62 | assertThat(NAVIGATION_MODEL_BINDERS).isEmpty();
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.f2prateek.dart
2 | VERSION_NAME=3.1.4-SNAPSHOT
3 |
4 | POM_DESCRIPTION=Extras bindings for Android.
5 |
6 | POM_URL=https://github.com/f2prateek/dart
7 | POM_SCM_URL=https://github.com/f2prateek/dart
8 | POM_SCM_CONNECTION=scm:git:git://github.com/f2prateek/dart.git
9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com:f2prateek/dart.git
10 |
11 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
12 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
13 | POM_LICENCE_DIST=repo
14 |
15 | POM_DEVELOPER_ID=f2prateek
16 | POM_DEVELOPER_NAME=Prateek Srivastava
17 |
18 | org.gradle.jvmargs=-Xmx1536M
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/f2prateek/dart/ce582c1a217c436bb93924004dc1f5b1fe04f1e0/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Dec 06 17:59:39 PST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/henson-plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'groovy'
2 | apply plugin: 'java-library'
3 | apply plugin: 'java-gradle-plugin'
4 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
5 |
6 | sourceCompatibility = 1.8
7 | targetCompatibility = 1.8
8 |
9 | sourceSets {
10 | functionalTest {
11 | groovy.srcDir file('src/functTest/groovy')
12 | resources.srcDir file('src/functTest/resources')
13 | compileClasspath += sourceSets.main.output + configurations.testRuntime
14 | runtimeClasspath += output + compileClasspath
15 | }
16 | }
17 |
18 | gradlePlugin {
19 | plugins {
20 | hensonPlugin {
21 | id = 'dart.henson-plugin'
22 | implementationClass = 'dart.henson.plugin.HensonPlugin'
23 | }
24 | }
25 | testSourceSets sourceSets.functionalTest
26 | }
27 |
28 | task functionalTest(type: Test) {
29 | description = 'Runs the functional tests.'
30 | group = 'verification'
31 | testClassesDirs = sourceSets.functionalTest.output.classesDirs
32 | classpath = sourceSets.functionalTest.runtimeClasspath
33 | mustRunAfter test
34 | }
35 |
36 | check.dependsOn functionalTest
37 |
38 | project.afterEvaluate {
39 | tasks.getByName('compileGroovy').doFirst {
40 | //we create a file in the plugin project containing the current project version
41 | //it will be used later by the plugin to add the proper version of
42 | //dependencies to the project that uses the plugin
43 | def prop = new Properties()
44 | def propFile = new File("${project.rootDir}/henson-plugin/src/main/resources/build.properties")
45 | propFile.parentFile.mkdirs()
46 | prop.setProperty("dart.version", "$version")
47 | propFile.createNewFile()
48 | prop.store(propFile.newWriter(), null)
49 | }
50 | }
51 |
52 | repositories {
53 | jcenter()
54 | google()
55 | mavenLocal()
56 | }
57 |
58 | dependencies {
59 | compile localGroovy()
60 | implementation 'com.android.tools.build:gradle:3.3.0'
61 |
62 | functionalTestCompile('org.spockframework:spock-core:1.1-groovy-2.4') {
63 | exclude group: 'org.codehaus.groovy'
64 | }
65 | functionalTestCompile gradleTestKit()
66 |
67 | testImplementation 'junit:junit:4.12'
68 | }
69 |
--------------------------------------------------------------------------------
/henson-plugin/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=henson-plugin
2 | POM_NAME=Henson Gradle Plugin
3 | POM_PACKAGING=jar
--------------------------------------------------------------------------------
/henson-plugin/src/main/groovy/dart/henson/plugin/HensonPlugin.groovy:
--------------------------------------------------------------------------------
1 | package dart.henson.plugin
2 |
3 | import com.android.build.gradle.AppPlugin
4 | import com.android.build.gradle.DynamicFeaturePlugin
5 | import com.android.build.gradle.LibraryPlugin
6 | import com.android.build.gradle.api.BaseVariant
7 | import dart.henson.plugin.internal.GenerateHensonNavigatorTask
8 | import org.gradle.api.DomainObjectSet
9 | import org.gradle.api.Plugin
10 | import org.gradle.api.Project
11 | import org.gradle.api.plugins.PluginCollection
12 | import org.gradle.api.tasks.TaskProvider
13 |
14 | class HensonPlugin implements Plugin {
15 |
16 | private HensonManager hensonManager
17 |
18 | void apply(Project project) {
19 |
20 | //the extension is created but will be read only during execution time
21 | //(it's not available before)
22 | project.extensions.create('henson', HensonPluginExtension)
23 |
24 |
25 | //check project
26 | def hasAppPlugin = project.plugins.withType(AppPlugin)
27 | def hasLibPlugin = project.plugins.withType(LibraryPlugin)
28 | def hasDynamicFeaturePlugin = project.plugins.withType(DynamicFeaturePlugin)
29 | checkProject(hasAppPlugin, hasLibPlugin, hasDynamicFeaturePlugin)
30 |
31 | hensonManager = new HensonManager(project)
32 |
33 | //we use the file build.properties that contains the version of
34 | //the dart & henson version to use. This avoids all problems related to using version x.y.+
35 | def dartVersionName = getVersionName()
36 |
37 | hensonManager.addDartAndHensonDependenciesToVariantConfigurations(dartVersionName)
38 |
39 | //for all android variants, we create a task to generate a henson navigator.
40 | final DomainObjectSet extends BaseVariant> variants = getAndroidVariants(project)
41 | variants.all { variant ->
42 | File destinationFolder =
43 | project.file(
44 | new File(project.getBuildDir(), "generated/source/navigator/" + variant.getName()))
45 | TaskProvider navigatorTask = hensonManager
46 | .createHensonNavigatorGenerationTask(variant, destinationFolder)
47 |
48 | variant.registerJavaGeneratingTask(navigatorTask.get(), destinationFolder)
49 | project.logger.debug("${navigatorTask.name} registered as Java Generating task")
50 | }
51 | }
52 |
53 | private Object getVersionName() {
54 | Properties properties = new Properties()
55 | properties.load(getClass().getClassLoader().getResourceAsStream("build.properties"))
56 | properties.get("dart.version")
57 | }
58 |
59 | private DomainObjectSet extends BaseVariant> getAndroidVariants(Project project) {
60 | def hasLib = project.plugins.withType(LibraryPlugin)
61 | if (hasLib) {
62 | project.android.libraryVariants
63 | } else {
64 | project.android.applicationVariants
65 | }
66 | }
67 |
68 | private boolean checkProject(PluginCollection hasApp,
69 | PluginCollection hasLib,
70 | PluginCollection hasDynamicFeature) {
71 | if (!hasApp && !hasLib && !hasDynamicFeature) {
72 | throw new IllegalStateException("'android' or 'android-library' or 'dynamic-feature' plugin required.")
73 | }
74 | return !hasApp
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/HensonManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin;
19 |
20 | import com.android.build.gradle.api.BaseVariant;
21 | import dart.henson.plugin.internal.DependencyManager;
22 | import dart.henson.plugin.internal.GenerateHensonNavigatorTask;
23 | import dart.henson.plugin.internal.TaskManager;
24 | import java.io.File;
25 | import java.security.InvalidParameterException;
26 | import org.gradle.api.Project;
27 | import org.gradle.api.logging.Logger;
28 | import org.gradle.api.tasks.TaskProvider;
29 |
30 | public class HensonManager {
31 | private final Project project;
32 | private final Logger logger;
33 | private final TaskManager taskManager;
34 | private final DependencyManager dependencyManager;
35 | private final HensonPluginExtension hensonExtension;
36 |
37 | public HensonManager(Project project) {
38 | this.project = project;
39 | this.logger = project.getLogger();
40 | this.taskManager = new TaskManager(project, logger);
41 | this.dependencyManager = new DependencyManager(project, logger);
42 | this.hensonExtension = (HensonPluginExtension) project.getExtensions().getByName("henson");
43 | }
44 |
45 | public TaskProvider createHensonNavigatorGenerationTask(
46 | BaseVariant variant, File destinationFolder) {
47 | if (hensonExtension == null || hensonExtension.getNavigatorPackageName() == null) {
48 | throw new InvalidParameterException(
49 | "The property 'henson.navigatorPackageName' must be defined in your build.gradle");
50 | }
51 | String hensonNavigatorPackageName = hensonExtension.getNavigatorPackageName();
52 | TaskProvider generateHensonNavigatorTask =
53 | taskManager.createHensonNavigatorGenerationTask(
54 | variant, hensonNavigatorPackageName, destinationFolder);
55 | return generateHensonNavigatorTask;
56 | }
57 |
58 | public void addDartAndHensonDependenciesToVariantConfigurations(String dartVersionName) {
59 | dependencyManager.addDartAndHensonDependenciesToVariantConfigurations(dartVersionName);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/HensonPluginExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin;
19 |
20 | public class HensonPluginExtension {
21 | private String navigatorPackageName;
22 | private boolean navigatorOnly;
23 |
24 | public String getNavigatorPackageName() {
25 | return navigatorPackageName;
26 | }
27 |
28 | public void setNavigatorPackageName(String navigatorPackageName) {
29 | this.navigatorPackageName = navigatorPackageName;
30 | }
31 |
32 | public boolean isNavigatorOnly() {
33 | return navigatorOnly;
34 | }
35 |
36 | public void setNavigatorOnly(boolean navigatorOnly) {
37 | this.navigatorOnly = navigatorOnly;
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/generator/HensonNavigatorGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin.generator;
19 |
20 | import static java.lang.String.format;
21 |
22 | import java.util.Set;
23 |
24 | public class HensonNavigatorGenerator {
25 |
26 | public String generateHensonNavigatorClass(Set targetActivities, String packageName) {
27 | String packageStatement = "package " + packageName + ";\n";
28 |
29 | StringBuilder importStatement = new StringBuilder("import android.content.Context;\n");
30 | targetActivities
31 | .stream()
32 | .forEach(
33 | targetActivity -> {
34 | importStatement.append(format("import %s__IntentBuilder;\n", targetActivity));
35 | });
36 |
37 | String classStartStatement = "public class HensonNavigator {\n";
38 | StringBuilder methodStatement = new StringBuilder();
39 | targetActivities
40 | .stream()
41 | .forEach(
42 | targetActivity -> {
43 | String targetActivitySimpleName =
44 | targetActivity.substring(
45 | 1 + targetActivity.lastIndexOf('.'), targetActivity.length());
46 | String targetActivityCapitalizedName =
47 | dart.henson.plugin.util.StringUtil.capitalize(targetActivitySimpleName);
48 | methodStatement.append(
49 | format(
50 | " public static %s__IntentBuilder.InitialState goto%s(Context context) {\n",
51 | targetActivityCapitalizedName,
52 | targetActivityCapitalizedName,
53 | targetActivityCapitalizedName));
54 | methodStatement.append(
55 | format(
56 | " return %s__IntentBuilder.getInitialState(context);\n",
57 | targetActivityCapitalizedName));
58 | methodStatement.append(" }\n");
59 | });
60 | String classEndStatement = "}\n";
61 | return new StringBuilder()
62 | .append(packageStatement)
63 | .append(importStatement)
64 | .append(classStartStatement)
65 | .append(methodStatement)
66 | .append(classEndStatement)
67 | .toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/internal/DependencyManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin.internal;
19 |
20 | import static java.lang.String.format;
21 |
22 | import org.gradle.api.Project;
23 | import org.gradle.api.artifacts.dsl.DependencyHandler;
24 | import org.gradle.api.logging.Logger;
25 |
26 | public class DependencyManager {
27 |
28 | private Project project;
29 | private Logger logger;
30 |
31 | public DependencyManager(Project project, Logger logger) {
32 | this.project = project;
33 | this.logger = logger;
34 | }
35 |
36 | public void addDartAndHensonDependenciesToVariantConfigurations(String dartVersionName) {
37 | DependencyHandler dependencies = project.getDependencies();
38 | dependencies.add("implementation", format("com.f2prateek.dart:henson:%s", dartVersionName));
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/internal/GenerateHensonNavigatorTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin.internal;
19 |
20 | import static com.android.build.gradle.internal.publishing.AndroidArtifacts.ARTIFACT_TYPE;
21 | import static java.util.Collections.singletonList;
22 |
23 | import com.android.build.gradle.api.BaseVariant;
24 | import com.android.build.gradle.internal.publishing.AndroidArtifacts;
25 | import com.google.common.collect.Streams;
26 | import dart.henson.plugin.generator.HensonNavigatorGenerator;
27 | import java.io.File;
28 | import java.io.IOException;
29 | import java.nio.file.Files;
30 | import java.util.ArrayList;
31 | import java.util.Collections;
32 | import java.util.HashSet;
33 | import java.util.List;
34 | import java.util.Set;
35 | import java.util.zip.ZipEntry;
36 | import java.util.zip.ZipFile;
37 | import org.gradle.api.Action;
38 | import org.gradle.api.DefaultTask;
39 | import org.gradle.api.Project;
40 | import org.gradle.api.attributes.AttributeContainer;
41 | import org.gradle.api.file.FileCollection;
42 | import org.gradle.api.internal.file.UnionFileCollection;
43 | import org.gradle.api.logging.Logger;
44 | import org.gradle.api.tasks.CacheableTask;
45 | import org.gradle.api.tasks.Classpath;
46 | import org.gradle.api.tasks.Input;
47 | import org.gradle.api.tasks.InputFiles;
48 | import org.gradle.api.tasks.OutputFile;
49 | import org.gradle.api.tasks.TaskAction;
50 | import org.gradle.api.tasks.TaskProvider;
51 | import org.gradle.api.tasks.compile.JavaCompile;
52 |
53 | @CacheableTask
54 | public class GenerateHensonNavigatorTask extends DefaultTask {
55 | @InputFiles
56 | @Classpath
57 | FileCollection getJarDependencies() {
58 | //Thanks to Xavier Durcrohet for this
59 | //https://android.googlesource.com/platform/tools/base/+/gradle_3.0.0/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/scope/VariantScopeImpl.java#1037
60 | Action attributes =
61 | container ->
62 | container.attribute(ARTIFACT_TYPE, AndroidArtifacts.ArtifactType.CLASSES.getType());
63 | boolean lenientMode = false;
64 | return variant
65 | .getCompileConfiguration()
66 | .getIncoming()
67 | .artifactView(
68 | config -> {
69 | config.attributes(attributes);
70 | config.lenient(lenientMode);
71 | })
72 | .getArtifacts()
73 | .getArtifactFiles();
74 | }
75 |
76 | @Input String hensonNavigatorPackageName;
77 |
78 | File destinationFolder;
79 |
80 | @OutputFile
81 | public File getHensonNavigatorSourceFile() {
82 | String generatedFolderName = hensonNavigatorPackageName.replace('.', '/').concat("/");
83 | File generatedFolder = new File(destinationFolder, generatedFolderName);
84 | generatedFolder.mkdirs();
85 | return new File(generatedFolder, "HensonNavigator.java");
86 | }
87 |
88 | BaseVariant variant;
89 | Project project;
90 | Logger logger;
91 | HensonNavigatorGenerator hensonNavigatorGenerator;
92 |
93 | @TaskAction
94 | public void generateHensonNavigator() {
95 | TaskProvider javaCompiler = variant.getJavaCompileProvider();
96 | FileCollection variantCompileClasspath = getJarDependencies();
97 | FileCollection uft =
98 | new UnionFileCollection(
99 | javaCompiler.get().getSource(), project.fileTree(destinationFolder));
100 | javaCompiler.get().setSource(uft);
101 | logger.debug("Analyzing configuration: " + variantCompileClasspath.getFiles());
102 | Set targetActivities = new HashSet<>();
103 | Streams.stream(variantCompileClasspath)
104 | .forEach(
105 | dependency -> {
106 | logger.debug("Detected dependency: {}", dependency.getAbsolutePath());
107 | if (dependency.getName().endsWith(".jar")) {
108 | logger.debug("Detected navigation API dependency: {}", dependency.getName());
109 | if (!dependency.exists()) {
110 | logger.debug("Dependency jar doesn't exist {}", dependency.getAbsolutePath());
111 | } else {
112 | File file = dependency.getAbsoluteFile();
113 | List entries = getJarContent(file);
114 | entries.forEach(
115 | entry -> {
116 | if (entry.matches(".*__IntentBuilder.class")) {
117 | logger.debug("Detected intent builder: {}", entry);
118 | String targetActivityFQN =
119 | entry
120 | .substring(0, entry.length() - "__IntentBuilder.class".length())
121 | .replace('/', '.');
122 | targetActivities.add(targetActivityFQN);
123 | }
124 | });
125 | }
126 | }
127 | });
128 | String hensonNavigator =
129 | hensonNavigatorGenerator.generateHensonNavigatorClass(
130 | targetActivities, hensonNavigatorPackageName);
131 | destinationFolder.mkdirs();
132 | String generatedFolderName = hensonNavigatorPackageName.replace('.', '/').concat("/");
133 | File generatedFolder = new File(destinationFolder, generatedFolderName);
134 | generatedFolder.mkdirs();
135 | File generatedFile = getHensonNavigatorSourceFile();
136 | try {
137 | logger.debug("Generating Henson navigator in " + generatedFile.getAbsolutePath());
138 | logger.debug(hensonNavigator);
139 | Files.write(generatedFile.toPath(), singletonList(hensonNavigator));
140 | } catch (IOException e) {
141 | throw new RuntimeException(e);
142 | }
143 | }
144 |
145 | private List getJarContent(File file) {
146 | final List result = new ArrayList<>();
147 | try {
148 | if (file.getName().endsWith(".jar")) {
149 | ZipFile zip = new ZipFile(file);
150 | Collections.list(zip.entries()).stream().map(ZipEntry::getName).forEach(result::add);
151 | }
152 | } catch (IOException e) {
153 | throw new RuntimeException(e);
154 | }
155 | return result;
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/internal/TaskManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin.internal;
19 |
20 | import static dart.henson.plugin.util.StringUtil.capitalize;
21 |
22 | import com.android.build.gradle.api.BaseVariant;
23 | import dart.henson.plugin.generator.HensonNavigatorGenerator;
24 | import java.io.File;
25 | import org.gradle.api.Action;
26 | import org.gradle.api.Project;
27 | import org.gradle.api.logging.Logger;
28 | import org.gradle.api.tasks.TaskProvider;
29 |
30 | public class TaskManager {
31 |
32 | private Project project;
33 | private Logger logger;
34 | private HensonNavigatorGenerator hensonNavigatorGenerator;
35 |
36 | public TaskManager(Project project, Logger logger) {
37 | this.project = project;
38 | this.logger = logger;
39 | this.hensonNavigatorGenerator = new HensonNavigatorGenerator();
40 | }
41 |
42 | /**
43 | * A henson navigator is a class that helps a consumer to consume the navigation api that it
44 | * declares in its dependencies. The henson navigator will wrap the intent builders. Thus, a
45 | * henson navigator, is driven by consumption of intent builders, whereas the henson classes are
46 | * driven by the production of an intent builder.
47 | *
48 | * This task is created per android variant:
49 | *
50 | *
51 | * - we scan the variant compile configuration for navigation api dependencies
52 | *
- we generate a henson navigator class for this variant that wraps the intent builders
53 | *
54 | *
55 | * @param variant the variant for which to create a builder.
56 | * @param hensonNavigatorPackageName the package name in which we create the class.
57 | */
58 | public TaskProvider createHensonNavigatorGenerationTask(
59 | BaseVariant variant, String hensonNavigatorPackageName, File destinationFolder) {
60 | TaskProvider generateHensonNavigatorTask =
61 | project
62 | .getTasks()
63 | .register(
64 | "generate" + capitalize(variant.getName()) + "HensonNavigator",
65 | GenerateHensonNavigatorTask.class,
66 | (Action)
67 | generateHensonNavigatorTask1 -> {
68 | generateHensonNavigatorTask1.hensonNavigatorPackageName =
69 | hensonNavigatorPackageName;
70 | generateHensonNavigatorTask1.destinationFolder = destinationFolder;
71 | generateHensonNavigatorTask1.variant = variant;
72 | generateHensonNavigatorTask1.logger = logger;
73 | generateHensonNavigatorTask1.project = project;
74 | generateHensonNavigatorTask1.hensonNavigatorGenerator =
75 | hensonNavigatorGenerator;
76 | });
77 | return generateHensonNavigatorTask;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/java/dart/henson/plugin/util/StringUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.plugin.util;
19 |
20 | public class StringUtil {
21 | public static String capitalize(String original) {
22 | if (original == null || original.length() == 0) {
23 | return original;
24 | }
25 | return original.substring(0, 1).toUpperCase() + original.substring(1);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/henson-plugin/src/main/resources/build.properties:
--------------------------------------------------------------------------------
1 | #Tue Jul 02 10:47:11 PDT 2019
2 | dart.version=3.1.4-SNAPSHOT
3 |
--------------------------------------------------------------------------------
/henson-processor/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_8
5 | targetCompatibility = JavaVersion.VERSION_1_8
6 |
7 |
8 | dependencies {
9 | implementation project(':dart-annotations')
10 | implementation project(':dart-common')
11 | implementation project(':henson')
12 | implementation deps.javapoet
13 | implementation deps.parceler.runtime
14 | compileOnly deps.android.runtime
15 |
16 | testImplementation files(org.gradle.internal.jvm.Jvm.current().getToolsJar())
17 | testImplementation deps.junit
18 | testImplementation deps.compiletesting
19 | testImplementation deps.truth
20 | testImplementation deps.fest
21 | testImplementation deps.android.runtime
22 | }
23 |
--------------------------------------------------------------------------------
/henson-processor/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=henson-processor
2 | POM_NAME=Henson Annotation Processor
3 | POM_PACKAGING=jar
--------------------------------------------------------------------------------
/henson-processor/src/main/java/dart/henson/processor/IntentBuilderProcessor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.processor;
19 |
20 | import dart.common.ExtraBindingTarget;
21 | import dart.common.util.BindExtraUtil;
22 | import dart.common.util.CompilerUtil;
23 | import dart.common.util.DartModelUtil;
24 | import dart.common.util.ExtraBindingTargetUtil;
25 | import dart.common.util.FileUtil;
26 | import dart.common.util.LoggingUtil;
27 | import dart.common.util.ParcelerUtil;
28 | import java.io.IOException;
29 | import java.util.HashMap;
30 | import java.util.LinkedHashMap;
31 | import java.util.Map;
32 | import java.util.Set;
33 | import javax.annotation.processing.AbstractProcessor;
34 | import javax.annotation.processing.ProcessingEnvironment;
35 | import javax.annotation.processing.RoundEnvironment;
36 | import javax.annotation.processing.SupportedAnnotationTypes;
37 | import javax.annotation.processing.SupportedOptions;
38 | import javax.lang.model.SourceVersion;
39 | import javax.lang.model.element.TypeElement;
40 |
41 | @SupportedAnnotationTypes({
42 | IntentBuilderProcessor.NAVIGATION_MODEL_ANNOTATION_CLASS_NAME,
43 | IntentBuilderProcessor.EXTRA_ANNOTATION_CLASS_NAME
44 | })
45 | @SupportedOptions({IntentBuilderProcessor.OPTION_HENSON_PACKAGE})
46 | public class IntentBuilderProcessor extends AbstractProcessor {
47 |
48 | static final String NAVIGATION_MODEL_ANNOTATION_CLASS_NAME = "dart.DartModel";
49 | static final String EXTRA_ANNOTATION_CLASS_NAME = "dart.BindExtra";
50 | static final String OPTION_HENSON_PACKAGE = "dart.henson.package";
51 |
52 | private LoggingUtil loggingUtil;
53 | private BindExtraUtil bindExtraUtil;
54 | private FileUtil fileUtil;
55 | private DartModelUtil dartModelUtil;
56 | private ExtraBindingTargetUtil extraBindingTargetUtil;
57 |
58 | private String hensonPackage;
59 | private boolean usesParceler = true;
60 | private Map allRoundsGeneratedToTypeElement = new HashMap<>();
61 |
62 | @Override
63 | public synchronized void init(ProcessingEnvironment processingEnv) {
64 | super.init(processingEnv);
65 |
66 | final CompilerUtil compilerUtil = new CompilerUtil(processingEnv);
67 | final ParcelerUtil parcelerUtil = new ParcelerUtil(compilerUtil, processingEnv, usesParceler);
68 | loggingUtil = new LoggingUtil(processingEnv);
69 | fileUtil = new FileUtil(processingEnv);
70 | extraBindingTargetUtil = new ExtraBindingTargetUtil(compilerUtil, processingEnv, loggingUtil);
71 | dartModelUtil = new DartModelUtil(loggingUtil, extraBindingTargetUtil, compilerUtil);
72 | bindExtraUtil =
73 | new BindExtraUtil(
74 | compilerUtil, parcelerUtil, loggingUtil, extraBindingTargetUtil, dartModelUtil);
75 |
76 | parseAnnotationProcessorOptions(processingEnv);
77 | }
78 |
79 | @Override
80 | public SourceVersion getSupportedSourceVersion() {
81 | return SourceVersion.latestSupported();
82 | }
83 |
84 | @Override
85 | public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
86 | dartModelUtil.setRoundEnvironment(roundEnv);
87 | bindExtraUtil.setRoundEnvironment(roundEnv);
88 |
89 | final Map targetClassMap = findAndParseTargets();
90 | generateIntentBuilders(targetClassMap);
91 |
92 | //return false here to let dart process the annotations too
93 | return false;
94 | }
95 |
96 | /**
97 | * Flag to force enabling/disabling Parceler. Used for testing.
98 | *
99 | * @param enable whether Parceler should be enable
100 | */
101 | public void enableParceler(boolean enable) {
102 | usesParceler = enable;
103 | }
104 |
105 | private void parseAnnotationProcessorOptions(ProcessingEnvironment processingEnv) {
106 | hensonPackage = processingEnv.getOptions().get(OPTION_HENSON_PACKAGE);
107 | }
108 |
109 | private Map findAndParseTargets() {
110 | Map targetClassMap = new LinkedHashMap<>();
111 |
112 | dartModelUtil.parseDartModelAnnotatedTypes(targetClassMap);
113 | bindExtraUtil.parseBindExtraAnnotatedElements(targetClassMap);
114 | extraBindingTargetUtil.createBindingTargetTrees(targetClassMap);
115 | extraBindingTargetUtil.addClosestRequiredAncestorForTargets(targetClassMap);
116 |
117 | return targetClassMap;
118 | }
119 |
120 | private void generateIntentBuilders(Map targetClassMap) {
121 | for (Map.Entry entry : targetClassMap.entrySet()) {
122 | if (entry.getValue().topLevel) {
123 | generateIntentBuildersForTree(targetClassMap, entry.getKey());
124 | }
125 | }
126 | }
127 |
128 | private void generateIntentBuildersForTree(
129 | Map targetClassMap, TypeElement typeElement) {
130 | //we unfortunately can't test that nothing is generated in a TRUTH based test
131 | final ExtraBindingTarget extraBindingTarget = targetClassMap.get(typeElement);
132 | try {
133 | IntentBuilderGenerator generator = new IntentBuilderGenerator(extraBindingTarget);
134 | fileUtil.writeFile(generator, typeElement);
135 | allRoundsGeneratedToTypeElement.put(generator.getFqcn(), typeElement);
136 | } catch (IOException e) {
137 | loggingUtil.error(
138 | typeElement,
139 | "Unable to write intent builder for type %s: %s",
140 | typeElement,
141 | e.getMessage());
142 | }
143 |
144 | for (TypeElement child : extraBindingTarget.childClasses) {
145 | generateIntentBuildersForTree(targetClassMap, child);
146 | }
147 | }
148 |
149 | /*visible for testing*/
150 | TypeElement getOriginatingElement(String generatedQualifiedName) {
151 | return allRoundsGeneratedToTypeElement.get(generatedQualifiedName);
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/henson-processor/src/main/resources/META-INF/gradle/incremental.annotation.processors:
--------------------------------------------------------------------------------
1 | dart.henson.processor.IntentBuilderProcessor,isolating
2 |
--------------------------------------------------------------------------------
/henson-processor/src/main/resources/META-INF/services/javax.annotation.processing.Processor:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2013 Jake Wharton
3 | # Copyright 2014 Prateek Srivastava (@f2prateek)
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 | dart.henson.processor.IntentBuilderProcessor
19 |
--------------------------------------------------------------------------------
/henson-processor/src/test/java/dart/henson/processor/ProcessorTestUtilities.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.processor;
19 |
20 | import javax.lang.model.element.Element;
21 | import javax.lang.model.element.TypeElement;
22 |
23 | public class ProcessorTestUtilities {
24 | static IntentBuilderProcessor hensonProcessor() {
25 | return new IntentBuilderProcessor();
26 | }
27 |
28 | static IntentBuilderProcessor hensonProcessorWithoutParceler() {
29 | IntentBuilderProcessor intentBuilderProcessor = new IntentBuilderProcessor();
30 | intentBuilderProcessor.enableParceler(false);
31 | return intentBuilderProcessor;
32 | }
33 |
34 | static TypeElement getMostEnclosingElement(Element element) {
35 | if (element == null) {
36 | return null;
37 | }
38 |
39 | while (element.getEnclosingElement() != null
40 | && element.getEnclosingElement().getKind().isClass()
41 | || element.getEnclosingElement().getKind().isInterface()) {
42 | element = element.getEnclosingElement();
43 | }
44 | return (TypeElement) element;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/henson-processor/src/test/java/dart/henson/processor/data/ClassWithOptionalExtrasNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.processor.data;
19 |
20 | import dart.BindExtra;
21 |
22 | public class ClassWithOptionalExtrasNavigationModel {
23 | @Nullable @BindExtra String optionalExtra1;
24 | @Nullable @BindExtra String optionalExtra2;
25 | }
26 |
--------------------------------------------------------------------------------
/henson-processor/src/test/java/dart/henson/processor/data/ClassWithRequiredAndOptionalExtrasNavigationModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.processor.data;
19 |
20 | import dart.BindExtra;
21 |
22 | public class ClassWithRequiredAndOptionalExtrasNavigationModel {
23 | @BindExtra String requiredExtra;
24 | @Nullable @BindExtra String optionalExtra;
25 | }
26 |
--------------------------------------------------------------------------------
/henson-processor/src/test/java/dart/henson/processor/data/Nullable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson.processor.data;
19 |
20 | public @interface Nullable {}
21 |
--------------------------------------------------------------------------------
/henson/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java-library'
2 | apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
3 |
4 | sourceCompatibility = JavaVersion.VERSION_1_8
5 | targetCompatibility = JavaVersion.VERSION_1_8
6 |
7 |
8 | dependencies {
9 | compileOnly deps.android.runtime
10 | }
11 |
--------------------------------------------------------------------------------
/henson/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=henson
2 | POM_NAME=Henson
3 | POM_PACKAGING=jar
--------------------------------------------------------------------------------
/henson/src/main/java/dart/henson/ActivityClassFinder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson;
19 |
20 | public class ActivityClassFinder {
21 | public static Class getClassDynamically(String className) {
22 | try {
23 | return Class.forName(className);
24 | } catch (Exception ex) {
25 | throw new RuntimeException(ex);
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/henson/src/main/java/dart/henson/AllRequiredSetState.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson;
19 |
20 | import android.content.Intent;
21 |
22 | public class AllRequiredSetState extends State {
23 | private Intent intent;
24 |
25 | public AllRequiredSetState(Bundler bundler, Intent intent) {
26 | super(bundler);
27 | this.intent = intent;
28 | }
29 |
30 | public Intent build() {
31 | intent.putExtras(bundler.get());
32 | return intent;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/henson/src/main/java/dart/henson/RequiredStateSequence.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson;
19 |
20 | public class RequiredStateSequence extends State {
21 | protected final ALL_REQUIRED_SET_STATE allRequiredSetState;
22 |
23 | public RequiredStateSequence(Bundler bundler, ALL_REQUIRED_SET_STATE allRequiredSetState) {
24 | super(bundler);
25 | this.allRequiredSetState = allRequiredSetState;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/henson/src/main/java/dart/henson/State.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package dart.henson;
19 |
20 | public abstract class State {
21 | protected final Bundler bundler;
22 |
23 | public State(Bundler bundler) {
24 | this.bundler = bundler;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'dart-annotations'
2 | include 'dart-common'
3 | include 'dart'
4 | include 'dart-processor'
5 | include 'henson'
6 | include 'henson-processor'
7 | include 'henson-plugin'
8 |
9 | rootProject.name = 'dart-parent'
10 |
--------------------------------------------------------------------------------
/spotless.license.java.txt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Jake Wharton
3 | * Copyright 2014 Prateek Srivastava (@f2prateek)
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
--------------------------------------------------------------------------------