1
1
package io .quarkus .maven ;
2
2
3
3
import java .io .BufferedReader ;
4
- import java .io .BufferedWriter ;
5
4
import java .io .File ;
6
5
import java .io .IOException ;
7
- import java .io .UncheckedIOException ;
8
6
import java .lang .reflect .Method ;
9
7
import java .nio .file .Files ;
10
8
import java .nio .file .Path ;
11
- import java .util .ArrayList ;
12
- import java .util .Collections ;
13
- import java .util .List ;
14
9
import java .util .Properties ;
15
10
16
11
import org .apache .maven .plugin .MojoExecutionException ;
23
18
import io .quarkus .bootstrap .app .CuratedApplication ;
24
19
import io .quarkus .bootstrap .classloading .QuarkusClassLoader ;
25
20
import io .quarkus .bootstrap .model .ApplicationModel ;
26
- import io .quarkus .deployment .configuration .tracker .ConfigTrackingWriter ;
27
21
import io .quarkus .runtime .LaunchMode ;
28
22
29
23
/**
@@ -58,6 +52,12 @@ public class TrackConfigChangesMojo extends QuarkusBootstrapMojo {
58
52
@ Parameter (property = "quarkus.recorded-build-config.file" , required = false )
59
53
File recordedBuildConfigFile ;
60
54
55
+ /**
56
+ * Whether to dump the current build configuration in case the configuration from the previous build isn't found
57
+ */
58
+ @ Parameter (defaultValue = "false" , property = "quarkus.track-config-changes.dump-current-when-recorded-unavailable" )
59
+ boolean dumpCurrentWhenRecordedUnavailable ;
60
+
61
61
@ Override
62
62
protected boolean beforeExecute () throws MojoExecutionException , MojoFailureException {
63
63
if (skip ) {
@@ -102,16 +102,17 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
102
102
compareFile = recordedBuildConfigDirectory .toPath ().resolve (this .recordedBuildConfigFile .toPath ());
103
103
}
104
104
105
- if (!Files .exists (compareFile )) {
105
+ final Properties compareProps = new Properties ();
106
+ if (Files .exists (compareFile )) {
107
+ try (BufferedReader reader = Files .newBufferedReader (compareFile )) {
108
+ compareProps .load (reader );
109
+ } catch (IOException e ) {
110
+ throw new RuntimeException ("Failed to read " + compareFile , e );
111
+ }
112
+ } else if (!dumpCurrentWhenRecordedUnavailable ) {
106
113
getLog ().info (compareFile + " not found" );
107
114
return ;
108
115
}
109
- final Properties compareProps = new Properties ();
110
- try (BufferedReader reader = Files .newBufferedReader (compareFile )) {
111
- compareProps .load (reader );
112
- } catch (IOException e ) {
113
- throw new RuntimeException ("Failed to read " + compareFile , e );
114
- }
115
116
116
117
CuratedApplication curatedApplication = null ;
117
118
QuarkusClassLoader deploymentClassLoader = null ;
@@ -124,11 +125,11 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
124
125
Thread .currentThread ().setContextClassLoader (deploymentClassLoader );
125
126
126
127
final Class <?> codeGenerator = deploymentClassLoader .loadClass ("io.quarkus.deployment.CodeGenerator" );
127
- final Method dumpConfig = codeGenerator .getMethod ("readCurrentConfigValues " , ApplicationModel .class , String .class ,
128
- Properties .class , QuarkusClassLoader .class , Properties .class );
129
- actualProps = ( Properties ) dumpConfig .invoke (null , curatedApplication .getApplicationModel (),
128
+ final Method dumpConfig = codeGenerator .getMethod ("dumpCurrentConfigValues " , ApplicationModel .class , String .class ,
129
+ Properties .class , QuarkusClassLoader .class , Properties .class , Path . class );
130
+ dumpConfig .invoke (null , curatedApplication .getApplicationModel (),
130
131
launchMode .name (), getBuildSystemProperties (true ),
131
- deploymentClassLoader , compareProps );
132
+ deploymentClassLoader , compareProps , targetFile );
132
133
} catch (Exception any ) {
133
134
throw new MojoExecutionException ("Failed to bootstrap Quarkus application" , any );
134
135
} finally {
@@ -140,24 +141,5 @@ protected void doExecute() throws MojoExecutionException, MojoFailureException {
140
141
deploymentClassLoader .close ();
141
142
}
142
143
}
143
-
144
- final List <String > names = new ArrayList <>(actualProps .stringPropertyNames ());
145
- Collections .sort (names );
146
-
147
- final Path outputDir = targetFile .getParent ();
148
- if (outputDir != null && !Files .exists (outputDir )) {
149
- try {
150
- Files .createDirectories (outputDir );
151
- } catch (IOException e ) {
152
- throw new UncheckedIOException (e );
153
- }
154
- }
155
- try (BufferedWriter writer = Files .newBufferedWriter (targetFile )) {
156
- for (var name : names ) {
157
- ConfigTrackingWriter .write (writer , name , actualProps .getProperty (name ));
158
- }
159
- } catch (IOException e ) {
160
- throw new UncheckedIOException (e );
161
- }
162
144
}
163
145
}
0 commit comments