View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.pluginwizard.service.generator;
35  
36  import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKey;
37  import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKeyHome;
38  import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
39  import fr.paris.lutece.portal.service.datastore.DatastoreService;
40  import fr.paris.lutece.util.ReferenceList;
41  
42  import java.util.Collection;
43  import java.util.HashMap;
44  import java.util.Map;
45  
46  /**
47   * The Pom generator is responsible of generating a project object model used by maven
48   *
49   */
50  public class PomGenerator extends AbstractFileGenerator
51  {
52  
53      private static final String KEY_PREFIX = "plugin-wizard.site_property.";
54  
55      private String _strModelVersion;
56      private String _strGlobalPomVersion;
57      private String _strDependencyCoreVersion;
58      private String _strDependencyRestVersion;
59  
60      /**
61       * {@inheritDoc }
62       */
63      @Override
64      public Map generate( PluginModel pm, String generationSchemeName )
65      {
66          HashMap map = new HashMap( );
67          map.put( getFilePath( pm ), getCode( pm, generationSchemeName ) );
68  
69          return map;
70      }
71  
72      /**
73       * {@inheritDoc }
74       */
75      @Override
76      protected String getCode( PluginModel pm, String generationSchemeName )
77      {
78          Map<String, Object> model = new HashMap<>( );
79          Collection<ConfigurationKey> listKeys = ConfigurationKeyHome.getConfigurationKeysList( );
80  
81          // Fetches the actual configuration values to be replaced in the templates
82          for ( ConfigurationKey key : listKeys )
83          {
84              model.put( key.getKeyDescription( ).trim( ), key.getKeyValue( ) );
85          }
86  
87          model.put( MARK_KOTLIN, isKotlin( ) );
88          model.put( Markers.MARK_PLUGIN, pm );
89          model.put( Markers.MARK_GLOBAL_POM_VERSION, getGlobalPomVersion( ) );
90          model.put( Markers.MARK_CORE_VERSION, getDependencyCoreVersion( ) );
91          model.put( Markers.MARK_DEPENDECY_REST_VERSION, getDependencyRestVersion( ) );
92          model.put( Markers.MARK_POM_MODEL_VERSION, getModelVersion( ) );
93  
94          return build( model );
95      }
96  
97      /**
98       * {@inheritDoc }
99       */
100     @Override
101     protected String getFilename( PluginModel pm )
102     {
103         return "pom.xml";
104     }
105 
106     /**
107      * {@inheritDoc }
108      */
109     @Override
110     public String getPath( )
111     {
112         return "";
113     }
114 
115     /**
116      * get pom model version
117      * 
118      * @return the pom model version
119      */
120     public String getModelVersion( )
121     {
122         return _strModelVersion;
123     }
124 
125     /**
126      * set PomModelVersion
127      * 
128      * @param strPomModelVersion
129      */
130     public void setModelVersion( String strModelVersion )
131     {
132         this._strModelVersion = strModelVersion;
133     }
134 
135     /**
136      * get global pom Version
137      * 
138      * @return the global Pom Version
139      */
140     public String getGlobalPomVersion( )
141     {
142         return _strGlobalPomVersion;
143     }
144 
145     /**
146      * set Pom Parent Version
147      * 
148      * @param strVersion
149      */
150     public void setGlobalPomVersion( String strVersion )
151     {
152         this._strGlobalPomVersion = strVersion;
153     }
154 
155     /**
156      * get Dependency Core Version
157      * 
158      * @return the Dependency Core Version
159      */
160     public String getDependencyCoreVersion( )
161     {
162         return _strDependencyCoreVersion;
163     }
164 
165     /**
166      * set Dependency Core Version
167      * 
168      * @param strDependencyCoreVersion
169      */
170     public void setDependencyCoreVersion( String strDependencyCoreVersion )
171     {
172         this._strDependencyCoreVersion = strDependencyCoreVersion;
173     }
174 
175     /**
176      * get Dependency Rest Version
177      * 
178      * @return the Dependency Rest Version
179      */
180     public String getDependencyRestVersion( )
181     {
182         return _strDependencyRestVersion;
183     }
184 
185     /**
186      * set Dependency Rest Version
187      * 
188      * @param strDependencyRestVersion
189      */
190     public void setDependencyRestVersion( String strDependencyRestVersion )
191     {
192         this._strDependencyRestVersion = strDependencyRestVersion;
193     }
194 }