This project has retired. For details please refer to its Attic page.
Source code
001package org.apache.archiva.metadata.model.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
022import org.apache.archiva.metadata.model.MetadataFacet;
023import org.apache.commons.lang.StringUtils;
024
025import java.util.HashMap;
026import java.util.Map;
027
028public class MavenArtifactFacet
029    implements MetadataFacet
030{
031    private String classifier;
032
033    private String type;
034
035    private String timestamp;
036
037    private int buildNumber;
038
039    public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.artifact";
040
041    public String getClassifier()
042    {
043        return classifier;
044    }
045
046    public void setClassifier( String classifier )
047    {
048        this.classifier = classifier;
049    }
050
051    public String getType()
052    {
053        return type;
054    }
055
056    public void setType( String type )
057    {
058        this.type = type;
059    }
060
061    public String getTimestamp()
062    {
063        return timestamp;
064    }
065
066    public void setTimestamp( String timestamp )
067    {
068        this.timestamp = timestamp;
069    }
070
071    public int getBuildNumber()
072    {
073        return buildNumber;
074    }
075
076    public void setBuildNumber( int buildNumber )
077    {
078        this.buildNumber = buildNumber;
079    }
080
081    @Override
082    public String getFacetId()
083    {
084        return FACET_ID;
085    }
086
087    @Override
088    public String getName()
089    {
090        // TODO: not needed, perhaps artifact/version metadata facet should be separate interface?
091        return null;
092    }
093
094    @Override
095    public Map<String, String> toProperties()
096    {
097        Map<String, String> properties = new HashMap<>();
098        properties.put( "type", type );
099        if ( classifier != null )
100        {
101            properties.put( "classifier", classifier );
102        }
103        if ( timestamp != null )
104        {
105            properties.put( "timestamp", timestamp );
106        }
107        if ( buildNumber > 0 )
108        {
109            properties.put( "buildNumber", Integer.toString( buildNumber ) );
110        }
111        return properties;
112    }
113
114    @Override
115    public void fromProperties( Map<String, String> properties )
116    {
117        type = properties.get( "type" );
118        classifier = properties.get( "classifier" );
119        timestamp = properties.get( "timestamp" );
120        String buildNumber = properties.get( "buildNumber" );
121        if ( buildNumber != null )
122        {
123            this.buildNumber = Integer.parseInt( buildNumber );
124        }
125    }
126
127    @Override
128    public boolean equals( Object o )
129    {
130        if ( this == o )
131        {
132            return true;
133        }
134        if ( !( o instanceof MavenArtifactFacet ) )
135        {
136            return false;
137        }
138
139        MavenArtifactFacet that = (MavenArtifactFacet) o;
140
141        return StringUtils.equals( that.getClassifier(), this.classifier );
142    }
143
144}