Search in sources :

Example 1 with IdeaContentRoot

use of org.gradle.tooling.model.idea.IdeaContentRoot in project android by JetBrains.

the class JavaModuleContentRootTest method testCopyWithGradleContentRoot.

@Test
public void testCopyWithGradleContentRoot() {
    IdeaContentRoot originalContentRoot = createMock(IdeaContentRoot.class);
    File rootDirPath = new File("root");
    expect(originalContentRoot.getRootDirectory()).andStubReturn(rootDirPath);
    Pair<File, IdeaSourceDirectory> mock = createSourceDirectoryMock("src");
    File sourceDirPath = mock.getFirst();
    IdeaSourceDirectory sourceDir = mock.getSecond();
    originalContentRoot.getSourceDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(sourceDir));
    mock = createSourceDirectoryMock("gen-src");
    File genSourceDirPath = mock.getFirst();
    IdeaSourceDirectory genSourceDir = mock.getSecond();
    originalContentRoot.getGeneratedSourceDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(genSourceDir));
    mock = createSourceDirectoryMock("test");
    File testDirPath = mock.getFirst();
    IdeaSourceDirectory testDir = mock.getSecond();
    originalContentRoot.getTestDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(testDir));
    mock = createSourceDirectoryMock("gen-test");
    File genTestDirPath = mock.getFirst();
    IdeaSourceDirectory genTestDir = mock.getSecond();
    originalContentRoot.getGeneratedTestDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(genTestDir));
    File exclude = new File("exclude");
    Set<File> allExclude = Sets.newSet(exclude, null);
    expect(originalContentRoot.getExcludeDirectories()).andStubReturn(allExclude);
    replay(originalContentRoot, sourceDir, genSourceDir, testDir, genTestDir);
    JavaModuleContentRoot contentRoot = JavaModuleContentRoot.copy(originalContentRoot);
    assertNotNull(contentRoot);
    assertSame(contentRoot.getRootDirPath(), rootDirPath);
    assertThat(contentRoot.getSourceDirPaths()).containsExactly(sourceDirPath);
    assertThat(contentRoot.getGenSourceDirPaths()).containsExactly(genSourceDirPath);
    assertThat(contentRoot.getTestDirPaths()).containsExactly(testDirPath);
    assertThat(contentRoot.getGenTestDirPaths()).containsExactly(genTestDirPath);
    assertThat(contentRoot.getResourceDirPaths()).isEmpty();
    assertThat(contentRoot.getTestResourceDirPaths()).isEmpty();
    verify(originalContentRoot, sourceDir, genSourceDir, testDir, genTestDir);
}
Also used : ExtIdeaContentRoot(org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) File(java.io.File) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) Test(org.junit.Test)

Example 2 with IdeaContentRoot

use of org.gradle.tooling.model.idea.IdeaContentRoot in project meghanada-server by mopemope.

the class GradleProject method searchProjectSources.

private Map<String, Set<File>> searchProjectSources(final IdeaModule ideaModule) throws IOException {
    final Map<String, Set<File>> result = new HashMap<>(8);
    result.put("sources", new HashSet<>(2));
    result.put("resources", new HashSet<>(2));
    result.put("testSources", new HashSet<>(2));
    result.put("testResources", new HashSet<>(2));
    for (final IdeaContentRoot ideaContentRoot : ideaModule.getContentRoots().getAll()) {
        for (final IdeaSourceDirectory sourceDirectory : ideaContentRoot.getSourceDirectories().getAll()) {
            final File file = normalizeFile(sourceDirectory.getDirectory());
            final String path = file.getCanonicalPath();
            if (path.contains("resources")) {
                result.get("resources").add(file);
            } else {
                result.get("sources").add(file);
            }
        }
        for (final IdeaSourceDirectory sourceDirectory : ideaContentRoot.getTestDirectories().getAll()) {
            final File file = normalizeFile(sourceDirectory.getDirectory());
            final String path = file.getCanonicalPath();
            if (path.contains("resources")) {
                result.get("testResources").add(file);
            } else {
                result.get("testSources").add(file);
            }
        }
    }
    return result;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DomainObjectSet(org.gradle.tooling.model.DomainObjectSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IdeaContentRoot(org.gradle.tooling.model.idea.IdeaContentRoot) File(java.io.File) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory)

Aggregations

File (java.io.File)2 IdeaContentRoot (org.gradle.tooling.model.idea.IdeaContentRoot)2 IdeaSourceDirectory (org.gradle.tooling.model.idea.IdeaSourceDirectory)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DomainObjectSet (org.gradle.tooling.model.DomainObjectSet)1 ExtIdeaContentRoot (org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot)1 Test (org.junit.Test)1