1 19 20 package org.netbeans.modules.projectimport.jbuilder.ui; 21 22 import java.io.File ; 23 import java.util.Collection ; 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.LinkedList ; 27 import org.netbeans.modules.projectimport.j2seimport.AbstractProject; 28 import org.netbeans.modules.projectimport.j2seimport.WarningContainer; 29 import org.netbeans.modules.projectimport.j2seimport.ui.WarningMessage; 30 import org.openide.util.NbBundle; 31 32 36 final class Utils { 37 38 39 private Utils() {} 40 41 static boolean checkNotFoundUserLibraries(Collection prjDefs) { 42 boolean notfound = notFoundUserLibraries(prjDefs).size() > 0; 43 if (!notfound && prjDefs != null) { 44 for (Iterator it = prjDefs.iterator(); it.hasNext();) { 45 AbstractProject prj = (AbstractProject) it.next(); 46 if (prj.getJdkId() != null && prj.getJDKDirectory() == null) return true; 47 } 48 } 49 return notfound; 50 } 51 52 private static Collection notFoundUserLibraries(Collection allPrjDefs) { 53 Collection notFoundUserLibraries = new HashSet (); 54 if (allPrjDefs != null) { 55 Iterator prjsIt = allPrjDefs.iterator(); 56 while (prjsIt.hasNext()) { 57 AbstractProject ap = (AbstractProject)prjsIt.next(); 58 Iterator it = ap.getUserLibraries().iterator(); 59 while (it.hasNext()) { 60 AbstractProject.UserLibrary uLib = (AbstractProject.UserLibrary)it.next(); 61 if (uLib.fileNotFound()) { 62 notFoundUserLibraries.add(uLib); 63 } 64 } 65 } 66 } 67 68 return notFoundUserLibraries; 69 } 70 71 static Collection getInvalidUserLibraries(Collection allPrjDefs) { 72 Collection invalidUserLibraries = new HashSet (); 73 if (allPrjDefs != null) { 74 Iterator prjsIt = allPrjDefs.iterator(); 75 while (prjsIt.hasNext()) { 76 AbstractProject ap = (AbstractProject)prjsIt.next(); 77 if (ap.getJDKDirectory() == null && ap.getJdkId() != null) { 78 invalidUserLibraries.add(new AbstractProject.UserLibrary(ap.getJdkId(), false)); 79 } 80 Iterator it = ap.getUserLibraries().iterator(); 81 while (it.hasNext()) { 82 AbstractProject.UserLibrary uLib = (AbstractProject.UserLibrary)it.next(); 83 if (!uLib.isValid()) { 84 invalidUserLibraries.add(uLib); 85 } 86 } 87 } 88 } 89 90 return invalidUserLibraries; 91 } 92 93 static StringBuffer getDependencyErrors(Collection prjDefs, File destinationDir) { 94 return getProjectsErrors(collectAllDependencies(prjDefs), destinationDir); 95 } 96 97 static StringBuffer getProjectsErrors(Collection prjDefs, File destinationDir) { 98 StringBuffer errBuf = null; 99 if (prjDefs != null) { 100 for (Iterator it = prjDefs.iterator(); it.hasNext();) { 101 AbstractProject ap = (AbstractProject)it.next(); 102 File importLocation = new File (destinationDir, ap.getName()); 103 104 if (ap.getErrors().size() > 0 || importLocation.exists()) { 105 errBuf = (errBuf == null) ? new StringBuffer () : errBuf; 106 for (Iterator errIt = ap.getErrors().iterator(); errIt.hasNext();) { 107 errBuf.append((String )errIt.next()).append(" "); } 109 if (importLocation.exists()) { 110 String errMsg = NbBundle.getMessage(JBWizardPanel.class, 111 "MSG_ProjectAlreadyExists",importLocation.getAbsolutePath()); errBuf.append(errMsg).append(" "); } 114 } 115 } 116 } 117 return errBuf; 118 } 119 120 static String getHtmlWarnings(Collection prjDefs) { 121 Collection all = new LinkedList (); 122 if (prjDefs != null) { 123 for (Iterator it = prjDefs.iterator(); it.hasNext();) { 124 AbstractProject ap = (AbstractProject)it.next(); 125 all.addAll(ap.getWarnings().getAllWarnings()); 126 } 127 } 128 129 return (all.isEmpty()) ? null : 130 WarningMessage.createHtmlString("",all.iterator(), true, 4); } 132 133 private static Collection collectAllDependencies(Collection prjDefs) { 134 Collection result = new HashSet (); 135 if (prjDefs != null && prjDefs.size() > 0) { 136 for (Iterator it = prjDefs.iterator(); it.hasNext();) { 137 AbstractProject ap = (AbstractProject)it.next(); 138 for (Iterator depsIt = ap.getDependencies().iterator(); depsIt.hasNext();) { 139 AbstractProject dep = (AbstractProject)depsIt.next(); 140 result.add(dep); 141 } 142 143 } 144 if (result.size() > 0) { 145 result.addAll(collectAllDependencies(result)); 146 } 147 } 148 149 return result; 150 } 151 } 152 | Popular Tags |