View Javadoc
1   package org.apache.maven.plugin.coreit;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.plugin.AbstractMojo;
23  import org.apache.maven.plugin.MojoExecutionException;
24  import org.apache.maven.settings.Settings;
25  import org.apache.maven.settings.io.xpp3.SettingsXpp3Writer;
26  import org.codehaus.plexus.util.IOUtil;
27  
28  import java.io.File;
29  import java.io.FileWriter;
30  import java.io.IOException;
31  
32  /**
33   * Goal which read settings and dump it to a file
34   *
35   * @goal settings-read
36   * @phase validate
37   */
38  public class SettingsReadItMojo
39      extends AbstractMojo
40  {
41      /**
42       * @parameter default-value="${settings}"
43       * @required
44       * @readonly
45       */
46      private Settings settings;
47  
48      /**
49       * @parameter default-value="target/settings-dump.xml"
50       * @required
51       */
52      private File dumpFile;
53  
54      public void execute()
55          throws MojoExecutionException
56      {
57          if ( dumpFile.exists() )
58          {
59              dumpFile.delete();
60          }
61          dumpFile.getParentFile().mkdirs();
62          FileWriter fw = null;
63          try
64          {
65              fw = new FileWriter( dumpFile );
66              SettingsXpp3Writer writer = new SettingsXpp3Writer();
67              writer.write( fw, settings );
68          }
69          catch ( IOException e )
70          {
71              throw new MojoExecutionException( e.getMessage(), e );
72          }
73          finally
74          {
75              IOUtil.close( fw );
76          }
77      }
78  
79  
80  }