21
21
import com .google .gson .Gson ;
22
22
import com .google .gson .JsonObject ;
23
23
import io .ballerina .cli .BLauncherCmd ;
24
+ import io .ballerina .projects .BuildOptions ;
24
25
import io .ballerina .projects .JvmTarget ;
25
26
import io .ballerina .projects .ProjectException ;
26
27
import io .ballerina .projects .SemanticVersion ;
@@ -72,8 +73,9 @@ public class PullCommand implements BLauncherCmd {
72
73
private static final String USAGE_TEXT =
73
74
"bal pull {<org-name>/<package-name> | <org-name>/<package-name>:<version>}" ;
74
75
75
- private PrintStream errStream ;
76
- private boolean exitWhenFinish ;
76
+ private final PrintStream outStream ;
77
+ private final PrintStream errStream ;
78
+ private final boolean exitWhenFinish ;
77
79
78
80
@ CommandLine .Parameters
79
81
private List <String > argList ;
@@ -87,12 +89,20 @@ public class PullCommand implements BLauncherCmd {
87
89
@ CommandLine .Option (names = "--repository" )
88
90
private String repositoryName ;
89
91
92
+ @ CommandLine .Option (names = "--sticky" , hidden = true , defaultValue = "true" )
93
+ private boolean sticky ;
94
+
95
+ @ CommandLine .Option (names = "--offline" , hidden = true )
96
+ private boolean offline ;
97
+
90
98
public PullCommand () {
99
+ this .outStream = System .out ;
91
100
this .errStream = System .err ;
92
101
this .exitWhenFinish = true ;
93
102
}
94
103
95
104
public PullCommand (PrintStream errStream , boolean exitWhenFinish ) {
105
+ this .outStream = errStream ;
96
106
this .errStream = errStream ;
97
107
this .exitWhenFinish = exitWhenFinish ;
98
108
}
@@ -254,6 +264,10 @@ public void execute() {
254
264
.resolve (ProjectConstants .REPOSITORIES_DIR ).resolve (ProjectConstants .CENTRAL_REPOSITORY_CACHE_NAME )
255
265
.resolve (ProjectConstants .BALA_DIR_NAME )
256
266
.resolve (orgName ).resolve (packageName );
267
+
268
+ if (!version .equals (Names .EMPTY .getValue ()) && Files .exists (packagePathInBalaCache .resolve (version ))) {
269
+ outStream .println ("Package already exists.\n " );
270
+ }
257
271
// create directory path in bala cache
258
272
try {
259
273
createDirectories (packagePathInBalaCache );
@@ -267,8 +281,9 @@ public void execute() {
267
281
String supportedPlatform = Arrays .stream (JvmTarget .values ())
268
282
.map (JvmTarget ::code )
269
283
.collect (Collectors .joining ("," ));
284
+ CentralAPIClient client ;
270
285
try {
271
- CentralAPIClient client = new CentralAPIClient (RepoUtils .getRemoteRepoURL (),
286
+ client = new CentralAPIClient (RepoUtils .getRemoteRepoURL (),
272
287
initializeProxy (settings .getProxy ()), settings .getProxy ().username (),
273
288
settings .getProxy ().password (), getAccessTokenOfCLI (settings ),
274
289
settings .getCentral ().getConnectTimeout (),
@@ -281,19 +296,23 @@ public void execute() {
281
296
RepoUtils .getBallerinaVersion ());
282
297
version = CommandUtil .getLatestVersion (versions );
283
298
}
284
- boolean hasCompilationErrors = CommandUtil .pullDependencyPackages (orgName , packageName , version );
285
- if (hasCompilationErrors ) {
286
- CommandUtil .printError (this .errStream , "compilation contains errors" , null , false );
287
- CommandUtil .exitError (this .exitWhenFinish );
288
- return ;
289
- }
290
299
} catch (PackageAlreadyExistsException e ) {
291
- errStream .println (e . getMessage () );
292
- CommandUtil . exitError ( this . exitWhenFinish );
300
+ outStream .println ("Package already exists. \n " );
301
+ version = e . version ( );
293
302
} catch (CentralClientException e ) {
294
303
errStream .println ("package not found: " + orgName + "/" + packageName );
295
304
CommandUtil .exitError (this .exitWhenFinish );
296
305
}
306
+
307
+ outStream .println ("Resolving dependencies" );
308
+ BuildOptions buildOptions = BuildOptions .builder ().setSticky (sticky ).setOffline (offline ).build ();
309
+ boolean hasCompilationErrors = CommandUtil .pullDependencyPackages (orgName , packageName , version , buildOptions );
310
+ if (hasCompilationErrors ) {
311
+ CommandUtil .printError (this .errStream , "compilation contains errors" , null , false );
312
+ CommandUtil .exitError (this .exitWhenFinish );
313
+ return ;
314
+ }
315
+
297
316
if (this .exitWhenFinish ) {
298
317
Runtime .getRuntime ().exit (0 );
299
318
}
0 commit comments