├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── dilpreet2028
│ │ └── fragmenter
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── dilpreet2028
│ │ │ └── fragmenter
│ │ │ ├── DemoFragment.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ └── fragment_demo.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── dilpreet2028
│ └── fragmenter
│ └── ExampleUnitTest.java
├── build.gradle
├── fragmenter-annotations
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── dilpreet2028
│ └── fragmenter_annotations
│ ├── Fragmenter.java
│ ├── Injector.java
│ └── annotations
│ ├── Arg.java
│ └── FragModule.java
├── fragmenter-compiler
├── .gitignore
├── build.gradle
└── src
│ └── main
│ └── java
│ └── com
│ └── dilpreet2028
│ └── fragmenter_compiler
│ ├── FileGenerator
│ ├── FieldInjectorGenerator.java
│ ├── FragGenerator.java
│ └── Generator.java
│ ├── FragModuleContainer.java
│ ├── FragmenterProcessor.java
│ └── ProcessorException.java
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # fragmenter
2 | Generates boilerplate code for initializing fragment using annotation processing and performs argument binding while following best practices for initializing a fragment.
3 | + Eliminates need to create a static function to initialize a fragment
4 | + Eliminates need to bind the arguments manually
5 |
6 | ### Example
7 |
8 |
Fragment Class
9 |
10 | ```java
11 | import com.dilpreet2028.fragmenter_annotations.Fragmenter;
12 | import com.dilpreet2028.fragmenter_annotations.annotations.Arg;
13 | import com.dilpreet2028.fragmenter_annotations.annotations.FragModule;
14 |
15 | @FragModule//Need to annotate fragment with @FragModule
16 | public class DemoFragment extends Fragment {
17 |
18 | @Arg
19 | String data; //Annotate variables needed to be initialised with @Arg
20 |
21 | @Override
22 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
23 | Bundle savedInstanceState) {
24 | View view=inflater.inflate(R.layout.fragment_demo, container, false);
25 |
26 | Fragmenter.inject(this);//arguments gets injected automically
27 |
28 | ((TextView) view.findViewById(R.id.tv_text)).setText(data);
29 |
30 | return view;
31 | }
32 |
33 | }
34 | ```
35 | **Note: After creating a fragment build the project to allow fragmenter to generate the classes for you.**
36 |
37 | Fragmenter generates a Builder class i.e. the name of your Fragment with "Builder" as suffix .
38 | In this example Fragmenter creates a `DemoFragmentBuilder` for `DemoFragment`
39 |
40 | Activity Class
41 |
42 | ```java
43 | public class MainActivity extends AppCompatActivity {
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_main);
49 |
50 | String data = "Hello world";
51 |
52 | //using the builder class and passing the required variables.
53 | DemoFragment fragment = DemoFragmentBuilder.newInstance(data);
54 |
55 | getSupportFragmentManager()
56 | .beginTransaction()
57 | .replace(R.id.content , fragment)
58 | .commit();
59 |
60 |
61 | }
62 | }
63 | ```
64 |
65 | Download
66 |
67 | In the root build.gradle file add :
68 | ```
69 | allprojects {
70 | repositories {
71 | ...
72 | maven { url "https://jitpack.io" }
73 | }
74 | }
75 | ```
76 | In your app build.gradle file add:
77 |
78 | ```
79 | dependencies {
80 | compile 'com.github.dilpreet96.fragmenter:fragmenter-annotations:1.0.2'
81 | annotationProcessor 'com.github.dilpreet96.fragmenter:fragmenter-compiler:1.0.2'
82 | }
83 | ```
84 |
85 |
86 | License
87 |
88 | ```
89 | Copyright (C) 2017 Dilpreet Singh
90 |
91 | Licensed under the Apache License, Version 2.0 (the "License");
92 | you may not use this file except in compliance with the License.
93 | You may obtain a copy of the License at
94 |
95 | http://www.apache.org/licenses/LICENSE-2.0
96 |
97 | Unless required by applicable law or agreed to in writing, software
98 | distributed under the License is distributed on an "AS IS" BASIS,
99 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
100 | See the License for the specific language governing permissions and
101 | limitations under the License.
102 | ```
103 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 | defaultConfig {
7 | applicationId "com.dilpreet2028.fragmenter"
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.1'
28 | compile 'com.android.support:support-v4:25.1.1'
29 | testCompile 'junit:junit:4.12'
30 | compile project(':fragmenter-annotations')
31 | annotationProcessor project(':fragmenter-compiler')
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/dilpreet/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/dilpreet2028/fragmenter/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.dilpreet2028.fragmenter", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dilpreet2028/fragmenter/DemoFragment.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter;
2 |
3 |
4 | import android.os.Bundle;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.dilpreet2028.fragmenter_annotations.Fragmenter;
12 | import com.dilpreet2028.fragmenter_annotations.annotations.Arg;
13 | import com.dilpreet2028.fragmenter_annotations.annotations.FragModule;
14 |
15 | import java.util.ArrayList;
16 |
17 |
18 | @FragModule
19 | public class DemoFragment extends Fragment {
20 |
21 | @Arg
22 | ArrayList strings;
23 |
24 | @Arg
25 | String data;
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | View view=inflater.inflate(R.layout.fragment_demo, container, false);
31 | Fragmenter.inject(this);
32 |
33 | ((TextView) view.findViewById(R.id.tv_text)).setText(data+" "+strings.get(0));
34 | return view;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dilpreet2028/fragmenter/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 |
7 | import java.util.ArrayList;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 |
16 | String data = "Hello world";
17 | ArrayList arrayList=new ArrayList<>();
18 | arrayList.add("one");
19 |
20 | //using the builder class and passing the required variables.
21 | DemoFragment fragment = DemoFragmentBuilder.newInstance(arrayList,data);
22 |
23 | getSupportFragmentManager()
24 | .beginTransaction()
25 | .replace(R.id.content , fragment)
26 | .commit();
27 |
28 | }
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_demo.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Fragmenter
3 |
4 |
5 | Hello blank fragment
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/dilpreet2028/fragmenter/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 | // NOTE: Do not place your application dependencies here; they belong
10 | // in the individual module build.gradle files
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | maven { url = 'https://jitpack.io' }
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/fragmenter-annotations/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fragmenter-annotations/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 |
4 | group='com.github.jitpack'
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | compile fileTree(dir: 'libs', include: ['*.jar'])
12 | }
13 |
14 | task sourcesJar(type: Jar, dependsOn: classes) {
15 | classifier = 'sources'
16 | from sourceSets.main.allSource
17 | }
18 |
19 | task javadocJar(type: Jar, dependsOn: javadoc) {
20 | classifier = 'javadoc'
21 | from javadoc.destinationDir
22 | }
23 |
24 | artifacts {
25 | archives sourcesJar
26 | archives javadocJar
27 | }
28 |
29 |
30 | sourceCompatibility = 1.7
31 | targetCompatibility = 1.7
32 |
--------------------------------------------------------------------------------
/fragmenter-annotations/src/main/java/com/dilpreet2028/fragmenter_annotations/Fragmenter.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_annotations;
2 |
3 | /**
4 | * Created by dilpreet on 12/3/17.
5 | */
6 |
7 | public class Fragmenter {
8 | private static Injector injector;
9 | private static final String MAPPING_PACKAGE = "com.dilpreet2028.fragmenter";
10 | private static final String MAPPING_CLASS = "FieldInjector";
11 |
12 | public static void inject(Object fragment) {
13 | try {
14 | Class> clazz = Class.forName(MAPPING_PACKAGE+"."+MAPPING_CLASS);
15 | injector = (Injector) clazz.newInstance();
16 | } catch (Exception e){
17 |
18 | }
19 |
20 | if(injector != null) {
21 | injector.inject(fragment);
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/fragmenter-annotations/src/main/java/com/dilpreet2028/fragmenter_annotations/Injector.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_annotations;
2 |
3 | /**
4 | * Created by dilpreet on 12/3/17.
5 | */
6 |
7 | public interface Injector {
8 | public void inject(Object fragment);
9 | }
10 |
--------------------------------------------------------------------------------
/fragmenter-annotations/src/main/java/com/dilpreet2028/fragmenter_annotations/annotations/Arg.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_annotations.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Target(ElementType.FIELD)
9 | @Retention(RetentionPolicy.CLASS)
10 | public @interface Arg {
11 | }
12 |
--------------------------------------------------------------------------------
/fragmenter-annotations/src/main/java/com/dilpreet2028/fragmenter_annotations/annotations/FragModule.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_annotations.annotations;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | /**
9 | * Created by dilpreet on 11/3/17.
10 | */
11 |
12 | @Target(ElementType.TYPE)
13 | @Retention(RetentionPolicy.CLASS)
14 | public @interface FragModule {
15 | }
16 |
--------------------------------------------------------------------------------
/fragmenter-compiler/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/fragmenter-compiler/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'java'
2 | apply plugin: 'maven'
3 |
4 | group='com.github.jitpack'
5 |
6 | repositories {
7 | mavenCentral()
8 | }
9 |
10 | dependencies {
11 | compile fileTree(dir: 'libs', include: ['*.jar'])
12 |
13 | compile 'com.google.auto.service:auto-service:1.0-rc2'
14 | compile 'com.squareup:javapoet:1.8.0'
15 | compile project(":fragmenter-annotations")
16 | }
17 |
18 | task sourcesJar(type: Jar, dependsOn: classes) {
19 | classifier = 'sources'
20 | from sourceSets.main.allSource
21 | }
22 |
23 | task javadocJar(type: Jar, dependsOn: javadoc) {
24 | classifier = 'javadoc'
25 | from javadoc.destinationDir
26 | }
27 |
28 | artifacts {
29 | archives sourcesJar
30 | archives javadocJar
31 | }
32 |
33 |
34 |
35 | sourceCompatibility = 1.7
36 | targetCompatibility = 1.7
37 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/FileGenerator/FieldInjectorGenerator.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler.FileGenerator;
2 |
3 | import com.dilpreet2028.fragmenter_annotations.Injector;
4 | import com.dilpreet2028.fragmenter_compiler.FragModuleContainer;
5 | import com.dilpreet2028.fragmenter_compiler.ProcessorException;
6 | import com.squareup.javapoet.ClassName;
7 | import com.squareup.javapoet.JavaFile;
8 | import com.squareup.javapoet.MethodSpec;
9 | import com.squareup.javapoet.TypeSpec;
10 |
11 | import java.io.IOException;
12 | import java.util.Map;
13 |
14 | import javax.annotation.processing.Filer;
15 | import javax.lang.model.element.Modifier;
16 | import javax.lang.model.element.TypeElement;
17 | import javax.lang.model.util.Elements;
18 |
19 | /**
20 | * Created by dilpreet on 12/3/17.
21 | */
22 |
23 | public class FieldInjectorGenerator implements Generator {
24 |
25 | private static final String MAPPING_PACKAGE = "com.dilpreet2028.fragmenter";
26 | private static final String MAPPING_CLASS = "FieldInjector";
27 | private Elements elementUtils;
28 | private Map processorMap;
29 |
30 | @Override
31 | public void generateClass(Map processorMap, Filer filer, Elements elementUtils)
32 | throws ProcessorException{
33 |
34 | this.processorMap = processorMap;
35 | this.elementUtils = elementUtils;
36 |
37 | TypeSpec generatedClass = generateClassData();
38 |
39 | JavaFile javaFile = JavaFile.builder(MAPPING_PACKAGE, generatedClass).build();
40 | try {
41 | javaFile.writeTo(filer);
42 | } catch (IOException e) {
43 | e.printStackTrace();
44 | }
45 | }
46 |
47 | private MethodSpec generateMethod() {
48 |
49 | String fragName;
50 | MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("inject")
51 | .addParameter(Object.class,"fragment")
52 | .addModifiers(Modifier.PUBLIC);
53 | for(FragModuleContainer fragModule : processorMap.values()) {
54 | fragName = getPackageName(fragModule.getTypeElement(), elementUtils)+"."
55 | +fragModule.getTypeElement().getSimpleName();
56 | methodBuilder.beginControlFlow("if ($N.class.getSimpleName()." +
57 | "compareTo(fragment.getClass().getSimpleName())==0)",fragName);
58 | methodBuilder.addStatement("$NBuilder.inject(($N) fragment)",fragName,fragName);
59 | methodBuilder.addStatement("return");
60 | methodBuilder.endControlFlow();
61 | }
62 | return methodBuilder.build();
63 | }
64 |
65 | private TypeSpec generateClassData() {
66 | return TypeSpec.classBuilder(MAPPING_CLASS)
67 | .addSuperinterface(Injector.class)
68 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
69 | .addMethod(generateMethod())
70 | .build();
71 | }
72 |
73 | private String getPackageName(TypeElement element, Elements elementsUtils) {
74 | return elementsUtils.getPackageOf(element).toString();
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/FileGenerator/FragGenerator.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler.FileGenerator;
2 |
3 | import com.dilpreet2028.fragmenter_annotations.annotations.Arg;
4 | import com.dilpreet2028.fragmenter_compiler.FragModuleContainer;
5 | import com.dilpreet2028.fragmenter_compiler.FragmenterProcessor;
6 | import com.dilpreet2028.fragmenter_compiler.ProcessorException;
7 | import com.squareup.javapoet.ClassName;
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 |
13 | import java.io.IOException;
14 | import java.lang.annotation.Annotation;
15 | import java.util.ArrayList;
16 | import java.util.HashMap;
17 | import java.util.List;
18 | import java.util.Map;
19 | import java.util.regex.Matcher;
20 | import java.util.regex.Pattern;
21 |
22 | import javax.annotation.processing.Filer;
23 | import javax.lang.model.element.Element;
24 | import javax.lang.model.element.Modifier;
25 | import javax.lang.model.element.TypeElement;
26 | import javax.lang.model.util.Elements;
27 |
28 | /**
29 | * Created by dilpreet on 11/3/17.
30 | */
31 |
32 | public class FragGenerator implements Generator {
33 |
34 | private final HashMap fieldMapper =
35 | new HashMap<>();
36 | private final HashMap bundleListMapper =
37 | new HashMap<>();
38 |
39 | private String packageName;
40 | private ClassName bundleClass=ClassName.get("android.os","Bundle");
41 | private ClassName parcelableClass = ClassName.get("android.os.","Parcelable");
42 |
43 | public FragGenerator() {
44 | fieldMapper.put("int", Integer.class);
45 | fieldMapper.put("java.lang.Integer", Integer.class);
46 | fieldMapper.put("java.lang.String", String.class);
47 | fieldMapper.put("float", Float.class);
48 | fieldMapper.put("java.lang.Float", Float.class);
49 | fieldMapper.put("long", Long.class);
50 | fieldMapper.put("java.lang.Long", Long.class);
51 | fieldMapper.put("double", Double.class);
52 | fieldMapper.put("java.lang.Double", Double.class);
53 | fieldMapper.put("boolean", Boolean.class);
54 | fieldMapper.put("java.lang.Boolean", Boolean.class);
55 | fieldMapper.put("byte", Byte.class);
56 | fieldMapper.put("java.lang.Byte", Byte.class);
57 | fieldMapper.put("short", Short.class);
58 | fieldMapper.put("java.lang.Short", Short.class);
59 | fieldMapper.put("android.os.Parcelable", parcelableClass.getClass());
60 | fieldMapper.put("java.lang.CharSequence", CharSequence.class);
61 |
62 | bundleListMapper.put("String", "StringArrayList");
63 | bundleListMapper.put("Integer", "IntegerArrayList");
64 | bundleListMapper.put("CharSequence", "CharSequenceArrayList");
65 | }
66 |
67 | @Override
68 | public void generateClass(Map processorMap ,
69 | Filer filer , Elements elementUtils) throws ProcessorException{
70 |
71 |
72 |
73 | for(FragModuleContainer fragModule : processorMap.values()) {
74 | packageName = getPackageName(fragModule.getTypeElement() , elementUtils);
75 |
76 |
77 | TypeSpec generatedClass = generateClassData(fragModule );
78 |
79 | JavaFile javaFile = JavaFile.builder(packageName, generatedClass).build();
80 | try {
81 | javaFile.writeTo(filer);
82 | } catch (IOException e) {
83 | e.printStackTrace();
84 | }
85 | }
86 |
87 | }
88 |
89 | /*
90 | * Generates newInstance() static function along with the parameters required
91 | * to be initialized and sets the arugments in the bundle
92 | */
93 | private MethodSpec generateStaticFunction(FragModuleContainer fragModule) throws ProcessorException {
94 |
95 | ClassName fragmentClassName=ClassName.get(fragModule.getTypeElement());
96 |
97 | MethodSpec.Builder staticFunctionBuilder=MethodSpec.methodBuilder("newInstance")
98 | .addModifiers(Modifier.PUBLIC,Modifier.STATIC)
99 | .returns(fragmentClassName)
100 | .addParameters(generateFields(fragModule))
101 | .addStatement("$T fragment=new $T()",fragmentClassName,fragmentClassName)
102 | .addStatement("$T bundle=new $T()",bundleClass,bundleClass);
103 |
104 | for(Element element : fragModule.getElements()) {
105 |
106 | staticFunctionBuilder.addStatement("bundle.put$N(\"$L\",$L)",
107 | returnBundleFunc(element),element.getSimpleName(),element.getSimpleName());
108 |
109 | }
110 |
111 | staticFunctionBuilder.addStatement("fragment.setArguments(bundle)")
112 | .addStatement("return fragment");
113 |
114 |
115 | return staticFunctionBuilder.build();
116 | }
117 |
118 | /*
119 | * Generates paramaters for newInstance static function
120 | */
121 | private List generateFields(FragModuleContainer fragModule) {
122 | List specList=new ArrayList<>();
123 | ParameterSpec parameterSpec;
124 | String name;
125 |
126 | for(Element element : fragModule.getElements()) {
127 | name=element.getSimpleName().toString();
128 |
129 | parameterSpec=ParameterSpec.builder(ClassName.get(element.asType()),name)
130 | .build();
131 | specList.add(parameterSpec);
132 | }
133 | return specList;
134 | }
135 |
136 |
137 | private TypeSpec generateClassData(FragModuleContainer fragModule) throws ProcessorException {
138 | return TypeSpec.classBuilder(fragModule.getTypeElement().
139 | getSimpleName().toString() + "Builder")
140 | .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
141 | .addMethod(generateStaticFunction(fragModule))
142 | .addMethod(generateInjectMethods(fragModule))
143 | .build();
144 | }
145 |
146 | /*
147 | * used for injecting arguments
148 | */
149 | private MethodSpec generateInjectMethods(FragModuleContainer fragModule) throws ProcessorException {
150 | ClassName fragmentName=ClassName.get(fragModule.getTypeElement());
151 | String name;
152 | MethodSpec.Builder injectMethodBuilder = MethodSpec.methodBuilder("inject")
153 | .addModifiers(Modifier.PUBLIC,Modifier.STATIC)
154 | .addParameter(fragmentName,"fragment")
155 | .addStatement("$T bundle=fragment.getArguments()",bundleClass)
156 | .beginControlFlow("if (bundle != null)");
157 | for(Element element : fragModule.getElements()) {
158 | name = element.getSimpleName().toString();
159 | injectMethodBuilder.addStatement("fragment.$L = bundle.get$N(\"$L\")",
160 | name,returnBundleFunc(element),name);
161 | }
162 |
163 | injectMethodBuilder.endControlFlow();
164 | return injectMethodBuilder.build();
165 | }
166 |
167 | private String getPackageName(TypeElement element, Elements elementsUtils) {
168 | return elementsUtils.getPackageOf(element).toString();
169 | }
170 |
171 | /*
172 | * Used for finding bundle function for a particular argument.
173 | */
174 | private String returnBundleFunc(Element element) throws ProcessorException{
175 |
176 | String elementTypeString = element.asType().toString();
177 | if(elementTypeString.contains("java.util.List")) {
178 | throw new ProcessorException(element, "List is not supported in bundle please use ArrayList for \"%s.\"",
179 | element.getSimpleName());
180 | }
181 |
182 | if(!elementTypeString.contains(ArrayList.class.getSimpleName())) {
183 | return singleValueClass(element);
184 | } else {
185 | return multipleValueClass(element);
186 | }
187 | }
188 |
189 | /*
190 | * Used in case of a paramter with single value for e.g. Integer, String, etc.
191 | */
192 | private String singleValueClass(Element element) throws ProcessorException{
193 | String elementTypeString = element.asType().toString();
194 | if(!fieldMapper.containsKey(elementTypeString))
195 | throw new ProcessorException(element, "%s is not supported right now ",
196 | elementTypeString);
197 |
198 | if (elementTypeString.compareTo("int") == 0 ||
199 | elementTypeString.compareTo("java.lang.Integer") == 0)
200 | return "Int";
201 | else if (elementTypeString.compareTo("java.lang.Character") == 0)
202 | return "Char";
203 | else
204 | return fieldMapper.get(elementTypeString).getSimpleName();
205 | }
206 |
207 | /*
208 | * Used in case of a List item
209 | */
210 | private String multipleValueClass(Element element) throws ProcessorException {
211 |
212 | String elementTypeString = element.asType().toString();
213 |
214 | Pattern pattern = Pattern.compile("java.lang.(.*?)>");
215 | Matcher matcher = pattern.matcher(elementTypeString);
216 | if(matcher.find()) {
217 |
218 | if (!bundleListMapper.containsKey(matcher.group(1))) {
219 | throw new ProcessorException(element,"%s type ArrayList is not supported in bundle. ",matcher.group(1));
220 | }
221 | return bundleListMapper.get(matcher.group(1));
222 | }
223 |
224 | return "";
225 | }
226 |
227 |
228 |
229 | }
230 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/FileGenerator/Generator.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler.FileGenerator;
2 |
3 | import com.dilpreet2028.fragmenter_compiler.FragModuleContainer;
4 | import com.dilpreet2028.fragmenter_compiler.ProcessorException;
5 |
6 | import java.util.Map;
7 |
8 | import javax.annotation.processing.Filer;
9 | import javax.lang.model.util.Elements;
10 |
11 | /**
12 | * Created by dilpreet on 12/3/17.
13 | */
14 |
15 | public interface Generator {
16 | public void generateClass(Map processorMap ,
17 | Filer filer , Elements elementUtils) throws ProcessorException;
18 | }
19 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/FragModuleContainer.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler;
2 |
3 | import com.dilpreet2028.fragmenter_annotations.annotations.Arg;
4 |
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import javax.lang.model.element.Element;
9 | import javax.lang.model.element.TypeElement;
10 |
11 | /**
12 | * Created by dilpreet on 11/3/17.
13 | */
14 |
15 | public class FragModuleContainer {
16 |
17 | private TypeElement typeElement;
18 |
19 | public FragModuleContainer(TypeElement typeElement) {
20 | this.typeElement=typeElement;
21 | }
22 |
23 | public TypeElement getTypeElement() {
24 | return typeElement;
25 | }
26 |
27 | public List getElements() {
28 | List elementList=new ArrayList<>();
29 |
30 |
31 | for(Element element:typeElement.getEnclosedElements()){
32 | // If Arg annotation is present then add it to the list.
33 |
34 | if ((element.getAnnotation(Arg.class)) != null) {
35 | elementList.add(element);
36 | }
37 | }
38 | return elementList;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/FragmenterProcessor.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler;
2 |
3 | import com.dilpreet2028.fragmenter_annotations.annotations.FragModule;
4 | import com.dilpreet2028.fragmenter_compiler.FileGenerator.FieldInjectorGenerator;
5 | import com.dilpreet2028.fragmenter_compiler.FileGenerator.FragGenerator;
6 | import com.google.auto.service.AutoService;
7 |
8 | import java.util.LinkedHashMap;
9 | import java.util.Map;
10 | import java.util.Set;
11 |
12 | import javax.annotation.processing.AbstractProcessor;
13 | import javax.annotation.processing.Filer;
14 | import javax.annotation.processing.Messager;
15 | import javax.annotation.processing.ProcessingEnvironment;
16 | import javax.annotation.processing.Processor;
17 | import javax.annotation.processing.RoundEnvironment;
18 | import javax.annotation.processing.SupportedAnnotationTypes;
19 | import javax.annotation.processing.SupportedSourceVersion;
20 | import javax.lang.model.SourceVersion;
21 | import javax.lang.model.element.Element;
22 | import javax.lang.model.element.ElementKind;
23 | import javax.lang.model.element.TypeElement;
24 | import javax.lang.model.util.Elements;
25 | import javax.lang.model.util.Types;
26 | import javax.tools.Diagnostic;
27 |
28 |
29 | @AutoService(Processor.class)
30 | @SupportedAnnotationTypes("com.dilpreet2028.fragmenter_annotations.annotations.FragModule")
31 | @SupportedSourceVersion(SourceVersion.RELEASE_7)
32 | public class FragmenterProcessor extends AbstractProcessor {
33 |
34 | private Map processorMap;
35 | private Types typeUtil;
36 | private Filer filer;
37 | private Messager messager;
38 | private Elements elements;
39 | private FragGenerator fragGenerator;
40 | private FieldInjectorGenerator injectorGenerator;
41 |
42 | @Override
43 | public synchronized void init(ProcessingEnvironment processingEnvironment) {
44 | super.init(processingEnvironment);
45 | typeUtil = processingEnvironment.getTypeUtils();
46 | filer = processingEnvironment.getFiler();
47 | messager = processingEnvironment.getMessager();
48 | elements = processingEnvironment.getElementUtils();
49 | processorMap = new LinkedHashMap<>();
50 | fragGenerator = new FragGenerator();
51 | injectorGenerator = new FieldInjectorGenerator();
52 | }
53 |
54 | @Override
55 | public boolean process(Set extends TypeElement> set, RoundEnvironment roundEnvironment) {
56 |
57 | for(Element annotatedElement : roundEnvironment.getElementsAnnotatedWith(FragModule.class)) {
58 | if (annotatedElement.getKind() != ElementKind.CLASS) {
59 | onError(annotatedElement,"%s does not appears to be a class " ,
60 | annotatedElement.getSimpleName().toString());
61 | return false;
62 | }
63 |
64 | FragModuleContainer fragModuleContainer=new
65 | FragModuleContainer( (TypeElement) annotatedElement);
66 |
67 | processorMap.put(fragModuleContainer.getTypeElement().getSimpleName().toString(),
68 | fragModuleContainer);
69 | }
70 |
71 | try {
72 | fragGenerator.generateClass(processorMap, filer, elements);
73 | injectorGenerator.generateClass(processorMap, filer, elements);
74 | } catch (ProcessorException e) {
75 | onError(e.getElement(),e.getMessage());
76 | }
77 | return true;
78 | }
79 |
80 | private void onError(Element e,String msg,Object... args){
81 | messager.printMessage(Diagnostic.Kind.ERROR,String.format(msg,args),e);
82 | }
83 |
84 | public void onPrompt(Element e,String msg,Object... args){
85 | messager.printMessage(Diagnostic.Kind.NOTE,String.format(msg,args),e);
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/fragmenter-compiler/src/main/java/com/dilpreet2028/fragmenter_compiler/ProcessorException.java:
--------------------------------------------------------------------------------
1 | package com.dilpreet2028.fragmenter_compiler;
2 |
3 | import javax.lang.model.element.Element;
4 |
5 | /**
6 | * Created by dilpreet on 11/3/17.
7 | */
8 |
9 | public class ProcessorException extends Exception {
10 | private String msg;
11 | private Object[] args;
12 | private Element element;
13 |
14 | public ProcessorException(Element element, String msg, Object... args) {
15 | this.msg=msg;
16 | this.args=args;
17 | this.element=element;
18 | }
19 |
20 | public Element getElement() {
21 | return element;
22 | }
23 |
24 | @Override
25 | public String getMessage() {
26 | return String.format(msg,args);
27 |
28 | }
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dilpreet2028/fragmenter/6e343323e1d81e726ce0a934faec69fd114b13af/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
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-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/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 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
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 Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':fragmenter-annotations', ':fragmenter-compiler'
2 |
--------------------------------------------------------------------------------