/** * Returns a relative path that should be unique across all remote and packages, based on the * repository and package names. */ public PathFragment getPathFragment() { return repository.isDefault() ? pkgName : new PathFragment(ExternalPackage.NAME) .getRelative(repository.strippedName()) .getRelative(pkgName); }
@Override public int compareTo(PackageIdentifier that) { return ComparisonChain.start() .compare(repository.toString(), that.repository.toString()) .compare(pkgName, that.pkgName) .result(); }
@Override public boolean equals(Object object) { if (this == object) { return true; } if (!(object instanceof PackageIdentifier)) { return false; } PackageIdentifier that = (PackageIdentifier) object; return pkgName.equals(that.pkgName) && repository.equals(that.repository); }
/** * Returns the name of this package. * * <p>There are certain places that expect the path fragment as the package name ('foo/bar') as a * package identifier. This isn't specific enough for packages in other repositories, so their * stringified version is '@baz//foo/bar'. */ @Override public String toString() { return (repository.isDefault() ? "" : repository + "//") + pkgName; }
public PackageIdentifier(String repository, PathFragment pkgName) throws SyntaxException { this(RepositoryName.create(repository), pkgName); }