Defines a BazelAspectLocation interface to pass around the location of the aspect workspace (#30)
This separate code that depends on Eclipse API from code related to Bazel. A future change
will inject the BazelAspectLocationImpl from another package.
diff --git a/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocation.java b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocation.java
new file mode 100644
index 0000000..277e13e
--- /dev/null
+++ b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocation.java
@@ -0,0 +1,29 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.bazel.e4b.command;
+
+import java.io.File;
+
+/**
+ * Define the location of the aspect to use to analyze a Bazel project.
+ */
+public interface BazelAspectLocation {
+
+ /** Returns a {@link File} object that points to the Bazel workspace containing the aspect. */
+ public File getWorkspaceDirectory();
+
+ /** Returns the label of the aspect in the Bazel workspace (with the function name). */
+ public String getAspectLabel();
+}
diff --git a/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocationImpl.java b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocationImpl.java
new file mode 100644
index 0000000..1503f1e
--- /dev/null
+++ b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelAspectLocationImpl.java
@@ -0,0 +1,50 @@
+// Copyright 2017 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.devtools.bazel.e4b.command;
+
+import com.google.devtools.bazel.e4b.Activator;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
+
+/** Implementation of {@link BazelAspectLocation} using Eclipse OSGi Bundle locations */
+class BazelAspectLocationImpl implements BazelAspectLocation {
+
+ // Returns the path of the resources file from this plugin.
+ private static File getAspectWorkspace() {
+ try {
+ URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("resources");
+ URL resolved = FileLocator.resolve(url);
+ return new File(resolved.getPath());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static File WORKSPACE_DIRECTORY = getAspectWorkspace();
+
+ @Override
+ public File getWorkspaceDirectory() {
+ return WORKSPACE_DIRECTORY;
+ }
+
+ @Override
+ public String getAspectLabel() {
+ return "//tools/must/be/unique:e4b_aspect.bzl%e4b_aspect.bzl";
+ }
+
+}
diff --git a/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelCommand.java b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelCommand.java
index 89da270..bffa541 100644
--- a/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelCommand.java
+++ b/com.google.devtools.bazel.e4b/src/com/google/devtools/bazel/e4b/command/BazelCommand.java
@@ -17,11 +17,9 @@
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.devtools.bazel.e4b.Activator;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
@@ -29,8 +27,6 @@
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.Platform;
/**
* Main utility to call bazel commands, wrapping its input and output to the message console.
@@ -44,24 +40,14 @@
// Minimum bazel version needed to work with this plugin (currently 0.4.0)
private static int[] MINIMUM_BAZEL_VERSION = {0, 4, 0};
- // Returns the path of the resources file from this plugin.
- private static File getAspectWorkspace() {
- try {
- URL url = Platform.getBundle(Activator.PLUGIN_ID).getEntry("resources");
- URL resolved = FileLocator.resolve(url);
- return new File(resolved.getPath());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
private static enum ConsoleType {
NO_CONSOLE, SYSTEM, WORKSPACE
}
- private static final File ASPECT_WORKSPACE = getAspectWorkspace();
+ // TODO: Inject
+ private static final BazelAspectLocation ASPECT_LOCATION = new BazelAspectLocationImpl();
private static final List<String> BUILD_OPTIONS =
- ImmutableList.of("--watchfs", "--aspects=tools/must/be/unique/e4b_aspect.bzl%e4b_aspect");
+ ImmutableList.of("--watchfs", "--aspects=" + ASPECT_LOCATION.getAspectLabel());
private static final List<String> ASPECT_OPTIONS = ImmutableList
.<String>builder().addAll(BUILD_OPTIONS).add("-k",
"--output_groups=ide-info-text,ide-resolve,-_,-defaults", "--experimental_show_artifacts")
@@ -94,7 +80,8 @@
throw new BazelNotFoundException.BazelNotExecutableException();
}
try {
- Command command = Command.builder().setConsoleName(null).setDirectory(ASPECT_WORKSPACE)
+ Command command = Command.builder().setConsoleName(null)
+ .setDirectory(ASPECT_LOCATION.getWorkspaceDirectory())
.addArguments(bazel, "version")
.setStdoutLineSelector((s) -> s.startsWith("Build label:") ? s.substring(13) : null)
.build();
@@ -164,7 +151,8 @@
throws IOException, InterruptedException, BazelNotFoundException {
this.workspaceRoot = workspaceRoot;
this.packagePath =
- String.join("", runBazel("info", "package_path")) + ":" + ASPECT_WORKSPACE.toString();
+ String.join("", runBazel("info", "package_path")) + ":"
+ + ASPECT_LOCATION.getWorkspaceDirectory().toString();
this.execRoot = new File(String.join("", runBazel("info", "execution_root")));
}