Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Commit

Permalink
Refactor ConfigOptions to manage removeUnusedAutoconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Jan 22, 2020
1 parent 481e977 commit d9d1f03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
* Encapsulate configurable feature behaviour.
*
* @author Andy Clement
* @author Sebastien Deleuze
*/
public abstract class ConfigOptions {

private final static boolean REMOVE_UNUSED_AUTOCONFIG;

private final static boolean AVOID_LOGBACK;

private final static boolean REMOVE_YAML_SUPPORT;
Expand All @@ -36,6 +39,10 @@ public abstract class ConfigOptions {
private final static String MODE; // 'default'/'light'

static {
REMOVE_UNUSED_AUTOCONFIG = Boolean.valueOf(System.getProperty("removeUnusedAutoconfig", "false"));
if(REMOVE_UNUSED_AUTOCONFIG) {
System.out.println("Removing unused configurations");
}
VERBOSE = Boolean.valueOf(System.getProperty("verbose","false"));
if (VERBOSE) {
System.out.println("Turning on verbose mode for the feature");
Expand All @@ -60,6 +67,10 @@ public abstract class ConfigOptions {
}
}

public static boolean shouldRemoveUnusedAutoconfig() {
return REMOVE_UNUSED_AUTOCONFIG;
}

public static boolean isVerbose() {
return VERBOSE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,6 @@ public class ResourcesHandler {

private DynamicProxiesHandler dynamicProxiesHandler;

private static boolean REMOVE_UNNECESSARY_CONFIGURATIONS;

static {
REMOVE_UNNECESSARY_CONFIGURATIONS = Boolean.valueOf(System.getProperty("removeUnusedAutoconfig", "false"));
System.out.println("Remove unused config = " + REMOVE_UNNECESSARY_CONFIGURATIONS);
}

public ResourcesHandler(ReflectionHandler reflectionHandler, DynamicProxiesHandler dynamicProxiesHandler) {
this.reflectionHandler = reflectionHandler;
this.dynamicProxiesHandler = dynamicProxiesHandler;
Expand Down Expand Up @@ -466,14 +459,14 @@ private void processSpringFactory(TypeSystem ts, URL springFactory) {
+ " configurations");
for (String config : configurations) {
if (!checkAndRegisterConfigurationType(config)) {
if (REMOVE_UNNECESSARY_CONFIGURATIONS) {
if (ConfigOptions.shouldRemoveUnusedAutoconfig()) {
excludedAutoConfigCount++;
SpringFeature.log("Excluding auto-configuration " + config);
forRemoval.add(config);
}
}
}
if (REMOVE_UNNECESSARY_CONFIGURATIONS) {
if (ConfigOptions.shouldRemoveUnusedAutoconfig()) {
System.out.println(
"Excluding " + excludedAutoConfigCount + " auto-configurations from spring.factories file");
configurations.removeAll(forRemoval);
Expand Down Expand Up @@ -617,7 +610,7 @@ private boolean processType(Type type, Set<String> visited, int depth) {
// ...
// @ConditionalOnProperty(prefix = "spring.datasource", name = "type")
// static class ExplicitType {
if (depth==0 && REMOVE_UNNECESSARY_CONFIGURATIONS && conditionalOnPropertyValues.size()!=0 &&
if (depth==0 && ConfigOptions.shouldRemoveUnusedAutoconfig() && conditionalOnPropertyValues.size()!=0 &&
(conditionalOnPropertyValues.get("matchIfMissing")==null || conditionalOnPropertyValues.get("matchIfMissing").equals("false"))) {
SpringFeature.log(spaces(depth) + "skipping "+type.getName()+" due to ConditionalOnPropertyCheck");
passesTests = false;
Expand Down Expand Up @@ -696,7 +689,7 @@ private boolean processType(Type type, Set<String> visited, int depth) {
// TODO this should be pushed earlier and access requests put into tar
String configNameDotted = type.getDottedName();
visited.add(type.getName());
if (passesTests || !REMOVE_UNNECESSARY_CONFIGURATIONS) {
if (passesTests || !ConfigOptions.shouldRemoveUnusedAutoconfig()) {
if (type.isCondition()) {
if (type.hasOnlySimpleConstructor()) {
reflectionHandler.addAccess(configNameDotted, new String[][] { { "<init>" } }, true);
Expand Down Expand Up @@ -732,7 +725,7 @@ private boolean processType(Type type, Set<String> visited, int depth) {
}
}

if (passesTests || !REMOVE_UNNECESSARY_CONFIGURATIONS) {
if (passesTests || !ConfigOptions.shouldRemoveUnusedAutoconfig()) {
if (type.isAtConfiguration()) {

// This type might have @AutoConfigureAfter/@AutoConfigureBefore references to
Expand Down Expand Up @@ -897,7 +890,7 @@ private boolean processType(Type type, Set<String> visited, int depth) {


// If the outer type is failing a test, we don't need to go into nested types...
if (passesTests || !REMOVE_UNNECESSARY_CONFIGURATIONS) {
if (passesTests || !ConfigOptions.shouldRemoveUnusedAutoconfig()) {
// if (type.isAtConfiguration() || type.isAbstractNestedCondition()) {
List<Type> nestedTypes = type.getNestedTypes();
for (Type t : nestedTypes) {
Expand Down

0 comments on commit d9d1f03

Please sign in to comment.