diff --git a/grounghog.json b/grounghog.json new file mode 100644 index 0000000..8a27aef --- /dev/null +++ b/grounghog.json @@ -0,0 +1,14 @@ +{ + "forge": "github", + "dest": "C:/groundhog/dest", + "out": "C:/groundhog/metrics", + "datetime": "2012-07-01_12_00", + "nprojects": 30, + "nthreads": 4, + "outputformat": "csv", + "search": { + "projects": ["rails", "bootstrap"], + "username":"gustavopinto" + } +} + diff --git a/pom.xml b/pom.xml index 53abb7d..195bfdc 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,11 @@ json 20090211 + + com.google.code.gson + gson + 2.2.3 + org.apache.httpcomponents httpcore diff --git a/src/java/main/br/ufpe/cin/groundhog/main/JsonInputArgs.java b/src/java/main/br/ufpe/cin/groundhog/main/JsonInputArgs.java new file mode 100644 index 0000000..301c48f --- /dev/null +++ b/src/java/main/br/ufpe/cin/groundhog/main/JsonInputArgs.java @@ -0,0 +1,72 @@ +package br.ufpe.cin.groundhog.main; + +import java.util.List; + +public final class JsonInputArgs { + private final String forge; + private final String dest; + private final String out; + private final String datetime; + private final String nprojects; + private final String outputformat; + private final Search search; + + public JsonInputArgs(String forge, String dest, String out, + String datetime, String nprojects, String outputformat, + Search search) { + this.forge = forge; + this.dest = dest; + this.out = out; + this.datetime = datetime; + this.nprojects = nprojects; + this.outputformat = outputformat; + this.search = search; + } + + public String getForge() { + return forge; + } + + public String getDest() { + return dest; + } + + public String getOut() { + return out; + } + + public String getDatetime() { + return datetime; + } + + public String getNprojects() { + return nprojects; + } + + public String getOutputformat() { + return outputformat; + } + + public Search getSearch() { + return search; + } +} + +class Search { + private final List projects; + private final String username; + + public Search(List projects, String username) { + super(); + this.projects = projects; + this.username = username; + } + + public String getUsername() { + return username; + } + + public List getProjects() { + return projects; + } +} \ No newline at end of file diff --git a/src/java/main/br/ufpe/cin/groundhog/main/Options.java b/src/java/main/br/ufpe/cin/groundhog/main/Options.java index d06f2f1..420ada2 100644 --- a/src/java/main/br/ufpe/cin/groundhog/main/Options.java +++ b/src/java/main/br/ufpe/cin/groundhog/main/Options.java @@ -1,6 +1,8 @@ package br.ufpe.cin.groundhog.main; import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -10,47 +12,58 @@ import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; +import com.google.common.base.Joiner; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + enum SupportedForge { GITHUB, SOURCEFORGE, GOOGLECODE } -enum MetricsOutputFormat{ +enum MetricsOutputFormat { JSON, CSV } /** * The command-line options parsing class + * * @author fjsj, gustavopinto, rodrigoalvesvieira */ public class Options { - private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH_mm"); - - @Option(name="-forge", usage="forge to be used in search and crawling process") + private static SimpleDateFormat dateFormat = new SimpleDateFormat( + "yyyy-MM-dd_HH_mm"); + + @Option(name = "-forge", usage = "forge to be used in search and crawling process") private SupportedForge forge = SupportedForge.GITHUB; - - @Option(name="-dest", usage="destination folder into which projects will be downloaded") + + @Option(name = "-dest", usage = "destination folder into which projects will be downloaded") private File destinationFolder = null; - - @Option(name="-out", usage="output folder to metrics files") + + @Option(name = "-out", usage = "output folder to metrics files") private File metricsFolder = null; - - @Option(name="-datetime", usage="datetime of projects source code to be processed") + + @Option(name = "-datetime", usage = "datetime of projects source code to be processed") private String datetime = dateFormat.format(new Date()); - - @Option(name="-nprojects", usage="maximum number of projects to be downloaded and processed") + + @Option(name = "-nprojects", usage = "maximum number of projects to be downloaded and processed") private int nProjects = 4; - - @Option(name="-nthreads", usage="maximum number of concurrent threads") + + @Option(name = "-nthreads", usage = "maximum number of concurrent threads") private int nThreads = 4; - - @Option(name="-o", usage="determine the output format of the metrics") + + @Option(name = "-o", usage = "determine the output format of the metrics") private MetricsOutputFormat metricsFormat = MetricsOutputFormat.JSON; + @Option(name = "-in", usage = "all inputs in one json file") + private JsonInputArgs inputFile = null; + @Argument - private List arguments = new ArrayList(); + private List arguments = new ArrayList(); /** * Informs the code forge where the project search will be performed + * * @return */ public SupportedForge getForge() { @@ -59,14 +72,16 @@ public SupportedForge getForge() { /** * Returns the destination folder into which projects will be downloaded + * * @return */ public File getDestinationFolder() { return this.destinationFolder; } - + /** * Sets the destination folder into which projects will be downloaded + * * @param destinationFolder */ public void setDestinationFolder(File destinationFolder) { @@ -75,6 +90,7 @@ public void setDestinationFolder(File destinationFolder) { /** * Informs the location of the folder where the metrics will be stored + * * @return A {@link File} object correspondent to the metrics folder */ public File getMetricsFolder() { @@ -83,6 +99,7 @@ public File getMetricsFolder() { /** * Sets the location of the folder where the metrics will be stored + * * @param metricsFolder */ public void setMetricsFolder(File metricsFolder) { @@ -99,6 +116,7 @@ public void setDatetime(String datetime) { /** * Informs the maximum number of projects to be downloaded and processed + * * @return */ public int getnProjects() { @@ -107,6 +125,7 @@ public int getnProjects() { /** * Sets the maximum number of projects to be downloaded and processed + * * @param nProjects */ public void setnProjects(int nProjects) { @@ -115,6 +134,7 @@ public void setnProjects(int nProjects) { /** * Informs the maximum number of concurrent threads to be ran + * * @return */ public int getnThreads() { @@ -123,6 +143,7 @@ public int getnThreads() { /** * Sets the maximum number of concurrent threads to be ran + * * @param nThreads */ public void setnThreads(int nThreads) { @@ -138,19 +159,19 @@ public void setArguments(List arguments) { } /** - * Sets the forge where the search for projects will be performed - * Valid options are those specified in the {@link SupportedForge} enumerator + * Sets the forge where the search for projects will be performed Valid + * options are those specified in the {@link SupportedForge} enumerator + * * @param forge */ public void setForge(SupportedForge forge) { this.forge = forge; } - + public static SimpleDateFormat getDateFormat() { return dateFormat; } - - + public MetricsOutputFormat getMetricsFormat() { return metricsFormat; } @@ -158,5 +179,23 @@ public MetricsOutputFormat getMetricsFormat() { public void setMetricsFormat(MetricsOutputFormat metricsFormat) { this.metricsFormat = metricsFormat; } - -} \ No newline at end of file + + public JsonInputArgs getInputFile() { + return inputFile; + } + + public void setInputFile(File inputFile) { + try { + List lines = Files.readLines(inputFile, Charset.defaultCharset()); + String json = Joiner.on(" ").join(lines); + JsonInputArgs args = new Gson().fromJson(json, JsonInputArgs.class); + System.out.println(args); + this.inputFile = args; + } catch (JsonSyntaxException e) { + throw new RuntimeException("O formato do arquivo json parece estranho. De uma olhada nos nossos exemplos!"); + } catch (IOException e) { + e.printStackTrace(); + throw new RuntimeException("Não consegui achar o arquivo " + inputFile.getName() + ". Ele não está em outro diretório?"); + } + } +} diff --git a/src/java/test/br/ufpe/cin/groundhog/main/OptionTest.java b/src/java/test/br/ufpe/cin/groundhog/main/OptionTest.java new file mode 100644 index 0000000..a626876 --- /dev/null +++ b/src/java/test/br/ufpe/cin/groundhog/main/OptionTest.java @@ -0,0 +1,17 @@ +package br.ufpe.cin.groundhog.main; + +import java.io.File; + +import org.junit.Assert; +import org.junit.Test; + +public class OptionTest { + + @Test + public void testJsonInputFile() { + Options op = new Options(); + op.setInputFile(new File( + "/home/ghlp/workspace/java/groundhog/grounghog.json")); + Assert.assertNotNull(op.getInputFile()); + } +}