use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class JavaSourceFolderProviderTest method testRelativePackagePrefix.
@Test
public void testRelativePackagePrefix() {
ImmutableList<BlazeContentEntry> contentEntries = ImmutableList.of(BlazeContentEntry.builder("/src/workspace/java/apps").addSource(BlazeSourceDirectory.builder("/src/workspace/java/apps").setPackagePrefix("apps").build()).build());
JavaSourceFolderProvider provider = new JavaSourceFolderProvider(new BlazeJavaSyncData(new BlazeJavaImportResult(contentEntries, ImmutableMap.of(), ImmutableList.of(), ImmutableSet.of(), null), new GlobSet(ImmutableList.of())));
VirtualFile root = workspace.createDirectory(new WorkspacePath("java/apps"));
ContentEntry contentEntry = getContentEntry(root);
ImmutableMap<File, SourceFolder> sourceFolders = provider.initializeSourceFolders(contentEntry);
assertThat(sourceFolders).hasSize(1);
VirtualFile testRoot = workspace.createDirectory(new WorkspacePath("java/apps/tests/model"));
SourceFolder testSourceChild = provider.setSourceFolderForLocation(contentEntry, sourceFolders.get(new File(root.getPath())), new File(testRoot.getPath()), true);
assertThat(testSourceChild.isTestSource()).isTrue();
assertThat(testSourceChild.getPackagePrefix()).isEqualTo("apps.tests.model");
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class KotlinSyncTest method testKotlinClassesPresentInClassPath.
@Test
public void testKotlinClassesPresentInClassPath() {
setProjectView("directories:", " src/main/kotlin/com/google", "targets:", " //src/main/kotlin/com/google:lib", "additional_languages:", " kotlin");
workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName1.kt"), "package com.google;", "public class ClassWithUniqueName1 {}");
workspace.createFile(new WorkspacePath("src/main/kotlin/com/google/ClassWithUniqueName2.kt"), "package com.google;", "public class ClassWithUniqueName2 {}");
workspace.createDirectory(new WorkspacePath("external/com_github_jetbrains_kotlin"));
TargetMap targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("src/main/kotlin/com/google/BUILD")).setLabel("//src/main/kotlin/com/google:lib").setKind("kt_jvm_library").addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName1.scala")).addSource(sourceRoot("src/main/kotlin/com/google/ClassWithUniqueName2.scala")).setJavaInfo(JavaIdeInfo.builder())).build();
setTargetMap(targetMap);
BlazeSyncParams syncParams = new BlazeSyncParams.Builder("Full Sync", BlazeSyncParams.SyncMode.FULL).addProjectViewTargets(true).build();
runBlazeSync(syncParams);
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData();
assertThat(blazeProjectData).isNotNull();
assertThat(blazeProjectData.targetMap).isEqualTo(targetMap);
assertThat(blazeProjectData.workspaceLanguageSettings).isEqualTo(new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.JAVA, LanguageClass.KOTLIN)));
BlazeJavaSyncData javaSyncData = blazeProjectData.syncState.get(BlazeJavaSyncData.class);
assertThat(javaSyncData).isNotNull();
List<BlazeContentEntry> contentEntries = javaSyncData.importResult.contentEntries;
assertThat(contentEntries).hasSize(1);
BlazeContentEntry contentEntry = contentEntries.get(0);
assertThat(contentEntry.contentRoot.getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
assertThat(contentEntry.sources).hasSize(1);
BlazeSourceDirectory sourceDir = contentEntry.sources.get(0);
assertThat(sourceDir.getPackagePrefix()).isEqualTo("com.google");
assertThat(sourceDir.getDirectory().getPath()).isEqualTo(this.workspaceRoot.fileForPath(new WorkspacePath("src/main/kotlin/com/google")).getPath());
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class BlazeJavaWorkspaceImporter method importWorkspace.
public BlazeJavaImportResult importWorkspace(BlazeContext context) {
WorkspaceBuilder workspaceBuilder = new WorkspaceBuilder();
for (TargetIdeInfo target : sourceFilter.sourceTargets) {
addTargetAsSource(workspaceBuilder, target, sourceFilter.targetToJavaSources.get(target.key));
}
SourceDirectoryCalculator sourceDirectoryCalculator = new SourceDirectoryCalculator();
ImmutableList<BlazeContentEntry> contentEntries = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, artifactLocationDecoder, importRoots, workspaceBuilder.sourceArtifacts, workspaceBuilder.javaPackageManifests);
int totalContentEntryCount = 0;
for (BlazeContentEntry contentEntry : contentEntries) {
totalContentEntryCount += contentEntry.sources.size();
}
context.output(PrintOutput.log("Java content entry count: " + totalContentEntryCount));
ImmutableMap<LibraryKey, BlazeJarLibrary> libraries = buildLibraries(workspaceBuilder, targetMap, sourceFilter.libraryTargets, sourceFilter.protoLibraries);
duplicateSourceDetector.reportDuplicates(context);
String sourceVersion = findSourceVersion(targetMap);
return new BlazeJavaImportResult(contentEntries, libraries, ImmutableList.copyOf(workspaceBuilder.buildOutputJars.stream().sorted().collect(Collectors.toList())), ImmutableSet.copyOf(workspaceBuilder.addedSourceFiles), sourceVersion);
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculator method calculateContentEntries.
public ImmutableList<BlazeContentEntry> calculateContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, ImportRoots importRoots, Collection<SourceArtifact> sources, Map<TargetKey, ArtifactLocation> javaPackageManifests) {
ManifestFilePackageReader manifestFilePackageReader = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("ReadPackageManifests", EventType.Other));
Map<TargetKey, Map<ArtifactLocation, String>> manifestMap = PackageManifestReader.getInstance().readPackageManifestFiles(project, childContext, artifactLocationDecoder, javaPackageManifests, packageReaderExecutorService);
return new ManifestFilePackageReader(manifestMap);
});
final List<JavaPackageReader> javaPackageReaders = Lists.newArrayList(manifestFilePackageReader, JavaSourcePackageReader.getInstance(), generatedFileJavaPackageReader);
Collection<SourceArtifact> nonGeneratedSources = filterGeneratedArtifacts(sources);
// Sort artifacts and excludes into their respective workspace paths
Multimap<WorkspacePath, SourceArtifact> sourcesUnderDirectoryRoot = sortArtifactLocationsByRootDirectory(context, importRoots, nonGeneratedSources);
List<BlazeContentEntry> result = Lists.newArrayList();
Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("CalculateSourceDirectories", EventType.Other));
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
File contentRoot = workspaceRoot.fileForPath(workspacePath);
ImmutableList<BlazeSourceDirectory> sourceDirectories = calculateSourceDirectoriesForContentRoot(context, workspaceRoot, artifactLocationDecoder, workspacePath, sourcesUnderDirectoryRoot.get(workspacePath), javaPackageReaders);
if (!sourceDirectories.isEmpty()) {
result.add(new BlazeContentEntry(contentRoot, sourceDirectories));
}
}
result.sort(Comparator.comparing(lhs -> lhs.contentRoot));
});
return ImmutableList.copyOf(result);
}
use of com.google.idea.blaze.java.sync.model.BlazeContentEntry in project intellij by bazelbuild.
the class SourceDirectoryCalculatorTest method testSourceRootUnderExcludedDirectoryIsIgnored.
@Test
public void testSourceRootUnderExcludedDirectoryIsIgnored() throws Exception {
mockInputStreamProvider.addFile("/root/included/src/com/google/Bla.java", "package com.google;\n public class Bla {}");
mockInputStreamProvider.addFile("/root/excluded/src/com/google/Foo.java", "package com.google;\n public class Foo {}");
List<SourceArtifact> sourceArtifacts = ImmutableList.of(SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("included/src/com/google/Bla.java").setIsSource(true)).build(), SourceArtifact.builder(TargetKey.forPlainTarget(LABEL)).setArtifactLocation(ArtifactLocation.builder().setRelativePath("excluded/src/com/google/Foo.java").setIsSource(true)).build());
ImmutableList<BlazeContentEntry> result = sourceDirectoryCalculator.calculateContentEntries(project, context, workspaceRoot, decoder, buildImportRoots(ImmutableList.of(new WorkspacePath("")), ImmutableList.of(new WorkspacePath("excluded"))), sourceArtifacts, NO_MANIFESTS);
assertThat(result).containsExactly(BlazeContentEntry.builder("/root").addSource(BlazeSourceDirectory.builder("/root").build()).addSource(BlazeSourceDirectory.builder("/root/included/src").build()).build());
issues.assertNoIssues();
}
Aggregations