forked from bazelbuild/intellij
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Preview fix #1
Open
colinrgodsey
wants to merge
16
commits into
base-v2023.03.21-aswb-stable
Choose a base branch
from
colin/previews_fix
base: base-v2023.03.21-aswb-stable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
502196f
[WIP] Fix compose preview
idanakav f728738
Try flipping on
pswaminathan fa76f26
Add more packages to workspace importer
pswaminathan 9d643c6
Fixup full resource resolution, and classpath resolution for preview …
colinrgodsey 5d56d57
Fix source code resolution for dependencies
colinrgodsey 7b83070
stash
colinrgodsey c8a906c
stash
colinrgodsey 443c77a
stash - targeted build
colinrgodsey 8285b12
[WIP] Fix compose preview
idanakav cc3f92c
Try flipping on
pswaminathan 2b17726
Add more packages to workspace importer
pswaminathan 9ba7e94
Fixup full resource resolution, and classpath resolution for preview …
colinrgodsey 42eab2c
Fix source code resolution for dependencies
colinrgodsey c5c930d
stash - targeted build
colinrgodsey 815c76d
[WIP] unblock generated resources
colinrgodsey 88c6b23
Merge remote-tracking branch 'origin/colin/previews_fix' into colin/p…
colinrgodsey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
aswb/src/com/google/idea/blaze/android/projectsystem/DefaultMavenArtifactLocator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.google.idea.blaze.android.projectsystem; | ||
|
||
import com.android.ide.common.repository.GradleCoordinate; | ||
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.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.project.Project; | ||
|
||
public class DefaultMavenArtifactLocator implements MavenArtifactLocator { | ||
colinrgodsey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, | ||
* but Android Studio requests specific artifacts needed for their preview | ||
* system, so we make our best attempt here to locate them using `maven_install` | ||
* patterned bazel artifacts. | ||
*/ | ||
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("[.-]", "_") | ||
); | ||
|
||
// 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)); | ||
return bestGuess; | ||
}); | ||
} | ||
|
||
public BuildSystemName buildSystem() { | ||
return BuildSystemName.Bazel; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? I wasn't actually sure. Someone in the Bazel Slack suggested it, but looking through the codebase, it didn't seem totally necessary. This seemed more of a "last resort".