Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.salesforce.bazel.eclipse.core.model.discovery.projects;

import static com.salesforce.bazel.sdk.command.querylight.BazelRuleAttribute.SRCS;
import static java.nio.file.Files.isRegularFile;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -116,7 +117,14 @@ public void addResource(GlobInfo globInfo) throws CoreException {
* @throws CoreException
*/
public void addResource(String resourceFileOrLabel, String resourceStripPrefix) throws CoreException {
addToResources(resources, resourceFileOrLabel, resourceStripPrefix);
var srcs = getFilegroupSrcs(resourceFileOrLabel);
if (srcs != null) {
for (String src : srcs) {
addResource(src, resourceStripPrefix);
}
} else {
addToResources(resources, resourceFileOrLabel, resourceStripPrefix);
}
}

/**
Expand Down Expand Up @@ -148,7 +156,14 @@ public void addSrc(GlobInfo globInfo, EntrySettings entrySettings) throws CoreEx
* @throws CoreException
*/
public void addSrc(String srcFileOrLabel, EntrySettings entrySettings) throws CoreException {
addToSrc(srcs, srcFileOrLabel, entrySettings);
var srcs = getFilegroupSrcs(srcFileOrLabel);
if (srcs != null) {
for (String src : srcs) {
addSrc(src, entrySettings);
}
} else {
addToSrc(this.srcs, srcFileOrLabel, entrySettings);
}
}

public void addTestJar(String jarFileOrLabel, String srcJarFileOrLabel) throws CoreException {
Expand All @@ -174,15 +189,29 @@ public void addTestResource(GlobInfo globInfo) throws CoreException {
* @throws CoreException
*/
public void addTestResource(String resourceFileOrLabel, String resourceStripPrefix) throws CoreException {
addToResources(testResources, resourceFileOrLabel, resourceStripPrefix);
var srcs = getFilegroupSrcs(resourceFileOrLabel);
if (srcs != null) {
for (String src : srcs) {
addResource(src, resourceStripPrefix);
}
} else {
addToResources(testResources, resourceFileOrLabel, resourceStripPrefix);
}
}

public void addTestSrc(GlobInfo globInfo, EntrySettings entrySettings) {
addToSrc(testSrcs, globInfo, entrySettings);
}

public void addTestSrc(String srcFileOrLabel, EntrySettings entrySettings) throws CoreException {
addToSrc(testSrcs, srcFileOrLabel, entrySettings);
var srcs = getFilegroupSrcs(srcFileOrLabel);
if (srcs != null) {
for (String src : srcs) {
addTestSrc(src, entrySettings);
}
} else {
addToSrc(testSrcs, srcFileOrLabel, entrySettings);
}
}

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

private List<String> getFilegroupSrcs(String srcFileOrLabel) throws CoreException {
var label = relativizeLabelToPackageIfPossible(srcFileOrLabel);
if (shouldTreatAsLabel(label)) {
var target = bazelPackage.getBazelTarget(label);
if ((target != null) && "filegroup".equals(target.getRuleClass())) {
var attributes = target.getRuleAttributes();
return attributes.getStringList(SRCS);
}
}
return null;
}

public JavaArchiveInfo getJarInfo() {
return requireNonNull(jarInfo, "Jar info not computed. Did you call analyzeProjectRecommendations?");
}
Expand Down
Loading