View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    * 
8    * http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  package org.apache.maven.plugin.eclipse;
16  
17  import java.io.File;
18  import java.net.MalformedURLException;
19  import java.net.URL;
20  
21  import org.apache.maven.plugin.MojoExecutionException;
22  import org.apache.maven.plugin.eclipse.writers.workspace.EclipseWorkspaceWriter;
23  import org.apache.maven.plugins.annotations.Mojo;
24  import org.apache.maven.plugins.annotations.Parameter;
25  
26  /**
27   * Configures The following Eclipse Workspace features:
28   * <ul>
29   * <li>Adds the classpath variable MAVEN_REPO to Eclipse.</li>
30   * <li>Optionally load Eclipse code style file via a URL.</li>
31   * </ul>
32   */
33  @Mojo( name = "configure-workspace", requiresProject = false )
34  public class ConfigureWorkspaceMojo
35      extends AbstractWorkspaceMojo
36  {
37      /**
38       * Point to a URL containing code styles content.
39       */
40      @Parameter( property = "eclipse.workspaceCodeStylesURL" )
41      private String workspaceCodeStylesURL;
42  
43      /**
44       * Name of a profile in <code>workspaceCodeStylesURL</code> to activate. Default is the first profile name in the
45       * code style file in <code>workspaceCodeStylesURL</code>
46       */
47      @Parameter( property = "eclipse.workspaceActiveCodeStyleProfileName" )
48      private String workspaceActiveCodeStyleProfileName;
49  
50      public void execute()
51          throws MojoExecutionException
52      {
53          WorkspaceConfiguration config = new WorkspaceConfiguration();
54          config.setWorkspaceDirectory( new File( this.getWorkspace() ) );
55          config.setLocalRepository( this.getLocalRepository() );
56  
57          if ( this.workspaceCodeStylesURL != null )
58          {
59              try
60              {
61                  config.setCodeStylesURL( new URL( workspaceCodeStylesURL ) );
62              }
63              catch ( MalformedURLException e )
64              {
65                  throw new MojoExecutionException( e.getMessage(), e );
66              }
67  
68              config.setActiveStyleProfileName( workspaceActiveCodeStyleProfileName );
69  
70          }
71  
72          new EclipseWorkspaceWriter().init( this.getLog(), config ).write();
73      }
74  
75  }