Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 782f1783f15b1b25e640f914a7c0a7b0966f3150 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2008-2010 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *      Sonatype, Inc. - initial API and implementation
 *******************************************************************************/

package org.eclipse.m2e.core.internal.project.registry;

import org.eclipse.m2e.core.embedder.ArtifactKey;


/**
 * MavenCapability
 * 
 * @author igor
 */
public class MavenCapability extends Capability {

  private static final long serialVersionUID = 8930981127331238566L;

  /**
   * Regular Maven dependency as defined in <dependency/> pom.xml element.
   */
  public static final String NS_MAVEN_ARTIFACT = "maven-artifact"; //$NON-NLS-1$

  /**
   * Import-scoped Maven dependency as defined in <dependencyManagement/> pom.xml element.
   */
  public static final String NS_MAVEN_ARTIFACT_IMPORT = "maven-artifact-import"; //$NON-NLS-1$

  /**
   * Maven parent dependency as defined in <parent/> pom.xml element.
   */
  public static final String NS_MAVEN_PARENT = "maven-parent"; //$NON-NLS-1$

  private final String version;

  private MavenCapability(String namespace, String id, String version) {
    super(namespace, id);
    this.version = version;
  }

  public String getVersion() {
    return version;
  }

  public String toString() {
    return getVersionlessKey().toString() + "/" + version; //$NON-NLS-1$
  }

  public int hashCode() {
    int hash = getVersionlessKey().hashCode();
    hash = hash * 17 + version.hashCode();
    return hash;
  }

  public boolean equals(Object obj) {
    if(this == obj) {
      return true;
    }
    if(!(obj instanceof MavenCapability)) {
      return false;
    }
    MavenCapability other = (MavenCapability) obj;
    return getVersionlessKey().equals(other.getVersionlessKey()) && version.equals(other.version);
  }

  public static MavenCapability createMavenArtifact(ArtifactKey key) {
    return new MavenCapability(NS_MAVEN_ARTIFACT, getId(key), key.getVersion());
  }

  public static MavenCapability createMavenArtifactImport(ArtifactKey key) {
    return new MavenCapability(NS_MAVEN_ARTIFACT_IMPORT, getId(key), key.getVersion());
  }

  public static MavenCapability createMavenParent(ArtifactKey key) {
    return new MavenCapability(NS_MAVEN_PARENT, getId(key), key.getVersion());
  }

  static String getId(ArtifactKey key) {
    StringBuilder sb = new StringBuilder();
    sb.append(key.getGroupId());
    sb.append(':').append(key.getArtifactId());
    if(key.getClassifier() != null) {
      sb.append(':').append(key.getClassifier());
    }
    return sb.toString();
  }

}

Back to the top