aboutsummaryrefslogtreecommitdiffstats
path: root/buildSrc/src/main/kotlin/tools/refinery/gradle/eclipse.gradle.kts
blob: 8bab1d2b4369671a45ed1ba80082a871fe02b413 (plain) (blame)
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
/*
 * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package tools.refinery.gradle

import java.util.Properties

plugins {
	eclipse
}

// Workaround from https://github.com/gradle/gradle/issues/898#issuecomment-885765821
val eclipseResourceEncoding by tasks.registering {
	val outputFile = file(".settings/org.eclipse.core.resources.prefs")
	val encoding = providers.systemProperty("file.encoding")

	inputs.property("file.encoding", encoding)
	outputs.file(outputFile)

	doLast {
		val eclipseEncodingProperties = Properties(2)
		eclipseEncodingProperties["eclipse.preferences.version"] = "1"
		eclipseEncodingProperties["encoding/<project>"] = encoding.get()
		outputFile.outputStream().use { outputStream ->
			eclipseEncodingProperties.store(outputStream, "generated by $name")
		}
	}
}

tasks.eclipse {
	dependsOn(eclipseResourceEncoding)
}

eclipse.synchronizationTasks(eclipseResourceEncoding)

tasks.register<Delete>("clobberEclipse") {
	mustRunAfter(tasks.eclipse)
	delete(".classpath")
	delete(".project")
	delete(".settings")
}