001    package org.apache.archiva.metadata.repository.storage.maven2;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import org.apache.archiva.metadata.model.MetadataFacet;
023    
024    import java.util.HashMap;
025    import java.util.Map;
026    
027    public class MavenProjectFacet
028        implements MetadataFacet
029    {
030        private String groupId;
031    
032        private String artifactId;
033    
034        private MavenProjectParent parent;
035    
036        private String packaging;
037    
038        public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.project";
039    
040        public String getGroupId()
041        {
042            return groupId;
043        }
044    
045        public void setGroupId( String groupId )
046        {
047            this.groupId = groupId;
048        }
049    
050        public String getArtifactId()
051        {
052            return artifactId;
053        }
054    
055        public void setArtifactId( String artifactId )
056        {
057            this.artifactId = artifactId;
058        }
059    
060        public MavenProjectParent getParent()
061        {
062            return parent;
063        }
064    
065        public void setParent( MavenProjectParent parent )
066        {
067            this.parent = parent;
068        }
069    
070        public String getPackaging()
071        {
072            return packaging;
073        }
074    
075        public void setPackaging( String packaging )
076        {
077            this.packaging = packaging;
078        }
079    
080        public String getFacetId()
081        {
082            return FACET_ID;
083        }
084    
085        public String getName()
086        {
087            // TODO: not needed, perhaps version metadata facet should be separate interface?
088            return null;
089        }
090    
091        public Map<String, String> toProperties()
092        {
093            HashMap<String, String> properties = new HashMap<String, String>();
094            properties.put( "groupId", groupId );
095            properties.put( "artifactId", artifactId );
096            properties.put( "packaging", packaging );
097            if ( parent != null )
098            {
099                properties.put( "parent.groupId", parent.getGroupId() );
100                properties.put( "parent.artifactId", parent.getArtifactId() );
101                properties.put( "parent.version", parent.getVersion() );
102            }
103            return properties;
104        }
105    
106        public void fromProperties( Map<String, String> properties )
107        {
108            groupId = properties.get( "groupId" );
109            artifactId = properties.get( "artifactId" );
110            packaging = properties.get( "packaging" );
111            String parentArtifactId = properties.get( "parent.artifactId" );
112            if ( parentArtifactId != null )
113            {
114                MavenProjectParent parent = new MavenProjectParent();
115                parent.setGroupId( properties.get( "parent.groupId" ) );
116                parent.setArtifactId( parentArtifactId );
117                parent.setVersion( properties.get( "parent.version" ) );
118                this.parent = parent;
119            }
120        }
121    
122        @Override
123        public boolean equals( Object o )
124        {
125            if ( this == o )
126            {
127                return true;
128            }
129            if ( !( o instanceof MavenProjectFacet ) )
130            {
131                return false;
132            }
133    
134            MavenProjectFacet that = (MavenProjectFacet) o;
135    
136            if ( !artifactId.equals( that.artifactId ) )
137            {
138                return false;
139            }
140            if ( !groupId.equals( that.groupId ) )
141            {
142                return false;
143            }
144            if ( !packaging.equals( that.packaging ) )
145            {
146                return false;
147            }
148    
149            return true;
150        }
151    
152        @Override
153        public int hashCode()
154        {
155            int result = groupId.hashCode();
156            result = 31 * result + artifactId.hashCode();
157            result = 31 * result + packaging.hashCode();
158            return result;
159        }
160    }