Package org.sonatype.nexus.proxy.repository

Examples of org.sonatype.nexus.proxy.repository.Repository


        }
      }
      return list;
    }

    final Repository combo;

    try {
      combo = registry.getRepository(comboId);
    } catch (final Exception e) {
      return list;
    }

    if (combo instanceof GroupRepository) {
      final GroupRepository group = (GroupRepository) combo;
      final List<Repository> repoList = group.getMemberRepositories();
      for (final Repository repo : repoList) {
        list.add(repo.getId());
      }
    } else {
      list.add(combo.getId());
    }

    return list;

  }
View Full Code Here


      ArtifactUsageCalculationRequest request)
      throws NoSuchRepositoryException, IllegalArgumentException {
    ArtifactUsageCalculationResult result = new ArtifactUsageCalculationResult();

    if (request.getRepositoryId() != null) {
      Repository repository = this.repositoryRegistry
          .getRepository(request.getRepositoryId());
      if (getLogger().isInfoEnabled()) {
        getLogger().info("Running ArtifactUsageCalculation only on " + repository.getId());
      }
      if (MavenRepository.class.isAssignableFrom(repository.getClass())
          && repository.getRepositoryContentClass().isCompatible(contentClass)) {
        result.addResult(calculateArtifactUsage((MavenRepository) repository));
      } else {
        String notAMavenRepository = "The repository with ID=" + repository.getId() + " is not a MavenRepository!";
        getLogger().error(notAMavenRepository);
        throw new IllegalArgumentException(notAMavenRepository);
      }
    } else {
      getLogger().info("Running ArtifactUsageCalculation on all repositories");
      for (Repository repository : this.repositoryRegistry
          .getRepositories()) {
        // skip repositories that aren't Maven repositories
        if (MavenRepository.class.isAssignableFrom(repository.getClass())
            && repository.getRepositoryContentClass().isCompatible(contentClass)) {
          result.addResult(calculateArtifactUsage((MavenRepository) repository));
        } else {
          if (getLogger().isInfoEnabled()) {
            getLogger().info(repository.getId() + " was skipped because it is not a maven repositories");
          }
        }
      }
    }
View Full Code Here

    @Inject
    private AptSigningConfiguration signingConfiguration;

    public boolean accepts( Event<?> evt )
    {
    Repository repository;
    if( evt instanceof RepositoryItemEventStore
      || evt instanceof RepositoryItemEventDelete
      || evt instanceof RepositoryEventLocalStatusChanged )
    {
      repository = ((RepositoryEvent)evt).getRepository();
    }
    else if(evt instanceof RepositoryRegistryEventAdd)
    {
      repository = ((RepositoryRegistryEventAdd)evt).getRepository();
    }
    else
    {
      // Not interested in this event type
      return false;
    }

    // Check that the repository is compatible
        if( !( maven2ContentClass.isCompatible( repository.getRepositoryContentClass() )
                && ( repository.getRepositoryKind().isFacetAvailable( HostedRepository.class )
                || repository.getRepositoryKind().isFacetAvailable( ProxyRepository.class ) || repository.getRepositoryKind().isFacetAvailable(
                GroupRepository.class ) ) ) )
        {
          // Not compatible with this repository
          return false;
        }
View Full Code Here

        return true;
    }

    public void inspect( Event<?> evt )
    {
        Repository repository = null;

        if ( evt instanceof RepositoryRegistryEventAdd )
        {
            repository = ((RepositoryRegistryEventAdd)evt).getRepository();
        }
View Full Code Here

  @Override
  protected ResourceStore getResourceStore()
      throws NoSuchRepositoryException, IOException
  {
    Repository repo1 = getRepositoryRegistry().getRepository("repo1");

    repo1.setWritePolicy(RepositoryWritePolicy.ALLOW_WRITE);

    getApplicationConfiguration().saveConfiguration();

    return repo1;
  }
View Full Code Here

  protected void testProxyLastRequestedAttribute(ShadowRepository shadowRepository, String shadowPath,
                                                 String masterPath)
      throws Exception
  {
    Repository masterRepository = shadowRepository.getMasterRepository();

    ResourceStoreRequest shadowRequest = new ResourceStoreRequest(shadowPath);
    ResourceStoreRequest masterRequest = new ResourceStoreRequest(masterPath);

    // simulate "user request" by adding IP address to requests
    shadowRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");
    masterRequest.getRequestContext().put(AccessManager.REQUEST_REMOTE_ADDRESS, "127.0.0.1");

    StorageItem shadowItem = shadowRepository.retrieveItem(shadowRequest);
    assertTrue("Shadow MUST return a link", StorageLinkItem.class.isAssignableFrom(shadowItem.getClass()));
    StorageItem masterItem = masterRepository.retrieveItem(masterRequest);
    assertTrue("Master MUST NOT return a link", !StorageLinkItem.class.isAssignableFrom(masterItem.getClass()));

    // produce a lastRequest timestamp to now less 10 days
    long lastRequest = System.currentTimeMillis() - 10 * A_DAY;

    // now set the lastRequest stamp programatically to both items to this "old" timestamp
    shadowRepository.getAttributesHandler().touchItemLastRequested(lastRequest, shadowItem);
    masterRepository.getAttributesHandler().touchItemLastRequested(lastRequest, masterItem);

    // now request the object, the lastRequested timestamp should be updated
    shadowItem = shadowRepository.retrieveItem(shadowRequest);
    assertTrue("Shadow MUST return a link", StorageLinkItem.class.isAssignableFrom(shadowItem.getClass()));

    // verify that shadow item lastRequested is updated, but master is still untouched
    // the attribute load will give us items without UIDs!
    Attributes shadowItem1 =
        shadowRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            shadowRepository.createUid(shadowPath));
    Assert.assertTrue("Shadow must have updated lastRequested field!",
        shadowItem1.getLastRequested() > lastRequest);

    // verify that shadow item lastRequested is updated, but master is still untouched
    // the attribute load will give us items without UIDs!
    Attributes masterItem1 =
        masterRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            masterRepository.createUid(masterPath));
    Assert.assertTrue("Master must have untouched lastRequested field!",
        masterItem1.getLastRequested() == lastRequest);

    // now dereference the link
    masterItem = getRootRouter().dereferenceLink((StorageLinkItem) shadowItem);
    assertTrue("Dereferenced item MUST NOT return a link", !StorageLinkItem.class.isAssignableFrom(masterItem
        .getClass()));

    // remember the lastRequests
    long shadowLastRequested = shadowItem.getLastRequested();
    long masterLastRequested = masterItem.getLastRequested();

    // verify that lastRequested is maintained (is updated to now)
    Assert.assertTrue("Shadow lastRequested have to be updated", shadowLastRequested > lastRequest);
    Assert.assertTrue("Master lastRequested have to be updated", masterLastRequested > lastRequest);

    // verify that master item, requested during resolution has lastRequested greater or equal then shadow link
    Assert.assertTrue("Master have to be updated at least at same time or later then shadow",
        masterLastRequested >= shadowLastRequested);

    // check the shadow attributes programatically
    Attributes shadowItemAttrs =
        shadowRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            shadowRepository.createUid(shadowPath));
    Assert.assertEquals("The attributes differ", shadowLastRequested, shadowItemAttrs.getLastRequested());

    // check the master attributes programatically
    Attributes masterItemAttrs =
        masterRepository.getAttributesHandler().getAttributeStorage().getAttributes(
            masterRepository.createUid(masterPath));
    Assert.assertEquals("The attributes differ", masterLastRequested, masterItemAttrs.getLastRequested());
  }
View Full Code Here

      if (log.isDebugEnabled()) {
        log.debug("Deleting attributes on UID=" + uid.toString());
      }

      try {
        final Repository repository = uid.getRepository();

        final ResourceStoreRequest request =
            new ResourceStoreRequest(getAttributePath(repository, uid.getPath()));

        repository.getLocalStorage().deleteItem(repository, request);

        return true;
      }
      catch (ItemNotFoundException e) {
        // ignore it
View Full Code Here

        final ByteArrayOutputStream bos = new ByteArrayOutputStream();

        marshaller.marshal(attributes, bos);

        final Repository repository = uid.getRepository();

        final DefaultStorageFileItem attributeItem =
            new DefaultStorageFileItem(repository, new ResourceStoreRequest(getAttributePath(repository,
                uid.getPath())), true, true, new ByteArrayContentLocator(bos.toByteArray(), "text/xml"));

        repository.getLocalStorage().storeItem(repository, attributeItem);
      }
      catch (UnsupportedStorageOperationException ex) {
        // TODO: what here? Is local storage unsuitable for storing attributes?
        log.error("Got UnsupportedStorageOperationException during store of UID=" + uid.toString(), ex);
      }
View Full Code Here

    Attributes result = null;

    boolean corrupt = false;

    try {
      final Repository repository = uid.getRepository();

      AbstractStorageItem attributeItemCandidate =
          repository.getLocalStorage().retrieveItem(repository,
              new ResourceStoreRequest(getAttributePath(repository, uid.getPath())));

      if (attributeItemCandidate instanceof StorageFileItem) {
        StorageFileItem attributeItem = (StorageFileItem) attributeItemCandidate;
View Full Code Here

  }

  @Subscribe
  @AllowConcurrentEvents
  public void inspect(final RepositoryRegistryEventRemove removedRepositoryEvent) {
    final Repository removedRepository = removedRepositoryEvent.getRepository();
    final PathCache pathCache = cacheManager.getPathCache(removedRepository.getId());
    if (log.isDebugEnabled()) {
      log.debug(
          "Purging NFC PathCache of repository {}",
          RepositoryStringUtils.getHumanizedNameString(removedRepository));
    }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.proxy.repository.Repository

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.