Skip to content

Commit

Permalink
Use the right file permission API, depending on the Gradle version
Browse files Browse the repository at this point in the history
  • Loading branch information
jbartok committed Sep 13, 2024
1 parent 312e3c6 commit f594f59
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package org.gradle.playframework.plugins;

import org.gradle.api.Action;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.*;
import org.gradle.api.artifacts.ArtifactCollection;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.component.ComponentIdentifier;
Expand Down Expand Up @@ -122,13 +119,32 @@ private void createDistributionContentTasks(Project project, Distribution distri

distSpec.into("bin", copySpec -> {
copySpec.from(createStartScriptsTask);
copySpec.setFileMode(0755);
setFileMode(copySpec);
});

distSpec.into("conf", copySpec -> copySpec.from("conf").exclude("routes"));
distSpec.from("README");
}

private void setFileMode(CopySpec copySpec) {
try {
if (GradleVersion.current().compareTo(GradleVersion.version("8.3")) >= 0) {
copySpec.getClass().getMethod("filePermissions", Action.class)
.invoke(copySpec, (Action<?>) filePermission -> {
try {
filePermission.getClass().getMethod("unix", String.class).invoke(filePermission, "0755");
} catch (Exception e) {
throw new GradleException("Failed to set unix file permission", e);
}
});
} else {
copySpec.getClass().getMethod("setFileMode", Integer.class).invoke(copySpec, 0755);
}
} catch (Exception e) {
throw new GradleException("Failed to set file permissions", e);
}
}

private String getMainClass(PlayPlatform playPlatform) {
switch (PlayMajorVersion.forPlatform(playPlatform)) {
case PLAY_2_3_X:
Expand Down

0 comments on commit f594f59

Please sign in to comment.