55import java .io .FileNotFoundException ;
66import java .io .FileReader ;
77import java .io .FileWriter ;
8+ import java .io .FilenameFilter ;
89import java .io .IOException ;
10+ import java .io .UnsupportedEncodingException ;
11+ import java .nio .file .Paths ;
912import java .util .HashMap ;
1013import java .util .List ;
1114import java .util .Set ;
@@ -242,7 +245,7 @@ private static void readConfig(String configFilePath) throws NumberFormatExcepti
242245 }
243246 }
244247
245- private static void checkAndPrepareParameters () throws MutAPKException {
248+ private static void checkAndPrepareParameters () throws MutAPKException , IOException {
246249 // TODO Auto-generated method stub
247250
248251 // Preprocess paths to fit to OS filsesystem format
@@ -260,14 +263,48 @@ private static void checkAndPrepareParameters() throws MutAPKException {
260263
261264 // Check general parameters
262265
263- // apkPath exists and to identify if it is an absolute or a relative path
264- // appName to not be empty
266+ String decodedPath = Helper .getInstance ().getCurrentDirectory ();
267+ // apkPath exists
268+ if (!(new File (Paths .get (decodedPath , apkPath ).toAbsolutePath ().toString ())).exists ()){
269+ throw new MutAPKException ("Path to APK is not correct. The path does not exist." );
270+ }
265271 // mutantsfolder exists (in case it does not exist to create it) and to identify if it is an absolute or a relative path
272+ File mutantsFolderFO = new File (Paths .get (decodedPath , mutantsFolder ).toAbsolutePath ().toString ());
273+ if (!mutantsFolderFO .exists ()){
274+ mutantsFolderFO .mkdirs ();
275+ }
266276
267-
268- // operatorsDir if the folder exists, check if exists a .properties file, and if it is an absolute or relative path
277+ // operatorsDir if the folder exists, check if exists a .properties file
278+ File operFolderFO = new File (Paths .get (decodedPath , operatorsDir ).toAbsolutePath ().toString ());
279+ if (!operFolderFO .exists ()){
280+ throw new MutAPKException ("Path to operator file is not correct. The path does not exist." );
281+ }
282+ System .out .println (operFolderFO .getCanonicalPath ().toString ());
283+ File [] properties = operFolderFO .listFiles (new FilenameFilter () {
284+
285+ @ Override
286+ public boolean accept (File dir , String name ) {
287+ return name .endsWith ("operators.properties" );
288+ }
289+ });
290+ if (properties .length ==0 ) {
291+ throw new MutAPKException ("Path to operators config file is not correct. No operators.properties file exist in folder" );
292+ }
269293 // extraPath if it is a parameter of JSON, if the folder exists and if it is an absolute or relative path
270-
294+ File extraFolderFO = new File (Paths .get (decodedPath , extraPath ).toAbsolutePath ().toString ());
295+ if (!extraFolderFO .exists ()){
296+ throw new MutAPKException ("Path to extra folder is not correct. The path does not exist." );
297+ }
298+ File [] extraFO = extraFolderFO .listFiles (new FilenameFilter () {
299+
300+ @ Override
301+ public boolean accept (File dir , String name ) {
302+ return ( name .endsWith ("apktool.jar" ) || name .endsWith ("uber-apk-signer.jar" ) || name .endsWith ("materialistic.jks" ));
303+ }
304+ });
305+ if (extraFO .length <3 ) {
306+ throw new MutAPKException ("Path to extra folder is not correct. No valid extra folder was provided." );
307+ }
271308
272309 // Check specific selection strategy parameters
273310 switch (selectionStrategy ) {
0 commit comments