use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class AbstractUpdateImportsTest method assertFullSortOrder.
@Test
public void assertFullSortOrder() throws MalformedURLException {
Class[] testClasses = { MainView.class, NodeTestComponents.TranslatedImports.class, NodeTestComponents.LocalP3Template.class, NodeTestComponents.JavaScriptOrder.class, UI.class };
ClassFinder classFinder = getClassFinder(testClasses);
updater = new UpdateImports(classFinder, getScanner(classFinder), tmpRoot, new File(tmpRoot, TOKEN_FILE), true);
updater.run();
// Imports are collected as
// - theme and css
// - JsModules (external e.g. in node_modules/)
// - JavaScript
// - Generated webcompoents
// - JsModules (internal e.g. in frontend/)
List<String> expectedImports = new ArrayList<>();
expectedImports.addAll(updater.getExportLines());
expectedImports.addAll(updater.getThemeLines());
getAnntotationsAsStream(JsModule.class, testClasses).map(JsModule::value).map(this::updateToImport).sorted().forEach(expectedImports::add);
getAnntotationsAsStream(JavaScript.class, testClasses).map(JavaScript::value).map(this::updateToImport).sorted().forEach(expectedImports::add);
List<String> internals = expectedImports.stream().filter(importValue -> importValue.contains(FrontendUtils.WEBPACK_PREFIX_ALIAS)).sorted().collect(Collectors.toList());
updater.getGeneratedModules().stream().map(this::updateToImport).forEach(expectedImports::add);
// Remove internals from the full list
expectedImports.removeAll(internals);
// Add internals to end of list
expectedImports.addAll(internals);
Assert.assertEquals(expectedImports, updater.resultingLines);
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class AbstractUpdateImportsTest method getModuleLines_oneFrontendDependencyAndFrontendDirectoryDontExist_throwExceptionAdvisingUserToRunPrepareFrontend.
@Test
public void getModuleLines_oneFrontendDependencyAndFrontendDirectoryDontExist_throwExceptionAdvisingUserToRunPrepareFrontend() throws Exception {
ClassFinder classFinder = getClassFinder();
updater = new UpdateImports(classFinder, getScanner(classFinder), tmpRoot, null, true);
Files.move(frontendDirectory.toPath(), new File(tmpRoot, "_frontend").toPath());
try {
updater.run();
Assert.fail("Execute should have failed with advice to run `prepare-frontend`");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), CoreMatchers.containsString("Unable to locate frontend resources and missing token file. " + "Please run the `prepare-frontend` Vaadin plugin goal before deploying the application"));
}
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class FrontendResourcesAreCopiedAfterCleaningTest method performPackageClean.
private void performPackageClean() throws ExecutionFailedException {
ClassFinder classFinder = new ClassFinder.DefaultClassFinder(FrontendResourcesAreCopiedAfterCleaningTest.class.getClassLoader());
Lookup mockLookup = Mockito.mock(Lookup.class);
Mockito.doReturn(classFinder).when(mockLookup).lookup(ClassFinder.class);
NodeTasks.Builder builder = new NodeTasks.Builder(mockLookup, npmFolder, TARGET);
File resourcesFolder = new File(npmFolder, Paths.get(TARGET, DEFAULT_FLOW_RESOURCES_FOLDER).toString());
builder.withEmbeddableWebComponents(false).enableImportsUpdate(false).createMissingPackageJson(true).enableImportsUpdate(true).runNpmInstall(false).enableNpmFileCleaning(true).withFlowResourcesFolder(resourcesFolder).copyResources(Collections.emptySet()).enablePackagesUpdate(true).build().execute();
}
Aggregations