public void addPackage(Package pkg) { addPackage( pkg.getName(), false ); }
public void create() throws IOException { explodedJar = null; jar = null; File root = new File( System.getProperty( "java.io.tmpdir" ) + "/" + getClass().getName() + "." + random.nextInt() ); root.mkdir(); root.deleteOnExit(); for ( Class<?> clazz : classes ) { copyClass( clazz, getClassesRoot( root ) ); } for ( ResourceDescriptor resourceDescriptor : resources ) { copyResource( resourceDescriptor, root ); } if ( isLibrariesSupported() ) { for ( ResourceDescriptor resourceDescriptor : libraries ) { copyResource( resourceDescriptor, getLibraryRoot( root ) ); } } this.explodedJar = root; }
public File getExplodedJar() throws IOException { if ( explodedJar == null ) { create(); } return explodedJar; }
public File getClassesRoot(File archiveRoot) { if ( classesRoot == null ) { classesRoot = makeDirectoryStructure( archiveRoot, getClassesRoot() ); } return classesRoot; }
@Override protected TCKArtifact postCreate(TCKArtifact artifact) throws IOException { super.postCreate(artifact); ArtifactDescriptor library = new ArtifactDescriptor(LibraryInWarTest.class); library.getClasses().add(Bar.class); library.getResources().add(new ResourceDescriptorImpl(JSR299ArtifactDescriptor.BEANS_XML_DESTINATION, JSR299ArtifactDescriptor.STANDARD_BEANS_XML_FILE_NAME)); artifact.getLibraries().add(new ResourceDescriptorImpl("cdi-tck-beans.jar", library.getJarAsStream())); return artifact; }
@Override protected TCKArtifact postCreate(TCKArtifact artifact) throws IOException { super.postCreate(artifact); ArtifactDescriptor library = new ArtifactDescriptor(LibraryMissingBeansXmlTest.class); library.getClasses().add(Bar.class); artifact.getLibraries().add(new ResourceDescriptorImpl("cdi-tck-beans.jar", library.getJarAsStream())); return artifact; }
public ArtifactDescriptor initialize() { for ( String packageName : ConfigurationImpl.get().getExtraPackages() ) { addPackage( packageName, false ); } getResources().addAll( ConfigurationImpl.get().getExtraResources() ); return this; }
public URL getJar() throws IOException { InputStream is = null; try { is = getJarAsStream(); File file = File.createTempFile( ArtifactDescriptor.class.getCanonicalName(), ".jar" ); file.deleteOnExit(); Files.copy( is, file ); is.close(); return file.toURI().toURL(); } finally { if ( is != null ) { is.close(); } } }
private static void copyClass(String className, File root) throws IOException { InputStream clazzStream = null; try { String classFilePathName = getClassFileName( className ); String directoryName = classFilePathName.substring( 0, classFilePathName.lastIndexOf( "/" ) ); String classFileName = classFilePathName.substring( classFilePathName.lastIndexOf( "/" ) + 1 ); File packageDirectory = makeDirectoryStructure( root, directoryName ); File classFile = new File( packageDirectory, classFileName ); classFile.createNewFile(); classFile.deleteOnExit(); clazzStream = loadResourceAsStream( classFilePathName ); if ( clazzStream == null ) { throw new IllegalStateException( "Eror loading " + className + " (" + classFilePathName + ")" ); } Files.copy( clazzStream, classFile ); } finally { if ( clazzStream != null ) { clazzStream.close(); } } }
public void addPackage(String packageName, boolean addRecursively) { URLPackageScanner packageScanner = new URLPackageScanner( packageName, addRecursively ); for ( String className : packageScanner.getClassNames() ) { Class<?> clazz = loadClass( className ); if ( clazz == null ) { System.out.println( "Class null: " + className ); } getClasses().add( clazz ); } }
private static void copyClass(Class<?> clazz, File root) throws IOException { copyClass( clazz.getName(), root ); }
@Override protected TCKArtifact postCreate(TCKArtifact artifact) throws IOException { super.postCreate(artifact); ArtifactDescriptor library = new ArtifactDescriptor(LibraryInEarTest.class); library.getClasses().addAll(Arrays.asList(Bar.class)); library.getResources().add(new ResourceDescriptorImpl(JSR299ArtifactDescriptor.BEANS_XML_DESTINATION, JSR299ArtifactDescriptor.STANDARD_BEANS_XML_FILE_NAME)); artifact.getLibraries().add(new ResourceDescriptorImpl("cdi-tck-beans.jar", library.getJarAsStream())); return artifact; }
public void writeArtifactToDisk(String outputDirectory, String fileName) throws IOException { OutputStream os = null; InputStream jar = null; try { File file = new File( outputDirectory, fileName ); file.createNewFile(); os = new BufferedOutputStream( new FileOutputStream( file ) ); jar = getJarAsStream(); Files.copy( jar, os ); } finally { if ( os != null ) { os.close(); } if ( jar != null ) { jar.close(); } } }