use of javax.annotation.Nullable in project buck by facebook.
the class DistBuildService method uploadBuckDotFiles.
public ListenableFuture<Void> uploadBuckDotFiles(final StampedeId id, final ProjectFilesystem filesystem, FileHashCache fileHashCache, ListeningExecutorService executorService) throws IOException {
ListenableFuture<Pair<List<FileInfo>, List<PathInfo>>> filesFuture = executorService.submit(() -> {
List<Path> buckDotFilesExceptConfig = Lists.newArrayList();
for (Path path : filesystem.getDirectoryContents(filesystem.getRootPath())) {
String fileName = path.getFileName().toString();
if (!filesystem.isDirectory(path) && !filesystem.isSymLink(path) && fileName.startsWith(".") && fileName.contains("buck") && !fileName.startsWith(".buckconfig")) {
buckDotFilesExceptConfig.add(path);
}
}
List<FileInfo> fileEntriesToUpload = new LinkedList<>();
List<PathInfo> pathEntriesToUpload = new LinkedList<>();
for (Path path : buckDotFilesExceptConfig) {
FileInfo fileInfoObject = new FileInfo();
fileInfoObject.setContent(filesystem.readFileIfItExists(path).get().getBytes());
fileInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
fileEntriesToUpload.add(fileInfoObject);
PathInfo pathInfoObject = new PathInfo();
pathInfoObject.setPath(path.toString());
pathInfoObject.setContentHash(fileHashCache.get(path.toAbsolutePath()).toString());
pathEntriesToUpload.add(pathInfoObject);
}
return new Pair<>(fileEntriesToUpload, pathEntriesToUpload);
});
ListenableFuture<Void> setFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
setBuckDotFiles(id, filesAndPaths.getSecond());
return Futures.immediateFuture(null);
}, executorService);
ListenableFuture<Void> uploadFilesFuture = Futures.transformAsync(filesFuture, filesAndPaths -> {
uploadMissingFilesFromList(filesAndPaths.getFirst(), executorService);
return Futures.immediateFuture(null);
}, executorService);
return Futures.transform(Futures.allAsList(ImmutableList.of(setFilesFuture, uploadFilesFuture)), new Function<List<Void>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<Void> input) {
return null;
}
});
}
use of javax.annotation.Nullable in project buck by facebook.
the class ChooseTargetContributor method addPathSugestions.
public void addPathSugestions(final List<String> names, final Project project) {
String currentText = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY).getEnteredText();
// Remove the begining //
currentText = currentText.replaceFirst("^/*", "");
// check if we have as input a proper target
int currentTargetSeparatorIndex = currentText.lastIndexOf(TARGET_NAME_SEPARATOR);
if (currentTargetSeparatorIndex != -1) {
currentText = currentText.substring(0, currentText.lastIndexOf(TARGET_NAME_SEPARATOR));
}
// Try to get the relative path to the current input folder
VirtualFile baseDir = project.getBaseDir().findFileByRelativePath(currentText + "/");
if (baseDir == null) {
// Try to get the relative path to the previous input folder
if (currentText.lastIndexOf("/") != -1) {
currentText = currentText.substring(0, currentText.lastIndexOf("/"));
} else {
// Get the base path if there is no previous folder
currentText = "";
}
baseDir = project.getBaseDir().findFileByRelativePath(currentText);
// If the base dir is still null, then we have a bad relative path
if (baseDir == null) {
return;
}
}
// get the files under the base folder
VirtualFile[] files = baseDir.getChildren();
if (!currentText.isEmpty()) {
currentText += "/";
}
for (VirtualFile file : files) {
// if the file is a directory we add it to the targets
if (file.isDirectory()) {
names.add("//" + currentText + file.getName());
}
//if the file is a buck file we parse it and add its target names to the list
if (file.getName().equals("BUCK")) {
int end = currentText.length() - 1;
// Handle if the BUCK file is the main directory of the project
if (currentText.isEmpty()) {
end = 0;
}
String target = "//" + currentText.substring(0, end) + ":";
// we need the aliases now
names.addAll(BuckQueryAction.execute(project, target, new Function<List<String>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<String> strings) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
ChooseByNamePopup chooseByNamePopup = project.getUserData(ChooseByNamePopup.CHOOSE_BY_NAME_POPUP_IN_PROJECT_KEY);
// the user might have closed the window
if (chooseByNamePopup != null) {
// if we don't have them, just refresh the view when we do, if the
// window is still open
chooseByNamePopup.rebuildList(true);
}
}
});
return null;
}
}));
}
}
}
use of javax.annotation.Nullable in project buck by facebook.
the class BuckAutoDepsContributor method getVirtualFileFromClassname.
@Nullable
public VirtualFile getVirtualFileFromClassname(String classname) {
GlobalSearchScope scope = GlobalSearchScope.allScope(mProject);
PsiClass psiClass = JavaPsiFacade.getInstance(mProject).findClass(classname, scope);
if (psiClass == null) {
return null;
}
PsiFile psiFile = psiClass.getContainingFile();
if (psiFile == null) {
return null;
}
return psiFile.getVirtualFile();
}
use of javax.annotation.Nullable in project buck by facebook.
the class TraceHandlerDelegate method getDataForRequest.
@Override
@Nullable
public SoyMapData getDataForRequest(Request baseRequest) throws IOException {
String path = baseRequest.getPathInfo();
Matcher matcher = TraceDataHandler.ID_PATTERN.matcher(path);
if (!matcher.matches()) {
return null;
}
SoyMapData templateData = new SoyMapData();
String id = matcher.group(1);
templateData.put("traceId", id);
// Read the args to `buck` out of the Chrome Trace.
TraceAttributes traceAttributes = buildTraces.getTraceAttributesFor(id);
templateData.put("dateTime", traceAttributes.getFormattedDateTime());
if (traceAttributes.getCommand().isPresent()) {
templateData.put("command", traceAttributes.getCommand().get());
}
return templateData;
}
use of javax.annotation.Nullable in project buck by facebook.
the class BuckQueryAction method execute.
public static synchronized List<String> execute(final Project project, final String target, final Function<List<String>, Void> fillTextResults) {
if (ongoingQuery.contains(target)) {
return Collections.emptyList();
}
List<String> targetsInBuckFile = buckTargetCache.getIfPresent(target);
if (targetsInBuckFile != null) {
return targetsInBuckFile;
}
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
public void run() {
ongoingQuery.add(target);
BuckBuildManager buildManager = BuckBuildManager.getInstance(project);
BuckCommandHandler handler = new BuckQueryCommandHandler(project, project.getBaseDir(), BuckCommand.QUERY, new Function<List<String>, Void>() {
@Nullable
@Override
public Void apply(@Nullable List<String> strings) {
ongoingQuery.remove(target);
buckTargetCache.put(target, strings);
fillTextResults.apply(strings);
return null;
}
});
handler.command().addParameter(target);
buildManager.runBuckCommand(handler, ACTION_TITLE);
}
});
return Collections.emptyList();
}
Aggregations