blob: 1ae2e502ac5603a7ee9184c34046ec956d7feb8c [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
import java.nio.file.Files
import java.time.temporal.ChronoUnit
import java.time.Instant
// See LUCENE-9471. We redirect temporary location for gradle
// so that it doesn't pollute user's tmp. Wipe it during a clean though.
configure(rootProject) {
gradle.buildFinished {
// we clean up the java.io.tmpdir we've redirected gradle to use (LUCENE-9471).
// these are still used and populated with junk.
rootProject.delete fileTree(".gradle/tmp").matching {
include "gradle-worker-classpath*"
}
// clean up any files older than 3 hours from the user's gradle temp. the time
// limit is added so that we don't interfere with any concurrent builds... just in case.
Instant deadline = Instant.now().minus(3, ChronoUnit.HOURS);
def toDelete = new ArrayList<>()
def gradleTmp = gradle.gradleUserHomeDir.toPath().resolve(".tmp")
if (Files.exists(gradleTmp)) {
toDelete.add(Files.list(gradleTmp))
}
def daemonDir = gradle.gradleUserHomeDir.toPath().resolve("daemon").resolve("${gradle.gradleVersion}")
if (Files.exists(daemonDir)) {
toDelete.add(Files.list(daemonDir).filter(path -> path.toString().endsWith(".out.log")))
}
try (def stream = toDelete.stream().flatMap(p -> p)) {
stream.filter(p -> Files.isRegularFile(p))
.filter(p -> Files.getLastModifiedTime(p).toInstant().isBefore(deadline))
.forEach(p -> {
Files.deleteIfExists(p)
})
}
}
}
// Make sure we clean up after running tests.
allprojects {
plugins.withType(JavaPlugin) {
def temps = []
task wipeTaskTemp() {
doLast {
temps.each { temp ->
project.delete fileTree(temp).matching {
include "jar_extract*"
}
}
}
}
tasks.withType(Test) {
finalizedBy wipeTaskTemp
temps += temporaryDir
}
}
}