@@ -72,16 +72,15 @@ public class BundleGenerator
72
72
73
73
private final Path projectBaseDir ;
74
74
private final Path baseFolder ;
75
+ private final Path projectBuildDirectory ;
75
76
76
- public BundleGenerator (Path projectBaseDir , Path baseFolder ) throws MojoExecutionException
77
+ public BundleGenerator (Path projectBaseDir , Path baseFolder , Path projectBuildDirectory )
78
+ throws MojoExecutionException
77
79
{
78
- this .projectBaseDir = projectBaseDir ;
79
- this .baseFolder = baseFolder ;
80
+ this .projectBaseDir = Objects .requireNonNull (projectBaseDir , "projectBaseDir" );
81
+ this .baseFolder = Objects .requireNonNull (baseFolder , "baseFolder" );
82
+ this .projectBuildDirectory = Objects .requireNonNull (projectBuildDirectory , "projectBuildDirectory" );
80
83
81
- if (projectBaseDir == null )
82
- throw new MojoExecutionException ("projectBaseDir not defined" );
83
- if (baseFolder == null )
84
- throw new MojoExecutionException ("baseFolder not defined" );
85
84
if (!Files .isReadable (baseFolder ))
86
85
throw new MojoExecutionException ("baseFolder '" + baseFolder .toString () + "' not readable" );
87
86
}
@@ -93,15 +92,17 @@ private Path relativeToProjectDir(Path path)
93
92
94
93
public void generateAndSaveBundle () throws MojoFailureException
95
94
{
95
+ final Path bundleFilename = getBundleFilename ();
96
+
96
97
Bundle bundle ;
97
98
try
98
99
{
99
- logger .info ("Generating bundle at {} ..." , relativeToProjectDir (getBundleFilename () ));
100
+ logger .info ("Generating bundle at {} ..." , relativeToProjectDir (bundleFilename ));
100
101
bundle = generateBundle ();
101
102
}
102
103
catch (IOException e )
103
104
{
104
- logger .error ("Error while generating bundle" , e );
105
+ logger .error ("Unable to generate bundle" , e );
105
106
throw new MojoFailureException (e );
106
107
}
107
108
@@ -115,12 +116,16 @@ public void generateAndSaveBundle() throws MojoFailureException
115
116
116
117
try
117
118
{
118
- saveBundle (bundle );
119
- logger .info ("Bundle saved at {}" , relativeToProjectDir (getBundleFilename ()));
119
+ saveBundle (bundle , bundleFilename );
120
+ logger .info ("Bundle saved at {}" , relativeToProjectDir (bundleFilename ));
121
+
122
+ Path target = projectBuildDirectory .resolve ("classes/fhir/" + BUNDLE_FILENAME );
123
+ Files .copy (bundleFilename , target );
124
+ logger .info ("Bundle copied to {}" , relativeToProjectDir (target ));
120
125
}
121
126
catch (IOException | TransformerException e )
122
127
{
123
- logger .error ("Error while generating bundle" , e );
128
+ logger .error ("Unable to save bundle" , e );
124
129
throw new MojoFailureException (e );
125
130
}
126
131
}
@@ -334,11 +339,11 @@ private String toLabel(BundleEntryComponent entry)
334
339
};
335
340
}
336
341
337
- private void saveBundle (Bundle bundle ) throws IOException , TransformerException
342
+ private void saveBundle (Bundle bundle , Path bundleFilename ) throws IOException , TransformerException
338
343
{
339
344
String xml = newXmlParser ().encodeResourceToString (bundle );
340
345
341
- try (OutputStream out = Files .newOutputStream (getBundleFilename () );
346
+ try (OutputStream out = Files .newOutputStream (bundleFilename );
342
347
OutputStreamWriter writer = new OutputStreamWriter (out , StandardCharsets .UTF_8 ))
343
348
{
344
349
// minimized output: empty-element tags, no indentation, no line-breaks
0 commit comments