PipelineResources { public static List<String> prepareFilesForStaging( List<String> resourcesToStage, String tmpJarLocation) { return resourcesToStage.stream() .map(File::new) .map( file -> { Preconditions.checkState( file.exists(), "To-be-staged file does not exist: '%s'", file); return file.isDirectory() ? packageDirectoriesToStage(file, tmpJarLocation) : file.getAbsolutePath(); }) .collect(Collectors.toList()); }  static List<String> detectClassPathResourcesToStage(
      ClassLoader classLoader, PipelineOptions options); static List<String> prepareFilesForStaging(
      List<String> resourcesToStage, String tmpJarLocation);  }
@Test public void testFailOnNonExistingPaths() throws IOException { String nonexistentFilePath = tmpFolder.getRoot().getPath() + "/nonexistent/file"; String existingFilePath = tmpFolder.newFile("existingFile").getAbsolutePath(); String temporaryLocation = tmpFolder.newFolder().getAbsolutePath(); List<String> filesToStage = Arrays.asList(nonexistentFilePath, existingFilePath); assertThrows( "To-be-staged file does not exist: ", IllegalStateException.class, () -> PipelineResources.prepareFilesForStaging(filesToStage, temporaryLocation)); }
@Test public void testPackagingDirectoryResourceToJarFile() throws IOException { String directoryPath = tmpFolder.newFolder().getAbsolutePath(); String temporaryLocation = tmpFolder.newFolder().getAbsolutePath(); List<String> filesToStage = new ArrayList<>(); filesToStage.add(directoryPath); List<String> result = PipelineResources.prepareFilesForStaging(filesToStage, temporaryLocation); assertTrue(new File(result.get(0)).exists()); assertTrue(result.get(0).matches(".*\\.jar")); }
@Test public void testIfThrowsWhenThereIsNoTemporaryFolderForJars() throws IOException { List<String> filesToStage = new ArrayList<>(); filesToStage.add(tmpFolder.newFolder().getAbsolutePath()); IllegalArgumentException exception = assertThrows( IllegalArgumentException.class, () -> PipelineResources.prepareFilesForStaging(filesToStage, null)); assertEquals( "Please provide temporary location for storing the jar files.", exception.getMessage()); }