[python.core] Fix Mac OS X platform auto-detection.
Default platform directories were not being traversed correctly.
1.1 --- a/python.core/src/org/netbeans/modules/python/api/PythonAutoDetector.java Sat Jun 06 20:52:24 2015 +0200
1.2 +++ b/python.core/src/org/netbeans/modules/python/api/PythonAutoDetector.java Tue Jun 23 01:41:09 2015 -0700
1.3 @@ -43,6 +43,9 @@
1.4 package org.netbeans.modules.python.api;
1.5
1.6 import java.io.File;
1.7 +import java.io.FileFilter;
1.8 +import java.nio.file.Files;
1.9 +import java.nio.file.Paths;
1.10 import java.util.ArrayList;
1.11 import java.util.logging.Level;
1.12 import java.util.logging.Logger;
1.13 @@ -181,41 +184,51 @@
1.14 // /Library/Frameworks/Python.framework/Versions/3.4/bin/python3
1.15 // and
1.16 // /System/Library/Frameworks/Python.framework/Versions/2.7/
1.17 - public void traverseMacDirectories( File dir) {
1.18 - if (dir.isDirectory()) { //this directory better end with "versions" !
1.19 - String spath = dir.getName();
1.20 - if( !(spath.toLowerCase().contains("versions")) ){
1.21 - return;
1.22 + public void traverseMacDirectories(File dir) {
1.23 +
1.24 + // Make sure the path is a directory named "Versions".
1.25 + if (! dir.getName().endsWith("Versions") || ! dir.isDirectory()) {
1.26 + return;
1.27 + }
1.28 +
1.29 + // Directories which are not symbolic links.
1.30 + FileFilter directoriesOnlyFilter = new FileFilter() {
1.31 + @Override
1.32 + public boolean accept(File file) {
1.33 + return file.isDirectory() &! Files.isSymbolicLink(Paths.get(file.getAbsolutePath()));
1.34 }
1.35 - // check the "next,next" (grandchild) level for the bin dir...
1.36 - String[] children = dir.list();
1.37 - if(children != null){
1.38 - for (String child : children) { //2.7, 3.4
1.39 - File childDir = new File(child);
1.40 - if (childDir.isDirectory()){
1.41 - String[] grandchildren = childDir.list(); // within, for example, 2.7
1.42 - for (String grandchild : grandchildren) {
1.43 - File gcDir = new File(grandchild);
1.44 - if (gcDir.isDirectory()) {
1.45 - String gcpath = gcDir.getName();
1.46 - if( gcpath.toLowerCase().contains("bin") ){ //find the bin directory
1.47 - String[] ggrandchildren = childDir.list();
1.48 - for (String ggrandchild : ggrandchildren) { // for all the files in the bin directory
1.49 - File ggcFile = new File(ggrandchild);
1.50 - if (ggcFile.isFile()) {
1.51 - searchNestedDirectoies = false; // must set each time
1.52 - processAction(ggcFile); // let processAction determine correctness of filename
1.53 - }
1.54 - }
1.55 - }
1.56 - }
1.57 - }
1.58 - }
1.59 + };
1.60 +
1.61 + // "bin" directory
1.62 + FileFilter binDirectoryFilter = new FileFilter() {
1.63 + @Override
1.64 + public boolean accept(File file) {
1.65 + return file.getName().equals("bin") && file.isDirectory();
1.66 + }
1.67 + };
1.68 +
1.69 + File[] versionDirs = dir.listFiles(directoriesOnlyFilter);
1.70 + File[] binDirs; // Should have either 0 or 1 element.
1.71 + File[] binContents;
1.72 + for (File versionDir : versionDirs) {
1.73 + binDirs = versionDir.listFiles(binDirectoryFilter);
1.74 + if (binDirs.length < 1) {
1.75 + continue;
1.76 + }
1.77 +
1.78 + File binDir = binDirs[0];
1.79 + binContents = binDir.listFiles(new FileFilter(){
1.80 + @Override public boolean accept(File file){
1.81 + return file.isFile(); // Regular files only.
1.82 }
1.83 - }
1.84 - }
1.85 - }
1.86 -
1.87 + });
1.88 +
1.89 + for (File binContent : binContents) {
1.90 + searchNestedDirectoies = false;
1.91 + processAction(binContent);
1.92 + }
1.93 + }// END for each version dir
1.94 + }
1.95
1.96 // Given a directory, for each subdirectory within,
1.97 // search the subdirectory and next-level subdirectories only