public void testSourceFilesAreCorrectlyMarkedAsSourceOrGenerated() throws Exception {
   scratch.file(
       "com/google/example/BUILD",
       "genrule(",
       "   name = 'gen',",
       "   outs = ['gen.java'],",
       "   cmd = '',",
       ")",
       "java_library(",
       "    name = 'lib',",
       "    srcs = ['Test.java', ':gen'],",
       ")");
   Map<String, RuleIdeInfo> ruleIdeInfos = buildRuleIdeInfo("//com/google/example:lib");
   RuleIdeInfo ruleIdeInfo = getRuleInfoAndVerifyLabel("//com/google/example:lib", ruleIdeInfos);
   assertThat(ruleIdeInfo.getJavaRuleIdeInfo().getSourcesList())
       .containsExactly(
           ArtifactLocation.newBuilder()
               .setRootPath(targetConfig.getGenfilesDirectory().getPath().getPathString())
               .setRelativePath("com/google/example/gen.java")
               .setIsSource(false)
               .build(),
           ArtifactLocation.newBuilder()
               .setRootPath(directories.getWorkspace().getPathString())
               .setRelativePath("com/google/example/Test.java")
               .setIsSource(true)
               .build());
 }
 @Override
 public String apply(Artifact artifact) {
   ArtifactLocation location = makeArtifactLocation(artifact);
   return Joiner.on(",")
       .join(
           location.getRootExecutionPathFragment(),
           location.getRelativePath(),
           location.getRootPath());
 }
 private static ArtifactLocation makeArtifactLocation(SourceDirectory resourceDir) {
   return ArtifactLocation.newBuilder()
       .setRootPath(resourceDir.getRootPath().toString())
       .setRootExecutionPathFragment(resourceDir.getRootExecutionPathFragment().toString())
       .setRelativePath(resourceDir.getRelativePath().toString())
       .setIsSource(resourceDir.isSource())
       .build();
 }
 private static ArtifactLocation makeArtifactLocation(Root root, PathFragment relativePath) {
   return ArtifactLocation.newBuilder()
       .setRootPath(root.getPath().toString())
       .setRootExecutionPathFragment(root.getExecPath().toString())
       .setRelativePath(relativePath.toString())
       .setIsSource(root.isSourceRoot())
       .build();
 }