22
33import lombok .extern .slf4j .Slf4j ;
44import org .apache .maven .model .*;
5- import org .codehaus .plexus .util .xml .Xpp3Dom ;
6- import org .codehaus .plexus .util .xml .Xpp3DomBuilder ;
5+ import org .apache .maven .plugins .annotations .LifecyclePhase ;
76import org .fugerit .java .core .cfg .ConfigRuntimeException ;
87import org .fugerit .java .core .io .FileIO ;
9- import org .fugerit .java .core .io .helper .HelperIOException ;
108import org .fugerit .java .core .lang .helpers .StringUtils ;
119import org .maxxq .maven .dependency .ModelIO ;
1210
@@ -21,9 +19,9 @@ public class BasicVenusFacade {
2119
2220 protected BasicVenusFacade () {}
2321
24- protected static final String GROUP_ID = "org.fugerit.java" ;
22+ protected static final String GROUP_ID = VenusConsts . GROUP_ID ;
2523
26- protected static final String KEY_VERSION = "fj-doc-version" ;
24+ protected static final String KEY_VERSION = VenusConsts . KEY_VERSION ;
2725
2826 private static void addOrOverwrite ( List <Dependency > deps , Dependency d ) {
2927 Iterator <Dependency > it = deps .iterator ();
@@ -148,7 +146,8 @@ protected static void addExtensionList( File pomFile, VenusContext context ) thr
148146 addJunit5 ( model , context );
149147 // addLombok parameter
150148 addLombok ( model , context );
151- addPlugin ( context , model );
149+ addDirectPlugin ( context , model );
150+ addVerifyPlugin ( context , model );
152151 log .info ( "end dependencies size : {}" , model .getDependencies ().size () );
153152 try (OutputStream pomStream = new FileOutputStream ( pomFile ) ) {
154153 modelIO .writeModelToStream ( model , pomStream );
@@ -221,41 +220,50 @@ protected static void addExtensionGradleList( File gradleFile, VenusContext cont
221220 FileIO .writeString ( gradleFileContent , gradleFile );
222221 }
223222
224- private static void addPlugin ( VenusContext context , Model model ) throws IOException {
223+ private static void addDirectPlugin (VenusContext context , Model model ) throws IOException {
224+ // addDirectPlugin?
225+ if ( context .isAddDirectPlugin () ) {
226+ if (context .isDirectPluginNotAvailable ()) {
227+ log .warn ("addDirectPlugin skipped, version {} has been selected, minimum required version is : {}" , context .getVersion (), VenusContext .VERSION_NA_DIRECT_PLUGIN );
228+ } else {
229+ FeatureFacade .copyFeatureList ( context .getProjectDir (), "direct" );
230+ log .info ("addDirectPlugin true, version {} has been selected, minimum required version is : {}" , context .getVersion (), VenusContext .VERSION_NA_DIRECT_PLUGIN );
231+ Plugin plugin = PluginUtils .findOrCreatePLugin ( model );
232+ PluginExecution execution = PluginUtils .createPluginExecution (
233+ "venus-direct" , LifecyclePhase .COMPILE .id (), PluginUtils .GOAL_DIRECT );
234+ plugin .getExecutions ().add ( execution );
235+ String xml = "<configuration>\n " +
236+ " <configPath>${project.basedir}/src/main/resources/venus-direct-config/venus-direct-config.yaml</configPath>\n " +
237+ " <outputAll>true</outputAll>\n " +
238+ " <directEnv>\n " +
239+ " <projectBasedir>${project.basedir}</projectBasedir>\n " +
240+ " </directEnv>\n " +
241+ "</configuration>" ;
242+ execution .setConfiguration ( PluginUtils .getPluginConfiguration ( xml ) );
243+ }
244+ } else {
245+ log .info ( "addDirectPlugin : false" );
246+ }
247+ }
248+
249+ private static void addVerifyPlugin (VenusContext context , Model model ) throws IOException {
225250 // addVerifyPlugin?
226251 if ( context .isAddVerifyPlugin () ) {
227252 if ( context .isVerifyPluginNotAvailable () ) {
228253 log .warn ( "addVerifyPlugin skipped, version {} has been selected, minimum required version is : {}" , context .getVersion (), VenusContext .VERSION_NA_VERIFY_PLUGIN );
229254 } else {
230255 log .info ( "addVerifyPlugin true, version {} has been selected, minimum required version is : {}" , context .getVersion (), VenusContext .VERSION_NA_VERIFY_PLUGIN );
231- Build build = model .getBuild ();
232- if ( build == null ) {
233- build = new Build ();
234- model .setBuild ( build );
235- }
236- List <Plugin > plugins = model .getBuild ().getPlugins ();
237- Plugin plugin = new Plugin ();
238- plugin .setGroupId ( GROUP_ID );
239- plugin .setArtifactId ( "fj-doc-maven-plugin" );
240- plugin .setVersion ( "${" +KEY_VERSION +"}" );
241- PluginExecution execution = new PluginExecution ();
242- execution .setId ( "freemarker-verify" );
243- execution .setPhase ( "compile" );
244- execution .addGoal ( "verify" );
256+ Plugin plugin = PluginUtils .findOrCreatePLugin ( model );
257+ PluginExecution execution = PluginUtils .createPluginExecution (
258+ "freemarker-verify" , LifecyclePhase .COMPILE .id (), LifecyclePhase .VERIFY .id () );
245259 plugin .getExecutions ().add ( execution );
246260 String xml = "<configuration>\n " +
247261 " <templateBasePath>${project.basedir}/src/main/resources/" +context .getArtificatIdForFolder ()+"/template</templateBasePath>\n " +
248262 " <generateReport>true</generateReport>\n " +
249263 " <failOnErrors>true</failOnErrors>\n " +
250264 " <reportOutputFolder>${project.build.directory}/freemarker-syntax-verify-report</reportOutputFolder>\n " +
251265 " </configuration>" ;
252- HelperIOException .apply ( () -> {
253- try ( StringReader sr = new StringReader ( xml ) ) {
254- Xpp3Dom dom = Xpp3DomBuilder .build ( sr );
255- plugin .setConfiguration ( dom );
256- }
257- });
258- plugins .add ( plugin );
266+ execution .setConfiguration ( PluginUtils .getPluginConfiguration ( xml ) );
259267 }
260268 } else {
261269 log .info ( "addVerifyPlugin : false" );
0 commit comments