Skip to content

Commit

Permalink
Gradle projects can no longer be opened from the temporary directory …
Browse files Browse the repository at this point in the history
…to avoid annoying errors when NetBeans creates temporary build.gradle files in them.
  • Loading branch information
kelemen committed Aug 19, 2012
1 parent e8ca7a9 commit 95cab77
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/org/netbeans/gradle/project/NbGradleProjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class NbGradleProjectFactory implements ProjectFactory {
private static final Logger LOGGER = Logger.getLogger(NbGradleProjectFactory.class.getName());

private static ConcurrentMap<File, Counter> SAFE_TO_OPEN_PROJECTS = new ConcurrentHashMap<File, Counter>();
private static final String TEMP_DIR = System.getProperty("java.io.tmpdir");

public static Closeable safeToOpen(FileObject projectDir) {
File projectDirFile = FileUtil.toFile(projectDir);
Expand Down Expand Up @@ -59,6 +60,20 @@ public boolean isProject(FileObject projectDirectory) {
return true;
}

// We will not load projects from the temporary directory simply
// because NetBeans has a habit to put temporary gradle files to
// them and then tries to load it which will fail because NetBeans will
// delete them soon.
if (TEMP_DIR != null) {
File tempDir = FileUtil.normalizeFile(new File(TEMP_DIR));
FileObject tempDirObj = FileUtil.toFileObject(tempDir);
if (tempDirObj != null) {
if (FileUtil.getRelativePath(tempDirObj, projectDirectory) != null) {
return false;
}
}
}

return projectDirectory.getFileObject(GradleProjectConstants.BUILD_FILE_NAME) != null;
}

Expand Down

0 comments on commit 95cab77

Please sign in to comment.