use of javax.annotation.Nullable in project buck by facebook.
the class AdbHelper method createAdb.
/**
* Creates connection to adb and waits for this connection to be initialized
* and receive initial list of devices.
*/
@Nullable
@SuppressWarnings("PMD.EmptyCatchBlock")
private AndroidDebugBridge createAdb(ExecutionContext context) throws InterruptedException {
DdmPreferences.setTimeOut(60000);
try {
AndroidDebugBridge.init(/* clientSupport */
false);
} catch (IllegalStateException ex) {
// ADB was already initialized, we're fine, so just ignore.
}
AndroidDebugBridge adb = AndroidDebugBridge.createBridge(context.getPathToAdbExecutable(), false);
if (adb == null) {
console.printBuildFailure("Failed to connect to adb. Make sure adb server is running.");
return null;
}
long start = System.currentTimeMillis();
while (!isAdbInitialized(adb)) {
long timeLeft = start + ADB_CONNECT_TIMEOUT_MS - System.currentTimeMillis();
if (timeLeft <= 0) {
break;
}
Thread.sleep(ADB_CONNECT_TIME_STEP_MS);
}
return isAdbInitialized(adb) ? adb : null;
}
use of javax.annotation.Nullable in project buck by facebook.
the class AdbHelper method deviceUninstallPackage.
/**
* Modified version of <a href="http://fburl.com/8840769">Device.uninstallPackage()</a>.
*
* @param device an {@link IDevice}
* @param packageName application package name
* @param keepData true if user data is to be kept
* @return error message or null if successful
* @throws InstallException
*/
@Nullable
private String deviceUninstallPackage(IDevice device, String packageName, boolean keepData) throws InstallException {
try {
AdbHelper.ErrorParsingReceiver receiver = new AdbHelper.ErrorParsingReceiver() {
@Override
@Nullable
protected String matchForError(String line) {
return line.toLowerCase(Locale.US).contains("failure") ? line : null;
}
};
device.executeShellCommand("pm uninstall " + (keepData ? "-k " : "") + packageName, receiver, AdbHelper.INSTALL_TIMEOUT, TimeUnit.MILLISECONDS);
return receiver.getErrorMessage();
} catch (AdbCommandRejectedException | IOException | ShellCommandUnresponsiveException | TimeoutException e) {
throw new InstallException(e);
}
}
use of javax.annotation.Nullable in project buck by facebook.
the class ResolveAliasHelper method validateBuildTargetForFullyQualifiedTarget.
/**
* Verify that the given target is a valid full-qualified (non-alias) target.
*/
@Nullable
static String validateBuildTargetForFullyQualifiedTarget(CommandRunnerParams params, ListeningExecutorService executor, boolean enableProfiling, String target, Parser parser) {
BuildTarget buildTarget = getBuildTargetForFullyQualifiedTarget(params.getBuckConfig(), target);
Cell owningCell = params.getCell().getCell(buildTarget);
Path buildFile;
try {
buildFile = owningCell.getAbsolutePathToBuildFile(buildTarget);
} catch (Cell.MissingBuildFileException e) {
throw new HumanReadableException(e);
}
// Get all valid targets in our target directory by reading the build file.
ImmutableSet<TargetNode<?, ?>> targetNodes;
try {
targetNodes = parser.getAllTargetNodes(params.getBuckEventBus(), owningCell, enableProfiling, executor, buildFile);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Check that the given target is a valid target.
for (TargetNode<?, ?> candidate : targetNodes) {
if (candidate.getBuildTarget().equals(buildTarget)) {
return buildTarget.getFullyQualifiedName();
}
}
return null;
}
use of javax.annotation.Nullable in project crate by crate.
the class ExpressionAnalyzer method getQuotedSubscriptLiteral.
@Nullable
protected static String getQuotedSubscriptLiteral(String nodeName) {
Matcher matcher = SUBSCRIPT_SPLIT_PATTERN.matcher(nodeName);
if (matcher.matches()) {
StringBuilder quoted = new StringBuilder();
String group1 = matcher.group(1);
if (!group1.isEmpty()) {
quoted.append("\"").append(group1).append("\"");
} else {
quoted.append(group1);
}
String group2 = matcher.group(2);
String group3 = matcher.group(3);
if (!group2.isEmpty() && !group3.isEmpty()) {
quoted.append(matcher.group(2));
quoted.append("\"").append(group3).append("\"");
} else if (!group2.isEmpty() && group3.isEmpty()) {
return null;
}
quoted.append(matcher.group(4));
return quoted.toString();
} else {
return null;
}
}
use of javax.annotation.Nullable in project crate by crate.
the class OrderBy method subset.
/**
* Create a new OrderBy with symbols that match the predicate
*/
@Nullable
public OrderBy subset(Predicate<? super Symbol> predicate) {
List<Integer> subSet = new ArrayList<>();
Integer i = 0;
for (Symbol orderBySymbol : orderBySymbols) {
if (predicate.apply(orderBySymbol)) {
subSet.add(i);
}
i++;
}
if (subSet.isEmpty()) {
return null;
}
return subset(subSet);
}
Aggregations