• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.support.build;
18 
19 import org.gradle.api.tasks.SourceSet;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 
25 /**
26  * Defines an API specific support library modules.
27  * e.g. Honeycomb implementation of Support-v4.
28  *
29  * These ApiModules are converted into real modules when project is opened in AndroidStudio.
30  * When project is run from the command line, they are converted into source sets.
31  * This allows us to rely on previous compile setup to deploy projects with their dependencies while
32  * supporting development on Android Studio.
33  */
34 public class ApiModule {
35     public static final int CURRENT = 99;
36     private String mFolderName;
37     private int mApi;
38     private SourceSet mSourceSet;
39     private ApiModule mPrev;
40     private String mParentModuleName;
41     private List<String> mParentModuleDependencies;
42     private List<String> mResourceFolders = new ArrayList<>();
43     private List<String> mAssetFolders = new ArrayList<>();
44     private List<String> mJavaResourceFolders = new ArrayList<>();
45 
ApiModule(String folderName, int api)46     public ApiModule(String folderName, int api) {
47         mFolderName = folderName;
48         mApi = api;
49     }
50 
resources(String... resourceFolders)51     public ApiModule resources(String... resourceFolders) {
52         Collections.addAll(mResourceFolders, resourceFolders);
53         return this;
54     }
55 
assets(String... assetFolders)56     public ApiModule assets(String... assetFolders) {
57         Collections.addAll(mAssetFolders, assetFolders);
58         return this;
59     }
60 
javaResources(String... javaResourceFolders)61     public ApiModule javaResources(String... javaResourceFolders) {
62         Collections.addAll(mJavaResourceFolders, javaResourceFolders);
63         return this;
64     }
65 
getResourceFolders()66     public List<String> getResourceFolders() {
67         return mResourceFolders;
68     }
69 
getAssetFolders()70     public List<String> getAssetFolders() {
71         return mAssetFolders;
72     }
73 
getJavaResourceFolders()74     public List<String> getJavaResourceFolders() {
75         return mJavaResourceFolders;
76     }
77 
setResourceFolders(List<String> resourceFolders)78     public void setResourceFolders(List<String> resourceFolders) {
79         mResourceFolders = resourceFolders;
80     }
81 
getParentModuleName()82     public String getParentModuleName() {
83         return mParentModuleName;
84     }
85 
setParentModuleName(String parentModuleName)86     public void setParentModuleName(String parentModuleName) {
87         mParentModuleName = parentModuleName;
88     }
89 
getFolderName()90     public String getFolderName() {
91         return mFolderName;
92     }
93 
getApi()94     public int getApi() {
95         return mApi;
96     }
97 
getApiForSourceSet()98     public Object getApiForSourceSet() {
99         return mApi == CURRENT ? "current" : mApi;
100     }
101 
getSourceSet()102     public SourceSet getSourceSet() {
103         return mSourceSet;
104     }
105 
setSourceSet(SourceSet sourceSet)106     public void setSourceSet(SourceSet sourceSet) {
107         mSourceSet = sourceSet;
108     }
109 
getPrev()110     public ApiModule getPrev() {
111         return mPrev;
112     }
113 
setPrev(ApiModule prev)114     public void setPrev(ApiModule prev) {
115         mPrev = prev;
116     }
117 
getModuleName()118     public String getModuleName() {
119         return ":" + mParentModuleName + "-" + mFolderName;
120     }
121 
getParentModuleDependencies()122     public List<String> getParentModuleDependencies() {
123         return mParentModuleDependencies;
124     }
125 
setParentModuleDependencies(List<String> parentModuleDependencies)126     public void setParentModuleDependencies(List<String> parentModuleDependencies) {
127         mParentModuleDependencies = parentModuleDependencies;
128     }
129 }
130