From f786a3620bb574413e184508a98bb4a57262d06d Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Tue, 26 Nov 2024 19:12:41 +0100 Subject: [PATCH] Improve readability, reduce complexity --- .../classpath/BazelClasspathContainer.java | 33 +++---- .../core/classpath/BazelClasspathManager.java | 10 +-- .../core/classpath/ClasspathHolder.java | 71 --------------- .../classpath/CompileAndRuntimeClasspath.java | 45 ++++++++++ .../core/edits/AddDependenciesJob.java | 10 ++- .../discovery/BaseProvisioningStrategy.java | 87 ++++++++++--------- ...dVisibilityDrivenProvisioningStrategy.java | 8 +- .../discovery/JavaAspectsClasspathInfo.java | 48 +++++----- ...ProjectPerPackageProvisioningStrategy.java | 15 ++-- .../ProjectPerTargetProvisioningStrategy.java | 8 +- .../discovery/TargetProvisioningStrategy.java | 4 +- .../discovery/WorkspaceClasspathStrategy.java | 10 +-- 12 files changed, 172 insertions(+), 177 deletions(-) delete mode 100644 bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/ClasspathHolder.java create mode 100644 bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/CompileAndRuntimeClasspath.java diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathContainer.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathContainer.java index b983bde5..35e16de1 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathContainer.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathContainer.java @@ -52,16 +52,21 @@ */ public class BazelClasspathContainer implements IClasspathContainer, Serializable { - private static final long serialVersionUID = 390898179243551622L; + private static final long serialVersionUID = 1010694752435706159L; private final IPath path; private final IClasspathEntry[] classpath; - private final IClasspathEntry[] transitiveClasspath; + private final IClasspathEntry[] additionalRuntimeClasspath; - public BazelClasspathContainer(IPath path, IClasspathEntry[] classpath, IClasspathEntry[] transitiveClasspath) { + public BazelClasspathContainer(IPath path, IClasspathEntry[] classpath, + IClasspathEntry[] additionalRuntimeClasspath) { this.path = path; this.classpath = requireNonNull(classpath); - this.transitiveClasspath = requireNonNull(transitiveClasspath); + this.additionalRuntimeClasspath = requireNonNull(additionalRuntimeClasspath); + } + + public IClasspathEntry[] getAdditionalRuntimeClasspathEntries() { + return additionalRuntimeClasspath; } @Override @@ -75,11 +80,16 @@ public String getDescription() { } public IClasspathEntry[] getFullClasspath() { - if (transitiveClasspath.length == 0) { + if (additionalRuntimeClasspath.length == 0) { return classpath; } - var fullClasspath = Arrays.copyOf(classpath, classpath.length + transitiveClasspath.length); - System.arraycopy(transitiveClasspath, 0, fullClasspath, classpath.length, transitiveClasspath.length); + var fullClasspath = Arrays.copyOf(classpath, classpath.length + additionalRuntimeClasspath.length); + System.arraycopy( + additionalRuntimeClasspath, + 0, + fullClasspath, + classpath.length, + additionalRuntimeClasspath.length); return fullClasspath; } @@ -92,13 +102,4 @@ public int getKind() { public IPath getPath() { return path; } - - /** - * A array of transitive classpath entries. - * - * @return - */ - public IClasspathEntry[] getTransitiveEntries() { - return transitiveClasspath; - } } diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathManager.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathManager.java index aa3c0e7d..f60cf35a 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathManager.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/BazelClasspathManager.java @@ -239,7 +239,7 @@ TargetProvisioningStrategy getTargetProvisioningStrategy(BazelWorkspace bazelWor * @param monitor * @throws CoreException */ - public void patchClasspathContainer(BazelProject bazelProject, ClasspathHolder classpath, IProgressMonitor progress) + public void patchClasspathContainer(BazelProject bazelProject, CompileAndRuntimeClasspath classpath, IProgressMonitor progress) throws CoreException { var monitor = SubMonitor.convert(progress); try { @@ -301,7 +301,7 @@ public void persistAttachedSourcesAndJavadoc(IJavaProject project, IClasspathCon DEFAULT_CLASSPATH, monitor.split(1, SUPPRESS_ALL_LABELS)); entries = configureClasspathWithSourceAttachments( - classpaths.get(bazelProject).compile(), + classpaths.get(bazelProject).compileEntries(), null /* no props */, monitor); for (IClasspathEntry entry : entries) { @@ -340,19 +340,19 @@ public void persistAttachedSourcesAndJavadoc(IJavaProject project, IClasspathCon } } - void saveAndSetContainer(IJavaProject javaProject, ClasspathHolder classpath, IProgressMonitor monitor) + void saveAndSetContainer(IJavaProject javaProject, CompileAndRuntimeClasspath classpath, IProgressMonitor monitor) throws CoreException, JavaModelException { var containerEntry = getBazelContainerEntry(javaProject); var path = containerEntry != null ? containerEntry.getPath() : new Path(BazelCoreSharedContstants.CLASSPATH_CONTAINER_ID); var sourceAttachmentProperties = getSourceAttachmentProperties(javaProject.getProject()); - var transativeClasspath = classpath.transitive().stream().map(ClasspathEntry::build).collect(toList()); + var transativeClasspath = classpath.additionalRuntimeEntries().stream().map(ClasspathEntry::build).collect(toList()); var container = new BazelClasspathContainer( path, configureClasspathWithSourceAttachments( - classpath.compile(), + classpath.compileEntries(), sourceAttachmentProperties, monitor.slice(1)), transativeClasspath.toArray(new IClasspathEntry[transativeClasspath.size()])); diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/ClasspathHolder.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/ClasspathHolder.java deleted file mode 100644 index 61cadf94..00000000 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/ClasspathHolder.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * Copyright (c) 2024 Salesforce and others. - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Salesforce - adapted from M2E, JDT or other Eclipse project - */ -package com.salesforce.bazel.eclipse.core.classpath; - -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import org.eclipse.core.runtime.IPath; - -import com.salesforce.bazel.eclipse.core.model.discovery.classpath.ClasspathEntry; - -/** - * Represents a targets classpath as two parts, compile being the classpath entries that are loaded into the project - * model, and transtative as classpaths that are part of the targets runtime, but are not to be loaded in the project - * model. - */ -public record ClasspathHolder(Collection compile, Collection transitive) { - - public static class ClasspathHolderBuilder { - // Preserve classpath order. Add leaf level dependencies first and work the way up. This - // prevents conflicts when a JAR repackages it's dependencies. In such a case we prefer to - // resolve symbols from the original JAR rather than the repackaged version. - // Using accessOrdered LinkedHashMap because jars that are present in `workspaceBuilder.jdeps` - // and in `workspaceBuilder.directDeps`, we want to treat it as a directDep - private final Map compileEntries = - new LinkedHashMap<>(/* initialCapacity= */ 32, /* loadFactor= */ 0.75f, /* accessOrder= */ true); - private final Map transitiveEntries = - new LinkedHashMap<>(/* initialCapacity= */ 32, /* loadFactor= */ 0.75f, /* accessOrder= */ true); - private boolean hasUnloadedEntries = false; - - private final boolean partialClasspathEnabled; - - public ClasspathHolderBuilder(boolean partialClasspathEnabled) { - this.partialClasspathEnabled = partialClasspathEnabled; - } - - public ClasspathHolder build() { - return new ClasspathHolder( - compileEntries.values(), - hasUnloadedEntries ? transitiveEntries.values() : Collections.emptyList()); - } - - public void put(IPath path, ClasspathEntry entry) { - compileEntries.put(path, entry); - } - - public void putIfAbsent(IPath path, ClasspathEntry entry) { - compileEntries.putIfAbsent(path, entry); - } - - public void putUnloadedIfAbsent(IPath path, ClasspathEntry entry) { - if (!compileEntries.containsKey(path)) { - transitiveEntries.putIfAbsent(path, entry); - hasUnloadedEntries = true; - } - } - } -} diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/CompileAndRuntimeClasspath.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/CompileAndRuntimeClasspath.java new file mode 100644 index 00000000..ad3a7458 --- /dev/null +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/classpath/CompileAndRuntimeClasspath.java @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 2024 Salesforce and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Salesforce - adapted from M2E, JDT or other Eclipse project + */ +package com.salesforce.bazel.eclipse.core.classpath; + +import java.util.Collection; +import java.util.LinkedHashSet; + +import com.salesforce.bazel.eclipse.core.model.discovery.classpath.ClasspathEntry; + +/** + * Represents a classpath as two parts, compile being the classpath entries that are loaded into the project model, and + * transitive as classpath that are part of the transitive set for runtime only. + */ +public record CompileAndRuntimeClasspath( + Collection compileEntries, + Collection additionalRuntimeEntries) { + + public static class Builder { + private final LinkedHashSet compileEntries = new LinkedHashSet<>(); + private final LinkedHashSet additionalRuntimeEntries = new LinkedHashSet<>(); + + public boolean addCompileEntry(ClasspathEntry entry) { + return compileEntries.add(entry); + } + + public boolean addRuntimeEntry(ClasspathEntry entry) { + return additionalRuntimeEntries.add(entry); + } + + public CompileAndRuntimeClasspath build() { + return new CompileAndRuntimeClasspath(compileEntries, additionalRuntimeEntries); + } + } +} diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java index 633ca728..1d98f6d7 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/edits/AddDependenciesJob.java @@ -22,7 +22,7 @@ import org.eclipse.core.runtime.jobs.Job; import com.google.idea.blaze.base.model.primitives.Label; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.classpath.InitializeOrRefreshClasspathJob; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; @@ -172,11 +172,13 @@ public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreExcepti } if (modified) { - var transitive = Arrays.stream(container.getTransitiveEntries()) + var additionalRuntimeEntries = Arrays.stream(container.getAdditionalRuntimeClasspathEntries()) .map(ClasspathEntry::fromExisting) .collect(toList()); - classpathManager - .patchClasspathContainer(bazelProject, new ClasspathHolder(classpath, transitive), monitor); + classpathManager.patchClasspathContainer( + bazelProject, + new CompileAndRuntimeClasspath(classpath, additionalRuntimeEntries), + monitor); } return Status.OK_STATUS; } diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java index 6bae00f8..e27619bd 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BaseProvisioningStrategy.java @@ -624,46 +624,6 @@ protected void analyzeProjectInfo(BazelProject project, JavaProjectInfo javaInfo } } - /** - * Calculates the java_library and java_imports for the provided targets, limited by the depth - * - * @param workspace - * the bazel workspace - * @param targetsToBuild - * a list of targets as part of the build to query their dependencies - * @param dependencyDepth - * the depth in the dependency graph to traverse and include in the result - * @return a set of java_library and java_imports, or null, if partial classpath is disabled - * @throws CoreException - */ - protected final Set calculateWorkspaceDependencies(BazelWorkspace workspace, - List targetsToBuild) throws CoreException { - - var classpathDepth = getClasspathDepthValue(workspace); - if (classpathDepth <= 0) { - return null; - } - if (classpathDepth == 1) { - return Collections.emptySet(); - } - var targetLabels = targetsToBuild.stream().map(BazelLabel::toString).collect(joining(" + ")); - return workspace.getCommandExecutor() - .runQueryWithoutLock( - new BazelQueryForLabelsCommand( - workspace.getLocation().toPath(), - format( - "kind(java_library, deps(%s, %d)) + kind(java_import, deps(%s, %d))", - targetLabels, - classpathDepth, - targetLabels, - classpathDepth), - true, - format("Querying for depdendencies for projects: %s", targetLabels))) - .stream() - .map(BazelLabel::new) - .collect(toSet()); - } - /** * Collects base Java information for a given project and the targets it represents. *

@@ -1734,6 +1694,53 @@ public List provisionProjectsForSelectedTargets(Collection + * The outcome of this method is intended to be used in + * {@link #computeClasspaths(Collection, BazelWorkspace, com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope, IProgressMonitor)} + * implementation for filtering/reducing the compile classpath. + *

+ * A depth of 0 will return null, which indicates unlimited/no filtering. A depth of 1 will return an + * empty collection, which indicates "direct dependencies only" for compilation. + *

+ * + * @param workspace + * the bazel workspace + * @param targetsToBuild + * a list of targets as part of the build to query their dependencies + * @return a set of java_library and java_imports, or null, if partial classpath is disabled + * @throws CoreException + */ + protected final Set queryForDepsWithClasspathDepth(BazelWorkspace workspace, + List targetsToBuild) throws CoreException { + + var classpathDepth = getClasspathDepthValue(workspace); + if (classpathDepth <= 0) { + return null; + } + if (classpathDepth == 1) { + return Collections.emptySet(); + } + var targetLabels = targetsToBuild.stream().map(BazelLabel::toString).collect(joining(" + ")); + return workspace.getCommandExecutor() + .runQueryWithoutLock( + new BazelQueryForLabelsCommand( + workspace.getLocation().toPath(), + format( + "kind(java_library, deps(%s, %d)) + kind(java_import, deps(%s, %d))", + targetLabels, + classpathDepth, + targetLabels, + classpathDepth), + true, + format("Querying for depdendencies for projects: %s", targetLabels))) + .stream() + .map(BazelLabel::new) + .collect(toSet()); + } + private java.nio.file.Path resolveJavaHome(BazelWorkspace workspace, String javaHome, String description) throws CoreException { var resolvedJavaHomePath = java.nio.file.Path.of(javaHome); diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BuildFileAndVisibilityDrivenProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BuildFileAndVisibilityDrivenProvisioningStrategy.java index c9338e45..bebc82ce 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BuildFileAndVisibilityDrivenProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/BuildFileAndVisibilityDrivenProvisioningStrategy.java @@ -37,7 +37,7 @@ import com.google.idea.blaze.base.model.primitives.WildcardTargetPattern; import com.google.idea.blaze.base.model.primitives.WorkspacePath; import com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.model.BazelPackage; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; @@ -195,7 +195,7 @@ public boolean isAllowedDependencyPath(BazelPackage fromPackage, BazelPackage to new TargetDiscoveryAndProvisioningExtensionLookup(); @Override - public Map computeClasspaths(Collection bazelProjects, + public Map computeClasspaths(Collection bazelProjects, BazelWorkspace workspace, BazelClasspathScope scope, IProgressMonitor progress) throws CoreException { LOG.debug("Computing classpath for projects: {}", bazelProjects); try { @@ -239,7 +239,7 @@ public Map computeClasspaths(Collection classpathsByProject = new HashMap<>(); + Map classpathsByProject = new HashMap<>(); for (BazelProject bazelProject : bazelProjects) { monitor.subTask("Analyzing: " + bazelProject); monitor.checkCanceled(); @@ -367,7 +367,7 @@ public Map computeClasspaths(Collection runtimeDependencyIncludes; + final Set runtimeDependencyIncludes; public JavaAspectsClasspathInfo(JavaAspectsInfo aspectsInfo, BazelWorkspace bazelWorkspace, Set runtimeDependencyIncludes, BazelProject bazelProject) throws CoreException { @@ -313,10 +313,10 @@ public IStatus addTarget(BazelTarget bazelTarget) throws CoreException { * @return the computed classpath * @throws CoreException */ - public ClasspathHolder compute() throws CoreException { + public CompileAndRuntimeClasspath compute() throws CoreException { // the code below is copied and adapted from BlazeJavaWorkspaceImporter - var classpathBuilder = new ClasspathHolderBuilder(runtimeDependencyIncludes != null); + var classpathBuilder = new Builder(); // Collect jars from jdep references for (JdepsDependency jdepsDependency : jdepsCompileJars) { @@ -342,11 +342,11 @@ public ClasspathHolder compute() throws CoreException { PATTERN_EVERYTHING, IAccessRule.K_DISCOURAGED | IAccessRule.IGNORE_IF_BETTER)); - // there might be an explicit entry, which we will never want to override! - classpathBuilder.putIfAbsent(entry.getPath(), entry); + // add implicit dependencies as compile entries so ECJ can process them and users get access errors instead of compile errors + classpathBuilder.addCompileEntry(entry); } else { entry.getAccessRules().add(new AccessRule(PATTERN_EVERYTHING, IAccessRule.K_ACCESSIBLE)); - classpathBuilder.put(entry.getPath(), entry); + classpathBuilder.addCompileEntry(entry); } } else if (LOG.isDebugEnabled()) { LOG.warn("Unable to resolve compile jar: {}", jdepsDependency); @@ -366,7 +366,7 @@ public ClasspathHolder compute() throws CoreException { continue; } jarEntry.setExported(true); // source jars should be exported - classpathBuilder.putIfAbsent(jarEntry.getPath(), jarEntry); + classpathBuilder.addCompileEntry(jarEntry); } // Collect jars referenced by direct deps @@ -374,7 +374,7 @@ public ClasspathHolder compute() throws CoreException { var entries = resolveDependency(targetKey); for (ClasspathEntry entry : entries) { if (validateEntry(entry)) { - classpathBuilder.putIfAbsent(entry.getPath(), entry); + classpathBuilder.addCompileEntry(entry); } } } @@ -382,7 +382,7 @@ public ClasspathHolder compute() throws CoreException { // Collect jars referenced by runtime deps for (TargetKey targetKey : runtimeDeps) { var entries = resolveDependency(targetKey); - var runtimeDependencyAvailable = includeRuntimeDependencyAsCompileDependency(targetKey); + var addRuntimeDependencyAsCompileEntry = includeRuntimeDependencyAsProjectCompileDependency(targetKey); for (ClasspathEntry entry : entries) { if (!validateEntry(entry)) { @@ -396,10 +396,10 @@ public ClasspathHolder compute() throws CoreException { new AccessRule( PATTERN_EVERYTHING, IAccessRule.K_DISCOURAGED | IAccessRule.IGNORE_IF_BETTER)); - if (runtimeDependencyAvailable) { - classpathBuilder.putIfAbsent(entry.getPath(), entry); + if (addRuntimeDependencyAsCompileEntry) { + classpathBuilder.addCompileEntry(entry); } else { - classpathBuilder.putUnloadedIfAbsent(entry.getPath(), entry); + classpathBuilder.addRuntimeEntry(entry); } } } @@ -480,16 +480,24 @@ IWorkspaceRoot getEclipseWorkspaceRoot() { } /** - * Allows filtering runtime dependencies based on the availability of the dependency in runtimseDependencyIncludes - * when it includes elements + * Indicates if the specified runtime dependences should be treated as a compile dependency. + *

+ * Compile dependencies appear on the compile classpath, runtime dependencies do not in order to improve the Eclipse + * performance. * * @param targetKey * the dependency to check - * @return true if runtimeDependencyAvailable is empty or it includes the dependency + * @return true if the dependency should be added to the project's compile dependencies, + * false otherwise */ - private boolean includeRuntimeDependencyAsCompileDependency(TargetKey targetKey) { - return (runtimeDependencyIncludes == null) - || runtimeDependencyIncludes.contains(new BazelLabel(targetKey.getLabel().toString())); + private boolean includeRuntimeDependencyAsProjectCompileDependency(TargetKey targetKey) { + if (runtimeDependencyIncludes == null) { + // filtering is disabled, always include as project dependency + return true; + } + + // only include when it is in the allow list + return runtimeDependencyIncludes.contains(new BazelLabel(targetKey.getLabel().toString())); } private List loadJdeps(TargetIdeInfo targetIdeInfo) throws CoreException { diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java index 0c024ca4..f4ee42f0 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerPackageProvisioningStrategy.java @@ -33,7 +33,7 @@ import com.google.common.collect.Interners; import com.google.idea.blaze.base.model.primitives.LanguageClass; import com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.model.BazelPackage; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; @@ -73,7 +73,7 @@ public class ProjectPerPackageProvisioningStrategy extends BaseProvisioningStrat private final Set additionalJavaLikeRules = new HashSet<>(); @Override - public Map computeClasspaths(Collection bazelProjects, + public Map computeClasspaths(Collection bazelProjects, BazelWorkspace workspace, BazelClasspathScope scope, IProgressMonitor progress) throws CoreException { LOG.debug("Computing classpath for projects: {}", bazelProjects); try { @@ -115,10 +115,10 @@ public Map computeClasspaths(Collection classpathsByProject = new HashMap<>(); + Map classpathsByProject = new HashMap<>(); var workspaceRoot = workspace.getLocation().toPath(); @@ -189,8 +189,11 @@ public Map computeClasspaths(Collection(); // add the targets diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerTargetProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerTargetProvisioningStrategy.java index 99b4213a..3f4a6a2a 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerTargetProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/ProjectPerTargetProvisioningStrategy.java @@ -21,7 +21,7 @@ import com.google.idea.blaze.base.model.primitives.LanguageClass; import com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; import com.salesforce.bazel.eclipse.core.model.BazelWorkspace; @@ -53,7 +53,7 @@ public class ProjectPerTargetProvisioningStrategy extends BaseProvisioningStrate public static final String STRATEGY_NAME = "project-per-target"; @Override - public Map computeClasspaths(Collection bazelProjects, + public Map computeClasspaths(Collection bazelProjects, BazelWorkspace workspace, BazelClasspathScope scope, IProgressMonitor progress) throws CoreException { LOG.debug("Computing classpath for projects: {}", bazelProjects); try { @@ -76,7 +76,7 @@ public Map computeClasspaths(Collection computeClasspaths(Collection classpathsByProject = new HashMap<>(); + Map classpathsByProject = new HashMap<>(); var aspectsInfo = new JavaAspectsInfo(result, workspace); for (BazelProject bazelProject : bazelProjects) { monitor.subTask(bazelProject.getName()); diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/TargetProvisioningStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/TargetProvisioningStrategy.java index b591adb6..1bf29401 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/TargetProvisioningStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/TargetProvisioningStrategy.java @@ -12,7 +12,7 @@ import org.eclipse.jdt.core.IClasspathEntry; import com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; import com.salesforce.bazel.eclipse.core.model.BazelWorkspace; @@ -78,7 +78,7 @@ public interface TargetProvisioningStrategy { * @throws CoreException * in case of problems computing the classpath */ - Map computeClasspaths(Collection bazelProjects, + Map computeClasspaths(Collection bazelProjects, BazelWorkspace workspace, BazelClasspathScope scope, IProgressMonitor monitor) throws CoreException; /** diff --git a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/WorkspaceClasspathStrategy.java b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/WorkspaceClasspathStrategy.java index 769e21b5..b07e1c8b 100644 --- a/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/WorkspaceClasspathStrategy.java +++ b/bundles/com.salesforce.bazel.eclipse.core/src/com/salesforce/bazel/eclipse/core/model/discovery/WorkspaceClasspathStrategy.java @@ -20,7 +20,7 @@ import org.eclipse.core.runtime.SubMonitor; import com.salesforce.bazel.eclipse.core.classpath.BazelClasspathScope; -import com.salesforce.bazel.eclipse.core.classpath.ClasspathHolder; +import com.salesforce.bazel.eclipse.core.classpath.CompileAndRuntimeClasspath; import com.salesforce.bazel.eclipse.core.model.BazelProject; import com.salesforce.bazel.eclipse.core.model.BazelTarget; import com.salesforce.bazel.eclipse.core.model.BazelWorkspace; @@ -59,7 +59,7 @@ public class WorkspaceClasspathStrategy extends BaseProvisioningStrategy { * @return the computed classpath * @throws CoreException */ - public ClasspathHolder computeClasspath(BazelProject workspaceProject, BazelWorkspace bazelWorkspace, + public CompileAndRuntimeClasspath computeClasspath(BazelProject workspaceProject, BazelWorkspace bazelWorkspace, BazelClasspathScope scope, IProgressMonitor progress) throws CoreException { try { var monitor = SubMonitor.convert(progress); @@ -86,7 +86,7 @@ public ClasspathHolder computeClasspath(BazelProject workspaceProject, BazelWork if (!bazelWorkspace.getBazelProjectView().discoverAllExternalAndWorkspaceJars()) { // abort early when discovery is disabled - return new ClasspathHolder(result, Collections.emptyList()); + return new CompileAndRuntimeClasspath(result, Collections.emptyList()); } var externalLibrariesDiscovery = new ExternalLibrariesDiscovery(bazelWorkspace); @@ -123,14 +123,14 @@ public ClasspathHolder computeClasspath(BazelProject workspaceProject, BazelWork "Some source jars are missing. Bazel does not build them by default. Consider runing 'bazel build --output_groups=+_source_jars //...' to build any missing source jar.")); } - return new ClasspathHolder(result, Collections.emptyList()); + return new CompileAndRuntimeClasspath(result, Collections.emptyList()); } finally { progress.done(); } } @Override - public Map computeClasspaths(Collection bazelProjects, + public Map computeClasspaths(Collection bazelProjects, BazelWorkspace workspace, BazelClasspathScope scope, IProgressMonitor monitor) throws CoreException { if (bazelProjects.size() != 1) { throw new IllegalArgumentException("This strategy must only be used for the BazelWorkspace project!");