public void testWarScan() throws Exception { final File war = File.createTempFile("test", ".war"); WebArchive archive = ShrinkWrap.create(WebArchive.class).addClasses(FunAnnotatedClientClass.class); archive.as(ZipExporter.class).exportTo(war, true); assertTrue(war.exists()); URL warUrl = war.toURI().toURL(); List<URL> urlList = new ArrayList<URL>(); urlList.add(warUrl); MetaDataScanner scanner = createScanner(urlList); String annotationToSearchFor = Local.class.getName(); Set<String> annotated = scanner.getStore().getTypesAnnotatedWith(annotationToSearchFor); assertFalse("Cannot find " + annotationToSearchFor + " in " + war, annotated.isEmpty()); war.delete(); }
public void testEarScan() throws Exception { File ear = File.createTempFile("helloworld", ".ear"); JavaArchive jarArchive = ShrinkWrap.create(JavaArchive.class, "my-lib-1.0.jar") .addClass(FunAnnotatedClientClass2.class); WebArchive warArchive = ShrinkWrap.create(WebArchive.class, "helloworld.war") .addClasses(FunAnnotatedClientClass.class) .addAsLibrary(jarArchive); EnterpriseArchive earArchive = ShrinkWrap.create(EnterpriseArchive.class).addAsModule(warArchive); earArchive.as(ZipExporter.class).exportTo(ear, true); URL earUrl = new URL(ear.toURI() + "/helloworld.war!/WEB-INF/classes"); URL libUrl = new URL(ear.toURI() + "/helloworld.war!/WEB-INF/lib/my-lib-1.0.jar"); List<URL> urlList = new ArrayList<URL>(); urlList.add(earUrl); urlList.add(libUrl); MetaDataScanner scanner = createScanner(urlList); // nested in ear/war/WEB-INF/classes assertTrue( "Didn't find @Local annotated class FunAnnotatedClientClass in ear-war nesting", scanner .getStore() .getTypesAnnotatedWith(Local.class.getName()) .contains("org.jboss.errai.bus.client.tests.support.FunAnnotatedClientClass")); // nested in ear/war/WEB-INF/lib assertTrue( "Didn't find @Service annotated class FunAnnotatedClientClass2 in ear-war-jar nesting", scanner .getStore() .getTypesAnnotatedWith(Service.class.getName()) .contains("org.jboss.errai.bus.client.tests.support.FunAnnotatedClientClass2")); }
public void testExplodedWarScan() throws Exception { final File warParentDir = Files.createTempDir(); assertTrue(warParentDir.isDirectory()); WebArchive archive = ShrinkWrap.create(WebArchive.class, "explode-me").addClasses(FunAnnotatedClientClass.class); archive.as(ExplodedExporter.class).exportExploded(warParentDir); File warBaseDir = new File(warParentDir, "explode-me"); assertTrue( "Missing exploded war at " + warBaseDir, new File(warBaseDir, "WEB-INF").isDirectory()); URL warUrl = new URL(warBaseDir.toURI().toURL() + "/WEB-INF/classes"); List<URL> urlList = new ArrayList<URL>(); urlList.add(warUrl); MetaDataScanner scanner = createScanner(urlList); String annotationToSearchFor = Local.class.getName(); Set<String> annotated = scanner.getStore().getTypesAnnotatedWith(annotationToSearchFor); assertFalse("Cannot find " + annotationToSearchFor + " in " + warBaseDir, annotated.isEmpty()); FileUtils.deleteDirectory(warParentDir); warParentDir.delete(); }
private void generateMarshallers() { MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance(); Set<Class<?>> exposed = new HashSet<Class<?>>(scanner.getTypesAnnotatedWith(Portable.class)); exposed.addAll(scanner.getTypesAnnotatedWith(ExposeEntity.class)); // add all GWT JRE classes exposed.add(Throwable.class); exposed.add(NullPointerException.class); exposed.add(RuntimeException.class); exposed.add(Exception.class); exposed.add(ArithmeticException.class); exposed.add(ArrayStoreException.class); exposed.add(AssertionError.class); exposed.add(ClassCastException.class); exposed.add(IllegalArgumentException.class); exposed.add(IndexOutOfBoundsException.class); exposed.add(NegativeArraySizeException.class); exposed.add(NumberFormatException.class); exposed.add(StringIndexOutOfBoundsException.class); exposed.add(UnsupportedOperationException.class); exposed.add(StackTraceElement.class); exposed.add(IOException.class); exposed.add(UnsupportedEncodingException.class); exposed.add(ConcurrentModificationException.class); exposed.add(EmptyStackException.class); // exposed.add(MissingResourceException.class); // exposed.add(NoSuchMethodException.class); for (Class<?> clazz : exposed) { mappingContext.registerGeneratedMarshaller(clazz.getName()); } for (Class<?> clazz : exposed) { if (clazz.isEnum()) continue; MetaClass metaClazz = MetaClassFactory.get(clazz); Statement marshaller = marshal(metaClazz); MetaClass type = marshaller.getType(); String varName = getVarName(clazz); classStructureBuilder.privateField(varName, type).finish(); constructor.append(loadVariable(varName).assignValue(marshaller)); constructor.append( Stmt.create(classContext) .loadVariable(MARSHALLERS_VAR) .invoke("put", clazz.getName(), loadVariable(varName))); for (String s : mappingContext.getReverseMappingAliasFor(clazz.getName())) { constructor.append( Stmt.create(classContext) .loadVariable(MARSHALLERS_VAR) .invoke("put", s, loadVariable(varName))); } } constructor.finish(); }
private MetaDataScanner createScanner(List<URL> urlList) { long s0 = System.currentTimeMillis(); MetaDataScanner scanner = MetaDataScanner.createInstance(urlList); System.out.println("Scan time: " + (System.currentTimeMillis() - s0)); return scanner; }