Skip to content

Commit

Permalink
task 884: enabling multiple paths for user custom rulesets (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
mareknovotny authored and jsight committed May 31, 2017
1 parent 7f2ba31 commit d7bc90f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ else if (Boolean.class.isAssignableFrom(option.getType()))
setDefaultOptionsValues(options, optionValues);

RuleProviderRegistryCache ruleProviderRegistryCache = furnace.getAddonRegistry().getServices(RuleProviderRegistryCache.class).get();
File userProvidedPath = (File) optionValues.get(UserRulesDirectoryOption.NAME);
if (userProvidedPath != null)
Iterable<File> userProvidedPaths = (Iterable<File>) optionValues.get(UserRulesDirectoryOption.NAME);
if (userProvidedPaths != null)
{
ruleProviderRegistryCache.addUserRulesPath(userProvidedPath.toPath());
for (File userProvidedPath : userProvidedPaths)
{
ruleProviderRegistryCache.addUserRulesPath(userProvidedPath.toPath());
}
}

// Target - interactive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public Collection<Path> getInputPaths()
Collection<Path> inputPaths = getOptionValue(InputPathOption.NAME);
return inputPaths;
}

/**
* Contains the directory to put the output to (migration report, temporary files, exported graph data...).
*/
Expand All @@ -252,10 +252,13 @@ public Iterable<Path> getAllUserRulesDirectories()
{
Set<Path> results = new HashSet<>();
results.addAll(getDefaultUserRulesDirectories());
File userSpecifiedFile = getOptionValue(UserRulesDirectoryOption.NAME);
if (userSpecifiedFile != null)

Collection<File> userSpecifiedFiles = getOptionValue(UserRulesDirectoryOption.NAME);
if (userSpecifiedFiles != null && !userSpecifiedFiles.isEmpty())
{
results.add(userSpecifiedFile.toPath());
userSpecifiedFiles.stream().forEach(file -> {
results.add(file.toPath());
});
}
return results;
}
Expand Down Expand Up @@ -318,17 +321,24 @@ public WindupConfiguration addDefaultUserRulesDirectory(Path path)
setOptionValue(DEFAULT_USER_RULES_DIRECTORIES_OPTION, paths);
}

File userSpecifiedRulePath = getOptionValue(UserRulesDirectoryOption.NAME);
if (userSpecifiedRulePath != null && userSpecifiedRulePath.toPath().equals(path))
{
return this;
}

for (Path existingPath : paths)
Iterable<File> userRulesDirs= getOptionValue(UserRulesDirectoryOption.NAME);
if (userRulesDirs != null)
{
if (existingPath.equals(path))
for (File userSpecifiedRuleFile : userRulesDirs)
{
return this;

if (userSpecifiedRuleFile != null && userSpecifiedRuleFile.toPath().equals(path))
{
return this;
}

for (Path existingPath : paths)
{
if (existingPath.equals(path))
{
return this;
}
}
}
}
paths.add(path);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.jboss.windup.exec.configuration.options;

import java.io.File;
import java.nio.file.Path;

import org.jboss.windup.config.AbstractPathConfigurationOption;
import org.jboss.windup.config.InputType;

/**
* Indicates the directory that will contain rules provided by the user.
* Indicates the directory or directories that will contain rules provided by the user.
* Multiple paths can be specified separated by a space (for example, --userRulesDirectory PATH_1 PATH_2).
*
* @author <a href="mailto:jesse.sightler@gmail.com">Jesse Sightler</a>
*
Expand Down Expand Up @@ -33,13 +37,19 @@ public String getLabel()
@Override
public String getDescription()
{
return "User Rules Directory (Search pattern: *.windup.groovy, *.windup.xml, *.rhamt.groovy and *.rhamt.xml).";
return "User Rules Directory (Search pattern: *.windup.groovy, *.windup.xml, *.rhamt.groovy and *.rhamt.xml). Multiple paths can be specified separated by a space (for example, --userRulesDirectory PATH_1 PATH_2).";
}

@Override
public Class<?> getType()
{
return File.class;
}

@Override
public InputType getUIType()
{
return InputType.DIRECTORY;
return InputType.MANY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void testRunWindupSourceMode() throws Exception
// The test-files folder in the project root dir.
List<String> includeList = Collections.emptyList();
List<String> excludeList = Collections.emptyList();
super.runTest(context, "../test-files/src_example", userPath.toFile(), true, includeList, excludeList);
super.runTest(context, "../test-files/src_example", Collections.singletonList(userPath.toFile()), true, includeList, excludeList);

validateWebXmlReferences(context);
validatePropertiesModels(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testRunWindupSourceMode() throws Exception
// The test-files folder in the project root dir.
List<String> includeList = Collections.emptyList();
List<String> excludeList = Collections.emptyList();
super.runTest(context, "../test-files/src_example", userPath.toFile(), true, includeList, excludeList);
super.runTest(context, "../test-files/src_example", Collections.singletonList(userPath.toFile()), true, includeList, excludeList);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,28 +121,28 @@ void runTest(GraphContext graphContext, Iterable<String> inputPaths, boolean sou

void runTest(final GraphContext graphContext,
final String inputPath,
final File userRulesDir,
final Iterable<File> userRulesDirs,
final boolean sourceMode,
final List<String> includePackages,
final List<String> excludePackages) throws Exception
{
runTest(graphContext, Collections.singletonList(inputPath), userRulesDir, sourceMode, includePackages, excludePackages);
runTest(graphContext, Collections.singletonList(inputPath), userRulesDirs, sourceMode, includePackages, excludePackages);
}

void runTest(final GraphContext graphContext,
final Iterable<String> inputPaths,
final File userRulesDir,
final Iterable<File> userRulesDirs,
final boolean sourceMode,
final List<String> includePackages,
final List<String> excludePackages) throws Exception
{
Map<String, Object> otherOptions = Collections.emptyMap();
runTest(graphContext, inputPaths, userRulesDir, sourceMode, includePackages, excludePackages, otherOptions);
runTest(graphContext, inputPaths, userRulesDirs, sourceMode, includePackages, excludePackages, otherOptions);
}

void runTest(final GraphContext graphContext,
final Iterable<String> inputPaths,
final File userRulesDir,
final Iterable<File> userRulesDirs,
final boolean sourceMode,
final List<String> includePackages,
final List<String> excludePackages,
Expand All @@ -158,9 +158,10 @@ void runTest(final GraphContext graphContext,
windupConfiguration.addInputPath(Paths.get(inputPath));
}
windupConfiguration.setOutputDirectory(graphContext.getGraphDirectory());
if (userRulesDir != null)
{
windupConfiguration.setOptionValue(UserRulesDirectoryOption.NAME, userRulesDir);
if (userRulesDirs != null) {
for (File uRulesDir : userRulesDirs) {
windupConfiguration.addDefaultUserRulesDirectory(uRulesDir.toPath());
}
}
windupConfiguration.setOptionValue(SourceModeOption.NAME, sourceMode);
windupConfiguration.setOptionValue(ScanPackagesOption.NAME, includePackages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public void testUserRulesDirMigration() throws Exception
File userRulesDir = FileUtils.getTempDirectory().toPath().resolve("Windup")
.resolve("windupcommanduserrules_" + RandomStringUtils.randomAlphanumeric(6)).toFile();
userRulesDir.mkdirs();
controller.setValueFor("userRulesDirectory", userRulesDir);
controller.setValueFor(UserRulesDirectoryOption.NAME, Collections.singletonList(userRulesDir));

Result result = controller.execute();
final String msg = "controller.execute() 'Failed': " + result.getMessage();
Expand All @@ -303,8 +303,8 @@ public void testUserRulesDirMigration() throws Exception
WindupConfiguration windupConfiguration = (WindupConfiguration) controller.getContext()
.getAttributeMap()
.get(WindupConfiguration.class);
File resultUserSpecifiedRulesDir = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME);
Assert.assertEquals(userRulesDir, resultUserSpecifiedRulesDir);
List<File> resultUserSpecifiedRulesDirs = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME);
Assert.assertEquals(1, resultUserSpecifiedRulesDirs.size());

Iterable<Path> allRulesPaths = windupConfiguration.getAllUserRulesDirectories();

Expand Down Expand Up @@ -369,7 +369,7 @@ public void testDuplicateUserRulesDirMigration() throws Exception

Path expectedUserHomeRulesDir = PathUtil.getUserRulesDir();
expectedUserHomeRulesDir.toFile().mkdirs();
controller.setValueFor("userRulesDirectory", expectedUserHomeRulesDir.toFile());
controller.setValueFor(UserRulesDirectoryOption.NAME, Collections.singletonList(expectedUserHomeRulesDir.toFile()));

Result result = controller.execute();
final String msg = "controller.execute() 'Failed': " + result.getMessage();
Expand All @@ -378,8 +378,9 @@ public void testDuplicateUserRulesDirMigration() throws Exception
WindupConfiguration windupConfiguration = (WindupConfiguration) controller.getContext()
.getAttributeMap()
.get(WindupConfiguration.class);
File resultUserSpecifiedRulesDir = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME);
Assert.assertEquals(expectedUserHomeRulesDir.toFile(), resultUserSpecifiedRulesDir);
Collection<File> resultUserSpecifiedRulesDirs = windupConfiguration.getOptionValue(UserRulesDirectoryOption.NAME);

Assert.assertEquals(expectedUserHomeRulesDir.toFile(), resultUserSpecifiedRulesDirs.iterator().next());

Iterable<Path> allRulesPaths = windupConfiguration.getAllUserRulesDirectories();

Expand Down

0 comments on commit d7bc90f

Please sign in to comment.