1 19 20 package org.netbeans.modules.projectimport.eclipse; 21 22 import java.io.BufferedInputStream ; 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.util.Properties ; 28 import org.openide.filesystems.FileUtil; 29 30 36 public class EclipseUtils { 37 38 42 public static boolean isRegularProject(String projectDir) { 43 return projectDir != null && 44 isRegularProject(new File (projectDir.trim())); 45 } 46 47 51 public static boolean isRegularProject(File projectDir) { 52 return projectDir != null 53 && FileUtil.toFileObject(FileUtil.normalizeFile(projectDir)) != null 54 && projectDir.isDirectory() 55 && new File (projectDir, EclipseProject.PROJECT_FILE).isFile(); 56 } 57 58 62 public static boolean isRegularJavaProject(File projectDir) { 63 return isRegularProject(projectDir) && 64 new File (projectDir, EclipseProject.CLASSPATH_FILE).isFile(); 65 } 66 67 71 public static boolean isRegularJavaProject(String projectDir) { 72 return projectDir != null && 73 isRegularJavaProject(new File (projectDir.trim())); 74 } 75 76 80 public static boolean isRegularWorkSpace(String workspaceDir) { 81 return workspaceDir != null && 82 isRegularWorkSpace(new File (workspaceDir.trim())); 83 } 84 85 89 public static boolean isRegularWorkSpace(File workspaceDir) { 90 FileUtil.toFileObject(FileUtil.normalizeFile(workspaceDir)); 91 return workspaceDir != null 92 && FileUtil.toFileObject(FileUtil.normalizeFile(workspaceDir)) != null 93 && workspaceDir.isDirectory() 94 && new File (workspaceDir, Workspace.CORE_PREFERENCE).isFile() 95 && new File (workspaceDir, Workspace.LAUNCHING_PREFERENCES).isFile() 96 && new File (workspaceDir, Workspace.RESOURCE_PROJECTS_DIR).isDirectory(); 97 } 98 99 private static final String TMP_NAME = 100 "NB___TMP___ENOUGH___UNIQUE___CONSTANT___"; 102 public static boolean isWritable(String projectDestination) { 103 File tmpDir = new File (projectDestination.trim(), 104 (TMP_NAME + System.currentTimeMillis())); 105 if (tmpDir.mkdirs()) { 106 tmpDir.delete(); 107 return true; 108 } 109 return false; 110 } 111 112 119 static Properties loadProperties(File file) throws IOException { 120 InputStream propsIS = new BufferedInputStream (new FileInputStream (file)); 121 Properties properties = new Properties (); 122 try { 123 properties.load(propsIS); 124 } finally { 125 propsIS.close(); 126 } 127 return properties; 128 } 129 130 } 131 | Popular Tags |