Search in sources :

Example 1 with IdeaSourceDirectory

use of org.gradle.tooling.model.idea.IdeaSourceDirectory 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 IdeaSourceDirectory

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

the class JavaModuleContentRootTest method createSourceDirectoryMock.

@NotNull
private static Pair<File, IdeaSourceDirectory> createSourceDirectoryMock(@NotNull String fileName) {
    File path = new File(fileName);
    IdeaSourceDirectory dir = createMock(IdeaSourceDirectory.class);
    expect(dir.getDirectory()).andStubReturn(path);
    return Pair.create(path, dir);
}
Also used : File(java.io.File) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with IdeaSourceDirectory

use of org.gradle.tooling.model.idea.IdeaSourceDirectory in project intellij-community by JetBrains.

the class ModuleExtendedModelBuilderImplTest method getAllPaths.

private Collection<? extends String> getAllPaths(DomainObjectSet<? extends IdeaSourceDirectory> directories, final String moduleName) {
    List<String> list = ContainerUtil.map2List(directories, new Function<IdeaSourceDirectory, String>() {

        @Override
        public String fun(IdeaSourceDirectory sourceDirectory) {
            String path = FileUtil.toCanonicalPath(FileUtil.getRelativePath(new File(testDir, moduleName), sourceDirectory.getDirectory()));
            Assert.assertNotNull(path);
            return path.substring(path.indexOf("/") + 1);
        }
    });
    Collections.sort(list);
    return list;
}
Also used : File(java.io.File) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory)

Example 4 with IdeaSourceDirectory

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

the class JavaModuleContentRootTest method testCopyWithIdeaContentRoot.

@Test
public void testCopyWithIdeaContentRoot() {
    ExtIdeaContentRoot originalContentRoot = createMock(ExtIdeaContentRoot.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));
    mock = createSourceDirectoryMock("resource");
    File resourceDirPath = mock.getFirst();
    IdeaSourceDirectory resourceDir = mock.getSecond();
    originalContentRoot.getResourceDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(resourceDir));
    mock = createSourceDirectoryMock("test-resource");
    File testResourceDirPath = mock.getFirst();
    IdeaSourceDirectory testResourceDir = mock.getSecond();
    originalContentRoot.getTestResourceDirectories();
    expectLastCall().andStubReturn(DomainObjectHashSet.newSet(testResourceDir));
    File exclude = new File("exclude");
    Set<File> allExclude = Sets.newSet(exclude, null);
    expect(originalContentRoot.getExcludeDirectories()).andStubReturn(allExclude);
    replay(originalContentRoot, sourceDir, genSourceDir, testDir, genTestDir, resourceDir, testResourceDir);
    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()).containsExactly(resourceDirPath);
    assertThat(contentRoot.getTestResourceDirPaths()).containsExactly(testResourceDirPath);
    verify(originalContentRoot, sourceDir, genSourceDir, testDir, genTestDir, resourceDir, testResourceDir);
}
Also used : ExtIdeaContentRoot(org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot) File(java.io.File) IdeaSourceDirectory(org.gradle.tooling.model.idea.IdeaSourceDirectory) Test(org.junit.Test)

Example 5 with IdeaSourceDirectory

use of org.gradle.tooling.model.idea.IdeaSourceDirectory 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)5 IdeaSourceDirectory (org.gradle.tooling.model.idea.IdeaSourceDirectory)5 IdeaContentRoot (org.gradle.tooling.model.idea.IdeaContentRoot)2 ExtIdeaContentRoot (org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot)2 Test (org.junit.Test)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 NotNull (org.jetbrains.annotations.NotNull)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1