1 19 20 package org.netbeans.modules.updatecenters.resources; 21 22 import java.io.File ; 23 import java.io.FileOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 import java.util.StringTokenizer ; 29 import org.netbeans.modules.autoupdate.AutoupdateClusterCreator; 30 31 32 36 public final class NetBeansClusterCreator extends AutoupdateClusterCreator { 37 protected File findCluster(String clusterName) { 38 File [] parent = new File [1]; 39 File conf = findConf(parent, new ArrayList <File >()); 40 return conf != null && conf.isFile() && conf.canWrite() ? new File (parent[0], clusterName) : null; 41 } 42 43 private static File findConf(File [] parent, List <? super File > clusters) { 44 StringTokenizer tok = new StringTokenizer (System.getProperty("netbeans.dirs"), File.pathSeparator); while (tok.hasMoreElements()) { 46 File cluster = new File (tok.nextToken()); 47 clusters.add(cluster); 48 if (!cluster.exists()) { 49 continue; 50 } 51 52 53 54 if (parent[0] == null) { 55 parent[0] = cluster.getParentFile(); 56 } 57 58 if (!parent[0].equals(cluster.getParentFile())) { 59 return null; 62 } 63 } 64 65 return new File (new File (parent[0], "etc"), "netbeans.clusters"); 66 } 67 68 protected File [] registerCluster(String clusterName, File cluster) throws IOException { 69 File [] parent = new File [1]; 70 List <File > clusters = new ArrayList <File >(); 71 File conf = findConf(parent, clusters); 72 assert conf != null; 73 clusters.add(cluster); 74 OutputStream os = new FileOutputStream (conf, true); 75 os.write('\n'); 76 os.write(clusterName.getBytes()); 77 os.write('\n'); 78 os.close(); 79 return clusters.toArray(new File [0]); 80 } 81 } 82 | Popular Tags |