001    /**
002     * Copyright 2010-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.codehaus.mojo.license.model;
017    
018    import org.apache.maven.artifact.Artifact;
019    import org.apache.maven.model.License;
020    
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    /**
025     * Contains the license information for a single project/dependency
026     *
027     * @author pgier
028     * @since 1.0
029     */
030    public class ProjectLicenseInfo
031    {
032        private String groupId;
033    
034        private String artifactId;
035    
036        private String version;
037    
038        private List<License> licenses = new ArrayList<License>();
039    
040        private String licenseResolutionResult;
041    
042        public String getLicenseResolutionResult()
043        {
044            return licenseResolutionResult;
045        }
046    
047        public void setLicenseResolutionResult( String licenseResolutionResult )
048        {
049            this.licenseResolutionResult = licenseResolutionResult;
050        }
051    
052        /**
053         * Default constructor
054         */
055        public ProjectLicenseInfo()
056        {
057    
058        }
059    
060        public ProjectLicenseInfo( String groupId, String artifactId, String version )
061        {
062            this.groupId = groupId;
063            this.artifactId = artifactId;
064            this.version = version;
065        }
066    
067        public String getGroupId()
068        {
069            return groupId;
070        }
071    
072        public void setGroupId( String groupId )
073        {
074            this.groupId = groupId;
075        }
076    
077        public String getArtifactId()
078        {
079            return artifactId;
080        }
081    
082        public void setArtifactId( String artifactId )
083        {
084            this.artifactId = artifactId;
085        }
086    
087        public String getVersion()
088        {
089            return version;
090        }
091    
092        public void setVersion( String version )
093        {
094            this.version = version;
095        }
096    
097        public List<License> getLicenses()
098        {
099            return licenses;
100        }
101    
102        public void setLicenses( List<License> licenses )
103        {
104            this.licenses = licenses;
105        }
106    
107        public void addLicense( License license )
108        {
109            licenses.add( license );
110        }
111    
112        public String toString()
113        {
114            return getId();
115        }
116    
117        /**
118         * The unique ID for the project
119         *
120         * @return String containing "groupId:artifactId"
121         */
122        public String getId()
123        {
124            return groupId + ":" + artifactId;
125        }
126    
127        /**
128         * Compare this artifact to another ProjectLicenseInfo, or compare to an instance
129         * of org.apache.maven.artifact.Artifact
130         */
131        public boolean equals( Object compareTo )
132        {
133            if ( compareTo instanceof ProjectLicenseInfo )
134            {
135                ProjectLicenseInfo compare = (ProjectLicenseInfo) compareTo;
136                if ( groupId.equals( compare.getGroupId() ) && artifactId.equals( compare.getArtifactId() ) )
137                {
138                    return true;
139                }
140            }
141            if ( compareTo instanceof Artifact )
142            {
143                Artifact compare = (Artifact) compareTo;
144                if ( groupId.equals( compare.getGroupId() ) && artifactId.equals( compare.getArtifactId() ) )
145                {
146                    return true;
147                }
148            }
149            return false;
150        }
151    
152        public int hashCode()
153        {
154            return getId().hashCode();
155        }
156    
157    }