Search in sources :

Example 6 with Completion

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

the class PackagingProviderConverterTest method testGetAllPossibleValues.

@Test
public void testGetAllPossibleValues() {
    // Set up
    final PackagingProvider[] providers = { mockCoreJarPackaging, mockCustomJarPackaging, mockWarPackaging };
    when(mockPackagingProviderRegistry.getAllPackagingProviders()).thenReturn(Arrays.asList(providers));
    final List<Completion> expectedCompletions = new ArrayList<Completion>();
    for (final PackagingProvider provider : providers) {
        expectedCompletions.add(new Completion(provider.getId().toUpperCase()));
    }
    final List<Completion> completions = new ArrayList<Completion>();
    // Invoke
    final boolean addSpace = converter.getAllPossibleValues(completions, PackagingProvider.class, "ignored", null, null);
    // Check
    assertTrue(addSpace);
    assertEquals(expectedCompletions.size(), completions.size());
    assertTrue("Expected " + expectedCompletions + " but was " + completions, completions.containsAll(expectedCompletions));
}
Also used : Completion(org.springframework.roo.shell.Completion) ArrayList(java.util.ArrayList) CorePackagingProvider(org.springframework.roo.project.packaging.CorePackagingProvider) PackagingProvider(org.springframework.roo.project.packaging.PackagingProvider) Test(org.junit.Test)

Example 7 with Completion

use of org.springframework.roo.shell.Completion 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);
}
Also used : JavaType(org.springframework.roo.model.JavaType) Completion(org.springframework.roo.shell.Completion) Pom(org.springframework.roo.project.maven.Pom) Test(org.junit.Test)

Example 8 with Completion

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

the class JavaTypeConverterTest method testGetAllPossibleValuesInProjectWhenNoModulePrefixIsUsed.

@Test
public void testGetAllPossibleValuesInProjectWhenNoModulePrefixIsUsed() {
    // Set up
    @SuppressWarnings("unchecked") final List<Completion> mockCompletions = mock(List.class);
    when(mockProjectOperations.isFocusedProjectAvailable()).thenReturn(true);
    final Pom mockFocusedModule = mock(Pom.class);
    when(mockProjectOperations.getFocusedModule()).thenReturn(mockFocusedModule);
    final String topLevelPackage = "com.example";
    when(mockTypeLocationService.getTopLevelPackageForModule(mockFocusedModule)).thenReturn(topLevelPackage);
    final String focusedModuleName = "web";
    when(mockFocusedModule.getModuleName()).thenReturn(focusedModuleName);
    final String modulePath = "/path/to/it";
    when(mockFocusedModule.getPath()).thenReturn(modulePath);
    final String otherModuleName = "core";
    when(mockProjectOperations.getModuleNames()).thenReturn(Arrays.asList(focusedModuleName, otherModuleName));
    final JavaType type1 = new JavaType("com.example.Foo");
    final JavaType type2 = new JavaType("com.example.sub.Bar");
    when(mockTypeLocationService.getTypesForModule(mockFocusedModule)).thenReturn(Arrays.asList(type1, type2));
    // Invoke
    converter.getAllPossibleValues(mockCompletions, JavaType.class, "", OptionContexts.PROJECT, null);
    // Check
    verify(mockCompletions).add(new Completion(otherModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.decorate(otherModuleName + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN), "Modules", 0));
    verify(mockCompletions).add(new Completion(topLevelPackage, topLevelPackage, focusedModuleName, 1));
    verify(mockCompletions).add(new Completion("~.Foo", "~.Foo", focusedModuleName, 1));
    verify(mockCompletions).add(new Completion("~.sub.Bar", "~.sub.Bar", focusedModuleName, 1));
    verifyNoMoreInteractions(mockCompletions);
}
Also used : JavaType(org.springframework.roo.model.JavaType) Completion(org.springframework.roo.shell.Completion) Pom(org.springframework.roo.project.maven.Pom) Test(org.junit.Test)

Example 9 with Completion

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

the class FileConverter method populate.

protected void populate(final List<Completion> completions, final String adjustedUserInput, final String originalUserInput, final String directoryData) {
    final File directory = new File(directoryData);
    if (!directory.isDirectory()) {
        return;
    }
    for (final File file : directory.listFiles()) {
        if (adjustedUserInput == null || adjustedUserInput.length() == 0 || file.getName().toLowerCase().startsWith(adjustedUserInput.toLowerCase())) {
            String completion = "";
            if (directoryData.length() > 0) {
                completion += directoryData;
            }
            completion += file.getName();
            completion = convertCompletionBackIntoUserInputStyle(originalUserInput, completion);
            if (file.isDirectory()) {
                completions.add(new Completion(completion + File.separator));
            } else {
                completions.add(new Completion(completion));
            }
        }
    }
}
Also used : Completion(org.springframework.roo.shell.Completion) File(java.io.File)

Example 10 with Completion

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

the class JmsCommands method returnApplicationPackages.

@CliOptionAutocompleteIndicator(command = "jms receiver", param = "endpoint", validate = false, includeSpaceOnFinish = false, help = "--endpoint parameter parameter is the service where will be added the " + "support to send emails.")
public List<String> returnApplicationPackages(ShellContext shellContext) {
    List<String> applicationPackages = new ArrayList<String>();
    // Get only application modules
    StringBuffer matcher = new StringBuffer("feature[");
    matcher.append(ModuleFeatureName.APPLICATION).append("]");
    JavaPackageConverter converter = (JavaPackageConverter) getJavaPackageConverterService().get(0);
    List<Completion> completions = new ArrayList<Completion>();
    converter.getAllPossibleValues(completions, String.class, shellContext.getParameters().get("endpoint"), matcher.toString(), null);
    for (Completion completion : completions) {
        applicationPackages.add(completion.getValue());
    }
    return applicationPackages;
}
Also used : Completion(org.springframework.roo.shell.Completion) JavaPackageConverter(org.springframework.roo.converters.JavaPackageConverter) ArrayList(java.util.ArrayList) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Aggregations

Completion (org.springframework.roo.shell.Completion)16 JavaType (org.springframework.roo.model.JavaType)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Pom (org.springframework.roo.project.maven.Pom)4 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1 Calendar (java.util.Calendar)1 Collection (java.util.Collection)1 Date (java.util.Date)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 TreeSet (java.util.TreeSet)1 Repository (org.apache.felix.bundlerepository.Repository)1 Resource (org.apache.felix.bundlerepository.Resource)1