use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.
the class FileLookup method getJava.
// ~~ Utils
/**
* Retrieve the corresponding source file for a given class name.
* It handles innerClass too !
* @param name The fully qualified class name
* @return The virtualFile if found
*/
public VirtualFile getJava(String name) {
String fileName = name;
if (fileName.contains("$")) {
fileName = fileName.substring(0, fileName.indexOf("$"));
}
fileName = fileName.replace(".", "/") + ".java";
for (VirtualFile path : javaPath) {
VirtualFile javaFile = path.child(fileName);
if (javaFile.exists()) {
return javaFile;
}
}
return null;
}
use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.
the class BytecodeCache method cacheBytecode.
/**
* Cache the bytecode
* @param byteCode The bytecode
* @param name The cache name
* @param source The corresponding source
*/
public void cacheBytecode(byte[] byteCode, String name, String source) {
try {
VirtualFile f = cacheFile(name.replace("/", "_").replace("{", "_").replace("}", "_").replace(":", "_"));
try (OutputStream fos = f.openOutputStream()) {
fos.write(hash(source).getBytes("utf-8"));
fos.write(0);
fos.write(byteCode);
}
log.trace(() -> name + "cached");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.
the class TestProdRouter method bothServers.
@SuppressWarnings("rawtypes")
@Parameterized.Parameters
public static Collection bothServers() {
String moduleFileContents = AppModules.class.getName();
VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
TestModule module = new TestModule();
RouterConfig config = new RouterConfig().setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
RouterService prodSvc = RouterSvcFactory.create(config);
return Arrays.asList(new Object[][] { { prodSvc, module } });
}
use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.
the class ErrorCommonTest method createServer.
/**
* Need to live test with browser to see if PRG is better or just returning 404 is better!!!
* Current behavior is to return a 404
*/
//TODO: Test this with browser and then fix for best user experience
// @Test
// public void testNotFoundPostRouteResultsInRedirectToNotFoundCatchAllController() {
// log.info("starting");
// String moduleFileContents = CommonRoutesModules.class.getName();
// RoutingService server = createServer(isProdTest, moduleFileContents);
//
// server.start();
//
// RouterRequest req = RequestCreation.createHttpRequest(HttpMethod.POST, "/notexistpostroute");
// MockResponseStream mockResponseStream = new MockResponseStream();
//
// server.incomingCompleteRequest(req, mockResponseStream);
//
// verifyNotFoundRendered(mockResponseStream);
// }
public static RouterService createServer(boolean isProdTest, String moduleFileContents) {
VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
if (isProdTest)
return RouterSvcFactory.create(f);
//otherwise create the development server
String filePath = System.getProperty("user.dir");
File myCodePath = new File(filePath + "/src/test/java");
CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath));
log.info("bytecode dir=" + compileConfig.getByteCodeCacheDir());
RouterService server = DevRouterFactory.create(f, compileConfig);
return server;
}
use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.
the class TestSimpleRoutes method bothServers.
@SuppressWarnings("rawtypes")
@Parameterized.Parameters
public static Collection bothServers() {
String moduleFileContents = AppModules.class.getName();
VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
TestModule module = new TestModule();
RouterConfig config = new RouterConfig().setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
RouterService prodSvc = RouterSvcFactory.create(config);
//for dev must be null
config.setWebappOverrides(null);
String filePath = System.getProperty("user.dir");
File myCodePath = new File(filePath + "/src/test/java");
CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath));
RouterService devSvc = DevRouterFactory.create(config, compileConfig);
return Arrays.asList(new Object[][] { { prodSvc, module }, { devSvc, module } });
}
Aggregations