View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.geronimo.genesis.plugins.tools;
21  
22  import org.apache.geronimo.genesis.MojoSupport;
23  
24  import org.apache.maven.project.MavenProject;
25  
26  import java.util.Iterator;
27  import java.util.Map;
28  import java.util.ArrayList;
29  import java.util.List;
30  import java.util.Collections;
31  
32  /**
33   * Helper to show all properties.
34   *
35   * @goal show-properties
36   *
37   * @version $Rev: 453829 $ $Date: 2006-10-06 18:26:25 -0700 (Fri, 06 Oct 2006) $
38   */
39  public class ShowPropertiesMojo
40      extends MojoSupport
41  {
42      /**
43       * The maven project.
44       *
45       * @parameter expression="${project}"
46       * @required
47       * @readonly
48       */
49      protected MavenProject project;
50  
51      protected MavenProject getProject() {
52          return project;
53      }
54      
55      protected void doExecute() throws Exception {
56          showProjectProperties();
57          showSystemProperties();
58      }
59  
60      private void logProperties(final Map props) {
61          List list = new ArrayList();
62          list.addAll(props.keySet());
63          Collections.sort(list);
64          
65          Iterator iter = list.iterator();
66          while (iter.hasNext()) {
67              String name = (String)iter.next();
68              String value = String.valueOf(props.get(name));
69              log.info("    " + name + "=" + value);
70          }
71      }
72      
73      private void showProjectProperties() {
74          log.info("Project properties:");
75  
76          Map props = getProject().getProperties();
77          logProperties(props);
78      }
79  
80      private void showSystemProperties() {
81          log.info("System properties:");
82  
83          Map props = System.getProperties();
84          logProperties(props);
85      }
86  }