Skip to content

Commit

Permalink
Allow ElasticsearchJavaPlugin for non-jar based projects
Browse files Browse the repository at this point in the history
Some standalone projects such as :distribution:archives:integ-test-zip have tests
but are not intended to ever create a jar. Applying the new ElasticsearchJavaPlugin
in favor over the elder "Standalone*Plugin" or BuildPlugin can result in these non-jar
projects erroring due to the lack of the license or notice file.

To avoid creating more permutations of ElasticsearchJavaPlugin
(i.e. ElasticsearchJavaPluginWithoutJar), the conuming project should be able disable
the jar task (e.g. `jar.enabled = false`) and the license checks should be skipped as
well as the javadoc and sources jars.

related: elastic#56841
  • Loading branch information
jakelandis committed May 20, 2020
1 parent 8a086ba commit 235e3e8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,48 +398,43 @@ static void configureJars(Project project) {
ExtraPropertiesExtension ext = project.getExtensions().getExtraProperties();
ext.set("licenseFile", null);
ext.set("noticeFile", null);
project.getTasks()
.withType(Jar.class)
.configureEach(
jarTask -> {
// we put all our distributable files under distributions
jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions"));
// fixup the jar manifest
jarTask.doFirst(
t -> {
// this doFirst is added before the info plugin, therefore it will run
// after the doFirst added by the info plugin, and we can override attributes
jarTask.getManifest()
.attributes(
Map.of(
"Build-Date",
BuildParams.getBuildDate(),
"Build-Java-Version",
BuildParams.getCompilerJavaVersion()
)
);
}
);
}
);
project.getTasks().withType(Jar.class).configureEach(jarTask -> {
if (jarTask.isEnabled()) {
// we put all our distributable files under distributions
jarTask.getDestinationDirectory().set(new File(project.getBuildDir(), "distributions"));
// fixup the jar manifest
jarTask.doFirst(
t -> {
// this doFirst is added before the info plugin, therefore it will run
// after the doFirst added by the info plugin, and we can override attributes
jarTask.getManifest()
.attributes(
Map.of("Build-Date", BuildParams.getBuildDate(), "Build-Java-Version", BuildParams.getCompilerJavaVersion())
);
}
);
}
});
// add license/notice files
project.afterEvaluate(p -> project.getTasks().withType(Jar.class).configureEach(jarTask -> {
File licenseFile = (File) ext.get("licenseFile");
File noticeFile = (File) ext.get("noticeFile");
if (licenseFile == null || noticeFile == null) {
throw new GradleException("Must specify license and notice file for project");
}
if (jarTask.isEnabled()) {
File licenseFile = (File) ext.get("licenseFile");
File noticeFile = (File) ext.get("noticeFile");
if (licenseFile == null || noticeFile == null) {
throw new GradleException("Must specify license and notice file for project");
}

jarTask.metaInf(spec -> {
spec.from(licenseFile.getParent(), from -> {
from.include(licenseFile.getName());
from.rename(s -> "LICENSE.txt");
jarTask.metaInf(spec -> {
spec.from(licenseFile.getParent(), from -> {
from.include(licenseFile.getName());
from.rename(s -> "LICENSE.txt");
});
spec.from(noticeFile.getParent(), from -> {
from.include(noticeFile.getName());
from.rename(s -> "NOTICE.txt");
});
});
spec.from(noticeFile.getParent(), from -> {
from.include(noticeFile.getName());
from.rename(s -> "NOTICE.txt");
});
});
}
}));
project.getPluginManager().withPlugin("com.github.johnrengelman.shadow", p -> {
project.getTasks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private static void configureJavadocJar(Project project) {
project.getPlugins().withId("elasticsearch.java", p -> {
TaskProvider<Jar> javadocJarTask = project.getTasks().register("javadocJar", Jar.class);
javadocJarTask.configure(jar -> {
jar.setEnabled(project.getTasks().getByName("jar").getEnabled());
jar.getArchiveClassifier().set("javadoc");
jar.setGroup("build");
jar.setDescription("Assembles a jar containing javadocs.");
Expand All @@ -145,6 +146,7 @@ static void configureSourcesJar(Project project) {
project.getPlugins().withId("elasticsearch.java", p -> {
TaskProvider<Jar> sourcesJarTask = project.getTasks().register("sourcesJar", Jar.class);
sourcesJarTask.configure(jar -> {
jar.setEnabled(project.getTasks().getByName("jar").getEnabled());
jar.getArchiveClassifier().set("sources");
jar.setGroup("build");
jar.setDescription("Assembles a jar containing source files.");
Expand Down

0 comments on commit 235e3e8

Please sign in to comment.