Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Apr 12, 2012
1 parent 393727d commit 4377f7e
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 152 deletions.
Expand Up @@ -171,8 +171,7 @@ private void displayModules(final DirectoryResource pluginDir)
public void find(@Option(description = "search string") final String searchString, final PipeOut out)
throws Exception
{
List<PluginRef> pluginList = PluginUtil.findPlugin(environment, getProxySettings(),
searchString, out);
List<PluginRef> pluginList = PluginUtil.findPlugin(shell, configuration, searchString);

if (!pluginList.isEmpty())
{
Expand All @@ -190,20 +189,6 @@ public void find(@Option(description = "search string") final String searchStrin
}
}

private ProxySettings getProxySettings()
{
Configuration proxyConfig = configuration.getScopedConfiguration(
ConfigurationScope.USER).subset("proxy");
if (proxyConfig != null && !proxyConfig.isEmpty())
{
return ProxySettings.fromForgeConfiguration(proxyConfig);
}
else
{
return null;
}
}

@Command(value = "remove-plugin",
help = "Removes a plugin from the current Forge runtime configuration")
public void removePlugin(
Expand Down Expand Up @@ -232,11 +217,11 @@ public void removePlugin(

@Command(value = "install-plugin",
help = "Installs a plugin from the configured Forge plugin index")
public void installFromIndex(@Option(description = "plugin-name") final String pluginName,
public void installFromIndex(@Option(description = "plugin-name", completer=IndexPluginNameCompleter.class) final String pluginName,
@Option(name = "version", description = "branch, tag, or version to build") final String version,
final PipeOut out) throws Exception
{
List<PluginRef> plugins = PluginUtil.findPlugin(environment, getProxySettings(), pluginName, out);
List<PluginRef> plugins = PluginUtil.findPlugin(shell, configuration, pluginName);

if (plugins.isEmpty())
{
Expand Down Expand Up @@ -525,7 +510,7 @@ else if (refName != null)

private void prepareProxyForJGit()
{
ProxySettings proxySettings = getProxySettings();
ProxySettings proxySettings = ProxySettings.fromForgeConfiguration(configuration);
if (proxySettings == null)
{
// There is no proxy configured
Expand Down
@@ -0,0 +1,70 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2012, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.forge.shell.plugins.builtin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.inject.Inject;

import org.jboss.forge.env.Configuration;
import org.jboss.forge.shell.Shell;
import org.jboss.forge.shell.completer.SimpleTokenCompleter;
import org.jboss.forge.shell.util.PluginRef;
import org.jboss.forge.shell.util.PluginUtil;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class IndexPluginNameCompleter extends SimpleTokenCompleter
{
@Inject
private Shell shell;

@Inject
private Configuration config;

@Override
public Iterable<?> getCompletionTokens()
{
List<String> plugins = new ArrayList<String>();
try
{
List<PluginRef> refs = PluginUtil.findPluginSilent(shell, config, "*");
for (PluginRef pluginRef : refs)
{
plugins.add(pluginRef.getName());
}
}
catch (Exception e)
{
e.printStackTrace();
}

Collections.sort(plugins);

return plugins;
}

}

0 comments on commit 4377f7e

Please sign in to comment.