CopybaraGenerator { public String generateOriginFilesConfig() { SortedSet<DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds(); return allDefinitionsChildIds.stream() .filter(id -> { RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, Constants.LICENSE_FILE_NAME); if (!repository.exists(repositoryFileReference)) { return false; } try (InputStream inputStream = repository.newInputStream(repositoryFileReference)) { final String licenceString = "Apache License"; String fileAsString = IOUtils.toString(inputStream); return fileAsString.trim().startsWith(licenceString); } catch (IOException e) { LOGGER.error("Could not create input stream for {}", repositoryFileReference.toString(), e); return false; } }) .map(id -> BackendUtils.getPathInsideRepo(id)) .collect(Collectors.joining("**\",\n \"", "origin_files = glob([\"README.md\", \"LICENSE\", \"", "**\"]),")); } CopybaraGenerator();  CopybaraGenerator(IRepository repository); String generateOriginFilesConfig(); String generateCopybaraConfigFile(); void generateCopybaraConfigFile(Path targetFile);  }
@Test public void generatedOriginFilesConfigHasCorrectStrings() throws Exception { this.setRevisionTo("4b218e6"); CopybaraGenerator copybaraGenerator = new CopybaraGenerator(); String config = copybaraGenerator.generateOriginFilesConfig(); assertEquals("origin_files = glob([\"README.md\", \"LICENSE\", \"artifacttemplates/http%3A%2F%2Fplain.winery.opentosca.org%2Fartifacttemplates/ArtifactTemplateWithFilesAndSources-ArtifactTypeWithoutProperties/**\",\n" + " \"artifacttemplates/http%3A%2F%2Fplain.winery.opentosca.org%2Fartifacttemplates/ArtifactTemplateWithoutAnyFiles-ArtifactTypeWithoutProperties/**\"]),", config); }