001 package org.codehaus.mojo.properties; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022 import org.apache.maven.model.Profile; 023 import org.apache.maven.plugin.MojoExecutionException; 024 025 import java.util.Iterator; 026 import java.util.List; 027 import java.util.Properties; 028 029 /** 030 * Writes properties of all active profiles to a file. 031 * 032 * @author <a href="mailto:zarars@gmail.com">Zarar Siddiqi</a> 033 * @version $Id: WriteActiveProfileProperties.java 8861 2009-01-21 15:35:38Z pgier $ 034 * @goal write-active-profile-properties 035 */ 036 public class WriteActiveProfileProperties extends AbstractWritePropertiesMojo 037 { 038 public void execute() 039 throws MojoExecutionException 040 { 041 validateOutputFile(); 042 List list = project.getActiveProfiles(); 043 if ( getLog().isInfoEnabled() ) 044 { 045 getLog().debug( list.size() + " profile(s) active" ); 046 } 047 Properties properties = new Properties(); 048 for ( Iterator iter = list.iterator(); iter.hasNext(); ) 049 { 050 Profile profile = (Profile) iter.next(); 051 if ( profile.getProperties() != null ) 052 { 053 properties.putAll( profile.getProperties() ); 054 } 055 } 056 057 writeProperties( properties, outputFile ); 058 } 059 }