From e2761d15d2d0988ff1bdff6ae76a735364c060de Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sun, 25 Mar 2018 16:36:03 +0530 Subject: [PATCH] update code style fk eclipse did everything wrong --- src/MainActivity.java | 10 +-- src/mkTree/MakeTree.java | 65 ++++++++++--------- src/util/Clean.java | 13 ++-- src/util/ExtractBackup.java | 12 ++-- src/util/GetBuildInfo.java | 22 ++++--- src/util/RunCode.java | 6 +- ...{ShellExecuter.java => ShellExecutor.java} | 2 +- 7 files changed, 71 insertions(+), 59 deletions(-) rename src/util/{ShellExecuter.java => ShellExecutor.java} (99%) diff --git a/src/MainActivity.java b/src/MainActivity.java index 7c078e4..50712d6 100644 --- a/src/MainActivity.java +++ b/src/MainActivity.java @@ -13,11 +13,12 @@ import mkTree.MakeTree; import util.RunCode; -import util.ShellExecuter; +import util.ShellExecutor; public class MainActivity { private static String applicationName = "TwrpBuilder"; + private static ShellExecutor shell; public static void usePosixParser(final String[] commandLineArguments) @@ -82,12 +83,12 @@ public static void usePosixParser(final String[] commandLineArguments) System.out.println("Building tree using: "+g); if(!new File("recovery.img").exists()) { - ShellExecuter.cp(g,"recovery.img"); + shell.cp(g,"recovery.img"); } else { - ShellExecuter.command("rm -rf recovery.img"); - ShellExecuter.cp(g,"recovery.img"); + shell.command("rm -rf recovery.img"); + shell.cp(g,"recovery.img"); } if(commandLine.hasOption("t")) @@ -197,6 +198,7 @@ public static void printHelp( public static void main(final String[] commandLineArguments) { + shell=new ShellExecutor(); if (commandLineArguments.length < 1) { System.out.println("-- USAGE --"); diff --git a/src/mkTree/MakeTree.java b/src/mkTree/MakeTree.java index 83d0ead..3fb58ad 100644 --- a/src/mkTree/MakeTree.java +++ b/src/mkTree/MakeTree.java @@ -5,18 +5,19 @@ import util.*; -import javax.rmi.CORBA.Util; - public class MakeTree { private long l=0; private String compressionType; private boolean lz4,lzma; - private String fstabIdata=ShellExecuter.CopyRight(); + private ShellExecutor shell; + private String copyRight=shell.CopyRight(); public static boolean otg; private GetBuildInfo info; private Config config; private String out; public MakeTree(boolean mtk,String type){ + config=new Config(); + shell=new ShellExecutor(); out=config.outDir; if(mtk) { @@ -28,7 +29,7 @@ public MakeTree(boolean mtk,String type){ extractFstab(); info=new GetBuildInfo(); - if(!ShellExecuter.mkdir(info.getPathS())) + if(!shell.mkdir(info.getPathS())) { System.out.println("Failed to make dir"); System.exit(0); @@ -36,7 +37,7 @@ public MakeTree(boolean mtk,String type){ if(info.getCodename().isEmpty()) { - ShellExecuter.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+info.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop"); + shell.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+info.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop"); if(info.getCodename().isEmpty()) { System.out.println("Failed to get info"); @@ -66,15 +67,15 @@ public MakeTree(boolean mtk,String type){ private void extractKernel(boolean mtk) { - ShellExecuter.command("chmod 777 umkbootimg"); + shell.command("chmod 777 umkbootimg"); if(mtk) { - ShellExecuter.command("./umkbootimg recovery.img"); + shell.command("./umkbootimg recovery.img"); } else { - ShellExecuter.mkdir(out); - ShellExecuter.command("./umkbootimg -i recovery.img -o "+out); + shell.mkdir(out); + shell.command("./umkbootimg -i recovery.img -o "+out); } } @@ -82,12 +83,12 @@ private void mkKernel(boolean mtk) { System.out.println("Making kernel.mk"); if(new File(out+"recovery.img-zImage").exists()) { - ShellExecuter.cp(out+"recovery.img-zImage", info.getPathS()+"kernel"); + shell.cp(out+"recovery.img-zImage", info.getPathS()+"kernel"); } if(new File(out+"recovery.img-dt").length()!=l) { - ShellExecuter.cp(out+"recovery.img-dt", info.getPathS()+"dt.img"); + shell.cp(out+"recovery.img-dt", info.getPathS()+"dt.img"); new FWriter("kernel.mk",getKernelData(true)); }else { new FWriter("kernel.mk",getKernelData(false)); @@ -97,12 +98,12 @@ private void mkKernel(boolean mtk) { private String getKernelData(boolean dt) { String idata; - String pagesize=ShellExecuter.commandnoapp("cat "+out+"recovery.img-pagesize"); - String cmdline=ShellExecuter.commandnoapp("cat "+out+"recovery.img-cmdline"); - String ramdiskofsset=ShellExecuter.commandnoapp("cat "+out+"recovery.img-ramdisk_offset"); - String tagsoffset=ShellExecuter.commandnoapp("cat "+out+"recovery.img-tags_offset"); - String kernelbase=ShellExecuter.commandnoapp("cat "+out+"recovery.img-base"); - idata=ShellExecuter.CopyRight(); + String pagesize=shell.commandnoapp("cat "+out+"recovery.img-pagesize"); + String cmdline=shell.commandnoapp("cat "+out+"recovery.img-cmdline"); + String ramdiskofsset=shell.commandnoapp("cat "+out+"recovery.img-ramdisk_offset"); + String tagsoffset=shell.commandnoapp("cat "+out+"recovery.img-tags_offset"); + String kernelbase=shell.commandnoapp("cat "+out+"recovery.img-base"); + idata=copyRight; idata+="# Kernel\n" + "TARGET_PREBUILT_KERNEL := "+info.getPathS()+"kernel\n" + "BOARD_KERNEL_CMDLINE := "+cmdline+" androidboot.selinux=permissive\n" + @@ -117,21 +118,21 @@ private String getKernelData(boolean dt) { } public void extractFstab() { - compressionType=ShellExecuter.commandnoapp("cd "+out+" && file --mime-type recovery.img-ramdisk.* | cut -d / -f 2 | cut -d '-' -f 2"); + compressionType=shell.commandnoapp("cd "+out+" && file --mime-type recovery.img-ramdisk.* | cut -d / -f 2 | cut -d '-' -f 2"); if(compressionType.equals("lzma")) { System.out.println("Found lzma comression in ramdisk"); - ShellExecuter.command("mv "+out+"recovery.img-ramdisk.gz "+out+"recovery.img-ramdisk.lzma && lzma -d "+out+"recovery.img-ramdisk.lzma && cd "+out+" && cpio -i > " +info.getPath()+"/kernel.mk"); + shell.command("echo "+idata +" >> " +info.getPath()+"/kernel.mk"); } } @@ -271,7 +272,7 @@ public void MkOmni() { } private String getOmniData() { - String idata =ShellExecuter.CopyRight(); + String idata =copyRight; idata+="$(call inherit-product, $(SRC_TARGET_DIR)/product/full_base.mk)\n" + "\n" + "PRODUCT_COPY_FILES += "+info.getPathS()+"kernel:kernel\n" + @@ -292,7 +293,7 @@ public void MkAndroid() { } private String getAndroidtData() { - String idata =ShellExecuter.CopyRight(); + String idata =copyRight; idata+="ifneq ($(filter "+info.getCodename()+",$(TARGET_DEVICE)),)\n" + "\n" + "LOCAL_PATH := "+info.getPath()+"\n" + @@ -310,7 +311,7 @@ public void MkAndroidProducts() { } private String getAndroidProductsData() { - String idata =ShellExecuter.CopyRight(); + String idata =copyRight; idata+="LOCAL_PATH := "+info.getPath()+"\n" + "\n" + "PRODUCT_MAKEFILES := $(LOCAL_PATH)/omni_"+info.getCodename()+".mk"; @@ -328,7 +329,7 @@ public void MkBoardConfig(String type){ } private String getBoardData(String type) { - String idata =ShellExecuter.CopyRight(); + String idata =copyRight; idata+="LOCAL_PATH := "+info.getPath()+"\n" + "\n" + "TARGET_BOARD_PLATFORM := "+info.getPlatform()+"\n" + diff --git a/src/util/Clean.java b/src/util/Clean.java index 61f7cd5..eed1d3a 100644 --- a/src/util/Clean.java +++ b/src/util/Clean.java @@ -3,26 +3,27 @@ import java.io.File; public class Clean { - + private ShellExecutor shell; public Clean(){ - ShellExecuter.commandnoapp("rm -rf build.prop recovery.img " ); + shell=new ShellExecutor(); + shell.commandnoapp("rm -rf build.prop recovery.img " ); if (new File("mounts").exists()) { - ShellExecuter.commandnoapp("rm mounts "); + shell.commandnoapp("rm mounts "); } if (new File("umkbootimg").exists()) { - ShellExecuter.commandnoapp("rm umkbootimg"); + shell.commandnoapp("rm umkbootimg"); } if (new File(Config.outDir).exists()) { - ShellExecuter.commandnoapp("rm -rf "+Config.outDir); + shell.commandnoapp("rm -rf "+Config.outDir); } if(new File("unpack-MTK.pl").exists()) { - ShellExecuter.command("rm unpack-MTK.pl"); + shell.command("rm unpack-MTK.pl"); } } diff --git a/src/util/ExtractBackup.java b/src/util/ExtractBackup.java index 21aa355..59f53fe 100644 --- a/src/util/ExtractBackup.java +++ b/src/util/ExtractBackup.java @@ -4,9 +4,11 @@ public class ExtractBackup { private String rooted; private String not_rooted; + private ShellExecutor shell; public ExtractBackup(String name) { - rooted=ShellExecuter.commandnoapp("file --mime-type "+name+" | grep -w 'gzip' | cut -d / -f 2 | cut -d \"-\" -f 2"); - not_rooted=ShellExecuter.commandnoapp("file --mime-type "+name+" | grep -w 'zip' | cut -d / -f 2 | cut -d \"-\" -f 2"); + shell=new ShellExecutor(); + rooted= shell.commandnoapp("file --mime-type "+name+" | grep -w 'gzip' | cut -d / -f 2 | cut -d \"-\" -f 2"); + not_rooted= shell.commandnoapp("file --mime-type "+name+" | grep -w 'zip' | cut -d / -f 2 | cut -d \"-\" -f 2"); if(rooted.equals("gzip")) { extractGzip(name); @@ -21,12 +23,12 @@ else if(not_rooted.equals("zip")) } private void extractGzip(String file) { - ShellExecuter.command("tar -xvf " + file); + shell.command("tar -xvf " + file); } private void extractZip(String file) { - ShellExecuter.command("unzip -o "+ file); - ShellExecuter.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+GetBuildInfo.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop"); + shell.command("unzip -o "+ file); + shell.command("sed 's/\\[\\([^]]*\\)\\]/\\1/g' "+GetBuildInfo.propFile()+" | sed 's/: /=/g' | tee > b.prop && mv -f b.prop build.prop"); new GetBuildInfo(); } } diff --git a/src/util/GetBuildInfo.java b/src/util/GetBuildInfo.java index 63ab648..96d151b 100644 --- a/src/util/GetBuildInfo.java +++ b/src/util/GetBuildInfo.java @@ -7,7 +7,11 @@ public class GetBuildInfo { private static String model,product,brand,codename,platform,api,size,fingerprint; private static Config config; private static String out=config.outDir; + private static ShellExecutor shell; + public static String propFile() { + shell=new ShellExecutor(); + config=new Config(); String prop=null; if(new File("build.prop").exists()) { @@ -25,17 +29,17 @@ public static String propFile() { } public static String getModel() { - model=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.model= | cut -d = -f 2"); + model= shell.commandnoapp("cat "+propFile()+" | grep ro.product.model= | cut -d = -f 2"); return model; } public static String getProduct(){ - product=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2"); + product= shell.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2"); return product; } public static String getBrand() { - brand=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.brand= | cut -d = -f 2"); + brand= shell.commandnoapp("cat "+propFile()+" | grep ro.product.brand= | cut -d = -f 2"); if(brand.contains("-")) { String newstr=brand.replace("-", "_"); @@ -46,7 +50,7 @@ public static String getBrand() { } public static String getCodename() { - codename=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2"); + codename= shell.commandnoapp("cat "+propFile()+" | grep ro.build.product= | cut -d = -f 2"); if(codename.contains("-")) { String newstr=codename.replace("-", "_"); @@ -63,10 +67,10 @@ else if (codename.contains(" ")) } public static String getPlatform() { - platform=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.board.platform= | cut -d = -f 2"); + platform= shell.commandnoapp("cat "+propFile()+" | grep ro.board.platform= | cut -d = -f 2"); if (platform.isEmpty()) { - platform=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.mediatek.platform= | cut -d = -f 2"); + platform= shell.commandnoapp("cat "+propFile()+" | grep ro.mediatek.platform= | cut -d = -f 2"); if(platform.isEmpty()) { System.out.println("Device not supported"); @@ -77,17 +81,17 @@ public static String getPlatform() { } public static String getApi() { - api=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.product.cpu.abi= | cut -d = -f 2"); + api= shell.commandnoapp("cat "+propFile()+" | grep ro.product.cpu.abi= | cut -d = -f 2"); return api; } public static String getFingerPrint() { - fingerprint=ShellExecuter.commandnoapp("cat "+propFile()+" | grep ro.build.fingerprint= | cut -d = -f 2"); + fingerprint= shell.commandnoapp("cat "+propFile()+" | grep ro.build.fingerprint= | cut -d = -f 2"); return fingerprint; } public static String getSize() { - size=ShellExecuter.commandnoapp("wc -c < recovery.img"); + size= shell.commandnoapp("wc -c < recovery.img"); return size; } diff --git a/src/util/RunCode.java b/src/util/RunCode.java index 1614270..f071494 100644 --- a/src/util/RunCode.java +++ b/src/util/RunCode.java @@ -9,6 +9,7 @@ public class RunCode implements Runnable{ private boolean mtk; private boolean samsung; public static boolean extract; + private ShellExecutor shell; public RunCode(String name) { RunCode.name=name; new GetAsset("umkbootimg"); @@ -17,17 +18,18 @@ public RunCode(String name) { public RunCode(String name,String type) { RunCode.name=name; RunCode.type=type; + shell=new ShellExecutor(); if(type.equals("mrvl")) { new GetAsset("degas-umkbootimg"); - ShellExecuter.commandnoapp("mv degas-umkbootimg umkbootimg "); + shell.commandnoapp("mv degas-umkbootimg umkbootimg "); mrvl=true; } else if(type.equals("mt") || type.equals("mtk")) { new GetAsset("unpack-MTK.pl"); - ShellExecuter.commandnoapp("mv unpack-MTK.pl umkbootimg"); + shell.commandnoapp("mv unpack-MTK.pl umkbootimg"); mtk=true; } else if(type.equals("samsung")) diff --git a/src/util/ShellExecuter.java b/src/util/ShellExecutor.java similarity index 99% rename from src/util/ShellExecuter.java rename to src/util/ShellExecutor.java index 0eb6378..6ecc08d 100644 --- a/src/util/ShellExecuter.java +++ b/src/util/ShellExecutor.java @@ -6,7 +6,7 @@ import java.io.InputStreamReader; import java.nio.file.Files; -public class ShellExecuter { +public class ShellExecutor { public static String command(String command) { Process process; String o=null;