Search in sources :

Example 1 with FeatureFlags

use of com.vaadin.experimental.FeatureFlags in project flow by vaadin.

the class BuildFrontendUtil method runFrontendBuild.

/**
 * Execute the frontend build with the wanted build system.
 *
 * @param adapter
 *            - the PluginAdapterBase.
 * @throws TimeoutException
 *             - while running build system
 * @throws URISyntaxException
 *             - while parsing nodeDownloadRoot()) to URI
 */
public static void runFrontendBuild(PluginAdapterBase adapter) throws TimeoutException, URISyntaxException {
    ClassFinder classFinder = adapter.getClassFinder();
    Lookup lookup = adapter.createLookup(classFinder);
    final FeatureFlags featureFlags = new FeatureFlags(lookup);
    featureFlags.setPropertiesLocation(adapter.javaResourceFolder());
    FrontendToolsSettings settings = getFrontendToolsSettings(adapter);
    FrontendTools tools = new FrontendTools(settings);
    if (featureFlags.isEnabled(FeatureFlags.VITE)) {
        BuildFrontendUtil.runVite(adapter, tools);
    } else {
        BuildFrontendUtil.runWebpack(adapter, tools);
    }
}
Also used : FrontendToolsSettings(com.vaadin.flow.server.frontend.FrontendToolsSettings) ClassFinder(com.vaadin.flow.server.frontend.scanner.ClassFinder) ReflectionsClassFinder(com.vaadin.flow.server.scanner.ReflectionsClassFinder) Lookup(com.vaadin.flow.di.Lookup) FeatureFlags(com.vaadin.experimental.FeatureFlags) FrontendTools(com.vaadin.flow.server.frontend.FrontendTools)

Example 2 with FeatureFlags

use of com.vaadin.experimental.FeatureFlags in project flow by vaadin.

the class AbstractNodeUpdatePackagesTest method setup.

@Before
public void setup() throws Exception {
    baseDir = temporaryFolder.getRoot();
    featureFlags = Mockito.mock(FeatureFlags.class);
    generatedDir = new File(baseDir, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
    resourcesDir = new File(baseDir, Paths.get(TARGET, DEFAULT_FLOW_RESOURCES_FOLDER).toString());
    FrontendStubs.createStubNode(true, true, baseDir.getAbsolutePath());
    packageCreator = new TaskGeneratePackageJson(baseDir, generatedDir, resourcesDir, TARGET, featureFlags);
    classFinder = Mockito.spy(getClassFinder());
    File versions = temporaryFolder.newFile();
    FileUtils.write(versions, "{}", StandardCharsets.UTF_8);
    Mockito.when(classFinder.getResource(Constants.VAADIN_VERSIONS_JSON)).thenReturn(versions.toURI().toURL());
    packageUpdater = new TaskUpdatePackages(classFinder, getScanner(classFinder), baseDir, generatedDir, resourcesDir, false, false, TARGET, featureFlags);
    packageJson = new File(baseDir, PACKAGE_JSON);
    mainNodeModules = new File(baseDir, FrontendUtils.NODE_MODULES);
    appNodeModules = new File(generatedDir, FrontendUtils.NODE_MODULES);
    packageLock = new File(baseDir, "package-lock.json");
}
Also used : FeatureFlags(com.vaadin.experimental.FeatureFlags) File(java.io.File) Before(org.junit.Before)

Example 3 with FeatureFlags

use of com.vaadin.experimental.FeatureFlags in project flow by vaadin.

the class BootstrapHandlerTest method enableViteFeature.

private void enableViteFeature(boolean productionMode) throws IOException {
    VaadinContext vaadinContext = Mockito.mock(VaadinContext.class);
    final Lookup lookup = Mockito.mock(Lookup.class);
    ResourceProvider resourceProvider = Mockito.mock(ResourceProvider.class);
    Mockito.when(lookup.lookup(ResourceProvider.class)).thenReturn(resourceProvider);
    Mockito.when(resourceProvider.getClientResourceAsStream("META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH + "/compile.properties")).thenReturn(getClass().getClassLoader().getResourceAsStream("META-INF/resources/" + ApplicationConstants.CLIENT_ENGINE_PATH + "/compile.properties"));
    Mockito.when(vaadinContext.getAttribute(Lookup.class)).thenReturn(lookup);
    service.setContext(vaadinContext);
    ApplicationConfiguration configuration = Mockito.mock(ApplicationConfiguration.class);
    Mockito.when(configuration.isProductionMode()).thenReturn(false);
    Mockito.when(configuration.getJavaResourceFolder()).thenReturn(tmpDir.getRoot());
    Mockito.when(lookup.lookup(ApplicationConfiguration.class)).thenReturn(configuration);
    Mockito.when(vaadinContext.getAttribute(ApplicationConfiguration.class)).thenReturn(configuration);
    Mockito.when(vaadinContext.getAttribute(Mockito.eq(ApplicationConfiguration.class), Mockito.any())).thenReturn(configuration);
    final FeatureFlags featureFlags = FeatureFlags.get(testUI.getSession().getService().getContext());
    Mockito.when(vaadinContext.getAttribute(FeatureFlags.class)).thenReturn(featureFlags);
    featureFlags.setEnabled(FeatureFlags.VITE.getId(), true);
    Mockito.when(configuration.isProductionMode()).thenReturn(productionMode);
}
Also used : ResourceProvider(com.vaadin.flow.di.ResourceProvider) Lookup(com.vaadin.flow.di.Lookup) FeatureFlags(com.vaadin.experimental.FeatureFlags) ApplicationConfiguration(com.vaadin.flow.server.startup.ApplicationConfiguration)

Example 4 with FeatureFlags

use of com.vaadin.experimental.FeatureFlags in project flow by vaadin.

the class ComponentFlagsTest method before.

@Before
public void before() throws IOException {
    tmpRoot = temporaryFolder.getRoot();
    propertiesDir = temporaryFolder.newFolder();
    featureFlags = new FeatureFlags(Mockito.mock(Lookup.class));
    featureFlags.setPropertiesLocation(propertiesDir);
    frontendDirectory = new File(tmpRoot, DEFAULT_FRONTEND_DIR);
    nodeModulesPath = new File(tmpRoot, NODE_MODULES);
    generatedPath = new File(tmpRoot, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
    importsFile = new File(generatedPath, IMPORTS_NAME);
    assertTrue(nodeModulesPath.mkdirs());
    createExpectedImports(frontendDirectory, nodeModulesPath);
}
Also used : FeatureFlags(com.vaadin.experimental.FeatureFlags) File(java.io.File) Before(org.junit.Before)

Example 5 with FeatureFlags

use of com.vaadin.experimental.FeatureFlags in project flow by vaadin.

the class NodeUpdatePackagesNpmVersionLockingTest method setup.

@Before
public void setup() throws Exception {
    baseDir = temporaryFolder.getRoot();
    featureFlags = Mockito.mock(FeatureFlags.class);
    generatedDir = new File(baseDir, Paths.get(TARGET, DEFAULT_GENERATED_DIR).toString());
    resourcesDir = new File(baseDir, Paths.get(TARGET, DEFAULT_FLOW_RESOURCES_FOLDER).toString());
    FrontendStubs.createStubNode(true, true, baseDir.getAbsolutePath());
    classFinder = Mockito.spy(getClassFinder());
    File versions = temporaryFolder.newFile();
    FileUtils.write(versions, String.format("{" + "\"vaadin-overlay\": {" + "\"npmName\": \"@vaadin/vaadin-overlay\"," + "\"jsVersion\": \"%s\"" + "}" + "}", PLATFORM_PINNED_DEPENDENCY_VERSION), StandardCharsets.UTF_8);
    // @formatter:on
    Mockito.when(classFinder.getResource(Constants.VAADIN_VERSIONS_JSON)).thenReturn(versions.toURI().toURL());
}
Also used : FeatureFlags(com.vaadin.experimental.FeatureFlags) File(java.io.File) Before(org.junit.Before)

Aggregations

FeatureFlags (com.vaadin.experimental.FeatureFlags)5 File (java.io.File)3 Before (org.junit.Before)3 Lookup (com.vaadin.flow.di.Lookup)2 ResourceProvider (com.vaadin.flow.di.ResourceProvider)1 FrontendTools (com.vaadin.flow.server.frontend.FrontendTools)1 FrontendToolsSettings (com.vaadin.flow.server.frontend.FrontendToolsSettings)1 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)1 ReflectionsClassFinder (com.vaadin.flow.server.scanner.ReflectionsClassFinder)1 ApplicationConfiguration (com.vaadin.flow.server.startup.ApplicationConfiguration)1