Skip to content

Commit

Permalink
Update to Gradle 8.8
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Jun 10, 2024
1 parent 04a417a commit 13bf604
Show file tree
Hide file tree
Showing 27 changed files with 428 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,28 @@ private JavaVersion determineJavaVersion(String description, File javaHome, Java
}

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 @@ private void configureGeneralTaskDefaults(Project project) {
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 @@ -37,6 +37,8 @@
import org.gradle.api.Task;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.internal.artifacts.ivyservice.LenientConfigurationInternal;
import org.gradle.api.internal.artifacts.ivyservice.ResolvedFilesCollectingVisitor;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.tasks.TaskProvider;

Expand All @@ -53,9 +55,13 @@ public TaskProvider<? extends Task> createTask(Project project) {
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)
);

final ResolvedFilesCollectingVisitor visitor = new ResolvedFilesCollectingVisitor();
final LenientConfigurationInternal configuration = (LenientConfigurationInternal) runtimeClasspath.getResolvedConfiguration()
.getLenientConfiguration();

Check warning on line 61 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-L61

Added lines #L59 - L61 were not covered by tests
configuration.select(dependency -> dependency instanceof ProjectDependency == false).visitArtifacts(visitor, false);

t.setDependencies(project.files(visitor.getFiles()).minus(compileOnly));

Check warning on line 64 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#L64

Added line #L64 was not covered by tests
});

// we also create the updateShas helper task that is associated with dependencyLicenses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.FileTree;
import org.gradle.api.internal.artifacts.ivyservice.LenientConfigurationInternal;
import org.gradle.api.internal.artifacts.ivyservice.ResolvedFilesCollectingVisitor;
import org.gradle.api.provider.Property;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.CacheableTask;
Expand Down Expand Up @@ -203,11 +205,12 @@ public Set<File> getJarsToScan() {
// 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 = getFiles(getRuntimeConfiguration(), reallyThirdParty);
Set<File> compileOnlyConfiguration = getFiles(
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#L209-L211

Added lines #L209 - L211 were not covered by tests
reallyThirdParty
);
// 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 Expand Up @@ -286,6 +289,14 @@ public void runThirdPartyAudit() throws IOException {
Files.write(getSuccessMarker().toPath(), new byte[] {});
}

private Set<File> getFiles(Configuration configuration, Spec<Dependency> spec) {
final ResolvedFilesCollectingVisitor visitor = new ResolvedFilesCollectingVisitor();
final LenientConfigurationInternal cfg = (LenientConfigurationInternal) configuration.getResolvedConfiguration()
.getLenientConfiguration();
cfg.select(spec).visitArtifacts(visitor, false);
return visitor.getFiles();

Check warning on line 297 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#L293-L297

Added lines #L293 - L297 were not covered by tests
}

private void logForbiddenAPIsOutput(String forbiddenApisOutput) {
getLogger().error("Forbidden APIs output:\n{}==end of forbidden APIs==", forbiddenApisOutput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void visitSymbolicLink(final FileCopyDetailsInternal details) {
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 visitSymbolicLink(final FileCopyDetailsInternal details) {
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 visitDirectory(final FileCopyDetailsInternal details) {
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
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
60 changes: 44 additions & 16 deletions distribution/packages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
}
from(rootProject.projectDir) {
include 'README.md'
fileMode 0644
filePermissions {
unix 0644
}
}
into('lib') {
with libFiles()
Expand All @@ -183,9 +185,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
directory('/' + segments[0..i].join('/'), 0755)
}
if (segments[-2] == 'bin' || segments[-1] == 'jspawnhelper') {
fcp.mode = 0755
fcp.permissions(perm -> perm.unix(0755))
} else {
fcp.mode = 0644
fcp.permissions(perm -> perm.unix(0644))
}
}
}
Expand All @@ -195,7 +197,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
if (type == 'deb') {
into("/usr/share/doc/${packageName}") {
from "${packagingFiles}/copyright"
fileMode 0644
filePermissions {
unix 0644
}
}
} else {
assert type == 'rpm'
Expand All @@ -204,7 +208,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
include 'APACHE-LICENSE-2.0.txt'
rename { 'LICENSE.txt' }
}
fileMode 0644
filePermissions {
unix 0644
}
}
}

Expand All @@ -213,7 +219,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
configurationFile '/etc/opensearch/jvm.options'
configurationFile '/etc/opensearch/log4j2.properties'
from("${packagingFiles}") {
dirMode 0750
dirPermissions {
unix 0750
}
into('/etc')
permissionGroup 'opensearch'
includeEmptyDirs true
Expand All @@ -223,8 +231,12 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
}
from("${packagingFiles}/etc/opensearch") {
into('/etc/opensearch')
dirMode 0750
fileMode 0660
dirPermissions {
unix 0750
}
filePermissions{
unix 0660
}
permissionGroup 'opensearch'
includeEmptyDirs true
createDirectoryEntry true
Expand All @@ -235,34 +247,46 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
into(new File(envFile).getParent()) {
fileType CONFIG | NOREPLACE
permissionGroup 'opensearch'
fileMode 0660
filePermissions {
unix 0660
}
from "${packagingFiles}/env/opensearch"
}

// ========= systemd =========
into('/usr/lib/tmpfiles.d') {
from "${packagingFiles}/systemd/opensearch.conf"
fileMode 0644
filePermissions {
unix 0644
}
}
into('/usr/lib/systemd/system') {
fileType CONFIG | NOREPLACE
from "${packagingFiles}/systemd/opensearch.service"
fileMode 0644
filePermissions {
unix 0644
}
}
into('/usr/lib/sysctl.d') {
fileType CONFIG | NOREPLACE
from "${packagingFiles}/systemd/sysctl/opensearch.conf"
fileMode 0644
filePermissions {
unix 0644
}
}
into('/usr/share/opensearch/bin') {
from "${packagingFiles}/systemd/systemd-entrypoint"
fileMode 0755
filePermissions {
unix 0755
}
}

// ========= sysV init =========
configurationFile '/etc/init.d/opensearch'
into('/etc/init.d') {
fileMode 0750
filePermissions {
unix 0750
}
fileType CONFIG | NOREPLACE
from "${packagingFiles}/init.d/opensearch"
}
Expand All @@ -278,7 +302,9 @@ Closure commonPackageConfig(String type, boolean jdk, String architecture) {
createDirectoryEntry true
user u
permissionGroup g
dirMode mode
dirPermissions {
unix mode
}
}
}
copyEmptyDir('/var/log/opensearch', 'opensearch', 'opensearch', 0750)
Expand Down Expand Up @@ -341,7 +367,9 @@ Closure commonDebConfig(boolean jdk, String architecture) {

into('/usr/share/lintian/overrides') {
from('src/deb/lintian/opensearch')
fileMode 0644
filePermissions {
unix 0644
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=194717442575a6f96e1c1befa2c30e9a4fc90f701d7aee33eb879b79e7ff05c0
distributionSha256Sum=f8b4f4772d302c8ff580bc40d0f56e715de69b163546944f787c87abf209c961
Loading

0 comments on commit 13bf604

Please sign in to comment.