1 19 20 package org.netbeans.modules.java.j2seproject.api; 21 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.OutputStream ; 25 26 import java.util.Properties ; 27 28 import org.netbeans.api.project.Project; 29 import org.netbeans.api.project.ProjectManager; 30 31 import org.openide.filesystems.FileObject; 32 import org.openide.filesystems.FileSystem; 33 import org.openide.filesystems.FileUtil; 34 35 import org.openide.util.Mutex; 36 import org.openide.util.MutexException; 37 38 44 public final class J2SEProjectConfigurations { 45 46 J2SEProjectConfigurations() {} 47 48 60 public static void createConfigurationFiles(Project prj, String configName, 61 final Properties sharedProps, final Properties privateProps) throws IOException , IllegalArgumentException { 62 63 if (prj == null || configName == null || "".equals(configName)) { 64 throw new IllegalArgumentException (); 65 } 66 67 final String configFileName = configName + ".properties"; final FileObject prjDir = prj.getProjectDirectory(); 69 70 try { 71 ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void >() { 72 public Void run() throws IOException { 73 prjDir.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() { 74 public void run() throws IOException { 75 generateConfig(prjDir, "nbproject/configs/" + configFileName, sharedProps); generateConfig(prjDir, "nbproject/private/configs/" + configFileName, privateProps); } 78 }); 79 return null; 80 } 81 }); 82 } catch (MutexException ex) { 83 throw (IOException ) ex.getException(); 84 } 85 86 } 87 88 private static void generateConfig(FileObject prjDir, String cfgFilePath, Properties propsToWrite) throws IOException { 89 90 if (propsToWrite == null) { 91 return; 93 } 94 FileObject jwsConfigFO = FileUtil.createData(prjDir, cfgFilePath); 95 Properties props = new Properties (); 96 InputStream is = jwsConfigFO.getInputStream(); 97 props.load(is); 98 is.close(); 99 if (props.equals(propsToWrite)) { 100 return; 102 } 103 OutputStream os = jwsConfigFO.getOutputStream(); 104 propsToWrite.store(os, null); 105 os.close(); 106 107 } 108 109 } 110 | Popular Tags |