This repository has been archived by the owner on Nov 10, 2023. It is now read-only.
/
AndroidLibraryRule.java
151 lines (129 loc) · 4.42 KB
/
AndroidLibraryRule.java
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright 2012-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.facebook.buck.android;
import com.facebook.buck.java.AnnotationProcessingParams;
import com.facebook.buck.java.DefaultJavaLibraryRule;
import com.facebook.buck.java.JavacOptions;
import com.facebook.buck.model.BuildTarget;
import com.facebook.buck.model.BuildTargetPattern;
import com.facebook.buck.rules.SourcePath;
import com.facebook.buck.rules.BuildContext;
import com.facebook.buck.rules.BuildRuleParams;
import com.facebook.buck.rules.BuildRuleResolver;
import com.facebook.buck.rules.BuildRuleType;
import com.facebook.buck.rules.RuleKey;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.Set;
public class AndroidLibraryRule extends DefaultJavaLibraryRule {
/**
* Manifest to associate with this rule. Ultimately, this will be used with the upcoming manifest
* generation logic.
*/
private final Optional<String> manifestFile;
@VisibleForTesting
public AndroidLibraryRule(BuildRuleParams buildRuleParams,
Set<String> srcs,
Set<SourcePath> resources,
Optional<String> proguardConfig,
JavacOptions javacOptions,
Optional<String> manifestFile) {
super(buildRuleParams,
srcs,
resources,
proguardConfig,
/* exportDeps */ false,
javacOptions);
this.manifestFile = Preconditions.checkNotNull(manifestFile);
}
@Override
public BuildRuleType getType() {
return BuildRuleType.ANDROID_LIBRARY;
}
public Optional<String> getManifestFile() {
return manifestFile;
}
@Override
public boolean isAndroidRule() {
return true;
}
@Override
protected RuleKey.Builder appendToRuleKey(RuleKey.Builder builder) {
return super.appendToRuleKey(builder)
.set("manifest", manifestFile.orNull());
}
@Override
protected List<String> getInputsToCompareToOutput(BuildContext context) {
if (manifestFile.isPresent()) {
return ImmutableList.<String>builder()
.addAll(super.getInputsToCompareToOutput(context))
.add(manifestFile.get())
.build();
} else {
return super.getInputsToCompareToOutput(context);
}
}
public static Builder newAndroidLibraryRuleBuilder() {
return new Builder();
}
public static class Builder extends DefaultJavaLibraryRule.Builder {
private Optional<String> manifestFile = Optional.absent();
@Override
public AndroidLibraryRule build(BuildRuleResolver ruleResolver) {
BuildRuleParams buildRuleParams = createBuildRuleParams(ruleResolver);
AnnotationProcessingParams processingParams =
annotationProcessingBuilder.build(ruleResolver);
javacOptions.setAnnotationProcessingData(processingParams);
return new AndroidLibraryRule(
buildRuleParams,
srcs,
resources,
proguardConfig,
javacOptions.build(),
manifestFile);
}
@Override
public Builder setBuildTarget(BuildTarget buildTarget) {
super.setBuildTarget(buildTarget);
return this;
}
@Override
public Builder addDep(BuildTarget dep) {
super.addDep(dep);
return this;
}
@Override
public AndroidLibraryRule.Builder addSrc(String src) {
return (AndroidLibraryRule.Builder)super.addSrc(src);
}
@Override
public Builder addVisibilityPattern(BuildTargetPattern visibilityPattern) {
super.addVisibilityPattern(visibilityPattern);
return this;
}
@Override
public AnnotationProcessingParams.Builder getAnnotationProcessingBuilder() {
return annotationProcessingBuilder;
}
public Builder setManifestFile(Optional<String> manifestFile) {
this.manifestFile = Preconditions.checkNotNull(manifestFile);
return this;
}
}
}