/** * Returns the {@code true} if given {@code project} is Java based project. * * <p>Java based project should has {@code java} string value in {@link Constants#LANGUAGE} * attribute. * * @param project the project to check * @return {@code true} if project is java based, otherwise {@code false} * @throws IllegalArgumentException in case if given {@code project} is null. Reason includes: * <ul> * <li>Null project occurred * </ul> * * @since 4.4.0 */ public static boolean isJavaProject(Project project) { checkArgument(project != null, "Null project occurred"); final Map<String, List<String>> attributes = project.getAttributes(); if (attributes == null || attributes.isEmpty()) { return false; } final List<String> languages = attributes.get(LANGUAGE); return languages != null && languages.contains("java"); }
protected final Path[] getPaths(Project project, String srcType) { final List<String> srcFolders = project.getAttributes().get(srcType); if (srcFolders == null || srcFolders.isEmpty()) { return new Path[0]; } Path[] paths = new Path[0]; for (String srcFolder : srcFolders) { final int index = paths.length; paths = Arrays.copyOf(paths, index + 1); paths[index] = project.getLocation().append(srcFolder); } return paths; } }
@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; }
/** 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 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(""); } }
final String artifactId = project.getAttributes().get(MavenAttributes.ARTIFACT_ID).get(0); final String effectivePomPath = "synthetic-file-" + artifactId + "-pom.xml";
@Override public void update(ActionEvent e) { panel.clear(); Project project = appContext.getRootProject(); if (project != null && project.getAttributes().containsKey(GIT_CURRENT_HEAD_NAME)) { Label projectNameLabel = new Label(project.getName()); projectNameLabel.ensureDebugId("statusBarProjectBranchRepositoryName"); projectNameLabel.getElement().getStyle().setMarginLeft(5., Unit.PX); panel.add(projectNameLabel); SVGImage branchIcon = new SVGImage(resources.checkoutReference()); branchIcon.getSvgElement().getStyle().setMarginLeft(5., Unit.PX); panel.add(branchIcon); Label headLabel = new Label(project.getAttribute(GIT_CURRENT_HEAD_NAME)); headLabel.ensureDebugId("statusBarProjectBranchName"); headLabel.setTitle(constant.branchesControlTitle()); Style headLabelStyle = headLabel.getElement().getStyle(); headLabelStyle.setCursor(Cursor.POINTER); headLabelStyle.setMarginLeft(5., Unit.PX); headLabel.addClickHandler(event -> branchPresenter.showBranches(project)); panel.add(headLabel); } } }