/** * List the resources. We skip the filter for now. */ @Override public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws Exception { for (ResourceDescriptorImpl d : getIndex().descriptors) { if (Arrays.equals(d.id, rd)) return d; } return null; }
public boolean delete(String repoId, byte[] id) throws Exception { ResourceDescriptorImpl rd = getResourceDescriptor(id); if (rd == null) return false; if (repoId == null) { delete(id); return true; } boolean remove = rd.repositories.remove(repoId); if (rd.repositories.isEmpty()) { delete(rd.id); } else save(); return remove; }
/** * Add a resource descriptor to the index. */ @Override public boolean add(String repoId, ResourceDescriptor rd) throws Exception { ResourceDescriptorImpl rdi = getResourceDescriptor(rd.id); boolean add = false; if (rdi != null) { add = true; logger.debug("adding repo {} to resource {} to index", repoId, rdi); } else { rdi = new ResourceDescriptorImpl(rd); getIndex().descriptors.add(rdi); logger.debug("adding resource {} to index", rdi); } rdi.repositories.add(repoId); event(TYPE.ADD, rdi, null); setDirty(); save(); return add; }
/** * Save the index file. * * @throws Exception */ private void save() throws Exception { if (!dirty) return; Path index = indexFile.toPath(); Path tmp = Files.createTempFile(IO.mkdirs(index.getParent()), "index", null); try (PrintWriter ps = IO.writer(tmp); Formatter frm = new Formatter(ps)) { getIndex().write(frm); } IO.rename(tmp, index); }
public SortedSet<ResourceDescriptor> find(String repoId, String bsn, VersionRange range) throws Exception { TreeSet<ResourceDescriptor> result = new TreeSet<ResourceDescriptor>(RESOURCE_DESCRIPTOR_COMPARATOR); for (ResourceDescriptorImpl r : filter(repoId, null)) { if (!bsn.equals(r.bsn)) continue; if (range != null && !range.includes(r.version)) continue; result.add(r); } return result; }
/** * Add a resource descriptor to the index. */ @Override public boolean add(String repoId, ResourceDescriptor rd) throws Exception { ResourceDescriptorImpl rdi = getResourceDescriptor(rd.id); boolean add = false; if (rdi != null) { add = true; logger.debug("adding repo {} to resource {} to index", repoId, rdi); } else { rdi = new ResourceDescriptorImpl(rd); getIndex().descriptors.add(rdi); logger.debug("adding resource {} to index", rdi); } rdi.repositories.add(repoId); event(TYPE.ADD, rdi, null); setDirty(); save(); return add; }
@Override public boolean delete(String repoId, byte[] id) throws Exception { ResourceDescriptorImpl rd = getResourceDescriptor(id); if (rd == null) return false; if (repoId == null) { delete(id); return true; } boolean remove = rd.repositories.remove(repoId); if (rd.repositories.isEmpty()) { delete(rd.id); } else save(); return remove; }
/** * Save the index file. * * @throws Exception */ private void save() throws Exception { if (!dirty) return; Path index = indexFile.toPath(); Path tmp = Files.createTempFile(IO.mkdirs(index.getParent()), "index", null); try (PrintWriter ps = IO.writer(tmp); Formatter frm = new Formatter(ps)) { getIndex().write(frm); } IO.rename(tmp, index); }
/** * List the resources. We skip the filter for now. */ public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws Exception { for (ResourceDescriptorImpl d : getIndex().descriptors) { if (Arrays.equals(d.id, rd)) return d; } return null; }
@Override public SortedSet<ResourceDescriptor> find(String repoId, String bsn, VersionRange range) throws Exception { TreeSet<ResourceDescriptor> result = new TreeSet<>(RESOURCE_DESCRIPTOR_COMPARATOR); for (ResourceDescriptorImpl r : filter(repoId, null)) { if (!bsn.equals(r.bsn)) continue; if (range != null && !range.includes(r.version)) continue; result.add(r); } return result; }
/** * Add a resource descriptor to the index. */ public boolean add(String repoId, ResourceDescriptor rd) throws Exception { ResourceDescriptorImpl rdi = getResourceDescriptor(rd.id); boolean add = false; if (rdi != null) { add = true; reporter.trace("adding repo %s to resource %s to index", repoId, rdi); } else { rdi = new ResourceDescriptorImpl(rd); getIndex().descriptors.add(rdi); reporter.trace("adding resource %s to index", rdi); } rdi.repositories.add(repoId); event(TYPE.ADD, rdi, null); setDirty(); save(); return add; }
@Override public boolean delete(String repoId, byte[] id) throws Exception { ResourceDescriptorImpl rd = getResourceDescriptor(id); if (rd == null) return false; if (repoId == null) { delete(id); return true; } boolean remove = rd.repositories.remove(repoId); if (rd.repositories.isEmpty()) { delete(rd.id); } else save(); return remove; }
/** * List the resources. We skip the filter for now. */ @Override public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws Exception { for (ResourceDescriptorImpl d : getIndex().descriptors) { if (Arrays.equals(d.id, rd)) return d; } return null; }
public SortedSet<ResourceDescriptor> find(String repoId, String bsn, VersionRange range) throws Exception { TreeSet<ResourceDescriptor> result = new TreeSet<ResourceDescriptor>(RESOURCE_DESCRIPTOR_COMPARATOR); for (ResourceDescriptorImpl r : filter(repoId, null)) { if (!bsn.equals(r.bsn)) continue; if (range != null && !range.includes(r.version)) continue; result.add(r); } return result; }
/** * Add a resource descriptor to the index. */ public boolean add(String repoId, ResourceDescriptor rd) throws Exception { ResourceDescriptorImpl rdi = getResourceDescriptor(rd.id); boolean add = false; if (rdi != null) { add = true; reporter.trace("adding repo %s to resource %s to index", repoId, rdi); } else { rdi = new ResourceDescriptorImpl(rd); getIndex().descriptors.add(rdi); reporter.trace("adding resource %s to index", rdi); } rdi.repositories.add(repoId); event(TYPE.ADD, rdi, null); setDirty(); save(); return add; }
public boolean delete(String repoId, byte[] id) throws Exception { ResourceDescriptorImpl rd = getResourceDescriptor(id); if (rd == null) return false; if (repoId == null) { delete(id); return true; } boolean remove = rd.repositories.remove(repoId); if (rd.repositories.isEmpty()) { delete(rd.id); } else save(); return remove; }
/** * List the resources. We skip the filter for now. */ public ResourceDescriptorImpl getResourceDescriptor(byte[] rd) throws Exception { for (ResourceDescriptorImpl d : getIndex().descriptors) { if (Arrays.equals(d.id, rd)) return d; } return null; }
/** * List the resources. We skip the filter for now. */ @Override public List<ResourceDescriptorImpl> filter(String repoId, String filter) throws Exception { List<ResourceDescriptorImpl> result = new ArrayList<>(); for (ResourceDescriptorImpl rdi : getIndex().descriptors) { if (repoId == null || rdi.repositories.contains(repoId)) result.add(rdi); } return result; }
/** * List the resources. We skip the filter for now. */ public List<ResourceDescriptorImpl> filter(String repoId, String filter) throws Exception { List<ResourceDescriptorImpl> result = new ArrayList<ResourceDescriptorImpl>(); for (ResourceDescriptorImpl rdi : getIndex().descriptors) { if (repoId == null || rdi.repositories.contains(repoId)) result.add(rdi); } return result; }
/** * List the resources. We skip the filter for now. */ @Override public List<ResourceDescriptorImpl> filter(String repoId, String filter) throws Exception { List<ResourceDescriptorImpl> result = new ArrayList<>(); for (ResourceDescriptorImpl rdi : getIndex().descriptors) { if (repoId == null || rdi.repositories.contains(repoId)) result.add(rdi); } return result; }