/** * @return the project if {@link UIContext#getSelection()()} returns a path containing a project, null otherwise */ public static Project getSelectedProject(ProjectFactory projectFactory, UIContext context) { return getSelectedProject(projectFactory, context.getSelection()); }
protected boolean hasProjectFile(UIContext context, String fileName) { UISelection<Object> selection = context.getSelection(); if (selection != null) { Object object = selection.get(); if (object instanceof Resource) { File folder = ResourceUtil.getContextFile((Resource<?>) object); if (folder != null && Files.isDirectory(folder)) { File file = new File(folder, fileName); return file != null && file.exists() && file.isFile(); } } } return false; }
protected File getSelectionFolder(UIContext context) { UISelection<Object> selection = context.getSelection(); if (selection != null) { Object object = selection.get(); if (object instanceof Resource) { File folder = ResourceUtil.getContextFile((Resource<?>) object); if (folder != null && Files.isDirectory(folder)) { return folder; } } } return null; }
public Project getCurrentSelectedProject(UIContext context) { Project project; Map<Object, Object> attributeMap = context.getAttributeMap(); if (attributeMap != null) { Object object = attributeMap.get(Project.class); if (object instanceof Project) { project = (Project) object; return project; } } UISelection<Object> selection = context.getSelection(); Object selectedObject = selection.get(); StopWatch watch = new StopWatch(); try { log.debug("START getCurrentSelectedProject: on " + getProjectFactory() + " selection: " + selectedObject + ". This may result in mvn artifacts being downloaded to ~/.m2/repository"); project = Projects.getSelectedProject(getProjectFactory(), context); if (project != null && attributeMap != null) { attributeMap.put(Project.class, project); } return project; } finally { log.debug("END getCurrentSelectedProject: on " + getProjectFactory() + " selection: " + selectedObject); log.info("getCurrentSelectedProject took " + watch.taken()); } }
UISelection<Object> selection = context.getSelection(); if (selection != null) { Object object = selection.get();
@Override public Result execute(UIExecutionContext context) throws Exception { ForgeScriptEngineFactory factory = new ForgeScriptEngineFactory(); ScriptEngine engine = factory.getScriptEngine(); ScriptContext scriptContext = ScriptContextBuilder.create() .currentResource((Resource<?>) context.getUIContext().getSelection().get()).build(); StringJoiner joiner = new StringJoiner(System.lineSeparator()); AddonDescriptor descriptor = addon.getValue(); for (String installCmd : descriptor.getInstallCmd()) { joiner.add(installCmd); } Object result = engine.eval(joiner.toString(), scriptContext); if (result == null) { return Results.success(); } else { return Results.success(result.toString()); } } }
Project project = Projects.getSelectedProject(projectFactory, uiContext.getSelection()); if (project != null && project.hasFacet(PackagingFacet.class))