use of com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder in project buck by facebook.
the class ProjectTest method testSrcRoots.
/**
* A project_config()'s src_roots argument can be {@code []}, or a non-empty array.
* Each of these should be treated differently.
*/
@Test
public void testSrcRoots() throws Exception {
// Create a project_config() with src_roots=[].
BuildRuleResolver ruleResolver2 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule baseBuildRule = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).build(ruleResolver2);
ProjectConfig inPackageProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseBuildRule.getBuildTarget()).setSrcRoots(ImmutableList.of()).build(ruleResolver2);
// Verify that the correct source folders are created.
JavaPackageFinder javaPackageFinder = EasyMock.createMock(JavaPackageFinder.class);
EasyMock.expect(javaPackageFinder.findJavaPackage(Paths.get("java/com/example/base/module_java_com_example_base.iml"))).andReturn("com.example.base");
EasyMock.replay(javaPackageFinder);
ProjectWithModules projectWithModules2 = getModulesForActionGraph(ruleResolver2, ImmutableSortedSet.of(inPackageProjectConfig), javaPackageFinder, null);
EasyMock.verify(javaPackageFinder);
assertEquals(1, projectWithModules2.modules.size());
SerializableModule moduleWithPackagePrefix = projectWithModules2.modules.get(0);
assertListEquals("The current directory should be a source tmp with a package prefix " + "as well as the gen/ directory.", ImmutableList.of(new SourceFolder("file://$MODULE_DIR$", false, /* isTestSource */
"com.example.base"), SerializableModule.SourceFolder.GEN), moduleWithPackagePrefix.sourceFolders);
// Create a project_config() with src_roots=['src'].
BuildRuleResolver ruleResolver3 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRule baseBuildRule3 = AndroidLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:base")).build(ruleResolver3);
ProjectConfig hasSrcFolderProjectConfig = ProjectConfigBuilder.createBuilder(BuildTargetFactory.newInstance("//java/com/example/base:project_config")).setSrcRule(baseBuildRule3.getBuildTarget()).setSrcRoots(ImmutableList.of("src")).build(ruleResolver3);
ProjectWithModules projectWithModules3 = getModulesForActionGraph(ruleResolver3, ImmutableSortedSet.of(hasSrcFolderProjectConfig), null, /* javaPackageFinder */
null);
// Verify that the correct source folders are created.
assertEquals(1, projectWithModules3.modules.size());
SerializableModule moduleHasSrcFolder = projectWithModules3.modules.get(0);
assertListEquals("Both src/ and gen/ should be source folders.", ImmutableList.of(new SourceFolder("file://$MODULE_DIR$/src", false), SerializableModule.SourceFolder.GEN), moduleHasSrcFolder.sourceFolders);
}
use of com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder in project buck by facebook.
the class ProjectTest method testProject.
/**
* This is an important test that verifies that the {@code no_dx} argument for an
* {@code android_binary} is handled appropriately when generating an IntelliJ project.
*/
@Test
public void testProject() throws Exception {
JavaPackageFinder javaPackageFinder = EasyMock.createMock(JavaPackageFinder.class);
EasyMock.expect(javaPackageFinder.findJavaPackage(Paths.get("foo/module_foo.iml"))).andReturn("");
EasyMock.expect(javaPackageFinder.findJavaPackage(Paths.get("bar/module_bar.iml"))).andReturn("");
EasyMock.replay(javaPackageFinder);
Pair<ProjectWithModules, BuildRuleResolver> projectWithModules = createActionGraphForTesting(javaPackageFinder);
Project project = projectWithModules.getFirst().project;
BuildRuleResolver resolver = projectWithModules.getSecond();
List<SerializableModule> modules = projectWithModules.getFirst().modules;
assertEquals("Should be one module for the java_library, one for the android_library, " + "one module for the android_resource, and one for each android_binary", 5, modules.size());
// Check the values of the module that corresponds to the android_library.
SerializableModule javaLibraryModule = modules.get(4);
assertSame(getRuleByBuildTarget("//java/src/com/facebook/exportlib:exportlib", resolver), javaLibraryModule.srcRule);
assertEquals("module_java_src_com_facebook_exportlib", javaLibraryModule.name);
assertEquals(Paths.get("java/src/com/facebook/exportlib/module_java_src_com_facebook_exportlib.iml"), javaLibraryModule.pathToImlFile);
assertListEquals(ImmutableList.of(SerializableModule.SourceFolder.SRC), javaLibraryModule.sourceFolders);
// Check the dependencies.
SerializableDependentModule inheritedJdk = SerializableDependentModule.newInheritedJdk();
SerializableDependentModule guavaAsProvidedDep = SerializableDependentModule.newLibrary(guava.getBuildTarget(), "buck_out_gen_third_party_guava___guava___guava_10_0_1_jar");
guavaAsProvidedDep.scope = "PROVIDED";
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), guavaAsProvidedDep, SerializableDependentModule.newStandardJdk(Optional.empty(), Optional.empty())), javaLibraryModule.getDependencies());
// Check the values of the module that corresponds to the android_library.
SerializableModule androidLibraryModule = modules.get(3);
assertSame(getRuleByBuildTarget("//java/src/com/facebook/base:base", resolver), androidLibraryModule.srcRule);
assertEquals("module_java_src_com_facebook_base", androidLibraryModule.name);
assertEquals(Paths.get("java/src/com/facebook/base/module_java_src_com_facebook_base.iml"), androidLibraryModule.pathToImlFile);
assertListEquals(ImmutableList.of(SerializableModule.SourceFolder.SRC, new SourceFolder("file://$MODULE_DIR$/src-gen", false), SerializableModule.SourceFolder.GEN), androidLibraryModule.sourceFolders);
assertTrue(androidLibraryModule.hasAndroidFacet);
assertTrue(androidLibraryModule.isAndroidLibraryProject);
assertEquals(null, androidLibraryModule.proguardConfigPath);
assertEquals(null, androidLibraryModule.resFolder);
// Check the dependencies.
SerializableDependentModule androidResourceAsProvidedDep = SerializableDependentModule.newModule(BuildTargetFactory.newInstance("//android_res/base:res"), "module_android_res_base");
SerializableDependentModule childAsProvidedDep = SerializableDependentModule.newModule(BuildTargetFactory.newInstance("//java/src/com/facebook/child:child"), "module_java_src_com_facebook_child");
SerializableDependentModule exportDepsAsProvidedDep = SerializableDependentModule.newModule(BuildTargetFactory.newInstance("//java/src/com/facebook/exportlib:exportlib"), "module_java_src_com_facebook_exportlib");
assertListEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), guavaAsProvidedDep, androidResourceAsProvidedDep, childAsProvidedDep, exportDepsAsProvidedDep, inheritedJdk), androidLibraryModule.getDependencies());
// Check the values of the module that corresponds to the android_binary that uses no_dx.
SerializableModule androidResourceModule = modules.get(0);
assertSame(getRuleByBuildTarget("//android_res/base:res", resolver), androidResourceModule.srcRule);
assertEquals(Paths.get("res"), androidResourceModule.resFolder);
// Check the values of the module that corresponds to the android_binary that uses no_dx.
SerializableModule androidBinaryModuleNoDx = modules.get(2);
assertSame(getRuleByBuildTarget("//foo:app", resolver), androidBinaryModuleNoDx.srcRule);
assertEquals("module_foo", androidBinaryModuleNoDx.name);
assertEquals(Paths.get("foo/module_foo.iml"), androidBinaryModuleNoDx.pathToImlFile);
assertListEquals(ImmutableList.of(SerializableModule.SourceFolder.GEN), androidBinaryModuleNoDx.sourceFolders);
assertTrue(androidBinaryModuleNoDx.hasAndroidFacet);
assertFalse(androidBinaryModuleNoDx.isAndroidLibraryProject);
assertEquals(null, androidBinaryModuleNoDx.proguardConfigPath);
assertEquals(null, androidBinaryModuleNoDx.resFolder);
assertEquals(Paths.get("../keystore/debug.keystore"), androidBinaryModuleNoDx.keystorePath);
// Check the moduleDependencies.
SerializableDependentModule grandchildAsProvidedDep = SerializableDependentModule.newModule(BuildTargetFactory.newInstance("//java/src/com/facebook/grandchild:grandchild"), "module_java_src_com_facebook_grandchild");
SerializableDependentModule androidLibraryDep = SerializableDependentModule.newModule(androidLibraryModule.srcRule.getBuildTarget(), "module_java_src_com_facebook_base");
assertEquals(ImmutableList.of(SerializableDependentModule.newSourceFolder(), guavaAsProvidedDep, androidLibraryDep, androidResourceAsProvidedDep, childAsProvidedDep, exportDepsAsProvidedDep, grandchildAsProvidedDep, inheritedJdk), androidBinaryModuleNoDx.getDependencies());
// Check the values of the module that corresponds to the android_binary with an empty no_dx.
SerializableModule androidBinaryModuleEmptyNoDx = modules.get(1);
assertSame(getRuleByBuildTarget("//bar:app", resolver), androidBinaryModuleEmptyNoDx.srcRule);
assertEquals("module_bar", androidBinaryModuleEmptyNoDx.name);
assertEquals(Paths.get("bar/module_bar.iml"), androidBinaryModuleEmptyNoDx.pathToImlFile);
assertListEquals(ImmutableList.of(SerializableModule.SourceFolder.GEN), androidBinaryModuleEmptyNoDx.sourceFolders);
assertTrue(androidBinaryModuleEmptyNoDx.hasAndroidFacet);
assertFalse(androidBinaryModuleEmptyNoDx.isAndroidLibraryProject);
assertEquals(null, androidBinaryModuleEmptyNoDx.proguardConfigPath);
assertEquals(null, androidBinaryModuleEmptyNoDx.resFolder);
assertEquals(Paths.get("../keystore/debug.keystore"), androidBinaryModuleEmptyNoDx.keystorePath);
// Check the moduleDependencies.
SerializableDependentModule guavaAsCompiledDep = SerializableDependentModule.newLibrary(guava.getBuildTarget(), "buck_out_gen_third_party_guava___guava___guava_10_0_1_jar");
assertEquals("Important that Guava is listed as a 'COMPILED' dependency here because it is " + "only listed as a 'PROVIDED' dependency earlier.", ImmutableList.of(SerializableDependentModule.newSourceFolder(), guavaAsCompiledDep, androidLibraryDep, androidResourceAsProvidedDep, childAsProvidedDep, exportDepsAsProvidedDep, grandchildAsProvidedDep, inheritedJdk), androidBinaryModuleEmptyNoDx.getDependencies());
// Check that the correct data was extracted to populate the .idea/libraries directory.
BuildRule guava = getRuleByBuildTarget("//third_party/guava:guava", resolver);
assertSame(guava, Iterables.getOnlyElement(project.getLibraryJars()));
}
use of com.facebook.buck.jvm.java.intellij.SerializableModule.SourceFolder in project buck by facebook.
the class ProjectTest method testDoNotIgnoreAllOfBuckOut.
@Test
public void testDoNotIgnoreAllOfBuckOut() {
SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
ProjectFilesystem projectFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem("/opt/src/buck");
BuildTarget buildTarget = BuildTarget.builder(projectFilesystem.getRootPath(), "//", "base").build();
BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
SerializableModule module = new SerializableModule(buildRule, buildTarget);
Project.addRootExcludes(module, buildRule, projectFilesystem);
ImmutableSortedSet.Builder<SourceFolder> expectedExcludeFolders = ImmutableSortedSet.orderedBy(SerializableModule.ALPHABETIZER);
expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/bin", /* isTestSource */
false));
expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/log", /* isTestSource */
false));
expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/buck-out/tmp", /* isTestSource */
false));
for (Path ignorePath : FluentIterable.from(projectFilesystem.getIgnorePaths()).filter(input -> input.getType() == PathOrGlobMatcher.Type.PATH).transform(PathOrGlobMatcher::getPath)) {
if (!ignorePath.equals(projectFilesystem.getBuckPaths().getBuckOut()) && !ignorePath.equals(projectFilesystem.getBuckPaths().getGenDir())) {
expectedExcludeFolders.add(new SourceFolder("file://$MODULE_DIR$/" + MorePaths.pathWithUnixSeparators(ignorePath), /* isTestSource */
false));
}
}
assertEquals("Specific subfolders of buck-out should be excluded rather than all of buck-out.", expectedExcludeFolders.build(), module.excludeFolders);
}
Aggregations