public Builder addClass(Class<?> clazz) { archive.add(new ClassAsset(clazz), ClassPath.ROOT_ARCHIVE_PATH + clazz.getName()); return this; }
@Test public void shouldBeAbleToReturnThisClass() throws Exception { final Class<?> clazz = ClassAssetTestCase.class; final Asset asset = new ClassAsset(clazz); Assert.assertTrue(clazz.getName().equals(((ClassAsset)asset).getSource().getName())); } }
/** * Converts the Class name into a Resource URL and uses the ClassloaderResource for loading the Class. */ @Override public InputStream openStream() { /* * https://jira.jboss.org/jira/browse/TMPARCH-19 If class is loaded by the Bootstrap ClassLoader, getClassLoader * will return null. Use Thread Current Context ClassLoader instead. */ ClassLoader classLoader = clazz.getClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } return new ClassLoaderAsset(getResourceNameOfClass(clazz), classLoader).openStream(); }
public static void materializeClass(File entryDirectory, ClassAsset classAsset) throws DeploymentException, IOException { File classDirectory; if (classAsset.getSource().getPackage() != null) { classDirectory = new File(entryDirectory, classAsset.getSource().getPackage().getName().replace(DELIMITER_CLASS_NAME_PATH, File.separatorChar)); if (!classDirectory.mkdirs()) { throw new DeploymentException("Could not create class package directory: " + classDirectory); } } else { classDirectory = entryDirectory; } File classFile = new File(classDirectory, classAsset.getSource().getSimpleName().concat(EXTENSION_CLASS)); classFile.createNewFile(); try (InputStream in = classAsset.openStream(); OutputStream out = new FileOutputStream(classFile)) { copy(in, out); } }
Asset resource = new ClassAsset(clazz); ArchivePath location = new BasicPath(getClassesPath(), AssetUtil.getFullPathForClassResource(clazz)); add(resource, location);
/** * Converts the Class name into a Resource URL and uses the ClassloaderResource for loading the Class. */ @Override public InputStream openStream() { /* * https://jira.jboss.org/jira/browse/TMPARCH-19 If class is loaded by the Bootstrap ClassLoader, getClassLoader * will return null. Use Thread Current Context ClassLoader instead. */ ClassLoader classLoader = clazz.getClassLoader(); if (classLoader == null) { classLoader = ClassLoader.getSystemClassLoader(); } return new ClassLoaderAsset(getResourceNameOfClass(clazz), classLoader).openStream(); }
Asset resource = new ClassAsset(clazz); ArchivePath location = new BasicPath(getClassesPath(), AssetUtil.getFullPathForClassResource(clazz)); add(resource, location);
classesPackage = clazz.getPackage(); Asset resource = new ClassAsset(clazz); ArchivePath location = ArchivePaths.create(resolveClassesPath(archive), AssetUtil.getFullPathForClassResource(clazz)); archive.add(resource, location);
@Test public void shouldThrowExceptionOnNullClass() throws Exception { try { new ClassAsset(null); Assert.fail("Should have thrown IllegalArgumentException"); } catch (Exception e) { Assert.assertEquals("A null clazz argument should result in a IllegalArgumentException", IllegalArgumentException.class, e.getClass()); } }
Asset classAsset = new ClassAsset(klass); ArchivePath classArchivePath = new BasicPath("/classes", AssetUtil.getFullPathForClassResource(klass));
@Test public void shouldBeAbleToReadThisClass() throws Exception { Class<?> clazz = ClassAssetTestCase.class; Asset asset = new ClassAsset(clazz); InputStream io = asset.openStream(); Assert.assertNotNull(io); Assert.assertEquals("Loaded class should have the same size", ApiTestUtils.findLengthOfStream(io), ApiTestUtils.findLengthOfClass(clazz)); }
/** * https://jira.jboss.org/jira/browse/TMPARCH-19 <br/> * <br/> * A {@link Class} loaded by the Bootstrap ClassLoader will return a null {@link ClassLoader}, should use * {@link Thread} current context {@link ClassLoader} instead. * * @throws Exception */ @Test public void shouldBeAbleAddBootstrapClass() throws Exception { Class<?> bootstrapClass = Class.class; Asset asset = new ClassAsset(bootstrapClass); InputStream io = asset.openStream(); Assert.assertNotNull(io); Assert.assertEquals("Loaded class should have the same size", ApiTestUtils.findLengthOfStream(io), ApiTestUtils.findLengthOfClass(bootstrapClass)); }