Search in sources :

Example 1 with CompileConfig

use of org.webpieces.compiler.api.CompileConfig in project webpieces by deanhiller.

the class TestDevRefreshPageWithNoRestarting method setUp.

@Before
public void setUp() throws ClassNotFoundException, IOException, InterruptedException, ExecutionException, TimeoutException {
    Asserts.assertWasCompiledWithParamNames("test");
    userDir = System.getProperty("user.dir");
    log.info("running from dir=" + userDir);
    existingCodeLoc = FileFactory.newBaseFile("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 = FileFactory.newBaseFile("src/test/devServerTest/devServerOriginal");
    FileUtils.copyDirectory(original, existingCodeLoc, null);
    // cache existing code for use by teardown...
    stashedExistingCodeDir = FileFactory.newCacheLocation("webpieces/" + getClass().getSimpleName() + "/javaFiles");
    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(VirtualFileFactory.newBaseFile("src/test/java"));
    VirtualFile metaFile = VirtualFileFactory.newBaseFile("src/test/resources/devMeta.txt");
    log.info("LOADING from meta file=" + metaFile.getCanonicalPath());
    // html and json template file encoding...
    TemplateCompileConfig templateConfig = new TemplateCompileConfig(srcPaths);
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + getClass().getSimpleName() + "/bytecode"));
    // java source files encoding...
    CompileConfig devConfig = new CompileConfig(srcPaths, cacheLocation);
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    Module platformOverrides = Modules.combine(new DevRouterModule(devConfig), new OverridesForEmbeddedSvrWithParsing(mgr, time, mockTimer, templateConfig, metrics));
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(platformOverrides, null, false, metaFile);
    webserver.start();
    http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) DevRouterModule(org.webpieces.devrouter.api.DevRouterModule) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) 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) OverridesForEmbeddedSvrWithParsing(org.webpieces.webserver.test.OverridesForEmbeddedSvrWithParsing) Before(org.junit.Before)

Example 2 with CompileConfig

use of org.webpieces.compiler.api.CompileConfig in project webpieces by deanhiller.

the class AbstractCompileTest method createCompileConfig.

protected CompileConfig createCompileConfig() {
    List<VirtualFile> arrayList = new ArrayList<>();
    arrayList.add(new VirtualFileImpl(MY_CODE_PATH));
    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 3 with CompileConfig

use of org.webpieces.compiler.api.CompileConfig in project webpieces by deanhiller.

the class ErrorCommonTest method createServer.

public static RouterService createServer(boolean isProdTest, String moduleFileContents) {
    VirtualFile f = new VirtualFileInputStream(moduleFileContents.getBytes(), "testAppModules");
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    if (isProdTest)
        return RouterServiceFactory.create("ErrorCommonTest", metrics, f, nullApi);
    // otherwise create the development server
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + ErrorCommonTest.class.getSimpleName() + "/bytecode"));
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath), cacheLocation);
    log.info("bytecode dir=" + compileConfig.getByteCodeCacheDir());
    RouterService server = DevRouterFactory.create("ErrorCommonTest", metrics, f, compileConfig, nullApi);
    return server;
}
Also used : VirtualFile(org.webpieces.util.file.VirtualFile) VirtualFileInputStream(org.webpieces.router.api.mocks.VirtualFileInputStream) RouterService(org.webpieces.router.api.RouterService) TemplateApi(org.webpieces.router.api.TemplateApi) NullTemplateApi(org.webpieces.router.api.simplesvr.NullTemplateApi) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) CompileConfig(org.webpieces.compiler.api.CompileConfig) NullTemplateApi(org.webpieces.router.api.simplesvr.NullTemplateApi) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 4 with CompileConfig

use of org.webpieces.compiler.api.CompileConfig 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();
    File baseWorkingDir = FileFactory.getBaseWorkingDir();
    Arguments args = new CommandLineParser().parse();
    RouterConfig config = new RouterConfig(baseWorkingDir, "TestSimpleRoutes").setMetaFile(f).setWebappOverrides(module).setSecretKey(SecretKeyInfo.generateForTest());
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    TemplateApi nullApi = new NullTemplateApi();
    RouterService prodSvc = RouterServiceFactory.create(metrics, config, nullApi);
    prodSvc.configure(args);
    args.checkConsumedCorrectly();
    // for dev must be null
    config.setWebappOverrides(null);
    String filePath = System.getProperty("user.dir");
    File myCodePath = new File(filePath + "/src/test/java");
    VirtualFile cacheLocation = new VirtualFileImpl(FileFactory.newCacheLocation("webpieces/" + TestSimpleRoutes.class.getSimpleName() + "/bytecode"));
    CompileConfig compileConfig = new CompileConfig(new VirtualFileImpl(myCodePath), cacheLocation);
    Arguments args2 = new CommandLineParser().parse();
    SimpleMeterRegistry metrics2 = new SimpleMeterRegistry();
    RouterService devSvc = DevRouterFactory.create(metrics2, config, compileConfig, nullApi);
    devSvc.configure(args2);
    args2.checkConsumedCorrectly();
    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) TemplateApi(org.webpieces.router.api.TemplateApi) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Arguments(org.webpieces.util.cmdline2.Arguments) CompileConfig(org.webpieces.compiler.api.CompileConfig) RouterConfig(org.webpieces.router.api.RouterConfig) CommandLineParser(org.webpieces.util.cmdline2.CommandLineParser) VirtualFileImpl(org.webpieces.util.file.VirtualFileImpl) File(java.io.File) VirtualFile(org.webpieces.util.file.VirtualFile)

Example 5 with CompileConfig

use of org.webpieces.compiler.api.CompileConfig in project webpieces by deanhiller.

the class AbstractCompileTest method setUp.

@Before
public void setUp() {
    LOG.info("storing bytecode cache in=" + byteCodeCacheDir.getAbsolutePath());
    LOG.info("running tests from user.dir=" + FileFactory.getBaseWorkingDir());
    // clear out the bytecode cache (maybe not every time?)
    clearByteCodeCache(byteCodeCacheDir);
    CompileConfig config = createCompileConfig();
    compiler = new CompileOnDemandImpl(config, getPackageFilter());
}
Also used : CompileOnDemandImpl(org.webpieces.compiler.impl.CompileOnDemandImpl) CompileConfig(org.webpieces.compiler.api.CompileConfig) Before(org.junit.Before)

Aggregations

CompileConfig (org.webpieces.compiler.api.CompileConfig)6 VirtualFile (org.webpieces.util.file.VirtualFile)4 VirtualFileImpl (org.webpieces.util.file.VirtualFileImpl)4 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 RouterService (org.webpieces.router.api.RouterService)2 TemplateApi (org.webpieces.router.api.TemplateApi)2 VirtualFileInputStream (org.webpieces.router.api.mocks.VirtualFileInputStream)2 Module (com.google.inject.Module)1 Callable (java.util.concurrent.Callable)1 Test (org.junit.Test)1 CompileOnDemandImpl (org.webpieces.compiler.impl.CompileOnDemandImpl)1 ForTestRouteId (org.webpieces.compiler.impl.test.ForTestRouteId)1 DevRouterModule (org.webpieces.devrouter.api.DevRouterModule)1 RouterConfig (org.webpieces.router.api.RouterConfig)1 NullTemplateApi (org.webpieces.router.api.simplesvr.NullTemplateApi)1 TemplateCompileConfig (org.webpieces.templatingdev.api.TemplateCompileConfig)1 Arguments (org.webpieces.util.cmdline2.Arguments)1