001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.project.model;
017
018import static org.kuali.common.util.ObjectUtils.equalByToString;
019import static org.kuali.common.util.base.Precondition.checkNotBlank;
020
021/**
022 * The project identifier concept is based on two facts:
023 *
024 * <p>
025 * 1 - All Kuali projects produce only one artifact containing executable java code and associated resources.<br>
026 * 2 - There is only one version of any given Kuali project in the java classpath.<br>
027 * </p>
028 *
029 * <p>
030 * Thus, groupId + artifactId is a simple way to uniquely namespace project resources at runtime.
031 *
032 * For example, files residing in the kuali-util project at the following locations:
033 *
034 * <pre>
035 *   src/main/resources/org/kuali/common/kuali-util/foo.txt
036 *   src/main/resources/org/kuali/common/kuali-util/bar.txt
037 * </pre>
038 *
039 * Can be uniquely referenced at runtime as:
040 *
041 * <pre>
042 *   classpath:org/kuali/common/kuali-util/foo.txt
043 *   classpath:org/kuali/common/kuali-util/bar.txt
044 * </pre>
045 *
046 * </p>
047 */
048public final class ProjectIdentifier {
049
050  private final String groupId;
051  private final String artifactId;
052
053  private final String identifier;
054  private final int hashCode;
055
056  public ProjectIdentifier(String groupId, String artifactId) {
057    checkNotBlank(groupId, "groupId");
058    checkNotBlank(artifactId, "artifactId");
059
060    // Finish setting things up
061    this.groupId = groupId;
062    this.artifactId = artifactId;
063    this.identifier = groupId + ":" + artifactId;
064    this.hashCode = identifier.hashCode();
065  }
066
067  public String getGroupId() {
068    return this.groupId;
069  }
070
071  public String getArtifactId() {
072    return this.artifactId;
073  }
074
075  public String getIdentifier() {
076    return identifier;
077  }
078
079  @Override
080  public String toString() {
081    return identifier;
082  }
083
084  @Override
085  public int hashCode() {
086    return hashCode;
087  }
088
089  @Override
090  public boolean equals(Object object) {
091    return equalByToString(this, object);
092  }
093
094}