1414package org .codehaus .plexus .components .secdispatcher .internal ;
1515
1616import java .io .OutputStream ;
17+ import java .nio .charset .StandardCharsets ;
1718import java .nio .file .Files ;
1819import java .nio .file .Path ;
1920import java .nio .file .Paths ;
2021import java .util .Map ;
2122
23+ import org .codehaus .plexus .components .secdispatcher .SecDispatcher ;
2224import org .codehaus .plexus .components .secdispatcher .SecDispatcherException ;
2325import org .codehaus .plexus .components .secdispatcher .model .Config ;
2426import org .codehaus .plexus .components .secdispatcher .model .ConfigProperty ;
@@ -51,6 +53,8 @@ private void saveSec(String masterSource) throws Exception {
5153 private void saveSec (String path , String masterSource ) throws Exception {
5254 SettingsSecurity sec = new SettingsSecurity ();
5355
56+ sec .setModelEncoding (StandardCharsets .UTF_8 .name ());
57+ sec .setModelVersion (SecDispatcher .class .getPackage ().getSpecificationVersion ());
5458 sec .setRelocation (null );
5559 sec .setMasterSource (masterSource );
5660
@@ -73,6 +77,8 @@ private void saveSec(String path, String masterSource) throws Exception {
7377 public void prepare () throws Exception {
7478 System .setProperty (DefaultSecDispatcher .SYSTEM_PROPERTY_CONFIGURATION_LOCATION , "./target/sec.xml" );
7579 SettingsSecurity sec = new SettingsSecurity ();
80+ sec .setModelEncoding (StandardCharsets .UTF_8 .name ());
81+ sec .setModelVersion (SecDispatcher .class .getPackage ().getSpecificationVersion ());
7682 sec .setRelocation ("sec1.xml" );
7783 try (OutputStream fos = Files .newOutputStream (Paths .get ("./target/sec.xml" ))) {
7884 new SecurityConfigurationStaxWriter ().write (fos , sec );
@@ -95,6 +101,8 @@ void testReadWithRelocation() throws Exception {
95101 void testReadWithRelocationCycleSelf () throws Exception {
96102 Path sec1 = Paths .get ("./target/sec-cycle-1.xml" );
97103 SettingsSecurity s1 = new SettingsSecurity ();
104+ s1 .setModelEncoding (StandardCharsets .UTF_8 .name ());
105+ s1 .setModelVersion (SecDispatcher .class .getPackage ().getSpecificationVersion ());
98106 s1 .setRelocation ("sec-cycle-1.xml" );
99107 try (OutputStream fos = Files .newOutputStream (sec1 )) {
100108 new SecurityConfigurationStaxWriter ().write (fos , s1 );
@@ -108,11 +116,15 @@ void testReadWithRelocationCycle() throws Exception {
108116 Path sec1 = Paths .get ("./target/sec-cycle-1.xml" );
109117 Path sec2 = Paths .get ("./target/sec-cycle-2.xml" );
110118 SettingsSecurity s1 = new SettingsSecurity ();
119+ s1 .setModelEncoding (StandardCharsets .UTF_8 .name ());
120+ s1 .setModelVersion (SecDispatcher .class .getPackage ().getSpecificationVersion ());
111121 s1 .setRelocation ("sec-cycle-2.xml" );
112122 try (OutputStream fos = Files .newOutputStream (sec1 )) {
113123 new SecurityConfigurationStaxWriter ().write (fos , s1 );
114124 }
115125 SettingsSecurity s2 = new SettingsSecurity ();
126+ s2 .setModelEncoding (StandardCharsets .UTF_8 .name ());
127+ s2 .setModelVersion (SecDispatcher .class .getPackage ().getSpecificationVersion ());
116128 s2 .setRelocation ("sec-cycle-1.xml" );
117129 try (OutputStream fos = Files .newOutputStream (sec1 )) {
118130 new SecurityConfigurationStaxWriter ().write (fos , s2 );
0 commit comments