Skip to content

Commit

Permalink
First rough support for srcjars
Browse files Browse the repository at this point in the history
  • Loading branch information
guw committed Oct 23, 2023
1 parent 21a82f3 commit fc5b480
Show file tree
Hide file tree
Showing 11 changed files with 569 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,28 @@ public BazelWorkspace getBazelWorkspace() {
return bazelWorkspace;
}

/**
* Returns the folder where source files links to generated sources will be created.
* <p>
* This can be used whenever there is a need to bring generated sources into a project (eg., <code>.srcjar</code> ).
* It is expected that this folder is used as a parent. It should only contain symlinks to folders with the
* generated sources. Do not copy generated sources in here.
* </p>
*
* @param project
* @return the folder to use for generated sources
*/
public IFolder getGeneratedSourcesFolder(BazelProject project) {
return project.getProject().getFolder("generated-srcs");
}

/**
* @see #getGeneratedSourcesFolder(BazelProject)
*/
public IFolder getGeneratedSourcesFolderForTests(BazelProject project) {
return project.getProject().getFolder("generated-test-srcs");
}

/**
* @see #getVirtualSourceFolder(BazelProject)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ BazelBinary getBazelBinary() throws CoreException {
return getInfo().getBazelBinary();
}

/**
* {@return absolute file system location to the <code>bazel-bin</code> symlink target}
*
* @throws CoreException
* if the workspace does not exist
*/
public IPath getBazelBinLocation() throws CoreException {
return getInfo().getBazelBin();
}

/**
* Returns a Bazel package for the given label.
* <p>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ protected List<BazelProject> doProvisionProjects(Collection<BazelTarget> targets
.collect(joining(", ")))));
}

// configure links
linkGeneratedSourcesIntoProject(project, javaInfo, monitor.split(1));

// configure classpath
configureRawClasspath(project, javaInfo, monitor.split(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ protected List<BazelProject> doProvisionProjects(Collection<BazelTarget> targets
.collect(joining(", ")))));
}

// configure links
linkGeneratedSourcesIntoProject(project, javaInfo, monitor.split(1));

// configure classpath
configureRawClasspath(project, javaInfo, monitor.split(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ protected BazelProject provisionJavaLibraryProject(BazelTarget target, SubMonito

// configure links
linkSourcesIntoProject(project, javaInfo, monitor.split(1));
linkGeneratedSourcesIntoProject(project, javaInfo, monitor.split(1));

// configure classpath
configureRawClasspath(project, javaInfo, monitor.split(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,13 @@ private void addToSrc(Collection<Entry> srcs, String srcFileOrLabel) throws Core
public IStatus analyzeProjectRecommendations(IProgressMonitor monitor) throws CoreException {
var result = new MultiStatus(JavaProjectInfo.class, 0, "Java Analysis Result");

sourceInfo = new JavaSourceInfo(this.srcs, bazelPackage.getLocation());
sourceInfo = new JavaSourceInfo(this.srcs, bazelPackage);
sourceInfo.analyzeSourceDirectories(result);

resourceInfo = new JavaResourceInfo(resources, bazelPackage);
resourceInfo.analyzeResourceDirectories(result);

testSourceInfo = new JavaSourceInfo(this.testSrcs, bazelPackage.getLocation(), sourceInfo);
testSourceInfo = new JavaSourceInfo(this.testSrcs, bazelPackage, sourceInfo);
testSourceInfo.analyzeSourceDirectories(result);

testResourceInfo = new JavaResourceInfo(testResources, bazelPackage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.eclipse.core.runtime.IPath;

/**
* A source entry points to exactly one <code>.java</code> source file. It contains additional logic for extracting
* the package path from the location.
* A source entry points to exactly one <code>.java</code> source file. It contains additional logic for extracting the
* package path from the location.
*/
public class JavaSourceEntry implements Entry {

private static boolean endsWith(IPath path, IPath lastSegments) {
static boolean endsWith(IPath path, IPath lastSegments) {
if (path.segmentCount() < lastSegments.segmentCount()) {
return false;
}
Expand Down Expand Up @@ -60,6 +60,13 @@ public boolean equals(Object obj) {
&& Objects.equals(relativePath, other.relativePath);
}

/**
* @return the Bazel package location this entry is contained in
*/
public IPath getBazelPackageLocation() {
return bazelPackageLocation;
}

/**
* {@return absolute location of of the container of this path entry}
*/
Expand Down Expand Up @@ -93,8 +100,8 @@ public IPath getPathParent() {
}

/**
* @return first few segments of {@link #getPathParent()} which could be the source directory, or
* <code>null</code> if unlikely
* @return first few segments of {@link #getPathParent()} (relative to {@link #getBazelPackageLocation()}) which
* could be the source directory, or <code>null</code> if unlikely
*/
public IPath getPotentialSourceDirectoryRoot() {
var detectedPackagePath = getDetectedPackagePath();
Expand All @@ -113,6 +120,14 @@ public int hashCode() {
return Objects.hash(bazelPackageLocation, relativePath);
}

/**
* {@return <code>true</code> if the entry is generated, i.e. located outside a Bazel package, <code>false</code>
* otherwise}
*/
public boolean isExternalOrGenerated() {
return false;
}

@Override
public String toString() {
return relativePath + " (relativePathParent=" + relativePathParent + ", bazelPackageLocation="
Expand Down
Loading

0 comments on commit fc5b480

Please sign in to comment.