Skip to content

Commit 858f645

Browse files
committed
Bazel Eclipse doesn't recognize filegroup
1 parent 5aef753 commit 858f645

File tree

1 file changed

+45
-4
lines changed
  • bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects

1 file changed

+45
-4
lines changed

bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/projects/JavaProjectInfo.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.salesforce.bazel.eclipse.core.model.discovery.projects;
22

3+
import static com.salesforce.bazel.sdk.command.querylight.BazelRuleAttribute.SRCS;
34
import static java.nio.file.Files.isRegularFile;
45
import static java.util.Objects.requireNonNull;
56
import static java.util.stream.Collectors.toList;
@@ -116,7 +117,14 @@ public void addResource(GlobInfo globInfo) throws CoreException {
116117
* @throws CoreException
117118
*/
118119
public void addResource(String resourceFileOrLabel, String resourceStripPrefix) throws CoreException {
119-
addToResources(resources, resourceFileOrLabel, resourceStripPrefix);
120+
var srcs = getFilegroupSrcs(resourceFileOrLabel);
121+
if (srcs != null) {
122+
for (String src : srcs) {
123+
addResource(src, resourceStripPrefix);
124+
}
125+
} else {
126+
addToResources(resources, resourceFileOrLabel, resourceStripPrefix);
127+
}
120128
}
121129

122130
/**
@@ -148,7 +156,14 @@ public void addSrc(GlobInfo globInfo, EntrySettings entrySettings) throws CoreEx
148156
* @throws CoreException
149157
*/
150158
public void addSrc(String srcFileOrLabel, EntrySettings entrySettings) throws CoreException {
151-
addToSrc(srcs, srcFileOrLabel, entrySettings);
159+
var srcs = getFilegroupSrcs(srcFileOrLabel);
160+
if (srcs != null) {
161+
for (String src : srcs) {
162+
addSrc(src, entrySettings);
163+
}
164+
} else {
165+
addToSrc(this.srcs, srcFileOrLabel, entrySettings);
166+
}
152167
}
153168

154169
public void addTestJar(String jarFileOrLabel, String srcJarFileOrLabel) throws CoreException {
@@ -174,15 +189,29 @@ public void addTestResource(GlobInfo globInfo) throws CoreException {
174189
* @throws CoreException
175190
*/
176191
public void addTestResource(String resourceFileOrLabel, String resourceStripPrefix) throws CoreException {
177-
addToResources(testResources, resourceFileOrLabel, resourceStripPrefix);
192+
var srcs = getFilegroupSrcs(resourceFileOrLabel);
193+
if (srcs != null) {
194+
for (String src : srcs) {
195+
addResource(src, resourceStripPrefix);
196+
}
197+
} else {
198+
addToResources(testResources, resourceFileOrLabel, resourceStripPrefix);
199+
}
178200
}
179201

180202
public void addTestSrc(GlobInfo globInfo, EntrySettings entrySettings) {
181203
addToSrc(testSrcs, globInfo, entrySettings);
182204
}
183205

184206
public void addTestSrc(String srcFileOrLabel, EntrySettings entrySettings) throws CoreException {
185-
addToSrc(testSrcs, srcFileOrLabel, entrySettings);
207+
var srcs = getFilegroupSrcs(srcFileOrLabel);
208+
if (srcs != null) {
209+
for (String src : srcs) {
210+
addTestSrc(src, entrySettings);
211+
}
212+
} else {
213+
addToSrc(testSrcs, srcFileOrLabel, entrySettings);
214+
}
186215
}
187216

188217
private void addToResources(Collection<Entry> resources, GlobInfo globInfo) {
@@ -257,6 +286,18 @@ public BazelPackage getBazelPackage() {
257286
return bazelPackage;
258287
}
259288

289+
private List<String> getFilegroupSrcs(String srcFileOrLabel) throws CoreException {
290+
var label = relativizeLabelToPackageIfPossible(srcFileOrLabel);
291+
if (shouldTreatAsLabel(label)) {
292+
var target = bazelPackage.getBazelTarget(label);
293+
if ((target != null) && "filegroup".equals(target.getRuleClass())) {
294+
var attributes = target.getRuleAttributes();
295+
return attributes.getStringList(SRCS);
296+
}
297+
}
298+
return null;
299+
}
300+
260301
public JavaArchiveInfo getJarInfo() {
261302
return requireNonNull(jarInfo, "Jar info not computed. Did you call analyzeProjectRecommendations?");
262303
}

0 commit comments

Comments
 (0)