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  package org.apache.maven.plugin.eclipse.writers.rad;
20  
21  import java.io.File;
22  import java.io.FileOutputStream;
23  import java.io.IOException;
24  import java.io.OutputStreamWriter;
25  import java.io.Writer;
26  
27  import org.apache.maven.artifact.repository.ArtifactRepository;
28  import org.apache.maven.plugin.MojoExecutionException;
29  import org.apache.maven.plugin.eclipse.Constants;
30  import org.apache.maven.plugin.eclipse.EclipseSourceDir;
31  import org.apache.maven.plugin.eclipse.Messages;
32  import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
33  import org.apache.maven.plugin.eclipse.writers.wtp.AbstractWtpResourceWriter;
34  import org.codehaus.plexus.util.IOUtil;
35  import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
36  import org.codehaus.plexus.util.xml.XMLWriter;
37  
38  /**
39   * Creates a .settings folder for Eclipse WTP 1.x release and writes out the configuration under it.
40   * 
41   * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven</a>
42   */
43  public class RadWebsiteConfigWriter
44      extends AbstractEclipseWriter
45  {
46  
47      private static final String WEBSITE_CONFIG_FILENAME = ".website-config";
48  
49      private static final String WEBSITE_CONFIG_STRUCTURE = "structure";
50  
51      private static final String WEBSITE_CONFIG_VERSION = "version";
52  
53      private static final String WEBSITE_CONFIG_WEBSITE = "website";
54  
55      /**
56       * write the website-config file for RAD6 if needed.
57       * 
58       * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
59       * @param sourceDirs all eclipse source directorys
60       * @param localRepository the local reposetory
61       * @param buildOutputDirectory build output directory (target)
62       * @throws MojoExecutionException when writing the config files was not possible
63       */
64      public void write()
65          throws MojoExecutionException
66      {
67          Writer w;
68          if ( Constants.PROJECT_PACKAGING_WAR.equalsIgnoreCase( config.getPackaging() ) )
69          {
70              try
71              {
72                  w =
73                      new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
74                                                                              WEBSITE_CONFIG_FILENAME ) ), "UTF-8" );
75              }
76              catch ( IOException ex )
77              {
78                  throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
79              }
80              XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
81              writeModuleTypeFacetCore( writer );
82              IOUtil.close( w );
83          }
84      }
85  
86      /**
87       * write the website-config file.
88       * 
89       * @param writer wher to write to
90       */
91      private void writeModuleTypeFacetCore( XMLWriter writer )
92      {
93          writer.startElement( WEBSITE_CONFIG_WEBSITE );
94          writer.addAttribute( WEBSITE_CONFIG_VERSION, "600" );
95          writer.startElement( WEBSITE_CONFIG_STRUCTURE );
96          writer.endElement();
97          writer.endElement();
98      }
99  }