Coverage Report - org.apache.maven.plugin.idea.IdeaMojo
 
Classes in this File Line Coverage Branch Coverage Complexity
IdeaMojo
84%
21/25
50%
1/2
1,6
 
 1  
 package org.apache.maven.plugin.idea;
 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.artifact.manager.WagonManager;
 23  
 import org.apache.maven.plugin.MojoExecutionException;
 24  
 import org.apache.maven.project.MavenProject;
 25  
 
 26  
 import java.util.HashSet;
 27  
 import java.util.List;
 28  
 import java.util.Set;
 29  
 
 30  
 /**
 31  
  * Goal for generating IDEA files from a POM.
 32  
  * This plug-in provides the ability to generate project files (.ipr, .iml and .iws files) for IDEA.
 33  
  *
 34  
  * @goal idea
 35  
  * @execute phase="generate-resources"
 36  
  */
 37  6
 public class IdeaMojo
 38  
     extends AbstractIdeaMojo
 39  
 {
 40  
     /**
 41  
      * The reactor projects in a multi-module build.
 42  
      *
 43  
      * @parameter expression="${reactorProjects}"
 44  
      * @required
 45  
      * @readonly
 46  
      */
 47  
     private List reactorProjects;
 48  
 
 49  
     /**
 50  
      * @component
 51  
      */
 52  
     private WagonManager wagonManager;
 53  
 
 54  
     /**
 55  
      * Whether to link the reactor projects as dependency modules or as libraries.
 56  
      *
 57  
      * @parameter expression="${linkModules}" default-value="true"
 58  
      */
 59  
     private boolean linkModules;
 60  
 
 61  
     /**
 62  
      * Specify the location of the deployment descriptor file, if one is provided.
 63  
      *
 64  
      * @parameter expression="${deploymentDescriptorFile}"
 65  
      */
 66  
     private String deploymentDescriptorFile;
 67  
 
 68  
     /**
 69  
      * Whether to use full artifact names when referencing libraries.
 70  
      *
 71  
      * @parameter expression="${useFullNames}" default-value="false"
 72  
      */
 73  
     private boolean useFullNames;
 74  
 
 75  
     /**
 76  
      * Enables/disables the downloading of source attachments.
 77  
      *
 78  
      * @parameter expression="${downloadSources}" default-value="false"
 79  
      */
 80  
     private boolean downloadSources;
 81  
 
 82  
     /**
 83  
      * Enables/disables the downloading of javadoc attachments.
 84  
      *
 85  
      * @parameter expression="${downloadJavadocs}" default-value="false"
 86  
      */
 87  
     private boolean downloadJavadocs;
 88  
 
 89  
     /**
 90  
      * Sets the classifier string attached to an artifact source archive name.
 91  
      *
 92  
      * @parameter expression="${sourceClassifier}" default-value="sources"
 93  
      */
 94  
     private String sourceClassifier;
 95  
 
 96  
     /**
 97  
      * Sets the classifier string attached to an artifact javadoc archive name.
 98  
      *
 99  
      * @parameter expression="${javadocClassifier}" default-value="javadoc"
 100  
      */
 101  
     private String javadocClassifier;
 102  
 
 103  
     /**
 104  
      * Specify the name of the registered IDEA JDK to use
 105  
      * for the project.
 106  
      *
 107  
      * @parameter expression="${jdkName}"
 108  
      */
 109  
     private String jdkName;
 110  
 
 111  
     /**
 112  
      * Specify the version of the JDK to use for the project for the purpose of
 113  
      * enabled assertions and Java 5.0 language features.
 114  
      * The default value is the specification version of the executing JVM.
 115  
      *
 116  
      * @parameter expression="${jdkLevel}"
 117  
      * @todo would be good to use the compilation source if possible
 118  
      */
 119  
     private String jdkLevel;
 120  
 
 121  
     /**
 122  
      * An optional set of Library objects that allow you to specify a comma separated list of source dirs, class dirs,
 123  
      * or to indicate that the library should be excluded from the module. For example:
 124  
      * <p/>
 125  
      * <pre>
 126  
      * &lt;libraries&gt;
 127  
      *  &lt;library&gt;
 128  
      *      &lt;name&gt;webwork&lt;/name&gt;
 129  
      *      &lt;sources&gt;file://$webwork$/src/java&lt;/sources&gt;
 130  
      *      &lt;!--
 131  
      *      &lt;classes&gt;...&lt;/classes&gt;
 132  
      *      &lt;exclude&gt;true&lt;/exclude&gt;
 133  
      *      --&gt;
 134  
      *  &lt;/library&gt;
 135  
      * &lt;/libraries&gt;
 136  
      * </pre>
 137  
      *
 138  
      * @parameter
 139  
      */
 140  
     private Library[] libraries;
 141  
 
 142  
     /**
 143  
      * A comma-separated list of directories that should be excluded. These directories are in addition to those
 144  
      * already excluded, such as target/classes. A common use of this is to exclude the entire target directory.
 145  
      *
 146  
      * @parameter
 147  
      */
 148  
     private String exclude;
 149  
 
 150  
     /**
 151  
      * Specify the resource pattern in wildcard format, for example "?*.xml;?*.properties".
 152  
      * Currently supports 4.x and 5.x.
 153  
      * Because IDEA doesn't distinguish between source and resources directories, this is needed.
 154  
      * The default value corresponds to any file without a java extension.
 155  
      * Please note that the default value includes package.html files as it's not possible to exclude those.
 156  
      *
 157  
      * @parameter expression="${wildcardResourcePatterns}" default-value="!?*.java"
 158  
      */
 159  
     private String wildcardResourcePatterns;
 160  
 
 161  
     /**
 162  
      * Specify the version of IDEA to target.  This is needed to identify the default formatting of
 163  
      * project-jdk-name used by IDEA.  Currently supports 4.x and 5.x.
 164  
      * <p/>
 165  
      * This will only be used when parameter jdkName is not set.
 166  
      *
 167  
      * @parameter expression="${ideaVersion}" default-value="5.x"
 168  
      */
 169  
     private String ideaVersion;
 170  
 
 171  
     /**
 172  
      * Causes the module libraries to use a short name for all dependencies. This is very convenient but has been
 173  
      * reported to cause problems with IDEA.
 174  
      *
 175  
      * @parameter default-value="false"
 176  
      */
 177  
     private boolean dependenciesAsLibraries;
 178  
 
 179  
     /**
 180  
      * Tell IntelliJ IDEA that this module is an IntelliJ IDEA Plugin.
 181  
      *
 182  
      * @parameter default-value="false"
 183  
      */
 184  
     private boolean ideaPlugin;
 185  
 
 186  
 
 187  
     public void execute()
 188  
         throws MojoExecutionException
 189  
     {
 190  
         try
 191  
         {
 192  4
             doDependencyResolution( executedProject, localRepo );
 193  
         }
 194  0
         catch ( Exception e )
 195  
         {
 196  0
             throw new MojoExecutionException( "Unable to build project dependencies.", e );
 197  4
         }
 198  
 
 199  4
         Set macros = new HashSet();
 200  4
         rewriteModule( macros );
 201  
 
 202  4
         if ( executedProject.isExecutionRoot() )
 203  
         {
 204  4
             rewriteProject( macros );
 205  
 
 206  4
             rewriteWorkspace();
 207  
         }
 208  4
     }
 209  
 
 210  
     private void rewriteModule( Set macros )
 211  
         throws MojoExecutionException
 212  
     {
 213  4
         IdeaModuleMojo mojo = new IdeaModuleMojo();
 214  
 
 215  4
         mojo.initParam( executedProject, artifactFactory, localRepo, artifactResolver, artifactMetadataSource, getLog(),
 216  
                         overwrite, executedProject, reactorProjects, wagonManager, linkModules, useFullNames,
 217  
                         downloadSources, sourceClassifier, downloadJavadocs, javadocClassifier, libraries, macros,
 218  
                         exclude, dependenciesAsLibraries, deploymentDescriptorFile, ideaPlugin, ideaVersion );
 219  
 
 220  4
         mojo.rewriteModule();
 221  4
     }
 222  
 
 223  
     private void rewriteProject( Set macros )
 224  
         throws MojoExecutionException
 225  
     {
 226  4
         IdeaProjectMojo mojo = new IdeaProjectMojo();
 227  
 
 228  4
         mojo.initParam( executedProject, artifactFactory, localRepo, artifactResolver, artifactMetadataSource, getLog(),
 229  
                         overwrite, jdkName, jdkLevel, wildcardResourcePatterns, ideaVersion, macros );
 230  
 
 231  4
         mojo.rewriteProject();
 232  4
     }
 233  
 
 234  
     private void rewriteWorkspace()
 235  
         throws MojoExecutionException
 236  
     {
 237  4
         IdeaWorkspaceMojo mojo = new IdeaWorkspaceMojo();
 238  
 
 239  4
         mojo.initParam( executedProject, artifactFactory, localRepo, artifactResolver, artifactMetadataSource, getLog(),
 240  
                         overwrite );
 241  
 
 242  4
         mojo.rewriteWorkspace();
 243  4
     }
 244  
 
 245  
     public void setProject( MavenProject project )
 246  
     {
 247  0
         this.executedProject = project;
 248  0
     }
 249  
 }