Gradle: gradle build file can be used to resolve project info instead of gradle project dir

This commit is contained in:
Vladislav.Soroka
2013-09-11 12:34:33 +04:00
parent 09cdde1725
commit 68d131a1b1
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.settings.DistributionType;
import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import java.io.File;
import java.io.IOException;
@@ -134,19 +135,28 @@ public class GradleExecutionHelper {
public <T> T execute(@NotNull String projectPath, @Nullable GradleExecutionSettings settings, @NotNull Function<ProjectConnection, T> f) {
final String projectDir;
final File projectPathFile = new File(projectPath);
if (projectPathFile.isFile() && projectPath.endsWith(GradleConstants.EXTENSION)
&& projectPathFile.getParent() != null) {
projectDir = projectPathFile.getParent();
} else {
projectDir = projectPath;
}
// This is a workaround to get right base dir in case of 'PROJECT' setting used in case custom wrapper property file location
// see org.gradle.wrapper.PathAssembler#getBaseDir for details
String userDir = null;
if(settings != null && settings.getDistributionType() == DistributionType.WRAPPED) {
try {
userDir = System.getProperty("user.dir");
System.setProperty("user.dir", projectPath);
System.setProperty("user.dir", projectDir);
}
catch (Exception e) {
// ignore
}
}
ProjectConnection connection = getConnection(projectPath, settings);
ProjectConnection connection = getConnection(projectDir, settings);
try {
return f.fun(connection);
}