Skip to content

Commit

Permalink
WINDUP-701 Fix automatic rulesets updating - Bootstrap args processing
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraZizka committed Jul 30, 2015
1 parent ca77162 commit 81114f6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
45 changes: 38 additions & 7 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 @@ -35,6 +36,7 @@
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 Down Expand Up @@ -237,9 +239,7 @@ else if (arg.startsWith("--updateRules"))
{
final String arg = arguments.get(i);
if (unknownArgs.contains(arg))
{
arguments.set(i, null);
}
arguments.remove(i);
}

// Move Windup arguments to --evaluate '...'
Expand All @@ -257,9 +257,13 @@ else if (arg.startsWith("--updateRules"))
furnaceService.getFurnace().addRepository(AddonRepositoryMode.MUTABLE, new File(getUserWindupDir(), "addons"));
}

if (command == null && updateRulesets && onlyRulesetsUpdateRequested(arguments))
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)
Expand Down Expand Up @@ -300,11 +304,15 @@ else if (command == null)
if(command == null)
command = BootstrapCommand.UPDATE_RULESETS;

System.out.println("Updating Rulesets...");
System.out.println("Checking for rulesets updates...");
try {
Imported<DependencyResolver> resolver = furnace.getAddonRegistry().getServices(DependencyResolver.class);
//new RulesetsUpdater(resolver.get(), furnace).replaceRulesetsDirectoryWithLatestRelease();
furnace.getAddonRegistry().getServices(RulesetsUpdater.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)
{
Expand All @@ -331,6 +339,8 @@ else if (command == null)
case RUN_WINDUP:
runWindup(windupArguments);
break;
case UPDATE_RULESETS:
break;
case DISPLAY_HELP:
default:
displayHelp();
Expand Down Expand Up @@ -834,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 @@ -59,6 +59,9 @@ public boolean rulesetsNeedUpdate()
MavenModelResource pom = (MavenModelResource) factory.create(pomXml);
SingleVersion installed = new SingleVersion(pom.getCurrentModel().getVersion());
SingleVersion latest = new SingleVersion(lastRelease.getVersion());
final String msg = "Core rulesets: Installed: " + installed + " Latest release: " + latest;
log.info(msg);
System.out.println(msg); // Print to both to have the info in the log too.
return 0 > installed.compareTo(latest);
}

Expand All @@ -73,7 +76,7 @@ public Path getRulesetsDir()
}


public String replaceRulesetsDirectoryWithLatestRelease() throws IOException, DependencyException
public String replaceRulesetsDirectoryWithLatestReleaseIfAny() throws IOException, DependencyException
{
if (!this.rulesetsNeedUpdate())
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public UICommandMetadata getMetadata(UIContext ctx)
@Override
public Result execute(UIExecutionContext context) throws Exception
{
String updatedTo = updater.replaceRulesetsDirectoryWithLatestRelease();
String updatedTo = updater.replaceRulesetsDirectoryWithLatestReleaseIfAny();

if (updatedTo == null)
return Results.fail("The ruleset is already in the most updated version.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void testUpdateRuleset() throws Exception
{
boolean rulesetNeedUpdate = this.updater.rulesetsNeedUpdate();
Assert.assertTrue("Rulesets should need an update.", rulesetNeedUpdate);
updater.replaceRulesetsDirectoryWithLatestRelease();
updater.replaceRulesetsDirectoryWithLatestReleaseIfAny();
Assert.assertFalse("Rulesets should not need an update.", this.updater.rulesetsNeedUpdate());
}
catch (Throwable ex){
Expand Down

0 comments on commit 81114f6

Please sign in to comment.