Java Code Examples for org.sonatype.nexus.repository.Repository#getName()

The following examples show how to use org.sonatype.nexus.repository.Repository#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageFacetManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void enqueueDeletion(final Repository repository, final BlobStore blobStore, final Bucket bucket)
{
  checkNotNull(repository);
  checkNotNull(blobStore);
  checkNotNull(bucket);

  // The bucket associated with repository needs a new "repository name" created for it in order to avoid clashes.
  // Consider what happens if the bucket is still being deleted and someone tries to reuse that repository name.
  String generatedRepositoryName = repository.getName() + '$' + UUID.randomUUID();
  bucket.setRepositoryName(generatedRepositoryName);
  bucket.attributes().set(P_PENDING_DELETION, true);

  updateBucket(bucket);
}
 
Example 2
Source File: SimpleApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String format = repository.getFormat().toString();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case GroupType.NAME:
      return new SimpleApiGroupRepository(name, format, url, online, getStorageAttributes(repository),
          getGroupAttributes(repository));
    case HostedType.NAME:
      return new SimpleApiHostedRepository(name, format, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository));
    case ProxyType.NAME:
      return new SimpleApiProxyRepository(name, format, url, online, getStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository),
          getRoutingRuleName(repository));
    default:
      return null;
  }
}
 
Example 3
Source File: RepositoryAdminSecurityContributor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Remove security configuration for given repository.
 */
public void remove(final Repository repository) {
  checkNotNull(repository);
  final String format = repository.getFormat().getValue();
  final String name = repository.getName();
  final List<String> privilegeIds = Arrays.asList(
      id(format, name, ALL),
      id(format, name, BROWSE),
      id(format, name, READ),
      id(format, name, EDIT),
      id(format, name, DELETE));
  apply((model, configurationManager) -> {
    // no per-repo repository-admin ADD action
    privilegeIds.forEach(model::removePrivilege);
    privilegeIds.forEach(configurationManager::cleanRemovedPrivilege);
  });
}
 
Example 4
Source File: RepositoryFormatSecurityContributor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Remove security configuration for given repository.
 */
public void remove(final Repository repository) {
  checkNotNull(repository);
  final String format = repository.getFormat().getValue();
  final String name = repository.getName();
  final List<String> privilegeIds = asList(
      id(format, name, ALL),
      id(format, name, BROWSE),
      id(format, name, READ),
      id(format, name, EDIT),
      id(format, name, ADD),
      id(format, name, DELETE));

  apply((model, configurationManager) -> {
    // remove repository-view <format> <name> privileges
    privilegeIds.forEach(model::removePrivilege);
    privilegeIds.forEach(configurationManager::cleanRemovedPrivilege);
  });
}
 
Example 5
Source File: RepositoryFormatSecurityContributor.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add security configuration for given repository.
 */
public void add(final Repository repository) {
  checkNotNull(repository);
  final String format = repository.getFormat().getValue();
  final String name = repository.getName();

  apply((model, configurationManager) -> {
    // add repository-view <format> <name> privileges
    maybeAddPrivilege(model, privilege(format, name, ALL));
    maybeAddPrivilege(model, privilege(format, name, BROWSE));
    maybeAddPrivilege(model, privilege(format, name, READ));
    maybeAddPrivilege(model, privilege(format, name, EDIT));
    maybeAddPrivilege(model, privilege(format, name, ADD));
    maybeAddPrivilege(model, privilege(format, name, DELETE));
  });
}
 
Example 6
Source File: AptApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new AptHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptHostedRepositoriesAttributes(repository),
          createAptSigningRepositoriesAttributes(repository));
    case ProxyType.NAME:
      return new AptProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptProxyRepositoriesAttributes(repository),
          getProxyAttributes(repository), getNegativeCacheAttributes(repository),
          getHttpClientAttributes(repository), getRoutingRuleName(repository));
  }
  return null;
}
 
Example 7
Source File: MavenApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new MavenHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createMavenAttributes(repository));
    case ProxyType.NAME:
      return new MavenProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository), getRoutingRuleName(repository),
          createMavenAttributes(repository));
    default:
      return super.adapt(repository);
  }
}
 
Example 8
Source File: OrientBrowseNodeManager.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates the browse nodes used to access a collection of assets and their components (if they have one).
 *
 * @param repository storing the assets
 * @param assets     which need to be accessible from the browse nodes
 * @see BrowseNodeGenerator#computeAssetPath(Asset, Component) for details on the default behavior used to compute the asset path
 * @see BrowseNodeGenerator#computeComponentPath(Asset, Component) for details on the default behavior used to compute the component path
 */
public void createFromAssets(final Repository repository, final Iterable<Asset> assets) {
  checkNotNull(repository);
  checkNotNull(assets);

  String repositoryName = repository.getName();
  BrowseNodeGenerator generator = pathGenerators.getOrDefault(repository.getFormat().getValue(), defaultGenerator);
  assets.forEach(asset -> createBrowseNodes(repositoryName, repository.getFormat().getValue(), generator, asset));
}
 
Example 9
Source File: MavenIndexPublisher.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Publishes MI index into {@code target}, sourced from {@code repositories} repositories.
 */
public static void publishMergedIndex(final Repository target,
                                      final List<Repository> repositories,
                                      final DuplicateDetectionStrategy<Record> duplicateDetectionStrategy)
    throws IOException
{
  checkNotNull(target);
  checkNotNull(repositories);
  Closer closer = Closer.create();
  try (Maven2WritableResourceHandler resourceHandler = new Maven2WritableResourceHandler(target);
       IndexWriter indexWriter = new IndexWriter(resourceHandler, target.getName(), false)) {
    indexWriter.writeChunk(
        transform(
            decorate(
                filter(concat(getGroupRecords(repositories, closer)), duplicateDetectionStrategy),
                target.getName()
            ),
            RECORD_COMPACTOR::apply
        ).iterator()
    );
  }
  catch (Throwable t) {
    throw closer.rethrow(t);
  }
  finally {
    closer.close();
  }
}
 
Example 10
Source File: RepositoryAdminSecurityContributor.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add security configuration for given repository.
 */
public void add(final Repository repository) {
  checkNotNull(repository);
  final String format = repository.getFormat().getValue();
  final String name = repository.getName();
  apply((model, configurationManager) -> {
    // no per-repo repository-admin ADD action
    maybeAddPrivilege(model, privilege(format, name, ALL));
    maybeAddPrivilege(model, privilege(format, name, BROWSE));
    maybeAddPrivilege(model, privilege(format, name, READ));
    maybeAddPrivilege(model, privilege(format, name, EDIT));
    maybeAddPrivilege(model, privilege(format, name, DELETE));
  });
}
 
Example 11
Source File: OrientSearchTestHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void verifyComponentExists(
    final WebTarget nexusSearchWebTarget,
    final Repository repository,
    final String name,
    final String version,
    final boolean exists) throws Exception
{
  String repositoryName = repository.getName();
  List<Map<String, Object>> items = searchForComponent(nexusSearchWebTarget, repositoryName, name, version);
  assertThat(items.size(), is(exists ? 1 : 0));
}
 
Example 12
Source File: ElasticSearchCleanupComponentBrowse.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private String getTimerName(final CleanupPolicy policy, final Repository repository) {
  return getClass().getName().replaceAll("\\$.*", "") + '.' + policy.getName() + "." + repository.getName() +
      ".timer";
}
 
Example 13
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Appends a content authentication filter in SQL for the current user.
 */
private void appendContentAuthFilter(final StringBuilder filterBuilder,
                                     final Repository repository,
                                     final List<SelectorConfiguration> selectors,
                                     final Map<String, Object> filterParameters)
{
  String repositoryName = repository.getName();
  String format = repository.getFormat().getValue();

  if (selectors.size() > 1) {
    filterBuilder.append('(');
  }

  SelectorSqlBuilder sqlBuilder = new SelectorSqlBuilder()
      .propertyAlias("path", P_PATH)
      .propertyAlias("format", P_FORMAT)
      .parameterPrefix(":")
      .propertyPrefix(P_ASSET_ID + ".attributes." + format + ".");

  int cselCount = 0;

  for (SelectorConfiguration selector : selectors) {
    if (CselSelector.TYPE.equals(selector.getType())) {
      try {
        sqlBuilder.parameterNamePrefix("s" + cselCount + "p");

        selectorManager.toSql(selector, sqlBuilder);

        if (cselCount > 0) {
          filterBuilder.append(" or ");
        }

        filterBuilder.append('(').append(sqlBuilder.getQueryString()).append(')');
        filterParameters.putAll(sqlBuilder.getQueryParameters());

        cselCount++;
      }
      catch (SelectorEvaluationException e) {
        log.warn("Problem evaluating selector {} as SQL", selector.getName(), e);
      }
      finally {
        sqlBuilder.clearQueryString();
      }
    }
  }

  if (selectors.size() > cselCount) {
    if (cselCount > 0) {
      filterBuilder.append(" or ");
    }

    // call 'contentAuth' function if we need to evaluate any non-CSEL selectors (such as JEXL based selectors)
    filterBuilder.append(
        String.format("contentAuth(@this.%s, @this.%s, :%s, true) = true", P_PATH, P_FORMAT, AUTHZ_REPOSITORY_NAME));

    filterParameters.put(AUTHZ_REPOSITORY_NAME, repositoryName);
  }

  if (selectors.size() > 1) {
    filterBuilder.append(')');
  }
}
 
Example 14
Source File: ComponentAssetTestHelper.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
AssetNotFoundException(final Repository repository, final String path) {
  super("Missing asset: " + path + " from repository: " + repository.getName());
}
 
Example 15
Source File: RemoveSnapshotsFacetImpl.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void removeSnapshots(RemoveSnapshotsConfig config)
{
  Repository repository = getRepository();
  String repositoryName = repository.getName();
  log.info("Beginning snapshot removal on repository '{}' with configuration: {}", repositoryName, config);
  UnitOfWork.beginBatch(facet(StorageFacet.class).txSupplier());
  Set<GAV> metadataUpdateRequired = new HashSet<>();
  try {
    if (groupType.equals(repository.getType())) {
      processGroup(repository.facet(MavenGroupFacet.class), config);
    }
    else {
      metadataUpdateRequired.addAll(processRepository(repository, config));
    }
  }
  finally {
    UnitOfWork.end();
  }

  //only update metadata for non-proxy repos
  if (!repository.optionalFacet(ProxyFacet.class).isPresent()) {
    log.info("Updating metadata on repository '{}'", repositoryName);
    ProgressLogIntervalHelper intervalLogger = new ProgressLogIntervalHelper(log, 60);

    int processed = 0;
    for (GAV gav : metadataUpdateRequired) {
      Optional<MavenHostedFacet> mavenHostedFacet = repository.optionalFacet(MavenHostedFacet.class);
      if (mavenHostedFacet.isPresent()) {
        try {
          mavenHostedFacet.get().deleteMetadata(gav.group, gav.name, gav.baseVersion);
          intervalLogger
              .info("Elapsed time: {}, updated metadata for {} GAVs", intervalLogger.getElapsed(), ++processed);
        }
        catch (Exception e) {
          log.warn("Unable to delete/rebuild {} {} {}", gav.group, gav.name, gav.baseVersion,
              log.isDebugEnabled() ? e : null);
        }
      }
    }

    intervalLogger.flush();
  }
  else {
    log.info("Skipping metadata updates on proxy repository '{}'", repositoryName);
  }

  log.info("Completed snapshot removal on repository '{}'", repositoryName);
}
 
Example 16
Source File: RepositoryContentSelectorPermission.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public RepositoryContentSelectorPermission(final SelectorConfiguration selector,
                                           final Repository repository,
                                           final List<String> actions)
{
  this(selector.getName(), repository.getFormat().getValue(), repository.getName(), actions);
}
 
Example 17
Source File: RepositoryAdminPermission.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @since 3.17
 */
public RepositoryAdminPermission(final Repository repository, final String... actions) {
  this(repository.getFormat().getValue(), repository.getName(), Arrays.asList(actions));
}
 
Example 18
Source File: RepositoryViewPermission.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
public RepositoryViewPermission(final Repository repository, final String... actions) {
  this(repository.getFormat().getValue(), repository.getName(), Arrays.asList(actions));
}