1 19 20 package org.netbeans.modules.apisupport.project.universe; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.net.URI ; 25 import java.net.URISyntaxException ; 26 import java.net.URL ; 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import org.netbeans.api.project.FileOwnerQuery; 30 import org.netbeans.api.project.Project; 31 import org.netbeans.modules.apisupport.project.NbModuleProject; 32 import org.netbeans.modules.apisupport.project.Util; 33 import org.netbeans.spi.project.SubprojectProvider; 34 import org.openide.filesystems.FileObject; 35 import org.openide.filesystems.FileUtil; 36 37 40 public final class TestEntry { 41 42 private static final String JAR_NAME = "tests.jar"; private static final String QA_FUNCTIONAL = "qa-functional"; private static final String UNIT = "unit"; 46 private static final String TEST_DIST_DIR = "nbbuild/build/testdist"; private final String codeNameBase; 48 private final boolean unit; 49 private final String cluster; 50 private final File jarFile; 51 52 55 private TestEntry(File jarFile,String codeNameBase,boolean unit,String cluster) { 56 this.jarFile = jarFile; 57 this.codeNameBase = codeNameBase; 58 this.unit = unit; 59 this.cluster = cluster; 60 61 } 62 68 public static TestEntry get(File jarFile) { 69 String path = jarFile.getPath().replace(File.separatorChar,'/'); 71 if (path.endsWith(JAR_NAME)) { 72 String tokens[] = path.split("/"); 73 int len = tokens.length; 74 if (len > 3 ) { 75 String cnb = tokens[len - 2].replace('-','.') ; 76 String cluster = tokens[len - 3]; 77 String testType = tokens[len - 4]; 78 boolean unit = true; 79 if (!testType.equals(UNIT)) { 80 if (testType.equals(QA_FUNCTIONAL)) { 81 unit = false; 82 } else { 83 return null; 84 } 85 } 86 return new TestEntry(jarFile,cnb,unit,cluster); 87 } 88 } 89 return null; 90 } 91 92 public String getCodeNameBase() { 93 return codeNameBase; 94 } 95 96 public boolean isUnit() { 97 return unit; 98 } 99 100 public String getCluster() { 101 return (cluster == null) ? "cluster" : cluster; } 104 105 public File getJarFile() { 106 return jarFile; 107 } 108 109 111 public File getTestDistRoot() { 112 return getJarFile().getParentFile().getParentFile().getParentFile().getParentFile(); 113 } 114 115 118 public URL getSrcDir() throws IOException { 119 String nborgPath = getNetBeansOrgPath(); 120 if (nborgPath != null) { 121 return new File (getNBCVSRoot(),nborgPath).toURI().toURL(); 122 } 123 File prjDir = getTestDistRoot(); 124 while(!prjDir.exists()) { 126 prjDir = prjDir.getParentFile(); 127 if (prjDir == null) { 128 return null; 130 } 131 } 132 Project prj = FileOwnerQuery.getOwner(FileUtil.toFileObject(prjDir)); 133 if (prj != null) { 134 SubprojectProvider subprojects = (SubprojectProvider) prj.getLookup().lookup(SubprojectProvider.class); 136 if (subprojects != null) { 137 Set <? extends Project> projects = subprojects.getSubprojects(); 138 for (Iterator it = projects.iterator() ; it.hasNext();) { 139 Project p = (Project)it.next(); 140 if (p instanceof NbModuleProject) { 141 NbModuleProject nbm = (NbModuleProject) p; 142 if (nbm != null && nbm.getCodeNameBase().equals(getCodeNameBase())) { 143 FileObject file = (isUnit()) ? nbm.getTestSourceDirectory() : nbm.getFunctionalTestSourceDirectory(); 144 if (file != null) { 145 return file.getURL(); 146 } 147 } 148 } 149 } 150 } 151 } 152 return null; 153 } 154 155 File getNBCVSRoot() { 156 File rootDir = getTestDistRoot(); 157 String path = rootDir.getAbsolutePath().replace(File.separatorChar,'/'); 158 File nbcvs = null; 159 if (path.endsWith(TEST_DIST_DIR)) { 161 nbcvs = rootDir.getParentFile().getParentFile().getParentFile(); 162 } 163 return nbcvs; 164 } 165 166 public String getNetBeansOrgPath () throws IOException { 167 File nbcvs = getNBCVSRoot(); 168 if (nbcvs != null && ModuleList.isNetBeansOrg(nbcvs) ) { 169 ModuleList list = ModuleList.getModuleList(new File (nbcvs,"core")); ModuleEntry entry = list.getEntry(codeNameBase); 171 if (entry == null) { 172 return null; 173 } 174 return entry.getNetBeansOrgPath() + "/test/" + getTestType() + "/src"; 175 } 176 return null; 177 } 178 179 public String getTestType() { 180 return (isUnit()) ? UNIT : QA_FUNCTIONAL; 181 } 182 183 187 public Project getProject() { 188 try { 189 URL url = getSrcDir(); 190 if (url != null) { 191 URI uri = url.toURI(); 192 if (uri != null) { 193 return FileOwnerQuery.getOwner(uri); 194 } 195 } 196 } catch (IOException ex) { 197 Util.err.notify(ex); 198 } catch (URISyntaxException ex) { 199 Util.err.notify(ex); 200 } 201 return null; 202 } 203 204 } 205 | Popular Tags |