@Test public void testGetResourceTrailingSlashIgnored() throws Exception { MemoryFileSystem mfs = new MemoryFileSystem(); mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/resources")), new byte[] {65, 66}); MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs); ResourceProvider resourceProvider = mkm.createResourceProvider(); String noTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1")); Assertions.assertThat(noTrailingSlashContents).hasLineCount(1).contains("AB"); // "AB" == new byte[] {65, 66} String withTrailingSlashContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1/")); Assertions.assertThat(withTrailingSlashContents).hasLineCount(1).contains("AB"); // "AB" == new byte[] {65, 66} }
final Path newFile = Paths.get(targetDirectory.getPath(), droolsModelCompilerPath, f.getPath().toPortableString()); Files.copy(f.getContents(), newFile, StandardCopyOption.REPLACE_EXISTING); final String packagesMemoryFilePath = packagesMemoryFile.getFolder().getPath().toPortableString(); final Path packagesDestinationPath = Paths.get(targetDirectory.getPath(), "classes", packagesMemoryFilePath, packagesMemoryFile.getName()); Files.createDirectories(packagesDestinationPath.getParent()); Files.copy(packagesMemoryFile.getContents(), packagesDestinationPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace();
private void saveFile(MemoryFileSystem mfs, String fileName) throws MojoFailureException { MemoryFile memFile = (MemoryFile)mfs.getFile(fileName); final Path path = Paths.get(outputDirectory.getPath(), memFile.getPath().toPortableString()); try { Files.deleteIfExists(path); Files.createDirectories(path); Files.copy(memFile.getContents(), path, StandardCopyOption.REPLACE_EXISTING); } catch(IOException iox) { iox.printStackTrace(); throw new MojoFailureException("Unable to write file", iox); } }
final Path newFile = Paths.get(targetDirectory.getPath(), droolsModelCompilerPath, f.getPath().toPortableString()); Files.copy(f.getContents(), newFile, StandardCopyOption.REPLACE_EXISTING); final String packagesMemoryFilePath = packagesMemoryFile.getFolder().getPath().toPortableString(); final Path packagesDestinationPath = Paths.get(targetDirectory.getPath(), "classes", packagesMemoryFilePath, packagesMemoryFile.getName()); Files.createDirectories(packagesDestinationPath.getParent()); Files.copy(packagesMemoryFile.getContents(), packagesDestinationPath, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace();
private void saveFile(MemoryFileSystem mfs, String fileName) throws MojoFailureException { MemoryFile memFile = (MemoryFile)mfs.getFile(fileName); final Path path = Paths.get(outputDirectory.getPath(), memFile.getPath().toPortableString()); try { Files.deleteIfExists(path); Files.createDirectories(path); Files.copy(memFile.getContents(), path, StandardCopyOption.REPLACE_EXISTING); } catch(IOException iox) { iox.printStackTrace(); throw new MojoFailureException("Unable to write file", iox); } }
@Test public void testGetResourceAsStreamForFile() throws Exception { MemoryFileSystem mfs = new MemoryFileSystem(); mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/resources")), new byte[] {65, 66}); MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs); ResourceProvider resourceProvider = mkm.createResourceProvider(); String folderContents = IOUtils.toString(resourceProvider.getResourceAsStream("src/main/resources/my-file1")); Assertions.assertThat(folderContents).hasLineCount(1).contains("AB"); // "AB" == new byte[] {65, 66} }
@Test public void testGetResourceForFolderWithFilesAndSubFolders() throws Exception { MemoryFileSystem mfs = new MemoryFileSystem(); mfs.createFolder(new MemoryFolder(mfs, "src/main/java")); mfs.createFolder(new MemoryFolder(mfs, "src/main/java/org")); mfs.createFolder(new MemoryFolder(mfs, "src/main/java/com")); mfs.setFileContents(new MemoryFile(mfs, "my-file1", mfs.getFolder("src/main/java")), new byte[10]); mfs.setFileContents(new MemoryFile(mfs, "my-file2", mfs.getFolder("src/main/java")), new byte[10]); MemoryKieModule mkm = new MemoryKieModule(releaseId, kieModuleModel, mfs); ResourceProvider resourceProvider = mkm.createResourceProvider(); String folderContents = IOUtils.toString(resourceProvider.getResource("src/main/java").openStream()); Assertions.assertThat(folderContents).hasLineCount(4).contains("com", "org", "my-file1", "my-file2"); }