Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 95bce2e

Browse files
olegzericbottard
authored andcommitted
GH-1495 continue general code cleanup of 'completion' module
- continuation of general code cleanup started in a490008 commit Fixes #1495
1 parent a490008 commit 95bce2e

11 files changed

+109
-258
lines changed

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/AddAppOptionsExpansionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public boolean addProposals(String text, StreamDefinition streamDefinition, int
5151

5252
if (appRegistration != null) {
5353
Set<String> alreadyPresentOptions = new HashSet<>(lastApp.getProperties().keySet());
54-
this.collectorSupport.doAddProposals(text, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
54+
this.collectorSupport.addPropertiesProposals(text, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
5555
}
5656
return false;
5757
}

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/AddAppOptionsTaskExpansionStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public boolean addProposals(String text, TaskDefinition taskDefinition, int deta
5353

5454
if (appRegistration != null) {
5555
Set<String> alreadyPresentOptions = new HashSet<>(taskDefinition.getProperties().keySet());
56-
this.collectorSupport.doAddProposals(text, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
56+
this.collectorSupport.addPropertiesProposals(text, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
5757
}
5858
return false;
5959
}

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/ConfigurationPropertyNameAfterDashDashRecoveryStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void addProposals(String dsl, CheckPointedParseException exception, int d
5757
AppRegistration appRegistration = this.collectorSupport.findAppRegistration(lastApp.getName(), CompletionUtils.determinePotentialTypes(lastApp));
5858
if (appRegistration != null) {
5959
Set<String> alreadyPresentOptions = new HashSet<>(lastApp.getProperties().keySet());
60-
this.collectorSupport.doAddProposals(safe, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
60+
this.collectorSupport.addPropertiesProposals(safe, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
6161
}
6262
}
6363
}

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/ConfigurationPropertyNameAfterDashDashTaskRecoveryStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void addProposals(String dsl, CheckPointedParseException exception, int d
5858

5959
if (appRegistration != null) {
6060
Set<String> alreadyPresentOptions = new HashSet<>(taskDefinition.getProperties().keySet());
61-
this.collectorSupport.doAddProposals(safe, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
61+
this.collectorSupport.addPropertiesProposals(safe, "", appRegistration, alreadyPresentOptions, collector, detailLevel);
6262
}
6363
}
6464
}

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/ConfigurationPropertyValueHintExpansionStrategy.java

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,38 @@
1616

1717
package org.springframework.cloud.dataflow.completion;
1818

19-
import java.io.IOException;
20-
import java.net.URLClassLoader;
2119
import java.util.HashSet;
2220
import java.util.List;
2321
import java.util.Set;
2422

2523
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
27-
import org.springframework.boot.configurationmetadata.ValueHint;
2824
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolver;
29-
import org.springframework.cloud.dataflow.core.ApplicationType;
3025
import org.springframework.cloud.dataflow.core.StreamAppDefinition;
3126
import org.springframework.cloud.dataflow.core.StreamDefinition;
3227
import org.springframework.cloud.dataflow.core.dsl.CheckPointedParseException;
3328
import org.springframework.cloud.dataflow.core.dsl.Token;
3429
import org.springframework.cloud.dataflow.core.dsl.TokenKind;
3530
import org.springframework.cloud.dataflow.registry.AppRegistration;
3631
import org.springframework.cloud.dataflow.registry.AppRegistry;
37-
import org.springframework.core.io.Resource;
38-
39-
import static org.springframework.cloud.dataflow.completion.CompletionProposal.expanding;
4032

4133
/**
4234
* Attempts to fill in possible values after a {@literal --foo=prefix} (syntactically
4335
* valid) construct in the DSL.
4436
*
4537
* @author Eric Bottard
4638
* @author Mark Fisher
39+
* @author Oleg Zhurakousky
4740
*/
4841
public class ConfigurationPropertyValueHintExpansionStrategy implements ExpansionStrategy {
4942

50-
private final AppRegistry appRegistry;
51-
52-
private final ApplicationConfigurationMetadataResolver metadataResolver;
43+
private final ProposalsCollectorSupportUtils collectorSupport;
5344

5445
@Autowired
5546
private ValueHintProvider[] valueHintProviders = new ValueHintProvider[0];
5647

5748
ConfigurationPropertyValueHintExpansionStrategy(AppRegistry appRegistry,
5849
ApplicationConfigurationMetadataResolver metadataResolver) {
59-
this.appRegistry = appRegistry;
60-
this.metadataResolver = metadataResolver;
50+
this.collectorSupport = new ProposalsCollectorSupportUtils(appRegistry, metadataResolver);
6151
}
6252

6353
@Override
@@ -75,66 +65,10 @@ public boolean addProposals(String text, StreamDefinition parseResult, int detai
7565
StreamAppDefinition lastApp = parseResult.getDeploymentOrderIterator().next();
7666
String alreadyTyped = lastApp.getProperties().get(propertyName);
7767

78-
String lastAppName = lastApp.getName();
79-
AppRegistration lastAppRegistration = null;
80-
for (ApplicationType appType : CompletionUtils.determinePotentialTypes(lastApp)) {
81-
lastAppRegistration = appRegistry.find(lastAppName, appType);
82-
if (lastAppRegistration != null) {
83-
break;
84-
}
85-
}
86-
87-
if (lastAppRegistration == null) {
88-
// Not a valid app name, do nothing
89-
return false;
68+
AppRegistration lastAppRegistration = this.collectorSupport.findAppRegistration(lastApp.getName(), CompletionUtils.determinePotentialTypes(lastApp));
69+
if (lastAppRegistration != null) {
70+
return this.collectorSupport.addAlreadyTypedValueHintsProposals(text, lastAppRegistration, collector, propertyName, valueHintProviders, alreadyTyped);
9071
}
91-
Resource metadataResource = lastAppRegistration.getMetadataResource();
92-
93-
CompletionProposal.Factory proposals = expanding(text);
94-
95-
List<ConfigurationMetadataProperty> allProps = metadataResolver.listProperties(metadataResource, true);
96-
List<ConfigurationMetadataProperty> whiteListedProps = metadataResolver.listProperties(metadataResource);
97-
98-
URLClassLoader classLoader = null;
99-
try {
100-
for (ConfigurationMetadataProperty property : allProps) {
101-
if (CompletionUtils.isMatchingProperty(propertyName, property, whiteListedProps)) {
102-
if (classLoader == null) {
103-
classLoader = metadataResolver.createAppClassLoader(metadataResource);
104-
}
105-
for (ValueHintProvider valueHintProvider : valueHintProviders) {
106-
List<ValueHint> valueHints = valueHintProvider.generateValueHints(property, classLoader);
107-
if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
108-
collector.clear();
109-
}
110-
for (ValueHint valueHint : valueHints) {
111-
String candidate = String.valueOf(valueHint.getValue());
112-
if (!candidate.equals(alreadyTyped) && candidate.startsWith(alreadyTyped)) {
113-
collector.add(proposals.withSuffix(candidate.substring(alreadyTyped.length()),
114-
valueHint.getShortDescription()));
115-
}
116-
}
117-
if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
118-
return true;
119-
}
120-
}
121-
}
122-
}
123-
}
124-
catch (Exception e) {
125-
throw new RuntimeException(e);
126-
}
127-
finally {
128-
if (classLoader != null) {
129-
try {
130-
classLoader.close();
131-
}
132-
catch (IOException e) {
133-
// ignore
134-
}
135-
}
136-
}
137-
13872
return false;
13973
}
14074

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/ConfigurationPropertyValueHintRecoveryStrategy.java

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,38 @@
1616

1717
package org.springframework.cloud.dataflow.completion;
1818

19-
import java.io.IOException;
20-
import java.net.URLClassLoader;
2119
import java.util.List;
2220

2321
import org.springframework.beans.factory.annotation.Autowired;
24-
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
25-
import org.springframework.boot.configurationmetadata.ValueHint;
2622
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolver;
27-
import org.springframework.cloud.dataflow.core.ApplicationType;
2823
import org.springframework.cloud.dataflow.core.StreamAppDefinition;
2924
import org.springframework.cloud.dataflow.core.StreamDefinition;
3025
import org.springframework.cloud.dataflow.core.dsl.CheckPointedParseException;
3126
import org.springframework.cloud.dataflow.core.dsl.Token;
3227
import org.springframework.cloud.dataflow.core.dsl.TokenKind;
3328
import org.springframework.cloud.dataflow.registry.AppRegistration;
3429
import org.springframework.cloud.dataflow.registry.AppRegistry;
35-
import org.springframework.core.io.Resource;
36-
37-
import static org.springframework.cloud.dataflow.completion.CompletionProposal.expanding;
3830

3931
/**
4032
* Attempts to fill in possible values after a {@literal --foo=} dangling construct in the
4133
* DSL.
4234
*
4335
* @author Eric Bottard
4436
* @author Mark Fisher
37+
* @author Oleg Zhurakousky
4538
*/
4639
public class ConfigurationPropertyValueHintRecoveryStrategy
4740
extends StacktraceFingerprintingRecoveryStrategy<CheckPointedParseException> {
4841

49-
private final AppRegistry appRegistry;
50-
51-
private final ApplicationConfigurationMetadataResolver metadataResolver;
42+
private final ProposalsCollectorSupportUtils collectorSupport;
5243

5344
@Autowired
5445
private ValueHintProvider[] valueHintProviders = new ValueHintProvider[0];
5546

5647
ConfigurationPropertyValueHintRecoveryStrategy(AppRegistry appRegistry,
5748
ApplicationConfigurationMetadataResolver metadataResolver) {
5849
super(CheckPointedParseException.class, "foo --bar=", "foo | wizz --bar=");
59-
this.appRegistry = appRegistry;
60-
this.metadataResolver = metadataResolver;
50+
this.collectorSupport = new ProposalsCollectorSupportUtils(appRegistry, metadataResolver);
6151
}
6252

6353
@Override
@@ -68,61 +58,16 @@ public void addProposals(String dsl, CheckPointedParseException exception, int d
6858

6959
AppRegistration lastAppRegistration = lookupLastApp(exception);
7060

71-
if (lastAppRegistration == null) {
72-
// Not a valid app name, do nothing
73-
return;
74-
}
75-
Resource metadataResource = lastAppRegistration.getMetadataResource();
76-
77-
CompletionProposal.Factory proposals = expanding(dsl);
78-
79-
List<ConfigurationMetadataProperty> whiteList = metadataResolver.listProperties(metadataResource);
80-
81-
URLClassLoader classLoader = null;
82-
try {
83-
for (ConfigurationMetadataProperty property : metadataResolver.listProperties(metadataResource, true)) {
84-
if (CompletionUtils.isMatchingProperty(propertyName, property, whiteList)) {
85-
if (classLoader == null) {
86-
classLoader = metadataResolver.createAppClassLoader(metadataResource);
87-
}
88-
for (ValueHintProvider valueHintProvider : valueHintProviders) {
89-
for (ValueHint valueHint : valueHintProvider.generateValueHints(property, classLoader)) {
90-
collector.add(proposals.withSuffix(String.valueOf(valueHint.getValue()),
91-
valueHint.getShortDescription()));
92-
}
93-
}
94-
}
95-
}
96-
}
97-
catch (Exception e) {
98-
throw new RuntimeException(e);
99-
}
100-
finally {
101-
if (classLoader != null) {
102-
try {
103-
classLoader.close();
104-
}
105-
catch (IOException e) {
106-
// ignore
107-
}
108-
}
61+
if (lastAppRegistration != null) {
62+
this.collectorSupport.addValueHintsProposals(dsl, lastAppRegistration, collector, propertyName, valueHintProviders);
10963
}
11064
}
11165

11266
private AppRegistration lookupLastApp(CheckPointedParseException exception) {
11367
String safe = exception.getExpressionStringUntilCheckpoint();
11468
StreamDefinition streamDefinition = new StreamDefinition("__dummy", safe);
11569
StreamAppDefinition lastApp = streamDefinition.getDeploymentOrderIterator().next();
116-
117-
String lastAppName = lastApp.getName();
118-
AppRegistration lastAppRegistration = null;
119-
for (ApplicationType appType : CompletionUtils.determinePotentialTypes(lastApp)) {
120-
lastAppRegistration = this.appRegistry.find(lastAppName, appType);
121-
if (lastAppRegistration != null) {
122-
break;
123-
}
124-
}
125-
return lastAppRegistration;
70+
return this.collectorSupport.findAppRegistration(lastApp.getName(), CompletionUtils.determinePotentialTypes(lastApp));
12671
}
12772

12873
private String recoverPropertyName(CheckPointedParseException exception) {

spring-cloud-dataflow-completion/src/main/java/org/springframework/cloud/dataflow/completion/ConfigurationPropertyValueHintTaskExpansionStrategy.java

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
package org.springframework.cloud.dataflow.completion;
1818

19-
import java.io.IOException;
20-
import java.net.URLClassLoader;
2119
import java.util.HashSet;
2220
import java.util.List;
2321
import java.util.Set;
2422

2523
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
27-
import org.springframework.boot.configurationmetadata.ValueHint;
2824
import org.springframework.cloud.dataflow.configuration.metadata.ApplicationConfigurationMetadataResolver;
2925
import org.springframework.cloud.dataflow.core.ApplicationType;
3026
import org.springframework.cloud.dataflow.core.TaskDefinition;
@@ -33,9 +29,6 @@
3329
import org.springframework.cloud.dataflow.core.dsl.TokenKind;
3430
import org.springframework.cloud.dataflow.registry.AppRegistration;
3531
import org.springframework.cloud.dataflow.registry.AppRegistry;
36-
import org.springframework.core.io.Resource;
37-
38-
import static org.springframework.cloud.dataflow.completion.CompletionProposal.expanding;
3932

4033
/**
4134
* Attempts to fill in possible values after a {@literal --foo=prefix} (syntactically
@@ -44,20 +37,18 @@
4437
* @author Eric Bottard
4538
* @author Mark Fisher
4639
* @author Andy Clement
40+
* @author Oleg Zhurakousky
4741
*/
4842
public class ConfigurationPropertyValueHintTaskExpansionStrategy implements TaskExpansionStrategy {
4943

50-
private final AppRegistry appRegistry;
51-
52-
private final ApplicationConfigurationMetadataResolver metadataResolver;
44+
private final ProposalsCollectorSupportUtils collectorSupport;
5345

5446
@Autowired
5547
private ValueHintProvider[] valueHintProviders = new ValueHintProvider[0];
5648

5749
ConfigurationPropertyValueHintTaskExpansionStrategy(AppRegistry appRegistry,
5850
ApplicationConfigurationMetadataResolver metadataResolver) {
59-
this.appRegistry = appRegistry;
60-
this.metadataResolver = metadataResolver;
51+
this.collectorSupport = new ProposalsCollectorSupportUtils(appRegistry, metadataResolver);
6152
}
6253

6354
@Override
@@ -73,59 +64,10 @@ public boolean addProposals(String text, TaskDefinition parseResult, int detailL
7364

7465
String alreadyTyped = parseResult.getProperties().get(propertyName);
7566

76-
String appName = parseResult.getRegisteredAppName();
77-
AppRegistration appRegistration = appRegistry.find(appName, ApplicationType.task);
78-
if (appRegistration == null) {
79-
// Not a valid app name, do nothing
80-
return false;
81-
}
82-
Resource metadataResource = appRegistration.getMetadataResource();
83-
84-
CompletionProposal.Factory proposals = expanding(text);
85-
86-
List<ConfigurationMetadataProperty> allProps = metadataResolver.listProperties(metadataResource, true);
87-
List<ConfigurationMetadataProperty> whiteListedProps = metadataResolver.listProperties(metadataResource);
88-
89-
URLClassLoader classLoader = null;
90-
try {
91-
for (ConfigurationMetadataProperty property : allProps) {
92-
if (CompletionUtils.isMatchingProperty(propertyName, property, whiteListedProps)) {
93-
if (classLoader == null) {
94-
classLoader = metadataResolver.createAppClassLoader(metadataResource);
95-
}
96-
for (ValueHintProvider valueHintProvider : valueHintProviders) {
97-
List<ValueHint> valueHints = valueHintProvider.generateValueHints(property, classLoader);
98-
if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
99-
collector.clear();
100-
}
101-
for (ValueHint valueHint : valueHints) {
102-
String candidate = String.valueOf(valueHint.getValue());
103-
if (!candidate.equals(alreadyTyped) && candidate.startsWith(alreadyTyped)) {
104-
collector.add(proposals.withSuffix(candidate.substring(alreadyTyped.length()),
105-
valueHint.getShortDescription()));
106-
}
107-
}
108-
if (!valueHints.isEmpty() && valueHintProvider.isExclusive(property)) {
109-
return true;
110-
}
111-
}
112-
}
113-
}
114-
}
115-
catch (Exception e) {
116-
throw new RuntimeException(e);
117-
}
118-
finally {
119-
if (classLoader != null) {
120-
try {
121-
classLoader.close();
122-
}
123-
catch (IOException e) {
124-
// ignore
125-
}
126-
}
67+
AppRegistration lastAppRegistration = this.collectorSupport.findAppRegistration(parseResult.getRegisteredAppName(), ApplicationType.task);
68+
if (lastAppRegistration != null) {
69+
return this.collectorSupport.addAlreadyTypedValueHintsProposals(text, lastAppRegistration, collector, propertyName, valueHintProviders, alreadyTyped);
12770
}
128-
12971
return false;
13072
}
13173

0 commit comments

Comments
 (0)