@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); FileManager files = getFiles(location); if (files != null) { return files.getReadable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } }
@Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); FileManager files = getFiles(location); if (files != null) { return files.getReadable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } }
@Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); // Address a bug if (location == StandardLocation.SOURCE_PATH) { FileObject file = sourcePath.getReadable(key); if (file == null) { throw new FileNotFoundException("Not found:" + key.toString()); } return file; } else { FileManager files = getFiles(location); if (files != null) { return files.getWritable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } } }
@Override public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) throws IOException { FileKey key = FileKey.newResourceName(packageName, relativeName); // Address a bug if (location == StandardLocation.SOURCE_PATH) { FileObject file = sourcePath.getReadable(key); if (file == null) { throw new FileNotFoundException("Not found:" + key.toString()); } return file; } else { FileManager files = getFiles(location); if (files != null) { return files.getWritable(key); } else { throw new FileNotFoundException("Cannot write: " + location); } } }
if (f.exists() && f.isFile()) { log.info("Resolved " + coordinates + " to " + f.getAbsolutePath()); return new JavaFileObjectImpl<File>(StandardLocation.SOURCE_PATH, FileKey.newResourceName(pkg.toString(), relativeName.toString()), sourcePath, f); } else { log.info("Resolving " + coordinates + " from source path does not exists " + f.getAbsolutePath());
if (f.exists() && f.isFile()) { log.info("Resolved " + coordinates + " to " + f.getAbsolutePath()); return new JavaFileObjectImpl<File>(StandardLocation.SOURCE_PATH, FileKey.newResourceName(pkg.toString(), relativeName.toString()), sourcePath, f); } else { log.info("Resolving " + coordinates + " from source path does not exists " + f.getAbsolutePath());
@Test public void testGetResourceFromClassPath() throws Exception { File fic = File.createTempFile("test", ".jar"); fic.deleteOnExit(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addAsResource(new StringAsset("the_resource"), "resource.txt"); jar.as(ZipExporter.class).exportTo(fic, true); JarFileSystem classpath = new JarFileSystem(new JarFile(fic)); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder(). javaCompiler(compilerProvider). config(new CompilerConfig().force(true)). addClassPath(classpath). sourcePath(new RAMFileSystem()). output(output).build(); GetResource processor = new GetResource(StandardLocation.CLASS_PATH, FileKey.newResourceName("", "resource.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); processor.assertResource("the_resource"); }
@Test public void testGetResourceFromClassPath() throws Exception { File fic = File.createTempFile("test", ".jar"); fic.deleteOnExit(); JavaArchive jar = ShrinkWrap.create(JavaArchive.class); jar.addAsResource(new StringAsset("the_resource"), "resource.txt"); jar.as(ZipExporter.class).exportTo(fic, true); JarFileSystem classpath = new JarFileSystem(new JarFile(fic)); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder(). javaCompiler(compilerProvider). config(new CompilerConfig().force(true)). addClassPath(classpath). sourcePath(new RAMFileSystem()). output(output).build(); GetResource processor = new GetResource(StandardLocation.CLASS_PATH, FileKey.newResourceName("", "resource.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); processor.assertResource("the_resource"); }
@Test public void testGetResourceFromSourcePath() throws Exception { DiskFileSystem input = diskFS("compiler.getresource"); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder().javaCompiler(compilerProvider).sourcePath(input).output(output).build(); GetResource processor = new GetResource(StandardLocation.SOURCE_PATH, FileKey.newResourceName("compiler.getresource", "A.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); processor.assertResource("value"); }
@Test public void testGetResourceFromSourcePath() throws Exception { DiskFileSystem input = diskFS("compiler.getresource"); RAMFileSystem output = new RAMFileSystem(); Compiler compiler = Compiler.builder().javaCompiler(compilerProvider).sourcePath(input).output(output).build(); GetResource processor = new GetResource(StandardLocation.SOURCE_PATH, FileKey.newResourceName("compiler.getresource", "A.txt")); compiler.addAnnotationProcessor(processor); compiler.compile(); assertEquals(1, output.size(ReadFileSystem.FILE)); processor.assertResource("value"); }