All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fabric8.forge.camel.commands.project.CamelEditComponentCommand Maven / Gradle / Ivy

/**
 * Copyright 2005-2015 Red Hat, Inc.
 * 

* Red Hat licenses this file to you under the Apache License, version * 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. See the License for the specific language governing * permissions and limitations under the License. */ package io.fabric8.forge.camel.commands.project; import java.io.StringReader; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import javax.inject.Inject; import io.fabric8.forge.camel.commands.project.completer.SpringBootConfigurationFileCompleter; import io.fabric8.forge.camel.commands.project.dto.ComponentDto; import io.fabric8.forge.camel.commands.project.helper.CamelCommandsHelper; import io.fabric8.forge.camel.commands.project.helper.PoorMansLogger; import io.fabric8.forge.camel.commands.project.helper.StringHelper; import io.fabric8.forge.camel.commands.project.model.InputOptionByGroup; import org.jboss.forge.addon.projects.Project; import org.jboss.forge.addon.projects.dependencies.DependencyInstaller; import org.jboss.forge.addon.projects.facets.ResourcesFacet; import org.jboss.forge.addon.resource.FileResource; import org.jboss.forge.addon.ui.context.UIBuilder; import org.jboss.forge.addon.ui.context.UIContext; import org.jboss.forge.addon.ui.context.UIExecutionContext; import org.jboss.forge.addon.ui.context.UINavigationContext; import org.jboss.forge.addon.ui.input.InputComponent; import org.jboss.forge.addon.ui.input.InputComponentFactory; import org.jboss.forge.addon.ui.input.UISelectOne; import org.jboss.forge.addon.ui.metadata.UICommandMetadata; import org.jboss.forge.addon.ui.metadata.WithAttributes; import org.jboss.forge.addon.ui.result.NavigationResult; import org.jboss.forge.addon.ui.result.Result; import org.jboss.forge.addon.ui.result.Results; import org.jboss.forge.addon.ui.result.navigation.NavigationResultBuilder; import org.jboss.forge.addon.ui.util.Categories; import org.jboss.forge.addon.ui.util.Metadata; import org.jboss.forge.addon.ui.wizard.UIWizard; import static io.fabric8.forge.camel.commands.project.helper.CamelCommandsHelper.createUIInputsForCamelComponent; import static io.fabric8.forge.camel.commands.project.helper.CamelCommandsHelper.isSpringBootProject; import static io.fabric8.forge.camel.commands.project.helper.CamelCommandsHelper.isSpringProject; import static io.fabric8.forge.camel.commands.project.helper.CollectionHelper.first; public class CamelEditComponentCommand extends AbstractCamelProjectCommand implements UIWizard { private static final PoorMansLogger LOG = new PoorMansLogger(false); private static final int MAX_OPTIONS = 20; @Inject @WithAttributes(label = "Components", required = true, description = "The components from the project") private UISelectOne componentName; @Inject private InputComponentFactory componentFactory; @Inject private DependencyInstaller dependencyInstaller; @Override public UICommandMetadata getMetadata(UIContext context) { return Metadata.forCommand(CamelEditComponentCommand.class).name( "Camel: Edit Component").category(Categories.create(CATEGORY)) .description("Edit Camel component"); } @Override public boolean isEnabled(UIContext context) { boolean answer = super.isEnabled(context); if (answer) { // must be spring boot project Project project = getSelectedProject(context); answer = isSpringBootProject(project); } return answer; } @Override public void initializeUI(UIBuilder builder) throws Exception { final Project project = getSelectedProject(builder); Map attributeMap = builder.getUIContext().getAttributeMap(); attributeMap.remove("navigationResult"); // include custom components discoverCustomCamelComponentsOnClasspathAndAddToCatalog(camelCatalog, project); // find all components in project (and filter out components without options) Iterable it = CamelCommandsHelper.createComponentDtoValues(project, getCamelCatalog(), null, false, false, false, true).call(); componentName.setValueChoices(it); builder.add(componentName); } @Override public NavigationResult next(UINavigationContext context) throws Exception { Map attributeMap = context.getUIContext().getAttributeMap(); ComponentDto selectedComponent = componentName.getValue(); if ("