Skip to content

Commit

Permalink
WINDUP-369: Be able to focus effort on specific jars in the ear or war
Browse files Browse the repository at this point in the history
  • Loading branch information
Matej Briskar committed Nov 7, 2014
1 parent b859260 commit 0fb3c1e
Show file tree
Hide file tree
Showing 16 changed files with 500 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.jboss.windup.exec.configuration.options.InputPathOption;
import org.jboss.windup.exec.configuration.options.OfflineModeOption;
import org.jboss.windup.exec.configuration.options.OutputPathOption;
import org.jboss.windup.exec.configuration.options.UserIgnorePathOption;
import org.jboss.windup.exec.configuration.options.UserRulesDirectoryOption;
import org.jboss.windup.graph.GraphContext;

Expand All @@ -35,6 +36,7 @@
public class WindupConfiguration
{
private static final String DEFAULT_USER_RULES_DIRECTORIES_OPTION = "defaultUserRulesDirectories";
private static final String DEFAULT_USER_IGNORE_DIRECTORIES_OPTION = "defaultUserIgnorePaths";

private Predicate<WindupRuleProvider> ruleProviderFilter;
private WindupProgressMonitor progressMonitor = new NullWindupProgressMonitor();
Expand Down Expand Up @@ -167,6 +169,19 @@ public Iterable<Path> getAllUserRulesDirectories()
}
return results;
}

public Iterable<Path> getAllIgnoreDirectories()
{
Set<Path> results = new HashSet<>();
results.addAll(getDefaultUserIgnoreDirectories());
File userSpecifiedFile = getOptionValue(UserIgnorePathOption.NAME);
if (userSpecifiedFile != null)
{
results.add(userSpecifiedFile.toPath());
}
return results;
}


/**
* Contains a list of {@link Path}s with directories that contains user provided rules.
Expand All @@ -180,6 +195,16 @@ public List<Path> getDefaultUserRulesDirectories()
}
return Collections.unmodifiableList(paths);
}

public List<Path> getDefaultUserIgnoreDirectories()
{
List<Path> paths = getOptionValue(DEFAULT_USER_IGNORE_DIRECTORIES_OPTION);
if (paths == null)
{
return Collections.emptyList();
}
return Collections.unmodifiableList(paths);
}

/**
* Contains a list of {@link Path}s with the directory that contains user provided rules.
Expand Down Expand Up @@ -211,6 +236,32 @@ public WindupConfiguration addDefaultUserRulesDirectory(Path path)
paths.add(path);
return this;
}

public WindupConfiguration addDefaultUserIgnorePath(Path path)
{
List<Path> paths = getOptionValue(DEFAULT_USER_IGNORE_DIRECTORIES_OPTION);
if (paths == null)
{
paths = new ArrayList<>();
setOptionValue(DEFAULT_USER_IGNORE_DIRECTORIES_OPTION, paths);
}

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

for (Path existingPath : paths)
{
if (existingPath.equals(path))
{
return this;
}
}
paths.add(path);
return this;
}

public Predicate<WindupRuleProvider> getRuleProviderFilter()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.jboss.windup.exec.configuration.options;

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

public class UserIgnorePathOption extends AbstractPathConfigurationOption
{

public static final String NAME = "userIgnorePath";

public UserIgnorePathOption()
{
super(true);
}

@Override
public String getName()
{
return NAME;
}

@Override
public String getLabel()
{
return "User Ignore Path";
}

@Override
public String getDescription()
{
return "User Ignore Path. In case of directory it rakes all the files inside matching the pattern. (Search pattern: *windup-ignore.txt)";
}

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

@Override
public boolean isRequired()
{
return false;
}

@Override
public int getPriority()
{
return 7000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void execute(WindupConfiguration windupConfiguration)
{
configModel.addUserRulesPath(getFileModel(context, path));
}

for (Path path : windupConfiguration.getAllIgnoreDirectories())
{
configModel.addUserIgnorePath(getFileModel(context, path));
}

GraphRewrite event = new GraphRewrite(context);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface WindupConfigurationModel extends WindupVertexFrame
public static final String TYPE = "BaseWindupConfiguration";

public static final String USER_RULES_PATH = "userRulesPath";
public static final String USER_IGNORE_PATH = "userIgnorePath";
public static final String OFFLINE_MODE = "fetchRemoteResources";

/**
Expand All @@ -37,12 +38,24 @@ public interface WindupConfigurationModel extends WindupVertexFrame
*/
@Adjacency(label = USER_RULES_PATH, direction = Direction.OUT)
void addUserRulesPath(FileModel userRulesPath);

/**
* The location for user provided ignore directory (list of ignored jar files)
*/
@Adjacency(label = USER_IGNORE_PATH, direction = Direction.OUT)
void addUserIgnorePath(FileModel userIgnorePath);

/**
* The location for user provided rules directories (typically Groovy or XML Rules)
*/
@Adjacency(label = USER_RULES_PATH, direction = Direction.OUT)
Iterable<FileModel> getUserRulesPaths();

/**
* The location for user provided rules directories (typically Groovy or XML Rules)
*/
@Adjacency(label = USER_IGNORE_PATH, direction = Direction.OUT)
Iterable<FileModel> getUserIgnorePaths();

/**
* Where to put the report and other files produced during Windup execution.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jboss.windup.rules.apps.java.model;

import org.jboss.windup.graph.model.WindupVertexFrame;

import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

@TypeValue(IgnoredFileRegexModel.TYPE)
public interface IgnoredFileRegexModel extends WindupVertexFrame
{

public static final String TYPE = "IgnoredFileRegex";

@Property("name_regex")
public String getRegex();

@Property("name_regex")
public void setRegex(String regex);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jboss.windup.rules.apps.java.model;

import org.jboss.windup.graph.model.WindupVertexFrame;

import com.tinkerpop.frames.Property;
import com.tinkerpop.frames.modules.typedgraph.TypeValue;

@TypeValue(IgnoredPathModel.TYPE)
public interface IgnoredPathModel extends WindupVertexFrame
{

public static final String TYPE = "IgnoredFile";

@Property("name_regex")
public String getRegex();

@Property("name_regex")
public void setRegex(String regex);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface WindupJavaConfigurationModel extends WindupVertexFrame
public static final String SOURCE_MODE = "sourceMode";
public static final String EXCLUDE_JAVA_PACKAGES = "excludeJavaPackages";
public static final String SCAN_JAVA_PACKAGES = "scanJavaPackages";
public static final String IGNORED_FILES = "ignoredFiles";

/**
* Specifies which Java packages should be scanned by windup
Expand All @@ -36,6 +37,16 @@ public interface WindupJavaConfigurationModel extends WindupVertexFrame
*/
@Adjacency(label = SCAN_JAVA_PACKAGES, direction = Direction.OUT)
Iterable<PackageModel> getScanJavaPackages();

/**
* Add a file that will be ignored during the migration.
* @param ignoredFile
*/
@Adjacency(label = IGNORED_FILES, direction = Direction.OUT)
void addIgnoredFileRegex(IgnoredFileRegexModel ignoredFile);

@Adjacency(label = IGNORED_FILES, direction = Direction.OUT)
Iterable<IgnoredFileRegexModel> getIgnoredFileRegexes();

/**
* Specifies which Java packages should be scanned by windup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
import org.jboss.windup.graph.service.FileModelService;
import org.jboss.windup.graph.service.GraphService;
import org.jboss.windup.graph.service.WindupConfigurationService;
import org.jboss.windup.rules.apps.java.service.WindupJavaConfigurationService;
import org.jboss.windup.util.ZipUtil;
import org.jboss.windup.util.exception.WindupException;
import org.ocpsoft.rewrite.context.EvaluationContext;

import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Pattern;

import org.jboss.windup.util.Logging;

public class UnzipArchiveToOutputFolder extends AbstractIterationOperation<ArchiveModel>
Expand Down Expand Up @@ -147,7 +152,8 @@ private void recurseAndAddFiles(GraphContext context, Path tempFolder, FileModel
FileModel parentFileModel)
{
File fileReference = parentFileModel.asFile();

WindupJavaConfigurationService windupJavaConfigurationService = new WindupJavaConfigurationService(
context);
if (fileReference.isDirectory())
{
File[] subFiles = fileReference.listFiles();
Expand All @@ -157,16 +163,23 @@ private void recurseAndAddFiles(GraphContext context, Path tempFolder, FileModel
{
FileModel subFileModel = fileService.createByFilePath(parentFileModel, subFile.getAbsolutePath());
subFileModel.setParentArchive(archiveModel);

//check if this file should not be ignored
if(checkIfIgnored(subFile.getName(),windupJavaConfigurationService.getIgnoredFileRegexes())) {
LOG.info("File/Directory placed in " + subFile.getAbsolutePath() + " was ignored, because matched some of the ignore regex.");
continue;
}

if (subFile.isFile() && ZipUtil.endsWithZipExtension(subFileModel.getFilePath()))
{

File newZipFile = subFileModel.asFile();
ArchiveModel newArchiveModel = GraphService.addTypeToModel(context, subFileModel,
ArchiveModel.class);
newArchiveModel.setParentArchive(archiveModel);
newArchiveModel.setArchiveName(newZipFile.getName());
archiveModel.addChildArchive(newArchiveModel);
unzipToTempDirectory(context, tempFolder, newZipFile, newArchiveModel);

}

if (subFile.isDirectory())
Expand All @@ -177,6 +190,22 @@ private void recurseAndAddFiles(GraphContext context, Path tempFolder, FileModel
}
}
}

private boolean checkIfIgnored(String fileName,List<String> regexes) {
boolean ignored = false;
if (regexes != null && regexes.size()!=0)
{
for (String r : regexes)
{
if (Pattern.matches(r, fileName))
{
ignored = true;
continue;
}
}
}
return ignored;
}

@Override
public String toString()
Expand Down
Loading

0 comments on commit 0fb3c1e

Please sign in to comment.