/** {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(name); String[] aliases = StringUtils.split(commandLine.getValue(Options.NATURE_OPTION), ','); IProjectDescription desc = project.getDescription(); String[] natureIds = desc.getNatureIds(); ArrayList<String> modified = new ArrayList<String>(); ArrayList<String> newNatures = new ArrayList<String>(); CollectionUtils.addAll(modified, natureIds); for (String alias : aliases) { String natureId = ProjectNatureFactory.getNatureForAlias(alias); if (natureId != null && !modified.contains(natureId)) { modified.add(natureId); newNatures.add(natureId); } } desc.setNatureIds((String[]) modified.toArray(new String[modified.size()])); project.setDescription(desc, new NullProgressMonitor()); for (String nature : newNatures) { ProjectManager manager = ProjectManagement.getProjectManager(nature); if (manager != null) { manager.create(project, commandLine); } } return Services.getMessage("project.nature.added"); }
/** {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(name, true); ProjectManagement.refresh(project, commandLine); return Services.getMessage("project.refreshed", name); }
/** {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(name, true); String setting = commandLine.getValue(Options.SETTING_OPTION); Preferences preferences = getPreferences(); if (commandLine.hasOption(Options.VALUE_OPTION)) { String value = commandLine.getValue(Options.VALUE_OPTION); preferences.setValue(project, setting, value); return null; } return preferences.getValue(project, setting); }
/** * Gets a java project from the supplied IProject. * * @param project The IProject. * @return The java project. */ public static IJavaProject getJavaProject(IProject project) throws Exception { if (ProjectUtils.getPath(project) == null) { throw new IllegalArgumentException( Services.getMessage("project.location.null", project.getName())); } if (!project.hasNature(PluginResources.NATURE)) { throw new IllegalArgumentException( Services.getMessage( "project.missing.nature", project.getName(), ProjectNatureFactory.getAliasForNature(PluginResources.NATURE))); } IJavaProject javaProject = JavaCore.create(project); if (javaProject == null || !javaProject.exists()) { throw new IllegalArgumentException(Services.getMessage("project.not.found", project)); } return javaProject; }
/** * Gets the compilation unit from the supplied project. * * @param project The project. * @param file The absolute path to the file. * @return The compilation unit or null if not found. */ public static ICompilationUnit getCompilationUnit(IJavaProject project, String file) throws Exception { return JavaCore.createCompilationUnitFrom(ProjectUtils.getFile(project.getProject(), file)); }
/** * Gets a java project by name. * * @param project The name of the project. * @return The project. */ public static IJavaProject getJavaProject(String project) throws Exception { return getJavaProject(ProjectUtils.getProject(project, true)); }