public TypeData(final List<String> includes, final List<String> excludes, final boolean strict, final String[] jsonNames, final String[] realNames) { rules = new InExRules<>(); for (String include : includes) { rules.include(include); } for (String exclude : excludes) { rules.exclude(exclude); } this.strict = strict; this.jsonNames = jsonNames; this.realNames = realNames; }
/** * Returns <code>true</code> if some entry name has to be accepted. * @see #prepareEntryName(String, boolean) * @see #scanEntry(ClassPathEntry) */ protected boolean acceptEntry(final String entryName) { return rulesEntries.match(entryName); }
/** * Reset the search so it can be run again with very * same parameters (and sorting options). */ public void reset() { pathList = pathListOriginal; pathListOriginal = null; todoFiles = null; lastFile = null; rules.reset(); }
@Test void testIncludeExcludes() { InExRules<String, String, String> inExRules = new InExRules<>(InExRuleMatcher.WILDCARD_RULE_MATCHER); assertTrue(inExRules.isBlacklist()); assertFalse(inExRules.isWhitelist()); inExRules.reset(); inExRules.blacklist(); // default inExRules.exclude("*"); assertFalse(inExRules.match("foo")); assertFalse(inExRules.match("fight")); assertFalse(inExRules.match("bar")); inExRules.reset(); inExRules.whitelist(); assertFalse(inExRules.match("foo")); assertFalse(inExRules.match("fight")); assertFalse(inExRules.match("bar")); inExRules.reset(); inExRules.whitelist(); inExRules.include("foo"); assertTrue(inExRules.match("foo")); assertFalse(inExRules.match("fight")); assertFalse(inExRules.match("bar"));
/** * Specify included jars. */ public ClassScanner includeJars(final String... includedJars) { for (final String includedJar : includedJars) { rulesJars.include(includedJar); } return this; }
/** * Specify excluded jars. */ public ClassScanner excludeJars(final String... excludedJars) { for (final String excludedJar : excludedJars) { rulesJars.exclude(excludedJar); } return this; }
@Test void testSmartMode() { InExRules<String, String, String> inExRules = new InExRules<>(InExRuleMatcher.WILDCARD_RULE_MATCHER); assertTrue(inExRules.isBlacklist()); assertFalse(inExRules.isWhitelist()); inExRules.include("xxx"); inExRules.detectMode(); assertFalse(inExRules.isBlacklist()); assertTrue(inExRules.isWhitelist()); }
/** * Adds excludes with optional parent including. When parents are included, * for each exclude query its parent will be included. * For example, exclude of 'aaa.bb.ccc' would include it's parent: 'aaa.bb'. */ public JsonSerializer exclude(final boolean includeParent, final String... excludes) { for (String exclude : excludes) { if (includeParent) { int dotIndex = exclude.lastIndexOf('.'); if (dotIndex != -1) { PathQuery pathQuery = new PathQuery(exclude.substring(0, dotIndex), true); rules.include(pathQuery); } } PathQuery pathQuery = new PathQuery(exclude, false); rules.exclude(pathQuery); } return this; }
/** * Creates rule engine. */ protected InExRules<String, String, ?> createRulesEngine() { return new InExRules<>(); }
/** * Matched current path to queries. If match is found, provided include * value may be changed. */ public boolean matchPathToQueries(final boolean include) { return jsonSerializer.rules.apply(path, include); }
/** * Initializes file walking. * Separates input files and folders. */ protected void init() { rules.detectMode(); todoFiles = new LinkedList<>(); todoFolders = new LinkedList<>(); if (pathList == null) { pathList = new LinkedList<>(); return; } if (pathListOriginal == null) { pathListOriginal = (LinkedList<File>) pathList.clone(); } String[] files = new String[pathList.size()]; int index = 0; Iterator<File> iterator = pathList.iterator(); while (iterator.hasNext()) { File file = iterator.next(); if (file.isFile()) { files[index++] = file.getAbsolutePath(); iterator.remove(); } } if (index != 0) { FilesIterator filesIterator = new FilesIterator(files); todoFiles.add(filesIterator); } }
/** * Enables whitelist mode. */ public FindFile excludeAll() { rules.whitelist(); return this; }
/** * Enables blacklist mode. */ public FindFile includeAll() { rules.blacklist(); return this; }
/** * Defines include patterns. */ public FindFile include(final String... patterns) { for (String pattern : patterns) { rules.include(pattern); } return this; }
/** * Defines exclude pattern. */ public FindFile exclude(final String pattern) { rules.exclude(pattern); return this; }
public InExRules<String, String, String> create() { return new InExRules<>(); }
/** * Applies rules on given flag using current black/white list mode. * @see #apply(Object, boolean, boolean) */ public boolean apply(final V value, final boolean flag) { return apply(value, blacklist, flag); }
/** * Starts with the scanner. */ public void start() { if (detectEntriesMode) { rulesEntries.detectMode(); } filesToScan.forEach(file -> { final String path = file.getAbsolutePath(); if (StringUtil.endsWithIgnoreCase(path, JAR_FILE_EXT)) { if (!acceptJar(file)) { return; } scanJarFile(file); } else if (file.isDirectory()) { scanClassPath(file); } }); }