/** * Returns the fully-qualified name of the given module, relative to the * currently focused module. * * @param moduleName can be blank for the root or only module * @param projectOperations * @return */ protected final String getFullyQualifiedModuleName(final String moduleName, final ProjectOperations projectOperations) { if (StringUtils.isBlank(moduleName)) { return ""; } final String focusedModuleName = projectOperations.getFocusedModuleName(); if (StringUtils.isBlank(focusedModuleName)) { return moduleName; } return focusedModuleName + File.separator + moduleName; }
@Override public boolean isIntegrationTestCreationAvailable() { Set<JavaType> jsonControllers = typeLocationService.findTypesWithAnnotation(RooJavaType.ROO_JSON); return projectOperations.isFocusedProjectAvailable() && projectOperations.isFeatureInstalled(FeatureNames.MVC) && !jsonControllers.isEmpty(); }
@Override public void install(Pom module) { // Including dependency with Spring Boot Starter Security getProjectOperations().addDependency(module.getModuleName(), SPRING_SECURITY_STARTER); // Add thymeleaf-extras-springsecurity4 dependency with Thymeleaf 3 support getProjectOperations().addProperty("", THYMELEAF_SPRING_SECURITY_VERSION_PROPERTY); getProjectOperations().addDependency(module.getModuleName(), THYMELEAF_SPRING_SECURITY); }
@Override public boolean isUnitTestCreationAvailable() { return projectOperations.isFocusedProjectAvailable() && projectOperations.isFeatureInstalled(FeatureNames.JPA); }
/** * Add needed dependencies and plugins to run created unit tests. * * @param module {@link String} the module name where add dependencies. */ private void addUnitTestDependencies(String module) { // Add dependencies if needed projectOperations.addDependency(module, JUNIT_DEPENDENCY); projectOperations.addDependency(module, ASSERTJ_CORE_DEPENDENCY); projectOperations.addDependency(module, SPRING_TEST_DEPENDENCY); // Add plugins if needed projectOperations.addBuildPlugin(module, MAVEN_SUREFIRE_PLUGIN); }
String javaTypeFullyQualilfiedName = cid.getType().getFullyQualifiedTypeName(); String javaTypeString = ""; String topLevelPackageString = ""; if (StringUtils.isNotBlank(cid.getType().getModule()) && !cid.getType().getModule().equals(projectOperations.getFocusedModuleName())) { javaTypeString = cid.getType().getModule().concat(LogicalPath.MODULE_PATH_SEPARATOR); topLevelPackageString = projectOperations.getTopLevelPackage(cid.getType().getModule()) .getFullyQualifiedPackageName(); } else if (StringUtils.isNotBlank(cid.getType().getModule()) && cid.getType().getModule().equals(projectOperations.getFocusedModuleName()) && (currentText.startsWith(cid.getType().getModule()) || cid.getType().getModule() .startsWith(currentText)) && StringUtils.isNotBlank(currentText)) { javaTypeString = cid.getType().getModule().concat(LogicalPath.MODULE_PATH_SEPARATOR); topLevelPackageString = projectOperations.getTopLevelPackage(cid.getType().getModule()) .getFullyQualifiedPackageName(); } else { projectOperations.getFocusedTopLevelPackage().getFullyQualifiedPackageName();
@Override public SortedSet<String> getPropertyKeys(LogicalPath propertyFilePath, String propertyFilename, String prefix, boolean includeValues) { Validate.notNull(prefix, "Prefix could be blank but not null"); Validate.notNull(propertyFilePath, "Property file path required"); Validate.notBlank(propertyFilename, "Property filename required"); getProjectOperations().getPathResolver().getIdentifier(propertyFilePath, propertyFilename); final Properties props = new Properties(); for (final Object key : props.keySet()) { String info = key.toString(); if (StringUtils.isNotBlank(prefix)) { if (info.startsWith(prefix)) { result.add(includeValues ? info.concat(" = ").concat(props.getProperty(key.toString()))
@CliOptionAutocompleteIndicator(command = "service", param = "class", help = "--class option should be a new class.", validate = false, includeSpaceOnFinish = false) public List<String> getClassPossibleResults(ShellContext shellContext) { List<String> allPossibleValues = new ArrayList<String>(); // Add all modules to completions list Collection<String> modules = projectOperations.getModuleNames(); for (String module : modules) { if (StringUtils.isNotBlank(module) && !module.equals(projectOperations.getFocusedModule().getModuleName())) { allPossibleValues.add(module.concat(LogicalPath.MODULE_PATH_SEPARATOR) .concat(JavaPackageConverter.TOP_LEVEL_PACKAGE_SYMBOL).concat(".")); } else if (!projectOperations.isMultimoduleProject()) { // Add only JavaPackage and JavaType completion allPossibleValues.add(String.format("%s.service.impl.", JavaPackageConverter.TOP_LEVEL_PACKAGE_SYMBOL)); } } // Always add base package allPossibleValues.add("~."); return allPossibleValues; }
.addDependency(module.getModuleName(), DEPENDENCY_SPRINGLETS_STARTER_MAIL); getProjectOperations().addProperty("", PROPERTY_SPRINGLETS_VERSION); if (getApplicationConfigService().existsSpringConfigFile(module.getModuleName(), profile) && areDefinedReceiveEmailProperties(module.getModuleName(), profile) && !force) { String moduleStr = " and module " + module.getModuleName(); if (StringUtils.isEmpty(module.getModuleName())) { moduleStr = ""; if (!service.getModule().equals(StringUtils.EMPTY)) { getProjectOperations().addDependency(service.getModule(), DEPENDENCY_SPRINGLETS_MAIL); getTypeLocationService().getTypeDetails(service); Validate.isTrue(serviceTypeDetails != null, "Cannot locate source for '%s'", service.getFullyQualifiedTypeName()); final String declaredByMetadataId = serviceTypeDetails.getDeclaredByMetadataId(); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(serviceTypeDetails);
Validate.notNull(fileManager, "FileManager is required"); Validate.notNull(metadataDependencyRegistry, "MetadataDependencyRegistry is required"); Validate.notNull(projectOperations, "ProjectOperations is required"); "Metadata id '%s' is not valid for this metadata provider", metadataIdentificationString); final String canonicalPath = typeLocationService.getPhysicalTypeCanonicalPath(metadataIdentificationString); if (StringUtils.isBlank(canonicalPath)) { return null; new DefaultPhysicalTypeMetadata(metadataIdentificationString, canonicalPath, typeDetails); final ClassOrInterfaceTypeDetails details = result.getMemberHoldingTypeDetails(); if (details != null && details.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS && details.getExtendsTypes().size() == 1) { if (details.getSuperclass() != null) { for (final LogicalPath sourcePath : projectOperations.getPathResolver().getSourcePaths()) { final String possibleSuperclass = PhysicalTypeIdentifier.createIdentifier(details.getExtendsTypes().get(0), sourcePath);
public JavaPackage convertFromText(String value, final Class<?> requiredType, final String optionContext) { if (StringUtils.isBlank(value)) { return null; } Pom module = projectOperations.getFocusedModule(); if (value.contains(MODULE_PATH_SEPARATOR)) { final String moduleName = value.substring(0, value.indexOf(MODULE_PATH_SEPARATOR)); module = projectOperations.getPomFromModuleName(moduleName); value = value.substring(value.indexOf(MODULE_PATH_SEPARATOR) + 1, value.length()).trim(); if (StringUtils.contains(optionContext, UPDATE)) { projectOperations.setModule(module); } } String moduleName = module == null ? null : module.getModuleName(); JavaPackage result = new JavaPackage(convertToFullyQualifiedPackageName(module, value), moduleName); if (optionContext != null && (optionContext.contains(UPDATE) || optionContext.contains(UPDATELAST))) { lastUsed.setPackage(result, module); } return result; }
String javaTypeFullyQualilfiedName = cid.getType().getFullyQualifiedTypeName(); String javaTypeString = ""; String topLevelPackageString = ""; if (StringUtils.isNotBlank(cid.getType().getModule())) { javaTypeString = cid.getType().getModule().concat(LogicalPath.MODULE_PATH_SEPARATOR); topLevelPackageString = projectOperations.getTopLevelPackage(cid.getType().getModule()) .getFullyQualifiedPackageName(); } else { projectOperations.getFocusedTopLevelPackage().getFullyQualifiedPackageName(); return javaTypeString.concat(StringUtils.replace(javaTypeFullyQualilfiedName, topLevelPackageString, "~"));
private void setPromptPath(final String fullyQualifiedName) { if (topLevelPackage == null) { return; } String moduleName = ""; if (module != null && StringUtils.isNotBlank(module.getModuleName())) { moduleName = AnsiEscapeCode.decorate(module.getModuleName() + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN); } topLevelPackage = new JavaPackage(typeLocationService.getTopLevelPackageForModule(projectOperations .getFocusedModule())); final String path = moduleName + fullyQualifiedName.replace(topLevelPackage.getFullyQualifiedPackageName(), TOP_LEVEL_PACKAGE_SYMBOL); shell.setPromptPath(path, StringUtils.isNotBlank(moduleName)); }
String module = ""; String topLevelPackage = ""; if (getProjectOperations().isMultimoduleProject()) { getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( SpringJavaType.SPRING_BOOT_APPLICATION); String focusedModuleName = getProjectOperations().getFocusedModuleName(); for (ClassOrInterfaceTypeDetails applicationClass : applicationClasses) { if (focusedModuleName.equals(applicationClass.getType().getModule())) { module = focusedModuleName; topLevelPackage = applicationClass.getType().getPackage().getFullyQualifiedPackageName(); controllersPackageNotSet = false; break; } else { ClassOrInterfaceTypeDetails applicationClass = applicationClasses.iterator().next(); module = applicationClass.getType().getModule(); topLevelPackage = applicationClass.getType().getPackage().getFullyQualifiedPackageName(); getProjectOperations().getFocusedTopLevelPackage().getFullyQualifiedPackageName(); if (StringUtils.isNotEmpty(module)) { packageStr = packageStr.concat(".").concat(module);
@Override public void createIntegrationTest(JavaType type, Pom module) { Validate.notNull(type, "Class to produce an integration test class for is required"); ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(type); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_CONTROLLER), "Type must be a Roo controller."); Validate.notNull(cid.getAnnotation(RooJavaType.ROO_THYMELEAF), "Type must be a Roo Thymeleaf controller."); projectOperations.addProperty("", SPRINGLETS_VERSION_PROPERTY); projectOperations .addDependency(module.getModuleName(), SPRINGLETS_BOOT_STARTER_TEST_DEPENDENCY); new JavaType(managedEntity.getFullyQualifiedTypeName(), managedEntity.getArray(), managedEntity.getDataType(), managedEntity.getArgName(), managedEntity.getParameters(), typeLocationService.getTypeDetails(managedEntity).getType().getModule()); if (projectOperations.isMultimoduleProject()) { String managedEntityModuleName = managedEntity.getModule(); Pom managedEntityModule = projectOperations.getPomFromModuleName(managedEntityModuleName); projectOperations.addDependency(module.getModuleName(), new Dependency(managedEntityModule.getGroupId(), managedEntityModule.getArtifactId(), "${project.version}", DependencyType.valueOfTypeCode("test-jar"), DependencyScope.TEST), true, true);
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); getProjectOperations().addProperty("", SPRINGLETS_VERSION_PROPERTY); getProjectOperations().addModuleDependency(superclass.getModule()); getProjectOperations().addModuleDependency(implementsType.getModule()); if (!getProjectOperations().getFocusedModule().hasDependencyExcludingVersion( new Dependency("org.springframework.boot", "spring-boot-starter-data-jpa", null))) { List<Dependency> dependencies = new ArrayList<Dependency>(); dependencies.add(new Dependency("org.springframework.data", "spring-data-commons", null)); dependencies.add(new Dependency("org.eclipse.persistence", "javax.persistence", null)); getProjectOperations().addDependencies(getProjectOperations().getFocusedModuleName(), dependencies);
@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); }
/** * Method that obtains entity details from entity name * * @param entityName * @return MemberDetails */ public MemberDetails getEntityDetails(String entityName) { String moduleName = getProjectOperations().getFocusedModuleName(); if (entityName.contains(":")) { moduleName = StringUtils.split(entityName, ":")[0]; entityName = StringUtils.split(entityName, ":")[1]; } // Getting JavaType for entityName // Check first if contains base package (~) if (entityName.contains("~")) { entityName = entityName.replace("~", getProjectOperations().getTopLevelPackage(moduleName) .getFullyQualifiedPackageName()); } JavaType entityType = new JavaType(entityName, moduleName); return getEntityDetails(entityType); }
public void setType(final JavaType javaType, final Pom module) { if (javaType == null) { Validate.notNull(module, "ERROR: javaType and module cannot be both null"); javaPackage = projectOperations.getTopLevelPackage(module.getModuleName()); } else { if (javaType.getPackage().getFullyQualifiedPackageName().startsWith("java.")) { return; } javaPackage = javaType.getPackage(); } this.module = module; this.javaType = javaType; this.isVerified = true; setPromptPath(javaType.getFullyQualifiedTypeName()); }
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;