@Override public Map<String, String> getProperties(final LogicalPath propertyFilePath, final String propertyFilename) { Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); final String filePath = getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties(); try { if (getFileManager().exists(filePath)) { loadProperties(props, new BufferedInputStream(new FileInputStream(filePath))); } else { throw new IllegalStateException(String.format( "ERROR: '%s' properties file doesn't exists.", filePath)); } } catch (final IOException ioe) { throw new IllegalStateException(ioe); } final Map<String, String> result = new HashMap<String, String>(); for (final Object key : props.keySet()) { result.put(key.toString(), props.getProperty(key.toString())); } return Collections.unmodifiableMap(result); }
public void createI18nAddon(final JavaPackage topLevelPackage, String language, final Locale locale, final File messageBundle, final File flagGraphic, String description, final String projectName) { Validate.notNull(topLevelPackage, "Top Level Package required"); Validate.notNull(locale, "Locale required"); Validate.notNull(messageBundle, "Message Bundle required"); try { outputStream = fileManager.createFile( pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + messageBundle.getName())).getOutputStream(); org.apache.commons.io.FileUtils.copyFile(messageBundle, outputStream); if (flagGraphic != null) { outputStream = fileManager.createFile( pathResolver.getFocusedIdentifier(Path.SRC_MAIN_RESOURCES, packagePath + separatorChar + flagGraphic.getName())).getOutputStream(); org.apache.commons.io.FileUtils.copyFile(flagGraphic, outputStream); pathResolver.getFocusedIdentifier(Path.SRC_MAIN_JAVA, packagePath + separatorChar + languageName + "Language.java"); if (!fileManager.exists(destinationFile)) { final InputStream templateInputStream = FileUtils.getInputStream(getClass(), Type.I18N.name().toLowerCase()
new JavaType(String.format("%s.config.jackson.DomainModelModule", getTypeLocationService() .getTopLevelPackageForModule(module)), module.getModuleName()); Validate.notNull(domainModelModule.getModule(), "ERROR: Module name is required to generate a valid JavaType"); getPathResolver().getCanonicalPath(domainModelModule.getModule(), Path.SRC_MAIN_JAVA, domainModelModule); if (!getFileManager().exists(domainModelModuleIdentifier)) { PhysicalTypeIdentifier.createIdentifier(domainModelModule, getPathResolver().getPath(domainModelModuleIdentifier)); final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, domainModelModule, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(new AnnotationMetadataBuilder(RooJavaType.ROO_DOMAIN_MODEL_MODULE)); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
new JavaType(String.format("%sImpl", interfaceType.getFullyQualifiedTypeName()), interfaceType.getModule()); pathResolver.getCanonicalPath(implType.getModule(), Path.SRC_MAIN_JAVA, implType); if (fileManager.exists(implIdentifier)) { return; // Type already exists - nothing to do PhysicalTypeIdentifier.createIdentifier(implType, pathResolver.getPath(implIdentifier)); final ClassOrInterfaceTypeDetailsBuilder implTypeBuilder = new ClassOrInterfaceTypeDetailsBuilder(implMid, PUBLIC, implType, PhysicalTypeCategory.CLASS); implTypeBuilder.addAnnotation(implAnnotationMetadata.build()); implTypeBuilder.addImplementsType(interfaceType); PhysicalTypeIdentifier.createIdentifier(implTypeBuilder.build().getType(), pathResolver.getPath(implType.getModule(), Path.SRC_MAIN_JAVA)); typeManagementService.createOrUpdateTypeOnDisk(implTypeBuilder.build()); projectOperations.addModuleDependency(implType.getModule(), interfaceType.getModule()); projectOperations.addModuleDependency(implType.getModule(), repository.getName().getModule()); projectOperations.addModuleDependency(implType.getModule(), domainType.getModule());
getPathResolver().getCanonicalPath(controllerAdviceClass.getModule(), Path.SRC_MAIN_JAVA, controllerAdviceClass); if (!getFileManager().exists(controllerAdviceClassIdentifier)) { PhysicalTypeIdentifier.createIdentifier(controllerAdviceClass, getPathResolver().getPath(controllerAdviceClassIdentifier)); final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, controllerAdviceClass, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.CONTROLLER_ADVICE) .build()); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build()); } else { typeLocationService.getTypeDetails(controllerAdviceClass); AnnotationMetadata annotation = typeDetails.getAnnotation(SpringJavaType.CONTROLLER_ADVICE); if (annotation == null) {
Validate.notNull(entity, "Entity required"); if (target == null) { target = generateJavaType(entity, null); Validate.isTrue( !JdkJavaType.isPartOfJavaLang(target.getSimpleTypeName()), "Target name '%s' must not be part of java.lang", target.getSimpleTypeName()); .createIdentifier(target, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); File targetFile = new File( typeLocationService .getPhysicalTypeCanonicalPath(declaredByMetadataId)); Validate.isTrue(!targetFile.exists(), "Type '%s' already exists", target); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder( declaredByMetadataId, modifier, target, PhysicalTypeCategory.CLASS); new JavaType(GvNIXJpaBatch.class)); jpaBatchAnnotation.addClassAttribute("entity", entity); annotations.add(jpaBatchAnnotation); cidBuilder.setAnnotations(annotations); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
final InheritanceType inheritanceType, final List<AnnotationMetadataBuilder> annotations) { Validate.notNull(name, "Entity name required"); Validate.isTrue(!JdkJavaType.isPartOfJavaLang(name.getSimpleTypeName()), "Entity name '%s' must not be part of java.lang", name.getSimpleTypeName()); getProjectOperations().setModule(getProjectOperations().getPomFromModuleName(name.getModule())); getProjectOperations().addDependency(name.getModule(), SPRINGLETS_CONTEXT_DEPENDENCY); PhysicalTypeIdentifier.createIdentifier(name, getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA)); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, modifier, name, PhysicalTypeCategory.CLASS); getTypeLocationService().getTypeDetails(superclass); if (superclassClassOrInterfaceTypeDetails != null) { cidBuilder.setSuperclass(new ClassOrInterfaceTypeDetailsBuilder( superclassClassOrInterfaceTypeDetails)); final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>(); final ClassOrInterfaceTypeDetails typeDetails = getTypeLocationService().getTypeDetails(declaredByMetadataId); if (typeDetails != null) { implementsTypes.addAll(typeDetails.getImplementsTypes()); getTypeManagementService().createOrUpdateTypeOnDisk(entityDetails);
SoapBindingType bindingType, String serviceUrl, String profile) { Validate.isTrue(getFileManager().exists(wsdlPath), "ERROR: You must provide an existing .wsdl file."); getApplicationConfigService().addProperty(configClass.getModule(), "url/".concat(endPoint), serviceUrl, profile, true); if (!isNewConfigClass) { cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(configClassDetails); cidBuilder.getDeclaredTypeAnnotation(RooJavaType.ROO_WS_CLIENTS); if (wsClientsAnnotation != null) { cidBuilder.addAnnotation(wsClientsAnnotation); getPathResolver().getCanonicalPath(configClass.getModule(), Path.SRC_MAIN_JAVA, configClass); final String mid = PhysicalTypeIdentifier.createIdentifier(configClass, getPathResolver().getPath(configClassIdentifier)); cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, Modifier.PUBLIC, configClass, getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
module = getProjectOperations().getFocusedModule(); getProjectOperations().addDependency(module.getModuleName(), new Dependency("org.springframework.boot", "spring-boot-starter-web", null)); getProjectOperations().addDependency(module.getModuleName(), new Dependency("joda-time", "joda-time", null)); new JavaType(String.format("%s.config.WebMvcConfiguration", getTypeLocationService() .getTopLevelPackageForModule(module)), module.getModuleName()); Validate.notNull(webMvcConfiguration.getModule(), "ERROR: Module name is required to generate a valid JavaType"); getPathResolver().getCanonicalPath(webMvcConfiguration.getModule(), Path.SRC_MAIN_JAVA, webMvcConfiguration); if (!getFileManager().exists(webMvcConfigurationIdentifier)) { PhysicalTypeIdentifier.createIdentifier(webMvcConfiguration, getPathResolver().getPath(webMvcConfigurationIdentifier)); final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, webMvcConfiguration, PhysicalTypeCategory.CLASS); typeBuilder.addAnnotation(annotationMetadata.build()); getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build());
Validate.isTrue(getTypeLocationService() .hasModuleFeature(module, ModuleFeatureName.APPLICATION), "ERROR: Provided module doesn't match with application modules features. " + "Execute this operation again and provide a valid application module."); Validate.notNull(language, "ERROR: You should provide a valid language code."); LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName()); final String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); targetDirectory.concat("static/public/img/").concat(language.getLocale().getLanguage()) .concat(".png"); if (!getFileManager().exists(flagGraphic)) { InputStream inputStream = null; OutputStream outputStream = null; getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_WEB_MVC_CONFIGURATION); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_CONTROLLER); for (ClassOrInterfaceTypeDetails controller : controllers) {
@Override public void createConstructor(final JavaType name, final Set<String> fields) { final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(name); Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", name.getFullyQualifiedTypeName()); PhysicalTypeIdentifier.createIdentifier(name, pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA)); final List<FieldMetadata> constructorFields = new ArrayList<FieldMetadata>(); final List<? extends FieldMetadata> declaredFields = javaTypeDetails.getDeclaredFields(); new ClassOrInterfaceTypeDetailsBuilder(javaTypeDetails); cidBuilder.addConstructor(constructorBuilder); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
.notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); ClassOrInterfaceTypeDetails classDetails = getTypeLocationService().getTypeDetails(klass); Validate .notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); PhysicalTypeIdentifier.createIdentifier(klass, getPathResolver().getPath(klass.getModule(), path)); new ClassOrInterfaceTypeDetailsBuilder(classDetails); if (!memberHoldingTypeDetails.getType().equals(classDetails.getType())) { continue; .getFullyQualifiedTypeName()) && !method.getDeclaredByMetadataId().equals(declaredByMetadataId)) { detailsBuilder.addMethod(newMethod); detailsBuilder.addField(newField); classDetails = getTypeLocationService().getTypeDetails(detailsBuilder.build().getType()); for (AnnotationMetadata annotation : allDeclaredAnnotations) { getTypeManagementService().createOrUpdateTypeOnDisk(detailsBuilder.build());
Validate.notNull(interfaceType.getModule(), "JavaType %s does not have a module", domainType); pathResolver.getCanonicalPath(interfaceType.getModule(), Path.SRC_MAIN_JAVA, interfaceType); if (fileManager.exists(interfaceIdentifier)) { return; // Type already exists - nothing to do PhysicalTypeIdentifier.createIdentifier(interfaceType, pathResolver.getPath(interfaceIdentifier)); final ClassOrInterfaceTypeDetailsBuilder interfaceTypeBuilder = new ClassOrInterfaceTypeDetailsBuilder(interfaceMid, PUBLIC, interfaceType, PhysicalTypeCategory.INTERFACE); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_ENTITY_RESOLVER, domainType, idType); interfaceTypeBuilder.addExtendsTypes(entityResolver); JavaType.wrapperOf(SpringletsJavaType.SPRINGLETS_VALIDATOR_SERVICE, domainType); interfaceTypeBuilder.addExtendsTypes(validatorServiceEntity); typeManagementService.createOrUpdateTypeOnDisk(interfaceTypeBuilder.build()); projectOperations.addModuleDependency(interfaceType.getModule(), domainType.getModule()); projectOperations.addDependency(interfaceType.getModule(), new Dependency("io.springlets", "springlets-data-commons", null));
getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_DESERIALIZER); for (JavaType entity : entitiesToCreateSerializers) { values = new EntityDeserializerAnnotationValues(deserializer); if (entity.equals(values.getEntity())) { final LogicalPath deserializerPath = getPathResolver().getPath(module, Path.SRC_MAIN_JAVA); final String resourceIdentifierItem = getTypeLocationService().getPhysicalTypeCanonicalPath(deserializerClass, deserializerPath); final String declaredByMetadataIdItem = PhysicalTypeIdentifier.createIdentifier(deserializerClass, getPathResolver().getPath(resourceIdentifierItem)); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataIdItem, Modifier.PUBLIC, deserializerClass, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); cidBuilder.addExtendsTypes(JavaType.wrapperOf(JSON_OBJECT_DESERIALIZER, entity)); cidBuilder.addConstructor(constructor); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
@Override public void newEmbeddableClass(final JavaType name, final boolean serializable) { Validate.notNull(name, "Embeddable name required"); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA)); final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(Arrays.asList(new AnnotationMetadataBuilder( ROO_JAVA_BEAN), new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder(EMBEDDABLE))); if (serializable) { annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE)); } final int modifier = Modifier.PUBLIC; final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, modifier, name, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); getProjectOperations().addDependency(name.getModule(), new Dependency("org.springframework.boot", "spring-boot-starter-data-jpa", null)); }
String profile, boolean force) { getPathResolver().getCanonicalPath(sei.getModule(), Path.SRC_MAIN_JAVA, sei); final String midSEI = PhysicalTypeIdentifier.createIdentifier(sei, getPathResolver().getPath(seiIdentifier)); ClassOrInterfaceTypeDetailsBuilder cidBuilderSEI = new ClassOrInterfaceTypeDetailsBuilder(midSEI, Modifier.PUBLIC, sei, PhysicalTypeCategory.INTERFACE); cidBuilderSEI.addAnnotation(seiAnnotation); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderSEI.build()); getPathResolver().getCanonicalPath(endpointClass.getModule(), Path.SRC_MAIN_JAVA, endpointClass); final String midEndpoint = PhysicalTypeIdentifier.createIdentifier(endpointClass, getPathResolver().getPath(endpointIdentifier)); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderEndpoint.build()); getPathResolver().getCanonicalPath(configClass.getModule(), Path.SRC_MAIN_JAVA, configClass); final String mid = PhysicalTypeIdentifier.createIdentifier(configClass, getPathResolver().getPath(configClassIdentifier)); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilderConfig.build());
getProjectOperations().getTopLevelPackage(module.getModuleName()) .getFullyQualifiedPackageName().concat(".web.advices"); new JavaType(String.format("%s.%s", packageName, "ConcurrencyExceptionManager"), module.getModuleName()); Validate.notNull(type.getModule(), "ERROR: Module name is required to generate a valid JavaType"); final String identifier = getPathResolver().getCanonicalPath(type.getModule(), Path.SRC_MAIN_JAVA, type); InputStream inputStream = null; if (!this.fileManager.exists(identifier)) { try { this.fileManager.createOrUpdateTextFileIfRequired(identifier, input, true); } catch (final IOException e) { throw new IllegalStateException(String.format("Unable to create '%s'", identifier), e);
.notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); ClassOrInterfaceTypeDetails classDetails = getTypeLocationService().getTypeDetails(klass); Validate .notNull(klass, "ERROR: You must specify a valid class to continue with push-in action"); Validate.notNull(method, "ERROR: You must provide a valid method"); PhysicalTypeIdentifier.createIdentifier(klass, getPathResolver().getPath(klass.getModule(), path)); new ClassOrInterfaceTypeDetailsBuilder(classDetails); Validate.notNull(attribute, "Unable to find 'repository' attribute of @RooJpaRepositoryCustomImpl on '%s'", classDetails.getType().getSimpleTypeName()); relatedRepositoryCustom = (JavaType) attribute.getValue(); detailsBuilder.addImplementsType(relatedRepositoryCustom); pushedElements.add(relatedRepositoryCustom); if (!memberHoldingTypeDetails.getType().equals(classDetails.getType())) { continue; detailsBuilder.addMethod(newMethod); getTypeManagementService().createOrUpdateTypeOnDisk(detailsBuilder.build());
@Override public void addRepository(JavaType interfaceType, final JavaType domainType, JavaType defaultReturnType, boolean failOnComposition) { Validate.notNull(domainType, "ERROR: You must specify a valid Entity. "); ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(domainType); AnnotationMetadata entityAnnotation = entityDetails.getAnnotation(RooJavaType.ROO_JPA_ENTITY); getTypeLocationService().getTypeDetails(defaultReturnType); AnnotationMetadata defaultReturnTypeAnnotation = defaultReturnTypeDetails.getAnnotation(RooJavaType.ROO_ENTITY_PROJECTION); getPathResolver().getCanonicalPath(interfaceType.getModule(), Path.SRC_MAIN_JAVA, interfaceType); if (getFileManager().exists(interfaceIdentifier)) { getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_REPOSITORY_JPA); getProjectOperations().addModuleDependency(interfaceType.getModule(), domainType.getModule());
/** * This method creates a banner.txt file inside generated project that will * be displayed when the generated Spring Boot application starts. * * @param Pom * module where banner.txt should be generated */ private void addBannerFile(Pom module) { LogicalPath resourcesPath = LogicalPath.getInstance(Path.SRC_MAIN_RESOURCES, module.getModuleName()); String sourceAntPath = "banner/banner.txt"; String targetDirectory = getPathResolver().getIdentifier(resourcesPath, ""); if (!getFileManager().exists(targetDirectory)) { getFileManager().createDirectory(targetDirectory); } final String path = FileUtils.getPath(getClass(), sourceAntPath); final Iterable<URL> urls = OSGiUtils.findEntriesByPattern(context, path); Validate.notNull(urls, "Could not search bundles for resources for Ant Path '%s'", path); for (final URL url : urls) { final String fileName = url.getPath().substring(url.getPath().lastIndexOf("/") + 1); try { String contents = IOUtils.toString(url); getFileManager().createOrUpdateTextFileIfRequired(targetDirectory + fileName, contents, false); } catch (final Exception e) { throw new IllegalStateException(e); } } }