Package org.sonatype.nexus.obr.metadata

Examples of org.sonatype.nexus.obr.metadata.ObrResourceReader


    StorageItem obrItem = ObrUtils.getCachedItem(obrUid);

    if (null == obrItem || obrItem.getModified() < backingItem.getModified()) {
      final boolean caching = obrConfiguration.isBundleCacheActive();

      ObrResourceReader reader = null;
      ObrResourceWriter writer = null;

      try {
        reader = obrMetadataSource.getReader(new ManagedObrSite((StorageFileItem) backingItem));
        writer = obrMetadataSource.getWriter(obrUid);

        for (Resource i = reader.readResource(); i != null; i = reader.readResource()) {
          if (caching && !"file".equals(i.getURL().getProtocol())) {
            writer.append(new CacheableResource(i));
          }
          else {
            writer.append(i);
View Full Code Here


   *
   * @param path cached bundle location
   * @return the remote bundle URL
   */
  private String getAbsoluteBundleUrl(final String path) {
    ObrResourceReader reader = null;

    try {
      reader = obrMetadataSource.getReader(new ManagedObrSite(ObrUtils.retrieveObrItem(this)));
      for (Resource i = reader.readResource(); i != null; i = reader.readResource()) {
        // the right entry should have the same path
        if (path.equals(i.getURL().getPath())) {
          return StringUtils.defaultString(i.getProperties().get(CacheableResource.REMOTE_URL), null);
        }
      }
View Full Code Here

  @Test
  public void testObrParsing()
      throws Exception
  {
    final ObrSite testSite = openObrSite(testRepository, "/obr/samples/osgi_alliance_obr.zip");
    final ObrResourceReader reader = obrMetadataSource.getReader(testSite);

    final BufferedReader br =
        new BufferedReader(new InputStreamReader(getResourceAsStream("/obr/samples/osgi_alliance_obr.lst")));

    int numBundles = 0;

    Resource r;
    while ((r = reader.readResource()) != null) {
      assertEquals(br.readLine(), r.toString());
      numBundles++;
    }

    assertNull(br.readLine());

    assertEquals(2710, numBundles);

    reader.close();
    br.close();
  }
View Full Code Here

  @Test
  public void testObrReferral()
      throws Exception
  {
    final ObrSite testSite = openObrSite(testRepository, "/obr/samples/referrals.xml");
    final ObrResourceReader reader = obrMetadataSource.getReader(testSite);

    int numBundles = 0;
    int numExceptions = 0;

    while (true) {
      try {
        final Resource r = reader.readResource();
        if (r != null) {
          numBundles++;
        }
        else {
          break;
        }
      }
      catch (final IOException e) {
        if (++numExceptions > 2) {
          throw e;
        }
      }
    }

    assertEquals(2713, numBundles);
    assertEquals(2, numExceptions);

    reader.close();
  }
View Full Code Here

  {
    final ObrSite testSite = openObrSite(testRepository, "/obr/samples/osgi_alliance_obr.zip");

    final RepositoryItemUid uid = testRepository.createUid("/obr/repository.xml");

    ObrResourceReader reader = obrMetadataSource.getReader(testSite);
    final ObrResourceWriter writer = obrMetadataSource.getWriter(uid);

    final Collection<Resource> bundles = new ArrayList<Resource>();

    Resource r;
    while ((r = reader.readResource()) != null) {
      bundles.add(r);
      writer.append(r);
      writer.flush();
    }

    assertEquals(2710, bundles.size());

    writer.complete();
    writer.close();

    reader = obrMetadataSource.getReader(openObrSite(uid));
    while ((r = reader.readResource()) != null) {
      assertTrue(bundles.remove(r));
    }

    assertEquals(Collections.emptyList(), bundles);
  }
View Full Code Here

  {
    final RepositoryItemUid uid1 = testRepository.createUid("/obr/samples/sample.xml");
    final RepositoryItemUid uid2 = testRepository.createUid("/obr/sample.xml");
    final RepositoryItemUid uid3 = testRepository.createUid("/sample.xml");

    ObrResourceReader reader = obrMetadataSource.getReader(openObrSite(uid1));
    ObrResourceWriter writer = obrMetadataSource.getWriter(uid2);

    final Collection<URL> urls = new ArrayList<URL>();

    Resource r;
    while ((r = reader.readResource()) != null) {
      urls.add(r.getURL());
      writer.append(r);
      writer.flush();
    }

    reader.close();
    writer.complete();
    writer.close();

    reader = obrMetadataSource.getReader(openObrSite(uid2));
    writer = obrMetadataSource.getWriter(uid3);

    while ((r = reader.readResource()) != null) {
      writer.append(r);
    }

    reader.close();
    writer.complete();
    writer.close();

    reader = obrMetadataSource.getReader(openObrSite(uid3));

    while ((r = reader.readResource()) != null) {
      urls.remove(r.getURL());
    }

    reader.close();

    assertEquals(Collections.emptyList(), urls);
  }
View Full Code Here

    RepositoryItemUid uid1 = testRepository.createUid("/obr/samples/long-package-name.xml");
    RepositoryItemUid uid2 = testRepository.createUid("/obr/samples/long-package-name.xml.clone");
    RepositoryItemUid temp;

    for (int i = 0; i < 5; i++) {
      final ObrResourceReader reader = obrMetadataSource.getReader(openObrSite(uid1));
      final ObrResourceWriter writer = obrMetadataSource.getWriter(uid2);

      Resource r;
      while ((r = reader.readResource()) != null) {
        writer.append(r);
        writer.flush();
      }

      reader.close();
      writer.complete();
      writer.close();

      if (i > 0) {
        assertEquals(obrToString(uid1), obrToString(uid2));
View Full Code Here

  private StorageItem retrieveBundleItem(final ResourceStoreRequest request)
      throws IllegalOperationException, ItemNotFoundException, StorageException
  {
    final String path = request.getRequestPath();

    ObrResourceReader reader = null;
    for (final Repository r : getRequestRepositories(request)) {
      try {
        reader = obrMetadataSource.getReader(new ManagedObrSite(ObrUtils.retrieveObrItem(r)));
        for (Resource i = reader.readResource(); i != null; i = reader.readResource()) {
          final URL url = i.getURL();
          if ("file".equals(url.getProtocol()) && path.equals(url.getPath())) {
            return r.retrieveItem(false, request);
          }
        }
View Full Code Here

        // ignore this particular OBR and continue
      }
    }

    if (null == obrItem || lastModified < modified) {
      ObrResourceReader reader = null;
      ObrResourceWriter writer = null;

      try {
        writer = obrMetadataSource.getWriter(createUid(request.getRequestPath()));
        for (final StorageFileItem f : memberObrItems) {
          try {
            reader = obrMetadataSource.getReader(new ManagedObrSite(f));
            for (Resource i = reader.readResource(); i != null; i = reader.readResource()) {
              writer.append(i);
            }
          }
          catch (final IOException e) {
            log.warn("Problem merging OBR metadata from " + f.getRepositoryItemUid(), e);
View Full Code Here

  public static void updateObr(final ObrMetadataSource source, final RepositoryItemUid uid, final Resource resource,
                               boolean adding)
      throws StorageException
  {
    ObrResourceWriter writer = null;
    ObrResourceReader reader = null;

    try {
      writer = source.getWriter(uid);
      reader = source.getReader(new ManagedObrSite(retrieveObrItem(uid.getRepository())));
      for (Resource i = reader.readResource(); i != null; i = reader.readResource()) {
        if (i.equals(resource)) {
          if (adding) // only update once, remove any duplicates
          {
            writer.append(resource);
            adding = false;
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.obr.metadata.ObrResourceReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.