Search in sources :

Example 11 with VirtualFile

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;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile)

Example 12 with VirtualFile

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);
    }
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) OutputStream(java.io.OutputStream)

Example 13 with VirtualFile

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 } });
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) RouterConfig(org.webpieces.router.api.RouterConfig)

Example 14 with VirtualFile

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;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) CompileConfig(org.webpieces.compiler.api.CompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 15 with VirtualFile

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 } });
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) CompileConfig(org.webpieces.compiler.api.CompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) RouterConfig(org.webpieces.router.api.RouterConfig)

Aggregations

VirtualFile (org.webpieces.util.file.VirtualFile)15 ArrayList (java.util.ArrayList)5 VirtualFileImpl (org.webpieces.util.file.VirtualFileImpl)5 CompileConfig (org.webpieces.compiler.api.CompileConfig)4 File (java.io.File)3 RouterService (org.webpieces.router.api.RouterService)3 VirtualFileInputStream (org.webpieces.router.api.mocks.VirtualFileInputStream)3 Module (com.google.inject.Module)2 InputStream (java.io.InputStream)2 Before (org.junit.Before)2 RouterConfig (org.webpieces.router.api.RouterConfig)2 TemplateCompileConfig (org.webpieces.templatingdev.api.TemplateCompileConfig)2 WebserverForTest (org.webpieces.webserver.WebserverForTest)2 PlatformOverridesForTest (org.webpieces.webserver.test.PlatformOverridesForTest)2 Injector (com.google.inject.Injector)1 FileNotFoundException (java.io.FileNotFoundException)1 OutputStream (java.io.OutputStream)1 ClassDefinition (java.lang.instrument.ClassDefinition)1 URL (java.net.URL)1 Charset (java.nio.charset.Charset)1