001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.geronimo.genesis.plugins.tools;
021    
022    import org.apache.geronimo.genesis.MojoSupport;
023    
024    import org.apache.maven.project.MavenProject;
025    
026    import java.util.Iterator;
027    import java.util.Map;
028    import java.util.ArrayList;
029    import java.util.List;
030    import java.util.Collections;
031    
032    /**
033     * Helper to show all properties.
034     *
035     * @goal show-properties
036     *
037     * @version $Rev: 453829 $ $Date: 2006-10-06 18:26:25 -0700 (Fri, 06 Oct 2006) $
038     */
039    public class ShowPropertiesMojo
040        extends MojoSupport
041    {
042        /**
043         * The maven project.
044         *
045         * @parameter expression="${project}"
046         * @required
047         * @readonly
048         */
049        protected MavenProject project;
050    
051        protected MavenProject getProject() {
052            return project;
053        }
054        
055        protected void doExecute() throws Exception {
056            showProjectProperties();
057            showSystemProperties();
058        }
059    
060        private void logProperties(final Map props) {
061            List list = new ArrayList();
062            list.addAll(props.keySet());
063            Collections.sort(list);
064            
065            Iterator iter = list.iterator();
066            while (iter.hasNext()) {
067                String name = (String)iter.next();
068                String value = String.valueOf(props.get(name));
069                log.info("    " + name + "=" + value);
070            }
071        }
072        
073        private void showProjectProperties() {
074            log.info("Project properties:");
075    
076            Map props = getProject().getProperties();
077            logProperties(props);
078        }
079    
080        private void showSystemProperties() {
081            log.info("System properties:");
082    
083            Map props = System.getProperties();
084            logProperties(props);
085        }
086    }