Coverage Report - org.apache.maven.plugin.ide.IdeDependency
 
Classes in this File Line Coverage Branch Coverage Complexity
IdeDependency
26%
24/94
0%
0/38
1.541
 
 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.ide;
 20  
 
 21  
 import java.io.File;
 22  
 
 23  
 import org.apache.maven.project.MavenProject;
 24  
 
 25  
 /**
 26  
  * @author Fabrizio Giustina
 27  
  * @version $Id: IdeDependency.java 616964 2008-01-31 00:04:15Z aheritier $
 28  
  */
 29  
 public class IdeDependency
 30  
     implements Comparable
 31  
 {
 32  
     /**
 33  
      * Is this dependency available in the reactor?
 34  
      */
 35  
     private boolean referencedProject;
 36  
 
 37  
     /**
 38  
      * Is this a test dependency?
 39  
      */
 40  
     private boolean testDependency;
 41  
 
 42  
     /**
 43  
      * Is this a system scope dependency?
 44  
      */
 45  
     private boolean systemScoped;
 46  
 
 47  
     /**
 48  
      * Is this a provided dependency?
 49  
      */
 50  
     private boolean provided;
 51  
 
 52  
     /**
 53  
      * Is this dependency added to classpath?
 54  
      */
 55  
     private boolean addedToClasspath;
 56  
 
 57  
     /**
 58  
      * Resolved artifact file.
 59  
      */
 60  
     private File file;
 61  
 
 62  
     /**
 63  
      * Resolved javadoc file.
 64  
      */
 65  
     private File javadocAttachment;
 66  
 
 67  
     /**
 68  
      * Resolved source file.
 69  
      */
 70  
     private File sourceAttachment;
 71  
 
 72  
     /**
 73  
      * Group id.
 74  
      */
 75  
     private String groupId;
 76  
 
 77  
     /**
 78  
      * Artifact id.
 79  
      */
 80  
     private String artifactId;
 81  
 
 82  
     /**
 83  
      * Artifact version.
 84  
      */
 85  
     private String version;
 86  
 
 87  
     /**
 88  
      * Artifact classifier
 89  
      */
 90  
     private String classifier;
 91  
 
 92  
     /**
 93  
      * Artifact type.
 94  
      */
 95  
     private String type;
 96  
 
 97  
     /**
 98  
      * Does this artifact contains a OSGI Manifest?
 99  
      */
 100  
     private boolean osgiBundle;
 101  
 
 102  
     /**
 103  
      * How is this dependency called when it is an eclipse project.
 104  
      */
 105  
     private String eclipseProjectName;
 106  
 
 107  
     /**
 108  
      * Creates an uninitialized instance
 109  
      */
 110  
     public IdeDependency()
 111  2
     {
 112  2
     }
 113  
 
 114  
     /**
 115  
      * @param groupId Group id
 116  
      * @param artifactId Artifact id
 117  
      * @param version Artifact version
 118  
      * @param classifier Artifact classifier
 119  
      * @param referencedProject Is this dependency available in the reactor?
 120  
      * @param testDependency Is this a test dependency?
 121  
      * @param systemScoped Is this a system scope dependency?
 122  
      * @param provided Is this a provided dependency?
 123  
      * @param addedToClasspath Is this dependency added to classpath?
 124  
      * @param file Resolved artifact file
 125  
      * @param type Artifact type
 126  
      * @param osgiBundle Does this artifact contains a OSGI Manifest?
 127  
      * @param osgiSymbolicName Bundle-SymbolicName from the Manifest (if available)
 128  
      * @param dependencyDepth Depth of this dependency in the transitive dependency trail.
 129  
      * @param eclipseProjectName The name of the project in eclipse
 130  
      */
 131  
     public IdeDependency( String groupId, String artifactId, String version, String classifier,
 132  
                           boolean referencedProject, boolean testDependency, boolean systemScoped, boolean provided,
 133  
                           boolean addedToClasspath, File file, String type, boolean osgiBundle,
 134  
                           String osgiSymbolicName, int dependencyDepth, String eclipseProjectName )
 135  0
     {
 136  
         // group:artifact:version
 137  0
         this.groupId = groupId;
 138  0
         this.artifactId = artifactId;
 139  0
         this.version = version;
 140  0
         this.classifier = classifier;
 141  
 
 142  
         // flags
 143  0
         this.referencedProject = referencedProject;
 144  0
         this.testDependency = testDependency;
 145  0
         this.systemScoped = systemScoped;
 146  0
         this.provided = provided;
 147  0
         this.addedToClasspath = addedToClasspath;
 148  
 
 149  
         // needed for OSGI support
 150  0
         this.osgiBundle = osgiBundle;
 151  
         // file and type
 152  0
         this.file = file;
 153  0
         this.type = type;
 154  0
         this.eclipseProjectName = eclipseProjectName;
 155  0
     }
 156  
 
 157  
     /**
 158  
      * Getter for <code>javadocAttachment</code>.
 159  
      * 
 160  
      * @return Returns the javadocAttachment.
 161  
      */
 162  
     public File getJavadocAttachment()
 163  
     {
 164  2
         return javadocAttachment;
 165  
     }
 166  
 
 167  
     /**
 168  
      * Setter for <code>javadocAttachment</code>.
 169  
      * 
 170  
      * @param javadocAttachment The javadocAttachment to set.
 171  
      */
 172  
     public void setJavadocAttachment( File javadocAttachment )
 173  
     {
 174  1
         this.javadocAttachment = javadocAttachment;
 175  1
     }
 176  
 
 177  
     /**
 178  
      * Getter for <code>artifactId</code>.
 179  
      * 
 180  
      * @return Returns the artifactId.
 181  
      */
 182  
     public String getArtifactId()
 183  
     {
 184  9
         return artifactId;
 185  
     }
 186  
 
 187  
     /**
 188  
      * Setter for <code>artifactId</code>.
 189  
      * 
 190  
      * @param artifactId The artifactId to set.
 191  
      */
 192  
     public void setArtifactId( String artifactId )
 193  
     {
 194  2
         this.artifactId = artifactId;
 195  2
     }
 196  
 
 197  
     /**
 198  
      * Getter for <code>groupId</code>.
 199  
      * 
 200  
      * @return Returns the groupId.
 201  
      */
 202  
     public String getGroupId()
 203  
     {
 204  7
         return groupId;
 205  
     }
 206  
 
 207  
     /**
 208  
      * Setter for <code>groupId</code>.
 209  
      * 
 210  
      * @param groupId The groupId to set.
 211  
      */
 212  
     public void setGroupId( String groupId )
 213  
     {
 214  2
         this.groupId = groupId;
 215  2
     }
 216  
 
 217  
     /**
 218  
      * Getter for <code>version</code>.
 219  
      * 
 220  
      * @return Returns the version.
 221  
      */
 222  
     public String getVersion()
 223  
     {
 224  7
         return version;
 225  
     }
 226  
 
 227  
     /**
 228  
      * Setter for <code>version</code>.
 229  
      * 
 230  
      * @param version The version to set.
 231  
      */
 232  
     public void setVersion( String version )
 233  
     {
 234  2
         this.version = version;
 235  2
     }
 236  
 
 237  
     /**
 238  
      * Getter for <code>classifier</code>.
 239  
      * 
 240  
      * @return Returns the classifier.
 241  
      */
 242  
     public String getClassifier()
 243  
     {
 244  1
         return classifier;
 245  
     }
 246  
 
 247  
     /**
 248  
      * Setter for <code>groupId</code>.
 249  
      * 
 250  
      * @param groupId The groupId to set.
 251  
      */
 252  
     public void setClassifier( String classifier )
 253  
     {
 254  0
         this.classifier = classifier;
 255  0
     }
 256  
 
 257  
     /**
 258  
      * Getter for <code>referencedProject</code>.
 259  
      * 
 260  
      * @return Returns the referencedProject.
 261  
      */
 262  
     public boolean isReferencedProject()
 263  
     {
 264  2
         return referencedProject;
 265  
     }
 266  
 
 267  
     /**
 268  
      * Getter for <code>osgiBundle</code>.
 269  
      * 
 270  
      * @return Returns the osgiBundle.
 271  
      */
 272  
     public boolean isOsgiBundle()
 273  
     {
 274  0
         return osgiBundle;
 275  
     }
 276  
 
 277  
     /**
 278  
      * Setter for <code>referencedProject</code>.
 279  
      * 
 280  
      * @param referencedProject The referencedProject to set.
 281  
      */
 282  
     public void setReferencedProject( boolean referencedProject )
 283  
     {
 284  0
         this.referencedProject = referencedProject;
 285  0
     }
 286  
 
 287  
     /**
 288  
      * Getter for <code>sourceAttachment</code>.
 289  
      * 
 290  
      * @return Returns the sourceAttachment.
 291  
      */
 292  
     public File getSourceAttachment()
 293  
     {
 294  1
         return sourceAttachment;
 295  
     }
 296  
 
 297  
     /**
 298  
      * Setter for <code>sourceAttachment</code>.
 299  
      * 
 300  
      * @param sourceAttachment The sourceAttachment to set.
 301  
      */
 302  
     public void setSourceAttachment( File sourceAttachment )
 303  
     {
 304  0
         this.sourceAttachment = sourceAttachment;
 305  0
     }
 306  
 
 307  
     /**
 308  
      * Getter for <code>systemScoped</code>.
 309  
      * 
 310  
      * @return Returns the systemScoped.
 311  
      */
 312  
     public boolean isSystemScoped()
 313  
     {
 314  1
         return systemScoped;
 315  
     }
 316  
 
 317  
     /**
 318  
      * Setter for <code>systemScoped</code>.
 319  
      * 
 320  
      * @param systemScoped The systemScoped to set.
 321  
      */
 322  
     public void setSystemScoped( boolean systemScoped )
 323  
     {
 324  0
         this.systemScoped = systemScoped;
 325  0
     }
 326  
 
 327  
     /**
 328  
      * Getter for <code>testDependency</code>.
 329  
      * 
 330  
      * @return Returns the testDependency.
 331  
      */
 332  
     public boolean isTestDependency()
 333  
     {
 334  0
         return testDependency;
 335  
     }
 336  
 
 337  
     /**
 338  
      * Setter for <code>testDependency</code>.
 339  
      * 
 340  
      * @param testDependency The testDependency to set.
 341  
      */
 342  
     public void setTestDependency( boolean testDependency )
 343  
     {
 344  0
         this.testDependency = testDependency;
 345  0
     }
 346  
 
 347  
     /**
 348  
      * Getter for <code>file</code>.
 349  
      * 
 350  
      * @return Returns the file.
 351  
      */
 352  
     public File getFile()
 353  
     {
 354  1
         return file;
 355  
     }
 356  
 
 357  
     /**
 358  
      * Setter for <code>file</code>.
 359  
      * 
 360  
      * @param file The file to set.
 361  
      */
 362  
     public void setFile( File file )
 363  
     {
 364  1
         this.file = file;
 365  1
     }
 366  
 
 367  
     /**
 368  
      * Getter for <code>artifactId</code>.
 369  
      * 
 370  
      * @return Returns the artifactId.
 371  
      */
 372  
     public String getId()
 373  
     {
 374  0
         return groupId + ':' + artifactId + ':' + version;
 375  
     }
 376  
 
 377  
     /**
 378  
      * Getter for <code>type</code>.
 379  
      * 
 380  
      * @return Returns the type.
 381  
      */
 382  
     public String getType()
 383  
     {
 384  0
         return type;
 385  
     }
 386  
 
 387  
     /**
 388  
      * Setter for <code>type</code>.
 389  
      * 
 390  
      * @param type The type to set.
 391  
      */
 392  
     public void setType( String type )
 393  
     {
 394  0
         this.type = type;
 395  0
     }
 396  
 
 397  
     /**
 398  
      * Getter for <code>addedToClasspath</code>.
 399  
      * 
 400  
      * @return Returns the addedToClasspath.
 401  
      */
 402  
     public boolean isAddedToClasspath()
 403  
     {
 404  1
         return addedToClasspath;
 405  
     }
 406  
 
 407  
     /**
 408  
      * Setter for <code>addedToClasspath</code>.
 409  
      * 
 410  
      * @param addedToClasspath The addedToClasspath to set.
 411  
      */
 412  
     public void setAddedToClasspath( boolean addedToClasspath )
 413  
     {
 414  1
         this.addedToClasspath = addedToClasspath;
 415  1
     }
 416  
 
 417  
     /**
 418  
      * Getter for <code>provided</code>.
 419  
      * 
 420  
      * @return Returns the provided.
 421  
      */
 422  
     public boolean isProvided()
 423  
     {
 424  0
         return provided;
 425  
     }
 426  
 
 427  
     /**
 428  
      * Setter for <code>provided</code>.
 429  
      * 
 430  
      * @param provided The provided to set.
 431  
      */
 432  
     public void setProvided( boolean provided )
 433  
     {
 434  0
         this.provided = provided;
 435  0
     }
 436  
 
 437  
     /**
 438  
      * Getter for <code>eclipseProjectName</code>.
 439  
      * 
 440  
      * @return Returns the eclipseProjectName.
 441  
      */
 442  
     public String getEclipseProjectName()
 443  
     {
 444  0
         return eclipseProjectName;
 445  
     }
 446  
 
 447  
     /**
 448  
      * Setter for <code>eclipseProjectName</code>.
 449  
      * 
 450  
      * @param eclipseProjectName The eclipseProjectName to set.
 451  
      */
 452  
     public void setEclipseProjectName( String eclipseProjectName )
 453  
     {
 454  0
         this.eclipseProjectName = eclipseProjectName;
 455  0
     }
 456  
 
 457  
     /**
 458  
      * @see java.lang.Object#toString()
 459  
      */
 460  
     public String toString()
 461  
     {
 462  0
         return getId();
 463  
     }
 464  
 
 465  
     /**
 466  
      * @see java.lang.Comparable#compareTo(java.lang.Object) Compare using groupId+artifactId+type+classifier Strings
 467  
      */
 468  
     public int compareTo( Object o )
 469  
     {
 470  0
         IdeDependency dep = (IdeDependency) o;
 471  
         // in case of system scoped dependencies the files must be compared.
 472  0
         if ( isSystemScoped() && dep.isSystemScoped() && getFile().equals( dep.getFile() ) )
 473  
         {
 474  0
             return 0;
 475  
         }
 476  0
         int equals = this.getGroupId().compareTo( dep.getGroupId() );
 477  0
         if ( equals != 0 )
 478  
         {
 479  0
             return equals;
 480  
         }
 481  0
         equals = this.getArtifactId().compareTo( dep.getArtifactId() );
 482  0
         if ( equals != 0 )
 483  
         {
 484  0
             return equals;
 485  
         }
 486  0
         equals = this.getType().compareTo( dep.getType() );
 487  0
         if ( equals != 0 )
 488  
         {
 489  0
             return equals;
 490  
         }
 491  0
         if ( this.getClassifier() != null && dep.getClassifier() != null )
 492  
         {
 493  0
             equals = this.getClassifier().compareTo( dep.getClassifier() );
 494  
         }
 495  0
         else if ( this.getClassifier() != null && dep.getClassifier() == null )
 496  
         {
 497  0
             return 1;
 498  
         }
 499  0
         else if ( this.getClassifier() == null && dep.getClassifier() != null )
 500  
         {
 501  0
             return -1;
 502  
         }
 503  0
         if ( equals != 0 )
 504  
         {
 505  0
             return equals;
 506  
         }
 507  0
         return 0;
 508  
     }
 509  
 
 510  
     /**
 511  
      * Is this dependency System scoped outside the eclipse project. This is NOT complete because in reality the check
 512  
      * should mean that any module in the reactor contains the system scope locally!
 513  
      * 
 514  
      * @return Returns this dependency is systemScoped outside the project.
 515  
      */
 516  
     public boolean isSystemScopedOutsideProject( MavenProject project )
 517  
     {
 518  0
         File modulesTop = project.getBasedir();
 519  0
         while ( new File( modulesTop.getParentFile(), "pom.xml" ).exists() )
 520  
         {
 521  0
             modulesTop = modulesTop.getParentFile();
 522  
         }
 523  0
         return isSystemScoped() && !getFile().getAbsolutePath().startsWith( modulesTop.getAbsolutePath() );
 524  
     }
 525  
 
 526  
     /**
 527  
      * {@inheritDoc}
 528  
      */
 529  
     public boolean equals( Object obj )
 530  
     {
 531  0
         return compareTo( obj ) == 0;
 532  
     }
 533  
 
 534  
     /**
 535  
      * {@inheritDoc}
 536  
      */
 537  
     public int hashCode()
 538  
     {
 539  0
         if ( isSystemScoped() )
 540  
         {
 541  0
             return getFile().hashCode();
 542  
         }
 543  
         else
 544  
         {
 545  0
             int hashCode = this.getGroupId().hashCode() ^ this.getArtifactId().hashCode() ^ this.getType().hashCode();
 546  0
             if ( this.getClassifier() == null )
 547  
             {
 548  0
                 return hashCode;
 549  
             }
 550  
             else
 551  
             {
 552  0
                 return hashCode ^ this.getClassifier().hashCode();
 553  
             }
 554  
 
 555  
         }
 556  
     }
 557  
 }