diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 822bf6baf5bb89b6c84710ac1301f4316dc2f5e4..4f8c00f1f36733a42ca04ecea15cd1c8c9032a6d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -23,10 +23,10 @@ check-version:
when: always
build-docker:
- image: docker:stable
+ image: docker:19
stage: prepare
services:
- - docker:18-dind
+ - docker:19-dind
tags:
- generic_privileged
variables:
diff --git a/.gradle/4.10.2/fileChanges/last-build.bin b/.gradle/4.10.2/fileChanges/last-build.bin
deleted file mode 100644
index f76dd238ade08917e6712764a16a22005a50573d..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileChanges/last-build.bin and /dev/null differ
diff --git a/.gradle/4.10.2/fileContent/annotation-processors.bin b/.gradle/4.10.2/fileContent/annotation-processors.bin
deleted file mode 100644
index 6c429036beb29ee317958a48fbf6cabcc7277dec..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileContent/annotation-processors.bin and /dev/null differ
diff --git a/.gradle/4.10.2/fileContent/fileContent.lock b/.gradle/4.10.2/fileContent/fileContent.lock
deleted file mode 100644
index 96f48c30a1adf19e965ea4926ee98fb15f58c5cd..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileContent/fileContent.lock and /dev/null differ
diff --git a/.gradle/4.10.2/fileHashes/fileHashes.bin b/.gradle/4.10.2/fileHashes/fileHashes.bin
deleted file mode 100644
index 1bf314e2ecdacaabb43f61171077a3349dc0508a..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileHashes/fileHashes.bin and /dev/null differ
diff --git a/.gradle/4.10.2/fileHashes/fileHashes.lock b/.gradle/4.10.2/fileHashes/fileHashes.lock
deleted file mode 100644
index 7c248ac0ca5551d6111e57dd0772e99cac7cd1c9..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileHashes/fileHashes.lock and /dev/null differ
diff --git a/.gradle/4.10.2/fileHashes/resourceHashesCache.bin b/.gradle/4.10.2/fileHashes/resourceHashesCache.bin
deleted file mode 100644
index e58f849177f56a8ca4c40812552674c9b439d34f..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/fileHashes/resourceHashesCache.bin and /dev/null differ
diff --git a/.gradle/4.10.2/gc.properties b/.gradle/4.10.2/gc.properties
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/.gradle/4.10.2/javaCompile/classAnalysis.bin b/.gradle/4.10.2/javaCompile/classAnalysis.bin
deleted file mode 100644
index 03bfcd29d64447cf66905fd2c705a291ea10d445..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/javaCompile/classAnalysis.bin and /dev/null differ
diff --git a/.gradle/4.10.2/javaCompile/jarAnalysis.bin b/.gradle/4.10.2/javaCompile/jarAnalysis.bin
deleted file mode 100644
index 3a6991401c3e5dcafd3b1e9bcae48a2eb2d447c5..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/javaCompile/jarAnalysis.bin and /dev/null differ
diff --git a/.gradle/4.10.2/javaCompile/javaCompile.lock b/.gradle/4.10.2/javaCompile/javaCompile.lock
deleted file mode 100644
index 3c0921be961c59db156bab454c370640b46a7122..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/javaCompile/javaCompile.lock and /dev/null differ
diff --git a/.gradle/4.10.2/javaCompile/taskHistory.bin b/.gradle/4.10.2/javaCompile/taskHistory.bin
deleted file mode 100644
index f6b71d73d3e6428ea2867f48ec0d3da27f9c75e9..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/javaCompile/taskHistory.bin and /dev/null differ
diff --git a/.gradle/4.10.2/taskHistory/taskHistory.bin b/.gradle/4.10.2/taskHistory/taskHistory.bin
deleted file mode 100644
index 8ce43b3e3e3664dc5c8ff41e8828d552754a59b2..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/taskHistory/taskHistory.bin and /dev/null differ
diff --git a/.gradle/4.10.2/taskHistory/taskHistory.lock b/.gradle/4.10.2/taskHistory/taskHistory.lock
deleted file mode 100644
index 4082dd9a5dd41201eeb7440e3e221b16e9bccc98..0000000000000000000000000000000000000000
Binary files a/.gradle/4.10.2/taskHistory/taskHistory.lock and /dev/null differ
diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock
deleted file mode 100644
index ed4c7bc1035c480f817ce27d6c12668e5c2e0852..0000000000000000000000000000000000000000
Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and /dev/null differ
diff --git a/.gradle/buildOutputCleanup/cache.properties b/.gradle/buildOutputCleanup/cache.properties
deleted file mode 100644
index 80096eeed04843c6d54549cde526bcc1de68d397..0000000000000000000000000000000000000000
--- a/.gradle/buildOutputCleanup/cache.properties
+++ /dev/null
@@ -1,2 +0,0 @@
-#Wed Nov 20 16:16:15 CET 2019
-gradle.version=4.10.2
diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin
deleted file mode 100644
index e741bd8345505b64575ba0e7f7149d4604920399..0000000000000000000000000000000000000000
Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and /dev/null differ
diff --git a/.gradle/nb-cache/easy-installer-702244358/project-info.ser b/.gradle/nb-cache/easy-installer-702244358/project-info.ser
deleted file mode 100644
index 3d1ba1f8c896fdca07d98cbdea23d68465b4962c..0000000000000000000000000000000000000000
Binary files a/.gradle/nb-cache/easy-installer-702244358/project-info.ser and /dev/null differ
diff --git a/.gradle/nb-cache/easy-installer-702244358/retriever/catalog.xml b/.gradle/nb-cache/easy-installer-702244358/retriever/catalog.xml
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/.gradle/vcs-1/gc.properties b/.gradle/vcs-1/gc.properties
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/build.gradle b/build.gradle
index 828e75c94e71519bf537e6bb0dc4593f3914748a..3370125eaa0c50b05bd725c3c23f1cf5f7fd7793 100644
--- a/build.gradle
+++ b/build.gradle
@@ -49,7 +49,6 @@ mainClassName = "$moduleName/ecorp.easy.installer.EasyInstaller"
dependencies {
compile 'org.yaml:snakeyaml:1.25'
testCompile 'junit:junit:4.12'
- compile fileTree(dir: 'lib', include: ['*.jar'])
}
// Application Configuration
diff --git a/lib/Flash-lib-1.0.jar b/lib/Flash-lib-1.0.jar
deleted file mode 100644
index 27e3f7ef4ae97601edf985c1aef9103faefbe08c..0000000000000000000000000000000000000000
Binary files a/lib/Flash-lib-1.0.jar and /dev/null differ
diff --git a/src/main/java/ecorp/easy/installer/AppConstants.java b/src/main/java/ecorp/easy/installer/AppConstants.java
index 2a9ce15bcfb1845584a9713c091385fd8ade97b7..eb45c4485949304db03c61046ac93af7ce0ecc5b 100644
--- a/src/main/java/ecorp/easy/installer/AppConstants.java
+++ b/src/main/java/ecorp/easy/installer/AppConstants.java
@@ -15,7 +15,6 @@
* along with this program. If not, see .
*/
package ecorp.easy.installer;
-import ecorp.flash.lib.utils.Constants;
import java.nio.file.FileSystems;
import java.io.File;
import java.nio.file.Paths;
@@ -25,8 +24,8 @@ import java.nio.file.Paths;
* @author Vincent Bourgmayer
* @author Omer Akram
*/
-public abstract class AppConstants extends Constants{
-
+public abstract class AppConstants {
+
public final static String Separator = FileSystems.getDefault().getSeparator();
public final static String OsName = System.getProperty("os.name");
public final static String JavaHome = System.getProperty("java.home");
@@ -39,7 +38,51 @@ public abstract class AppConstants extends Constants{
public final static String FEEDBACK_STORAGE_URL ="https://ecloud.global/s/QLwyiZ4fysodiz3";
public final static String LOG_STORAGE_URL ="https://ecloud.global/s/4qRxWjeM5Yb72b4";
private final static String BuildSrcFolderName = "buildSrc";
+
+ // Not fully constructed
+ private static String TWRP_IMAGE_PATH;
+ private static String E_ARCHIVE_PATH;
+ public static String DEVICE_MODEL;
+ public static void setDeviceModel(String deviceModel){
+ DEVICE_MODEL = deviceModel;
+ }
+
+ public static String getDeviceModel(){
+ return DEVICE_MODEL;
+ }
+
+ /**
+ * Get the path to eel OS archive to flash
+ * @return can return null if not already setted
+ */
+ public static String getEArchivePath() {
+ return E_ARCHIVE_PATH;
+ }
+
+ /**
+ * Define the path to access eel OS Archive to flash
+ * @param eImagePath
+ */
+ public static void setEArchivePath(String eImagePath) {
+ E_ARCHIVE_PATH = eImagePath;
+ }
+
+ /**
+ * Get path of TWRP archive to use
+ * @return can return null if not setted
+ */
+ public static String getTwrpImgPath(){
+ return TWRP_IMAGE_PATH;
+ }
+
+ /**
+ * Define where TWRP archive will be store
+ * @param twrpImgPath path to archive
+ */
+ public static void setTwrpImgPath(String twrpImgPath){
+ TWRP_IMAGE_PATH = twrpImgPath;
+ }
/**
* Get path to the folder where the app download source to flash the device
diff --git a/src/main/java/ecorp/easy/installer/EasyInstaller.java b/src/main/java/ecorp/easy/installer/EasyInstaller.java
index 857cf922583f5b6657ad189a65f087381fdbfaef..2a690fdde9340068776e058cd9c1ceb60b389410 100644
--- a/src/main/java/ecorp/easy/installer/EasyInstaller.java
+++ b/src/main/java/ecorp/easy/installer/EasyInstaller.java
@@ -72,7 +72,7 @@ public class EasyInstaller extends Application {
double screenWidth= Screen.getPrimary().getVisualBounds().getWidth();
double screenHeight = Screen.getPrimary().getVisualBounds().getHeight();
-
+ System.out.println("Detected screen dimension: "+screenWidth+"x"+screenHeight);
if(screenWidth >= 1440.0 && screenHeight >= 1024.0){
stage.setWidth(1440);
stage.setHeight(1024);
@@ -80,6 +80,8 @@ public class EasyInstaller extends Application {
stage.setWidth(screenWidth);
stage.setHeight(screenHeight);
}
+
+ System.out.println("Stage (=window) dimension: "+stage.getWidth()+"x"+stage.getHeight());
//Display UI
stage.show();
}
diff --git a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java
index 0ebc1064ab66c0123f685bd29c41cb64fd829247..8f27cabe9a4fa525d1b37ba441990b916d6f8044 100644
--- a/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java
+++ b/src/main/java/ecorp/easy/installer/controllers/subcontrollers/FlashSceneController.java
@@ -19,12 +19,13 @@ package ecorp.easy.installer.controllers.subcontrollers;
import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.controllers.MainWindowController;
import ecorp.easy.installer.graphics.FlashGlobalProgressManager;
+import ecorp.easy.installer.models.DataBundle;
import ecorp.easy.installer.threads.EasilyCancelable;
import ecorp.easy.installer.threads.FlashThread;
import ecorp.easy.installer.threads.TimerTask;
import ecorp.easy.installer.threads.UploadToEcloudTask;
-import ecorp.flash.lib.utils.DataBundle;
-import ecorp.flash.lib.utils.IFlashHandler;
+import ecorp.easy.installer.utils.IFlashHandler;
+
import java.net.URL;
import java.util.List;
import java.util.Locale;
diff --git a/src/main/java/ecorp/easy/installer/logger/FlashLogger.java b/src/main/java/ecorp/easy/installer/logger/FlashLogger.java
index cd0efb5508b777389c60058f1e86fc6374d38d24..cc16fa15afc5de7ee259729b240e19848995a756 100644
--- a/src/main/java/ecorp/easy/installer/logger/FlashLogger.java
+++ b/src/main/java/ecorp/easy/installer/logger/FlashLogger.java
@@ -17,8 +17,7 @@
package ecorp.easy.installer.logger;
import ecorp.easy.installer.AppConstants;
-import ecorp.flash.lib.loggers.AbstractLogger;
-import ecorp.flash.lib.utils.IFlashHandler;
+import ecorp.easy.installer.utils.IFlashHandler;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
@@ -30,9 +29,9 @@ import javafx.application.Platform;
*
* @author vincent Bourgmayer
*/
-public class FlashLogger extends AbstractLogger{
-
- IFlashHandler displayOutput;
+public class FlashLogger{
+ private final StringBuilder logs;
+ private final IFlashHandler displayOutput;
public FlashLogger(IFlashHandler output){
super();
@@ -40,7 +39,7 @@ public class FlashLogger extends AbstractLogger{
this.logs = new StringBuilder();
}
- @Override
+
public void writeLine(String log) {
this.logs.append(log);
Platform.runLater( () -> {
@@ -67,13 +66,26 @@ public class FlashLogger extends AbstractLogger{
return logFilePath;
}
- @Override
+ /**
+ * Write content of log into a file.
+ * @param logFilePath path to the local file
+ * @param log the String to write into a file
+ */
public void writeTofile(String logFilePath, String log) {
- super.writeTofile(logFilePath, log);
+ System.out.println("write log to file");
+ try(PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(logFilePath, true)))) {
+ out.println(log);
+ } catch (IOException e) {
+ System.err.println(e);
+ }
}
- @Override
+ /**
+ * Write a String in the StringBuilder for specified API
+ * @param log The text to write in Log
+ */
public void write(String log) {
- super.write(log); //To change body of generated methods, choose Tools | Templates.
+ if(log != null && ! log.isEmpty())
+ this.logs.append(log);
}
}
diff --git a/src/main/java/ecorp/easy/installer/models/Command.java b/src/main/java/ecorp/easy/installer/models/Command.java
new file mode 100644
index 0000000000000000000000000000000000000000..928e811896aaf63c514089f1dc070389c95fbbac
--- /dev/null
+++ b/src/main/java/ecorp/easy/installer/models/Command.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2019-2020 - ECORP SAS
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package ecorp.easy.installer.models;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Vincent Bourgmayer
+ */
+public class Command {
+ String command; //String containing command to perform
+ volatile boolean cancelled = false; //boolean to tell if it is cancelled or not
+ Map parameters; //Parameters to add to the command
+ private int exitValue; //the exit value of the script.
+ private String shellOutput; //The shell text output of the execution of the script
+ Process pc; //Process which run the command
+ Step step; //Object which contain data about the command like next step, ...
+
+
+ /**
+ * Constructor for instance in context of FlashThread
+ * @param step
+ */
+
+ public Command(String runScriptCmd, Step step){
+ this.step = step;
+ this.command = runScriptCmd+step.getScript();
+ this.parameters = step.getParameters();
+ }
+
+
+ /**
+ * Constructor for command object in context of PreparationThread
+ * @param command
+ */
+ public Command(String command){
+ this.command = command;
+ this.parameters = new HashMap<>();
+ }
+
+ /**
+ * Update a parameter only if already exist
+ * @param key the key of parameter to update
+ * @param value the new value of the param
+ * @return false if param isn't already in the map
+ */
+ public boolean updateParameter(String key, String value){
+ if(parameters.containsKey(key)){
+ this.parameters.put(key, value);
+ return true;
+ }
+ return false;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+
+ public void setCommand(String cmd){
+ this.command = cmd;
+ }
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(HashMap parameters) {
+ this.parameters = parameters;
+ }
+
+ public void addParameter(String key, String value){
+ this.parameters.put(key, value);
+ }
+
+ public int getExitValue() {
+ return exitValue;
+ }
+
+ public void setExitValue(int exitValue) {
+ this.exitValue = exitValue;
+ }
+
+ public String getShellOutput() {
+ return shellOutput;
+ }
+
+ public void setShellOutput(String shellOutput) {
+ this.shellOutput = shellOutput;
+ }
+
+ /**
+ * Build the string that contain full command with its parameters
+ * @return String command and its parameters
+ */
+ public String[] getFinalCmd(){
+ StringBuilder sb = new StringBuilder(command);
+ if(parameters != null){
+ parameters.values().forEach((param) -> {
+ sb.append(" ").append(param);
+ });
+ }
+
+ System.out.println("Splitted command: "+sb.toString());
+ return sb.toString().split(" ");
+ }
+
+ /**
+ * @TODO: change name
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ public void execAndReadOutput() throws IOException, InterruptedException{
+
+ System.out.println("execAndReadOutput() : "+this.command);
+
+ ProcessBuilder pb = new ProcessBuilder(getFinalCmd());
+
+ pb.redirectErrorStream(true);
+ pc= pb.start();
+ System.out.println("Process started");
+ InputStream stdout = pc.getInputStream();
+ InputStreamReader isr = new InputStreamReader (stdout);
+ BufferedReader br = new BufferedReader(isr);
+
+ StringBuilder sb = new StringBuilder();
+ String line;
+ try{
+ while(pc.isAlive() && !cancelled){
+ line = br.readLine();
+ if( line != null && !line.equals("null") ){
+ sb.append("\n\n").append(line);
+ System.out.println("\n"+line);
+ }
+ }
+ this.exitValue = pc.exitValue();
+ }catch(IOException e){
+ System.out.println(e.toString() );
+ this.exitValue = -1;
+ }
+ br.close();
+ isr.close();
+
+ this.shellOutput = sb.toString();
+ if(pc.isAlive())
+ pc.destroy();
+
+ }
+
+ public void cancel(){
+ System.out.println("Command.cancel()");
+ this.cancelled = true;
+ if(pc != null && pc.isAlive())
+ pc.destroy();
+ }
+
+
+ /**
+ * Return the new values for the UI but can be null if there is nothing to change in UI
+ * @return null or StepUI instance
+ */
+ public StepUi getNewUIValues(){
+ return step.getUI();
+ }
+
+ /**
+ * Retourne the key define for output of script
+ * the value is stored in this class property: shellOutput.
+ * @return String can be null
+ */
+
+ public String getOutputKey(){
+ return this.step.getOutput();
+ }
+
+ /**
+ * Return the message associated with the exit Value
+ * @return String can be null if exitValue is not define for this step
+ */
+
+ public String getErrorMsg(){
+ return this.step.getKoCode().getOrDefault(this.exitValue, null);
+ }
+
+ public boolean isSuccess(){
+ if(step.getOkCode() == null ) return (exitValue == 0);
+
+ return this.step.getOkCode().keySet().contains(this.exitValue);
+ }
+
+ public String getNextCommandKey(){
+ if(isSuccess() && !cancelled){
+ return step.getAfterSuccess();
+ }
+ return step.getAfterFail();
+ }
+
+ public boolean mustStartNewThread(){
+ return step.isStartNewThread();
+ }
+}
diff --git a/src/main/java/ecorp/easy/installer/models/DataBundle.java b/src/main/java/ecorp/easy/installer/models/DataBundle.java
new file mode 100644
index 0000000000000000000000000000000000000000..47f5506fc7bf5d7479a316178dd97b37f6f791db
--- /dev/null
+++ b/src/main/java/ecorp/easy/installer/models/DataBundle.java
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2019-2020 - ECORP SAS
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package ecorp.easy.installer.models;
+
+import java.util.AbstractMap.SimpleImmutableEntry;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import java.util.Set;
+
+/**
+ *
+ * @author Vincent Bourgmayer
+ */
+public class DataBundle {
+ private final static String STRING = "String";
+ private final static String INT = "int";
+ private final static String BOOLEAN = "boolean";
+ private final static String LIST ="List<%s>";
+
+ private final Map> datas;
+
+ public DataBundle(){
+ datas = new HashMap<>();
+ }
+
+
+ public void putBoolean(String key, Boolean value){
+ datas.put(key, new SimpleImmutableEntry("boolean", value));
+ }
+
+ public void putInteger(String key, Integer value){
+ datas.put(key, new SimpleImmutableEntry("int", value));
+ }
+
+
+ public void putString(String key, String value){
+ datas.put(key, new SimpleImmutableEntry("String", value));
+ }
+
+ public void putObject(String key, Object value){
+ datas.put(key, new SimpleImmutableEntry(value.getClass().getSimpleName(), value));
+ }
+
+ public void putList(String key, String itemClassName, List list){
+ datas.put(key, new SimpleImmutableEntry(String.format(LIST, itemClassName), list));
+ }
+
+ /**
+ * Return an List of Object
+ * @param key the key of the list in the bundle
+ * @param itemClassName the Object's type
+ * @return
+ */
+ public List getList(String key, String itemClassName){
+ SimpleImmutableEntry p = datas.get(key);
+ if(p != null && p.getKey().equals(String.format(LIST, itemClassName) )){
+ return (List) p.getValue();
+ }else{
+ return null;
+ }
+ }
+
+ public Object getObject(String key, String className){
+ SimpleImmutableEntry p = datas.get(key);
+ if(p != null && p.getKey() == className){
+ return p.getValue();
+ }else{
+ return null;
+ }
+ }
+
+ public Integer getInt(String key) {
+ SimpleImmutableEntry p = datas.get(key);
+ if(p != null && p.getKey() == INT){
+ return (Integer) p.getValue();
+ }else{
+ return null;
+ }
+ }
+
+ public String getString(String key){
+ SimpleImmutableEntry p = datas.get(key);
+ if(p != null && p.getKey() == STRING){
+ return (String) p.getValue();
+ }else{
+ return null;
+ }
+ }
+
+ public Boolean getBoolean(String key){
+ SimpleImmutableEntry p = datas.get(key);
+ if(p != null && p.getKey() == BOOLEAN){
+ return (Boolean) p.getValue();
+ }else{
+ return null;
+ }
+ }
+
+ public Set getKeys(){
+ return datas.keySet();
+ }
+
+}
diff --git a/src/main/java/ecorp/easy/installer/models/ProcessMould.java b/src/main/java/ecorp/easy/installer/models/ProcessMould.java
new file mode 100644
index 0000000000000000000000000000000000000000..2da333f585ececae23cd797046319ab39d24c475
--- /dev/null
+++ b/src/main/java/ecorp/easy/installer/models/ProcessMould.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019-2020 - ECORP SAS
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package ecorp.easy.installer.models;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Vincent Bourgmayer
+ */
+public class ProcessMould {
+
+ String modelName;
+ Map steps;
+
+
+ public ProcessMould(String modelName){
+ this.modelName = modelName;
+ this.steps = new HashMap<>();
+ }
+
+ public void addStep(String key, Step step){
+ this.steps.put(key, step);
+ }
+ public String getModelName() {
+ return modelName;
+ }
+
+ public void setModelName(String modelName) {
+ this.modelName = modelName;
+ }
+
+ public Map getSteps() {
+ return steps;
+ }
+
+ public void setSteps(Map steps) {
+ this.steps = steps;
+ }
+}
diff --git a/src/main/java/ecorp/easy/installer/models/Step.java b/src/main/java/ecorp/easy/installer/models/Step.java
new file mode 100644
index 0000000000000000000000000000000000000000..ae603dcd039082dc3327b8a6e0edf5f4dfa875a2
--- /dev/null
+++ b/src/main/java/ecorp/easy/installer/models/Step.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright 2019-2020 - ECORP SAS
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package ecorp.easy.installer.models;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * @author Vincent Bourgmayer
+ */
+public class Step {
+ private StepUi ui;
+ private boolean startNewThread = false; //define if a new thread should be started if this command succeeds
+ private String script; //script's file script
+ private String output; //Key of output to store as common parameter
+ private String afterSuccess; // index of next script if succeed
+ private String afterFail; //index of next script if failure
+ private Map okCode;
+ private Map koCode;
+ private Map parameters; //parameters to add to the script //@TODO think if is possible to set only one map in Thread instance instead of in each Step.
+
+ public Step(){}
+
+ public Step (Step s){
+ this.script = s.script;
+ afterSuccess = s.afterSuccess;
+ afterFail = s.afterFail;
+ ui = s.ui;
+ okCode = s.okCode;
+ koCode = s.koCode;
+ output = s.output;
+ startNewThread = s.startNewThread;
+ if(s.parameters != null){
+ parameters = new LinkedHashMap<>();
+ for(Map.Entry param : s.parameters.entrySet()){
+ parameters.put(param.getKey(), param.getValue());
+ }
+ }
+ }
+
+ public String getScript() {
+ return script;
+ }
+
+ public void setScript(String name) {
+ this.script = name;
+ }
+
+ public String getOutput() {
+ return output;
+ }
+
+ public void setOutput(String output) {
+ this.output = output;
+ }
+
+ public Map getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(LinkedHashMap parameters) {
+ this.parameters = parameters;
+ }
+ public String getAfterSuccess() {
+ return afterSuccess;
+ }
+
+ public void setAfterSuccess(String afterSuccess) {
+ this.afterSuccess = afterSuccess;
+ }
+
+ public String getAfterFail() {
+ return afterFail;
+ }
+
+ public void setAfterFail(String afterFail) {
+ this.afterFail = afterFail;
+ }
+
+ public Map getOkCode() {
+ return okCode;
+ }
+
+ public void setOkCode(Map okCode) {
+ this.okCode = okCode;
+ }
+
+ public Map getKoCode() {
+ return koCode;
+ }
+
+ public void setKoCode(Map koCode) {
+ this.koCode = koCode;
+ }
+
+ /**
+ * Get the StepUI object which encapsulate new value for UI.
+ * It will be "null" if UI must not change.
+ * @return null or StepUI instance
+ */
+ public StepUi getUI() {
+ return ui;
+ }
+
+ public void setUI(StepUi ui) {
+ this.ui = ui;
+ }
+
+
+ public boolean isStartNewThread() {
+ return startNewThread;
+ }
+
+ public void setStartNewThread(boolean startNewThread) {
+ this.startNewThread = startNewThread;
+ }
+}
diff --git a/src/main/java/ecorp/easy/installer/models/StepUi.java b/src/main/java/ecorp/easy/installer/models/StepUi.java
index 027846358c79bc03e557e8b0db3e80616f69cd7f..68079335f2cbae32c8a935af68ea352747bd7598 100644
--- a/src/main/java/ecorp/easy/installer/models/StepUi.java
+++ b/src/main/java/ecorp/easy/installer/models/StepUi.java
@@ -16,15 +16,17 @@
*/
package ecorp.easy.installer.models;
-import ecorp.flash.lib.models.StepUI;
import java.util.List;
/**
*
* @author vincent Bourgmayer
*/
-public class StepUi extends StepUI{
-
+public class StepUi{
+ private String type; //Can be: error, load or action
+ private List instructions; //Instruction of the step
+ private String title; // Title of the step
+ private String stepNumber; //It correspond more to the state of progression. It should be like: 1/7 not just: 1
final private String titleIconName;
final private String instructionImgName;
final private int averageTime; //in second. The average time required to finsh the step. It only concern 'load' type.
@@ -39,7 +41,10 @@ public class StepUi extends StepUI{
* @param averageTime The number of second needed to finish the step (it's an average)
*/
public StepUi(String type, List instructions, String instructionImgName, String title, String titleIconName, String stepNumber, int averageTime){
- super(type, instructions, title, stepNumber);
+ this.type = type;
+ this.instructions = instructions;
+ this.title = title;
+ this.stepNumber = stepNumber;
this.titleIconName = titleIconName;
this.instructionImgName = instructionImgName;
this.averageTime = averageTime;
@@ -68,4 +73,57 @@ public class StepUi extends StepUI{
public int getAverageTime(){
return this.averageTime;
}
+
+ /**
+ * get the type of Step from UI point of view.
+ * It has mainly impact on background color of the flash box
+ * @return can be null but should be "error", "load" or "action"
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * Define the type of Step from UI point of view.
+ * It has mainly impact on background color of the flash box
+ * @param type should be "error", "load" or "action"
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * Get the instruction to print for user
+ * @return String, but can be null.
+ */
+ public List getInstructions() {
+ return instructions;
+ }
+
+
+ public void setInstruction(List instructions) {
+ this.instructions = instructions;
+ }
+
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ /**
+ * Return the step number as progress.
+ * It will be like "1/7" or something like that.
+ * @return String
+ */
+ public String getStepNumber() {
+ return stepNumber;
+ }
+
+ public void setStepNumber(String stepnumber) {
+ this.stepNumber = stepnumber;
+ }
}
diff --git a/src/main/java/ecorp/easy/installer/threads/DeviceDetectionTask.java b/src/main/java/ecorp/easy/installer/threads/DeviceDetectionTask.java
index 70499932a20484c1a6c4e42ddeff5cf5abfc81db..435522e8aff5ce10bd1ff9fab9714bc3a55ed7e1 100644
--- a/src/main/java/ecorp/easy/installer/threads/DeviceDetectionTask.java
+++ b/src/main/java/ecorp/easy/installer/threads/DeviceDetectionTask.java
@@ -18,8 +18,9 @@ package ecorp.easy.installer.threads;
import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.exceptions.TooManyDevicesException;
+import ecorp.easy.installer.models.Command;
import ecorp.easy.installer.models.Device;
-import ecorp.flash.lib.models.Command;
+
import javafx.concurrent.Task;
/**
diff --git a/src/main/java/ecorp/easy/installer/threads/FlashThread.java b/src/main/java/ecorp/easy/installer/threads/FlashThread.java
index 4dae6d721f9f87540f833d064bf3d386c10b33f3..6ad3752d0256c478129da8432cb2c73ed3483d15 100644
--- a/src/main/java/ecorp/easy/installer/threads/FlashThread.java
+++ b/src/main/java/ecorp/easy/installer/threads/FlashThread.java
@@ -19,20 +19,27 @@ package ecorp.easy.installer.threads;
import ecorp.easy.installer.AppConstants;
import ecorp.easy.installer.logger.FlashLogger;
import ecorp.easy.installer.models.Device;
+import ecorp.easy.installer.models.Command;
+import ecorp.easy.installer.models.DataBundle;
import ecorp.easy.installer.models.StepUi;
+import ecorp.easy.installer.utils.IFlashHandler;
import javafx.application.Platform;
-import ecorp.flash.lib.models.Command;
-import ecorp.flash.lib.threads.AbstractThread;
-import ecorp.flash.lib.utils.Constants;
-import ecorp.flash.lib.utils.DataBundle;
-import ecorp.flash.lib.utils.IFlashHandler;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
*
* @author Vincent Bourgmayer
*/
-public class FlashThread extends AbstractThread implements EasilyCancelable{
+public class FlashThread extends Thread implements EasilyCancelable{
+ final protected static char COMMON_PARAM_IDENTIFIER = '$';//allow to identify when an param of a step is to load from common parameter
+ final protected static Pattern REGEX_FIND_PARAM = Pattern.compile("\\$\\{(.*?)\\}");
+
+ private final FlashLogger logger;
boolean running = false;
boolean cancelled = false;
boolean sendIssueLog = false; //if true then the app must write the file for issue. @TODO replace the word "send" by a word more accurate.
@@ -41,9 +48,14 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
boolean atLeastOneError = false; //Say if there has been at least one issue during all the process
final IFlashHandler application;
final Object pauseLock;
+
final Device device;
-
- /**
+ protected final Map commonParameters; // this is parameters that are define by a script output and that can be use as parameter by another script
+ protected final Map commands;
+ protected String currentStepCode = "";
+ protected final String firstCommandKey;
+
+ /**
* Constructor for flashThread
* @param controller This is the controller which change the UI depending on the flash thread result
* @param firstCommandKey The command key to use to get the first step to perform
@@ -51,7 +63,10 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
* @param device Object containing device info
*/
public FlashThread(IFlashHandler controller, String firstCommandKey, Object pauseLock, Device device){
- super(firstCommandKey, new FlashLogger(controller));
+ this.commands = new HashMap<>();
+ this.commonParameters = new HashMap<>();
+ this.firstCommandKey = firstCommandKey;
+ this.logger = new FlashLogger(controller);
this.application = controller;
this.pauseLock = pauseLock;
this.device = device;
@@ -59,14 +74,25 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
//setParameters
this.commonParameters.put("SOURCES_PATH", sourcePath);
- this.commonParameters.put("TWRP_IMAGE_PATH", sourcePath+Constants.getTwrpImgPath());
- this.commonParameters.put("ARCHIVE_PATH", sourcePath+Constants.getEArchivePath());
+ this.commonParameters.put("TWRP_IMAGE_PATH", sourcePath+AppConstants.getTwrpImgPath());
+ this.commonParameters.put("ARCHIVE_PATH", sourcePath+AppConstants.getEArchivePath());
this.commonParameters.put("ADB_FOLDER_PATH", AppConstants.getADBFolderPath());
this.commonParameters.put("HEIMDALL_FOLDER_PATH", AppConstants.getHeimdallFolderPath());
this.commonParameters.put("DEVICE_ID", device.getAdbId());
this.commonParameters.put("DEVICE_DEVICE", device.getDevice());
}
+
+ /**
+ * Add a command associated to a specific key
+ * @param key must unique or the value associated with will be replaced by new one
+ * @param command Command to add
+ */
+ public void addCommand(String key, Command command){
+ if(command != null && key!= null)
+ commands.put(key, command);
+ }
+
/**
* Handle result of a command
* @param command
@@ -172,8 +198,13 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
}
- @Override
- protected void doBeforeToRunCommand() {
+ /**
+ * Execute some code before to execute the current command
+ * It is runned in the While loop which loops over commands
+ * It's executed in a Try catch.
+ * @throws java.lang.Exception
+ */
+ protected void doBeforeToRunCommand() throws Exception{
//Update UI
final Command cmd = commands.get(currentStepCode);
final DataBundle bundle = new DataBundle();
@@ -212,15 +243,24 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
}
}
}
-
- @Override
- protected void doAfterToRunCommand() {
+
+ /**
+ * Execute some code after the current command has been
+ * It is runned in the While loop which loops over commands
+ * It's executed in a Try catch.
+ * @throws java.lang.Exception
+ */
+ protected void doAfterToRunCommand() throws Exception{
atLeastOneError = (atLeastOneError || !success || cancelled);
sendIssueLog = (atLeastOneError && !cancelled);
}
- @Override
+ /**
+ * Do some code when an error has been raised
+ * It isn't executed in a try catch;
+ * @param e The exception raised for the error
+ */
protected void onErrorRaised(Exception e) {
showError("java_error_unknow");
System.out.println("catched exception "+e.toString());
@@ -230,7 +270,10 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
logger.writeLine("Java exception: "+ e.toString());
}
- @Override
+ /**
+ * Do some code at the real end of "run" methodremove-fs-
+ * It is not executed in a Try Catch;
+ */
protected void onRunEnd() {
final boolean issueEncountered = atLeastOneError;
final DataBundle bundle = new DataBundle();
@@ -241,7 +284,6 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
});
}
- @Override
protected void runInitialization() {
running = true;
}
@@ -257,7 +299,6 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
}
-
@Override
public void run(){
if(commands.isEmpty()) return;
@@ -300,4 +341,24 @@ public class FlashThread extends AbstractThread implements EasilyCancelable{
public int getCommandsSize(){
return this.commands.size();
}
+
+
+ /**
+ * Update parameters of the current command
+ * It is called before to execute the command
+ */
+ protected void updateParameters(){
+ final Command cmd = commands.get(currentStepCode);
+ //Update Parameters
+ if(cmd.getParameters() != null){ //@TODO: remove functionnal and rewrite it as it was before with simple loop.
+ cmd.getParameters().entrySet().stream().filter((param) -> (param.getValue().contains("$"))).forEachOrdered((param) -> {
+ Matcher matcher = REGEX_FIND_PARAM.matcher(param.getValue());
+ while(matcher.find()){
+ cmd.updateParameter(param.getKey(), param.getValue().replace(matcher.group(0), commonParameters.get(matcher.group(1))));
+ }
+ });
+
+ this.logger.write("\n\nParameters : "+cmd.getParameters().toString());
+ }
+ }
}
diff --git a/src/main/java/ecorp/easy/installer/threads/ThreadFactory.java b/src/main/java/ecorp/easy/installer/threads/ThreadFactory.java
index 6e476c55cec93ec4beed7199fd1e91f7ad938804..3c0e062a21895dd2c04d8ebb28e42364a5ea5ec3 100644
--- a/src/main/java/ecorp/easy/installer/threads/ThreadFactory.java
+++ b/src/main/java/ecorp/easy/installer/threads/ThreadFactory.java
@@ -17,14 +17,11 @@
package ecorp.easy.installer.threads;
import ecorp.easy.installer.models.StepUi;
import ecorp.easy.installer.AppConstants;
+import ecorp.easy.installer.models.Command;
import ecorp.easy.installer.models.Device;
-import ecorp.flash.lib.models.Command;
-import ecorp.flash.lib.models.ProcessMould;
-import ecorp.flash.lib.models.Step;
-import ecorp.flash.lib.utils.Constants;
-import ecorp.flash.lib.utils.IPreparationListener;
-import ecorp.flash.lib.utils.IFlashHandler;
-
+import ecorp.easy.installer.models.ProcessMould;
+import ecorp.easy.installer.models.Step;
+import ecorp.easy.installer.utils.IFlashHandler;
import java.io.IOException;
import java.io.InputStream;
import java.security.InvalidParameterException;
@@ -193,10 +190,10 @@ public class ThreadFactory {
for(String key : (Set) sources.keySet() ){
Map source = (Map) sources.get(key);
if(key.equals("rom")){
- Constants.setEArchivePath((String) source.get("filePath"));
+ AppConstants.setEArchivePath((String) source.get("filePath"));
}
if(key.equals("twrp")){
- Constants.setTwrpImgPath((String) source.get("filePath"));
+ AppConstants.setTwrpImgPath((String) source.get("filePath"));
}
sourcesToDownload.put((String) source.get("url"), (String) source.get("filePath"));
}
diff --git a/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java b/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java
new file mode 100644
index 0000000000000000000000000000000000000000..15423d9c1046989b75aa3ad7e7a5d3b0a9573912
--- /dev/null
+++ b/src/main/java/ecorp/easy/installer/utils/IFlashHandler.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2019-2020 - ECORP SAS
+
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package ecorp.easy.installer.utils;
+
+import ecorp.easy.installer.models.DataBundle;
+
+
+/**
+ * @author Vincent Bourgmayer
+ */
+public interface IFlashHandler {
+
+ public void onStepStart(DataBundle bundle);
+
+ public void onFlashError(DataBundle bundle);
+
+ public void onFlashThreadEnd(DataBundle bundle);
+
+ public void onEvent(String eventKey, DataBundle bundle);
+
+ public void onFlashStop(DataBundle bundle);
+
+ public void onLogToDisplayRecieved(String log);
+}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 57fd3066e93c7103000c461bfd933c03f5531598..b8c0b624b4e581fa20fcbd98caac5387f5c7785a 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -22,7 +22,6 @@ module ecorp.easy.installer {
requires javafx.graphics;
requires javafx.base;
requires jdk.crypto.ec; //REQUIRED TO DOWNLOAD OVER HTTPS
- requires ecorp.flash.lib;
requires org.yaml.snakeyaml;
opens ecorp.easy.installer to javafx.fxml;
opens ecorp.easy.installer.controllers to javafx.fxml;