-
Notifications
You must be signed in to change notification settings - Fork 4.6k
/
AbstractCompile.java
170 lines (153 loc) · 5.71 KB
/
AbstractCompile.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* Copyright 2010 the original author or authors.
*
* 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 org.gradle.api.tasks.compile;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
import org.gradle.api.model.ReplacedBy;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Classpath;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.SourceTask;
import org.gradle.internal.deprecation.DeprecationLogger;
import org.gradle.work.DisableCachingByDefault;
import java.io.File;
/**
* The base class for all JVM-based language compilation tasks.
*/
@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly")
public abstract class AbstractCompile extends SourceTask {
private final DirectoryProperty destinationDirectory;
private FileCollection classpath;
private String sourceCompatibility;
private String targetCompatibility;
public AbstractCompile() {
this.destinationDirectory = getProject().getObjects().directoryProperty();
}
/**
* Returns the classpath to use to compile the source files.
*
* @return The classpath.
*/
@Classpath
public FileCollection getClasspath() {
return classpath;
}
/**
* Sets the classpath to use to compile the source files.
*
* @param configuration The classpath. Must not be null, but may be empty.
*/
public void setClasspath(FileCollection configuration) {
this.classpath = configuration;
}
/**
* Returns the directory property that represents the directory to generate the {@code .class} files into.
*
* @return The destination directory property.
* @since 6.1
*/
@OutputDirectory
public DirectoryProperty getDestinationDirectory() {
return destinationDirectory;
}
/**
* Returns the directory to generate the {@code .class} files into.
*
* @return The destination directory.
*
* @deprecated Use {@link #getDestinationDirectory()} instead. This method will be removed in Gradle 9.0.
*/
@ReplacedBy("destinationDirectory")
@Deprecated
public File getDestinationDir() {
// Used in Kotlin plugin - needs updating there and bumping the version first. Followup with https://github.com/gradle/gradle/issues/16783
DeprecationLogger.deprecateProperty(AbstractCompile.class, "destinationDir")
.replaceWith("destinationDirectory")
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "compile_task_wiring")
.nagUser();
return destinationDirectory.getAsFile().getOrNull();
}
/**
* Sets the directory to generate the {@code .class} files into.
*
* @param destinationDir The destination directory. Must not be null.
*
* @deprecated Use {@link #getDestinationDirectory()}.set() instead. This method will be removed in Gradle 9.0.
*/
@Deprecated
public void setDestinationDir(File destinationDir) {
DeprecationLogger.deprecateProperty(AbstractCompile.class, "destinationDir")
.replaceWith("destinationDirectory")
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "compile_task_wiring")
.nagUser();
this.destinationDirectory.set(destinationDir);
}
/**
* Sets the directory to generate the {@code .class} files into.
*
* @param destinationDir The destination directory. Must not be null.
* @since 4.0
*
* @deprecated Use {@link #getDestinationDirectory()}.set() instead. This method will be removed in Gradle 9.0.
*/
@Deprecated
public void setDestinationDir(Provider<File> destinationDir) {
// Used by Android plugin. Followup with https://github.com/gradle/gradle/issues/16782
DeprecationLogger.deprecateProperty(AbstractCompile.class, "destinationDir")
.replaceWith("destinationDirectory")
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "compile_task_wiring")
.nagUser();
this.destinationDirectory.set(getProject().getLayout().dir(destinationDir));
}
/**
* Returns the Java language level to use to compile the source files.
*
* @return The source language level.
*/
@Input
public String getSourceCompatibility() {
return sourceCompatibility;
}
/**
* Sets the Java language level to use to compile the source files.
*
* @param sourceCompatibility The source language level. Must not be null.
*/
public void setSourceCompatibility(String sourceCompatibility) {
this.sourceCompatibility = sourceCompatibility;
}
/**
* Returns the target JVM to generate the {@code .class} files for.
*
* @return The target JVM.
*/
@Input
public String getTargetCompatibility() {
return targetCompatibility;
}
/**
* Sets the target JVM to generate the {@code .class} files for.
*
* @param targetCompatibility The target JVM. Must not be null.
*/
public void setTargetCompatibility(String targetCompatibility) {
this.targetCompatibility = targetCompatibility;
}
}