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

Updated AppPaths.java for better gradle compatibility #5472

Closed
wants to merge 4 commits into from
Closed
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 @@ -32,7 +32,18 @@ public enum BuildTool {
GRADLE;

public static AppPaths.BuildTool findBuildTool() {
return System.getProperty("org.gradle.appname") == null ? MAVEN : GRADLE;
return System.getProperties()
.keySet()
.stream()
.map(String.class::cast)
.anyMatch(k -> k.contains("gradle")) ||
System.getProperties()
.values()
.stream()
.map(String.class::cast)
.anyMatch(v -> v.contains("gradle"))
? GRADLE
: MAVEN;
}
}

Expand All @@ -42,11 +53,12 @@ public static AppPaths.BuildTool findBuildTool() {
private final Collection<Path> classesPaths = new ArrayList<>();

private final boolean isJar;
private final BuildTool bt;
private final Path resourcesPath;
private final Path outputTarget;

public static AppPaths fromProjectDir(Path projectDir, Path outputTarget) {
return new AppPaths(Collections.singleton(projectDir), Collections.emptyList(), false, BuildTool.MAVEN, "main", outputTarget);
return new AppPaths(Collections.singleton(projectDir), Collections.emptyList(), false, BuildTool.findBuildTool(), "main", outputTarget);
}

/**
Expand All @@ -56,7 +68,7 @@ public static AppPaths fromProjectDir(Path projectDir, Path outputTarget) {
* @return
*/
public static AppPaths fromTestDir(Path projectDir) {
return new AppPaths(Collections.singleton(projectDir), Collections.emptyList(), false, BuildTool.MAVEN, "test", Paths.get(projectDir.toString(), TARGET_DIR));
return new AppPaths(Collections.singleton(projectDir), Collections.emptyList(), false, BuildTool.findBuildTool(), "test", Paths.get(projectDir.toString(), TARGET_DIR));
}

/**
Expand All @@ -69,6 +81,7 @@ public static AppPaths fromTestDir(Path projectDir) {
protected AppPaths(Set<Path> projectPaths, Collection<Path> classesPaths, boolean isJar, BuildTool bt,
String resourcesBasePath, Path outputTarget) {
this.isJar = isJar;
this.bt = bt;
this.projectPaths.addAll(projectPaths);
this.classesPaths.addAll(classesPaths);
this.outputTarget = outputTarget;
Expand All @@ -88,7 +101,9 @@ public Path[] getPaths() {
}

public Path getFirstProjectPath() {
return projectPaths.iterator().next();
return bt == BuildTool.MAVEN
? projectPaths.iterator().next()
: outputTarget;
}

private Path[] getJarPaths() {
Expand Down