29
29
import io .quarkus .deployment .cmd .DeployCommandDeclarationResultBuildItem ;
30
30
import io .quarkus .deployment .cmd .DeployCommandHandler ;
31
31
import io .quarkus .deployment .util .DeploymentUtil ;
32
+ import io .quarkus .maven .dependency .ArtifactCoords ;
32
33
33
34
public abstract class Deploy extends QuarkusBuildTask {
34
35
@@ -66,6 +67,10 @@ public String[] getRequiresOneOf() {
66
67
boolean imageBuild = false ;
67
68
Optional <String > imageBuilder = Optional .empty ();
68
69
70
+ public Optional <String > getDeployer () {
71
+ return deployer ;
72
+ }
73
+
69
74
@ Option (option = "deployer" , description = "The deployer to use" )
70
75
public void setDeployer (String deployer ) {
71
76
this .deployer = Optional .ofNullable (deployer );
@@ -115,7 +120,7 @@ public void accept(List<String> strings) {
115
120
if (targets .isEmpty () && target == null ) {
116
121
// Currently forcedDependencies() is not implemented for gradle.
117
122
// So, let's give users a meaningful warning message.
118
- Deployer deployer = getDeployer ( );
123
+ Deployer deployer = getDeployerFromDependencies ( appModel );
119
124
extension ().forcedPropertiesProperty ().convention (
120
125
getProject ().provider (() -> {
121
126
Map <String , String > props = new HashMap <>();
@@ -125,12 +130,11 @@ public void accept(List<String> strings) {
125
130
return props ;
126
131
}));
127
132
String requiredDeployerExtension = deployer .getExtension ();
128
- Optional <String > requiredContainerImageExtension = requiredContainerImageExtension ();
133
+ Optional <String > requiredContainerImageExtension = requiredContainerImageExtension (appModel );
129
134
130
- List <String > projectDependencies = getProject ().getConfigurations ().stream ()
131
- .flatMap (c -> c .getDependencies ().stream ())
132
- .map (d -> d .getName ())
133
- .collect (Collectors .toList ());
135
+ List <String > projectDependencies = appModel .getDependencies ().stream ()
136
+ .map (ArtifactCoords ::getArtifactId )
137
+ .toList ();
134
138
135
139
if (!projectDependencies .contains (requiredDeployerExtension )) {
136
140
abort ("Task: {} requires extensions: {}\n " +
@@ -188,27 +192,28 @@ public void accept(Boolean success) {
188
192
}
189
193
}
190
194
191
- public Deployer getDeployer ( ) {
192
- return getDeployer ( Deployer .kubernetes );
195
+ public Deployer getDeployerFromDependencies ( ApplicationModel appModel ) {
196
+ return getDeployerFromDependencies ( appModel , Deployer .kubernetes );
193
197
}
194
198
195
- public Deployer getDeployer ( Deployer defaultDeployer ) {
199
+ public Deployer getDeployerFromDependencies ( ApplicationModel appModel , Deployer defaultDeployer ) {
196
200
return deployer
197
- .or (() -> DeploymentUtil . getEnabledDeployer () )
198
- .or (() -> getProjectDeployers ().stream ().findFirst ())
201
+ .or (DeploymentUtil :: getEnabledDeployer )
202
+ .or (() -> getProjectDeployers (appModel ).stream ().findFirst ())
199
203
.map (Deployer ::valueOf )
200
204
.orElse (defaultDeployer );
201
205
}
202
206
203
- public Optional <String > requiredContainerImageExtension () {
207
+ public Optional <String > requiredContainerImageExtension (ApplicationModel appModel ) {
204
208
return imageBuilder .map (b -> "quarkus-container-image-" + b )
205
- .or (() -> imageBuild ? Arrays .stream (getDeployer ().requiresOneOf ).findFirst () : Optional .empty ());
209
+ .or (() -> imageBuild ? Arrays .stream (getDeployerFromDependencies (appModel ).requiresOneOf ).findFirst ()
210
+ : Optional .empty ());
206
211
}
207
212
208
- private Set <String > getProjectDeployers () {
209
- return getProject (). getConfigurations ().stream (). flatMap ( c -> c . getDependencies (). stream () )
210
- .map (d -> d . getName () )
211
- .filter (d -> Arrays .stream (Deployer .values ()).map (Deployer ::getExtension ).anyMatch (e -> d . equals ( e ) ))
213
+ private Set <String > getProjectDeployers (ApplicationModel appModel ) {
214
+ return appModel . getRuntimeDependencies ().stream ()
215
+ .map (ArtifactCoords :: getArtifactId )
216
+ .filter (d -> Arrays .stream (Deployer .values ()).map (Deployer ::getExtension ).anyMatch (d :: equals ))
212
217
.map (d -> d .replaceAll ("^quarkus\\ -" , "" ))
213
218
.collect (Collectors .toSet ());
214
219
}
0 commit comments