Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Gradle 8.8 (#13584) #14182

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,28 @@
}

private JvmInstallationMetadata getJavaInstallation(File javaHome) {
final InstallationLocation location = new InstallationLocation(javaHome, "Java home");
InstallationLocation location = null;

try {
try {
// The InstallationLocation(File, String) is used by Gradle pre-8.8
location = (InstallationLocation) MethodHandles.publicLookup()
.findConstructor(InstallationLocation.class, MethodType.methodType(void.class, File.class, String.class))
.invokeExact(javaHome, "Java home");

Check warning on line 209 in buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java#L208-L209

Added lines #L208 - L209 were not covered by tests
} catch (Throwable ex) {
// The InstallationLocation::userDefined is used by Gradle post-8.7
location = (InstallationLocation) MethodHandles.publicLookup()
.findStatic(
InstallationLocation.class,
"userDefined",
MethodType.methodType(InstallationLocation.class, File.class, String.class)
)
.invokeExact(javaHome, "Java home");

}
} catch (Throwable ex) {
throw new IllegalStateException("Unable to find suitable InstallationLocation constructor / factory method", ex);

Check warning on line 222 in buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java#L220-L222

Added lines #L220 - L222 were not covered by tests
}

try {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
project.getTasks().withType(AbstractCopyTask.class).configureEach(t -> {
t.dependsOn(project.getTasks().withType(EmptyDirTask.class));
t.setIncludeEmptyDirs(true);
t.setDirMode(0755);
t.setFileMode(0644);
t.dirPermissions(perms -> perms.unix(0755));
t.filePermissions(perms -> perms.unix(0644));

Check warning on line 152 in buildSrc/src/main/java/org/opensearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/internal/InternalDistributionArchiveSetupPlugin.java#L151-L152

Added lines #L151 - L152 were not covered by tests
});

// common config across all archives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@
package org.opensearch.gradle.precommit;

import org.opensearch.gradle.dependencies.CompileOnlyResolvePlugin;
import org.opensearch.gradle.util.GradleUtils;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.file.FileCollection;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.TaskProvider;

public class DependencyLicensesPrecommitPlugin extends PrecommitPlugin {
Expand All @@ -48,15 +51,16 @@
TaskProvider<DependencyLicensesTask> dependencyLicenses = project.getTasks()
.register("dependencyLicenses", DependencyLicensesTask.class);

final Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
final Configuration compileOnly = project.getConfigurations()
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
final Provider<FileCollection> provider = project.provider(
() -> GradleUtils.getFiles(project, runtimeClasspath, dependency -> dependency instanceof ProjectDependency == false)
.minus(compileOnly)

Check warning on line 59 in buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesPrecommitPlugin.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesPrecommitPlugin.java#L59

Added line #L59 was not covered by tests
);

// only require dependency licenses for non-opensearch deps
dependencyLicenses.configure(t -> {
Configuration runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);
Configuration compileOnly = project.getConfigurations()
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME);
t.setDependencies(
runtimeClasspath.fileCollection(dependency -> dependency instanceof ProjectDependency == false).minus(compileOnly)
);
});
dependencyLicenses.configure(t -> t.getDependencies().set(provider));

// we also create the updateShas helper task that is associated with dependencyLicenses
project.getTasks().register("updateShas", UpdateShasTask.class, t -> t.setParentTask(dependencyLicenses));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.gradle.api.file.FileCollection;
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputDirectory;
import org.gradle.api.tasks.InputFiles;
Expand Down Expand Up @@ -121,7 +122,7 @@
/**
* A collection of jar files that should be checked.
*/
private FileCollection dependencies;
private Property<FileCollection> dependenciesProvider;

/**
* The directory to find the license and sha files in.
Expand Down Expand Up @@ -158,12 +159,11 @@
}

@InputFiles
public FileCollection getDependencies() {
return dependencies;
}

public void setDependencies(FileCollection dependencies) {
this.dependencies = dependencies;
public Property<FileCollection> getDependencies() {
if (dependenciesProvider == null) {
dependenciesProvider = getProject().getObjects().property(FileCollection.class);
}
return dependenciesProvider;
}

@Optional
Expand All @@ -190,6 +190,11 @@

@TaskAction
public void checkDependencies() throws IOException, NoSuchAlgorithmException {
if (dependenciesProvider == null) {
throw new GradleException("No dependencies variable defined.");

Check warning on line 194 in buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/DependencyLicensesTask.java#L194

Added line #L194 was not covered by tests
}

final FileCollection dependencies = dependenciesProvider.get();
if (dependencies == null) {
throw new GradleException("No dependencies variable defined.");
}
Expand Down Expand Up @@ -226,7 +231,7 @@
}
}

checkDependencies(licenses, notices, sources, shaFiles);
checkDependencies(dependencies, licenses, notices, sources, shaFiles);

licenses.forEach((item, exists) -> failIfAnyMissing(item, exists, "license"));

Expand Down Expand Up @@ -255,6 +260,7 @@
}

private void checkDependencies(
FileCollection dependencies,
Map<String, Boolean> licenses,
Map<String, Boolean> notices,
Map<String, Boolean> sources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.opensearch.gradle.LoggedExec;
import org.opensearch.gradle.OS;
import org.opensearch.gradle.dependencies.CompileOnlyResolvePlugin;
import org.opensearch.gradle.util.GradleUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.JavaVersion;
import org.gradle.api.artifacts.Configuration;
Expand Down Expand Up @@ -203,11 +204,13 @@
// or dependencies added as `files(...)`, we can't be sure if those are third party or not.
// err on the side of scanning these to make sure we don't miss anything
Spec<Dependency> reallyThirdParty = dep -> dep.getGroup() != null && dep.getGroup().startsWith("org.opensearch") == false;
Set<File> jars = getRuntimeConfiguration().getResolvedConfiguration().getFiles(reallyThirdParty);
Set<File> compileOnlyConfiguration = getProject().getConfigurations()
.getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME)
.getResolvedConfiguration()
.getFiles(reallyThirdParty);

Set<File> jars = GradleUtils.getFiles(getProject(), getRuntimeConfiguration(), reallyThirdParty).getFiles();
Set<File> compileOnlyConfiguration = GradleUtils.getFiles(
getProject(),
getProject().getConfigurations().getByName(CompileOnlyResolvePlugin.RESOLVEABLE_COMPILE_ONLY_CONFIGURATION_NAME),

Check warning on line 211 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L208-L211

Added lines #L208 - L211 were not covered by tests
reallyThirdParty
).getFiles();

Check warning on line 213 in buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/precommit/ThirdPartyAuditTask.java#L213

Added line #L213 was not covered by tests
// don't scan provided dependencies that we already scanned, e.x. don't scan cores dependencies for every plugin
if (compileOnlyConfiguration != null) {
jars.removeAll(compileOnlyConfiguration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public UpdateShasTask() {
public void updateShas() throws NoSuchAlgorithmException, IOException {
Set<File> shaFiles = parentTask.get().getShaFiles();

for (File dependency : parentTask.get().getDependencies()) {
for (File dependency : parentTask.get().getDependencies().get()) {
String jarName = dependency.getName();
File shaFile = parentTask.get().getShaFile(jarName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
visitedSymbolicLinks.add(details.getFile());
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString(), TarConstants.LF_SYMLINK);
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.LINK_FLAG | details.getMode());
entry.setMode(UnixStat.LINK_FLAG | details.getPermissions().toUnixNumeric());

Check warning on line 187 in buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java#L187

Added line #L187 was not covered by tests
try {
entry.setLinkName(Files.readSymbolicLink(details.getFile().toPath()).toString());
tar.putArchiveEntry(entry);
Expand All @@ -197,7 +197,7 @@
private void visitDirectory(final FileCopyDetailsInternal details) {
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString() + "/");
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.DIR_FLAG | details.getMode());
entry.setMode(UnixStat.DIR_FLAG | details.getPermissions().toUnixNumeric());

Check warning on line 200 in buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java#L200

Added line #L200 was not covered by tests
try {
tar.putArchiveEntry(entry);
tar.closeArchiveEntry();
Expand All @@ -209,7 +209,7 @@
private void visitFile(final FileCopyDetailsInternal details) {
final TarArchiveEntry entry = new TarArchiveEntry(details.getRelativePath().getPathString());
entry.setModTime(getModTime(details));
entry.setMode(UnixStat.FILE_FLAG | details.getMode());
entry.setMode(UnixStat.FILE_FLAG | details.getPermissions().toUnixNumeric());

Check warning on line 212 in buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/tar/SymbolicLinkPreservingTar.java#L212

Added line #L212 was not covered by tests
entry.setSize(details.getSize());
try {
tar.putArchiveEntry(entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,17 @@
import org.gradle.api.UnknownTaskException;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.LenientConfiguration;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.artifacts.ivyservice.ResolvedFilesCollectingVisitor;
import org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.SelectedArtifactSet;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.services.BuildService;
import org.gradle.api.services.BuildServiceRegistration;
import org.gradle.api.services.BuildServiceRegistry;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskContainer;
Expand All @@ -53,6 +58,9 @@
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
import org.gradle.plugins.ide.idea.model.IdeaModel;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -245,4 +253,22 @@
int lastDelimiterIndex = taskPath.lastIndexOf(":");
return lastDelimiterIndex == 0 ? ":" : taskPath.substring(0, lastDelimiterIndex);
}

public static FileCollection getFiles(Project project, Configuration cfg, Spec<Dependency> spec) {
final LenientConfiguration configuration = cfg.getResolvedConfiguration().getLenientConfiguration();

Check warning on line 258 in buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java#L258

Added line #L258 was not covered by tests
try {
// Using reflection here to cover the pre 8.7 releases (since those have no such APIs), the
// ResolverResults.LegacyResolverResults.LegacyVisitedArtifactSet::select(...) is not available
// on older versions.
final MethodHandle mh = MethodHandles.lookup()
.findVirtual(configuration.getClass(), "select", MethodType.methodType(SelectedArtifactSet.class, Spec.class))
.bindTo(configuration);

Check warning on line 265 in buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java#L263-L265

Added lines #L263 - L265 were not covered by tests

final ResolvedFilesCollectingVisitor visitor = new ResolvedFilesCollectingVisitor();
((SelectedArtifactSet) mh.invoke(spec)).visitArtifacts(visitor, false);
return project.files(visitor.getFiles());
} catch (Throwable ex) {
return project.files(configuration.getFiles(spec));

Check warning on line 271 in buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/util/GradleUtils.java#L267-L271

Added lines #L267 - L271 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private TaskProvider<DependencyLicensesTask> createDependencyLicensesTask(Projec
.register("dependencyLicenses", DependencyLicensesTask.class, new Action<DependencyLicensesTask>() {
@Override
public void execute(DependencyLicensesTask dependencyLicensesTask) {
dependencyLicensesTask.setDependencies(getDependencies(project));
dependencyLicensesTask.getDependencies().set(getDependencies(project));

final Map<String, String> mappings = new HashMap<>();
mappings.put("from", "groovy-.*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void whenDependencyExistsButShaNotThenShouldCreateNewShaFile() throws IOE
public void whenDependencyAndWrongShaExistsThenShouldNotOverwriteShaFile() throws IOException, NoSuchAlgorithmException {
project.getDependencies().add("someCompileConfiguration", dependency);

File groovyJar = task.getParentTask().getDependencies().getFiles().iterator().next();
File groovyJar = task.getParentTask().getDependencies().get().getFiles().iterator().next();
String groovyShaName = groovyJar.getName() + ".sha1";

File groovySha = createFileIn(getLicensesDir(project), groovyShaName, "content");
Expand Down Expand Up @@ -162,7 +162,7 @@ private TaskProvider<DependencyLicensesTask> createDependencyLicensesTask(Projec
.register("dependencyLicenses", DependencyLicensesTask.class, new Action<DependencyLicensesTask>() {
@Override
public void execute(DependencyLicensesTask dependencyLicensesTask) {
dependencyLicensesTask.setDependencies(getDependencies(project));
dependencyLicensesTask.getDependencies().set(getDependencies(project));
}
});

Expand Down
20 changes: 15 additions & 5 deletions distribution/archives/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
with libFiles()
}
into('config') {
dirMode 0750
fileMode 0660
dirPermissions {
unix 0750
}
filePermissions {
unix 0660
}
with configFiles(distributionType, java)
from {
dirMode 0750
dirPermissions {
unix 0750
}
jvmOptionsDir.getParent()
}
}
Expand All @@ -61,13 +67,17 @@ CopySpec archiveFiles(CopySpec modulesFiles, String distributionType, String pla
}
into('') {
from {
dirMode 0755
dirPermissions {
unix 0755
}
logsDir.getParent()
}
}
into('') {
from {
dirMode 0755
dirPermissions {
unix 0755
}
pluginsDir.getParent()
}
}
Expand Down
12 changes: 6 additions & 6 deletions distribution/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
if (it.relativePath.segments[-2] == 'bin' || ((platform == 'darwin-x64' || platform == 'darwin-arm64') && it.relativePath.segments[-2] == 'MacOS')) {
// bin files, wherever they are within modules (eg platform specific) should be executable
// and MacOS is an alternative to bin on macOS
it.mode = 0755
it.permissions(perm -> perm.unix(0755))
} else {
it.mode = 0644
it.permissions(perm -> perm.unix(0644))
}
}
def buildModules = buildModulesTaskProvider
Expand Down Expand Up @@ -413,7 +413,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
from '../src/bin'
exclude '*.exe'
exclude '*.bat'
eachFile { it.setMode(0755) }
eachFile { it.permissions(perm -> perm.unix(0755)) }
MavenFilteringHack.filter(it, expansionsForDistribution(distributionType, java))
}
// windows files, only for zip
Expand All @@ -431,7 +431,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
// module provided bin files
with copySpec {
eachFile { it.setMode(0755) }
eachFile { it.permissions(perm -> perm.unix(0755)) }
from project(':distribution').buildBin
if (distributionType != 'zip') {
exclude '*.bat'
Expand Down Expand Up @@ -473,7 +473,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
eachFile { FileCopyDetails details ->
if (details.relativePath.segments[-2] == 'bin' || details.relativePath.segments[-1] == 'jspawnhelper') {
details.mode = 0755
details.permissions(perm -> perm.unix(0755))
}
if (details.name == 'src.zip') {
details.exclude()
Expand Down Expand Up @@ -501,7 +501,7 @@ configure(subprojects.findAll { ['archives', 'packages'].contains(it.name) }) {
}
eachFile { FileCopyDetails details ->
if (details.relativePath.segments[-2] == 'bin' || details.relativePath.segments[-1] == 'jspawnhelper') {
details.mode = 0755
details.permissions(perm -> perm.unix(0755))
}
}
}
Expand Down
Loading
Loading