36
36
import java .util .stream .Collectors ;
37
37
import java .util .stream .Stream ;
38
38
39
+ import com .fasterxml .jackson .databind .JsonNode ;
40
+ import com .fasterxml .jackson .databind .node .ObjectNode ;
39
41
import org .apache .maven .artifact .DefaultArtifact ;
40
42
import org .apache .maven .artifact .handler .DefaultArtifactHandler ;
41
43
import org .apache .maven .model .Build ;
60
62
import org .mockito .Mockito ;
61
63
62
64
import com .vaadin .flow .di .Lookup ;
65
+ import com .vaadin .flow .internal .JacksonUtils ;
63
66
import com .vaadin .flow .internal .StringUtil ;
64
67
import com .vaadin .flow .plugin .TestUtils ;
65
68
import com .vaadin .flow .server .Constants ;
70
73
import com .vaadin .flow .server .frontend .installer .NodeInstaller ;
71
74
import com .vaadin .flow .server .frontend .scanner .ClassFinder ;
72
75
73
- import elemental .json .Json ;
74
- import elemental .json .JsonObject ;
75
- import elemental .json .impl .JsonUtil ;
76
-
77
76
import static com .vaadin .flow .server .Constants .PACKAGE_JSON ;
78
77
import static com .vaadin .flow .server .Constants .TARGET ;
79
78
import static com .vaadin .flow .server .Constants .VAADIN_SERVLET_RESOURCES ;
@@ -203,7 +202,7 @@ public void setup() throws Exception {
203
202
// need to run `npm install`
204
203
createExpectedImports (frontendDirectory , nodeModulesPath );
205
204
FileUtils .fileWrite (packageJson , "UTF-8" ,
206
- TestUtils .getInitialPackageJson ().toJson ());
205
+ TestUtils .getInitialPackageJson ().toString ());
207
206
208
207
lookup = Mockito .mock (Lookup .class );
209
208
Mockito .doReturn (new TestEndpointGeneratorTaskFactory ()).when (lookup )
@@ -459,27 +458,27 @@ public void should_AddRemove_Imports() throws Exception {
459
458
@ Test
460
459
public void mavenGoalWhenPackageJsonContainsDependencies_onlyFrameworkHandledDependencyIsTouched ()
461
460
throws Exception {
462
- JsonObject json = TestUtils .getInitialPackageJson ();
463
- JsonObject dependencies = Json . createObject ();
461
+ ObjectNode json = TestUtils .getInitialPackageJson ();
462
+ ObjectNode dependencies = JacksonUtils . createObjectNode ();
464
463
dependencies .put ("proj4" , "2.9.0" );
465
464
dependencies .put ("line-awesome" , "1.3.0" );
466
465
// Make proj4 framework handled
467
- json .getObject ("vaadin" ).getObject ("dependencies" ).put ("proj4" ,
466
+ (( ObjectNode ) json .get ("vaadin" ).get ("dependencies" ) ).put ("proj4" ,
468
467
"2.9.0" );
469
- json .put ("dependencies" , dependencies );
470
- FileUtils .fileWrite (packageJson , "UTF-8" , json .toJson ());
468
+ json .set ("dependencies" , dependencies );
469
+ FileUtils .fileWrite (packageJson , "UTF-8" , json .toString ());
471
470
472
471
mojo .execute ();
473
- JsonObject packageJsonObject = getPackageJson (packageJson );
474
- dependencies = packageJsonObject . getObject ("dependencies" );
472
+ ObjectNode packageObjectNode = getPackageJson (packageJson );
473
+ dependencies = ( ObjectNode ) packageObjectNode . get ("dependencies" );
475
474
476
475
assertContainsPackage (dependencies , "@vaadin/button" ,
477
476
"@vaadin/vaadin-element-mixin" );
478
477
479
478
Assert .assertFalse ("proj4 should have been removed" ,
480
- dependencies .hasKey ("proj4" ));
479
+ dependencies .has ("proj4" ));
481
480
Assert .assertTrue ("line-awesome should remain" ,
482
- dependencies .hasKey ("line-awesome" ));
481
+ dependencies .has ("line-awesome" ));
483
482
}
484
483
485
484
@ Test
@@ -498,7 +497,7 @@ public void existingTokenFile_parametersShouldBeRemoved()
498
497
ReflectionUtils .setVariableValueInObject (mojo ,
499
498
"resourceOutputDirectory" , resourceOutputDirectory );
500
499
501
- JsonObject initialBuildInfo = Json . createObject ();
500
+ ObjectNode initialBuildInfo = JacksonUtils . createObjectNode ();
502
501
initialBuildInfo .put (SERVLET_PARAMETER_PRODUCTION_MODE , false );
503
502
initialBuildInfo .put (Constants .NPM_TOKEN , "npm" );
504
503
initialBuildInfo .put (Constants .FRONTEND_TOKEN , "src/main/frontend" );
@@ -512,13 +511,13 @@ public void existingTokenFile_parametersShouldBeRemoved()
512
511
513
512
org .apache .commons .io .FileUtils .forceMkdir (tokenFile .getParentFile ());
514
513
org .apache .commons .io .FileUtils .write (tokenFile ,
515
- JsonUtil . stringify ( initialBuildInfo , 2 ) + "\n " , "UTF-8" );
514
+ initialBuildInfo . toPrettyString ( ) + "\n " , "UTF-8" );
516
515
517
516
mojo .execute ();
518
517
519
518
String json = org .apache .commons .io .FileUtils
520
519
.readFileToString (tokenFile , "UTF-8" );
521
- JsonObject buildInfo = JsonUtil . parse (json );
520
+ ObjectNode buildInfo = JacksonUtils . readTree (json );
522
521
Assert .assertNull (
523
522
"enable dev server token shouldn't be added " + "automatically" ,
524
523
buildInfo .get (FRONTEND_HOTDEPLOY ));
@@ -552,7 +551,7 @@ public void existingTokenFile_defaultApplicationIdentifierWritten()
552
551
String expectedAppId = "app-" + StringUtil .getHash (
553
552
"com.vaadin.testing:my-application" , StandardCharsets .UTF_8 );
554
553
555
- JsonObject initialBuildInfo = Json . createObject ();
554
+ ObjectNode initialBuildInfo = JacksonUtils . createObjectNode ();
556
555
initialBuildInfo .put (SERVLET_PARAMETER_PRODUCTION_MODE , false );
557
556
initialBuildInfo .put (Constants .NPM_TOKEN , "npm" );
558
557
initialBuildInfo .put (Constants .FRONTEND_TOKEN , "src/main/frontend" );
@@ -566,17 +565,18 @@ public void existingTokenFile_defaultApplicationIdentifierWritten()
566
565
567
566
org .apache .commons .io .FileUtils .forceMkdir (tokenFile .getParentFile ());
568
567
org .apache .commons .io .FileUtils .write (tokenFile ,
569
- JsonUtil . stringify ( initialBuildInfo , 2 ) + "\n " , "UTF-8" );
568
+ initialBuildInfo . toPrettyString ( ) + "\n " , "UTF-8" );
570
569
571
570
mojo .execute ();
572
571
Assert .assertTrue ("No token file could be found" , tokenFile .exists ());
573
572
574
573
String json = org .apache .commons .io .FileUtils
575
574
.readFileToString (tokenFile , "UTF-8" );
576
- JsonObject buildInfo = JsonUtil . parse (json );
575
+ ObjectNode buildInfo = JacksonUtils . readTree (json );
577
576
Assert .assertEquals (
578
577
"Custom application identifier not written on token file" ,
579
- expectedAppId , buildInfo .getString (APPLICATION_IDENTIFIER ));
578
+ expectedAppId ,
579
+ buildInfo .get (APPLICATION_IDENTIFIER ).textValue ());
580
580
}
581
581
582
582
@ Test
@@ -587,7 +587,7 @@ public void existingTokenFile_customApplicationIdentifierWritten()
587
587
ReflectionUtils .setVariableValueInObject (mojo , "applicationIdentifier" ,
588
588
appId );
589
589
590
- JsonObject initialBuildInfo = Json . createObject ();
590
+ ObjectNode initialBuildInfo = JacksonUtils . createObjectNode ();
591
591
initialBuildInfo .put (SERVLET_PARAMETER_PRODUCTION_MODE , false );
592
592
initialBuildInfo .put (Constants .NPM_TOKEN , "npm" );
593
593
initialBuildInfo .put (Constants .FRONTEND_TOKEN , "src/main/frontend" );
@@ -601,17 +601,17 @@ public void existingTokenFile_customApplicationIdentifierWritten()
601
601
602
602
org .apache .commons .io .FileUtils .forceMkdir (tokenFile .getParentFile ());
603
603
org .apache .commons .io .FileUtils .write (tokenFile ,
604
- JsonUtil . stringify ( initialBuildInfo , 2 ) + "\n " , "UTF-8" );
604
+ initialBuildInfo . toPrettyString ( ) + "\n " , "UTF-8" );
605
605
606
606
mojo .execute ();
607
607
Assert .assertTrue ("No token file could be found" , tokenFile .exists ());
608
608
609
609
String json = org .apache .commons .io .FileUtils
610
610
.readFileToString (tokenFile , "UTF-8" );
611
- JsonObject buildInfo = JsonUtil . parse (json );
611
+ ObjectNode buildInfo = JacksonUtils . readTree (json );
612
612
Assert .assertEquals (
613
613
"Custom application identifier not written on token file" ,
614
- appId , buildInfo .getString (APPLICATION_IDENTIFIER ));
614
+ appId , buildInfo .get (APPLICATION_IDENTIFIER ). textValue ( ));
615
615
}
616
616
617
617
@ Test
@@ -677,10 +677,10 @@ public void mavenGoal_generateTsFiles_when_enabled() throws Exception {
677
677
Assert .assertTrue (endpointClientApi .exists ());
678
678
}
679
679
680
- static void assertContainsPackage (JsonObject dependencies ,
680
+ static void assertContainsPackage (JsonNode dependencies ,
681
681
String ... packages ) {
682
682
Arrays .asList (packages ).forEach (dep -> Assert
683
- .assertTrue ("Missing " + dep , dependencies .hasKey (dep )));
683
+ .assertTrue ("Missing " + dep , dependencies .has (dep )));
684
684
}
685
685
686
686
private void assertContainsImports (boolean contains , String ... imports )
@@ -784,12 +784,12 @@ static void sleep(int ms) throws InterruptedException {
784
784
Thread .sleep (ms ); // NOSONAR
785
785
}
786
786
787
- static JsonObject getPackageJson (String packageJson ) throws IOException {
787
+ static ObjectNode getPackageJson (String packageJson ) throws IOException {
788
788
if (FileUtils .fileExists (packageJson )) {
789
- return Json . parse (FileUtils .fileRead (packageJson ));
789
+ return JacksonUtils . readTree (FileUtils .fileRead (packageJson ));
790
790
791
791
} else {
792
- return Json . createObject ();
792
+ return JacksonUtils . createObjectNode ();
793
793
}
794
794
}
795
795
0 commit comments