Added the creator of the jar to compile and create jar

The jar converts json configuration into normal
android-scanner
VladimirEliTokarev 2016-11-12 17:05:53 +02:00
parent e611d0c721
commit 7b937cc754
3 changed files with 42 additions and 13 deletions

View File

@ -13,7 +13,6 @@ import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
/** /**
* Created by Vladimir Eliezer Tokarev on 8/27/2016. * Created by Vladimir Eliezer Tokarev on 8/27/2016.
* The current voting-booth intialization process is next: * The current voting-booth intialization process is next:
@ -22,7 +21,7 @@ import java.net.URISyntaxException;
public class Main extends Application { public class Main extends Application {
private final Logger logger = LoggerFactory.getLogger(Main.class); private final Logger logger = LoggerFactory.getLogger(Main.class);
private final String CONFIGURATION_PATH = "/configuration/configuration.bin"; private final String DEFAULT_CONFIGURATION_PATH = "/configuration/configuration.bin";
/** /**
* Creates the VotingBoothConfigurationCreator and creates configuration based on given path * Creates the VotingBoothConfigurationCreator and creates configuration based on given path
* @return VotingBoothVonfiguration parsed from json file * @return VotingBoothVonfiguration parsed from json file
@ -30,9 +29,7 @@ public class Main extends Application {
* @throws JSONException will be thrown if the json is unvalid * @throws JSONException will be thrown if the json is unvalid
*/ */
private VotingBoothConfiguration GetConfig() throws IOException, JSONException, URISyntaxException { private VotingBoothConfiguration GetConfig() throws IOException, JSONException, URISyntaxException {
FileInputStream fis = new FileInputStream(getClass().getResource(DEFAULT_CONFIGURATION_PATH).getPath());
FileInputStream fis = new FileInputStream(getClass().getResource(CONFIGURATION_PATH).getPath());
BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions = BallotQuestionUIElementOuterClass.BallotQuestionsUIElements.parseFrom(fis); BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions = BallotQuestionUIElementOuterClass.BallotQuestionsUIElements.parseFrom(fis);
VotingBoothConfiguration votingBoothConfiguration = new VotingBoothConfiguration(); VotingBoothConfiguration votingBoothConfiguration = new VotingBoothConfiguration();
votingBoothConfiguration.NameSelectionQuestion = read_questions.getQuestions(1); votingBoothConfiguration.NameSelectionQuestion = read_questions.getQuestions(1);
@ -43,7 +40,7 @@ public class Main extends Application {
@Override @Override
public void start(Stage primaryStage) throws Exception public void start(Stage primaryStage) throws Exception
{ {
this.logger.debug("Running the app."); this.logger.debug("Started Meerkat Voting GUI Application");
ChainBuilder.Build(primaryStage, GetConfig()); ChainBuilder.Build(primaryStage, GetConfig());
primaryStage.setTitle("Meerkat Polling Station"); primaryStage.setTitle("Meerkat Polling Station");
primaryStage.show(); primaryStage.show();

View File

@ -1,5 +1,7 @@
package meerkat.voting.gui.configuration; package meerkat.voting.gui.configuration;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import meerkat.protobuf.BallotQuestionUIElementOuterClass; import meerkat.protobuf.BallotQuestionUIElementOuterClass;
import org.json.JSONException; import org.json.JSONException;
@ -11,7 +13,13 @@ import java.io.IOException;
* This class uses the configuration creator which converts json configuration into normal binary proto file * This class uses the configuration creator which converts json configuration into normal binary proto file
*/ */
public class Converter { public class Converter {
private final static String OUTPUTNAME = "configuration.bin"; private final static String DEFAULT_OUTPUT_PATH = "configuration.bin";
private final static String DEFAULT_CONFIGURATION_PATH = "VotingBoothConfiguration.json";
private final static String CONVERTER_DESCRIPTION = "Welcome to simple voting booth " +
"configuration converter (which converts json voting booth configuration into " +
"binary configuration).\n-p (path) stands for the path to the json file configuration " +
"which we want to convert into binary file.\n-o (output) stands for the path to which we " +
"want to write the output binary file.\n-?,/?,help (help) stands for this description.\n";
/** /**
* Reads the json configuration from given path * Reads the json configuration from given path
@ -27,9 +35,10 @@ public class Converter {
/** /**
* Converts the configuration file into single binary proto file and writes it to the disc * Converts the configuration file into single binary proto file and writes it to the disc
* @param configuration the configuration object * @param configuration the configuration object
* @param outputPath the path to the new configuraiton file
*/ */
private static void ConvertJsonIntoBinaryFile(VotingBoothConfiguration configuration) throws IOException { private static void ConvertJsonIntoBinaryFile(VotingBoothConfiguration configuration, String outputPath) throws IOException {
FileOutputStream fileOutputStream = new FileOutputStream(OUTPUTNAME); FileOutputStream fileOutputStream = new FileOutputStream(outputPath);
BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions = BallotQuestionUIElementOuterClass.BallotQuestionsUIElements read_questions =
BallotQuestionUIElementOuterClass BallotQuestionUIElementOuterClass
.BallotQuestionsUIElements .BallotQuestionsUIElements
@ -42,12 +51,35 @@ public class Converter {
} }
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
System.out.println("args are: " + args);
try { try {
ConvertJsonIntoBinaryFile(GetVotingBoothJsonConfiguration(args[0])); OptionParser parser = new OptionParser( "p:o:?*.::" );
String configurationPath = "";
String outputPath = "";
OptionSet options = parser.parse(args);
if (options.has("?") || options.has("help")){
System.out.println(CONVERTER_DESCRIPTION);
}
if (!options.has("p")){
configurationPath = DEFAULT_CONFIGURATION_PATH;
}
if (options.has("p")){
configurationPath = (String) options.valueOf("p");
System.out.println("Configuraiton read from " + configurationPath + ".\n");
}
if (!options.has("o")){
outputPath = DEFAULT_OUTPUT_PATH;
}
if (options.has("o")){
outputPath = (String) options.valueOf("o");
}
VotingBoothConfiguration config = GetVotingBoothJsonConfiguration(configurationPath);
System.out.print("yeyyy");
ConvertJsonIntoBinaryFile(config, outputPath);
} }
catch (Exception e) { catch (Exception e) {
System.out.println("Exception thrown: " + e); System.out.println("Exception thrown: " + e + ", " + e.getMessage());
} }
} }

View File

@ -70,7 +70,7 @@ public class VotingBoothConfigurationCreator {
* @throws JSONException will be thrown if the parsing will fail * @throws JSONException will be thrown if the parsing will fail
*/ */
private JSONArray getJsonFromPath(String path) throws FileNotFoundException, JSONException { private JSONArray getJsonFromPath(String path) throws FileNotFoundException, JSONException {
String content = new Scanner(new File(getClass().getResource(path).getPath())).useDelimiter("\\Z").next(); String content = new Scanner(new File(path)).next();
JSONObject jsonObject = new JSONObject(content); JSONObject jsonObject = new JSONObject(content);
this.logger.debug("Created json object from from configuration path."); this.logger.debug("Created json object from from configuration path.");
return (JSONArray)jsonObject.get("questions"); return (JSONArray)jsonObject.get("questions");