use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class JavaTypeConverter method convertFromText.
public JavaType convertFromText(String value, final Class<?> requiredType, final String optionContext) {
if (StringUtils.isBlank(value)) {
return null;
}
// Check for number primitives
if (NUMBER_PRIMITIVES.contains(value)) {
return getNumberPrimitiveType(value);
}
if (LAST_USED_INDICATOR.equals(value)) {
final JavaType result = lastUsed.getJavaType();
if (result == null) {
throw new IllegalStateException("Unknown type; please indicate the type as a command option (ie --xxxx)");
}
return result;
}
String topLevelPath;
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);
topLevelPath = typeLocationService.getTopLevelPackageForModule(module);
value = value.substring(value.indexOf(MODULE_PATH_SEPARATOR) + 1, value.length()).trim();
if (StringUtils.contains(optionContext, UPDATE)) {
projectOperations.setModule(module);
}
} else {
topLevelPath = typeLocationService.getTopLevelPackageForModule(projectOperations.getFocusedModule());
}
if (value.equals(topLevelPath)) {
return null;
}
String newValue = locateExisting(value, topLevelPath);
if (newValue == null) {
newValue = locateNew(value, topLevelPath);
}
if (StringUtils.isNotBlank(newValue)) {
final String physicalTypeIdentifier = typeLocationService.getPhysicalTypeIdentifier(new JavaType(newValue));
if (StringUtils.isNotBlank(physicalTypeIdentifier)) {
module = projectOperations.getPomFromModuleName(PhysicalTypeIdentifier.getPath(physicalTypeIdentifier).getModule());
}
}
// taken as relative to the current package directory
if (!newValue.contains(".")) {
newValue = (lastUsed.getJavaPackage() == null ? lastUsed.getTopLevelPackage().getFullyQualifiedPackageName() : lastUsed.getJavaPackage().getFullyQualifiedPackageName()) + "." + newValue;
}
// Automatically capitalise the first letter of the last name segment
// (i.e. capitalise the type name, but not the package)
final int index = newValue.lastIndexOf(".");
if (index > -1 && !newValue.endsWith(".")) {
String typeName = newValue.substring(index + 1);
typeName = StringUtils.capitalize(typeName);
newValue = newValue.substring(0, index).toLowerCase() + "." + typeName;
}
final JavaType result = new JavaType(newValue, module.getModuleName());
// not verified
if (StringUtils.contains(optionContext, UPDATE) || StringUtils.contains(optionContext, UPDATELAST)) {
if (StringUtils.contains(optionContext, INTERFACE)) {
lastUsed.setTypeNotVerified(null, module);
} else {
lastUsed.setTypeNotVerified(result, module);
}
}
return result;
}
use of org.springframework.roo.project.maven.Pom 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;
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class JavaPackageConverterTest method testGetAllPossibleValuesWhenProjectIsAvailable.
@Test
public void testGetAllPossibleValuesWhenProjectIsAvailable() {
// Set up
final Pom mockPom1 = setUpMockPom("/path/to/pom/1", new JavaType("com.example.domain.Choice"), new JavaType("com.example.domain.Vote"));
final Pom mockPom2 = setUpMockPom("/path/to/pom/2", new JavaType("com.example.web.ChoiceController"), new JavaType("com.example.web.VoteController"));
when(mockProjectOperations.getPoms()).thenReturn(Arrays.asList(mockPom1, mockPom2));
// Invoke and check
assertGetAllPossibleValues(true, new Completion("com.example"), new Completion("com.example.domain"), new Completion("com.example.web"));
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class JavaPackageConverterTest method assertGetAllPossibleValues.
/**
* Asserts that when the converter is asked for possible completions, the
* expected completions are provided.
*
* @param projectAvailable
* @param expectedAllComplete
* @param expectedCompletions
*/
private void assertGetAllPossibleValues(final boolean projectAvailable, final Completion... expectedCompletions) {
// Set up
when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(projectAvailable);
final List<Completion> completions = new ArrayList<Completion>();
final Pom mockPom1 = setUpMockPom("/path/to/pom/1", new JavaType("com.example.domain.Choice"), new JavaType("com.example.web.ChoiceController"));
when(mockProjectOperations.getFocusedModule()).thenReturn(mockPom1);
when(mockTypeLocationService.getTopLevelPackageForModule(mockPom1)).thenReturn(TOP_LEVEL_PACKAGE);
// Invoke
final boolean allComplete = converter.getAllPossibleValues(completions, JavaPackage.class, null, null, null);
// Check
assertEquals(false, allComplete);
assertEquals(Arrays.asList(expectedCompletions), completions);
}
use of org.springframework.roo.project.maven.Pom in project spring-roo by spring-projects.
the class JavaTypeConverterTest method testGetAllPossibleValuesInProjectWhenModulePrefixIsUsed.
@Test
public void testGetAllPossibleValuesInProjectWhenModulePrefixIsUsed() {
// Set up
@SuppressWarnings("unchecked") final List<Completion> mockCompletions = mock(List.class);
when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(true);
final String otherModuleName = "core";
final Pom mockOtherModule = mock(Pom.class);
when(mockOtherModule.getModuleName()).thenReturn(otherModuleName);
when(mockProjectOperations.getPomFromModuleName(otherModuleName)).thenReturn(mockOtherModule);
final String topLevelPackage = "com.example";
when(mockTypeLocationService.getTopLevelPackageForModule(mockOtherModule)).thenReturn(topLevelPackage);
final String focusedModuleName = "web";
when(mockProjectOperations.getModuleNames()).thenReturn(Arrays.asList(focusedModuleName, otherModuleName));
final String modulePath = "/path/to/it";
when(mockOtherModule.getPath()).thenReturn(modulePath);
final JavaType type1 = new JavaType("com.example.web.ShouldBeFound");
final JavaType type2 = new JavaType("com.example.foo.ShouldNotBeFound");
when(mockTypeLocationService.getTypesForModule(mockOtherModule)).thenReturn(Arrays.asList(type1, type2));
// Invoke
converter.getAllPossibleValues(mockCompletions, JavaType.class, otherModuleName + MODULE_PATH_SEPARATOR + "~.web", OptionContexts.PROJECT, null);
// Check
verify(mockCompletions).add(new Completion(focusedModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.decorate(focusedModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN), "Modules", 0));
// prefix + topLevelPackage, formattedPrefix + topLevelPackage, heading
final String formattedPrefix = decorate(otherModuleName + MODULE_PATH_SEPARATOR, FG_CYAN);
final String prefix = otherModuleName + MODULE_PATH_SEPARATOR;
verify(mockCompletions).add(new Completion(prefix + topLevelPackage, formattedPrefix + topLevelPackage, "", 1));
verify(mockCompletions).add(new Completion(prefix + "~.web.ShouldBeFound", formattedPrefix + "~.web.ShouldBeFound", "", 1));
verifyNoMoreInteractions(mockCompletions);
}
Aggregations