public Project getProject(UIContext uiContext) { return Projects.getSelectedProject(projectFactory, uiContext); }
/** * Returns <code>true</code> if a {@link Project} exists in the current {@link UISelection}. */ protected boolean containsProject(UIContext context) { return Projects.containsProject(getProjectFactory(), context); }
private void monitorResource(final MavenModelResource pomResource) { if (Projects.isCacheDisabled()) { return; } final ResourceMonitor monitor = pomResource.monitor(); monitor.addResourceListener((event) -> { evictFromCache(pomResource); monitor.cancel(); }); }
private void cacheProject(final Project project) if (Projects.isCacheDisabled())
/** * @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()); }
public ModelBuildingResult getModelBuildingResult(MavenModelResource pomResource) throws ModelBuildingException { ModelBuildingResult result = cacheModel.get(pomResource.getFullyQualifiedName()); if (result == null) { ModelBuilder builder = getModelBuilder(); DefaultModelBuildingRequest request = getModelBuildingRequest(); boolean inTransaction = !pomResource.getUnderlyingResourceObject().exists(); // FORGE-1287 if (inTransaction) { // If under a transaction, don't start monitoring request.setModelSource(new FileResourceModelSource(pomResource)); } else { request.setPomFile(pomResource.getUnderlyingResourceObject()); monitorResource(pomResource); } result = builder.build(request); if (!Projects.isCacheDisabled()) { cacheModel.put(pomResource.getFullyQualifiedName(), result); } } return result; }
@Override public boolean accept(UIContext context) { ProjectFactory projectFactory = SimpleContainer.getServices(getClass().getClassLoader(), ProjectFactory.class) .get(); return Projects.containsProject(projectFactory, context); } }
protected Project getSelectedProjectOrNull(UIContext context) { return Projects.getSelectedProject(this.getProjectFactory(), context); }
if (result != null && !Projects.isCacheDisabled()) cacheProject.put(pomResource.getFullyQualifiedName(), result);
protected Project getSelectedProjectOrNull(UIContext context) { return Projects.getSelectedProject(this.getProjectFactory(), context); }
/** * Returns the selected {@link Project}. <code>null</code> if no {@link Project} is found. */ protected Project getSelectedProject(UIContext context) { Project selectedProject = Projects.getSelectedProject(getProjectFactory(), context); if (isProjectRequired() && selectedProject == null) { throw new IllegalStateException("A project is required in the current context"); } return selectedProject; }
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()); } }
@SuppressWarnings("unchecked") @Override public void enrich(InputComponentInjectionPoint injectionPoint, InputComponent<?, ?> input) { UIContextProvider contextProvider = SimpleContainer .getServices(getClass().getClassLoader(), UIContextProvider.class).get(); UIContext context = contextProvider.getUIContext(); // Setting for Single valued components only at the moment if (input instanceof SingleValued && context != null) { Class<?> valueType = input.getValueType(); if (ProjectFacet.class.isAssignableFrom(valueType)) { Class<? extends ProjectFacet> projectFacet = (Class<? extends ProjectFacet>) valueType; ProjectFactory projectFactory = SimpleContainer .getServices(getClass().getClassLoader(), ProjectFactory.class).get(); Project project = Projects.getSelectedProject(projectFactory, context); if (project != null && project.hasFacet(projectFacet)) { ConverterFactory converterFactory = SimpleContainer .getServices(getClass().getClassLoader(), ConverterFactory.class).get(); InputComponents.setDefaultValueFor(converterFactory, (InputComponent<?, Object>) input, project.getFacet(projectFacet)); } } } } }
return Results.fail("No className field provided"); Project project = Projects.getSelectedProject(getProjectFactory(), uiContext);
Project project = Projects.getSelectedProject(projectFactory, context.getUIContext()); if (project != null)
@Override public String convert(String source) { final String result; if (Strings.isNullOrEmpty(source) || contextProvider.getUIContext() == null) { result = source; } else { UIContext context = contextProvider.getUIContext(); Project selectedProject = Projects.getSelectedProject(projectFactory, context); if (selectedProject != null && selectedProject.hasFacet(JavaSourceFacet.class)) { String basePackage = selectedProject.getFacet(JavaSourceFacet.class).getBasePackage(); String fullPackage = source.replaceAll("\\~", basePackage); result = fullPackage; } else { result = source; } } return result; } }
final Project project = Projects.getSelectedProject(getProjectFactory(), builder.getUIContext());
Project project = Projects.getSelectedProject(projectFactory, builder.getUIContext()); if (project != null)
Project project = Projects.getSelectedProject(getProjectFactory(), uiContext); final Collection<FractionDescriptor> fractions; if (project != null && project.hasFacet(WildFlySwarmFacet.class))
@Override public void initializeUI(UIBuilder builder) throws Exception { InputComponentFactory factory = builder.getInputComponentFactory(); coordinate = factory.createInput("coordinate", String.class).setLabel("Coordinate") .setDescription("The addon's \"groupId:artifactId,version\" coordinate") .setNote("The addon's \"groupId:artifactId,version\" coordinate").setRequired(true); ProjectFactory projectFactory = SimpleContainer.getServices(getClass().getClassLoader(), ProjectFactory.class) .get(); Project project = Projects.getSelectedProject(projectFactory, builder.getUIContext()); if (project != null) { MetadataFacet facet = project.getFacet(MetadataFacet.class); Coordinate c = facet.getOutputDependency().getCoordinate(); coordinate.setDefaultValue(AddonId.from(c.getGroupId() + ":" + c.getArtifactId(), c.getVersion()) .toCoordinates()); } List<String> defaultCoords = Arrays.asList(CoordinateUtils.FORGE_ADDON_GROUP_ID); coordinate.setCompleter((UIContext context, InputComponent<?, String> input, String value) -> { Iterable<String> items = Collections.emptySet(); if (Strings.isNullOrEmpty(value)) { items = defaultCoords; } return items; }); builder.add(coordinate); }