-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FORGE-2023: Created config-set and config-clear
- Loading branch information
Showing
4 changed files
with
190 additions
and
110 deletions.
There are no files selected for viewing
150 changes: 150 additions & 0 deletions
150
configuration/impl/src/main/java/org/jboss/forge/addon/configuration/ui/ConfigCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/** | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.addon.configuration.ui; | ||
|
||
import java.io.PrintStream; | ||
import java.util.Iterator; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.forge.addon.configuration.Configuration; | ||
import org.jboss.forge.addon.configuration.facets.ConfigurationFacet; | ||
import org.jboss.forge.addon.projects.Project; | ||
import org.jboss.forge.addon.projects.ProjectFactory; | ||
import org.jboss.forge.addon.projects.Projects; | ||
import org.jboss.forge.addon.ui.annotation.Command; | ||
import org.jboss.forge.addon.ui.annotation.Option; | ||
import org.jboss.forge.addon.ui.annotation.predicate.NonGUIEnabledPredicate; | ||
import org.jboss.forge.addon.ui.context.UIContext; | ||
import org.jboss.forge.addon.ui.output.UIOutput; | ||
import org.jboss.forge.addon.ui.result.Result; | ||
import org.jboss.forge.addon.ui.result.Results; | ||
|
||
/** | ||
* Configuration commands | ||
* | ||
* @author <a href="ggastald@redhat.com">George Gastaldi</a> | ||
*/ | ||
public class ConfigCommand | ||
{ | ||
@Inject | ||
private Configuration userConfig; | ||
|
||
@Inject | ||
private ProjectFactory projectFactory; | ||
|
||
@Command(value = "Config: Set", categories = { "Configuration" }, enabled = NonGUIEnabledPredicate.class) | ||
public Result setConfigurationProperty(UIContext context, | ||
@Option(value = "key", required = true) String key, | ||
@Option(value = "value", required = true) String value, | ||
@Option(value = "local") boolean local) throws Exception | ||
{ | ||
if (local) | ||
{ | ||
Project project = Projects.getSelectedProject(projectFactory, context); | ||
if (project != null) | ||
{ | ||
Configuration projectConfig = project.getFacet(ConfigurationFacet.class).getConfiguration(); | ||
projectConfig.setProperty(key, value); | ||
} | ||
else | ||
{ | ||
return Results.fail("No project found in current context. Can't store in local configuration."); | ||
} | ||
} | ||
else | ||
{ | ||
userConfig.setProperty(key, value); | ||
} | ||
return Results.success(); | ||
} | ||
|
||
@Command(value = "Config: Clear", categories = { "Configuration" }, enabled = NonGUIEnabledPredicate.class) | ||
public Result clearProperty(UIContext context, | ||
@Option(value = "key", required = true) String key, | ||
@Option(value = "local") boolean local) throws Exception | ||
{ | ||
if (local) | ||
{ | ||
Project project = Projects.getSelectedProject(projectFactory, context); | ||
if (project != null) | ||
{ | ||
Configuration projectConfig = project.getFacet(ConfigurationFacet.class).getConfiguration(); | ||
projectConfig.clearProperty(key); | ||
} | ||
else | ||
{ | ||
return Results.fail("No project found in current context. Can't clear from local configuration."); | ||
} | ||
} | ||
else | ||
{ | ||
userConfig.clearProperty(key); | ||
} | ||
return Results.success(); | ||
} | ||
|
||
@Command(value = "Config: List", categories = { "Configuration" }, enabled = NonGUIEnabledPredicate.class) | ||
public void listConfiguration(UIContext context, UIOutput output) | ||
{ | ||
PrintStream out = output.out(); | ||
|
||
Project project = Projects.getSelectedProject(projectFactory, context); | ||
Configuration projectConfig = null; | ||
|
||
if (project != null) | ||
{ | ||
projectConfig = project.getFacet(ConfigurationFacet.class).getConfiguration(); | ||
} | ||
|
||
Iterator<?> userConfigKeys = userConfig.getKeys(); | ||
|
||
while (userConfigKeys.hasNext()) | ||
{ | ||
Object key = userConfigKeys.next(); | ||
|
||
if (key != null) | ||
{ | ||
out.print(key.toString()); | ||
out.print("="); | ||
|
||
out.print("user: [" + userConfig.getProperty(key.toString()) + "]"); | ||
if (projectConfig != null) | ||
{ | ||
out.print(", project: "); | ||
Object value = projectConfig.getProperty(key.toString()); | ||
if (value != null) | ||
{ | ||
out.print("[" + value.toString() + "] "); | ||
} | ||
else | ||
out.print("[]"); | ||
} | ||
} | ||
out.println(); | ||
} | ||
|
||
if (projectConfig != null) | ||
{ | ||
Iterator<?> projectConfigKeys = projectConfig.getKeys(); | ||
|
||
while (projectConfigKeys.hasNext()) | ||
{ | ||
String key = projectConfigKeys.next().toString(); | ||
if (!userConfig.containsKey(key)) | ||
{ | ||
out.print(key.toString()); | ||
out.print("=project: ["); | ||
out.print(projectConfig.getProperty(key.toString()).toString() + "]"); | ||
} | ||
out.println(); | ||
} | ||
} | ||
} | ||
|
||
} |
103 changes: 0 additions & 103 deletions
103
...guration/impl/src/main/java/org/jboss/forge/addon/configuration/ui/ConfigListCommand.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters