-
Notifications
You must be signed in to change notification settings - Fork 0
Commandline arguments #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bozali
wants to merge
4
commits into
Gismo150:master
Choose a base branch
from
bozali:commandline-arguments
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
774d690
Add ConfigurationService, BuildSystem and CrawlerConfig to the projec…
bozali 89ac74f
Replace the old BuildSystem with a new one that can be serialized and…
bozali 1005c1b
Replace common-cli with jcommander, because common-cli didn't support…
bozali f37bdee
Add the crawl command to the cli. It is now possible to passe languag…
bozali File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package commands; | ||
|
|
||
| import com.beust.jcommander.Parameter; | ||
| import com.beust.jcommander.Parameters; | ||
| import configuration.ConfigurationService; | ||
| import configuration.CrawlerConfig; | ||
| import main.GitHubCrawler; | ||
|
|
||
| /** | ||
| * The Crawl Command executes the GitHubCrawler with the settings passed through the commandline. | ||
| * | ||
| * @author Ali Bozna | ||
| */ | ||
| @Parameters(separators = "=") | ||
| public class CrawlCommand { | ||
| @Parameter(names = "--language", description = "") | ||
| private String language; | ||
|
|
||
| @Parameter(names = { "--stars", "--stars-decrease-amount" }, description = "", required = true) | ||
| private int starDecreaseAmount; | ||
|
|
||
| @Parameter(names = { "--build-system", "--bs" }, description = "", required = false) | ||
| private String buildSystem; | ||
|
|
||
| /** | ||
| * Gets the language. | ||
| * | ||
| * @return Returns the language. | ||
| */ | ||
| public String getLanguage() { | ||
| return this.language; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the stars decrease amount. | ||
| * | ||
| * @return Returns the stars decrease amount. | ||
| */ | ||
| public int getStarsDecreaseAmount() { | ||
| return this.starDecreaseAmount; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the Build-System. | ||
| * | ||
| * @return Returns the Build-System. | ||
| */ | ||
| public String getBuildSystem() { | ||
| return this.buildSystem; | ||
| } | ||
|
|
||
| /** | ||
| * Executes the GitHubCrawler with the settings passed through the commandline. Also it loads the | ||
| * configured Build-Systems from the configuration file. | ||
| */ | ||
| public void execute() { | ||
| CrawlerConfig config = new CrawlerConfig(); | ||
| config.starDecreaseAmount = this.getStarsDecreaseAmount(); | ||
| config.buildSystem = this.getBuildSystem(); | ||
| config.language = this.getLanguage(); | ||
|
|
||
| // Get the Build-Systems from the configuration file. | ||
| config.buildSystems = new ConfigurationService().getConfig().buildSystems; | ||
|
|
||
| GitHubCrawler crawler = new GitHubCrawler(config); | ||
| crawler.run(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package configuration; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Defining Build System with public name and buildFiles fields so the objects can be | ||
| * serialized. The end-user has the option to define custom build systems. | ||
| * | ||
| * @author Ali Bozna | ||
| */ | ||
| public class BuildSystem { | ||
| public static BuildSystem UNKOWN = new BuildSystem("UNKOWN", new String[]{}); | ||
|
|
||
| public String name; | ||
| public String[] buildFiles; | ||
|
|
||
| private List<String> filePaths; | ||
|
|
||
| public BuildSystem(String name, String[] buildFiles) { | ||
| this.buildFiles = buildFiles; | ||
| this.name = name; | ||
| } | ||
|
|
||
| public BuildSystem() { | ||
| } | ||
|
|
||
| public List<String> getFilePaths() { | ||
| return this.filePaths; | ||
| } | ||
|
|
||
| public void setFilePaths(List<String> filePaths) { | ||
| this.filePaths = filePaths; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package configuration; | ||
|
|
||
| import com.esotericsoftware.yamlbeans.YamlReader; | ||
| import com.esotericsoftware.yamlbeans.YamlWriter; | ||
|
|
||
| import java.io.FileReader; | ||
| import java.io.FileWriter; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.time.LocalDateTime; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * @author Ali Bozna | ||
| */ | ||
| public class ConfigurationService { | ||
|
|
||
| public ConfigurationService() { | ||
| } | ||
|
|
||
| /** | ||
| * Deserializes the @see CrawlerConfig from the user path. | ||
| * | ||
| * @return Returns the @see CrawlerConfig. | ||
| */ | ||
| public CrawlerConfig getConfig() { | ||
| Path configPath = Paths.get(System.getProperty("user.home"), "crawler", "config.yaml"); | ||
|
|
||
| System.out.println(configPath.toFile().getAbsolutePath()); | ||
|
|
||
| // TODO If the configuration file is empty it will still deserialize it instead of failing. | ||
| try(FileReader fileReader = new FileReader(configPath.toFile())) { | ||
| YamlReader reader = new YamlReader(fileReader); | ||
| CrawlerConfig config = (CrawlerConfig)reader.read(); | ||
| reader.close(); | ||
|
|
||
| return config; | ||
|
|
||
| } catch(Exception exception) { | ||
| System.err.println(exception.getMessage()); | ||
| } | ||
|
|
||
| // If the configuration deserialization failed create overwrite the configuration with | ||
| // some default configuration. | ||
| CrawlerConfig config = new CrawlerConfig(); | ||
| config.oauthtoken = ""; | ||
| config.language = "CPP"; | ||
| config.lastPushDate = DateTimeFormatter.ofPattern("YYYY-MM-dd").format(LocalDateTime.now()); | ||
| config.starDecreaseAmount = 1; | ||
| config.buildSystem = "CUSTOM"; | ||
| config.customFile = "CHANGELOG.md"; | ||
| config.filePath = "shared"; | ||
| config.buildSystems = this.getDefaultBuildSystems(); | ||
|
|
||
| try { | ||
| configPath.toFile().getParentFile().mkdirs(); | ||
| } catch (Exception exception) { | ||
| System.err.println(exception.getMessage()); | ||
| } | ||
|
|
||
| // Save the created default configuration. | ||
| try(FileWriter fileWriter = new FileWriter(configPath.toFile())) { | ||
| YamlWriter writer = new YamlWriter(fileWriter); | ||
| writer.write(config); | ||
| writer.close(); | ||
|
|
||
| } catch(Exception exception) { | ||
| System.err.println(exception.getMessage()); | ||
| } | ||
|
|
||
| return config; | ||
| } | ||
|
|
||
| /** | ||
| * @return Returns default build-systems. | ||
| */ | ||
| private List getDefaultBuildSystems() { | ||
| List systems = new ArrayList(); | ||
| systems.add(new BuildSystem("CMAKE", new String[] { "CMakeLists.txt" })); | ||
| systems.add(new BuildSystem("AUTOTOOLS", new String[] { "configure.ac", "configure.in", "Makefile.am" })); | ||
| systems.add(new BuildSystem("MAKE", new String[] { "Makefile" })); | ||
| systems.add(new BuildSystem("CUSTOM", new String[] { "" })); | ||
| systems.add(BuildSystem.UNKOWN); | ||
|
|
||
| return systems; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package configuration; | ||
|
|
||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Configuration file that will be de/serialized from/to Yaml file. | ||
| * | ||
| * @author Ali Bozna | ||
| */ | ||
| public class CrawlerConfig { | ||
| public String language; | ||
|
|
||
| public String lastPushDate; | ||
|
|
||
| public int starDecreaseAmount; | ||
|
|
||
| public String oauthtoken; | ||
|
|
||
| public String filePath; | ||
|
|
||
| public String jsonFileName; | ||
|
|
||
| public String customFile; | ||
|
|
||
| public String buildSystem; | ||
|
|
||
| public List buildSystems; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,14 +6,14 @@ | |
|
|
||
| public class Config { | ||
|
|
||
| public static final String LANGUAGE = PropertyFileReader.getInstance().getProperty(EConfig.LANGUAGE); | ||
| public static final String LASTPUSHEDDATE = PropertyFileReader.getInstance().getProperty(EConfig.LASTPUSHEDDATE); | ||
| public static final String STARSDECREASEAMOUNT = PropertyFileReader.getInstance().getProperty(EConfig.STARSDECREASEAMOUNT); | ||
| public static final BuildSystem BUILDSYSTEM = BuildSystem.getBuildType(PropertyFileReader.getInstance().getProperty(EConfig.BUILDSYSTEM)); | ||
| public static final String OAUTHTOKEN = PropertyFileReader.getInstance().getProperty(EConfig.OAUTHTOKEN); | ||
| public static final String FILEPATH = PropertyFileReader.getInstance().getProperty(EConfig.FILEPATH); | ||
| public static final String JSONFILENAME = "repositories.json"; | ||
| public static final String CUSTOMFILE = PropertyFileReader.getInstance().getProperty(EConfig.CUSTOMFILE); | ||
| public static final String LANGUAGE = null;//PropertyFileReader.getInstance().getProperty(EConfig.LANGUAGE); | ||
| public static final String LASTPUSHEDDATE = null;//PropertyFileReader.getInstance().getProperty(EConfig.LASTPUSHEDDATE); | ||
| public static final String STARSDECREASEAMOUNT = null;//PropertyFileReader.getInstance().getProperty(EConfig.STARSDECREASEAMOUNT); | ||
| public static final BuildSystem BUILDSYSTEM = null;//BuildSystem.getBuildType(PropertyFileReader.getInstance().getProperty(EConfig.BUILDSYSTEM)); | ||
| public static final String OAUTHTOKEN = null;//PropertyFileReader.getInstance().getProperty(EConfig.OAUTHTOKEN); | ||
| public static final String FILEPATH = null;//PropertyFileReader.getInstance().getProperty(EConfig.FILEPATH); | ||
| public static final String JSONFILENAME = null;//"repositories.json"; | ||
| public static final String CUSTOMFILE = null;//PropertyFileReader.getInstance().getProperty(EConfig.CUSTOMFILE); | ||
|
Comment on lines
+14
to
+16
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These properties are never set by the configservice. The FileHelper.java file then needs to be updated to get the configs from the CrawlerConfig and not the old Config file. |
||
|
|
||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need another function that we can call to simply get the already parsed Configuration.
This service should only parse the yaml file once and provide the CrawlerConfig with a getter.