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  /*
19   * Licensed to the Apache Software Foundation (ASF) under one
20   * or more contributor license agreements.  See the NOTICE file 
21   * distributed with this work for additional information
22   * regarding copyright ownership.  The ASF licenses this file
23   * to you under the Apache License, Version 2.0 (the
24   * "License"); you may not use this file except in compliance
25   * with the License.  You may obtain a copy of the License at
26   * 
27   *   http://www.apache.org/licenses/LICENSE-2.0
28   * 
29   * Unless required by applicable law or agreed to in writing, 
30   * software distributed under the License is distributed on an
31   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
32   * KIND, either express or implied.  See the License for the 
33   * specific language governing permissions and limitations 
34   * under the License.
35   */
36  
37  import org.apache.maven.model.Profile;
38  import org.apache.maven.plugin.MojoExecutionException;
39  
40  import java.util.Iterator;
41  import java.util.List;
42  import java.util.Properties;
43  
44  /**
45   * Writes properties of all active profiles to a file.
46   *
47   * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a>
48   * @version $Id: WriteActiveProfileProperties.java 8861 2009-01-21 15:35:38Z pgier $
49   * @goal write-active-profile-properties
50   */
51  public class WriteActiveProfileProperties extends AbstractWritePropertiesMojo
52  {
53      public void execute()
54          throws MojoExecutionException
55      {
56          validateOutputFile();
57          List list = project.getActiveProfiles();
58          if ( getLog().isInfoEnabled() )
59          {
60              getLog().debug( list.size() + " profile(s) active" );
61          }
62          Properties properties = new Properties();
63          for ( Iterator iter = list.iterator(); iter.hasNext(); )
64          {
65              Profile profile = (Profile) iter.next();
66              if ( profile.getProperties() != null )
67              {
68                  properties.putAll( profile.getProperties() );
69              }
70          }
71  
72          writeProperties( properties, outputFile );
73      }
74  }