Browse Source

运行环境API

master
richie 5 years ago
parent
commit
b5a7b00729
  1. 15
      src/main/java/com/fanruan/api/env/EnvKit.java
  2. 35
      src/test/java/com/fanruan/api/env/EnvKitTest.java

15
src/main/java/com/fanruan/api/env/EnvKit.java vendored

@ -1,8 +1,11 @@
package com.fanruan.api.env; package com.fanruan.api.env;
import com.fr.stable.project.ProjectConstants;
import com.fr.workspace.WorkContext; import com.fr.workspace.WorkContext;
import com.fr.workspace.Workspace; import com.fr.workspace.Workspace;
import com.fr.workspace.resource.WorkResource; import com.fr.workspace.resource.WorkResource;
import com.fr.workspace.simple.SimpleWork;
import org.jetbrains.annotations.NotNull;
/** /**
* @author richie * @author richie
@ -26,4 +29,16 @@ public class EnvKit {
public static WorkResource getWorkResource() { public static WorkResource getWorkResource() {
return WorkContext.getWorkResource(); return WorkContext.getWorkResource();
} }
/**
* 设置一个目录为工作目录
* @param path 工作目录位置
*/
public static void setCurrent(@NotNull String path) {
if (path.endsWith(ProjectConstants.WEBINF_NAME)) {
SimpleWork.checkIn(path);
} else {
throw new IllegalArgumentException("Cannot set " + path + " as work directory.");
}
}
} }

35
src/test/java/com/fanruan/api/env/EnvKitTest.java vendored

@ -0,0 +1,35 @@
package com.fanruan.api.env;
import com.fanruan.api.Prepare;
import org.junit.Assert;
import org.junit.Test;
/**
* @author richie
* @version 10.0
* Created by richie on 2019-08-09
*/
public class EnvKitTest extends Prepare {
@Test
public void getWorkResource() {
String path = "usr/shared/webroot/WEB-INF";
EnvKit.setCurrent(path);
boolean r = EnvKit.getWorkResource().exist("a/b.txt");
Assert.assertFalse(r);
}
@Test
public void getAndSetCurrent() {
String path = "/usr/shared/webroot";
try {
EnvKit.setCurrent(path);
Assert.fail();
} catch (IllegalArgumentException e) {
Assert.assertTrue(true);
}
path = "usr/shared/webroot/WEB-INF";
EnvKit.setCurrent(path);
Assert.assertEquals(EnvKit.getCurrent().getPath(), path);
}
}
Loading…
Cancel
Save