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 settings-read
34   * @phase validate
35   * @description Goal which read settings and dump it to a file
36   */
37  public class SettingsReadItMojo
38      extends AbstractMojo
39  {
40      /**
41       * @parameter expression="${settings}"
42       * @required
43       * @readonly
44       */
45      private Settings settings;
46  
47      /**
48       * @parameter default-value="target/settings-dump.xml"
49       * @required
50       */
51      private File dumpFile;
52  
53      public void execute()
54          throws MojoExecutionException
55      {
56          if ( dumpFile.exists() )
57          {
58              dumpFile.delete();
59          }
60          dumpFile.getParentFile().mkdirs();
61          FileWriter fw = null;
62          try
63          {
64              fw = new FileWriter( dumpFile );
65              SettingsXpp3Writer writer = new SettingsXpp3Writer();
66              writer.write( fw, settings );
67          }
68          catch ( IOException e )
69          {
70              throw new MojoExecutionException( e.getMessage(), e );
71          }
72          finally
73          {
74              IOUtil.close( fw );
75          }
76      }
77  
78  
79  }