View Javadoc

1   /**
2    * Copyright 2009-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.mojo.properties;
17  
18  import java.util.Iterator;
19  import java.util.List;
20  import java.util.Properties;
21  
22  import org.apache.maven.model.Profile;
23  import org.apache.maven.plugin.MojoExecutionException;
24  
25  /**
26   * Writes properties of all active profiles to a file.
27   *
28   * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
29   * @version $Id: WriteActiveProfileProperties.java 8861 2009-01-21 15:35:38Z pgier $
30   * @goal write-active-profile-properties
31   */
32  public class WriteActiveProfileProperties extends AbstractWritePropertiesMojo {
33      @Override
34      public void execute() throws MojoExecutionException {
35          validateOutputFile();
36          List<?> list = project.getActiveProfiles();
37          if (getLog().isInfoEnabled()) {
38              getLog().debug(list.size() + " profile(s) active");
39          }
40          Properties properties = new Properties();
41          for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
42              Profile profile = (Profile) iter.next();
43              if (profile.getProperties() != null) {
44                  properties.putAll(profile.getProperties());
45              }
46          }
47  
48          getLog().info("Creating " + outputFile);
49          writeProperties(properties, outputFile);
50      }
51  }