Skip to content

Commit 7b98f88

Browse files
committed
Find more potential maven binary locations
1 parent a77b83d commit 7b98f88

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/EnsureMavenBinaryIsExecutable.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
11
package fi.helsinki.cs.tmc.actions;
22

3+
import java.io.File;
34
import java.io.IOException;
45
import java.nio.file.Files;
56
import java.nio.file.Path;
67
import java.nio.file.Paths;
78
import java.nio.file.attribute.PosixFilePermission;
89
import java.util.Set;
10+
import org.openide.modules.InstalledFileLocator;
911

1012
public class EnsureMavenBinaryIsExecutable {
1113

1214
private final static Path RELATIVE_MAVEN_LOCATION = Paths.get("java").resolve("maven").resolve("bin").resolve("mvn");
1315

14-
private final Path mavenPath;
16+
private Path mavenPath;
1517
private final boolean isUnix;
1618

1719
public EnsureMavenBinaryIsExecutable() {
20+
this.isUnix = !System.getProperty("os.name").startsWith("Windows");
21+
}
22+
23+
public void run() {
24+
if (!isUnix) {
25+
return;
26+
}
1827
Path pathCandidate = Paths.get(System.getProperty("user.dir")).resolve(RELATIVE_MAVEN_LOCATION);
1928
if (Files.exists(pathCandidate)) {
2029
this.mavenPath = pathCandidate;
2130
} else {
2231
this.mavenPath = Paths.get(System.getProperty("user.dir")).resolve("../").resolve(RELATIVE_MAVEN_LOCATION);
2332
}
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)) {
2937
return;
3038
}
39+
tryToChmod(mavenPath);
40+
}
41+
42+
private void tryToChmod(Path path) {
3143
try {
32-
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(mavenPath);
44+
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(path);
3345
if (!permissions.contains(PosixFilePermission.OWNER_EXECUTE)) {
3446
permissions.add(PosixFilePermission.OWNER_EXECUTE);
35-
Files.setPosixFilePermissions(mavenPath, permissions);
47+
Files.setPosixFilePermissions(path, permissions);
3648
}
3749
} catch (IOException ex) { }
3850
}

0 commit comments

Comments
 (0)