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

Fix update rulesets - WINDUP-701 #643

Closed
Closed
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
10 changes: 10 additions & 0 deletions bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>dependencies</artifactId>
<version>2.16.2.Final</version>
</dependency>


<dependency>
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-manager</artifactId>
Expand All @@ -51,6 +59,8 @@
<groupId>org.jboss.forge.furnace</groupId>
<artifactId>furnace-se</artifactId>
</dependency>


<!-- Optional log manager dependency -->
<dependency>
<groupId>org.jboss.logmanager</groupId>
Expand Down
192 changes: 117 additions & 75 deletions bootstrap/src/main/java/org/jboss/windup/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Path;
import java.nio.file.attribute.FileTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -26,12 +27,16 @@
import java.util.concurrent.TimeUnit;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.jboss.forge.addon.dependencies.DependencyResolver;
import org.jboss.forge.furnace.Furnace;
import org.jboss.forge.furnace.impl.addons.AddonRepositoryImpl;
import org.jboss.forge.furnace.repositories.AddonRepository;
import org.jboss.forge.furnace.repositories.AddonRepositoryMode;
import org.jboss.forge.furnace.repositories.MutableAddonRepository;
import org.jboss.forge.furnace.se.FurnaceFactory;
import org.jboss.forge.furnace.services.Imported;
import org.jboss.forge.furnace.util.Assert;
import org.jboss.forge.furnace.util.OperatingSystemUtils;
import org.jboss.forge.furnace.versions.EmptyVersion;
import org.jboss.forge.furnace.versions.SingleVersion;
Expand All @@ -46,6 +51,7 @@
import org.jboss.windup.exec.configuration.options.InputPathOption;
import org.jboss.windup.exec.configuration.options.OutputPathOption;
import org.jboss.windup.exec.configuration.options.OverwriteOption;
import org.jboss.windup.exec.updater.RulesetsUpdater;
import org.jboss.windup.graph.GraphContext;
import org.jboss.windup.graph.GraphContextFactory;
import org.jboss.windup.util.PathUtil;
Expand Down Expand Up @@ -148,6 +154,7 @@ private void processArguments(List<String> arguments, BootstrapFurnaceService fu
command = BootstrapCommand.DISPLAY_HELP;
}
String addonID = null;
boolean updateRulesets = false;

List<String> unknownArgs = new ArrayList<>();
List<File> mutableRepos = new ArrayList<>();
Expand Down Expand Up @@ -214,6 +221,10 @@ else if ("--generateCompletionData".equals(arg))
{
command = BootstrapCommand.GENERATE_COMPLETION_DATA;
}
else if (arg.startsWith("--updateRules"))
{
updateRulesets = true;
}
else
{
unknownArgs.add(arg);
Expand All @@ -228,25 +239,13 @@ else if ("--generateCompletionData".equals(arg))
{
final String arg = arguments.get(i);
if (unknownArgs.contains(arg))
{
arguments.set(i, null);
}
}

// Make it a List, Get rid of nulls.
List<String> argsList = new ArrayList<>(arguments.size() + 2);
for (String arg : arguments)
{
if (arg != null)
argsList.add(arg);
arguments.remove(i);
}

// Move Windup arguments to --evaluate '...'
List<String> windupArguments = new ArrayList<>();
if (!unknownArgs.isEmpty())
{
setupNonInteractive(furnace);

// Pass unknown arguments to Windup (Forge).
for (String windupArg : unknownArgs)
windupArguments.add(windupArg);
Expand All @@ -258,31 +257,32 @@ else if ("--generateCompletionData".equals(arg))
furnaceService.getFurnace().addRepository(AddonRepositoryMode.MUTABLE, new File(getUserWindupDir(), "addons"));
}

if (command == null && updateRulesets && onlyRulesetsUpdateRequested(arguments))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if --updateRulesets is specified in addition to windup execution/analysis information? It currently looks like it will skip the ruleset update silently. That doesn't seem right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we probably need to be able to do both comments (e.g. allow multiple commands to be executed based on CLI values supplied.)

command = BootstrapCommand.UPDATE_RULESETS;

if (command == null && !windupArguments.isEmpty())
command = BootstrapCommand.RUN_WINDUP;
else if (command == null)

if (command == null)
command = BootstrapCommand.DISPLAY_HELP;

switch (command)
{
case LIST_INSTALLED_ADDONS:
furnaceService.list();
break;
case INSTALL_ADDON:
furnaceService.install(addonID, this.batchMode);
break;
case REMOVE_ADDON:
furnaceService.remove(addonID, this.batchMode);
break;
case GENERATE_COMPLETION_DATA:
break;
default:
break;
case LIST_INSTALLED_ADDONS:
furnaceService.list();
break;
case INSTALL_ADDON:
furnaceService.install(addonID, this.batchMode);
break;
case REMOVE_ADDON:
furnaceService.remove(addonID, this.batchMode);
break;
}

// Start Furnace service if we are going to need it.
try
{
if (command == BootstrapCommand.RUN_WINDUP)
if (command == BootstrapCommand.RUN_WINDUP || command == BootstrapCommand.UPDATE_RULESETS)
furnace.addContainerLifecycleListener(new GreetingListener());
Future<Furnace> future = furnaceService.start(true);
// use future.get() to wait until it is started
Expand All @@ -296,29 +296,55 @@ else if (command == null)
e.printStackTrace();
}


// Update rulesets
if (updateRulesets)
{
// Prevent help from being printed.
if(command == null)
command = BootstrapCommand.UPDATE_RULESETS;

System.out.println("Checking for rulesets updates...");
try {
Imported<DependencyResolver> resolver = furnace.getAddonRegistry().getServices(DependencyResolver.class);
//new RulesetsUpdater(resolver.get(), furnace).replaceRulesetsDirectoryWithLatestReleaseIfAny();
Imported<RulesetsUpdater> services = furnace.getAddonRegistry().getServices(RulesetsUpdater.class);
Assert.notNull(services, "Couldn't find the " + RulesetsUpdater.class.getSimpleName() + " service.");
RulesetsUpdater updater = services.get();
String newVersion = updater.replaceRulesetsDirectoryWithLatestReleaseIfAny();
System.out.println("Updated the rulesets to version " + newVersion + ".");
}
catch (Throwable ex)
{
System.err.println("Could not update the rulesets: " + ex.getMessage());
ex.printStackTrace(System.err);
}
}


switch (command)
{
case GENERATE_COMPLETION_DATA:
generateCompletionData(true);
break;
case DISPLAY_HELP:
displayHelp();
break;
case LIST_TAGS:
listTags();
break;
case LIST_SOURCE_TECHNOLOGIES:
listSourceTechnologies();
break;
case LIST_TARGET_TECHNOLOGIES:
listTargetTechnologies();
break;
case RUN_WINDUP:
runWindup(windupArguments);
break;
default:
displayHelp();
break;
case GENERATE_COMPLETION_DATA:
generateCompletionData(true);
break;
case LIST_TAGS:
listTags();
break;
case LIST_SOURCE_TECHNOLOGIES:
listSourceTechnologies();
break;
case LIST_TARGET_TECHNOLOGIES:
listTargetTechnologies();
break;
case RUN_WINDUP:
runWindup(windupArguments);
break;
case UPDATE_RULESETS:
break;
case DISPLAY_HELP:
default:
displayHelp();
break;
}
}

Expand Down Expand Up @@ -374,17 +400,17 @@ private void generateCompletionData(boolean force)
}
try (FileWriter writer = new FileWriter(completionPath.toFile()))
{
writer.write("listTags:none" + OperatingSystemUtils.getLineSeparator());
writer.write("listSourceTechnologies:none" + OperatingSystemUtils.getLineSeparator());
writer.write("listTargetTechnologies:none" + OperatingSystemUtils.getLineSeparator());
writer.write("install:none" + OperatingSystemUtils.getLineSeparator());
writer.write("remote:none" + OperatingSystemUtils.getLineSeparator());
writer.write("addonDir:file" + OperatingSystemUtils.getLineSeparator());
writer.write("immutableAddonDir:file" + OperatingSystemUtils.getLineSeparator());
writer.write("batchMode:none" + OperatingSystemUtils.getLineSeparator());
writer.write("debug:none" + OperatingSystemUtils.getLineSeparator());
writer.write("help:none" + OperatingSystemUtils.getLineSeparator());
writer.write("version:none" + OperatingSystemUtils.getLineSeparator());
writer.write("listTags:none" + NEW_LINE);
writer.write("listSourceTechnologies:none" + NEW_LINE);
writer.write("listTargetTechnologies:none" + NEW_LINE);
writer.write("install:none" + NEW_LINE);
writer.write("remote:none" + NEW_LINE);
writer.write("addonDir:file" + NEW_LINE);
writer.write("immutableAddonDir:file" + NEW_LINE);
writer.write("batchMode:none" + NEW_LINE);
writer.write("debug:none" + NEW_LINE);
writer.write("help:none" + NEW_LINE);
writer.write("version:none" + NEW_LINE);

Iterable<ConfigurationOption> optionIterable = WindupConfiguration.getWindupConfigurationOptions(furnaceService.getFurnace());
for (ConfigurationOption option : optionIterable)
Expand All @@ -402,7 +428,7 @@ else if (option.getUIType() == InputType.SELECT_MANY || option.getUIType() == In
else
line.append("none");

line.append(OperatingSystemUtils.getLineSeparator());
line.append(NEW_LINE);
writer.write(line.toString());
}
}
Expand All @@ -413,6 +439,10 @@ else if (option.getUIType() == InputType.SELECT_MANY || option.getUIType() == In
}
}

private static final String NEW_LINE = OperatingSystemUtils.getLineSeparator();



@SuppressWarnings("unchecked")
private void runWindup(List<String> arguments)
{
Expand Down Expand Up @@ -454,28 +484,19 @@ private void runWindup(List<String> arguments)

String valueString = arguments.get(i);
// lists are space delimited... split them here
if (valueString.contains(" "))
{
for (String value : valueString.split(" "))
{
values.add(convertType(option.getType(), value));
}
}
else
{
values.add(convertType(option.getType(), valueString));
}
for (String value : StringUtils.split(valueString, ' '))
values.add(convertType(option.getType(), value));

i++;
}

/*
* This allows us to support specifying a parameter multiple times.
*
*
* For example:
*
*
* `windup --packages foo --packages bar --packages baz`
*
*
* While this is not necessarily the recommended approach, it would be nice for it to work smoothly if
* someone does it this way.
*/
Expand Down Expand Up @@ -823,4 +844,25 @@ public static Version getRuntimeAPIVersion()
}
return EmptyVersion.getInstance();
}


private boolean onlyRulesetsUpdateRequested(List<String> arguments)
{
List<String> nonActionableArguments = Arrays.asList(new String[]{
"--debug", "--addonDir", "--immutableAddonDir", "--batchMode"
});

for (String arg : arguments)
{
if (!arg.startsWith("-"))
continue;
if (arg.startsWith("--updateRules"))
continue;
if (nonActionableArguments.contains(arg))
continue;
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public enum BootstrapCommand {
LIST_INSTALLED_ADDONS,
INSTALL_ADDON,
REMOVE_ADDON,
UPDATE_RULESETS,
}
14 changes: 14 additions & 0 deletions exec/addon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>dependencies</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>maven</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>


</dependencies>


Expand Down
8 changes: 8 additions & 0 deletions exec/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,13 @@
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.jboss.forge.addon</groupId>
<artifactId>maven</artifactId>
<classifier>forge-addon</classifier>
<scope>provided</scope>
</dependency>

</dependencies>
</project>