Search in sources :

Example 81 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class ThymeleafMVCViewResponseService method addMainController.

/**
 * This method add new MainController.java class annotated
 * with @RooThymeleafMainController
 *
 * This controller will be used to return index page.
 *
 * @param module
 */
private void addMainController(Pom module) {
    // Check if already exists other main controller annotated with @RooThymeleafMainController
    if (getMainController() != null) {
        return;
    }
    // If not, define new JavaType
    JavaType mainController = new JavaType(String.format("%s.web.MainController", getProjectOperations().getTopLevelPackage(module.getModuleName())), module.getModuleName());
    // Check that new JavaType doesn't exists
    ClassOrInterfaceTypeDetails mainControllerDetails = getTypeLocationService().getTypeDetails(mainController);
    if (mainControllerDetails != null) {
        AnnotationMetadata mainControllerThymeleafAnnotation = mainControllerDetails.getAnnotation(getMainControllerAnnotation());
        // Maybe, this controller already exists
        if (mainControllerThymeleafAnnotation != null) {
            return;
        } else {
            throw new RuntimeException("ERROR: You are trying to generate more than one MainController.");
        }
    }
    ClassOrInterfaceTypeDetailsBuilder cidBuilder = null;
    final LogicalPath controllerPath = getPathResolver().getPath(mainController.getModule(), Path.SRC_MAIN_JAVA);
    final String resourceIdentifier = getTypeLocationService().getPhysicalTypeCanonicalPath(mainController, controllerPath);
    final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(mainController, getPathResolver().getPath(resourceIdentifier));
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    annotations.add(new AnnotationMetadataBuilder(getMainControllerAnnotation()));
    cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, mainController, PhysicalTypeCategory.CLASS);
    cidBuilder.setAnnotations(annotations);
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) LogicalPath(org.springframework.roo.project.LogicalPath) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 82 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class ThymeleafMVCViewResponseService method copyStaticResources.

/**
 * This method copy and generate all necessary resources to be able
 * to use THYMELEAF.
 *
 * @param module
 */
private void copyStaticResources(Pom module) {
    LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName());
    // copy all necessary styles inside SRC_MAIN_RESOURCES/static/public/css
    copyDirectoryContents("static/css/*.css", getPathResolver().getIdentifier(resourcesPath, "/static/public/css"), true);
    // copy all necessary fonts inside SRC_MAIN_RESOURCES/static/public/fonts
    copyDirectoryContents("static/fonts/*.eot", getPathResolver().getIdentifier(resourcesPath, "/static/public/fonts"), true);
    copyDirectoryContents("static/fonts/*.svg", getPathResolver().getIdentifier(resourcesPath, "/static/public/fonts"), true);
    copyDirectoryContents("static/fonts/*.ttf", getPathResolver().getIdentifier(resourcesPath, "/static/public/fonts"), true);
    copyDirectoryContents("static/fonts/*.woff", getPathResolver().getIdentifier(resourcesPath, "/static/public/fonts"), true);
    copyDirectoryContents("static/fonts/*.woff2", getPathResolver().getIdentifier(resourcesPath, "/static/public/fonts"), true);
    // copy all necessary images inside SRC_MAIN_RESOURCES/static/public/img
    copyDirectoryContents("static/img/*.ico", getPathResolver().getIdentifier(resourcesPath, "/static/public/img"), false);
    copyDirectoryContents("static/img/*.jpg", getPathResolver().getIdentifier(resourcesPath, "/static/public/img"), false);
    copyDirectoryContents("static/img/*.png", getPathResolver().getIdentifier(resourcesPath, "/static/public/img"), false);
    copyDirectoryContents("static/img/*.gif", getPathResolver().getIdentifier(resourcesPath, "/static/public/img"), false);
    // copy all necessary scripts inside SRC_MAIN_RESOURCES/static/public/js
    copyDirectoryContents("static/js/*.js", getPathResolver().getIdentifier(resourcesPath, "/static/public/js"), true);
    // copy all necessary scripts inside SRC_MAIN_RESOURCES/templates/fragments/js
    copyDirectoryContents("templates/fragments/js/*.html", getPathResolver().getIdentifier(resourcesPath, "/templates/fragments/js"), true);
    copyDirectoryContents("templates/fragments/js/*.js", getPathResolver().getIdentifier(resourcesPath, "/templates/fragments/js"), true);
    // copy default JasperReports template
    copyDirectoryContents("templates/reports/*.jrxml", getPathResolver().getIdentifier(resourcesPath, "/templates/reports"), true);
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath)

Example 83 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class ThymeleafControllerIntegrationTestMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = ThymeleafControllerIntegrationTestMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = ThymeleafControllerIntegrationTestMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 84 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class I18nOperationsImpl method addOrUpdateLabels.

/**
 * Add labels to all installed languages
 *
 * @param moduleName
 * @param labels
 */
@Override
public void addOrUpdateLabels(String moduleName, final Map<String, String> labels) {
    final LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, moduleName);
    final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, "");
    Set<I18n> supportedLanguages = getI18nSupport().getSupportedLanguages();
    for (I18n i18n : supportedLanguages) {
        String messageBundle = String.format("messages_%s.properties", i18n.getLocale().getLanguage());
        String bundlePath = String.format("%s%s%s", targetDirectory, AntPathMatcher.DEFAULT_PATH_SEPARATOR, messageBundle);
        if (getFileManager().exists(bundlePath)) {
            // Adding labels if not exists already
            getPropFilesManager().addPropertiesIfNotExists(resourcesPath, messageBundle, labels, true, false);
        }
    }
    // Allways update english message bundles if label not exists already
    getPropFilesManager().addPropertiesIfNotExists(resourcesPath, "messages.properties", labels, true, false);
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath) I18n(org.springframework.roo.addon.web.mvc.i18n.components.I18n)

Example 85 with LogicalPath

use of org.springframework.roo.project.LogicalPath in project spring-roo by spring-projects.

the class PhysicalTypeIdentifierNamingUtilsTest method testGetLogicalPathFromMetadataInstanceId.

@Test
public void testGetLogicalPathFromMetadataInstanceId() {
    // Invoke
    final LogicalPath logicalPath = PhysicalTypeIdentifierNamingUtils.getPath(METADATA_INSTANCE_ID);
    // Check
    assertEquals(LogicalPath.getInstance(PATH, MODULE), logicalPath);
}
Also used : LogicalPath(org.springframework.roo.project.LogicalPath) Test(org.junit.Test)

Aggregations

LogicalPath (org.springframework.roo.project.LogicalPath)85 JavaType (org.springframework.roo.model.JavaType)62 RooJavaType (org.springframework.roo.model.RooJavaType)55 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)13 JpaJavaType (org.springframework.roo.model.JpaJavaType)12 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)9 SpringJavaType (org.springframework.roo.model.SpringJavaType)9 ArrayList (java.util.ArrayList)8 InputStream (java.io.InputStream)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)5 BufferedInputStream (java.io.BufferedInputStream)4 IOException (java.io.IOException)4 OutputStream (java.io.OutputStream)4 ZipInputStream (java.util.zip.ZipInputStream)4 I18n (org.springframework.roo.addon.web.mvc.i18n.components.I18n)4 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3