7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 */ 24 25 package client.test.runner; 26 27 import client.test.CheckUI; 28 import client.test.Keywords; 29 import client.test.RunUI; 30 import java.io.File; 31 import java.io.IOException; 32 import java.lang.annotation.Annotation; 33 import java.lang.reflect.Method; 34 import java.util.ArrayList; 35 import java.util.HashMap; 36 import java.util.List; 37 import java.util.regex.Matcher; 38 import java.util.regex.Pattern; 39 40 /** 41 * @author shura 42 */ 43 public class RunUITestFinder extends AbstractTestFinder { 44 45 static final String TEST_NAME = "unit.test.testname"; 46 static final String UNIT_TEST_CLASS_NAME = "unit.test.classname"; 47 static final String NO_DESCRIPTION = "unit.test.nodescription"; 48 static final String HAS_CHECK_UI = "unit.test.has.check.ui"; 49 static final String TYPE_JUNIT = "unit.test.type.junit"; 50 private static boolean excludeNoDesc = false; 51 private static boolean excludeDesc = false; 52 protected final static String testRoot; 53 54 static { 55 String tr = null; 56 try { 57 tr = new File(System.getProperty("client.test.root")).getCanonicalPath() + File.separator; 58 } catch (IOException ex) { 59 ex.printStackTrace(); 60 } 61 testRoot = tr; 62 excludeNoDesc = Boolean.getBoolean("client.exclude.nodesc"); 63 excludeDesc = Boolean.getBoolean("client.exclude.desc"); 64 } 75 } 76 77 private static String calcHtmlFileName(String javaFileName, String htmlRelName) { 78 return new File(javaFileName).getParent() + File.separator + htmlRelName; 79 } 80 81 @Override 82 public void scan(File file) { 83 if (file.isDirectory()) { 84 super.scan(file); 85 } else { 86 try { 87 Class testClass = fileToClass(file); 88 if (excludeTestClass(testClass)) { 89 return; 90 } 91 List<RunUI> runUIs = findAnnotations(testClass, RunUI.class); 92 boolean hasCheckUI = findAnnotations(testClass, CheckUI.class).size() > 0; 93 List<String> resources = new ArrayList<String>(runUIs.size()); 94 List<Keywords> keys = findAnnotations(testClass, Keywords.class); 95 if (!runUIs.isEmpty()) { 96 boolean nodescription = false; 97 for (RunUI runUI : runUIs) { 98 if (runUI.noDescription()) { 99 nodescription = true; 100 break; 101 } 102 String value = runUI.value(); 103 if (value != null) { 104 if (value.length() == 0) { 105 value = testClass.getSimpleName() + ".html"; 106 } 107 resources.add(value); 108 } 109 } 110 111 if (nodescription && !excludeNoDesc 112 || !nodescription && !excludeDesc) { 113 String rootDir = getRootDir().getAbsolutePath(); 114 String filePath = file.getAbsolutePath().substring(rootDir.length() + 1, file.getAbsolutePath().length()); 115 String path = file.getPath(); 116 HashMap tagValues = new HashMap(); 117 118 // Keywords processing 119 String key_str = null; 120 if (!keys.isEmpty()) 121 { 122 for (Keywords key : keys) { 123 key_str = (key_str==null?key.keywords():" " + key.keywords()); 124 } 125 tagValues.put("keywords", key_str); 126 System.out.println("The following keywords \"" + key_str + "\" were found in the test " + file.getName()); 127 } 128 129 if (nodescription) { 130 tagValues.put("testName", removeDotJavaExtensionFromFilePath(filePath)); 131 tagValues.put(FILE_PATH_PROP, path); 132 tagValues.put(UNIT_TEST_CLASS_NAME, testClass.getName()); 133 tagValues.put(NO_DESCRIPTION, Boolean.TRUE.toString()); 134 tagValues.put(HAS_CHECK_UI, "false"); 135 136 foundTestDescription(tagValues, new File(filePath), 0); 137 138 } else { 139 for (String html : resources) { 140 String htmlFile = calcHtmlFileName(path, html); 141 if (!new File(htmlFile).exists()) { 142 error("Html resource '" + htmlFile + "' doesn't exists."); 143 continue; 144 } 145 146 if (resources.size() > 1) { | 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 */ 24 25 package client.test.runner; 26 27 import client.test.AddExports; 28 import client.test.CheckUI; 29 import client.test.Keywords; 30 import client.test.RunUI; 31 import java.io.File; 32 import java.io.IOException; 33 import java.lang.annotation.Annotation; 34 import java.lang.reflect.Method; 35 import java.util.ArrayList; 36 import java.util.HashMap; 37 import java.util.List; 38 import java.util.regex.Matcher; 39 import java.util.regex.Pattern; 40 import java.util.stream.Collectors; 41 import java.util.stream.Stream; 42 43 /** 44 * @author shura 45 */ 46 public class RunUITestFinder extends AbstractTestFinder { 47 48 static final String ADD_EXPORTS = "unit.test.addExports"; 49 static final String TEST_NAME = "unit.test.testname"; 50 static final String UNIT_TEST_CLASS_NAME = "unit.test.classname"; 51 static final String NO_DESCRIPTION = "unit.test.nodescription"; 52 static final String HAS_CHECK_UI = "unit.test.has.check.ui"; 53 static final String TYPE_JUNIT = "unit.test.type.junit"; 54 private static boolean excludeNoDesc = false; 55 private static boolean excludeDesc = false; 56 protected final static String testRoot; 57 58 static { 59 String tr = null; 60 try { 61 tr = new File(System.getProperty("client.test.root")).getCanonicalPath() + File.separator; 62 } catch (IOException ex) { 63 ex.printStackTrace(); 64 } 65 testRoot = tr; 66 excludeNoDesc = Boolean.getBoolean("client.exclude.nodesc"); 67 excludeDesc = Boolean.getBoolean("client.exclude.desc"); 68 } 79 } 80 81 private static String calcHtmlFileName(String javaFileName, String htmlRelName) { 82 return new File(javaFileName).getParent() + File.separator + htmlRelName; 83 } 84 85 @Override 86 public void scan(File file) { 87 if (file.isDirectory()) { 88 super.scan(file); 89 } else { 90 try { 91 Class testClass = fileToClass(file); 92 if (excludeTestClass(testClass)) { 93 return; 94 } 95 List<RunUI> runUIs = findAnnotations(testClass, RunUI.class); 96 boolean hasCheckUI = findAnnotations(testClass, CheckUI.class).size() > 0; 97 List<String> resources = new ArrayList<String>(runUIs.size()); 98 List<Keywords> keys = findAnnotations(testClass, Keywords.class); 99 List<AddExports> addExportsList = findAnnotations(testClass, AddExports.class); 100 if (!runUIs.isEmpty()) { 101 boolean nodescription = false; 102 for (RunUI runUI : runUIs) { 103 if (runUI.noDescription()) { 104 nodescription = true; 105 break; 106 } 107 String value = runUI.value(); 108 if (value != null) { 109 if (value.length() == 0) { 110 value = testClass.getSimpleName() + ".html"; 111 } 112 resources.add(value); 113 } 114 } 115 116 if (nodescription && !excludeNoDesc 117 || !nodescription && !excludeDesc) { 118 String rootDir = getRootDir().getAbsolutePath(); 119 String filePath = file.getAbsolutePath().substring(rootDir.length() + 1, file.getAbsolutePath().length()); 120 String path = file.getPath(); 121 HashMap tagValues = new HashMap(); 122 123 // Keywords processing 124 String key_str = null; 125 if (!keys.isEmpty()) 126 { 127 for (Keywords key : keys) { 128 key_str = (key_str==null?key.keywords():" " + key.keywords()); 129 } 130 tagValues.put("keywords", key_str); 131 System.out.println("The following keywords \"" + key_str + "\" were found in the test " + file.getName()); 132 } 133 134 // --add-exports value 135 if (!addExportsList.isEmpty()) { 136 String[] addExportsArray = new String[addExportsList.size()]; 137 for (int i = 0; i < addExportsList.size(); i++) { 138 addExportsArray[i] = addExportsList.get(i).value(); 139 } 140 String addExports = Stream.of(TestScript.combineAddExports(addExportsArray)).collect(Collectors.joining(" ")); 141 tagValues.put(ADD_EXPORTS, addExports); 142 System.out.println("The following addExports \"" + addExports + "\" were found in the test " + file.getName()); 143 } 144 145 if (nodescription) { 146 tagValues.put("testName", removeDotJavaExtensionFromFilePath(filePath)); 147 tagValues.put(FILE_PATH_PROP, path); 148 tagValues.put(UNIT_TEST_CLASS_NAME, testClass.getName()); 149 tagValues.put(NO_DESCRIPTION, Boolean.TRUE.toString()); 150 tagValues.put(HAS_CHECK_UI, "false"); 151 152 foundTestDescription(tagValues, new File(filePath), 0); 153 154 } else { 155 for (String html : resources) { 156 String htmlFile = calcHtmlFileName(path, html); 157 if (!new File(htmlFile).exists()) { 158 error("Html resource '" + htmlFile + "' doesn't exists."); 159 continue; 160 } 161 162 if (resources.size() > 1) { |