Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/org/reflections/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public interface Configuration {
/** if true (default), expand super types after scanning, for super types that were not scanned.
* <p>see {@link Reflections#expandSuperTypes(Map, Map)}*/
boolean shouldExpandSuperTypes();

/** if true (default), log the scanning process.
* @return true if logging is enabled, false otherwise
*/
boolean shouldLog();
}
6 changes: 3 additions & 3 deletions src/main/java/org/reflections/Reflections.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ protected Map<String, Map<String, Set<String>>> scan() {
if (entries != null) collect.get(scanner.index()).addAll(entries);
}
} catch (Exception e) {
if (log != null) log.debug("could not scan file {} with scanner {}", file.getRelativePath(), scanner.getClass().getSimpleName(), e);
if (log != null && configuration.shouldLog()) log.debug("could not scan file {} with scanner {}", file.getRelativePath(), scanner.getClass().getSimpleName(), e);
}
}
}
}
} catch (Exception e) {
if (log != null) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e);
if (log != null && configuration.shouldLog()) log.warn("could not create Vfs.Dir from url. ignoring the exception and continuing", e);
}
});

Expand All @@ -206,7 +206,7 @@ protected Map<String, Map<String, Set<String>>> scan() {
Map.Entry::getKey,
HashMap::new,
Collectors.mapping(Map.Entry::getValue, Collectors.toSet())))));
if (log != null) {
if (log != null && configuration.shouldLog()) {
int keys = 0, values = 0;
for (Map<String, Set<String>> map : storeMap.values()) {
keys += map.size();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/reflections/util/ConfigurationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class ConfigurationBuilder implements Configuration {
private boolean isParallel = true;
private ClassLoader[] classLoaders;
private boolean expandSuperTypes = true;
private boolean shouldLog = true;

public ConfigurationBuilder() {
urls = new HashSet<>();
Expand Down Expand Up @@ -232,10 +233,20 @@ public boolean shouldExpandSuperTypes() {
return expandSuperTypes;
}

@Override
public boolean shouldLog() {
return shouldLog;
}

/** if set to true, Reflections will expand super types after scanning.
* <p>see {@link org.reflections.Reflections#expandSuperTypes(Map, Map)} */
public ConfigurationBuilder setExpandSuperTypes(boolean expandSuperTypes) {
this.expandSuperTypes = expandSuperTypes;
return this;
}

public ConfigurationBuilder disableLogging() {
this.shouldLog = false;
return this;
}
}