@Nullable private Project getProjectByPath(String path) { for (Project project : appContext.getProjects()) { if (path.equals(project.getPath())) { return project; } } return null; }
/** Refresh 'Projects' section in the view. */ private void refreshProjects() { final Map<Project, Boolean> projectsStates = new HashMap<>(); for (Project project : appContext.getProjects()) { ApplicableContext context = editedCommand.getApplicableContext(); boolean applicable = context.getApplicableProjects().contains(project.getPath()); projectsStates.put(project, applicable); } view.setProjects(projectsStates); }
private void checkProjectProblems(Project project) { final Optional<Marker> marker = project.getMarker(PROBLEM_PROJECT); if (!marker.isPresent()) { return; } final Project.ProblemProjectMarker problemProjectMarker = (Project.ProblemProjectMarker) marker.get(); final Map<Integer, String> problems = problemProjectMarker.getProblems(); // If no project folder on file system final String noProjectFolderProblem = problems.get(NO_PROJECT_ON_FILE_SYSTEM); final List<String> importingProjects = appContext.getImportingProjects(); if (!isNullOrEmpty(noProjectFolderProblem) && !importingProjects.contains(project.getPath())) { showImportDialog(project); } }
@NotNull private static List<String> doGetSourceFolders(Project projectConfig, String projectBuilder) { List<String> allSourceFolders = new LinkedList<>(); String projectPath = removeEndingPathSeparator(projectConfig.getPath()); Map<String, List<String>> attributes = projectConfig.getAttributes(); List<String> sourceFolders = attributes.get(SOURCE_FOLDER); if (sourceFolders != null) { for (String sourceFolder : sourceFolders) { allSourceFolders.add(projectPath + addStartingPathSeparator(sourceFolder) + '/'); } } List<String> testSourceFolders = attributes.get(projectBuilder + ".test.source.folder"); if (testSourceFolders != null) { for (String testSourceFolder : testSourceFolders) { allSourceFolders.add(projectPath + addStartingPathSeparator(testSourceFolder) + '/'); } } return allSourceFolders; }
/** Checks whether the given command is applicable to the current project. */ private boolean isCommandApplicableToCurrentProject(CommandImpl command) { final Set<String> applicableProjects = command.getApplicableContext().getApplicableProjects(); if (applicableProjects.isEmpty()) { return true; } final Resource currentResource = appContext.getResource(); if (currentResource != null) { final Project currentProject = currentResource.getProject(); if (currentProject != null) { return applicableProjects.contains(currentProject.getPath()); } } return false; }
/** Returns the default {@link ApplicableContext} for the new command. */ private ApplicableContext getDefaultContext() { final ApplicableContext context = new ApplicableContext(); if (appContext.getProjects().length > 0) { context.setWorkspaceApplicable(false); Arrays.stream(appContext.getProjects()).forEach(p -> context.addProject(p.getPath())); } return context; }
/** Returns commands for the specified {@code project}. */ List<CommandImpl> getCommands(Project project) { List<String> attrValues = project.getAttributes(COMMANDS_ATTRIBUTE_NAME); if (attrValues == null) { return new ArrayList<>(); } Map<String, CommandImpl> commands = new HashMap<>(attrValues.size()); for (String commandJson : attrValues) { try { CommandDto commandDto = dtoFactory.createDtoFromJson(commandJson, CommandDto.class); commands.put(commandDto.getName(), new CommandImpl(commandDto)); } catch (JSONException e) { Log.error( ProjectCommandManagerDelegate.class, "Unable to parse command of project '" + project.getPath() + "': " + commandJson + ". " + e.getMessage()); } } return new ArrayList<>(commands.values()); }
@Override public Location toLocation(int lineNumber) { return new LocationImpl(getLocation().toString(), lineNumber, getProject().getPath()); } }
@Override public void onApplicableProjectChanged(Project project, boolean applicable) { final ApplicableContext context = editedCommand.getApplicableContext(); if (applicable) { // if command is bound with one project at least // then remove command from the workspace if (context.getApplicableProjects().isEmpty()) { context.setWorkspaceApplicable(false); } context.addProject(project.getPath()); } else { context.removeProject(project.getPath()); // if command isn't bound to any project // then save it to the workspace if (context.getApplicableProjects().isEmpty()) { context.setWorkspaceApplicable(true); } } notifyDirtyStateChanged(); }
private Promise<CommandImpl> addCommand(Project project, CommandDto commandDto) { final String name = project.getName() + ": " + commandDto.getName(); final String absoluteProjectPath = appContext.getProjectsRoot().append(project.getPath()).toString(); final String commandLine = commandDto.getCommandLine().replaceAll(PROJECT_PATH_MACRO_REGEX, absoluteProjectPath); final CommandImpl command = new CommandImpl( name, commandLine, commandDto.getType(), commandDto.getAttributes(), new ApplicableContext(project.getPath())); return commandManager.createCommand(command); }
@Override public void go(final AcceptsOneWidget container) { final Resource resource = appContext.getResource(); Preconditions.checkState(resource != null); final Project project = resource.getProject(); isPlainJava = JAVAC.equals(project.getType()); setReadOnlyMod(); container.setWidget(view); if (!categories.isEmpty()) { view.renderLibraries(); return; } classpathContainer .getClasspathEntries(project.getPath()) .then( entries -> { categories.clear(); for (ClasspathEntry entry : entries) { if (CONTAINER == entry.getEntryKind() || LIBRARY == entry.getEntryKind()) { categories.put(entry.getPath(), entry); } } view.setData(categories); view.renderLibraries(); }); }
startImport(Path.valueOf(projectConfig.getPath()), projectConfig.getSource()) .thenPromise(project -> project.update().withBody(projectConfig).send()));
private void save() { if (ACTIVATED == mode && editor.isDirty()) { editor.doSave(); } VirtualFile file = editor.getEditorInput().getFile(); Project project = getProject(file); if (project == null) { return; } String filePath = file.getLocation().toString(); String projectPath = project.getPath(); synchronizeWorkingCopy(filePath, projectPath); }
private void importForProject(StatusNotification notification) { Project rootProject = appContext.getRootProject(); if (rootProject == null) { notification.setStatus(FAIL); notification.setTitle("Failed to import code formatter. No project selected."); return; } javaFormatterServiceClient .updateProjectFormatter(view.getFileContent(), rootProject.getPath()) .then( content -> { onSuccessImported(notification); }) .catchError( error -> { onFailedImported(notification); }); }