├── .circleci
└── config.yml
├── .gitignore
├── CHANGELOG.md
├── LICENSE.txt
├── README.md
├── RELEASING.md
├── auto-value-with
├── build.gradle
├── gradle.properties
└── src
│ ├── main
│ └── java
│ │ └── com
│ │ └── gabrielittner
│ │ └── auto
│ │ └── value
│ │ └── with
│ │ ├── AutoValueWithExtension.java
│ │ └── WithMethod.java
│ └── test
│ └── java
│ └── com
│ └── gabrielittner
│ └── auto
│ └── value
│ └── with
│ └── AutoValueWithExtensionTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
└── settings.gradle
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2.1
2 |
3 |
4 | references:
5 | cache_key_gradle_wrapper: &cache_key_gradle_wrapper
6 | key: gradle-wrapper-v1-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
7 | cache_key_android_sdk: &cache_key_android_sdk
8 | key: android-sdk-v1-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build.gradle" }}
9 | cache_key_gradle_cache: &cache_key_gradle_cache
10 | key: gradle-cache-v1-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}-{{ checksum "build.gradle" }}
11 |
12 |
13 | executors:
14 | android:
15 | docker:
16 | - image: gabrielittner/android-sdk:tools-26.1.1-jdk8u222
17 | working_directory: ~/lazythreetenbp
18 | environment:
19 | - GRADLE_OPTS: -Dorg.gradle.jvmargs="-Xmx1536m" -Dorg.gradle.workers.max=2 -Dkotlin.incremental=false
20 |
21 |
22 | commands:
23 | save_gradle_wrapper:
24 | steps:
25 | - save_cache:
26 | name: "Saving Gradle Wrapper to cache"
27 | <<: *cache_key_gradle_wrapper
28 | paths:
29 | - "~/.gradle/wrapper"
30 |
31 | restore_gradle_wrapper:
32 | steps:
33 | - restore_cache:
34 | name: "Restoring Gradle Wrapper from cache"
35 | <<: *cache_key_gradle_wrapper
36 |
37 | save_android_sdk:
38 | steps:
39 | - save_cache:
40 | name: "Saving downloaded Android SDK components to cache"
41 | <<: *cache_key_android_sdk
42 | paths:
43 | #TODO replace ~/android-sdk with $ANDROID_HOME to be less reliant on docker image
44 | - "/android-sdk/build-tools"
45 | - "/android-sdk/platforms"
46 | - "/android-sdk/platform-tools"
47 |
48 | restore_android_sdk:
49 | steps:
50 | - restore_cache:
51 | name: "Restoring downloaded Android SDK components from cache"
52 | <<: *cache_key_android_sdk
53 |
54 | save_gradle_cache:
55 | steps:
56 | - save_cache:
57 | name: "Saving Gradle cache to cache"
58 | <<: *cache_key_gradle_cache
59 | paths:
60 | - "~/.android/build-cache"
61 | - "~/.gradle/caches/"
62 |
63 | restore_gradle_cache:
64 | steps:
65 | - restore_cache:
66 | name: "Restoring Gradle cache from cache"
67 | <<: *cache_key_gradle_cache
68 |
69 | gradle_android_setup:
70 | steps:
71 | - restore_gradle_wrapper
72 | - restore_android_sdk
73 | - restore_gradle_cache
74 | - run:
75 | name: Download Gradle wrapper
76 | command: ./gradlew -v
77 | - save_gradle_wrapper
78 | - run:
79 | name: Download Android SDK components
80 | #TODO https://issuetracker.google.com/issues/64934388
81 | command: ./gradlew help && sdkmanager --list
82 | - save_android_sdk
83 |
84 |
85 | jobs:
86 | build:
87 | executor: android
88 | steps:
89 | - checkout
90 | - gradle_android_setup
91 | - run: ./gradlew build --stacktrace --continue
92 | - save_gradle_cache
93 |
94 | publish_snapshot:
95 | executor: android
96 | steps:
97 | - checkout
98 | - gradle_android_setup
99 | - run: ./gradlew uploadArchives --stacktrace
100 |
101 | workflows:
102 | build:
103 | jobs:
104 | - build
105 |
106 | publish_snapshot:
107 | jobs:
108 | - publish_snapshot:
109 | context: gradle-maven-publish
110 | filters:
111 | branches:
112 | only: main
113 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ IDEA
2 | .idea
3 | *.iml
4 | annotations
5 |
6 | # Gradle
7 | .gradle
8 | gradlew.bat
9 | build
10 | local.properties
11 |
12 | .DS_Store
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.1.1 *(2020-07-17)*
5 | ----------------------------
6 |
7 | #### Supports: AutoValue 1.7.0
8 |
9 | - fix packaging issue
10 |
11 | Version 1.1.0 *(2020-05-03)*
12 | ----------------------------
13 |
14 | #### Supports: AutoValue 1.7.0
15 |
16 | - support incremental annotation processing
17 |
18 | Version 1.1.0-rc1 *(2018-11-04)*
19 | ----------------------------
20 |
21 | #### Supports: AutoValue 1.6.3rc1
22 |
23 | - support incremental annotation processing
24 | - improvements to generated code when AutoValue class is generic
25 |
26 | Version 1.0.0 *(2016-09-09)*
27 | ----------------------------
28 |
29 | #### Supports: AutoValue 1.3
30 |
31 | - support for AutoValue 1.3
32 | - support for with-ers with multiple properties, e.g. `withNameAndEmail(String name, String email)`
33 |
34 | Version 1.0.0-rc1 *(2016-06-13)*
35 | ----------------------------
36 |
37 | #### Supports: AutoValue 1.3-rc1
38 |
39 | - support for AutoValue 1.3-rc1
40 |
41 | Version 0.1.5 *(2016-06-09)*
42 | ----------------------------
43 |
44 | #### Supports: AutoValue 1.2
45 |
46 | - support generic return types for with-ers in interfaces
47 |
48 | Version 0.1.4 *(2016-06-02)*
49 | ----------------------------
50 |
51 | #### Supports: AutoValue 1.2
52 |
53 | - support generic return types for with-ers
54 | - fix duplicate `@Override` annotation in generated code
55 | - improved error reporting
56 | - removed dependency on AutoService
57 |
58 | Version 0.1.3 *(2016-05-06)*
59 | ----------------------------
60 |
61 | #### Supports: AutoValue 1.2
62 |
63 | - fix support for nested AutoValue classes
64 |
65 | Version 0.1.2 *(2016-05-05)*
66 | ----------------------------
67 |
68 | #### Supports: AutoValue 1.2
69 |
70 | - add support for properties prefixed with get` and `is``
71 |
72 | Version 0.1.1 *(2016-04-17)*
73 | ----------------------------
74 |
75 | #### Supports: AutoValue 1.2
76 |
77 | - don't override already implemented with-ers
78 |
79 | Version 0.1.0 *(2016-03-22)*
80 | ----------------------------
81 |
82 | Initial release. Only guaranteed to support AutoValue 1.2-rc1.
83 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutoValue: With Extension
2 |
3 | An extension for Google's [AutoValue][auto] that implements "with-er" methods for AutoValue objects.
4 |
5 | **Note**: This is an early version that requires the extension support currently in AutoValue 1.2-SNAPSHOT.
6 |
7 | ## Usage
8 |
9 | Include auto-value-with in your project and "with-er" methods to your auto-value objects.
10 |
11 | ```java
12 | @AutoValue public abstract class User {
13 | abstract String id();
14 | abstract String name();
15 | abstract String email();
16 |
17 | abstract User withEmail(String email);
18 |
19 | // you can also use multiple
20 | abstract User withNameAndEmail(String name, String email);
21 | }
22 | ```
23 |
24 | The extension will generate an implementation of `withEmail(String)` that returns a new instance of `User` with the given email.
25 |
26 |
27 | By convention "with-er" methods have to use `with` as prefix and use the exact property name for both method name and parameter name.
28 |
29 |
30 |
31 | ## Download
32 |
33 | Add a Gradle dependency:
34 |
35 | ```groovy
36 | annotationProcessor 'com.gabrielittner.auto.value:auto-value-with:1.1.1'
37 | ```
38 |
39 | or Maven:
40 | ```xml
41 |
42 | com.gabrielittner.auto.value
43 | auto-value-with
44 | 1.1.1
45 | provided
46 |
47 | ```
48 |
49 | Snapshots of the development version are available in [Sonatype's `snapshots` repository][snap].
50 |
51 | ## License
52 |
53 |
54 | ```
55 | Copyright 2016 Gabriel Ittner.
56 |
57 | Licensed under the Apache License, Version 2.0 (the "License");
58 | you may not use this file except in compliance with the License.
59 | You may obtain a copy of the License at
60 |
61 | http://www.apache.org/licenses/LICENSE-2.0
62 |
63 | Unless required by applicable law or agreed to in writing, software
64 | distributed under the License is distributed on an "AS IS" BASIS,
65 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
66 | See the License for the specific language governing permissions and
67 | limitations under the License.
68 | ```
69 |
70 |
71 |
72 | [auto]: https://github.com/google/auto
73 | [snap]: https://oss.sonatype.org/content/repositories/snapshots/
74 |
--------------------------------------------------------------------------------
/RELEASING.md:
--------------------------------------------------------------------------------
1 | Releasing
2 | ========
3 |
4 | 1. Change the version in `gradle.properties` to a non-SNAPSHOT version.
5 | 2. Update the `CHANGELOG.md` for the impending release.
6 | 3. Update the `README.md` with the new version.
7 | 4. `git commit -am "Prepare for release X.Y.Z."` (where X.Y.Z is the new version)
8 | 5. `./gradlew clean uploadArchives`.
9 | 6. Visit [Sonatype Nexus](https://oss.sonatype.org/) and promote the artifact.
10 | 7. `git tag -a X.Y.X -m "Version X.Y.Z"` (where X.Y.Z is the new version)
11 | 8. Update the `gradle.properties` to the next SNAPSHOT version.
12 | 9. `git commit -am "Prepare next development version."`
13 | 10. `git push && git push --tags`
14 |
15 | If step 5 or 6 fails, drop the Sonatype repo, fix the problem, commit, and start again at step 5.
--------------------------------------------------------------------------------
/auto-value-with/build.gradle:
--------------------------------------------------------------------------------
1 | import org.gradle.internal.jvm.Jvm
2 |
3 | apply plugin: 'java-library'
4 | apply plugin: 'com.vanniktech.maven.publish'
5 |
6 | sourceCompatibility = rootProject.ext.javaVersion
7 | targetCompatibility = rootProject.ext.javaVersion
8 |
9 | dependencies {
10 | api deps.auto_value
11 | implementation deps.javapoet
12 | implementation deps.guava
13 | implementation deps.auto_common
14 | implementation deps.auto_ext_util
15 |
16 | compileOnly deps.auto_service_annotations
17 | annotationProcessor deps.auto_service
18 |
19 | testImplementation deps.junit
20 | testImplementation deps.truth
21 | testImplementation deps.compile_testing
22 | testImplementation files(Jvm.current().getToolsJar())
23 | testImplementation deps.jsr305
24 | }
25 |
--------------------------------------------------------------------------------
/auto-value-with/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_ARTIFACT_ID=auto-value-with
2 | POM_NAME=AutoValue: With Extension
3 | POM_PACKAGING=jar
4 |
--------------------------------------------------------------------------------
/auto-value-with/src/main/java/com/gabrielittner/auto/value/with/AutoValueWithExtension.java:
--------------------------------------------------------------------------------
1 | package com.gabrielittner.auto.value.with;
2 |
3 | import com.gabrielittner.auto.value.util.Property;
4 | import com.google.auto.service.AutoService;
5 | import com.google.auto.value.extension.AutoValueExtension;
6 | import com.google.common.collect.ImmutableList;
7 | import com.squareup.javapoet.AnnotationSpec;
8 | import com.squareup.javapoet.JavaFile;
9 | import com.squareup.javapoet.MethodSpec;
10 | import com.squareup.javapoet.ParameterSpec;
11 | import com.squareup.javapoet.TypeSpec;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import java.util.Set;
15 | import javax.annotation.processing.ProcessingEnvironment;
16 | import javax.lang.model.element.AnnotationMirror;
17 | import javax.lang.model.element.ExecutableElement;
18 | import javax.lang.model.element.Modifier;
19 |
20 | import static com.gabrielittner.auto.value.util.AutoValueUtil.getAutoValueClassTypeName;
21 | import static com.gabrielittner.auto.value.util.AutoValueUtil.newFinalClassConstructorCall;
22 | import static com.gabrielittner.auto.value.util.AutoValueUtil.newTypeSpecBuilder;
23 | import static javax.lang.model.element.Modifier.FINAL;
24 |
25 | @AutoService(AutoValueExtension.class)
26 | public class AutoValueWithExtension extends AutoValueExtension {
27 |
28 | @Override
29 | public boolean applicable(Context context) {
30 | return WithMethod.filteredAbstractMethods(context).size() > 0;
31 | }
32 |
33 | @Override
34 | public IncrementalExtensionType incrementalType(ProcessingEnvironment processingEnvironment) {
35 | return IncrementalExtensionType.ISOLATING;
36 | }
37 |
38 | @Override
39 | public Set consumeMethods(Context context) {
40 | return WithMethod.filteredAbstractMethods(context);
41 | }
42 |
43 | @Override
44 | public String generateClass(
45 | Context context, String className, String classToExtend, boolean isFinal) {
46 | TypeSpec subclass =
47 | newTypeSpecBuilder(context, className, classToExtend, isFinal)
48 | .addMethods(generateWithMethods(context))
49 | .build();
50 |
51 | return JavaFile.builder(context.packageName(), subclass).build().toString();
52 | }
53 |
54 | private List generateWithMethods(Context context) {
55 | List withMethods = WithMethod.getWithMethods(context);
56 | ImmutableList properties = Property.buildProperties(context);
57 | List generatedMethods = new ArrayList<>(withMethods.size());
58 | for (WithMethod withMethod : withMethods) {
59 | generatedMethods.add(generateWithMethod(withMethod, context, properties));
60 | }
61 | return generatedMethods;
62 | }
63 |
64 | private MethodSpec generateWithMethod(
65 | WithMethod withMethod, Context context, ImmutableList properties) {
66 | String[] propertyNames = new String[properties.size()];
67 | for (int i = 0; i < propertyNames.length; i++) {
68 | Property property = properties.get(i);
69 | if (withMethod.propertyNames.contains(property.humanName())) {
70 | propertyNames[i] = property.humanName();
71 | } else {
72 | propertyNames[i] = property.methodName() + "()";
73 | }
74 | }
75 |
76 | List annotations = new ArrayList<>(withMethod.methodAnnotations.size() + 1);
77 | for (AnnotationMirror methodAnnotation : withMethod.methodAnnotations) {
78 | annotations.add(AnnotationSpec.get(methodAnnotation));
79 | }
80 | AnnotationSpec override = AnnotationSpec.builder(Override.class).build();
81 | if (!annotations.contains(override)) {
82 | annotations.add(0, override);
83 | }
84 |
85 | List modifiers = new ArrayList<>(2);
86 | modifiers.add(FINAL);
87 | for (Modifier modifier : withMethod.methodModifiers) {
88 | if (modifier == Modifier.PUBLIC || modifier == Modifier.PROTECTED) {
89 | modifiers.add(modifier);
90 | break;
91 | }
92 | }
93 |
94 | List parameters = new ArrayList<>(withMethod.properties.size());
95 | for (Property property : withMethod.properties) {
96 | parameters.add(ParameterSpec.builder(property.type(), property.humanName()).build());
97 | }
98 |
99 | return MethodSpec.methodBuilder(withMethod.methodName)
100 | .addAnnotations(annotations)
101 | .addModifiers(modifiers)
102 | .returns(getAutoValueClassTypeName(context))
103 | .addParameters(parameters)
104 | .addCode("return ")
105 | .addCode(newFinalClassConstructorCall(context, propertyNames))
106 | .build();
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/auto-value-with/src/main/java/com/gabrielittner/auto/value/with/WithMethod.java:
--------------------------------------------------------------------------------
1 | package com.gabrielittner.auto.value.with;
2 |
3 | import com.gabrielittner.auto.value.util.Property;
4 | import com.google.auto.value.extension.AutoValueExtension.Context;
5 | import com.google.common.collect.ImmutableSet;
6 | import com.squareup.javapoet.TypeName;
7 | import java.util.ArrayList;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Set;
11 | import javax.annotation.processing.Messager;
12 | import javax.lang.model.element.AnnotationMirror;
13 | import javax.lang.model.element.ExecutableElement;
14 | import javax.lang.model.element.Modifier;
15 | import javax.lang.model.element.TypeElement;
16 | import javax.lang.model.element.VariableElement;
17 | import javax.lang.model.type.TypeMirror;
18 | import javax.lang.model.util.Types;
19 | import javax.tools.Diagnostic.Kind;
20 |
21 | import static com.gabrielittner.auto.value.util.ElementUtil.getResolvedReturnType;
22 |
23 | class WithMethod {
24 |
25 | private static final String PREFIX = "with";
26 |
27 | final String methodName;
28 | final Set methodModifiers;
29 | final List extends AnnotationMirror> methodAnnotations;
30 |
31 | final List properties;
32 | final List propertyNames;
33 |
34 | private WithMethod(ExecutableElement method, List properties,
35 | List methodPropertyNames) {
36 | this.methodName = method.getSimpleName().toString();
37 | this.methodModifiers = method.getModifiers();
38 | this.methodAnnotations = method.getAnnotationMirrors();
39 | this.properties = properties;
40 | this.propertyNames = methodPropertyNames;
41 | }
42 |
43 | static List getWithMethods(Context context) {
44 | Messager messager = context.processingEnvironment().getMessager();
45 | Types typeUtils = context.processingEnvironment().getTypeUtils();
46 |
47 | TypeElement autoValueClass = context.autoValueClass();
48 | Map properties = context.properties();
49 |
50 | ImmutableSet methods = filteredAbstractMethods(context);
51 | List withMethods = new ArrayList<>(methods.size());
52 | for (ExecutableElement method : methods) {
53 | TypeMirror returnType = getResolvedReturnType(typeUtils, autoValueClass, method);
54 | if (!typeUtils.isAssignable(autoValueClass.asType(), returnType)) {
55 | String message = String.format("Expected %s as return type", autoValueClass);
56 | messager.printMessage(Kind.ERROR, message, method);
57 | continue;
58 | }
59 |
60 | List extends VariableElement> parameters = method.getParameters();
61 | List methodProperties = new ArrayList<>(parameters.size());
62 | List methodPropertyNames = new ArrayList<>(parameters.size());
63 | for (VariableElement parameter : parameters) {
64 | String propertyName = parameter.getSimpleName().toString();
65 | ExecutableElement propertyMethod = properties.get(propertyName);
66 | if (propertyMethod == null) {
67 | String message = String.format("Property \"%s\" not found", propertyName);
68 | messager.printMessage(Kind.ERROR, message, parameter);
69 | continue;
70 | }
71 | Property property = new Property(propertyName, propertyMethod);
72 | if (!TypeName.get(parameter.asType()).equals(property.type())) {
73 | String message =
74 | String.format("Expected type %s for %s", property.type(), propertyName);
75 | messager.printMessage(Kind.ERROR, message, parameter);
76 | continue;
77 | }
78 | methodProperties.add(property);
79 | methodPropertyNames.add(propertyName);
80 | }
81 |
82 | withMethods.add(new WithMethod(method, methodProperties, methodPropertyNames));
83 | }
84 | return withMethods;
85 | }
86 |
87 | static ImmutableSet filteredAbstractMethods(Context context) {
88 | Set abstractMethods = context.abstractMethods();
89 | ImmutableSet.Builder withMethods = ImmutableSet.builder();
90 | for (ExecutableElement method : abstractMethods) {
91 | if (method.getSimpleName().toString().startsWith(PREFIX)
92 | && method.getParameters().size() > 0) {
93 | withMethods.add(method);
94 | }
95 | }
96 | return withMethods.build();
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/auto-value-with/src/test/java/com/gabrielittner/auto/value/with/AutoValueWithExtensionTest.java:
--------------------------------------------------------------------------------
1 | package com.gabrielittner.auto.value.with;
2 |
3 | import com.google.auto.value.processor.AutoValueProcessor;
4 | import com.google.testing.compile.JavaFileObjects;
5 | import java.util.Arrays;
6 | import java.util.Collections;
7 | import javax.tools.JavaFileObject;
8 | import org.junit.Test;
9 |
10 | import static com.google.common.truth.Truth.assertAbout;
11 | import static com.google.testing.compile.JavaSourcesSubjectFactory.javaSources;
12 |
13 | public final class AutoValueWithExtensionTest {
14 |
15 | @Test
16 | public void simple() {
17 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
18 | + "package test;\n"
19 | + "import com.google.auto.value.AutoValue;\n"
20 | + "import javax.annotation.Nonnull;\n"
21 | + "@AutoValue public abstract class Test {\n"
22 | // normal
23 | + " public abstract String a();\n"
24 | + " public abstract String b();\n"
25 | + " abstract Test withA(String a);\n"
26 | // primitive
27 | + " public abstract int c();\n"
28 | + " public abstract int d();\n"
29 | + " abstract Test withC(int c);\n"
30 | // public
31 | + " public abstract String e();\n"
32 | + " public abstract Test withE(String e);\n"
33 | // protected
34 | + " public abstract String f();\n"
35 | + " protected abstract Test withF(String f);\n"
36 | // with annotation
37 | + " public abstract String g();\n"
38 | + " @Nonnull abstract Test withG(String g);\n"
39 | // public with annotation
40 | + " public abstract String h();\n"
41 | + " @Nonnull public abstract Test withH(String h);\n"
42 | // property name starting with "with"
43 | + " public abstract String withI();\n"
44 | + " abstract Test withWithI(String withI);\n"
45 | // multiple properties
46 | + " abstract Test withAC(String a, int c);\n"
47 | + " abstract Test withBACD(String b, String a, int c, int d);\n"
48 | + "}\n");
49 |
50 | JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
51 | + "package test;\n"
52 | + "import java.lang.Override;\n"
53 | + "import java.lang.String;\n"
54 | + "import javax.annotation.Nonnull;\n"
55 | + "final class AutoValue_Test extends $AutoValue_Test {\n"
56 | + " AutoValue_Test(String a, String b, int c, int d, String e, String f, String g, String h, String withI) {\n"
57 | + " super(a, b, c, d, e, f, g, h, withI);\n"
58 | + " }\n"
59 | + " @Override final Test withA(String a) {\n"
60 | + " return new AutoValue_Test(a, b(), c(), d(), e(), f(), g(), h(), withI());\n"
61 | + " }\n"
62 | + " @Override final Test withC(int c) {\n"
63 | + " return new AutoValue_Test(a(), b(), c, d(), e(), f(), g(), h(), withI());\n"
64 | + " }\n"
65 | + " @Override public final Test withE(String e) {\n"
66 | + " return new AutoValue_Test(a(), b(), c(), d(), e, f(), g(), h(), withI());\n"
67 | + " }\n"
68 | + " @Override protected final Test withF(String f) {\n"
69 | + " return new AutoValue_Test(a(), b(), c(), d(), e(), f, g(), h(), withI());\n"
70 | + " }\n"
71 | + " @Override @Nonnull final Test withG(String g) {\n"
72 | + " return new AutoValue_Test(a(), b(), c(), d(), e(), f(), g, h(), withI());\n"
73 | + " }\n"
74 | + " @Override @Nonnull public final Test withH(String h) {\n"
75 | + " return new AutoValue_Test(a(), b(), c(), d(), e(), f(), g(), h, withI());\n"
76 | + " }\n"
77 | + " @Override final Test withWithI(String withI) {\n"
78 | + " return new AutoValue_Test(a(), b(), c(), d(), e(), f(), g(), h(), withI);\n"
79 | + " }\n"
80 | + " @Override final Test withAC(String a, int c) {\n"
81 | + " return new AutoValue_Test(a, b(), c, d(), e(), f(), g(), h(), withI());\n"
82 | + " }\n"
83 | + " @Override final Test withBACD(String b, String a, int c, int d) {\n"
84 | + " return new AutoValue_Test(a, b, c, d, e(), f(), g(), h(), withI());\n"
85 | + " }\n"
86 | + "}\n");
87 |
88 | assertAbout(javaSources())
89 | .that(Collections.singletonList(source))
90 | .processedWith(new AutoValueProcessor())
91 | .compilesWithoutError()
92 | .and()
93 | .generatesSources(expectedSource);
94 | }
95 |
96 | @Test
97 | public void generic() {
98 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
99 | + "package test;\n"
100 | + "import com.google.auto.value.AutoValue;\n"
101 | + "@AutoValue public abstract class Test {\n"
102 | + " public abstract T a();\n"
103 | + " abstract Test withA(T a);\n"
104 | + "}\n");
105 |
106 | JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
107 | + "package test;\n"
108 | + "import java.lang.Override;\n"
109 | + "final class AutoValue_Test extends $AutoValue_Test {\n"
110 | + " AutoValue_Test(T a) {\n"
111 | + " super(a);\n"
112 | + " }\n"
113 | + " @Override final Test withA(T a) {\n"
114 | + " return new AutoValue_Test<>(a);\n"
115 | + " }\n"
116 | + "}\n");
117 |
118 | assertAbout(javaSources())
119 | .that(Collections.singletonList(source))
120 | .processedWith(new AutoValueProcessor())
121 | .compilesWithoutError()
122 | .and()
123 | .generatesSources(expectedSource);
124 | }
125 |
126 | @Test
127 | public void returnsSuperType() {
128 | JavaFileObject source1 = JavaFileObjects.forSourceString("test.AbstractTest", ""
129 | + "package test;\n"
130 | + "import com.google.auto.value.AutoValue;\n"
131 | + "public abstract class AbstractTest {\n"
132 | + " public abstract String a();\n"
133 | + " abstract AbstractTest withA(String a);\n"
134 | + " public abstract String b();\n"
135 | + " abstract AbstractTest withB(String B);\n"
136 | + "}\n");
137 | JavaFileObject source2 = JavaFileObjects.forSourceString("test.Test", ""
138 | + "package test;\n"
139 | + "import com.google.auto.value.AutoValue;\n"
140 | + "@AutoValue public abstract class Test extends AbstractTest {\n"
141 | + " @Override abstract Test withB(String b);\n"
142 | + "}\n");
143 |
144 | JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
145 | + "package test;\n"
146 | + "import java.lang.Override;\n"
147 | + "import java.lang.String;\n"
148 | + "final class AutoValue_Test extends $AutoValue_Test {\n"
149 | + " AutoValue_Test(String a, String b) {\n"
150 | + " super(a, b);\n"
151 | + " }\n"
152 | + " @Override final Test withA(String a) {\n"
153 | + " return new AutoValue_Test(a, b());\n"
154 | + " }\n"
155 | + " @Override final Test withB(String b) {\n"
156 | + " return new AutoValue_Test(a(), b);\n"
157 | + " }\n"
158 | + "}\n");
159 |
160 | assertAbout(javaSources())
161 | .that(Arrays.asList(source1, source2))
162 | .processedWith(new AutoValueProcessor())
163 | .compilesWithoutError()
164 | .and()
165 | .generatesSources(expectedSource);
166 | }
167 |
168 | @Test
169 | public void returnsGenericSuperType() {
170 | JavaFileObject source1 = JavaFileObjects.forSourceString("test.AbstractTest", ""
171 | + "package test;\n"
172 | + "import com.google.auto.value.AutoValue;\n"
173 | + "public abstract class AbstractTest> {\n"
174 | + " public abstract String a();\n"
175 | + " abstract T withA(String a);\n"
176 | + "}\n");
177 | JavaFileObject source2 = JavaFileObjects.forSourceString("test.Test", ""
178 | + "package test;\n"
179 | + "import com.google.auto.value.AutoValue;\n"
180 | + " @AutoValue public abstract class Test extends AbstractTest {\n"
181 | + "}\n");
182 |
183 | JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
184 | + "package test;\n"
185 | + "import java.lang.Override;\n"
186 | + "import java.lang.String;\n"
187 | + "final class AutoValue_Test extends $AutoValue_Test {\n"
188 | + " AutoValue_Test(String a) {\n"
189 | + " super(a);\n"
190 | + " }\n"
191 | + " @Override final Test withA(String a) {\n"
192 | + " return new AutoValue_Test(a);\n"
193 | + " }\n"
194 | + "}\n");
195 |
196 | assertAbout(javaSources())
197 | .that(Arrays.asList(source1, source2))
198 | .processedWith(new AutoValueProcessor())
199 | .compilesWithoutError()
200 | .and()
201 | .generatesSources(expectedSource);
202 | }
203 |
204 | @Test
205 | public void wrongParameterName() {
206 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
207 | + "package test;\n"
208 | + "import com.google.auto.value.AutoValue;\n"
209 | + "@AutoValue public abstract class Test {\n"
210 | + " public abstract String a();\n"
211 | + " abstract Test withA(String b);\n"
212 | + "}\n");
213 |
214 | assertAbout(javaSources())
215 | .that(Collections.singletonList(source))
216 | .processedWith(new AutoValueProcessor())
217 | .failsToCompile()
218 | .withErrorContaining("Property \"b\" not found");
219 | }
220 |
221 | @Test
222 | public void wrongParameterType() {
223 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
224 | + "package test;\n"
225 | + "import com.google.auto.value.AutoValue;\n"
226 | + "@AutoValue public abstract class Test {\n"
227 | + " public abstract String a();\n"
228 | + " abstract Test withA(int a);\n"
229 | + "}\n");
230 |
231 | assertAbout(javaSources())
232 | .that(Collections.singletonList(source))
233 | .processedWith(new AutoValueProcessor())
234 | .failsToCompile()
235 | .withErrorContaining("Expected type java.lang.String for a");
236 | }
237 |
238 | @Test
239 | public void wrongReturnType() {
240 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
241 | + "package test;\n"
242 | + "import com.google.auto.value.AutoValue;\n"
243 | + "@AutoValue public abstract class Test {\n"
244 | + " public abstract String a();\n"
245 | + " abstract String withA(String a);\n"
246 | + "}\n");
247 |
248 | assertAbout(javaSources())
249 | .that(Collections.singletonList(source))
250 | .processedWith(new AutoValueProcessor())
251 | .failsToCompile()
252 | .withErrorContaining("Expected test.Test as return type");
253 | }
254 |
255 | @Test
256 | public void prefixedMethods() {
257 | JavaFileObject source = JavaFileObjects.forSourceString("test.Test", ""
258 | + "package test;\n"
259 | + "import com.google.auto.value.AutoValue;\n"
260 | + "@AutoValue public abstract class Test {\n"
261 | + " public abstract int getA();\n"
262 | + " public abstract boolean isB();\n"
263 | + " abstract Test withA(int a);\n"
264 | + " abstract Test withB(boolean b);\n"
265 | + "}\n");
266 |
267 | JavaFileObject expectedSource = JavaFileObjects.forSourceString("test/AutoValue_Test", ""
268 | + "package test;\n"
269 | + "import java.lang.Override;\n"
270 | + "final class AutoValue_Test extends $AutoValue_Test {\n"
271 | + " AutoValue_Test(int a, boolean b) {\n"
272 | + " super(a, b);\n"
273 | + " }\n"
274 | + " @Override final Test withA(int a) {\n"
275 | + " return new AutoValue_Test(a, isB());\n"
276 | + " }\n"
277 | + " @Override final Test withB(boolean b) {\n"
278 | + " return new AutoValue_Test(getA(), b);\n"
279 | + " }\n"
280 | + "}\n");
281 |
282 | assertAbout(javaSources())
283 | .that(Collections.singletonList(source))
284 | .processedWith(new AutoValueProcessor())
285 | .compilesWithoutError()
286 | .and()
287 | .generatesSources(expectedSource);
288 | }
289 | }
290 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | jcenter()
5 | }
6 |
7 | dependencies {
8 | classpath 'com.vanniktech:gradle-maven-publish-plugin:0.12.0'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | mavenCentral()
15 | }
16 | }
17 |
18 | ext {
19 | javaVersion = JavaVersion.VERSION_1_7
20 | autoServiceVersion = "1.0-rc7"
21 | }
22 |
23 | ext.deps = [
24 | javapoet: 'com.squareup:javapoet:1.13.0',
25 | auto_value: 'com.google.auto.value:auto-value:1.7.4',
26 | auto_common: 'com.google.auto:auto-common:0.10',
27 | guava: 'com.google.guava:guava:29.0-jre',
28 | auto_ext_util: 'com.gabrielittner.auto.value:auto-value-extension-util:0.4.0',
29 |
30 | auto_service_annotations: "com.google.auto.service:auto-service-annotations:$autoServiceVersion",
31 | auto_service: "com.google.auto.service:auto-service:$autoServiceVersion",
32 |
33 | junit: 'junit:junit:4.13',
34 | truth: 'com.google.truth:truth:1.0.1',
35 | compile_testing: 'com.google.testing.compile:compile-testing:0.18',
36 | jsr305: 'com.google.code.findbugs:jsr305:3.0.2'
37 | ]
38 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.gabrielittner.auto.value
2 | VERSION_NAME=1.2.0-SNAPSHOT
3 |
4 | POM_DESCRIPTION=AutoValue extension to implement "with-er" methods for AutoValue objects
5 |
6 | POM_URL=https://github.com/gabrielittner/auto-value-with/
7 | POM_SCM_URL=https://github.com/gabrielittner/auto-value-with/
8 | POM_SCM_CONNECTION=scm:git:git://github.com/gabrielittner/auto-value-with.git
9 | POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/gabrielittner/auto-value-with.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=gabrielittner
16 | POM_DEVELOPER_NAME=Gabriel Ittner
17 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gabrielittner/auto-value-with/a88a235e8ad9ac19f44ca6453808e4f990a0d40d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # http://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 | # Determine the Java command to use to start the JVM.
86 | if [ -n "$JAVA_HOME" ] ; then
87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
88 | # IBM's JDK on AIX uses strange locations for the executables
89 | JAVACMD="$JAVA_HOME/jre/sh/java"
90 | else
91 | JAVACMD="$JAVA_HOME/bin/java"
92 | fi
93 | if [ ! -x "$JAVACMD" ] ; then
94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
95 |
96 | Please set the JAVA_HOME variable in your environment to match the
97 | location of your Java installation."
98 | fi
99 | else
100 | JAVACMD="java"
101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
102 |
103 | Please set the JAVA_HOME variable in your environment to match the
104 | location of your Java installation."
105 | fi
106 |
107 | # Increase the maximum file descriptors if we can.
108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
109 | MAX_FD_LIMIT=`ulimit -H -n`
110 | if [ $? -eq 0 ] ; then
111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
112 | MAX_FD="$MAX_FD_LIMIT"
113 | fi
114 | ulimit -n $MAX_FD
115 | if [ $? -ne 0 ] ; then
116 | warn "Could not set maximum file descriptor limit: $MAX_FD"
117 | fi
118 | else
119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
120 | fi
121 | fi
122 |
123 | # For Darwin, add options to specify how the application appears in the dock
124 | if $darwin; then
125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
126 | fi
127 |
128 | # For Cygwin, switch paths to Windows format before running java
129 | if $cygwin ; then
130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
132 | JAVACMD=`cygpath --unix "$JAVACMD"`
133 |
134 | # We build the pattern for arguments to be converted via cygpath
135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
136 | SEP=""
137 | for dir in $ROOTDIRSRAW ; do
138 | ROOTDIRS="$ROOTDIRS$SEP$dir"
139 | SEP="|"
140 | done
141 | OURCYGPATTERN="(^($ROOTDIRS))"
142 | # Add a user-defined pattern to the cygpath arguments
143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
145 | fi
146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
147 | i=0
148 | for arg in "$@" ; do
149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
151 |
152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
154 | else
155 | eval `echo args$i`="\"$arg\""
156 | fi
157 | i=$((i+1))
158 | done
159 | case $i in
160 | (0) set -- ;;
161 | (1) set -- "$args0" ;;
162 | (2) set -- "$args0" "$args1" ;;
163 | (3) set -- "$args0" "$args1" "$args2" ;;
164 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
165 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
166 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
167 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
168 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
169 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
170 | esac
171 | fi
172 |
173 | # Escape application args
174 | save () {
175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
176 | echo " "
177 | }
178 | APP_ARGS=$(save "$@")
179 |
180 | # Collect all arguments for the java command, following the shell quoting and substitution rules
181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
182 |
183 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
184 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
185 | cd "$(dirname "$0")"
186 | fi
187 |
188 | exec "$JAVACMD" "$@"
189 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'auto-value-with-root'
2 |
3 | include ':auto-value-with'
--------------------------------------------------------------------------------