• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StorageFacet类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.sonatype.nexus.repository.storage.StorageFacet的典型用法代码示例。如果您正苦于以下问题:Java StorageFacet类的具体用法?Java StorageFacet怎么用?Java StorageFacet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

StorageFacet类属于org.sonatype.nexus.repository.storage包,在下文中一共展示了StorageFacet类的40个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createSnapshot

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Transactional(retryOn = { ONeedRetryException.class })
@Override
public void createSnapshot(String id, SnapshotComponentSelector selector) throws IOException {
  StorageTx tx = UnitOfWork.currentTx();
  StorageFacet storageFacet = facet(StorageFacet.class);
  Bucket bucket = tx.findBucket(getRepository());
  Component component = tx.createComponent(bucket, getRepository().getFormat()).name(id);
  tx.saveComponent(component);
  for (SnapshotItem item : collectSnapshotItems(selector)) {
    String assetName = createAssetPath(id, item.specifier.path);
    Asset asset = tx.createAsset(bucket, component).name(assetName);
    try (final TempBlob streamSupplier = storageFacet.createTempBlob(item.content.openInputStream(), FacetHelper.hashAlgorithms)) {
      AssetBlob blob = tx.createBlob(item.specifier.path, streamSupplier, FacetHelper.hashAlgorithms, null,
          FacetHelper.determineContentType(item), true);
      tx.attachBlob(asset, blob);
    }
    finally {
      item.content.close();
    }
    tx.saveAsset(asset);
  }
}
 

开发者ID:sonatype-nexus-community,
项目名称:nexus-repository-apt,
代码行数:23,
代码来源:AptSnapshotFacetSupport.java

示例2: setup

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() {
  underTest = new ComponentComponent();
  underTest.setRepositoryManager(repositoryManager);
  underTest.setContentPermissionChecker(contentPermissionChecker);
  underTest.setVariableResolverAdapterManager(variableResolverAdapterManager);
  underTest.setMaintenanceService(maintenanceService);
  underTest.setBrowseService(browseService);
  underTest.setJexlExpressionValidator(jexlExpressionValidator);
  underTest.setCselExpressionValidator(cselExpressionValidator);

  when(repositoryManager.get("testRepositoryName")).thenReturn(repository);
  when(repository.getName()).thenReturn("testRepositoryName");
  when(repository.getFormat()).thenReturn(new Format("testFormat") { });
  when(repository.facet(ComponentMaintenance.class)).thenReturn(componentMaintenance);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(variableResolverAdapterManager.get("testFormat")).thenReturn(variableResolverAdapter);
  when(storageFacet.txSupplier()).thenReturn(Suppliers.ofInstance(storageTx));
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:20,
代码来源:ComponentComponentTest.java

示例3: handle

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public Collection<String> handle(final Repository repository, final ComponentUpload upload) throws IOException {
  RawContentFacet facet = repository.facet(RawContentFacet.class);

  String basePath = normalize(upload.getFields().get(DIRECTORY));

  List<String> paths = new ArrayList<>();
  TransactionalStoreBlob.operation.withDb(repository.facet(StorageFacet.class).txSupplier())
      .throwing(IOException.class).run(() -> {
        for (AssetUpload asset : upload.getAssetUploads()) {
          String path = basePath + asset.getFields().get(FILENAME);

          ensurePermitted(repository.getName(), RawFormat.NAME, path, emptyMap());
          facet.put(path, asset.getPayload());
          paths.add(path);
        }
      });
  return paths;
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:20,
代码来源:RawUploadHandler.java

示例4: publishIndex

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void publishIndex() throws IOException {
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    List<Repository> leafMembers = facet(GroupFacet.class).leafMembers();
    ArrayList<String> withoutIndex = new ArrayList<>();
    for (Iterator<Repository> ri = leafMembers.iterator(); ri.hasNext(); ) {
      Repository repository = ri.next();
      if (repository.facet(MavenIndexFacet.class).lastPublished() == null) {
        withoutIndex.add(repository.getName());
        ri.remove();
      }
    }
    if (!withoutIndex.isEmpty()) {
      log.info("Following members of group {} have no index, will not participate in merged index: {}",
          getRepository().getName(),
          withoutIndex
      );
    }
    MavenIndexPublisher.publishMergedIndex(getRepository(), leafMembers);
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:26,
代码来源:IndexGroupFacet.java

示例5: on

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Subscribe
@AllowConcurrentEvents
public void on(final AssetEvent event) {
  // only make DB changes on the originating node, as orient will also replicate those for us
  if (event.isLocal() && member(event.getRepositoryName()) && event.getComponentId() == null) {
    final String path = event.getAsset().name();
    final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
    // group deletes path + path.hashes, but it should do only on content change in member
    if (!mavenPath.isHash()) {
      UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
      try {
        evictCache(mavenPath);
      }
      catch (IOException e) {
        log.warn("Could not evict merged content from {} cache at {}", getRepository().getName(),
            mavenPath.getPath(), e);
      }
      finally {
        UnitOfWork.end();
      }
    }
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:24,
代码来源:MavenGroupFacet.java

示例6: publishIndex

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void publishIndex() throws IOException {
  log.debug("Fetching maven index properties from remote");
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    if (!prefetchIndexFiles(getRepository())) {
      if (Boolean.TRUE.equals(config.cacheFallback)) {
        log.debug("No remote index found... generating partial index from caches");
        publishHostedIndex(getRepository());
      }
      else {
        log.debug("No remote index found... nothing to publish");
      }
    }
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:20,
代码来源:MavenProxyIndexFacet.java

示例7: deleteComponent

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void deleteComponent(final EntityId componentId) {
  String[] coordinates = Transactional.operation
      .withDb(getRepository().facet(StorageFacet.class).txSupplier())
      .call(() -> {
        final StorageTx tx = UnitOfWork.currentTx();
        Component component = tx.findComponentInBucket(componentId, tx.findBucket(getRepository()));
        if (component != null) {
          return new String[]{
              component.formatAttributes().get(P_GROUP_ID, String.class),
              component.formatAttributes().get(P_ARTIFACT_ID, String.class),
              component.formatAttributes().get(P_BASE_VERSION, String.class)
          };
        }
        return null;
      });
  super.deleteComponent(componentId);
  if (coordinates != null) {
    getRepository().facet(MavenHostedFacet.class)
        .deleteMetadata(coordinates[0], coordinates[1], coordinates[2]);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:23,
代码来源:MavenHostedComponentMaintenanceFacet.java

示例8: rebuild

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
/**
 * Rebuilds/updates Maven metadata.
 *
 * @param repository  The repository whose metadata needs rebuild (Maven2 format, Hosted type only).
 * @param update      if {@code true}, updates existing metadata, otherwise overwrites them with newly generated
 *                    ones.
 * @param rebuildChecksums whether or not checksums should be checked and corrected if found                     
 *                           missing or incorrect                    
 * @param groupId     scope the work to given groupId.
 * @param artifactId  scope the work to given artifactId (groupId must be given).
 * @param baseVersion scope the work to given baseVersion (groupId and artifactId must ge given).
 */
public void rebuild(final Repository repository,
                    final boolean update,
                    final boolean rebuildChecksums,
                    @Nullable final String groupId,
                    @Nullable final String artifactId,
                    @Nullable final String baseVersion)
{
  checkNotNull(repository);
  final StorageTx tx = repository.facet(StorageFacet.class).txSupplier().get();
  UnitOfWork.beginBatch(tx);
  try {
    new Worker(repository, update, rebuildChecksums, groupId, artifactId, baseVersion, bufferSize, timeoutSeconds)
        .rebuildMetadata();
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:31,
代码来源:MetadataRebuilder.java

示例9: setup

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() {
  when(versionPolicyValidator.validArtifactPath(any(), any())).thenReturn(true);
  when(contentPermissionChecker.isPermitted(eq(REPO_NAME), eq(Maven2Format.NAME), eq(BreadActions.EDIT), any()))
      .thenReturn(true);

  when(mavenPomGenerator.generatePom(any(), any(), any(), any())).thenReturn("<project/>");

  Maven2MavenPathParser pathParser = new Maven2MavenPathParser();
  underTest = new MavenUploadHandler(pathParser, new MavenVariableResolverAdapter(pathParser),
      contentPermissionChecker, versionPolicyValidator, mavenPomGenerator);

  when(repository.getName()).thenReturn(REPO_NAME);
  when(repository.getFormat()).thenReturn(new Maven2Format());
  when(repository.facet(MavenFacet.class)).thenReturn(mavenFacet);

  StorageFacet storageFacet = mock(StorageFacet.class);
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.createTempBlob(any(Payload.class), any())).thenReturn(tempBlob);

  when(mavenFacet.getVersionPolicy()).thenReturn(VersionPolicy.RELEASE);
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:24,
代码来源:MavenUploadHandlerTest.java

示例10: restore

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void restore(final Properties properties,
                    final Blob blob,
                    final String blobStoreName,
                    final boolean isDryRun)
{
  RestoreBlobData blobData = new RestoreBlobData(blob, properties, blobStoreName, repositoryManager);
  Optional<StorageFacet> storageFacet = blobData.getRepository().optionalFacet(StorageFacet.class);
  T restoreData = createRestoreData(blobData);

  if (storageFacet.isPresent() && canAttemptRestore(restoreData)) {
    doRestore(storageFacet.get(), blobData, restoreData, isDryRun);
  }
  else {
    log.debug("Skipping asset, blob store: {}, repository: {}, blob name: {}, blob id: {}",
        blobStoreName, blobData.getRepository().getName(), blobData.getBlobName(), blob.getId());
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:19,
代码来源:BaseRestoreBlobStrategy.java

示例11: setup

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() throws Exception {
  defaultIntegrityCheckStrategy = spy(new TestIntegrityCheckFacet());

  assets = new HashSet<>();

  BlobStoreConfiguration blobStoreConfiguration = mock(BlobStoreConfiguration.class);
  when(blobStoreConfiguration.getName()).thenReturn("reponame");
  when(blobStore.getBlobStoreConfiguration()).thenReturn(blobStoreConfiguration);

  StorageFacet storageFacet = mock(StorageFacet.class);
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);

  when(storageTx.findBucket(repository)).thenReturn(bucket);
  when(storageTx.browseAssets(bucket)).thenReturn(assets);
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:18,
代码来源:DefaultIntegrityCheckStrategyTest.java

示例12: doUpdateSearchIndex

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private void doUpdateSearchIndex(final Repository repository, final IndexRequest indexRequest) {
  repository.optionalFacet(SearchFacet.class).ifPresent(searchFacet -> {
    UnitOfWork.begin(repository.facet(StorageFacet.class).txSupplier());
    try {
      if (bulkProcessing) {
        indexRequest.bulkApply(searchFacet);
      }
      else {
        indexRequest.apply(searchFacet);
      }
    }
    finally {
      UnitOfWork.end();
    }
  });
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:17,
代码来源:IndexRequestProcessor.java

示例13: deleteComponent

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void deleteComponent(final Repository repository, final Component component) {
  checkNotNull(repository);
  checkNotNull(component);

  String repositoryFormat = repository.getFormat().toString();
  VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(repositoryFormat);

  StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get();

  try {
    storageTx.begin();
    for (Asset asset : storageTx.browseAssets(component)) {
      if (!canDeleteAssetInRepository(repository, repositoryFormat, variableResolverAdapter, asset)) {
        throw new AuthorizationException();
      }
    }
  }
  finally {
    storageTx.close();
  }

  getComponentMaintenanceFacet(repository).deleteComponent(component.getEntityMetadata().getId());
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:25,
代码来源:MaintenanceServiceImpl.java

示例14: getAssetById

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private Asset getAssetById(final Repository repository, final EntityId assetId) {
  Optional<GroupFacet> optionalGroupFacet = repository.optionalFacet(GroupFacet.class);
  List<Repository> members = optionalGroupFacet.isPresent() ? optionalGroupFacet.get().allMembers()
      : Collections.singletonList(repository);

  return Transactional.operation.withDb(repository.facet(StorageFacet.class).txSupplier()).call(() -> {
    StorageTx tx = UnitOfWork.currentTx();
    Asset candidate = tx.findAsset(assetId);
    if (candidate != null) {
      final String asssetBucketRepositoryName = bucketStore.getById(candidate.bucketId()).getRepositoryName();
      if (members.stream().anyMatch(repo -> repo.getName().equals(asssetBucketRepositoryName))) {
        return candidate;
      }
    }

    return null;
  });
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:19,
代码来源:RepositoryBrowseResource.java

示例15: browseComponents

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public BrowseResult<Component> browseComponents(final Repository repository,
                                                final QueryOptions queryOptions)
{
  checkNotNull(repository);
  final List<Repository> repositories = getRepositories(repository);
  try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) {
    storageTx.begin();
    List<String> bucketIds = getBucketIds(storageTx, repositories);
    List<Component> components = Collections.emptyList();
    // ensure there are components before incurring contentAuth overhead
    if (hasComponents(storageTx, repository, bucketIds, queryOptions)) {
      components = getComponents(storageTx.browse(
          browseComponentsSqlBuilder.buildBrowseSql(bucketIds, queryOptions),
          browseComponentsSqlBuilder.buildSqlParams(repository.getName(), queryOptions)));
    }
    return new BrowseResult<>(queryOptions, components);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:20,
代码来源:BrowseServiceImpl.java

示例16: browseComponentAssets

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public BrowseResult<Asset> browseComponentAssets(final Repository repository, final String componentId)
{
  checkNotNull(repository);
  checkNotNull(componentId);
  try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) {
    storageTx.begin();
    Component component = storageTx.findComponent(new DetachedEntityId(componentId));
    if (component == null) {
      return new BrowseResult<>(0, Collections.emptyList());
    }
    VariableResolverAdapter variableResolverAdapter = variableResolverAdapterManager.get(component.format());
    List<Asset> assets = StreamSupport.stream(storageTx.browseAssets(component).spliterator(), false)
        .filter(
            (Asset asset) -> contentPermissionChecker.isPermitted(
                repository.getName(),
                asset.format(),
                BreadActions.BROWSE,
                variableResolverAdapter.fromAsset(asset))
        ).collect(Collectors.toList());
    return new BrowseResult<>(assets.size(), assets);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:24,
代码来源:BrowseServiceImpl.java

示例17: browseAssets

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public BrowseResult<Asset> browseAssets(final Repository repository,
                                        final QueryOptions queryOptions)
{
  checkNotNull(repository);
  final List<Repository> repositories = getRepositories(repository);
  try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) {
    storageTx.begin();
    List<String> bucketIds = getBucketIds(storageTx, repositories);
    List<Asset> assets = Collections.emptyList();
    // ensure there are assets before incurring contentAuth overhead
    if (hasAssets(storageTx, repository, bucketIds, queryOptions)) {
      assets = getAssets(storageTx.browse(
          browseAssetsSqlBuilder.buildBrowseSql(bucketIds, queryOptions),
          browseAssetsSqlBuilder.buildSqlParams(repository.getName(), queryOptions)));
    }
    return new BrowseResult<>(queryOptions, assets);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:20,
代码来源:BrowseServiceImpl.java

示例18: getById

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private <T extends MetadataNode<?>> T getById(final ORID orid,
                                              final Repository repository,
                                              final String tableName,
                                              final MetadataNodeEntityAdapter<T> adapter)
{
  String sql = format("SELECT * FROM %s WHERE contentAuth(@this, :browsedRepository) == true AND @RID == :rid",
      tableName);

  Map<String, Object> params = ImmutableMap
      .of("browsedRepository", repository.getName(), "rid", orid.toString());

  try (StorageTx storageTx = repository.facet(StorageFacet.class).txSupplier().get()) {
    storageTx.begin();
    return stream(storageTx.browse(sql, params).spliterator(), false)
        .map(adapter::readEntity).findFirst().orElse(null);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:18,
代码来源:BrowseServiceImpl.java

示例19: getAssetById

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public Asset getAssetById(final EntityId assetId, final Repository repository) {
  List<Repository> members = allMembers(repository);

  return Transactional.operation.withDb(repository.facet(StorageFacet.class).txSupplier()).call(() -> {
    StorageTx tx = UnitOfWork.currentTx();
    Asset candidate = tx.findAsset(assetId);
    if (candidate != null) {
      final String assetBucketRepositoryName = bucketStore.getById(candidate.bucketId()).getRepositoryName();
      if (members.stream().anyMatch(repo -> repo.getName().equals(assetBucketRepositoryName))) {
        return candidate;
      }
    }
    return null;
  });
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:17,
代码来源:BrowseServiceImpl.java

示例20: purgeUnused

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
@Guarded(by = STARTED)
public void purgeUnused(final int numberOfDays) {
  checkArgument(numberOfDays > 0, "Number of days must be greater then zero");
  log.info("Purging unused components from repository {}", getRepository().getName());

  Date olderThan = DateTime.now().minusDays(numberOfDays).withTimeAtStartOfDay().toDate();

  UnitOfWork.beginBatch(facet(StorageFacet.class).txSupplier());
  try {
    deleteUnusedComponents(olderThan);
    deleteUnusedAssets(olderThan);
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:18,
代码来源:PurgeUnusedFacetImpl.java

示例21: setup

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() {
  results = asList(assetOne, assetTwo);

  when(queryOptions.getContentAuth()).thenReturn(true);

  when(assetOneORID.toString()).thenReturn("assetOne");
  when(componentOneORID.toString()).thenReturn("componentOne");

  when(mavenReleases.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(mavenReleases.getName()).thenReturn("releases");

  when(storageFacet.txSupplier()).thenReturn(txSupplier);
  when(txSupplier.get()).thenReturn(storageTx);

  browseAssetsSqlBuilder = new BrowseAssetsSqlBuilder(assetEntityAdapter);
  browseComponentsSqlBuilder = new BrowseComponentsSqlBuilder(componentEntityAdapter);

  underTest = spy(new BrowseServiceImpl(new GroupType(), componentEntityAdapter, variableResolverAdapterManager,
      contentPermissionChecker, assetDownloadCountStore, assetEntityAdapter, browseAssetsSqlBuilder, browseComponentsSqlBuilder, bucketStore));
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:22,
代码来源:BrowseServiceImplTest.java

示例22: testGetAssetById_withEntityId_groupRepository

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Test
public void testGetAssetById_withEntityId_groupRepository() {
  EntityId assetId = new DetachedEntityId(assetOneORID.toString());
  EntityId bucketId = mock(EntityId.class);
  Bucket bucket = mock(Bucket.class);

  when(storageTx.findAsset(assetId)).thenReturn(assetOne);
  when(assetOne.bucketId()).thenReturn(bucketId);
  when(bucketStore.getById(bucketId)).thenReturn(bucket);
  when(bucket.getRepositoryName()).thenReturn("releases");

  Repository groupRepository = mock(Repository.class);
  when(groupRepository.getType()).thenReturn(new GroupType());
  when(groupRepository.getName()).thenReturn("group-repository");
  when(groupRepository.facet(StorageFacet.class)).thenReturn(storageFacet);
  GroupFacet groupFacet = mock(GroupFacet.class);
  when(groupFacet.allMembers()).thenReturn(Arrays.asList(groupRepository, mavenReleases));
  when(groupRepository.facet(GroupFacet.class)).thenReturn(groupFacet);

  when(assetEntityAdapter.readEntity(assetOneDoc)).thenReturn(assetOne);

  assertThat(underTest.getAssetById(assetId, groupRepository), is(assetOne));
  verify(groupFacet).allMembers();
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:25,
代码来源:BrowseServiceImplTest.java

示例23: setup

点赞 3

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() throws Exception {
  Bucket bucket = mockBucket();
  when(tx.findBucket(repository)).thenReturn(bucket);
  when(tx.browse(any(), any())).thenReturn(componentDocsIterable);
  when(tx.findAssets(any(), any(), any(), any())).thenReturn(assetIterable);
  when(componentDocsIterable.iterator()).thenReturn(componentDocsIterator);
  when(assetIterable.iterator()).thenReturn(assetIterator);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(() -> tx);

  uncaught = newArrayList();

  underTest = new PurgeUnusedFacetImpl(componentEntityAdapter);
  underTest.attach(repository);
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:17,
代码来源:PurgeUnusedFacetImplTest.java

示例24: upload

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void upload(final String path, final Payload payload) throws IOException {
  checkNotNull(path);
  checkNotNull(payload);
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(payload, RFacetUtils.HASH_ALGORITHMS)) {
    doPutArchive(path, tempBlob, payload);
  }
}
 

开发者ID:sonatype-nexus-community,
项目名称:nexus-repository-r,
代码行数:10,
代码来源:RHostedFacetImpl.java

示例25: putPackage

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private Content putPackage(final String assetPath,
                           final Content content,
                           final String project,
                           final String version,
                           final String group) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(content.openInputStream(), HASH_ALGORITHMS)) {
    return doPutPackage(assetPath, project, version, tempBlob, content, group);
  }
}
 

开发者ID:sonatype-nexus-community,
项目名称:nexus-repository-conan,
代码行数:11,
代码来源:ConanProxyFacet.java

示例26: setupRepositoryMock

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private void setupRepositoryMock() {
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.createTempBlob(any(InputStream.class), any(Iterable.class))).thenAnswer(args -> {
    InputStream inputStream = (InputStream) args.getArguments()[0];
    byte[] bytes = IOUtils.toByteArray(inputStream);
    when(processedBlob.get()).thenReturn(new ByteArrayInputStream(bytes));
    return processedBlob;
  });
}
 

开发者ID:sonatype-nexus-community,
项目名称:nexus-repository-conan,
代码行数:10,
代码来源:ConanAbsoluteUrlRemoverTest.java

示例27: put

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
@TransactionalStoreBlob
public Content put(String path, Payload content) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (final TempBlob tembBlob = storageFacet.createTempBlob(content, FacetHelper.hashAlgorithms)) {
    StorageTx tx = UnitOfWork.currentTx();
    Bucket bucket = tx.findBucket(getRepository());
    Asset asset = tx.findAssetWithProperty(P_NAME, path, bucket);
    if (asset == null) {
      asset = tx.createAsset(bucket, getRepository().getFormat()).name(path);
    }

    AttributesMap contentAttributes = null;
    if (content instanceof Content) {
      contentAttributes = ((Content) content).getAttributes();
    }
    Content.applyToAsset(asset, Content.maintainLastModified(asset, contentAttributes));
    AssetBlob blob = tx.setBlob(
        asset,
        path,
        tembBlob,
        FacetHelper.hashAlgorithms,
        null,
        content.getContentType(),
        false);
    tx.saveAsset(asset);
    return FacetHelper.toContent(asset, blob.getBlob());
  }
}
 

开发者ID:sonatype-nexus-community,
项目名称:nexus-repository-apt,
代码行数:30,
代码来源:AptFacetImpl.java

示例28: put

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public Content put(final String path, final Payload content) throws IOException {
  StorageFacet storageFacet = facet(StorageFacet.class);
  try (TempBlob tempBlob = storageFacet.createTempBlob(content, hashAlgorithms)) {
    return doPutContent(path, tempBlob, content);
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:8,
代码来源:RawContentFacetImpl.java

示例29: setup

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() {
  when(contentPermissionChecker.isPermitted(eq(REPO_NAME), eq(RawFormat.NAME), eq(BreadActions.EDIT), any()))
      .thenReturn(true);

  underTest = new RawUploadHandler(contentPermissionChecker, new SimpleVariableResolverAdapter());
  when(repository.getFormat()).thenReturn(new RawFormat());
  when(repository.facet(RawContentFacet.class)).thenReturn(rawFacet);
  when(repository.getName()).thenReturn(REPO_NAME);

  StorageFacet storageFacet = mock(StorageFacet.class);
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:15,
代码来源:RawUploadHandlerTest.java

示例30: doUpload

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private List<String> doUpload(final Repository repository, final ComponentUpload componentUpload) throws IOException {
  MavenFacet facet = repository.facet(MavenFacet.class);
  StorageFacet storageFacet = repository.facet(StorageFacet.class);

  return TransactionalStoreBlob.operation.withDb(storageFacet.txSupplier()).throwing(IOException.class).call(() -> {
    Optional<AssetUpload> pomAsset = findPomAsset(componentUpload);
    if (pomAsset.isPresent()) {
      PartPayload payload = pomAsset.get().getPayload();

      try (TempBlob pom = storageFacet.createTempBlob(payload, HashType.ALGORITHMS)) {
        pomAsset.get().setPayload(new TempBlobPartPayload(payload, pom));
        return createAssets(repository.getName(), facet, createBasePathFromPom(pom),
            componentUpload.getAssetUploads());
      }
    }
    else {
      Map<String, String> componentFields = componentUpload.getFields();
      String basePath = createBasePath(componentFields.get(GROUP_ID), componentFields.get(ARTIFACT_ID),
          componentFields.get(VERSION));

      List<String> assetPaths = createAssets(repository.getName(), facet, basePath,
          componentUpload.getAssetUploads());

      if (Boolean.valueOf(componentUpload.getField(GENERATE_POM))) {
        String pomPath = generatePom(facet, basePath, componentFields.get(GROUP_ID),
            componentFields.get(ARTIFACT_ID), componentFields.get(VERSION), componentFields.get(PACKAGING));

        assetPaths.add(pomPath);
      }

      return assetPaths;
    }
  });
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:35,
代码来源:MavenUploadHandler.java

示例31: purgeSnapshotsFromRepository

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
/**
 * Purges snapshots from the given repository, returning a set of the affected groups for metadata rebuilding.
 */
private Set<String> purgeSnapshotsFromRepository(final int numberOfDays) {
  LocalDate olderThan = LocalDate.now().minusDays(numberOfDays);
  UnitOfWork.beginBatch(facet(StorageFacet.class).txSupplier());
  try {
    return deleteUnusedSnapshotComponents(olderThan);
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:14,
代码来源:PurgeUnusedSnapshotsFacetImpl.java

示例32: lastPublished

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Nullable
public DateTime lastPublished() throws IOException {
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    return MavenIndexPublisher.lastPublished(getRepository());
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:11,
代码来源:MavenIndexFacetSupport.java

示例33: unpublishIndex

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void unpublishIndex() throws IOException {
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    MavenIndexPublisher.unpublishIndexFiles(getRepository());
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:11,
代码来源:MavenIndexFacetSupport.java

示例34: doInit

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
protected void doInit(final Configuration configuration) throws Exception {
  super.doInit(configuration);
  mavenPathParser = checkNotNull(mavenPathParsers.get(getRepository().getFormat().getValue()));
  storageFacet = getRepository().facet(StorageFacet.class);
  storageFacet.registerWritePolicySelector(new MavenWritePolicySelector());
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:8,
代码来源:MavenFacetImpl.java

示例35: publishIndex

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Override
public void publishIndex() throws IOException {
  UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
  try {
    MavenIndexPublisher.publishHostedIndex(getRepository());
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:11,
代码来源:MavenHostedIndexFacet.java

示例36: on

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Subscribe
@AllowConcurrentEvents
public void on(final EntityBatchEvent batchEvent) {
  // are we affected by this event?
  boolean deleteCatalog = false;
  for (final EntityEvent event : batchEvent.getEvents()) {
    if (event instanceof ComponentEvent) {
      final ComponentEvent componentEvent = (ComponentEvent) event;
      if (getRepository().getName().equals(componentEvent.getRepositoryName()) &&
          MAVEN_ARCHETYPE_PACKAGING.equals(
              componentEvent.getComponent().formatAttributes().get(Attributes.P_PACKAGING, String.class))) {
        deleteCatalog = true;
        break;
      }
    }
  }

  if (deleteCatalog) {
    UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
    try {
      TransactionalDeleteBlob.operation.throwing(IOException.class).call(() ->
          MavenFacetUtils.deleteWithHashes(mavenFacet, archetypeCatalogMavenPath)
      );
    }
    catch (IOException e) {
      log.warn("Could not delete {}", archetypeCatalogMavenPath, e);
    }
    finally {
      UnitOfWork.end();
    }
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:33,
代码来源:MavenHostedFacetImpl.java

示例37: setup

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() {
  bucket = new Bucket();
  bucket.setEntityMetadata(mockBucketEntityMetadata());

  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(repository.facet(MavenFacet.class)).thenReturn(mavenFacet);
  when(storageTx.findBucket(repository)).thenReturn(bucket);
  when(mavenFacet.getMavenPathParser()).thenReturn(mavenPathParser);
  when(mavenPathParser.parsePath(anyString())).thenReturn(mock(MavenPath.class));
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:13,
代码来源:MetadataRebuilderTest.java

示例38: getAssets

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private Iterable<Asset> getAssets(final Repository repository) {
  return Transactional.operation
      .withDb(repository.facet(StorageFacet.class).txSupplier())
      .call(() -> {
        final StorageTx tx = UnitOfWork.currentTx();
        return tx.browseAssets(tx.findBucket(repository));
      });

}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:10,
代码来源:DefaultIntegrityCheckStrategy.java

示例39: doRestore

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
private void doRestore(StorageFacet storageFacet, RestoreBlobData blobData, T restoreData, boolean isDryRun) {
  String logPrefix = isDryRun ? dryRunPrefix.get() : "";
  String path = getAssetPath(restoreData);
  String blobStoreName = blobData.getBlobStoreName();
  String repoName = blobData.getRepository().getName();
  String blobName = blobData.getBlobName();
  Blob blob = blobData.getBlob();

  UnitOfWork.begin(storageFacet.txSupplier());
  try {
    if (assetExists(restoreData)) {
      log.debug(
          "Skipping as asset already exists, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
          blobStoreName, repoName, path, blobName, blob.getId());
      return;
    }

    if (!isDryRun) {
      List<HashAlgorithm> hashTypes = getHashAlgorithms();

      AssetBlob assetBlob = new AssetBlob(nodeAccess, blobStoreManager.get(blobStoreName), blobStore -> blob,
          blobData.getProperty(HEADER_PREFIX + CONTENT_TYPE_HEADER),
          hash(hashTypes, blob.getInputStream()), true);

      createAssetFromBlob(assetBlob, restoreData);
    }

    log.info("{}Restored asset, blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
        logPrefix, blobStoreName, repoName, path, blobName, blob.getId());
  }
  catch (IOException e) {
    log.error("Error while restoring asset: blob store: {}, repository: {}, path: {}, blob name: {}, blob id: {}",
        blobStoreName, repoName, path, blobName, blob.getId(), e);
  }
  finally {
    UnitOfWork.end();
  }
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:39,
代码来源:BaseRestoreBlobStrategy.java

示例40: setup

点赞 2

import org.sonatype.nexus.repository.storage.StorageFacet; //导入依赖的package包/类
@Before
public void setup() throws IOException {
  underTest = new MavenRestoreBlobStrategy(maven2MavenPathParser, nodeAccess, repositoryManager, blobStoreManager,
      dryRunPrefix);
  properties.setProperty("@BlobStore.blob-name", "org/codehaus/plexus/plexus/3.1/plexus-3.1.pom");
  properties.setProperty("@Bucket.repo-name", "test-repo");
  properties.setProperty("size", "1000");
  properties.setProperty("@BlobStore.content-type", "application/xml");
  properties.setProperty("sha1", "b64de86ceaa4f0e4d8ccc44a26c562c6fb7fb230");

  when(repositoryManager.get("test-repo")).thenReturn(repository);
  when(repository.optionalFacet(StorageFacet.class)).thenReturn(Optional.of(storageFacet));
  when(repository.optionalFacet(MavenFacet.class)).thenReturn(Optional.of(mavenFacet));
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);

  when(storageTx.findBucket(repository)).thenReturn(bucket);

  when(blob.getId()).thenReturn(new BlobId("test"));
  when(blob.getInputStream()).thenReturn(new ByteArrayInputStream(blobBytes));

  when(maven2MavenPathParser.parsePath("org/codehaus/plexus/plexus/3.1/plexus-3.1.pom"))
      .thenReturn(mavenPath);

  when(mavenPath.getCoordinates()).thenReturn(coordinates);

  when(nodeAccess.getId()).thenReturn("node");

  when(repository.facet(MavenFacet.class)).thenReturn(mavenFacet);

  when(blobStoreManager.get("test")).thenReturn(mock(BlobStore.class));
}
 

开发者ID:sonatype,
项目名称:nexus-public,
代码行数:32,
代码来源:MavenRestoreBlobStrategyTest.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)