Loading src/main/java/ecorp/easy/installer/controllers/MainWindowController.java +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import ecorp.easy.installer.controllers.stepControllers.CustomStepController; import ecorp.easy.installer.controllers.stepControllers.StepController; import ecorp.easy.installer.models.Phone; import ecorp.easy.installer.models.steps.IStep; import ecorp.easy.installer.tasks.CommandRunnerService; import ecorp.easy.installer.threads.ThreadFactory; import ecorp.easy.installer.utils.UiUtils; Loading Loading @@ -275,6 +276,8 @@ public class MainWindowController implements Initializable { public void setDevice(Phone device){ this.factory.changeMould(device); this.device = device; CommandRunnerService.updateCommonParam("DEVICE_ID", device.getSerialNo()); CommandRunnerService.updateCommonParam("DEVICE_DEVICE", device.getAdbDevice()); } /** Loading Loading @@ -313,7 +316,7 @@ public class MainWindowController implements Initializable { fadeOutTransition.setOnFinished(e -> { removeNodeFromRoot(previousNodeId); logger.debug("removing previous interface finished"); //logger.debug("Fade out for previous interface finished"); final Node subRoot = loadSubUI(fxmlName, viewTitle, controller); if (subRoot != null) { Loading src/main/java/ecorp/easy/installer/tasks/CommandRunnerService.java +67 −6 Original line number Diff line number Diff line /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template * Copyright 2019-2021 - 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 <https://www.gnu.org/licenses/>. */ package ecorp.easy.installer.tasks; import ecorp.easy.installer.AppConstants; import ecorp.easy.installer.models.Command; import java.io.IOException; import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.concurrent.Service; import javafx.concurrent.Task; import org.slf4j.Logger; Loading @@ -16,7 +32,22 @@ import org.slf4j.LoggerFactory; * @author vincent Bourgmayer */ public class CommandRunnerService extends Service<Boolean>{ 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 static Logger logger = LoggerFactory.getLogger(CommandRunnerService.class); private final static HashMap<String, String> COMMON_PARAMS = new HashMap<>(); static { final String sourcePath = AppConstants.getSourcesFolderPath(); COMMON_PARAMS.put("SOURCES_PATH", sourcePath); COMMON_PARAMS.put("TWRP_IMAGE_PATH", sourcePath+AppConstants.getTwrpImgPath()); COMMON_PARAMS.put("ARCHIVE_PATH", sourcePath+AppConstants.getEArchivePath()); COMMON_PARAMS.put("ADB_FOLDER_PATH", AppConstants.getADBFolderPath()); COMMON_PARAMS.put("HEIMDALL_FOLDER_PATH", AppConstants.getHeimdallFolderPath()); COMMON_PARAMS.put("JAVA_FOLDER_PATH", AppConstants.JavaHome); } private final Command cmd; public CommandRunnerService( Command cmd){ Loading @@ -30,6 +61,7 @@ public class CommandRunnerService extends Service<Boolean>{ @Override protected Boolean call() throws Exception { logger.info("Command Task call()"); updateParameters(); try{ cmd.execAndReadOutput(); }catch( IOException | InterruptedException e){ Loading @@ -48,14 +80,13 @@ public class CommandRunnerService extends Service<Boolean>{ String outputKey = cmd.getOutputKey(); //If an output is expected from succeed script //@TODO: uncomment and fix COMMON_PARAM_IDENTIFIER ref /*if( outputKey != null && outputKey.charAt(0) == COMMON_PARAM_IDENTIFIER){ if( outputKey != null && outputKey.charAt(0) == COMMON_PARAM_IDENTIFIER){ final int lastIndex = shellOutput.lastIndexOf("\n"); final int length = shellOutput.length(); final String shellOutputCleaned = shellOutput.substring(lastIndex+1, length); logger.debug("shell output cleaned : "+shellOutputCleaned); this.commonParameters.put(outputKey.replace("${","").replace("}", ""), shellOutputCleaned); }*/ COMMON_PARAMS.put(outputKey.replace("${","").replace("}", ""), shellOutputCleaned); } return true; }else{ //fails case Loading @@ -67,4 +98,34 @@ public class CommandRunnerService extends Service<Boolean>{ return task; } /** * Update parameters of the current command * It is called before to execute the command * @param cmd */ protected void updateParameters(){ //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), COMMON_PARAMS.get(matcher.group(1)))); } }); logger.debug("updateParameters(), Parameters = "+cmd.getParameters().toString()); } } /** * Write a new value for the associated key. * If the value is already present, the precedent value will be overwritten * @param key the key to identify a param * @param value the value of the param */ public static void updateCommonParam(String key, String value){ COMMON_PARAMS.put(key, value); } } Loading
src/main/java/ecorp/easy/installer/controllers/MainWindowController.java +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import ecorp.easy.installer.controllers.stepControllers.CustomStepController; import ecorp.easy.installer.controllers.stepControllers.StepController; import ecorp.easy.installer.models.Phone; import ecorp.easy.installer.models.steps.IStep; import ecorp.easy.installer.tasks.CommandRunnerService; import ecorp.easy.installer.threads.ThreadFactory; import ecorp.easy.installer.utils.UiUtils; Loading Loading @@ -275,6 +276,8 @@ public class MainWindowController implements Initializable { public void setDevice(Phone device){ this.factory.changeMould(device); this.device = device; CommandRunnerService.updateCommonParam("DEVICE_ID", device.getSerialNo()); CommandRunnerService.updateCommonParam("DEVICE_DEVICE", device.getAdbDevice()); } /** Loading Loading @@ -313,7 +316,7 @@ public class MainWindowController implements Initializable { fadeOutTransition.setOnFinished(e -> { removeNodeFromRoot(previousNodeId); logger.debug("removing previous interface finished"); //logger.debug("Fade out for previous interface finished"); final Node subRoot = loadSubUI(fxmlName, viewTitle, controller); if (subRoot != null) { Loading
src/main/java/ecorp/easy/installer/tasks/CommandRunnerService.java +67 −6 Original line number Diff line number Diff line /* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template * Copyright 2019-2021 - 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 <https://www.gnu.org/licenses/>. */ package ecorp.easy.installer.tasks; import ecorp.easy.installer.AppConstants; import ecorp.easy.installer.models.Command; import java.io.IOException; import java.util.HashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.concurrent.Service; import javafx.concurrent.Task; import org.slf4j.Logger; Loading @@ -16,7 +32,22 @@ import org.slf4j.LoggerFactory; * @author vincent Bourgmayer */ public class CommandRunnerService extends Service<Boolean>{ 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 static Logger logger = LoggerFactory.getLogger(CommandRunnerService.class); private final static HashMap<String, String> COMMON_PARAMS = new HashMap<>(); static { final String sourcePath = AppConstants.getSourcesFolderPath(); COMMON_PARAMS.put("SOURCES_PATH", sourcePath); COMMON_PARAMS.put("TWRP_IMAGE_PATH", sourcePath+AppConstants.getTwrpImgPath()); COMMON_PARAMS.put("ARCHIVE_PATH", sourcePath+AppConstants.getEArchivePath()); COMMON_PARAMS.put("ADB_FOLDER_PATH", AppConstants.getADBFolderPath()); COMMON_PARAMS.put("HEIMDALL_FOLDER_PATH", AppConstants.getHeimdallFolderPath()); COMMON_PARAMS.put("JAVA_FOLDER_PATH", AppConstants.JavaHome); } private final Command cmd; public CommandRunnerService( Command cmd){ Loading @@ -30,6 +61,7 @@ public class CommandRunnerService extends Service<Boolean>{ @Override protected Boolean call() throws Exception { logger.info("Command Task call()"); updateParameters(); try{ cmd.execAndReadOutput(); }catch( IOException | InterruptedException e){ Loading @@ -48,14 +80,13 @@ public class CommandRunnerService extends Service<Boolean>{ String outputKey = cmd.getOutputKey(); //If an output is expected from succeed script //@TODO: uncomment and fix COMMON_PARAM_IDENTIFIER ref /*if( outputKey != null && outputKey.charAt(0) == COMMON_PARAM_IDENTIFIER){ if( outputKey != null && outputKey.charAt(0) == COMMON_PARAM_IDENTIFIER){ final int lastIndex = shellOutput.lastIndexOf("\n"); final int length = shellOutput.length(); final String shellOutputCleaned = shellOutput.substring(lastIndex+1, length); logger.debug("shell output cleaned : "+shellOutputCleaned); this.commonParameters.put(outputKey.replace("${","").replace("}", ""), shellOutputCleaned); }*/ COMMON_PARAMS.put(outputKey.replace("${","").replace("}", ""), shellOutputCleaned); } return true; }else{ //fails case Loading @@ -67,4 +98,34 @@ public class CommandRunnerService extends Service<Boolean>{ return task; } /** * Update parameters of the current command * It is called before to execute the command * @param cmd */ protected void updateParameters(){ //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), COMMON_PARAMS.get(matcher.group(1)))); } }); logger.debug("updateParameters(), Parameters = "+cmd.getParameters().toString()); } } /** * Write a new value for the associated key. * If the value is already present, the precedent value will be overwritten * @param key the key to identify a param * @param value the value of the param */ public static void updateCommonParam(String key, String value){ COMMON_PARAMS.put(key, value); } }