aboutsummaryrefslogtreecommitdiff
path: root/buildScripts/compile.ant.xml
blob: 5baf50c387a1c2e0c15f52aa14498eb01bc56181 (plain)
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<!--
 Copyright (C) 2020 The Project Lombok Authors.
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
-->
<project name="lombok.compile" default="dist" xmlns:ivy="antlib:com.zwitserloot.ivyplusplus" basedir="..">
	<description>
This buildfile is part of projectlombok.org. It takes care of compiling and building lombok itself.
	</description>
	
	<property name="mapstruct-binding.version" value="0.1.0" />
	
	<!-- compiles just 'version.java' and runs the produced class file, setting up the various version properties -->
	<target name="version" depends="ipp.setup, deps.jdk-runtime" description="Shows the version number" unless="lombok.version">
		<mkdir dir="build/lombok" />
		<ivy:compile destdir="build/lombok" source="1.5" target="1.5" ecj="true" nowarn="true">
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/core" />
			<include name="lombok/core/Version.java" />
		</ivy:compile>
		<java
			classname="lombok.core.Version"
			classpath="build/lombok"
			failonerror="true"
			output="build/version.txt">
			<arg value="full" />
		</java>
		<ivy:loadversion property="lombok.fullversion" file="build/version.txt" />
		<java
			classname="lombok.core.Version"
			classpath="build/lombok"
			failonerror="true"
			output="build/version.txt" />
		<ivy:loadversion property="lombok.version" file="build/version.txt" />
		<echo level="info">Lombok version: ${lombok.version} (${lombok.fullversion})</echo>
	</target>
	
	<target name="compile" depends="version, deps" description="Compiles the code">
		<!--
			1. Compile stubs.
			2. Compile lombok-utils.
			3. Compile transplants.
			4. Compile lombok.
			5. Run SPI processor.
			6. Create other manifest entries. -->
		
		<!--
			ant includes the destination dir on the classpath (and there are good reasons to do this), but that also means
			the bleeding edge lombok from the previous build is run (as lombok is an annotation processor), which means if
			there are bugs in it, you can't compile anymore until you 'ant clean'. That's very undesirable. so we kill the processor,
			which stops lombok from running. We re-create the file at the end of this target. -->
		<delete file="build/lombok/META-INF/services/javax.annotation.processing.Processor" quiet="true" />
		
		<!--
			first, compile stubs. Lombok needs to produce class files that run in a wide variety of JDK, javac, and ecj/eclipse versions.
			Instead of depending on conflicting versions, we write stub files; just enough for compilation to succeed.
			
			However, the stubs themselves also have a ton of dependencies; to avoid _that_, we have stubs for stubs, too! -->
		<ivy:compile destdir="build/stubsstubs" source="1.5" target="1.5" ecj="true">
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/stubsstubs" />
		</ivy:compile>
		<ivy:compile destdir="build/stubs" source="1.5" target="1.5" ecj="true">
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/stubs" />
			<src path="src/javac-only-stubs" />
			<classpath location="build/stubsstubs" />
			<classpath location="build/stubs" />
		</ivy:compile>
		
		<!--
			compile the eclipse agent's transplant sources.
			This is code that is not actually run within lombok; it is bytecode that the eclipse agent extracts from the class file
			within its own jar and injects it into the eclipse classes as a patch.
			
			To keep the project clean of warnings, a few SuppressWarnings have been added, but we don't want them there during compilation,
			so remove them first.
			
			For legacy eclipse support we include them in both class file format 48 (java 1.4) and 50 (java 1.6), though in practice
			we don't support eclipses that run on anything below java 1.8 anymore. -->
		<mkdir dir="build/transformedSources" />
		<copy todir="build/transformedSources">
			<fileset dir="src/eclipseAgent">
				<include name="**/*Transplants.java" />
			</fileset>
			<filterchain>
				<lineContainsRegExp negate="true">
					<regexp pattern="^\s*@SuppressWarnings.*$" />
				</lineContainsRegExp>
			</filterchain>
		</copy>
		
		<ivy:compile destdir="build/lombok" source="1.4" target="1.4" ecj="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="build/transformedSources" />
		</ivy:compile>
		
		<ivy:compile destdir="build/lombok/Class50" source="1.4" target="1.6" ecj="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="build/transformedSources" />
		</ivy:compile>
		
		<ivy:compile destdir="build/lombok" source="1.5" target="1.5" ecj="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/utils" />
			<exclude name="lombok/javac/**" />
			<classpath path="build/lombok" />
			<classpath refid="cp.javac6" />
			<classpath refid="cp.ecj8" />
		</ivy:compile>
		<ivy:compile destdir="build/lombok" source="1.6" target="1.6" ecj="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/utils" />
			<include name="lombok/javac/**" />
			<classpath location="build/lombok" />
			<classpath refid="cp.javac6" />
		</ivy:compile>
		
		<!--
			compile lombok proper. We target java 1.6 to be as compatible with older releases as we can, using a JDK6 boot rt to ensure we don't
			use API that didn't exist in those versions yet. -->
		<ivy:compile destdir="build/lombok" source="1.6" target="1.6" ecj="true" nowarn="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/launch" />
			<src path="src/core" />
			<src path="src/installer" />
			<src path="src/eclipseAgent" />
			<src path="src/delombok" />
			<exclude name="**/*Transplants.java" />
			<classpath location="build/lombok" />
			<classpath refid="cp.build" />
			<classpath refid="cp.eclipse-oxygen" />
			<classpath refid="cp.javac6" />
		</ivy:compile>
		
		<!-- This is really part of the eclipse agent, but references lombok, so that had to be compiled first -->
		<ivy:compile destdir="build/lombok/Class50" source="1.5" target="1.6" ecj="true">
			<bootclasspath location="build/stubs" />
			<bootclasspath path="${jdk6-rt.loc}" />
			<src path="src/eclipseAgent" />
			<include name="lombok/launch/PatchFixesHider.java" />
			<classpath location="build/lombok" />
			<classpath refid="cp.build" />
			<classpath refid="cp.eclipse-oxygen" />
		</ivy:compile>
		
		<!--
			a couple of classes to cater to the bits of javac8+ that require j8 language constructs/API types; the main lombok
			compile refers to these via reflection -->
		<ivy:compile destdir="build/lombok" source="1.8" target="1.8" ecj="true" nowarn="true" includesystembootclasspath="true">
			<bootclasspath location="build/stubs" />
			<src path="src/core8" />
			<classpath location="build/lombok" />
			<classpath refid="cp.javac8" />
		</ivy:compile>
		
		<!--
			We also act as a jigsaw module so that module-based compile runs can use module-style dependency management. Obviously,
			that bit we can only compile with jdk9+. -->
		<ivy:compile destdir="build/lombok" release="9">
			<src path="src/core9" />
			<compilerarg value="-Xlint:none" />
			<classpath location="build/lombok" />
			<classpath refid="cp.build" />
		</ivy:compile>
		
		<!-- Run the SPI processor to create the services files listing all lombok handlers -->
		<delete dir="build/lombok-proc-result" quiet="true" />
		<ivy:compile destdir="build/lombok-proc-result" release="9" nowarn="true">
			<classpath location="build/stubs" />
			<compilerarg value="-proc:only" />
			<compilerarg value="-processor" />
			<compilerarg value="org.mangosdk.spi.processor.SpiProcessor" />
			<src path="src/core" />
			<src path="src/installer" />
			<src path="src/eclipseAgent" />
			<src path="src/delombok" />
			<classpath location="build/lombok" />
			<classpath refid="cp.build" />
			<classpath refid="cp.javac6" />
			<classpath refid="cp.eclipse-oxygen" />
		</ivy:compile>
		
		<copy todir="build/lombok">
			<fileset dir="build/lombok-proc-result">
				<include name="META-INF/services/*" />
			</fileset>
		</copy>
		
		<mkdir dir="build/lombok/META-INF" />
		<mkdir dir="build/lombok/META-INF/services" />
		<echo file="build/lombok/META-INF/services/javax.annotation.processing.Processor">lombok.launch.AnnotationProcessorHider$AnnotationProcessor
lombok.launch.AnnotationProcessorHider$ClaimingProcessor</echo>
		<mkdir dir="build/lombok/META-INF/gradle" />
		<echo file="build/lombok/META-INF/gradle/incremental.annotation.processors">lombok.launch.AnnotationProcessorHider$AnnotationProcessor,isolating
lombok.launch.AnnotationProcessorHider$ClaimingProcessor,isolating</echo>
	</target>
	
	<!-- compiles the bit of API from mapstruct that lombok compiles against. -->
	<target name="mapstruct.compile">
		<mkdir dir="build/mapstruct" />
		<ivy:compile destdir="build/mapstruct" release="9">
			<src path="src/j9stubs" />
		</ivy:compile>
		<mkdir dir="build/lombok/secondaryLoading.SCL.lombok/org/mapstruct/ap/spi" />
		<move
			file="build/mapstruct/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.class"
			tofile="build/lombok/secondaryLoading.SCL.lombok/org/mapstruct/ap/spi/AstModifyingAnnotationProcessor.SCL.lombok" />
	</target>
	
	<target name="-deps.unpack" depends="deps">
		<ivy:cachedunjar dest="build/lombok" marker="build/unpackDeps.marker">
			<path refid="cp.stripe" />
		</ivy:cachedunjar>
	</target>
	
	<target name="dist" depends="version, compile, latest-changes.build, mapstruct.compile, -deps.unpack" description="Builds the 'everything' lombok.jar">
		<mkdir dir="dist" />
		<copy file="doc/changelog.markdown" tofile="build/changelog.txt" />
		<tstamp><format property="release.timestamp" pattern="yyyy-MM-dd" /></tstamp>
		<echo file="release-timestamp.txt">${release.timestamp}</echo>
		
		<!-- the ant jar task doesn't quite let us do all we need to, so build with zip, then do the jar bits afterwards -->
		<zip destfile="dist/lombok-${lombok.version}.jar">
			<fileset dir="build" includes="changelog.txt, latestchanges.html" />
			<fileset dir="." includes="README.md, LICENSE, AUTHORS, release-timestamp.txt" />
			
			<!--
				most class files that need to be in the lombok distro are loaded in a separate class loader;
				we want any project that includes lombok.jar as a dependency to NOT get a bunch of otherwise public
				lombok classes served up in autocomplete dialogs, amongst other reasons.
				
				Thus, we list here only the few class files that serve as 'entry points'. -->
			<fileset dir="build/lombok">
				<include name="module-info.class" />
				<include name="lombok/*.class" />
				<include name="lombok/experimental/**" />
				<include name="lombok/extern/**" />
				<include name="lombok/launch/**" />
				<include name="lombok/delombok/ant/Tasks*" />
				<include name="lombok/javac/apt/Processor.class" />
				<include name="lombok/META-INF/**" />
			</fileset>
			
			<!-- now include everything else but renamed for the shadowloader system, to make these clsases invisible to other projects. -->
			<mappedresources>
				<fileset dir="build/lombok">
					<exclude name="com/sun/tools/javac/**" />
					<exclude name="module-info.class" />
					<exclude name="lombok/*.class" />
					<exclude name="lombok/experimental/**" />
					<exclude name="lombok/extern/**" />
					<exclude name="lombok/launch/**" />
					<exclude name="lombok/delombok/ant/Tasks*" />
					<exclude name="lombok/javac/apt/Processor.class" />
					<exclude name="lombok/META-INF/**" />
				</fileset>
				<firstmatchmapper>
					<globmapper from="*.class" to="*.SCL.lombok" />
					<identitymapper />
				</firstmatchmapper>
			</mappedresources>
		</zip>
		
		<!-- ... but manifest is not part of the ant zip task, so do that with the jar task -->
		<jar destfile="dist/lombok-${lombok.version}.jar" update="true">
			<manifest>
				<attribute name="Premain-Class" value="lombok.launch.Agent" />
				<attribute name="Agent-Class" value="lombok.launch.Agent" />
				<attribute name="Can-Redefine-Classes" value="true" />
				<attribute name="Main-Class" value="lombok.launch.Main" />
				<attribute name="Lombok-Version" value="${lombok.version}" />
			</manifest>
		</jar>
		<delete file="release-timestamp.txt" />
		<copy overwrite="true" tofile="dist/lombok.jar" file="dist/lombok-${lombok.version}.jar" />
		<property name="lombok.dist.built" value="true" />
	</target>
	
	<target name="compile.support" depends="ipp.setup, deps" description="Compiles code that is used solely by the build, such as website and IDE project creation">
		<ivy:compile includeDestClasses="false" includeantruntime="false" destdir="build/support" debug="on" source="1.8" target="1.8">
			<compilerarg value="-proc:none" />
			<compilerarg value="-Xlint:-options" />
			<classpath refid="cp.buildtools" />
			<src path="src/support" />
		</ivy:compile>
	</target>
</project>