Search in sources :

Example 21 with Nullable

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;
        }
    });
}
Also used : Path(java.nio.file.Path) LinkedList(java.util.LinkedList) FileInfo(com.facebook.buck.distributed.thrift.FileInfo) PathInfo(com.facebook.buck.distributed.thrift.PathInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) Pair(com.facebook.buck.model.Pair)

Example 22 with Nullable

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;
                }
            }));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Function(com.google.common.base.Function) ChooseByNamePopup(com.intellij.ide.util.gotoByName.ChooseByNamePopup) ArrayList(java.util.ArrayList) List(java.util.List) Nullable(javax.annotation.Nullable)

Example 23 with Nullable

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();
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) Nullable(javax.annotation.Nullable)

Example 24 with Nullable

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;
}
Also used : SoyMapData(com.google.template.soy.data.SoyMapData) Matcher(java.util.regex.Matcher) TraceAttributes(com.facebook.buck.util.trace.BuildTraces.TraceAttributes) Nullable(javax.annotation.Nullable)

Example 25 with Nullable

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();
}
Also used : Function(com.google.common.base.Function) BuckQueryCommandHandler(com.facebook.buck.intellij.ideabuck.build.BuckQueryCommandHandler) BuckBuildManager(com.facebook.buck.intellij.ideabuck.build.BuckBuildManager) List(java.util.List) BuckCommandHandler(com.facebook.buck.intellij.ideabuck.build.BuckCommandHandler) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)3188 List (java.util.List)363 IOException (java.io.IOException)307 Map (java.util.Map)294 ArrayList (java.util.ArrayList)284 Nonnull (javax.annotation.Nonnull)264 File (java.io.File)225 Collectors (java.util.stream.Collectors)175 Arrays (java.util.Arrays)165 HashMap (java.util.HashMap)161 Test (org.junit.Test)137 Layer (com.simiacryptus.mindseye.lang.Layer)116 Tensor (com.simiacryptus.mindseye.lang.Tensor)116 ItemStack (net.minecraft.item.ItemStack)115 Logger (org.slf4j.Logger)113 LoggerFactory (org.slf4j.LoggerFactory)113 ImmutableList (com.google.common.collect.ImmutableList)111 Set (java.util.Set)107 Result (com.simiacryptus.mindseye.lang.Result)104 Function (com.google.common.base.Function)100