@Test public void localComparator() { RepositoryAtom local = RepositoryAtom.parse("/opt/ply/repo"); RepositoryAtom remote = RepositoryAtom.parse("http: List<RepositoryAtom> repos = new ArrayList<RepositoryAtom>(2); repos.add(remote); repos.add(local); Collections.sort(repos, RepositoryAtom.LOCAL_COMPARATOR); assertSame(local, repos.get(0)); assertSame(remote, repos.get(1)); repos.clear(); repos.add(local); repos.add(remote); Collections.sort(repos, RepositoryAtom.LOCAL_COMPARATOR); assertSame(local, repos.get(0)); assertSame(remote, repos.get(1)); }
public static RepositoryAtom parse(String atom) { if ((atom == null) || atom.isEmpty()) { return null; } Type type; if (atom.startsWith(MAVEN_REPO_TYPE_PREFIX)) { type = Type.maven; atom = atom.substring(MAVEN_REPO_TYPE_PREFIX.length()); } else if (atom.startsWith(PLY_REPO_TYPE_PREFIX)) { type = Type.ply; atom = atom.substring(PLY_REPO_TYPE_PREFIX.length()); } else { type = Type.ply; } String preResolved = atom; atom = FileUtil.resolveUnixTilde(atom); URI repositoryUri; File localRef = new File(atom); try { localRef = localRef.getCanonicalFile(); if (localRef.isDirectory()) { if (!atom.startsWith("/")) { String resolved = localRef.getCanonicalPath(); if (resolved.startsWith("file: return new RepositoryAtom(preResolved, localRef.toURI(), type); } } atom = "file: } } catch (IOException ioe) { } try { atom = atom.startsWith("file:") ? FileUtil.encodeForURI(atom) : atom; repositoryUri = URI.create(atom); } catch (IllegalArgumentException iae) { Output.print(iae); return null; } return new RepositoryAtom(preResolved, repositoryUri, type); }
RepositoryAtom { public static RepositoryAtom parse(String atom) { if ((atom == null) || atom.isEmpty()) { return null; } Type type; if (atom.startsWith(MAVEN_REPO_TYPE_PREFIX)) { type = Type.maven; atom = atom.substring(MAVEN_REPO_TYPE_PREFIX.length()); } else if (atom.startsWith(PLY_REPO_TYPE_PREFIX)) { type = Type.ply; atom = atom.substring(PLY_REPO_TYPE_PREFIX.length()); } else { type = Type.ply; } String preResolved = atom; atom = FileUtil.resolveUnixTilde(atom); URI repositoryUri; File localRef = new File(atom); try { localRef = localRef.getCanonicalFile(); if (localRef.isDirectory()) { if (!atom.startsWith("/")) { String resolved = localRef.getCanonicalPath(); if (resolved.startsWith("file: return new RepositoryAtom(preResolved, localRef.toURI(), type); } } atom = "file: } } catch (IOException ioe) { } try { atom = atom.startsWith("file:") ? FileUtil.encodeForURI(atom) : atom; repositoryUri = URI.create(atom); } catch (IllegalArgumentException iae) { Output.print(iae); return null; } return new RepositoryAtom(preResolved, repositoryUri, type); } }
RepositoryAtom { public static RepositoryAtom parse(String atom) { if ((atom == null) || atom.isEmpty()) { return null; } Type type; if (atom.startsWith(MAVEN_REPO_TYPE_PREFIX)) { type = Type.maven; atom = atom.substring(MAVEN_REPO_TYPE_PREFIX.length()); } else if (atom.startsWith(PLY_REPO_TYPE_PREFIX)) { type = Type.ply; atom = atom.substring(PLY_REPO_TYPE_PREFIX.length()); } else { type = Type.ply; } String preResolved = atom; atom = FileUtil.resolveUnixTilde(atom); URI repositoryUri; File localRef = new File(atom); try { localRef = localRef.getCanonicalFile(); if (localRef.isDirectory()) { if (!atom.startsWith("/")) { String resolved = localRef.getCanonicalPath(); if (resolved.startsWith("file: return new RepositoryAtom(preResolved, localRef.toURI(), type); } } atom = "file: } } catch (IOException ioe) { } try { atom = atom.startsWith("file:") ? FileUtil.encodeForURI(atom) : atom; repositoryUri = URI.create(atom); } catch (IllegalArgumentException iae) { Output.print(iae); return null; } return new RepositoryAtom(preResolved, repositoryUri, type); } RepositoryAtom(String preResolvedUri, URI repositoryUri, Type type);  RepositoryAtom(String preResolvedUri, URI repositoryUri); }
RepositoryAtom { public static RepositoryAtom parse(String atom) { if ((atom == null) || atom.isEmpty()) { return null; } Type type; if (atom.startsWith(MAVEN_REPO_TYPE_PREFIX)) { type = Type.maven; atom = atom.substring(MAVEN_REPO_TYPE_PREFIX.length()); } else if (atom.startsWith(PLY_REPO_TYPE_PREFIX)) { type = Type.ply; atom = atom.substring(PLY_REPO_TYPE_PREFIX.length()); } else { type = Type.ply; } String preResolved = atom; atom = FileUtil.resolveUnixTilde(atom); URI repositoryUri; File localRef = new File(atom); try { localRef = localRef.getCanonicalFile(); if (localRef.isDirectory()) { if (!atom.startsWith("/")) { String resolved = localRef.getCanonicalPath(); if (resolved.startsWith("file: return new RepositoryAtom(preResolved, localRef.toURI(), type); } } atom = "file: } } catch (IOException ioe) { } try { atom = atom.startsWith("file:") ? FileUtil.encodeForURI(atom) : atom; repositoryUri = URI.create(atom); } catch (IllegalArgumentException iae) { Output.print(iae); return null; } return new RepositoryAtom(preResolved, repositoryUri, type); } RepositoryAtom(String preResolvedUri, URI repositoryUri, Type type);  RepositoryAtom(String preResolvedUri, URI repositoryUri); String getPropertyName(); String getPreResolvedUri(); String getPropertyValue(); Type getResolvedType(); Auth getAuth(); boolean isPlyType(); String getResolvedPropertyValue(); void setAuth(Auth auth); @Override String toString(); Map<String, String> getAuthHeaders(); @Override boolean equals(Object o); @Override int hashCode(); static String atomFromProp(Prop repositoryProp); static RepositoryAtom parse(String atom); }
RepositoryAtom { public static RepositoryAtom parse(String atom) { if ((atom == null) || atom.isEmpty()) { return null; } Type type; if (atom.startsWith(MAVEN_REPO_TYPE_PREFIX)) { type = Type.maven; atom = atom.substring(MAVEN_REPO_TYPE_PREFIX.length()); } else if (atom.startsWith(PLY_REPO_TYPE_PREFIX)) { type = Type.ply; atom = atom.substring(PLY_REPO_TYPE_PREFIX.length()); } else { type = Type.ply; } String preResolved = atom; atom = FileUtil.resolveUnixTilde(atom); URI repositoryUri; File localRef = new File(atom); try { localRef = localRef.getCanonicalFile(); if (localRef.isDirectory()) { if (!atom.startsWith("/")) { String resolved = localRef.getCanonicalPath(); if (resolved.startsWith("file: return new RepositoryAtom(preResolved, localRef.toURI(), type); } } atom = "file: } } catch (IOException ioe) { } try { atom = atom.startsWith("file:") ? FileUtil.encodeForURI(atom) : atom; repositoryUri = URI.create(atom); } catch (IllegalArgumentException iae) { Output.print(iae); return null; } return new RepositoryAtom(preResolved, repositoryUri, type); } RepositoryAtom(String preResolvedUri, URI repositoryUri, Type type);  RepositoryAtom(String preResolvedUri, URI repositoryUri); String getPropertyName(); String getPreResolvedUri(); String getPropertyValue(); Type getResolvedType(); Auth getAuth(); boolean isPlyType(); String getResolvedPropertyValue(); void setAuth(Auth auth); @Override String toString(); Map<String, String> getAuthHeaders(); @Override boolean equals(Object o); @Override int hashCode(); static String atomFromProp(Prop repositoryProp); static RepositoryAtom parse(String atom); static final Comparator<RepositoryAtom> LOCAL_COMPARATOR; static final String MAVEN_REPO_TYPE_PREFIX; static final String PLY_REPO_TYPE_PREFIX; final String preResolvedUri; final URI repositoryUri; final Type type; }