|
1 | 1 | package fi.helsinki.cs.tmc.actions;
|
2 | 2 |
|
| 3 | +import java.io.File; |
3 | 4 | import java.io.IOException;
|
4 | 5 | import java.nio.file.Files;
|
5 | 6 | import java.nio.file.Path;
|
6 | 7 | import java.nio.file.Paths;
|
7 | 8 | import java.nio.file.attribute.PosixFilePermission;
|
8 | 9 | import java.util.Set;
|
| 10 | +import org.openide.modules.InstalledFileLocator; |
9 | 11 |
|
10 | 12 | public class EnsureMavenBinaryIsExecutable {
|
11 | 13 |
|
12 | 14 | private final static Path RELATIVE_MAVEN_LOCATION = Paths.get("java").resolve("maven").resolve("bin").resolve("mvn");
|
13 | 15 |
|
14 |
| - private final Path mavenPath; |
| 16 | + private Path mavenPath; |
15 | 17 | private final boolean isUnix;
|
16 | 18 |
|
17 | 19 | public EnsureMavenBinaryIsExecutable() {
|
| 20 | + this.isUnix = !System.getProperty("os.name").startsWith("Windows"); |
| 21 | + } |
| 22 | + |
| 23 | + public void run() { |
| 24 | + if (!isUnix) { |
| 25 | + return; |
| 26 | + } |
18 | 27 | Path pathCandidate = Paths.get(System.getProperty("user.dir")).resolve(RELATIVE_MAVEN_LOCATION);
|
19 | 28 | if (Files.exists(pathCandidate)) {
|
20 | 29 | this.mavenPath = pathCandidate;
|
21 | 30 | } else {
|
22 | 31 | this.mavenPath = Paths.get(System.getProperty("user.dir")).resolve("../").resolve(RELATIVE_MAVEN_LOCATION);
|
23 | 32 | }
|
24 |
| - this.isUnix = !System.getProperty("os.name").startsWith("Windows"); |
25 |
| - } |
26 |
| - |
27 |
| - public void run() { |
28 |
| - if (!isUnix || !Files.exists(mavenPath)) { |
| 33 | + for (File file : InstalledFileLocator.getDefault().locateAll(".", null, false)) { |
| 34 | + tryToChmod(Paths.get(file.getAbsolutePath()).resolve("..").resolve(RELATIVE_MAVEN_LOCATION)); |
| 35 | + } |
| 36 | + if (!Files.exists(mavenPath)) { |
29 | 37 | return;
|
30 | 38 | }
|
| 39 | + tryToChmod(mavenPath); |
| 40 | + } |
| 41 | + |
| 42 | + private void tryToChmod(Path path) { |
31 | 43 | try {
|
32 |
| - Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(mavenPath); |
| 44 | + Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(path); |
33 | 45 | if (!permissions.contains(PosixFilePermission.OWNER_EXECUTE)) {
|
34 | 46 | permissions.add(PosixFilePermission.OWNER_EXECUTE);
|
35 |
| - Files.setPosixFilePermissions(mavenPath, permissions); |
| 47 | + Files.setPosixFilePermissions(path, permissions); |
36 | 48 | }
|
37 | 49 | } catch (IOException ex) { }
|
38 | 50 | }
|
|
0 commit comments