001package 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 022import org.apache.archiva.metadata.model.MetadataFacet; 023 024import java.util.HashMap; 025import java.util.Map; 026 027public 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 @Override 081 public String getFacetId() 082 { 083 return FACET_ID; 084 } 085 086 @Override 087 public String getName() 088 { 089 // TODO: not needed, perhaps version metadata facet should be separate interface? 090 return null; 091 } 092 093 @Override 094 public Map<String, String> toProperties() 095 { 096 HashMap<String, String> properties = new HashMap<>(); 097 properties.put( "groupId", groupId ); 098 properties.put( "artifactId", artifactId ); 099 properties.put( "packaging", packaging ); 100 if ( parent != null ) 101 { 102 properties.put( "parent.groupId", parent.getGroupId() ); 103 properties.put( "parent.artifactId", parent.getArtifactId() ); 104 properties.put( "parent.version", parent.getVersion() ); 105 } 106 return properties; 107 } 108 109 @Override 110 public void fromProperties( Map<String, String> properties ) 111 { 112 groupId = properties.get( "groupId" ); 113 artifactId = properties.get( "artifactId" ); 114 packaging = properties.get( "packaging" ); 115 String parentArtifactId = properties.get( "parent.artifactId" ); 116 if ( parentArtifactId != null ) 117 { 118 MavenProjectParent parent = new MavenProjectParent(); 119 parent.setGroupId( properties.get( "parent.groupId" ) ); 120 parent.setArtifactId( parentArtifactId ); 121 parent.setVersion( properties.get( "parent.version" ) ); 122 this.parent = parent; 123 } 124 } 125 126 @Override 127 public boolean equals( Object o ) 128 { 129 if ( this == o ) 130 { 131 return true; 132 } 133 if ( !( o instanceof MavenProjectFacet ) ) 134 { 135 return false; 136 } 137 138 MavenProjectFacet that = (MavenProjectFacet) o; 139 140 if ( !artifactId.equals( that.artifactId ) ) 141 { 142 return false; 143 } 144 if ( !groupId.equals( that.groupId ) ) 145 { 146 return false; 147 } 148 if ( !packaging.equals( that.packaging ) ) 149 { 150 return false; 151 } 152 153 return true; 154 } 155 156 @Override 157 public int hashCode() 158 { 159 int result = groupId.hashCode(); 160 result = 31 * result + artifactId.hashCode(); 161 result = 31 * result + packaging.hashCode(); 162 return result; 163 } 164}