View Javadoc
1   package org.codehaus.mojo.gwt;
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 java.io.File;
23  import java.io.IOException;
24  import java.util.Collection;
25  
26  import org.apache.maven.plugin.MojoExecutionException;
27  import org.apache.maven.plugin.MojoFailureException;
28  import org.apache.maven.plugins.annotations.LifecyclePhase;
29  import org.apache.maven.plugins.annotations.Mojo;
30  import org.apache.maven.plugins.annotations.Parameter;
31  import org.codehaus.plexus.util.FileUtils;
32  
33  /**
34   * Copy GWT java source code and module descriptor as resources in the build
35   * outputDirectory. Alternative to declaring a <resource> in the POM with finer
36   * filtering as the module descriptor is read to detect sources to be copied.
37   * 
38   * @author <a href="mailto:nicolas@apache.org">Nicolas De Loof</a>
39   * @deprecated use maven-source-plugin and sources classifier dependencies instead
40   */
41  @Deprecated
42  @Mojo(name = "resources", defaultPhase = LifecyclePhase.PROCESS_RESOURCES, threadSafe = true)
43  public class GwtResourcesMojo
44      extends GwtResourcesBaseMojo
45  {
46      @Parameter(defaultValue = "${project.build.outputDirectory}", required = true, readonly = true)
47      private File outputDirectory;
48  
49      /**
50       * {@inheritDoc}
51       * 
52       * @see org.apache.maven.plugin.Mojo#execute()
53       */
54      public void execute()
55          throws MojoExecutionException, MojoFailureException
56      {
57          Collection<ResourceFile> files = getAllResourceFiles();
58          for ( ResourceFile file : files )
59          {
60              File f = new File( file.basedir, file.fileRelativeName );
61              File target = new File( outputDirectory, file.fileRelativeName );
62              try
63              {
64                  getLog().debug( "copy " + f + " to outputDirectory" );
65                  if ( !target.getParentFile().exists() )
66                  {
67                      if ( !target.getParentFile().mkdirs() )
68                      {
69                          throw new MojoExecutionException( "Failed to create destination directory "
70                              + target.getParentFile() );
71                      }
72                  }
73                  FileUtils.copyFile( f, target );
74              }
75              catch ( IOException e )
76              {
77                  throw new MojoExecutionException( "Failed to copy GWT source " + f, e );
78              }
79          }
80      }
81  }