Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
ROO-3612: Refactoring Roo commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jcagarcia committed Apr 24, 2015
1 parent e967caa commit 0dcbb78
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,37 @@ public class ObrAddOnCommands implements CommandMarker {
@Reference private ObrAddOnSearchOperations operations;


@CliCommand(value = "addon info", help = "Provide information about a specific Spring Roo Add-on")
@CliCommand(value = "addon info bundle", help = "Provide information about a specific Spring Roo Add-on")
public void infoBundle(
@CliOption(key = "bundleSymbolicName", mandatory = true, help = "The bundle symbolic name for the add-on of interest") final ObrAddOnBundleSymbolicName bsn) {

operations.addOnInfo(bsn);
}

@CliCommand(value = "addon install", help = "Install Spring Roo Add-on")
@CliCommand(value = "addon install bundle", help = "Install Spring Roo Add-on")
public void installBsn(
@CliOption(key = "bundleSymbolicName", mandatory = true, help = "The bundle symbolic name for the add-on of interest") final ObrAddOnBundleSymbolicName bsn) {
operations.installAddOn(bsn);
}

@CliCommand(value = "addon install url", help = "Install Spring Roo Add-on using url")
public void installByUrl(
@CliOption(key = "url", mandatory = true, help = "The url for the add-on of interest") final String url) {
operations.installAddOnByUrl(url);
}

@CliCommand(value = "addon remove", help = "Remove Spring Roo Add-on")
public void remove(
@CliOption(key = "bundleSymbolicName", mandatory = true, help = "The bundle symbolic name for the add-on of interest") final BundleSymbolicName bsn) {

operations.removeAddOn(bsn);
}

@CliCommand(value = "addon list", help = "List all installed addons")
public void list() {

operations.list();
}

@CliCommand(value = "addon search", help = "Search all known Spring Roo Add-ons")
public void search(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ List<ObrBundle> findAddons(boolean showFeedback, String searchTerms,
* @param bsn the bundle symbolic name (required)
*/
InstallOrUpgradeStatus installAddOn(ObrAddOnBundleSymbolicName bsn);


/**
* Install addon with given URL
*
* @param url
* @return
*/
InstallOrUpgradeStatus installAddOnByUrl(String url);

/**
* Install addon with given Add-On ID.
Expand All @@ -93,5 +102,10 @@ List<ObrBundle> findAddons(boolean showFeedback, String searchTerms,
* @param bsn the bundle symbolic name (required)
*/
InstallOrUpgradeStatus removeAddOn(BundleSymbolicName bsn);

/**
* List all installed addons. Equivalent to 'lb' felix command
*/
void list();

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.InvalidSyntaxException;
Expand Down Expand Up @@ -174,6 +175,11 @@ private void populateBundlesToInstallByCommand(String requiresCommand){
repoResource.getPresentationName(), repoResource.getSize(),
repoResource.getVersion(), repoResource.getURI());

// If current bundle is installed, continue with the next one
if(checkIfBundleIsInstalled(bundle)){
continue;
}

// Getting Resource Capabilites
Capability[] resourceCapabilities = repoResource.getCapabilities();

Expand Down Expand Up @@ -205,8 +211,23 @@ private void populateBundlesToInstallByCommand(String requiresCommand){
}
}



/**
* Method to check if some bundle is installed on OSGi
* @param bundle
* @return
*/
private boolean checkIfBundleIsInstalled(ObrBundle bundle) {
// Refreshing installed bundles
Bundle[] allInstalledBundles = context.getBundles();
// Checking if bundles is installed
for(Bundle installedBundle : allInstalledBundles){
if(installedBundle.getSymbolicName().equals(bundle.getSymbolicName())){
return true;
}
}
return false;
}

/**
* Method to populate current Bundles on installed repositories
*/
Expand Down Expand Up @@ -267,8 +288,8 @@ private void printResultList(List<ObrBundle> bundles) {
sb.setLength(0);
}
LOGGER.warning("--------------------------------------------------------------------------------");
LOGGER.info("[HINT] use 'addon info --bundleSymbolicName' to see details about a search result");
LOGGER.info("[HINT] use 'addon install --bundleSymbolicName' to install a specific add-on version");
LOGGER.info("[HINT] use 'addon info bundle --bundleSymbolicName' to see details about a search result");
LOGGER.info("[HINT] use 'addon install bundle --bundleSymbolicName' to install a specific add-on version");
}


Expand Down Expand Up @@ -388,6 +409,20 @@ public InstallOrUpgradeStatus installAddOn(String bundleId) {
bundle.getSymbolicName());
}
}

@Override
public InstallOrUpgradeStatus installAddOnByUrl(String url) {
synchronized (mutex) {
Validate.notNull(url, "Valid url is required");
boolean success = getShell().executeCommand("!g felix:install "
+ url);
success = getShell().executeCommand("!g felix:start "
+ url);

return success ? InstallOrUpgradeStatus.SUCCESS
: InstallOrUpgradeStatus.FAILED;
}
}

@Override
public InstallOrUpgradeStatus removeAddOn(BundleSymbolicName bsn) {
Expand Down Expand Up @@ -520,6 +555,13 @@ private InstallOrUpgradeStatus installOrUpgradeAddOn(
: InstallOrUpgradeStatus.FAILED;
}

@Override
public void list() {
synchronized (mutex) {
getShell().executeCommand("!g lb");
}
}

/**
* Method to get RepositoryAdmin Service implementation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public void listRepos() throws Exception{
operations.listRepos();
}

@CliCommand(value = "addon repository introspect", help = "Introspects all installed OBR Repositories and list all their addons")
public void introspectRepos() throws Exception{
operations.introspectRepos();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ public interface ObrRepositoryOperations {
* @throws Exception
*/
void listRepos() throws Exception;


/**
* Introspects all installed OBR Repositories and list all their addons
* @throws Exception
*/
void introspectRepos() throws Exception;


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.apache.commons.lang3.Validate;
import org.apache.felix.bundlerepository.Repository;
import org.apache.felix.bundlerepository.RepositoryAdmin;
import org.apache.felix.bundlerepository.Resource;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.osgi.framework.BundleContext;
Expand Down Expand Up @@ -123,6 +124,29 @@ public void listRepos() throws Exception {
"%s installed repositories on Spring Roo were found",
getRepositoryAdmin().listRepositories().length));
}

@Override
public void introspectRepos() throws Exception {
LOGGER.log(Level.INFO, "Getting current installed repositories...");
// Populating repositories
populateRepositories();
LOGGER.log(Level.INFO, "");
// Getting all addons installed on repositories
int totalAddons = 0;
for (Repository repo : repositories) {
Resource[] allResources = repo.getResources();
// Getting all resources for repo
for(Resource resource : allResources){
// Printing all resources
LOGGER.log(Level.INFO, resource.getPresentationName() + "(" + resource.getVersion() + ")");
totalAddons++;
}
}
LOGGER.log(Level.INFO, "");
LOGGER.log(Level.INFO, String.format(
"%s available addons on installed repositories were found",
totalAddons));
}

/**
* Method to get RepositoryAdmin Service implementation
Expand Down

0 comments on commit 0dcbb78

Please sign in to comment.