Skip to content

Commit

Permalink
Merge pull request #203 from gastaldi/master
Browse files Browse the repository at this point in the history
FORGE-206: Display a diff of available commands when starting forge after installing/removing a plugin
  • Loading branch information
lincolnthree committed Aug 22, 2012
2 parents 6a7fc4b + c99cfa2 commit 916088c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright 2012 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.shell.plugins.builtin;

import java.util.Set;
import java.util.TreeSet;

import javax.enterprise.event.Observes;

import org.jboss.forge.shell.Shell;
import org.jboss.forge.shell.ShellColor;
import org.jboss.forge.shell.command.PluginRegistry;
import org.jboss.forge.shell.events.PostStartup;
import org.jboss.forge.shell.events.ReinitializeEnvironment;

/**
* Display a diff of available commands when starting forge after installing/removing a plugin
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public class PluginDiffObserver
{

private static volatile Set<String> LAST_PLUGINS_DIFF;

/**
* Called when Forge is restarted
*/
public void onRestart(@Observes ReinitializeEnvironment restart, PluginRegistry pluginRegistry)
{
LAST_PLUGINS_DIFF = new TreeSet<String>();
LAST_PLUGINS_DIFF.addAll(pluginRegistry.getPlugins().keySet());
}

/**
* Called when Forge is booted up
*/
public void onInitialize(@Observes PostStartup start, PluginRegistry pluginRegistry, Shell shell)
{
if (LAST_PLUGINS_DIFF != null)
{
Set<String> loadedPlugins = pluginRegistry.getPlugins().keySet();
Set<String> currentPlugins = new TreeSet<String>();
currentPlugins.addAll(loadedPlugins);
currentPlugins.removeAll(LAST_PLUGINS_DIFF);
if (!LAST_PLUGINS_DIFF.isEmpty() && !currentPlugins.isEmpty())
{
shell.print("The following plugins have been activated: ");
shell.println(ShellColor.BOLD, currentPlugins.toString());
}
LAST_PLUGINS_DIFF.removeAll(loadedPlugins);
if (!LAST_PLUGINS_DIFF.isEmpty())
{
shell.print("The following plugins have been deactivated: ");
shell.println(ShellColor.BOLD, LAST_PLUGINS_DIFF.toString());
}
LAST_PLUGINS_DIFF = null;
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2012 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.shell.plugins.builtin;

import static org.junit.Assert.*;

import org.jboss.forge.test.AbstractShellTest;
import org.junit.Ignore;
import org.junit.Test;

/**
* Test case for the {@link PluginDiffObserver} class
*
* @author <a href="mailto:ggastald@redhat.com">George Gastaldi</a>
*
*/
public class PluginDiffObserverTest extends AbstractShellTest
{

@Test
@Ignore
public void test()
{
fail("Not yet implemented");
}

}

0 comments on commit 916088c

Please sign in to comment.