-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
bazel_binary
in project view
- Loading branch information
Showing
13 changed files
with
320 additions
and
143 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...e/src/com/salesforce/bazel/eclipse/core/extensions/DetectBazelVersionAndSetBinaryJob.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,67 @@ | ||
package com.salesforce.bazel.eclipse.core.extensions; | ||
|
||
import static java.lang.String.format; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.core.runtime.IStatus; | ||
import org.eclipse.core.runtime.Status; | ||
import org.eclipse.core.runtime.jobs.Job; | ||
|
||
import com.salesforce.bazel.sdk.command.BazelBinary; | ||
import com.salesforce.bazel.sdk.command.BazelBinaryVersionDetector; | ||
|
||
/** | ||
* Calls <code>bazel --version</code> on a provided binary to identify the version use. | ||
* <p> | ||
* Calls {@link EclipseHeadlessBazelCommandExecutor#setBazelBinary(BazelBinary)} when done. | ||
* </p> | ||
*/ | ||
public final class DetectBazelVersionAndSetBinaryJob extends Job { | ||
private final Path binary; | ||
private final boolean wrapExecutionIntoShell; | ||
private final Consumer<BazelBinary> binaryConsumer; | ||
private final Supplier<BazelBinary> fallbackSupplier; | ||
|
||
/** | ||
* @param binary | ||
* the binary to test | ||
* @param wrapExecutionIntoShell | ||
* <code>true</code> if shell wrapping is desired, <code>false</code> otherwise | ||
* @param binaryConsumer | ||
* receiver of the binary including the detected version (will be called with a fallback value in | ||
* case of errors) | ||
* @param fallbackSupplier | ||
* supplier for fallback value in case of errors | ||
*/ | ||
public DetectBazelVersionAndSetBinaryJob(Path binary, boolean wrapExecutionIntoShell, | ||
Consumer<BazelBinary> binaryConsumer, Supplier<BazelBinary> fallbackSupplier) { | ||
super(format("Detecting Bazel version...", binary)); | ||
this.binary = binary; | ||
this.wrapExecutionIntoShell = wrapExecutionIntoShell; | ||
this.binaryConsumer = binaryConsumer; | ||
this.fallbackSupplier = fallbackSupplier; | ||
setSystem(true); | ||
setPriority(SHORT); | ||
} | ||
|
||
@Override | ||
protected IStatus run(IProgressMonitor monitor) { | ||
try { | ||
var bazelVersion = new BazelBinaryVersionDetector(binary, wrapExecutionIntoShell).detectVersion(); | ||
binaryConsumer.accept(new BazelBinary(binary, bazelVersion)); | ||
return Status.OK_STATUS; | ||
} catch (IOException e) { | ||
binaryConsumer.accept(fallbackSupplier.get()); | ||
return Status.error(format("Unable to detect Bazel version of binary '%s'!", binary), e); | ||
} catch (InterruptedException e) { | ||
EclipseHeadlessBazelCommandExecutor.LOG.warn("Interrupted waiting for bazel --version to respond for binary '{}'", binary, e); | ||
binaryConsumer.accept(fallbackSupplier.get()); | ||
return Status.CANCEL_STATUS; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.