private Project getProject(VirtualFile file) { if (file == null || !(file instanceof Resource)) { return null; } Project project = ((Resource) file).getProject(); return (project != null && project.exists()) ? project : null; }
/** Imports all projects described in workspace configuration but not existed on file system. */ private void importProjects() { if (appContext.getFactory() != null) { return; } Project[] projects = appContext.getProjects(); List<Project> importProjects = new ArrayList<>(); for (Project project : projects) { if (project.exists() || project.getSource() == null || project.getSource().getLocation() == null) { continue; } importProjects.add(project); } importProjects(importProjects, null); }
/** Import source projects */ private void importProjects() { final Project[] projects = appContext.getProjects(); Set<String> projectNames = new HashSet<>(); String createPolicy = factory.getPolicies() != null ? factory.getPolicies().getCreate() : null; for (Project project : projects) { if (project.getSource() == null || project.getSource().getLocation() == null) { continue; } if (project.exists()) { // to prevent warning when reusing same workspace if (!("perUser".equals(createPolicy) || "perAccount".equals(createPolicy))) { notificationManager.notify( "Import", locale.projectAlreadyImported(project.getName()), FAIL, FLOAT_MODE); } continue; } projectNames.add(project.getName()); } importProjects(projectNames); }
@Override public Promise<String> expand() { final Resource[] resources = appContext.getResources(); if (resources != null && resources.length == 1) { final Resource resource = resources[0]; Project project = resource.getProject(); if (!project.exists() || !isJavaProject(project)) { return promises.resolve(""); } if (project.getAttributes().containsKey(OUTPUT_FOLDER)) { return promises.resolve( appContext .getProjectsRoot() .append(project.getLocation()) .append(project.getAttributes().get(OUTPUT_FOLDER).get(0)) .toString()); } else { return promises.resolve( appContext.getProjectsRoot().append(project.getLocation()).toString()); } } return promises.resolve(""); } }