Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WINDUP-1724 Reduce list {source,target,tag} commands execution time #1215

Merged
merged 2 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package org.jboss.windup.bootstrap.commands;

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

import org.jboss.forge.furnace.Furnace;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public abstract class AbstractListCommand implements Command, FurnaceDependent
public abstract class AbstractListCommand extends AbstractListCommandWithoutFurnace implements Command, FurnaceDependent
{
private Furnace furnace;

Expand All @@ -24,19 +19,4 @@ public void setFurnace(Furnace furnace)
{
this.furnace = furnace;
}

/**
* Print the given values after displaying the provided message.
*/
protected static void printValuesSorted(String message, Set<String> values)
{
System.out.println();
System.out.println(message + ":");
List<String> sorted = new ArrayList<>(values);
Collections.sort(sorted);
for (String value : sorted)
{
System.out.println("\t" + value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.jboss.windup.bootstrap.commands;

import org.jboss.forge.furnace.Furnace;
import org.jboss.windup.bootstrap.help.Help;

import java.util.*;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public abstract class AbstractListCommandWithoutFurnace implements Command
{
/**
* Print the given values after displaying the provided message.
*/
protected static void printValuesSorted(String message, Set<String> values)
{
System.out.println();
System.out.println(message + ":");
List<String> sorted = new ArrayList<>(values);
Collections.sort(sorted);
for (String value : sorted)
{
System.out.println("\t" + value);
}
}

protected static Set<String> getOptionValuesFromHelp(String optionName)
{
Set<String> options = new HashSet<>();
Help.load().getOptions().stream()
.filter(opt -> opt.getName().equals(optionName))
.forEach(optionDescription -> options.addAll(optionDescription.getAvailableOptions()));
return options;
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
package org.jboss.windup.bootstrap.commands.windup;

import org.jboss.windup.bootstrap.commands.AbstractListCommand;
import org.jboss.windup.bootstrap.commands.AbstractListCommandWithoutFurnace;
import org.jboss.windup.bootstrap.commands.Command;
import org.jboss.windup.bootstrap.commands.CommandPhase;
import org.jboss.windup.bootstrap.commands.CommandResult;
import org.jboss.windup.bootstrap.commands.FurnaceDependent;
import org.jboss.windup.config.metadata.RuleProviderRegistryCache;
import org.jboss.windup.exec.configuration.options.SourceOption;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class ListSourceTechnologiesCommand extends AbstractListCommand implements Command, FurnaceDependent
public class ListSourceTechnologiesCommand extends AbstractListCommandWithoutFurnace implements Command
{
@Override
public CommandResult execute()
{
RuleProviderRegistryCache ruleProviderRegistryCache = getFurnace().getAddonRegistry().getServices(RuleProviderRegistryCache.class).get();
printValuesSorted("Available source technologies", ruleProviderRegistryCache.getAvailableSourceTechnologies());
printValuesSorted("Available source technologies", getOptionValuesFromHelp(SourceOption.NAME));
return CommandResult.EXIT;
}

@Override
public CommandPhase getPhase()
{
return CommandPhase.PRE_EXECUTION;
return CommandPhase.PRE_CONFIGURATION;
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package org.jboss.windup.bootstrap.commands.windup;

import org.jboss.windup.bootstrap.commands.AbstractListCommand;
import org.jboss.windup.bootstrap.commands.AbstractListCommandWithoutFurnace;
import org.jboss.windup.bootstrap.commands.Command;
import org.jboss.windup.bootstrap.commands.CommandPhase;
import org.jboss.windup.bootstrap.commands.CommandResult;
import org.jboss.windup.bootstrap.commands.FurnaceDependent;
import org.jboss.windup.config.metadata.RuleProviderRegistryCache;
import org.jboss.windup.exec.configuration.options.IncludeTagsOption;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class ListTagsCommand extends AbstractListCommand implements Command, FurnaceDependent
public class ListTagsCommand extends AbstractListCommandWithoutFurnace implements Command
{
@Override
public CommandResult execute()
{
RuleProviderRegistryCache ruleProviderRegistryCache = getFurnace().getAddonRegistry().getServices(RuleProviderRegistryCache.class).get();
printValuesSorted("Available tags", ruleProviderRegistryCache.getAvailableTags());
printValuesSorted("Available tags", getOptionValuesFromHelp(IncludeTagsOption.NAME));
return CommandResult.EXIT;
}

@Override
public CommandPhase getPhase()
{
return CommandPhase.PRE_EXECUTION;
return CommandPhase.PRE_CONFIGURATION;
}

}
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package org.jboss.windup.bootstrap.commands.windup;

import org.jboss.windup.bootstrap.commands.AbstractListCommand;
import org.jboss.windup.bootstrap.commands.AbstractListCommandWithoutFurnace;
import org.jboss.windup.bootstrap.commands.Command;
import org.jboss.windup.bootstrap.commands.CommandPhase;
import org.jboss.windup.bootstrap.commands.CommandResult;
import org.jboss.windup.bootstrap.commands.FurnaceDependent;
import org.jboss.windup.config.metadata.RuleProviderRegistryCache;
import org.jboss.windup.exec.configuration.options.TargetOption;

/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*/
public class ListTargetTechnologiesCommand extends AbstractListCommand implements Command, FurnaceDependent
public class ListTargetTechnologiesCommand extends AbstractListCommandWithoutFurnace implements Command
{
@Override
public CommandResult execute()
{
RuleProviderRegistryCache ruleProviderRegistryCache = getFurnace().getAddonRegistry().getServices(RuleProviderRegistryCache.class).get();
printValuesSorted("Available target technologies", ruleProviderRegistryCache.getAvailableTargetTechnologies());
printValuesSorted("Available target technologies", getOptionValuesFromHelp(TargetOption.NAME));
return CommandResult.EXIT;
}

@Override
public CommandPhase getPhase()
{
return CommandPhase.PRE_EXECUTION;
return CommandPhase.PRE_CONFIGURATION;
}

}