本文整理汇总了Java中com.google.devtools.build.lib.events.EventHandler类的典型用法代码示例。如果您正苦于以下问题:Java EventHandler类的具体用法?Java EventHandler怎么用?Java EventHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EventHandler类属于com.google.devtools.build.lib.events包,在下文中一共展示了EventHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGlobals
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Create native global variables from the modules
*
* <p>The returned object can be reused for different instances of environments.
*/
private Environment.Frame createGlobals(
EventHandler eventHandler, Options options, ConfigFile<?> currentConfigFile,
ConfigFile<?> mainConfigFile,
Supplier<ImmutableMap<String, ? extends ConfigFile<?>>> configFilesSupplier) {
Environment env = createEnvironment(eventHandler, Environment.SKYLARK,
ImmutableMap.of());
for (Class<?> module : modules) {
logger.log(Level.INFO, "Creating variable for " + module.getName());
// Create the module object and associate it with the functions
Runtime.registerModuleGlobals(env, module);
// Add the options to the module that require them
if (OptionsAwareModule.class.isAssignableFrom(module)) {
((OptionsAwareModule) getModuleGlobal(env, module)).setOptions(options);
}
if (LabelsAwareModule.class.isAssignableFrom(module)) {
((LabelsAwareModule) getModuleGlobal(env, module))
.setConfigFile(mainConfigFile, currentConfigFile);
((LabelsAwareModule) getModuleGlobal(env, module))
.setAllConfigResources(configFilesSupplier);
}
}
env.mutability().close();
return env.getGlobals();
}
示例2: getCorrectedApiLevel
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Translates the given API level to the equivalent API level in the NDK.
*/
private String getCorrectedApiLevel(
EventHandler eventHandler, String repositoryName, String apiLevel) {
String correctedApiLevel = apiEquivalencies.get(apiLevel);
if (correctedApiLevel == null) {
// The user specified an API level we don't know about. Default to the most recent API level.
// This relies on the entries being added in sorted order.
String latestApiLevel = Iterables.getLast(apiEquivalencies.keySet());
correctedApiLevel = apiEquivalencies.get(latestApiLevel);
eventHandler.handle(Event.warn(String.format(
"API level %s specified by android_ndk_repository '%s' is not available. "
+ "Using latest known API level %s",
apiLevel, repositoryName, latestApiLevel)));
}
return correctedApiLevel;
}
示例3: createSkylarkRuleClassEnvironment
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
@Override
public Environment createSkylarkRuleClassEnvironment(
Label extensionLabel,
Mutability mutability,
SkylarkSemantics skylarkSemantics,
EventHandler eventHandler,
String astFileContentHashCode,
Map<String, Extension> importMap) {
return createSkylarkRuleClassEnvironment(
mutability,
globals.withLabel(extensionLabel),
skylarkSemantics,
eventHandler,
astFileContentHashCode,
importMap);
}
示例4: calculateOutputs
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
@Override
public ImmutableMap<String, String> calculateOutputs(
EventHandler eventHandler, AttributeMap map) throws EvalException, InterruptedException {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
for (Map.Entry<String, String> entry : outputMap.entrySet()) {
// Empty iff invalid placeholders present.
ImplicitOutputsFunction outputsFunction =
fromUnsafeTemplates(ImmutableList.of(entry.getValue()));
Iterable<String> substitutions = outputsFunction.getImplicitOutputs(eventHandler, map);
if (Iterables.isEmpty(substitutions)) {
throw new EvalException(
null,
String.format(
"For attribute '%s' in outputs: %s",
entry.getKey(), "Invalid placeholder(s) in template"));
}
builder.put(entry.getKey(), Iterables.getOnlyElement(substitutions));
}
return builder.build();
}
示例5: fromFunctions
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* The implicit output function that generates files based on a set of
* template substitutions using rule attribute values.
*
* @param functions The functions used to construct the name of the implicit
* output file target. The substring "%{name}" will be replaced by the
* actual name of the rule, the substring "%{srcs}" will be replaced by the
* name of each source file without its extension. If multiple %{}
* substrings exist, the cross-product of them is generated.
*/
public static SafeImplicitOutputsFunction fromFunctions(
final Iterable<SafeImplicitOutputsFunction> functions) {
return new SafeImplicitOutputsFunction() {
@Override
public Iterable<String> getImplicitOutputs(EventHandler eventHandler, AttributeMap rule) {
Collection<String> result = new LinkedHashSet<>();
for (SafeImplicitOutputsFunction function : functions) {
Iterables.addAll(result, function.getImplicitOutputs(eventHandler, rule));
}
return result;
}
@Override
public String toString() {
return StringUtil.joinEnglishList(functions);
}
};
}
示例6: createLexer
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Create a lexer which takes input from the specified string. Resets the
* error handler beforehand.
*/
private Lexer createLexer(String input) {
PathFragment somePath = PathFragment.create("/some/path.txt");
ParserInputSource inputSource = ParserInputSource.create(input, somePath);
Reporter reporter = new Reporter(new EventBus());
reporter.addHandler(new EventHandler() {
@Override
public void handle(Event event) {
if (EventKind.ERRORS.contains(event.getKind())) {
lastErrorLocation = event.getLocation();
lastError = lastErrorLocation.getPath() + ":"
+ event.getLocation().getStartLineAndColumn().getLine() + ": " + event.getMessage();
}
}
});
return new Lexer(inputSource, reporter);
}
示例7: checkThirdPartyRuleHasLicense
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Reports an error against the specified rule if it's beneath third_party
* but does not have a declared license.
*/
private static void checkThirdPartyRuleHasLicense(Rule rule,
Package.Builder pkgBuilder, EventHandler eventHandler) {
if (isThirdPartyPackage(rule.getLabel().getPackageIdentifier())) {
License license = rule.getLicense();
if (license == null) {
license = pkgBuilder.getDefaultLicense();
}
if (!license.isSpecified()) {
rule.reportError("third-party rule '" + rule.getLabel() + "' lacks a license declaration "
+ "with one of the following types: notice, reciprocal, permissive, "
+ "restricted, unencumbered, by_exception_only",
eventHandler);
}
}
}
示例8: setRuleAttributeValue
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Sets the value of attribute {@code attr} in {@code rule} to the native value {@code
* nativeAttrVal}, and sets the value's explicitness to {@code explicit}.
*
* <p>Handles the special case of the "visibility" attribute by also setting the rule's
* visibility with {@link Rule#setVisibility}.
*
* <p>Checks that {@code nativeAttrVal} is an allowed value via {@link #checkAllowedValues}.
*/
private static void setRuleAttributeValue(
Rule rule,
EventHandler eventHandler,
Attribute attr,
Object nativeAttrVal,
boolean explicit) {
if (attr.getName().equals("visibility")) {
@SuppressWarnings("unchecked")
List<Label> attrList = (List<Label>) nativeAttrVal;
if (!attrList.isEmpty()
&& ConstantRuleVisibility.LEGACY_PUBLIC_LABEL.equals(attrList.get(0))) {
rule.reportError(
rule.getLabel() + ": //visibility:legacy_public only allowed in package declaration",
eventHandler);
}
try {
rule.setVisibility(PackageFactory.getVisibility(rule.getLabel(), attrList));
} catch (EvalException e) {
rule.reportError(rule.getLabel() + " " + e.getMessage(), eventHandler);
}
}
rule.setAttributeValue(attr, nativeAttrVal, explicit);
checkAllowedValues(rule, attr, eventHandler);
}
示例9: BuildEventServiceTransport
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
public BuildEventServiceTransport(
BuildEventServiceClient besClient,
Duration uploadTimeout,
boolean bestEffortUpload,
boolean publishLifecycleEvents,
String buildRequestId,
String invocationId,
String command,
ModuleEnvironment moduleEnvironment,
Clock clock,
PathConverter pathConverter,
EventHandler commandLineReporter,
@Nullable String projectId,
Set<String> keywords) {
this(besClient, uploadTimeout, bestEffortUpload, publishLifecycleEvents, buildRequestId,
invocationId, command, moduleEnvironment, clock, pathConverter, commandLineReporter,
projectId, keywords, new JavaSleeper());
}
示例10: checkConstraints
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Returns {@code true} iff all constraints set by the toolchain are present in the {@link
* PlatformInfo}.
*/
private static boolean checkConstraints(
@Nullable EventHandler eventHandler,
Iterable<ConstraintValueInfo> toolchainConstraints,
String platformType,
PlatformInfo platform) {
for (ConstraintValueInfo constraint : toolchainConstraints) {
ConstraintValueInfo found = platform.getConstraint(constraint.constraint());
if (!constraint.equals(found)) {
debugMessage(
eventHandler,
" Toolchain constraint %s has value %s, "
+ "which does not match value %s from the %s platform %s",
constraint.constraint().label(),
constraint.label(),
found != null ? found.label() : "<missing>",
platformType,
platform.label());
return false;
}
}
return true;
}
示例11: create
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
private static BuildFileAST create(
List<Statement> preludeStatements,
ParseResult result,
String contentHashCode,
EventHandler eventHandler) {
ImmutableList<Statement> statements =
ImmutableList.<Statement>builder()
.addAll(preludeStatements)
.addAll(result.statements)
.build();
boolean containsErrors = result.containsErrors;
Pair<Boolean, ImmutableList<SkylarkImport>> skylarkImports =
fetchLoads(statements, eventHandler);
containsErrors |= skylarkImports.first;
return new BuildFileAST(
statements,
containsErrors,
contentHashCode,
result.location,
ImmutableList.copyOf(result.comments),
skylarkImports.second);
}
示例12: execTopLevelStatement
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Executes tol-level statement of this build file in a given Environment.
*
* <p>If, for any reason, execution of a statement cannot be completed, an {@link EvalException}
* is thrown by {@link Eval#exec(Statement)}. This exception is caught here and reported
* through reporter. In effect, there is a
* "try/except" block around every top level statement. Such exceptions are not ignored, though:
* they are visible via the return value. Rules declared in a package containing any error
* (including loading-phase semantical errors that cannot be checked here) must also be considered
* "in error".
*
* <p>Note that this method will not affect the value of {@link #containsErrors()}; that refers
* only to lexer/parser errors.
*
* @return true if no error occurred during execution.
*/
public boolean execTopLevelStatement(Statement stmt, Environment env,
EventHandler eventHandler) throws InterruptedException {
try {
new Eval(env).exec(stmt);
return true;
} catch (EvalException e) {
// Do not report errors caused by a previous parsing error, as it has already been
// reported.
if (e.isDueToIncompleteAST()) {
return false;
}
// When the exception is raised from another file, report first the location in the
// BUILD file (as it is the most probable cause for the error).
Location exnLoc = e.getLocation();
Location nodeLoc = stmt.getLocation();
eventHandler.handle(Event.error(
(exnLoc == null || !nodeLoc.getPath().equals(exnLoc.getPath())) ? nodeLoc : exnLoc,
e.getMessage()));
return false;
}
}
示例13: processDeps
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
@Override
void processDeps(
FirstErrorMessageAccumulator accumulator,
EventHandler eventHandler,
TargetAndErrorIfAny targetAndErrorIfAny,
Iterable<Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>>>
depEntries) {
for (Entry<SkyKey, ValueOrException2<NoSuchPackageException, NoSuchTargetException>> entry :
depEntries) {
TransitiveTraversalValue transitiveTraversalValue;
try {
transitiveTraversalValue = (TransitiveTraversalValue) entry.getValue().get();
if (transitiveTraversalValue == null) {
continue;
}
} catch (NoSuchPackageException | NoSuchTargetException e) {
accumulator.maybeSet(e.getMessage());
continue;
}
String firstErrorMessage = transitiveTraversalValue.getFirstErrorMessage();
if (firstErrorMessage != null) {
accumulator.maybeSet(firstErrorMessage);
}
}
}
示例14: Environment
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Constructs an Environment. This is the main, most basic constructor.
*
* @param globalFrame a frame for the global Environment
* @param dynamicFrame a frame for the dynamic Environment
* @param eventHandler an EventHandler for warnings, errors, etc
* @param importedExtensions Extension-s from which to import bindings with load()
* @param fileContentHashCode a hash for the source file being evaluated, if any
* @param phase the current phase
* @param callerLabel the label this environment came from
*/
private Environment(
Frame globalFrame,
Frame dynamicFrame,
SkylarkSemantics semantics,
EventHandler eventHandler,
Map<String, Extension> importedExtensions,
@Nullable String fileContentHashCode,
Phase phase,
@Nullable Label callerLabel) {
this.globalFrame = Preconditions.checkNotNull(globalFrame);
this.dynamicFrame = Preconditions.checkNotNull(dynamicFrame);
Preconditions.checkArgument(!globalFrame.mutability().isFrozen());
Preconditions.checkArgument(!dynamicFrame.mutability().isFrozen());
this.semantics = semantics;
this.eventHandler = eventHandler;
this.importedExtensions = importedExtensions;
this.phase = phase;
this.callerLabel = callerLabel;
this.transitiveHashCode =
computeTransitiveContentHashCode(fileContentHashCode, importedExtensions);
}
示例15: removeOutputDirectoryLinks
import com.google.devtools.build.lib.events.EventHandler; //导入依赖的package包/类
/**
* Attempts to remove the convenience symlinks in the workspace directory.
*
* <p>Issues a warning if it fails, e.g. because workspaceDirectory is readonly.
* Also cleans up any child directories created by a custom prefix.
*
* @param workspace the runtime's workspace
* @param eventHandler the error eventHandler
* @param symlinkPrefix the symlink prefix which should be removed
* @param productName the product name
*/
public static void removeOutputDirectoryLinks(String workspaceName, Path workspace,
EventHandler eventHandler, String symlinkPrefix, String productName) {
if (NO_CREATE_SYMLINKS_PREFIX.equals(symlinkPrefix)) {
return;
}
List<String> failures = new ArrayList<>();
for (String outputSymlinkName : getOutputSymlinkNames(productName, symlinkPrefix)) {
removeLink(workspace, outputSymlinkName, failures);
}
removeLink(workspace, execRootSymlink(symlinkPrefix, workspaceName), failures);
removeLink(workspace, execRootSymlink(symlinkPrefix, workspace.getBaseName()), failures);
removeLink(workspace, symlinkPrefix + "bin", failures);
removeLink(workspace, symlinkPrefix + "testlogs", failures);
removeLink(workspace, symlinkPrefix + "genfiles", failures);
FileSystemUtils.removeDirectoryAndParents(workspace, PathFragment.create(symlinkPrefix));
if (!failures.isEmpty()) {
eventHandler.handle(Event.warn(String.format(
"failed to remove one or more convenience symlinks for prefix '%s':\n %s", symlinkPrefix,
Joiner.on("\n ").join(failures))));
}
}