private static void writeModuleProgramResourcesToCar(WorkspaceManager workspaceManager, ModuleName moduleName, JarOutputStream jos, ProgramResourcePathMapper programResourcePathMapper) throws IOException {
ResourcePath.Folder moduleFolderPath = (ResourcePath.Folder)programResourcePathMapper.getModuleResourcePath(moduleName);
ProgramResourceLocator.Folder folderLocator = new ProgramResourceLocator.Folder(moduleName, ResourcePath.EMPTY_PATH);
ProgramResourceRepository programResourceRepository = workspaceManager.getRepository();
ProgramResourceLocator[] resourceLocators = programResourceRepository.getMembers(folderLocator);
for (final ProgramResourceLocator resourceLocator : resourceLocators) {
if (resourceLocator instanceof ProgramResourceLocator.File) {
ProgramResourceLocator.File fileLocator = (ProgramResourceLocator.File)resourceLocator;
String relativePath = moduleFolderPath.extendFile(resourceLocator.getName()).getPathStringMinusSlash();
ZipEntry entry = new ZipEntry(relativePath);
jos.putNextEntry(entry);
InputStream inputStream = programResourceRepository.getContents(fileLocator); // this call throws IOException, and should not return null on error
try {
FileSystemResourceHelper.transferData(inputStream, jos);
} finally {
// We need to close the input stream explicitly or else we will be leaking file handles
inputStream.close();