use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.
the class TaskUpdateWebpackTest method should_enableCustomOfflinePath_when_customisedInPwa.
@Test
public void should_enableCustomOfflinePath_when_customisedInPwa() throws IOException {
pwaConfiguration = new PwaConfiguration(AppShellWithOfflinePath.class.getAnnotation(PWA.class));
createWebpackUpdater();
webpackUpdater.execute();
String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
Assert.assertTrue("offlinePath should be customizable", webpackGeneratedContents.contains("const offlinePath = 'off.html';"));
}
use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.
the class TaskUpdateWebpackTest method setup.
@Before
public void setup() throws Exception {
baseDir = temporaryFolder.getRoot();
frontendFolder = new File(baseDir, "frontend");
frontendGeneratedFolder = new File(baseDir, DEFAULT_PROJECT_FRONTEND_GENERATED_DIR);
FrontendStubs.createStubNode(true, true, baseDir.getAbsolutePath());
pwaConfiguration = new PwaConfiguration(AppShell.class.getAnnotation(PWA.class));
createWebpackUpdater();
webpackConfig = new File(baseDir, WEBPACK_CONFIG);
webpackGenerated = new File(baseDir, WEBPACK_GENERATED);
}
use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.
the class TaskUpdateWebpackTest method should_setPwaEnabledFalse_when_noPwa.
@Test
public void should_setPwaEnabledFalse_when_noPwa() throws IOException {
pwaConfiguration = new PwaConfiguration();
createWebpackUpdater();
webpackUpdater.execute();
String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
Assert.assertTrue("pwaEnabled expected false", webpackGeneratedContents.contains("const pwaEnabled = false;"));
}
use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.
the class TaskUpdateWebpackTest method should_setOfflineEnabledFalse_when_customisedInPwa.
@Test
public void should_setOfflineEnabledFalse_when_customisedInPwa() throws IOException {
pwaConfiguration = new PwaConfiguration(AppShellWithDisabledOffline.class.getAnnotation(PWA.class));
createWebpackUpdater();
webpackUpdater.execute();
String webpackGeneratedContents = Files.lines(webpackGenerated.toPath()).collect(Collectors.joining("\n"));
Assert.assertTrue("offlineEnabled expected false", webpackGeneratedContents.contains("const offlineEnabled = false;"));
}
use of com.vaadin.flow.server.PwaConfiguration in project flow by vaadin.
the class FullDependenciesScanner method discoverPwa.
private PwaConfiguration discoverPwa() {
try {
Class<? extends Annotation> loadedPWAAnnotation = getFinder().loadClass(PWA.class.getName());
Set<Class<?>> annotatedClasses = getFinder().getAnnotatedClasses(loadedPWAAnnotation);
if (annotatedClasses.isEmpty()) {
return new PwaConfiguration(useV14Bootstrap);
} else if (annotatedClasses.size() != 1) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
}
Class<?> hopefullyAppShellClass = annotatedClasses.iterator().next();
if (!useV14Bootstrap && !Arrays.stream(hopefullyAppShellClass.getInterfaces()).map(Class::getName).collect(Collectors.toList()).contains(AppShellConfigurator.class.getName())) {
throw new IllegalStateException(ERROR_INVALID_PWA_ANNOTATION);
}
Annotation pwa = annotationFinder.apply(hopefullyAppShellClass, loadedPWAAnnotation).get(0);
String name = getAnnotationValueAsString(pwa, "name");
String shortName = getAnnotationValueAsString(pwa, "shortName");
String description = getAnnotationValueAsString(pwa, "description");
String backgroundColor = getAnnotationValueAsString(pwa, "backgroundColor");
String themeColor = getAnnotationValueAsString(pwa, "themeColor");
String iconPath = getAnnotationValueAsString(pwa, "iconPath");
String manifestPath = getAnnotationValueAsString(pwa, "manifestPath");
String offlinePath = getAnnotationValueAsString(pwa, "offlinePath");
String display = getAnnotationValueAsString(pwa, "display");
String startPath = getAnnotationValueAsString(pwa, "startPath");
String[] offlineResources = (String[]) getAnnotationValue(pwa, "offlineResources");
boolean offline = (Boolean) getAnnotationValue(pwa, "offline");
// required in @PWA annotation
assert shortName != null;
return new PwaConfiguration(true, name, shortName, description, backgroundColor, themeColor, iconPath, manifestPath, offlinePath, display, startPath, offlineResources, offline, useV14Bootstrap);
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("Could not load PWA annotation class", exception);
}
}
Aggregations