@Test public void pipLogParserTest() throws IOException { Map<String, String> expectedResult = new HashMap<String, String>() {{ put("ecopkg1", "ecoPkg1-3.11.tar.gz"); put("ecopkg2", ""); put("ecopkg3", ""); put("ecopkg4", "ecoPkg4-1.1.1-py2.py3-none-any.whl"); put("ecopkg5", ""); }}; InputStream pipLogStream = this.getClass().getResourceAsStream("/pipLogParser/pipLog.txt"); try { String pipLog = IOUtils.toString(pipLogStream, StandardCharsets.UTF_8); Map<String, String> actualMap = PipLogParser.parse(pipLog, log); assertEquals(actualMap.keySet(), expectedResult.keySet()); assertEquals(actualMap.values(), expectedResult.values()); } catch (IOException e) { } finally { if (pipLogStream != null) { pipLogStream.close(); } } }
static Map<String, String> parse(String installationLog, Log logger) { Map<String, String> downloadedDependencies = new HashMap<>(); String[] lines = installationLog.split("\\R"); MutableBoolean expectingPackageFilePath = new MutableBoolean(false); String packageName = ""; for (String line : lines) { Matcher matcher = COLLECTING_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { packageName = extractPackageName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = DOWNLOADED_FILE_PATTERN.matcher(line); if (matcher.find()) { extractDownloadedFileName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = INSTALLED_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { extractAlreadyInstalledPackage(downloadedDependencies, matcher, logger); } } if (expectingPackageFilePath.isTrue()) { downloadedDependencies.put(StringUtils.lowerCase(packageName), ""); } return downloadedDependencies; }
PipLogParser { static Map<String, String> parse(String installationLog, Log logger) { Map<String, String> downloadedDependencies = new HashMap<>(); String[] lines = installationLog.split("\\R"); MutableBoolean expectingPackageFilePath = new MutableBoolean(false); String packageName = ""; for (String line : lines) { Matcher matcher = COLLECTING_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { packageName = extractPackageName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = DOWNLOADED_FILE_PATTERN.matcher(line); if (matcher.find()) { extractDownloadedFileName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = INSTALLED_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { extractAlreadyInstalledPackage(downloadedDependencies, matcher, logger); } } if (expectingPackageFilePath.isTrue()) { downloadedDependencies.put(StringUtils.lowerCase(packageName), ""); } return downloadedDependencies; } }
PipLogParser { static Map<String, String> parse(String installationLog, Log logger) { Map<String, String> downloadedDependencies = new HashMap<>(); String[] lines = installationLog.split("\\R"); MutableBoolean expectingPackageFilePath = new MutableBoolean(false); String packageName = ""; for (String line : lines) { Matcher matcher = COLLECTING_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { packageName = extractPackageName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = DOWNLOADED_FILE_PATTERN.matcher(line); if (matcher.find()) { extractDownloadedFileName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = INSTALLED_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { extractAlreadyInstalledPackage(downloadedDependencies, matcher, logger); } } if (expectingPackageFilePath.isTrue()) { downloadedDependencies.put(StringUtils.lowerCase(packageName), ""); } return downloadedDependencies; }  }
PipLogParser { static Map<String, String> parse(String installationLog, Log logger) { Map<String, String> downloadedDependencies = new HashMap<>(); String[] lines = installationLog.split("\\R"); MutableBoolean expectingPackageFilePath = new MutableBoolean(false); String packageName = ""; for (String line : lines) { Matcher matcher = COLLECTING_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { packageName = extractPackageName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = DOWNLOADED_FILE_PATTERN.matcher(line); if (matcher.find()) { extractDownloadedFileName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = INSTALLED_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { extractAlreadyInstalledPackage(downloadedDependencies, matcher, logger); } } if (expectingPackageFilePath.isTrue()) { downloadedDependencies.put(StringUtils.lowerCase(packageName), ""); } return downloadedDependencies; }   }
PipLogParser { static Map<String, String> parse(String installationLog, Log logger) { Map<String, String> downloadedDependencies = new HashMap<>(); String[] lines = installationLog.split("\\R"); MutableBoolean expectingPackageFilePath = new MutableBoolean(false); String packageName = ""; for (String line : lines) { Matcher matcher = COLLECTING_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { packageName = extractPackageName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = DOWNLOADED_FILE_PATTERN.matcher(line); if (matcher.find()) { extractDownloadedFileName(downloadedDependencies, matcher, packageName, expectingPackageFilePath, logger); continue; } matcher = INSTALLED_PACKAGE_PATTERN.matcher(line); if (matcher.find()) { extractAlreadyInstalledPackage(downloadedDependencies, matcher, logger); } } if (expectingPackageFilePath.isTrue()) { downloadedDependencies.put(StringUtils.lowerCase(packageName), ""); } return downloadedDependencies; }    }