Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrgodsey committed Apr 24, 2023
1 parent 2778dc2 commit 0ccce4d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package com.google.idea.blaze.android.projectsystem;

import static java.lang.Math.max;

import com.android.annotations.concurrency.UiThread;
import com.android.tools.idea.projectsystem.ProjectSystemBuildManager;
import com.google.idea.blaze.base.build.BlazeBuildListener;
Expand All @@ -28,9 +26,12 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import org.jetbrains.annotations.NotNull;

import static java.lang.Math.max;

/** Blaze implementation of {@link ProjectSystemBuildManager} */
public class BlazeProjectSystemBuildManager implements ProjectSystemBuildManager {
Expand All @@ -51,8 +52,12 @@ public void compileProject() {
@Override
public void compileFilesAndDependencies(Collection<? extends VirtualFile> files) {
// TODO(b/191937319): Implement incremental builds for individual files
// Just compile the entire project for now.
// Do an incremental sync for now so that previews update appropriately
//BlazeSyncManager.getInstance(project).workingSetSync("Compile files and dependencies");
// TODO: use partialSync with targets verived from `files` (see logic in
// BlazeSyncParams.sourceFilesToSync
compileProject();
//project.putUserData(PROJECT_LAST_BUILD_TIMESTAMP_KEY, System.currentTimeMillis());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.google.idea.blaze.android.projectsystem;

import com.android.ide.common.repository.GradleCoordinate;
import com.google.idea.blaze.base.ideinfo.TargetKey;
import com.google.idea.blaze.base.ideinfo.TargetMap;
import com.google.idea.blaze.base.model.primitives.Label;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager;
import com.google.idea.blaze.base.targetmaps.TransitiveDependencyMap;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;


public class DefaultMavenArtifactLocator implements MavenArtifactLocator {
private static final Logger log = Logger.getInstance(DefaultMavenArtifactLocator.class);
private static final String mavenCoordinateTagPrefix = "maven_coordinates=";

/**
* Locate an artifact label by maven coordinates. This is somewhat brittle,
Expand All @@ -24,19 +22,34 @@ public Label labelFor(Project project, GradleCoordinate coordinate) {
TargetMap targetMap = BlazeProjectDataManager.getInstance(project)
.getBlazeProjectData().getTargetMap();

String desiredCoord = mavenCoordinateTagPrefix + coordinate.getGroupId() +
":" + coordinate.getArtifactId() + ":";
String labelSuffix = String.format(":%s_%s",
coordinate.getGroupId().replaceAll("[.-]", "_"),
coordinate.getArtifactId().replaceAll("[.-]", "_")
);

return TransitiveDependencyMap.getDependenciesStream(targetMap)
.filter(x -> x.getLabel().toString().endsWith(labelSuffix))
.map(TargetKey::getLabel).findFirst()
.orElseGet(() -> {
// Debug code to list all targets. Some go missing sometimes...
/*String debugString = targetMap.map().keySet().stream()
.sorted(Comparator.comparing(TargetKey::toString))
.map(x -> x.getLabel().toString())
.collect(Collectors.joining(", "));
System.out.println(debugString);*/

return targetMap.targets().stream().filter(target -> {
for (String tag : target.getTags()) {
if (tag.startsWith(desiredCoord)) {
return true;
}
}
return false;
})
.map(x -> x.getKey().getLabel())
.findFirst().orElseGet(() -> {
Label bestGuess = Label.create("@maven//" + labelSuffix);
log.warn(String.format(
"Could not find exact label for %s, returning best guess of %s",
coordinate, bestGuess));
"Could not find exact label for %s, returning best guess of %s",
coordinate, bestGuess));
return bestGuess;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public class RenderJarClassFileFinder implements ClassFileFinder {
// true if the current module is the .workspace Module
private final boolean isWorkspaceModule;

private List<File> moduleLibraries = Collections.emptyList();
private Map<String, File> packageJarHint = new HashMap();

public RenderJarClassFileFinder(Module module) {
Expand Down Expand Up @@ -212,7 +211,6 @@ public VirtualFile findClass(String fqcn) {

public synchronized void clearCache() {
log.warn("clearing cache");
moduleLibraries = new BlazeClassJarProvider(this.project).getModuleExternalLibraries(module);
packageJarHint = new HashMap();
}

Expand Down Expand Up @@ -288,7 +286,8 @@ private VirtualFile getClassFromRenderResolveJar(

@Nullable
private VirtualFile searchForFQCNInModule(String fqcn) {
VirtualFile psiFile = ApplicationManager.getApplication().runReadAction((Computable<VirtualFile>) () -> {
// keeps throwing java.lang.Throwable: Slow operations are prohibited on EDT. See SlowOperations.assertSlowOperationsAreAllowed javadoc
/*VirtualFile psiFile = ApplicationManager.getApplication().runReadAction((Computable<VirtualFile>) () -> {
try {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
PsiClass baseClass =
Expand All @@ -308,7 +307,7 @@ private VirtualFile searchForFQCNInModule(String fqcn) {
if (psiFile != null) {
return psiFile;
}
}*/

String pkg = null;
int pkgIdx = fqcn.lastIndexOf('.');
Expand All @@ -325,6 +324,8 @@ private VirtualFile searchForFQCNInModule(String fqcn) {
}
}
}
List<File> moduleLibraries = new BlazeClassJarProvider(this.project).getModuleExternalLibraries(module);

for (File jar : moduleLibraries) {
VirtualFile jarVF = VirtualFileSystemProvider.getInstance().getSystem().findFileByIoFile(jar);
if (jarVF == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,17 @@ public List<File> getModuleExternalLibraries(Module module) {
}

if (useRenderJarForExternalLibraries.getValue()) {
return TargetToBinaryMap.getInstance(project).getSourceBinaryTargets().stream()
List<File> renderJarLibraries = TargetToBinaryMap.getInstance(project).getSourceBinaryTargets().stream()
.filter(targetMap::contains)
.map(
(binaryTarget) ->
RenderJarCache.getInstance(project)
.getCachedJarForBinaryTarget(decoder, targetMap.get(binaryTarget)))
.filter(Objects::nonNull)
.collect(toImmutableList());
if (!renderJarLibraries.isEmpty()) {
return renderJarLibraries;
}
}

AndroidResourceModuleRegistry registry = AndroidResourceModuleRegistry.getInstance(project);
Expand Down Expand Up @@ -196,14 +199,9 @@ public static boolean testIsClassFileOutOfDate(
}

List<File> getAllExternalLibraries(TargetMap targetMap, ArtifactLocationDecoder decoder) {
return TransitiveDependencyMap.getDependenciesStream(targetMap)
.map(x -> {
TargetIdeInfo target = targetMap.get(x);
if (target != null) {
return target.getJavaIdeInfo();
}
return null;
}).filter(Objects::nonNull)
return targetMap.targets().stream()
.map(x -> x.getJavaIdeInfo())
.filter(Objects::nonNull)
.flatMap(x -> x.getJars().stream())
.map(LibraryArtifact::getClassJar).filter(Objects::nonNull)
.map(x -> OutputArtifactResolver.resolve(project, decoder, x))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,6 @@ public static Stream<TargetKey> getTransitiveDependenciesStream(
return Streams.stream(new TransitiveDependencyIterator(keys, targetMap));
}

/**
* Returns a stream which traverses the transitive dependencies of the given collection of Blaze
* targets, including the top-level targets themselves.
*/
public static Stream<TargetKey> getDependenciesStream(TargetMap targetMap) {
List<TargetKey> keys = targetMap.targets().stream()
.map(x -> x.getKey()).collect(Collectors.toList());
return Stream.concat(
keys.stream(),
getTransitiveDependenciesStream(keys, targetMap)
).distinct();
}

/**
* An iterator which performs a breadth-first traversal over the transitive dependencies of a
* collection of Blaze targets. Targets in the top-level collection will only be included in the
Expand Down

0 comments on commit 0ccce4d

Please sign in to comment.