-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,027 additions
and
435 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
base/src/com/google/idea/blaze/base/command/info/BlazeInfo.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
16 changes: 16 additions & 0 deletions
16
base/src/com/google/idea/blaze/base/command/mod/BlazeModException.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,16 @@ | ||
package com.google.idea.blaze.base.command.mod; | ||
|
||
import com.google.idea.blaze.exception.BuildException; | ||
|
||
import javax.annotation.concurrent.Immutable; | ||
|
||
@Immutable | ||
public final class BlazeModException extends BuildException { | ||
public BlazeModException(String message) { | ||
super(message); | ||
} | ||
|
||
public BlazeModException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
base/src/com/google/idea/blaze/base/command/mod/BlazeModRunner.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,72 @@ | ||
/* | ||
* Copyright 2016 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.idea.blaze.base.command.mod; | ||
|
||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker; | ||
import com.google.idea.blaze.base.model.ExternalWorkspaceData; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.base.settings.BuildSystemName; | ||
import com.intellij.openapi.components.ServiceManager; | ||
import com.intellij.openapi.project.Project; | ||
|
||
import java.util.List; | ||
|
||
/** Runs the blaze info command. The results may be cached in the workspace. */ | ||
public abstract class BlazeModRunner { | ||
|
||
public static BlazeModRunner getInstance() { | ||
return ServiceManager.getService(BlazeModRunner.class); | ||
} | ||
|
||
/** | ||
* @param blazeFlags The blaze flags that will be passed to Blaze. | ||
* @param key The key passed to blaze info | ||
* @return The blaze info value associated with the specified key | ||
*/ | ||
public abstract ListenableFuture<String> runBlazeMod( | ||
Project project, | ||
BuildInvoker invoker, | ||
BlazeContext context, | ||
List<String> blazeFlags, | ||
String key); | ||
|
||
/** | ||
* @param blazeFlags The blaze flags that will be passed to Blaze. | ||
* @param key The key passed to blaze info | ||
* @return The blaze info value associated with the specified key | ||
*/ | ||
public abstract ListenableFuture<byte[]> runBlazeModGetBytes( | ||
Project project, | ||
BuildInvoker invoker, | ||
BlazeContext context, | ||
List<String> blazeFlags, | ||
String key); | ||
|
||
/** | ||
* This calls blaze info without any specific key so blaze info will return all keys and values | ||
* that it has. | ||
* | ||
* @param blazeFlags The blaze flags that will be passed to Blaze. | ||
* @return The blaze info data fields. | ||
*/ | ||
public abstract ListenableFuture<ExternalWorkspaceData> dumpRepoMapping( | ||
Project project, | ||
BuildInvoker invoker, | ||
BlazeContext context, | ||
BuildSystemName buildSystemName, | ||
List<String> blazeFlags); | ||
} |
70 changes: 70 additions & 0 deletions
70
base/src/com/google/idea/blaze/base/command/mod/BlazeModRunnerImpl.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,70 @@ | ||
package com.google.idea.blaze.base.command.mod; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.util.concurrent.Futures; | ||
import com.google.common.util.concurrent.ListenableFuture; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.google.idea.blaze.base.async.executor.BlazeExecutor; | ||
import com.google.idea.blaze.base.bazel.BuildSystem; | ||
import com.google.idea.blaze.base.command.BlazeCommand; | ||
import com.google.idea.blaze.base.command.BlazeCommandName; | ||
import com.google.idea.blaze.base.command.buildresult.BuildResultHelper; | ||
import com.google.idea.blaze.base.model.ExternalWorkspaceData; | ||
import com.google.idea.blaze.base.model.primitives.ExternalWorkspace; | ||
import com.google.idea.blaze.base.scope.BlazeContext; | ||
import com.google.idea.blaze.base.settings.BuildSystemName; | ||
import com.intellij.openapi.project.Project; | ||
|
||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
|
||
public class BlazeModRunnerImpl extends BlazeModRunner { | ||
@Override | ||
public ListenableFuture<String> runBlazeMod(Project project, BuildSystem.BuildInvoker invoker, BlazeContext context, List<String> blazeFlags, String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ListenableFuture<ExternalWorkspaceData> dumpRepoMapping( | ||
Project project, | ||
BuildSystem.BuildInvoker invoker, | ||
BlazeContext context, | ||
BuildSystemName buildSystemName, | ||
List<String> blazeFlags) { | ||
return Futures.transform( | ||
runBlazeModGetBytes(project, invoker, context, blazeFlags, "dump_repo_mapping"), | ||
bytes -> { | ||
JsonObject jsonObject = JsonParser.parseString(new String(bytes, StandardCharsets.UTF_8).trim()).getAsJsonObject(); | ||
|
||
ImmutableList<ExternalWorkspace> externalWorkspaces = jsonObject.asMap().entrySet().stream() | ||
.filter(entry -> entry.getValue().isJsonPrimitive()) | ||
.filter(entry -> !entry.getValue().getAsString().trim().isEmpty()) | ||
.map(entry -> ExternalWorkspace.create(entry.getKey(), entry.getValue().getAsString())) | ||
.collect(ImmutableList.toImmutableList()); | ||
|
||
return ExternalWorkspaceData.create(externalWorkspaces); | ||
}, | ||
BlazeExecutor.getInstance().getExecutor()); | ||
} | ||
|
||
@Override | ||
public ListenableFuture<byte[]> runBlazeModGetBytes(Project project, BuildSystem.BuildInvoker invoker, BlazeContext context, List<String> blazeFlags, String query_type) { | ||
return BlazeExecutor.getInstance().submit(() -> { | ||
BlazeCommand.Builder builder = BlazeCommand.builder(invoker, BlazeCommandName.MOD); | ||
builder.addBlazeFlags(blazeFlags); | ||
|
||
if (query_type != null) { | ||
builder.addBlazeFlags(query_type, "workspace"); | ||
} | ||
|
||
try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper()) { | ||
try (InputStream stream = invoker.getCommandRunner().runBlazeMod(project, builder, buildResultHelper, context)) { | ||
return stream.readAllBytes(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
base/src/com/google/idea/blaze/base/lang/buildfile/completion/WorkspaceLookupElement.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,28 @@ | ||
package com.google.idea.blaze.base.lang.buildfile.completion; | ||
|
||
import com.google.idea.blaze.base.lang.buildfile.references.QuoteType; | ||
import com.intellij.util.PlatformIcons; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
|
||
public class WorkspaceLookupElement extends BuildLookupElement { | ||
public WorkspaceLookupElement(String baseName) { | ||
super(baseName, QuoteType.NoQuotes); | ||
} | ||
|
||
@Override | ||
protected @Nullable String getTypeText() { | ||
return "gigi"; | ||
} | ||
|
||
@Override | ||
public @Nullable Icon getIcon() { | ||
return PlatformIcons.IMPORT_ICON; | ||
} | ||
|
||
protected String getItemText() { | ||
return baseName; | ||
} | ||
|
||
} |
Oops, something went wrong.