Search in sources :

Example 16 with ExecutionFailedException

use of com.vaadin.flow.server.ExecutionFailedException in project flow by vaadin.

the class TaskUpdateThemeImportTest method taskExecuted_customThemeFolderExistsInBothFrontendAndInClasspath_throwsException.

@Test
public void taskExecuted_customThemeFolderExistsInBothFrontendAndInClasspath_throwsException() {
    File themeDir = new File(frontendDirectory, CUSTOM_THEME_PATH);
    Assert.assertTrue(themeDir.mkdirs());
    String classPathThemePath = NODE_MODULES + FLOW_NPM_PACKAGE_NAME + CUSTOM_THEME_PATH;
    File classPathThemeDir = new File(projectRoot, classPathThemePath);
    Assert.assertTrue(classPathThemeDir.mkdirs());
    ExecutionFailedException e = Assert.assertThrows(ExecutionFailedException.class, taskUpdateThemeImport::execute);
    Assert.assertTrue(e.getMessage().contains(String.format("Theme '%s' should not exist inside a " + "jar and in the project at the same time.", CUSTOM_THEME_NAME)));
}
Also used : ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) File(java.io.File) Test(org.junit.Test)

Example 17 with ExecutionFailedException

use of com.vaadin.flow.server.ExecutionFailedException in project flow by vaadin.

the class TaskUpdateThemeImportTest method taskExecuted_customThemeWithNonExistingThemeFolder_throwsException.

@Test
public void taskExecuted_customThemeWithNonExistingThemeFolder_throwsException() {
    File faultyFrontendDirectory = new File(projectRoot, DEFAULT_FRONTEND_DIR);
    TaskUpdateThemeImport taskUpdateThemeImportWithNonExistentThemeFolder = new TaskUpdateThemeImport(npmFolder, customTheme, faultyFrontendDirectory, frontendGeneratedDirectory);
    ExecutionFailedException e = Assert.assertThrows(ExecutionFailedException.class, taskUpdateThemeImportWithNonExistentThemeFolder::execute);
    Assert.assertTrue(e.getMessage().contains(String.format("Discovered @Theme annotation with theme name '%s', " + "but could not find the theme directory in the " + "project or available as a jar dependency.", CUSTOM_THEME_NAME)));
}
Also used : ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) File(java.io.File) Test(org.junit.Test)

Example 18 with ExecutionFailedException

use of com.vaadin.flow.server.ExecutionFailedException in project flow by vaadin.

the class TaskUpdateThemeImportTest method taskExecuted_customThemeFolderExistsInClassPathAndStaticAndMetaInfResources_throwsException.

@Test
public void taskExecuted_customThemeFolderExistsInClassPathAndStaticAndMetaInfResources_throwsException() {
    String classPathThemePath = NODE_MODULES + FLOW_NPM_PACKAGE_NAME + CUSTOM_THEME_PATH;
    File classPathThemeDir = new File(projectRoot, classPathThemePath);
    Assert.assertTrue(classPathThemeDir.mkdirs());
    String staticResources = String.join("/", APPLICATION_STATIC_RESOURCES, CUSTOM_THEME_PATH);
    File themeDirInStatic = new File(projectRoot, staticResources);
    Assert.assertTrue(themeDirInStatic.mkdirs());
    String metaInfResources = String.join("/", APPLICATION_META_INF_RESOURCES, CUSTOM_THEME_PATH);
    File themeDirInMetaInf = new File(projectRoot, metaInfResources);
    Assert.assertTrue(themeDirInMetaInf.mkdirs());
    ExecutionFailedException e = Assert.assertThrows(ExecutionFailedException.class, taskUpdateThemeImport::execute);
    Assert.assertTrue(e.getMessage().contains(String.format("Theme '%s' should not exist inside a " + "jar and in the project at the same time.", CUSTOM_THEME_NAME)));
}
Also used : ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) File(java.io.File) Test(org.junit.Test)

Example 19 with ExecutionFailedException

use of com.vaadin.flow.server.ExecutionFailedException in project flow by vaadin.

the class TaskUpdateThemeImport method execute.

@Override
public void execute() throws ExecutionFailedException {
    if (theme == null || theme.getName().isEmpty()) {
        if (themeImportFile.exists()) {
            themeImportFile.delete();
            themeImportFileDefinition.delete();
        }
        return;
    }
    verifyThemeDirectoryExistence();
    if (!themeImportFile.getParentFile().mkdirs()) {
        LoggerFactory.getLogger(getClass()).debug("Didn't create folders as they probably already exist. " + "If there is a problem check access rights for folder {}", themeImportFile.getParentFile().getAbsolutePath());
    }
    try {
        FileUtils.write(themeImportFile, String.format("import {applyTheme as _applyTheme} from './theme-%s.generated.js';%n" + "export const applyTheme = _applyTheme;%n", theme.getName()), StandardCharsets.UTF_8);
        FileUtils.write(themeImportFileDefinition, EXPORT_MODULES_DEF, StandardCharsets.UTF_8);
    } catch (IOException e) {
        throw new ExecutionFailedException("Unable to write theme import file", e);
    }
}
Also used : ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) IOException(java.io.IOException)

Example 20 with ExecutionFailedException

use of com.vaadin.flow.server.ExecutionFailedException in project flow by vaadin.

the class TaskCopyTemplateFiles method execute.

@Override
public void execute() throws ExecutionFailedException {
    Set<Class<?>> classes = new HashSet<>(classFinder.getSubTypesOf(Template.class));
    Class<? extends Annotation> jsModuleAnnotationClass;
    try {
        jsModuleAnnotationClass = classFinder.loadClass(JsModule.class.getName());
    } catch (ClassNotFoundException e) {
        throw new ExecutionFailedException(e);
    }
    for (Class<?> clazz : classes) {
        for (Annotation jsmAnnotation : clazz.getAnnotationsByType(jsModuleAnnotationClass)) {
            String path = getJsModuleAnnotationValue(jsmAnnotation);
            File source = FrontendUtils.resolveFrontendPath(projectDirectory, path);
            if (source == null) {
                throw new ExecutionFailedException("Unable to locate file " + path);
            }
            File templateDirectory = new File(resourceOutputDirectory, Constants.TEMPLATE_DIRECTORY);
            File target = new File(templateDirectory, path).getParentFile();
            target.mkdirs();
            try {
                FileUtils.copyFileToDirectory(source, target);
            } catch (IOException e) {
                throw new ExecutionFailedException(e);
            }
        }
    }
}
Also used : ExecutionFailedException(com.vaadin.flow.server.ExecutionFailedException) IOException(java.io.IOException) File(java.io.File) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) Template(com.vaadin.flow.internal.Template)

Aggregations

ExecutionFailedException (com.vaadin.flow.server.ExecutionFailedException)20 File (java.io.File)17 Test (org.junit.Test)10 IOException (java.io.IOException)5 Lookup (com.vaadin.flow.di.Lookup)2 ClassFinder (com.vaadin.flow.server.frontend.scanner.ClassFinder)2 ReflectionsClassFinder (com.vaadin.flow.server.scanner.ReflectionsClassFinder)2 URI (java.net.URI)2 AbstractDevModeTest (com.vaadin.base.devserver.startup.AbstractDevModeTest)1 Template (com.vaadin.flow.internal.Template)1 VaadinResponse (com.vaadin.flow.server.VaadinResponse)1 FallbackChunk (com.vaadin.flow.server.frontend.FallbackChunk)1 FrontendTools (com.vaadin.flow.server.frontend.FrontendTools)1 FrontendToolsSettings (com.vaadin.flow.server.frontend.FrontendToolsSettings)1 FrontendUtils.commandToString (com.vaadin.flow.server.frontend.FrontendUtils.commandToString)1 NodeTasks (com.vaadin.flow.server.frontend.NodeTasks)1 BufferedReader (java.io.BufferedReader)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 UncheckedIOException (java.io.UncheckedIOException)1