From 0a62edeb8bf39348b6013edb43393d71e170ca47 Mon Sep 17 00:00:00 2001 From: Rafael Campos Nunes Date: Thu, 13 Apr 2023 14:28:22 -0300 Subject: [PATCH 1/3] Remove empty line Signed-off-by: Rafael Campos Nunes --- src/main/java/br/unb/cic/cpp/evolution/Main.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/br/unb/cic/cpp/evolution/Main.java b/src/main/java/br/unb/cic/cpp/evolution/Main.java index f825bf9..3e59348 100644 --- a/src/main/java/br/unb/cic/cpp/evolution/Main.java +++ b/src/main/java/br/unb/cic/cpp/evolution/Main.java @@ -117,7 +117,6 @@ public static void usage() { logger.info("--step= - The number of steps used when walking the project"); logger.info("--threads= - The number of threads used to walk the project"); logger.info("--project= - A string denoting the name of the project"); - } } From f3e767aa39bc255bba8a87bb1026e4fad6f28310 Mon Sep 17 00:00:00 2001 From: Rafael Campos Nunes Date: Thu, 13 Apr 2023 23:56:36 -0300 Subject: [PATCH 2/3] Create a directory before trying to write results The old behaviour would fail if there wasn't a results directory to write the results.csv file into. Now it automatically creates one in the parent directory of the parsed folder. Signed-off-by: Rafael Campos Nunes --- .../java/br/unb/cic/cpp/evolution/Main.java | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/br/unb/cic/cpp/evolution/Main.java b/src/main/java/br/unb/cic/cpp/evolution/Main.java index 3e59348..3fc14f0 100644 --- a/src/main/java/br/unb/cic/cpp/evolution/Main.java +++ b/src/main/java/br/unb/cic/cpp/evolution/Main.java @@ -1,6 +1,7 @@ package br.unb.cic.cpp.evolution; import java.io.File; +import java.net.URLDecoder; import java.nio.file.Path; import java.nio.file.Paths; import java.text.SimpleDateFormat; @@ -27,11 +28,11 @@ public class Main { public static void main(final String[] args) throws Exception { val formatter = new SimpleDateFormat("dd-MM-yyyy"); + int step = 7; int threads = 0; - Date initialDate = formatter.parse("01-01-2010"); - Date finalDate = Calendar.getInstance().getTime(); - int step = 7; + var initialDate = formatter.parse("01-01-2010"); + var finalDate = Calendar.getInstance().getTime(); if (args.length == 0 || args[0].isEmpty()) { usage(); @@ -56,24 +57,39 @@ public static void main(final String[] args) throws Exception { logger.info("End date {}", finalDate.toString()); logger.info("Step {}", step); - val path = args[0]; - val f = new File(path); + // make sure to pass the path argument enclosed in quotes if you are using a filepath that contain spaces + val repositoriesPath = args[0]; + val repositoriesPathHandler = new File(repositoriesPath); - if (f.exists() && f.isDirectory()) { + if (repositoriesPathHandler.exists() && repositoriesPathHandler.isDirectory()) { File[] repositories; if (project == null) { - repositories = f.listFiles(File::isDirectory); + repositories = repositoriesPathHandler.listFiles(File::isDirectory); } else { - repositories = f.listFiles(File::isDirectory); + repositories = repositoriesPathHandler.listFiles(File::isDirectory); repositories = Arrays.stream(repositories) .filter(t -> t.getName().equals(project)) .toArray(File[]::new); } try { - val csvPath = Paths.get(f.getAbsolutePath(), "..", "out", "results.csv"); - val csv = new FileCSV(csvPath); + val repositoriesAbsolutePath = Path.of(repositoriesPathHandler.getAbsolutePath()); + val repositoriesParentPath = repositoriesAbsolutePath.getParent(); + + val resultsFolder = Paths.get(repositoriesParentPath.toString(), "out"); + val resultsFolderHandler = new File(resultsFolder.toString()); + + // if the result folder doesn't exist, create a new one so nothing related to that throws down the line + if (!(resultsFolderHandler.exists() || resultsFolderHandler.mkdir())) { + logger.error("failed to create results folder, please create the following folder: " + resultsFolder); + System.exit(1); + } + + val csvFile = Paths.get(resultsFolder.toString(), "results.csv"); + val csv = new FileCSV(csvFile); + + logger.info("writing results into "+csvFile.toString()); if (repositories != null) { val cores = threads == 0 ? Runtime.getRuntime().availableProcessors() : threads; @@ -82,7 +98,7 @@ public static void main(final String[] args) throws Exception { val futures = new ArrayList(); for (File repository : repositories) { - val outputFile = Paths.get(f.getAbsolutePath(), "..", "out", repository.getName() + ".md"); + val outputFile = Paths.get(resultsFolder.toString(), repository.getName() + ".md"); val walker = RepositoryWalkerTask.builder() .csv(csv) .repositoryName(repository.getName()) From 8c123725205f8361b52a6e917dbfe52e119964ed Mon Sep 17 00:00:00 2001 From: Rafael Campos Nunes Date: Fri, 14 Apr 2023 00:00:46 -0300 Subject: [PATCH 3/3] Move log expressions a few lines down Signed-off-by: Rafael Campos Nunes --- src/main/java/br/unb/cic/cpp/evolution/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/br/unb/cic/cpp/evolution/Main.java b/src/main/java/br/unb/cic/cpp/evolution/Main.java index 3fc14f0..8d28575 100644 --- a/src/main/java/br/unb/cic/cpp/evolution/Main.java +++ b/src/main/java/br/unb/cic/cpp/evolution/Main.java @@ -53,10 +53,6 @@ public static void main(final String[] args) throws Exception { } } - logger.info("Init date {}", initialDate.toString()); - logger.info("End date {}", finalDate.toString()); - logger.info("Step {}", step); - // make sure to pass the path argument enclosed in quotes if you are using a filepath that contain spaces val repositoriesPath = args[0]; val repositoriesPathHandler = new File(repositoriesPath); @@ -89,7 +85,11 @@ public static void main(final String[] args) throws Exception { val csvFile = Paths.get(resultsFolder.toString(), "results.csv"); val csv = new FileCSV(csvFile); - logger.info("writing results into "+csvFile.toString()); + logger.info("init date {}", initialDate.toString()); + logger.info("end date {}", finalDate.toString()); + logger.info("step {}", step); + logger.info("threads {}", threads); + logger.info("writing results into {}", csvFile.toString()); if (repositories != null) { val cores = threads == 0 ? Runtime.getRuntime().availableProcessors() : threads;