forked from fanruan/design
pengda
5 years ago
16 changed files with 111 additions and 109 deletions
@ -1,5 +0,0 @@
|
||||
package com.fr.design.os; |
||||
|
||||
public interface OSBasedAction { |
||||
void execute(); |
||||
} |
@ -1,24 +0,0 @@
|
||||
package com.fr.design.os; |
||||
|
||||
import com.fr.invoke.Reflect; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
public class OSSupportCenter { |
||||
|
||||
private static Map<Class<? extends OSBasedAction>,OSBasedAction> osBasedActionMap = new HashMap<Class<? extends OSBasedAction>,OSBasedAction>(); |
||||
public static void buildAction(OSBasedAction action, SupportOS supportOS){ |
||||
if(supportOS.support()){ |
||||
action.execute(); |
||||
} |
||||
} |
||||
|
||||
public static <T extends OSBasedAction> T getAction(Class<T> clazz) { |
||||
OSBasedAction action = osBasedActionMap.get(clazz); |
||||
if(action == null){ |
||||
action = Reflect.on(clazz).create().get(); |
||||
osBasedActionMap.put(clazz,action); |
||||
} |
||||
return (T) action; |
||||
} |
||||
} |
@ -1,6 +0,0 @@
|
||||
package com.fr.design.os; |
||||
|
||||
public interface SupportOS { |
||||
//判断是否支持
|
||||
boolean support(); |
||||
} |
@ -0,0 +1,59 @@
|
||||
package com.fr.design.os.impl; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.os.OperatingSystem; |
||||
import com.fr.stable.os.support.OSBasedAction; |
||||
|
||||
import java.io.IOException; |
||||
/** |
||||
* @author pengda |
||||
* @date 2019/10/9 |
||||
*/ |
||||
public class DemoAction implements OSBasedAction { |
||||
|
||||
@Override |
||||
public void execute() { |
||||
String installHome = StableUtils.getInstallHome(); |
||||
if (installHome == null) { |
||||
FineLoggerFactory.getLogger().error("Can not find the install home, please check it."); |
||||
return; |
||||
} |
||||
|
||||
String executorPath; |
||||
|
||||
if (OperatingSystem.isMacos()) { |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.app"); |
||||
} else if(OperatingSystem.isWindows()){ |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.exe demo"); |
||||
}else{ |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.sh demo"); |
||||
} |
||||
|
||||
if (OperatingSystem.isMacos()) { |
||||
ProcessBuilder builder = new ProcessBuilder(); |
||||
builder.command("open", "-a", executorPath, "--args", "demo"); |
||||
try { |
||||
builder.start(); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} else if(OperatingSystem.isWindows()){ |
||||
// ProcessBuilder这种方式在window下报错:系统找不到指定文件
|
||||
Runtime rt = Runtime.getRuntime(); |
||||
try { |
||||
rt.exec(executorPath); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
}else{ |
||||
//先用和win一样的方式
|
||||
Runtime rt = Runtime.getRuntime(); |
||||
try { |
||||
rt.exec(executorPath); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -1,56 +1,13 @@
|
||||
package com.fr.start; |
||||
|
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.os.OperatingSystem; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import java.io.IOException; |
||||
import com.fr.design.os.impl.DemoAction; |
||||
import com.fr.stable.os.support.OSBasedAction; |
||||
import com.fr.stable.os.support.OSSupportCenter; |
||||
|
||||
public class Demo { |
||||
public static void main(String[] args) { |
||||
String installHome = StableUtils.getInstallHome(); |
||||
if (installHome == null) { |
||||
FineLoggerFactory.getLogger().error("Can not find the install home, please check it."); |
||||
return; |
||||
} |
||||
|
||||
String executorPath; |
||||
|
||||
if (OperatingSystem.isMacos()) { |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.app"); |
||||
} else if(OperatingSystem.isWindows()){ |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.exe demo"); |
||||
}else{ |
||||
executorPath = StableUtils.pathJoin(installHome, "bin", "designer.sh demo"); |
||||
} |
||||
|
||||
if (OperatingSystem.isMacos()) { |
||||
ProcessBuilder builder = new ProcessBuilder(); |
||||
builder.command("open", "-a", executorPath, "--args", "demo"); |
||||
try { |
||||
builder.start(); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} else if(OperatingSystem.isWindows()){ |
||||
// ProcessBuilder这种方式在window下报错:系统找不到指定文件
|
||||
Runtime rt = Runtime.getRuntime(); |
||||
try { |
||||
rt.exec(executorPath); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
}else{ |
||||
//先用和win一样的方式
|
||||
Runtime rt = Runtime.getRuntime(); |
||||
try { |
||||
rt.exec(executorPath); |
||||
} catch (IOException e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
} |
||||
|
||||
OSBasedAction osBasedAction = OSSupportCenter.getAction(DemoAction.class); |
||||
osBasedAction.execute(); |
||||
System.exit(0); |
||||
} |
||||
} |
Loading…
Reference in new issue