GradleValueProviderFactory implements ValueProviderFactory { @Override public ValueProvider newInstance(FolderEntry projectFolder) { return new GradleValueProvider(projectFolder); } @Inject  GradleValueProviderFactory(GradleProjectManager projectManager); @Override ValueProvider newInstance(FolderEntry projectFolder);  }
@Test public void testValueProvider() throws Exception { final URL resource = getClass().getClassLoader().getResource("pro/javax/che/plugin/gradle/server/quickstart.zip"); assertNotNull(resource); vfs.importZip(vfs.getMountPoint().getRoot().getId(), resource.openStream(), true, false); final VirtualFile project = vfs.getMountPoint().getVirtualFile("/quickstart"); assertTrue(project.isFolder()); final FolderEntry projectFolder = new FolderEntry(workspace, project); final GradleProjectManager gradleProjectManager = new GradleProjectManager(new DefaultProjectConnectionFactory()); final ValueProviderFactory valueProviderFactory = new GradleValueProviderFactory(gradleProjectManager); final ValueProvider valueProvider = valueProviderFactory.newInstance(projectFolder); List<String> computedPath = valueProvider.getValues(PROJECT_PATH_VAR); List<String> expectedPath = singletonList(":"); assertTrue(elementsEqual(computedPath, expectedPath)); List<String> computedBuildDir = valueProvider.getValues(PROJECT_BUILD_DIR_VAR); List<String> expectedBuildDir = singletonList("build"); assertTrue(elementsEqual(computedBuildDir, expectedBuildDir)); List<String> computedBuildScript = valueProvider.getValues(PROJECT_BUILD_SCRIPT_VAR); List<String> expectedBuildScript = singletonList("build.gradle"); assertTrue(elementsEqual(computedBuildScript, expectedBuildScript)); List<String> computedTasks = valueProvider.getValues(PROJECT_TASKS_VAR); List<String> expectedTasks = newArrayList(":assemble", ":build", ":buildDependents", ":buildEnvironment", ":buildNeeded", ":check", ":classes", ":clean", ":cleanEclipse", ":components", ":dependencies", ":dependencyInsight", ":eclipse", ":help", ":init", ":jar", ":javadoc", ":model", ":projects", ":properties", ":tasks", ":test", ":testClasses", ":uploadArchives", ":wrapper"); assertTrue(elementsEqual(computedTasks, expectedTasks)); List<String> computedDescription = valueProvider.getValues(PROJECT_DESCRIPTION_VAR); List<String> expectedDescription = singletonList(""); assertTrue(elementsEqual(computedDescription, expectedDescription)); List<String> computedSourceDirectories = valueProvider.getValues(PROJECT_SOURCE_DIR_VAR); List<String> expectedSourceDirectories = newArrayList("src/main/resources", "src/main/java"); assertTrue(elementsEqual(computedSourceDirectories, expectedSourceDirectories)); List<String> computedTestDirectories = valueProvider.getValues(PROJECT_TEST_DIR_VAR); List<String> expectedTestDirectories = newArrayList("src/test/resources", "src/test/java"); assertTrue(elementsEqual(computedTestDirectories, expectedTestDirectories)); List<String> computedGradleVersion = valueProvider.getValues(PROJECT_GRADLE_VERSION_VAR); List<String> expectedGradleVersion = singletonList("2.10"); assertTrue(elementsEqual(computedGradleVersion, expectedGradleVersion)); }
@Test public void testShouldReturnEmptyValueForEmptyProjectFolder() throws Exception { vfs.createFolder(vfs.getMountPoint().getRoot().getId(), "empty"); final VirtualFile project = vfs.getMountPoint().getVirtualFile("/empty"); assertTrue(project.isFolder()); final FolderEntry projectFolder = new FolderEntry(workspace, project); final GradleProjectManager gradleProjectManager = new GradleProjectManager(new DefaultProjectConnectionFactory()); final ValueProviderFactory valueProviderFactory = new GradleValueProviderFactory(gradleProjectManager); final ValueProvider valueProvider = valueProviderFactory.newInstance(projectFolder); List<String> computedPath = valueProvider.getValues(PROJECT_PATH_VAR); assertTrue(computedPath.isEmpty()); }