Search in sources :

Example 1 with ModuleFeatureName

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

the class PomConverter method convertFromText.

public Pom convertFromText(final String value, final Class<?> targetType, final String optionContext) {
    final String moduleName;
    Pom result;
    ModuleFeatureName moduleFeatureName = null;
    // Get module feature
    if (optionContext != null) {
        final Matcher matcher = pattern.matcher(optionContext);
        if (matcher.find()) {
            moduleFeatureName = ModuleFeatureName.valueOf(matcher.group(1));
        }
    }
    if (LAST_USED_INDICATOR.equals(value)) {
        result = lastUsed.getModule();
        if (result == null) {
            throw new IllegalStateException("Unknown pom; please indicate the module as a command option (ie --xxxx)");
        }
    } else if (FOCUSED_INDICATOR.equals(value)) {
        result = projectOperations.getFocusedModule();
        if (moduleFeatureName != null && !typeLocationService.hasModuleFeature(result, moduleFeatureName)) {
            // Get valid module
            List<Pom> modules = (List<Pom>) typeLocationService.getModules(moduleFeatureName);
            if (modules.size() == 0) {
                throw new RuntimeException(String.format("ERROR: Not exists a module with %s feature", moduleFeatureName));
            } else {
                result = modules.get(0);
            }
        }
    } else {
        if (ROOT_MODULE_SYMBOL.equals(value)) {
            moduleName = "";
        } else {
            moduleName = value;
        }
        result = projectOperations.getPomFromModuleName(moduleName);
        Validate.notNull(result, String.format("Module %s not found", moduleName));
    }
    // Validate feature
    if (moduleFeatureName != null && !typeLocationService.hasModuleFeature(result, moduleFeatureName)) {
        return null;
    }
    if (StringUtils.contains(optionContext, UPDATE) || StringUtils.contains(optionContext, UPDATELAST)) {
        lastUsed.setTypeNotVerified(null, result);
    }
    return result;
}
Also used : ModuleFeatureName(org.springframework.roo.classpath.ModuleFeatureName) Matcher(java.util.regex.Matcher) List(java.util.List) Pom(org.springframework.roo.project.maven.Pom)

Example 2 with ModuleFeatureName

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

the class PomConverter method getAllPossibleValues.

public boolean getAllPossibleValues(final List<Completion> completions, final Class<?> targetType, final String existingData, final String optionContext, final MethodTarget target) {
    boolean filteredByFeature = false;
    if (optionContext != null) {
        for (ModuleFeatureName moduleFeatureName : ModuleFeatureName.values()) {
            if (optionContext.contains(moduleFeatureName.name())) {
                filteredByFeature = true;
                addModules(completions, optionContext, typeLocationService.getModuleNames(moduleFeatureName));
            }
        }
    }
    if (!filteredByFeature) {
        addModules(completions, optionContext, projectOperations.getModuleNames());
    }
    return true;
}
Also used : ModuleFeatureName(org.springframework.roo.classpath.ModuleFeatureName)

Aggregations

ModuleFeatureName (org.springframework.roo.classpath.ModuleFeatureName)2 List (java.util.List)1 Matcher (java.util.regex.Matcher)1 Pom (org.springframework.roo.project.maven.Pom)1