Kaynağa Gözat

优化启动顺序。

yangzhijie 5 yıl önce
ebeveyn
işleme
3ec18949ce

+ 71 - 60
src/main/java/com/leanwo/management/util/FileUtil.java

@@ -8,6 +8,8 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 
 import org.slf4j.Logger;
@@ -17,6 +19,7 @@ import com.leanwo.management.model.ApplicationSetting;
 
 /**
  * 获取程序上级文件夹下的所有文件下的stop.bat和run.bat
+ * 
  * @author GuoZhiBo
  *
  */
@@ -25,76 +28,84 @@ public class FileUtil {
 
 	/**
 	 * 获取文件stop.bat和run.bat
+	 * 
 	 * @param closeables
 	 */
 	public List<ApplicationSetting> getFile() {
 		List<ApplicationSetting> settings = new ArrayList<>();
-		File directory = new File(""); 
+		File directory = new File("");
 		String path = directory.getAbsolutePath();
 		File parentPath = new File(path).getParentFile();
-		 // 取 文件/文件夹
-        File files[] = parentPath.listFiles();
-        
-        // 对象为空 直接返回
-        if(files == null){
-            return settings;
-        }
-        // 存在文件 遍历 判断
-        for (File f : files) {
-            // 判断是否为 文件夹
-            if(f.isDirectory()){
-            	ApplicationSetting applicationSetting = new ApplicationSetting();
-               String filePath = f.getAbsolutePath(); 
-               if(path.equals(filePath)) {
-            	   continue;
-               }
-               File runFile = new File(filePath + "\\run.bat"); 
-               if(!runFile.exists()) {
-            	   continue;
-               }
-               File stopFile = new File(filePath + "\\stop.bat"); 
-               if(!stopFile.exists()) {
-            	   continue;
-               }
-               String name = readFileContent(runFile);
-               name = name.replace("::", "").replace(" ", "").replace("echo", "").replace("title", "");
-               if(name == null || name.length() <= 0) {
-            	   name = f.getName();
-               }
-               applicationSetting.setName(name);
-               applicationSetting.setInstallPath(filePath);
-               applicationSetting.setStartBatFile("run.bat");
-               applicationSetting.setStopBatFile("stop.bat");
-               settings.add(applicationSetting);
-            } 
-            
-        }   
-        return settings;
+		// 取 文件/文件夹
+		File files[] = parentPath.listFiles();
+
+		// 对象为空 直接返回
+		if (files == null) {
+			return settings;
+		}
+		// 存在文件 遍历 判断
+		for (File f : files) {
+			// 判断是否为 文件夹
+			if (f.isDirectory()) {
+				ApplicationSetting applicationSetting = new ApplicationSetting();
+				String filePath = f.getAbsolutePath();
+				if (path.equals(filePath)) {
+					continue;
+				}
+				File runFile = new File(filePath + "\\run.bat");
+				if (!runFile.exists()) {
+					continue;
+				}
+				File stopFile = new File(filePath + "\\stop.bat");
+				if (!stopFile.exists()) {
+					continue;
+				}
+				String name = readFileContent(runFile);
+				name = name.replace("::", "").replace(" ", "").replace("echo", "").replace("title", "");
+				if (name == null || name.length() <= 0) {
+					name = f.getName();
+				}
+				applicationSetting.setName(name);
+				applicationSetting.setInstallPath(filePath);
+				applicationSetting.setStartBatFile("run.bat");
+				applicationSetting.setStopBatFile("stop.bat");
+				settings.add(applicationSetting);
+			}
+		}
+
+		Collections.sort(settings, new Comparator<ApplicationSetting>() {
+			@Override
+			public int compare(ApplicationSetting o1, ApplicationSetting o2) {
+				return o1.getName().compareTo(o2.getName());
+			}
+		});
+
+		return settings;
 	}
-	
+
 	public static String readFileContent(File file) {
-	    BufferedReader reader = null;
-	    StringBuffer sbf = new StringBuffer();
-	    try {
-	        reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
-	        String tempStr = reader.readLine();
-	        sbf.append(tempStr);
+		BufferedReader reader = null;
+		StringBuffer sbf = new StringBuffer();
+		try {
+			reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
+			String tempStr = reader.readLine();
+			sbf.append(tempStr);
 //	        while ((tempStr = reader.readLine()) != null) {
 //	            sbf.append(tempStr);
 //	        }
-	        reader.close();
-	        return sbf.toString();
-	    } catch (IOException e) {
-	        e.printStackTrace();
-	    } finally {
-	        if (reader != null) {
-	            try {
-	                reader.close();
-	            } catch (IOException e1) {
-	                e1.printStackTrace();
-	            }
-	        }
-	    }
-	    return sbf.toString();
+			reader.close();
+			return sbf.toString();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} finally {
+			if (reader != null) {
+				try {
+					reader.close();
+				} catch (IOException e1) {
+					e1.printStackTrace();
+				}
+			}
+		}
+		return sbf.toString();
 	}
 }

+ 1 - 1
src/main/resources/run.bat

@@ -1,4 +1,4 @@
-:: 程序管理器
+:: 1.程序管理器
 title ServerManagement
 cd /d %~dp0
 set current_path=%~dp0