You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MavenProjectFacet.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. package org.apache.archiva.metadata.repository.storage.maven2;
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. import org.apache.archiva.metadata.model.MetadataFacet;
  21. import java.util.HashMap;
  22. import java.util.Map;
  23. public class MavenProjectFacet
  24. implements MetadataFacet
  25. {
  26. private String groupId;
  27. private String artifactId;
  28. private MavenProjectParent parent;
  29. private String packaging;
  30. public static final String FACET_ID = "org.apache.archiva.metadata.repository.storage.maven2.project";
  31. public String getGroupId()
  32. {
  33. return groupId;
  34. }
  35. public void setGroupId( String groupId )
  36. {
  37. this.groupId = groupId;
  38. }
  39. public String getArtifactId()
  40. {
  41. return artifactId;
  42. }
  43. public void setArtifactId( String artifactId )
  44. {
  45. this.artifactId = artifactId;
  46. }
  47. public MavenProjectParent getParent()
  48. {
  49. return parent;
  50. }
  51. public void setParent( MavenProjectParent parent )
  52. {
  53. this.parent = parent;
  54. }
  55. public String getPackaging()
  56. {
  57. return packaging;
  58. }
  59. public void setPackaging( String packaging )
  60. {
  61. this.packaging = packaging;
  62. }
  63. @Override
  64. public String getFacetId()
  65. {
  66. return FACET_ID;
  67. }
  68. @Override
  69. public String getName()
  70. {
  71. // TODO: not needed, perhaps version metadata facet should be separate interface?
  72. return null;
  73. }
  74. @Override
  75. public Map<String, String> toProperties()
  76. {
  77. HashMap<String, String> properties = new HashMap<>();
  78. properties.put( "groupId", groupId );
  79. properties.put( "artifactId", artifactId );
  80. properties.put( "packaging", packaging );
  81. if ( parent != null )
  82. {
  83. properties.put( "parent.groupId", parent.getGroupId() );
  84. properties.put( "parent.artifactId", parent.getArtifactId() );
  85. properties.put( "parent.version", parent.getVersion() );
  86. }
  87. return properties;
  88. }
  89. @Override
  90. public void fromProperties( Map<String, String> properties )
  91. {
  92. groupId = properties.get( "groupId" );
  93. artifactId = properties.get( "artifactId" );
  94. packaging = properties.get( "packaging" );
  95. String parentArtifactId = properties.get( "parent.artifactId" );
  96. if ( parentArtifactId != null )
  97. {
  98. MavenProjectParent parent = new MavenProjectParent();
  99. parent.setGroupId( properties.get( "parent.groupId" ) );
  100. parent.setArtifactId( parentArtifactId );
  101. parent.setVersion( properties.get( "parent.version" ) );
  102. this.parent = parent;
  103. }
  104. }
  105. @Override
  106. public boolean equals( Object o )
  107. {
  108. if ( this == o )
  109. {
  110. return true;
  111. }
  112. if ( !( o instanceof MavenProjectFacet ) )
  113. {
  114. return false;
  115. }
  116. MavenProjectFacet that = (MavenProjectFacet) o;
  117. if ( !artifactId.equals( that.artifactId ) )
  118. {
  119. return false;
  120. }
  121. if ( !groupId.equals( that.groupId ) )
  122. {
  123. return false;
  124. }
  125. if ( !packaging.equals( that.packaging ) )
  126. {
  127. return false;
  128. }
  129. return true;
  130. }
  131. @Override
  132. public int hashCode()
  133. {
  134. int result = groupId.hashCode();
  135. result = 31 * result + artifactId.hashCode();
  136. result = 31 * result + packaging.hashCode();
  137. return result;
  138. }
  139. }