Skip to content
Permalink
Browse files

Make build incremental

Reviewed-by: rwestberg
  • Loading branch information
Erik Helin
Erik Helin committed Sep 24, 2019
1 parent 6ba889e commit 65f572880fe41b0ad206fc96082616cbbbdfff32
@@ -91,29 +91,27 @@ configure(subprojects.findAll() { it.name != 'bots' }) {
}
}

task jar {
subprojects.findAll() { it.name != 'bots' }.each { dependsOn "${it.path}:jar" }
task test {
subprojects.findAll() { !it.getTasksByName('test', false).isEmpty() }.each { dependsOn "${it.path}:test" }
}

task test {
subprojects.findAll() { it.name != 'bots' }.each { dependsOn "${it.path}:test" }
task clean {
subprojects.findAll() { !it.getTasksByName('clean', false).isEmpty() }.each { dependsOn "${it.path}:clean" }
}

reproduce {
dockerfile = 'test.dockerfile'
}

task deleteBuildDir(type: Delete) {
delete project.buildDir
}

task local(type: Copy) {
doFirst {
delete project.buildDir
}
def os = System.getProperty('os.name').toLowerCase()
def osName = os.startsWith('win') ? 'Windows' :
os.startsWith('mac') ? 'Macos' : 'Linux'

dependsOn ':cli:image' + osName
dependsOn deleteBuildDir
from zipTree(file(project.rootDir.toString() +
'/cli/build/distributions/cli' +
'-' + project.version + '-' +
@@ -26,6 +26,9 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.OutputDirectory;
import org.gradle.api.tasks.Input;
import org.gradle.api.provider.Property;

import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@@ -42,20 +45,29 @@
import java.util.Comparator;

public class DownloadJDKTask extends DefaultTask {
private String url;
private String sha256;
private Path toDir;
private final Property<String> url;
private final Property<String> sha256;
private final Property<Path> toDir;

public DownloadJDKTask() {
url = getProject().getObjects().property(String.class);
sha256 = getProject().getObjects().property(String.class);
toDir = getProject().getObjects().property(Path.class);
}

void setUrl(String url) {
this.url = url;
@Input
Property<String> getUrl() {
return url;
}

void setSha256(String sha256) {
this.sha256 = sha256;
@Input
Property<String> getSha256() {
return sha256;
}

void setToDir(Path toDir) {
this.toDir = toDir;
@OutputDirectory
Property<Path> getToDir() {
return toDir;
}

private static String checksum(Path file) throws IOException {
@@ -101,27 +113,27 @@ private void unpack(Path file, Path dist) throws IOException {

@TaskAction
void download() throws IOException, InterruptedException {
var uri = URI.create(url);
var uri = URI.create(url.get());
var filename = Path.of(uri.getPath()).getFileName().toString();
var file = toDir.resolve(filename).toAbsolutePath();
var dist = toDir.resolve(filename.replace(".zip", "").replace(".tar.gz", ""));
var file = toDir.get().resolve(filename).toAbsolutePath();
var dist = toDir.get().resolve(filename.replace(".zip", "").replace(".tar.gz", ""));

if (Files.exists(dist) && Files.isDirectory(dist)) {
return;
}

if (Files.exists(file)) {
var sum = checksum(file);
if (sum.equals(sha256)) {
if (sum.equals(sha256.get())) {
unpack(file, dist);
return;
} else {
Files.delete(file);
}
}

if (!Files.exists(toDir)) {
Files.createDirectories(toDir);
if (!Files.exists(toDir.get())) {
Files.createDirectories(toDir.get());
}

var client = HttpClient.newHttpClient();
@@ -131,11 +143,11 @@ void download() throws IOException, InterruptedException {

var res = client.send(req, BodyHandlers.ofFile(file));
if (res.statusCode() >= 300) {
throw new GradleException("could not download " + url + ", got " + res.statusCode());
throw new GradleException("could not download " + url.get() + ", got " + res.statusCode());
}

var sum = checksum(file);
if (!sum.equals(sha256)) {
if (!sum.equals(sha256.get())) {
throw new GradleException("checksums do not match, actual: " + sum + ", expected: " + sha256);
}

@@ -24,9 +24,12 @@
package org.openjdk.skara.gradle.images;

import org.gradle.api.*;
import org.gradle.api.file.Directory;
import org.gradle.api.tasks.bundling.*;
import org.gradle.api.artifacts.UnknownConfigurationException;

import java.util.ArrayList;
import java.io.File;

public class ImagesPlugin implements Plugin<Project> {
@Override
@@ -51,31 +54,41 @@ public void execute(ImageEnvironment env) {

var downloadTaskName = "download" + subName + "JDK";
project.getTasks().register(downloadTaskName, DownloadJDKTask.class, (task) -> {
task.setUrl(env.getUrl());
task.setSha256(env.getSha256());
task.setToDir(rootDir.resolve(".jdk"));
task.getUrl().set(env.getUrl());
task.getSha256().set(env.getSha256());
task.getToDir().set(rootDir.resolve(".jdk"));
});

var linkTaskName = "link" + subName;
project.getTasks().register(linkTaskName, LinkTask.class, (task) -> {
for (var build : project.getRootProject().getGradle().getIncludedBuilds()) {
task.dependsOn(build.task(":jar"));
for (var jarTask : project.getTasksByName("jar", true)) {
if (jarTask instanceof Jar) {
task.getModulePath().add(((Jar) jarTask).getArchiveFile());
}
}

try {
var runtimeClasspath = project.getConfigurations().getByName("runtimeClasspath");
task.getRuntimeModules().addAll(runtimeClasspath.getElements());
task.dependsOn(runtimeClasspath);
} catch (UnknownConfigurationException e) {
// ignored
}
task.dependsOn(project.getRootProject().getTasksByName("jar", true));

task.dependsOn(projectPath + ":" + downloadTaskName);
task.setToDir(buildDir.resolve("images"));
task.setUrl(env.getUrl());
task.setOS(name);
task.getToDir().set(buildDir.resolve("images"));
task.getUrl().set(env.getUrl());
task.getOS().set(name);
task.getLaunchers().set(env.getLaunchers());
task.getModules().set(env.getModules());
});

var launchersTaskName = "launchers" + subName;
project.getTasks().register(launchersTaskName, LaunchersTask.class, (task) -> {
task.getLaunchers().set(env.getLaunchers());
task.setOptions(env.getOptions());
task.setToDir(buildDir.resolve("launchers"));
task.setOS(name);
task.getOptions().set(env.getOptions());
task.getToDir().set(buildDir.resolve("launchers"));
task.getOS().set(name);
});

var zipTaskName = "bundleZip" + subName;
@@ -35,27 +35,32 @@
import java.util.Comparator;

public class LaunchersTask extends DefaultTask {
private Path toDir;
private String os;
private Property<Path> toDir;
private Property<String> os;
private MapProperty<String, String> launchers;
private ListProperty<String> options;

@Inject
public LaunchersTask(ObjectFactory factory) {
this.launchers = factory.mapProperty(String.class, String.class);
toDir = factory.property(Path.class);
os = factory.property(String.class);
launchers = factory.mapProperty(String.class, String.class);
options = factory.listProperty(String.class);
}

void setOptions(ListProperty<String> options) {
this.options.set(options);
@Input
ListProperty<String> getOptions() {
return options;
}

void setToDir(Path toDir) {
this.toDir = toDir;
@OutputDirectory
Property<Path> getToDir() {
return toDir;
}

void setOS(String os) {
this.os = os;
@Input
Property<String> getOS() {
return os;
}

@Input
@@ -72,7 +77,7 @@ private static void clearDirectory(Path directory) throws IOException {

@TaskAction
void generate() throws IOException {
var dest = toDir.resolve(os);
var dest = toDir.get().resolve(os.get());
if (Files.isDirectory(dest)) {
clearDirectory(dest);
}

0 comments on commit 65f5728

Please sign in to comment.
You can’t perform that action at this time.