Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added JAR/jcommander.jar
Binary file not shown.
Binary file added JAR/yamlbeans-1.06.jar
Binary file not shown.
68 changes: 68 additions & 0 deletions src/commands/CrawlCommand.java
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();
}
}
34 changes: 34 additions & 0 deletions src/configuration/BuildSystem.java
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;
}
}
89 changes: 89 additions & 0 deletions src/configuration/ConfigurationService.java
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() {
Copy link
Owner

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.

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;
}
}
29 changes: 29 additions & 0 deletions src/configuration/CrawlerConfig.java
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;
}
16 changes: 8 additions & 8 deletions src/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

@Gismo150 Gismo150 Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These properties are never set by the configservice.
Read the comment on the ConfigurationService file.

The FileHelper.java file then needs to be updated to get the configs from the CrawlerConfig and not the old Config file.



}
Loading