use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class BuildFrontendUtil method runNodeUpdater.
/**
* runs the node-Updater.
*
* @param adapter
* - the PluginAdapterBase.
* @throws ExecutionFailedException
* - a ExecutionFailedException.
* @throws URISyntaxException
* - - Could not build an URI from nodeDownloadRoot().
*/
public static void runNodeUpdater(PluginAdapterBuild adapter) throws ExecutionFailedException, URISyntaxException {
Set<File> jarFiles = adapter.getJarFiles();
File flowResourcesFolder = new File(adapter.npmFolder(), Paths.get(adapter.buildFolder(), DEFAULT_FLOW_RESOURCES_FOLDER).toString());
final URI nodeDownloadRootURI;
nodeDownloadRootURI = adapter.nodeDownloadRoot();
ClassFinder classFinder = adapter.getClassFinder();
Lookup lookup = adapter.createLookup(classFinder);
try {
new NodeTasks.Builder(lookup, adapter.npmFolder(), adapter.generatedFolder(), adapter.frontendDirectory(), adapter.buildFolder()).runNpmInstall(adapter.runNpmInstall()).withWebpack(adapter.webpackOutputDirectory(), adapter.servletResourceOutputDirectory()).useV14Bootstrap(adapter.isUseDeprecatedV14Bootstrapping()).enablePackagesUpdate(true).useByteCodeScanner(adapter.optimizeBundle()).withFlowResourcesFolder(flowResourcesFolder).copyResources(jarFiles).copyTemplates(true).copyLocalResources(adapter.frontendResourcesDirectory()).enableImportsUpdate(true).withEmbeddableWebComponents(adapter.generateEmbeddableWebComponents()).withTokenFile(BuildFrontendUtil.getTokenFile(adapter)).enablePnpm(adapter.pnpmEnable()).useGlobalPnpm(adapter.useGlobalPnpm()).withApplicationProperties(adapter.applicationProperties()).withEndpointSourceFolder(adapter.javaSourceFolder()).withEndpointGeneratedOpenAPIFile(adapter.openApiJsonFile()).withFrontendGeneratedFolder(adapter.generatedTsFolder()).withHomeNodeExecRequired(adapter.requireHomeNodeExec()).withNodeVersion(adapter.nodeVersion()).withNodeDownloadRoot(nodeDownloadRootURI).setNodeAutoUpdate(adapter.nodeAutoUpdate()).setJavaResourceFolder(adapter.javaResourceFolder()).withPostinstallPackages(adapter.postinstallPackages()).build().execute();
} catch (ExecutionFailedException exception) {
throw exception;
} catch (Throwable throwable) {
// NOSONAR Intentionally throwable
throw new ExecutionFailedException("Error occured during goal execution: " + throwable.getMessage() + "Please run Maven with the -e switch (or Gradle with the --stacktrace switch), to learn the full stack trace.", throwable);
}
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class EndpointsValidator method process.
@Override
public void process(Set<Class<?>> classSet, ServletContext servletContext) throws ServletException {
if (classSet == null) {
// an endpoint and dependencies are not added to the project.
return;
}
ClassFinder finder = new DefaultClassFinder(classSet);
Set<Class<?>> endpoints = finder.getAnnotatedClasses(Endpoint.class);
if (!endpoints.isEmpty()) {
try {
finder.loadClass(classToCheck);
} catch (ClassNotFoundException e) {
throw new ServletException("ERROR: Vaadin endpoints only work for Spring " + "enabled projects.\n" + "This is not a spring application but there are Vaadin endpoints in these classes: " + endpoints.stream().map(Class::getName).collect(Collectors.joining("\n - ")), e);
}
}
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class TaskRunPnpmInstallTest method getGeneratedVersionsContent.
private JsonObject getGeneratedVersionsContent(File versions) throws IOException {
ClassFinder classFinder = getClassFinder();
Mockito.when(classFinder.getResource(Constants.VAADIN_VERSIONS_JSON)).thenReturn(versions.toURI().toURL());
String path = getNodeUpdater().generateVersionsJson();
File generatedVersionsFile = new File(getNodeUpdater().npmFolder, path);
return Json.parse(FileUtils.readFileToString(generatedVersionsFile, StandardCharsets.UTF_8));
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class TaskRunPnpmInstallTest method runPnpmInstall_versionsJsonIsFound_pnpmHookFileIsGenerated.
@Test
public void runPnpmInstall_versionsJsonIsFound_pnpmHookFileIsGenerated() throws IOException, ExecutionFailedException {
ClassFinder classFinder = getClassFinder();
File versions = temporaryFolder.newFile();
FileUtils.write(versions, "{}", StandardCharsets.UTF_8);
Mockito.when(classFinder.getResource(Constants.VAADIN_VERSIONS_JSON)).thenReturn(versions.toURI().toURL());
TaskRunNpmInstall task = createTask();
getNodeUpdater().modified = true;
getNodeUpdater().versionsPath = "./versions.json";
task.execute();
File file = new File(getNodeUpdater().npmFolder, "pnpmfile.js");
Assert.assertTrue(file.exists());
String content = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
MatcherAssert.assertThat(content, CoreMatchers.containsString("JSON.parse(fs.readFileSync"));
}
use of com.vaadin.flow.server.frontend.scanner.ClassFinder in project flow by vaadin.
the class NodeUpdateImportsTest method noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists.
@Test
public void noFallBackScanner_fallbackIsNotImportedEvenIfTheFileExists() throws Exception {
Stream<Class<?>> classes = Stream.concat(Stream.of(NodeTestComponents.class.getDeclaredClasses()), Stream.of(ExtraNodeTestComponents.class.getDeclaredClasses()));
ClassFinder classFinder = new DefaultClassFinder(new URLClassLoader(getClassPath()), classes.toArray(Class<?>[]::new));
// create fallback imports file:
// it is present after generated but the user is now running
// everything without fallback. The file should not be included into
// the imports
fallBackImportsFile.mkdirs();
fallBackImportsFile.createNewFile();
Assert.assertTrue(fallBackImportsFile.exists());
updater = new TaskUpdateImports(classFinder, new FrontendDependenciesScannerFactory().createScanner(false, classFinder, true), finder -> null, tmpRoot, generatedPath, frontendDirectory, tokenFile, null, false, TARGET, true, false, Mockito.mock(FeatureFlags.class)) {
@Override
Logger log() {
return logger;
}
};
updater.execute();
assertTrue(importsFile.exists());
String mainContent = FileUtils.readFileToString(importsFile, Charset.defaultCharset());
// fallback file is not imported in generated-flow-imports
MatcherAssert.assertThat(mainContent, CoreMatchers.not(CoreMatchers.containsString(FrontendUtils.FALLBACK_IMPORTS_NAME)));
}
Aggregations