Search in sources :

Example 6 with VirtualFile

use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.

the class AbstractCompileTest method createCompileConfig.

protected CompileConfig createCompileConfig() {
    List<VirtualFile> arrayList = new ArrayList<>();
    arrayList.add(new VirtualFileImpl(myCodePath));
    CompileConfig config = new CompileConfig(arrayList, new VirtualFileImpl(byteCodeCacheDir));
    return config;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) ArrayList(java.util.ArrayList) CompileConfig(org.webpieces.compiler.api.CompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl)

Example 7 with VirtualFile

use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.

the class DevTemplateService method loadTemplateImpl.

private Template loadTemplateImpl(OurGroovyClassLoader cl, String fullTemplatePath, String templateFullClassName) throws IOException, ClassNotFoundException {
    if (config.isMustReadClassFromFileSystem()) {
        //shortcut for tests that use PlatformOverridesForTest to ensure we test the production groovy class files AND
        //it ensures we give code coverage numbers on those class files as well.
        Class<?> compiledTemplate = DevTemplateService.class.getClassLoader().loadClass(templateFullClassName);
        return new TemplateImpl(urlLookup, htmlTagLookup, compiledTemplate);
    }
    VirtualFile theResource = null;
    List<VirtualFile> srcPaths = config.getSrcPaths();
    for (VirtualFile f : srcPaths) {
        //take off the leading '/' so it is a relative path
        VirtualFile child = f.child(fullTemplatePath.substring(1));
        if (child.exists()) {
            theResource = child;
            break;
        }
    }
    if (theResource == null)
        theResource = new VirtualFileClasspath(fullTemplatePath, DevTemplateService.class);
    if (!theResource.exists())
        throw new FileNotFoundException("resource=" + fullTemplatePath + " was not found in classpath");
    try (InputStream resource = theResource.openInputStream()) {
        String viewSource = IOUtils.toString(resource, config.getFileEncoding().name());
        Class<?> compiledTemplate = createTemplate(cl, templateFullClassName, viewSource);
        return new TemplateImpl(urlLookup, htmlTagLookup, compiledTemplate);
    }
}
Also used : TemplateImpl(org.webpieces.templating.impl.TemplateImpl) VirtualFile(org.webpieces.util.file.VirtualFile) InputStream(java.io.InputStream) VirtualFileClasspath(org.webpieces.util.file.VirtualFileClasspath) FileNotFoundException(java.io.FileNotFoundException)

Example 8 with VirtualFile

use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.

the class DevRoutingService method reloadIfTextFileChanged.

/**
	 * Only used with DevRouterConfig which is not on classpath in prod mode
	 * 
	 * @return
	 */
private boolean reloadIfTextFileChanged() {
    VirtualFile metaTextFile = config.getMetaFile();
    //if timestamp the same, no changes
    if (lastFileTimestamp == metaTextFile.lastModified())
        return false;
    log.info("text file changed so need to reload RouterModules.java implementation");
    routerModule = routeLoader.load(classLoader, NO_OP);
    lastFileTimestamp = metaTextFile.lastModified();
    return true;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile)

Example 9 with VirtualFile

use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.

the class TestDevRefreshPageWithNoRestarting method setUp.

@Before
public void setUp() throws ClassNotFoundException, IOException {
    Asserts.assertWasCompiledWithParamNames("test");
    userDir = System.getProperty("user.dir");
    log.info("running from dir=" + userDir);
    existingCodeLoc = new File(userDir + "/src/test/java/org/webpieces/webserver/dev/app");
    //developers tend to exit their test leaving the code in a bad state so if they run it again, restore the original
    //version for them(if we change the original version, we have to copy it to this directory as well though :(
    File original = new File(userDir + "/src/test/devServerTest/devServerOriginal");
    FileUtils.copyDirectory(original, existingCodeLoc, null);
    //cache existing code for use by teardown...
    stashedExistingCodeDir = new File(System.getProperty("java.io.tmpdir") + "/webpiecesTestDevServer/app");
    FileUtils.copyDirectory(existingCodeLoc, stashedExistingCodeDir);
    //list all source paths here as you add them(or just create for loop)
    //These are the list of directories that we detect java file changes under
    List<VirtualFile> srcPaths = new ArrayList<>();
    srcPaths.add(new VirtualFileImpl(userDir + "/src/test/java"));
    VirtualFile metaFile = new VirtualFileImpl(userDir + "/src/test/resources/devMeta.txt");
    log.info("LOADING from meta file=" + metaFile.getCanonicalPath());
    //html and json template file encoding...
    TemplateCompileConfig templateConfig = new TemplateCompileConfig(srcPaths);
    //java source files encoding...
    CompileConfig devConfig = new CompileConfig(srcPaths);
    Module platformOverrides = Modules.combine(new DevRouterModule(devConfig), new PlatformOverridesForTest(mgr, time, mockTimer, templateConfig));
    WebserverForTest webserver = new WebserverForTest(platformOverrides, null, false, metaFile);
    webserver.start();
    http11Socket = http11Simulator.openHttp();
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) PlatformOverridesForTest(org.webpieces.webserver.test.PlatformOverridesForTest) DevRouterModule(org.webpieces.devrouter.api.DevRouterModule) WebserverForTest(org.webpieces.webserver.WebserverForTest) ArrayList(java.util.ArrayList) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) CompileConfig(org.webpieces.compiler.api.CompileConfig) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) Module(com.google.inject.Module) DevRouterModule(org.webpieces.devrouter.api.DevRouterModule) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile) Before(org.junit.Before)

Example 10 with VirtualFile

use of org.webpieces.util.file.VirtualFile in project webpieces by deanhiller.

the class TestDevSynchronousErrors method setUp.

@Before
public void setUp() throws InterruptedException, ClassNotFoundException {
    Asserts.assertWasCompiledWithParamNames("test");
    String filePath1 = System.getProperty("user.dir");
    log.info("running from dir=" + filePath1);
    List<VirtualFile> srcPaths = new ArrayList<>();
    srcPaths.add(new VirtualFileImpl(filePath1 + "/src/test/java"));
    TemplateCompileConfig templateConfig = new TemplateCompileConfig(false);
    Module platformOverrides = Modules.combine(new PlatformOverridesForTest(mgr, time, mockTimer, templateConfig), new ForTestingStaticDevelopmentModeModule());
    //you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
    //mocks after every test AND you can no longer run single threaded(tradeoffs, tradeoffs)
    //This is however pretty fast to do in many systems...
    WebserverForTest webserver = new WebserverForTest(platformOverrides, new AppOverridesModule(), false, null);
    webserver.start();
    http11Socket = http11Simulator.openHttp();
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) PlatformOverridesForTest(org.webpieces.webserver.test.PlatformOverridesForTest) WebserverForTest(org.webpieces.webserver.WebserverForTest) ArrayList(java.util.ArrayList) TemplateCompileConfig(org.webpieces.templatingdev.api.TemplateCompileConfig) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) Module(com.google.inject.Module) Before(org.junit.Before)

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