org.sonatype.nexus.repository.config.Configuration Java Examples
The following examples show how to use
org.sonatype.nexus.repository.config.Configuration.
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: RoutingRuleCacheTest.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Test public void invalidateRepoCacheOnDelete() throws Exception { mockRule("rule-a"); Repository repository = createRepository("repo-a", "rule-a"); // prime the cache assertNotNull(routingRuleCache.getRoutingRule(repository)); // Clear the cache routingRuleCache.handle(new RepositoryDeletedEvent(repository)); // update the assigned rule RoutingRule rule = mockRule("rule-b"); Configuration configuration = repository.getConfiguration(); when(configuration.getRoutingRuleId()).thenReturn(new DetachedEntityId("rule-b")); assertThat(routingRuleCache.getRoutingRule(repository), is(rule)); }
Example #2
Source File: RepositoryImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override @Transitions(from = NEW, to = INITIALISED) public void init(final Configuration configuration) throws Exception { this.configuration = checkNotNull(configuration); this.name = configuration.getRepositoryName(); MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { try { log.debug("Initializing facet: {}", facet); facet.init(); } catch (Throwable t) { log.error("Failed to initialize facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to initialize facets"); }
Example #3
Source File: RepositoryManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
/** * Construct a new repository from configuration. */ private Repository newRepository(final Configuration configuration) throws Exception { String recipeName = configuration.getRecipeName(); Recipe recipe = recipe(recipeName); log.debug("Using recipe: [{}] {}", recipeName, recipe); Repository repository = factory.create(recipe.getType(), recipe.getFormat()); // attach mandatory facets repository.attach(configFacet.get()); // apply recipe to repository recipe.apply(repository); // verify required facets repository.facet(ViewFacet.class); // ensure configuration sanity, once all facets are attached repository.validate(configuration); // initialize repository repository.init(configuration); return repository; }
Example #4
Source File: ProxyFacetSupport.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override protected void doConfigure(final Configuration configuration) throws Exception { config = facet(ConfigurationFacet.class).readSection(configuration, CONFIG_KEY, Config.class); cacheControllerHolder = new CacheControllerHolder( new CacheController(Time.minutes(config.contentMaxAge).toSecondsI(), null), new CacheController(Time.minutes(config.metadataMaxAge).toSecondsI(), null) ); // normalize URL path to contain trailing slash if (!config.remoteUrl.getPath().endsWith("/")) { config.remoteUrl = config.remoteUrl.resolve(config.remoteUrl.getPath() + "/"); } log.debug("Config: {}", config); }
Example #5
Source File: CleanupPolicyEventHandler.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
private void remove(final Configuration configuration, final CleanupPolicy cleanupPolicy) { try { removeFromConfigurationIfHasCleanupPolicy(configuration, cleanupPolicy); repositoryManager.update(configuration); log.info("Removed Cleanup Policy {} from Repository {}", cleanupPolicy.getName(), configuration.getRepositoryName()); } catch (Exception e) { // this should not occur log.error("Unable to remove Cleanup Policy {} from Repository {}", cleanupPolicy.getName(), configuration.getRepositoryName(), e); throw new RuntimeException(e); } }
Example #6
Source File: NegativeCacheFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Override protected void doUpdate(final Configuration configuration) throws Exception { Config previous = config; super.doUpdate(configuration); // re-create cache if enabled or cache settings changed if (config.enabled) { if (!previous.enabled || !config.timeToLive.equals(previous.timeToLive)) { maybeDestroyCache(); maybeCreateCache(); } } else { // else destroy cache if disabled maybeDestroyCache(); } }
Example #7
Source File: GroupRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public Configuration convert(final T request) { Configuration configuration = super.convert(request); configuration.attributes("storage").set("blobStoreName", request.getStorage().getBlobStoreName()); configuration.attributes("storage") .set("strictContentTypeValidation", request.getStorage().getStrictContentTypeValidation()); configuration.attributes("group").set("memberNames", request.getGroup().getMemberNames()); return configuration; }
Example #8
Source File: DatastoreOrphanedBlobFinderTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void setupRepository(final Repository repository) { Configuration repositoryConfiguration = mock(Configuration.class); when(repositoryConfiguration.getAttributes()).thenReturn( of("storage", of("blobStoreName", BLOB_STORE_NAME)) ); when(repository.getConfiguration()).thenReturn(repositoryConfiguration); }
Example #9
Source File: ContentFacetSupport.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doConfigure(final Configuration configuration) throws Exception { config = facet(ConfigurationFacet.class).readSection(configuration, STORAGE, Config.class); log.debug("Config: {}", config); stores = new ContentFacetStores( dependencies.blobStoreManager, config.blobStoreName, formatStoreManager, config.dataStoreName); }
Example #10
Source File: SearchFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doInit(Configuration configuration) throws Exception { String format = getRepository().getFormat().getValue(); searchDocumentProducer = lookupSearchDocumentProducer(format); repositoryFields = ImmutableMap.of(REPOSITORY_NAME, getRepository().getName(), FORMAT, format); super.doInit(configuration); }
Example #11
Source File: StorageFacetImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Before public void setUp() throws Exception { Config config = new Config(); config.blobStoreName = BLOB_STORE_NAME; when(blobStore.getBlobStoreConfiguration()).thenReturn(blobStoreConfiguration); when(blobStoreConfiguration.getName()).thenReturn(BLOB_STORE_NAME); when(blobStoreConfiguration.getType()).thenReturn(FileBlobStore.TYPE); when(repository.facet(ConfigurationFacet.class)).thenReturn(configurationFacet); when(repository.getType()).thenReturn(new HostedType()); when(configurationFacet .readSection(any(Configuration.class), eq(STORAGE), eq(StorageFacetImpl.Config.class))) .thenReturn(config); when(nodeAccess.getId()).thenReturn(NODE_ID); when(blob.getId()).thenReturn(blobId); when(blob.getMetrics()).thenReturn(blobMetrics); when(blobId.asUniqueString()).thenReturn(BLOB_ID); underTest = new StorageFacetImpl( nodeAccess, blobStoreManager, () -> databaseInstance, bucketEntityAdapter, componentEntityAdapter, assetEntityAdapter, clientInfoProvider, contentValidatorSelector, mimeRulesSourceSelector, storageFacetManager, componentFactory, violationFactory ); underTest.attach(repository); }
Example #12
Source File: AptApiRepositoryAdapterTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private static Configuration config(final String repositoryName) { Configuration configuration = mock(Configuration.class); when(configuration.isOnline()).thenReturn(true); when(configuration.getRepositoryName()).thenReturn(repositoryName); when(configuration.attributes(not(eq("apt")))).thenReturn(new NestedAttributesMap("dummy", newHashMap())); return configuration; }
Example #13
Source File: OrientOrphanedBlobFinderTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void throwExceptionWhenBlobStoreNameBlank() { Configuration config = repository.getConfiguration(); when(config.getAttributes()).thenReturn(of("storage", of("blobStoreName", ""))); underTest.detect(repository, orphanedBlobHandler); }
Example #14
Source File: DatastoreBrowseNodeStoreImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void mockRepository( final Repository repository, final String name, final String formatName, final int repositoryIndex) { when(repositoryManager.get(name)).thenReturn(repository); when(repository.optionalFacet(BrowseNodeFacet.class)).thenReturn(Optional.empty()); Format format = mock(Format.class); when(format.getValue()).thenReturn(formatName); when(repository.getName()).thenReturn(name); when(repository.getFormat()).thenReturn(format); Configuration config = mock(Configuration.class, withSettings().extraInterfaces(Entity.class)); when(repository.getConfiguration()).thenReturn(config); EntityMetadata metadata = mock(EntityMetadata.class); when(((Entity) config).getEntityMetadata()).thenReturn(metadata); when(metadata.getId()).thenReturn(new DetachedEntityId(name)); ContentRepositoryData data = generatedRepositories().get(repositoryIndex); when(contentRepositoryStores.readContentRepository(new DetachedEntityId(name))).thenReturn(Optional.of(data)); }
Example #15
Source File: CleanupServiceImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test public void ignoreRepositoryWhenAttributesNull() throws Exception { when(repository1.getConfiguration()).thenReturn(mock(Configuration.class)); underTest.cleanup(cancelledCheck); verify(cleanupMethod).run(repository2, ImmutableList.of(component3), cancelledCheck); }
Example #16
Source File: HostedRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
public Configuration convert(final T request) { Configuration configuration = super.convert(request); configuration.attributes(STORAGE).set(BLOB_STORE_NAME, request.getStorage().getBlobStoreName()); configuration.attributes(STORAGE) .set(STRICT_CONTENT_TYPE_VALIDATION, request.getStorage().getStrictContentTypeValidation()); configuration.attributes(STORAGE).set(WRITE_POLICY, request.getStorage().getWritePolicy()); if (request.getCleanup() != null) { configuration.attributes(CLEANUP_ATTRIBUTES_KEY) .set(CLEANUP_NAME_KEY, Sets.newHashSet(request.getCleanup().getPolicyNames())); } return configuration; }
Example #17
Source File: CleanupConfigurationValidator.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private List<CleanupPolicy> getCleanupPolicy(final Configuration configuration) { List<CleanupPolicy> cleanupPolicies = new ArrayList<>(); Map<String, Map<String, Object>> attributes = configuration.getAttributes(); if (attributes != null && attributes.containsKey(CLEANUP_ATTRIBUTES_KEY)) { addToCleanupPoliciesFromCleanupAttributes(cleanupPolicies, attributes.get(CLEANUP_ATTRIBUTES_KEY)); } return cleanupPolicies; }
Example #18
Source File: RoutingRuleHelperImplTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void configureRepositoryMock(final Repository repo, final String repositoryRuleId) { Configuration configuration = mock(Configuration.class); when(repo.getConfiguration()).thenReturn(configuration); if (repositoryRuleId != null) { when(configuration.getRoutingRuleId()).thenReturn(new DetachedEntityId(repositoryRuleId)); } }
Example #19
Source File: OrientOrphanedBlobFinderTest.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void throwExceptionWhenRepositoryConfigurationAttributesNull() { Configuration config = repository.getConfiguration(); when(config.getAttributes()).thenReturn(null); underTest.detect(repository, orphanedBlobHandler); }
Example #20
Source File: RepositoryManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public boolean isDataStoreUsed(final String dataStoreName) { return stream(browse().spliterator(), false) .map(Repository::getConfiguration) .map(Configuration::getAttributes) .map(a -> a.get(STORAGE)) .map(s -> s.get(DATA_STORE_NAME)) .anyMatch(dataStoreName::equals); }
Example #21
Source File: AptSigningFacet.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doValidate(final Configuration configuration) throws Exception { facet(ConfigurationFacet.class).validateSection( configuration, CONFIG_KEY, Config.class, Default.class, getRepository().getType().getValidationGroup()); }
Example #22
Source File: AptFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doValidate(final Configuration configuration) throws Exception { facet(ConfigurationFacet.class).validateSection( configuration, CONFIG_KEY, Config.class, Default.class, getRepository().getType().getValidationGroup()); }
Example #23
Source File: AptProxyRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Configuration convert(final AptProxyRepositoryApiRequest request) { Configuration configuration = super.convert(request); configuration.attributes("apt").set("distribution", request.getApt().getDistribution()); configuration.attributes("apt").set("flat", request.getApt().getFlat()); return configuration; }
Example #24
Source File: ProxyRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private void convertHttpClient(final T request, final Configuration configuration) { HttpClientAttributes httpClient = request.getHttpClient(); if (nonNull(httpClient)) { NestedAttributesMap httpClientConfiguration = configuration.attributes("httpclient"); httpClientConfiguration.set("blocked", httpClient.getBlocked()); httpClientConfiguration.set("autoBlock", httpClient.getAutoBlock()); HttpClientConnectionAttributes connection = httpClient.getConnection(); NestedAttributesMap connectionConfiguration = httpClientConfiguration.child("connection"); convertConnection(connection, connectionConfiguration); convertAuthentication(httpClient, httpClientConfiguration); } }
Example #25
Source File: ConfigurationFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public <T> T readSection(final Configuration configuration, final String section, final Class<T> type) { checkNotNull(configuration); checkNotNull(section); log.trace("Reading section: {}", section); AttributesMap attributes = configuration.attributes(section); return convert(attributes.backing(), type); }
Example #26
Source File: RepositoryImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public void validate(final Configuration configuration) throws Exception { checkNotNull(configuration); Set<ConstraintViolation<?>> violations = new HashSet<>(); MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { log.debug("Validating facet: {}", facet); try { facet.validate(configuration); } catch (ConstraintViolationException e) { log.debug("Facet validation produced violations: {}", facet, e); violations.addAll(e.getConstraintViolations()); } catch (Throwable t) { log.error("Failed to validate facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to validate facets"); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } }
Example #27
Source File: MavenArchetypeCatalogFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void doInit(final Configuration configuration) throws Exception { super.doInit(configuration); mavenContentFacet = facet(MavenContentFacet.class); this.archetypeCatalogMavenPath = mavenContentFacet.getMavenPathParser() .parsePath(ARCHETYPE_CATALOG_PATH); }
Example #28
Source File: RepositoryManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private boolean repositoryHasCleanupPolicy(final Repository repository, final String cleanupPolicyName) { return ofNullable(repository.getConfiguration()) .map(Configuration::getAttributes) .map(attributes -> attributes.get(CLEANUP_ATTRIBUTES_KEY)) .filter(Objects::nonNull) .map(cleanupPolicyMap -> (Set) cleanupPolicyMap.get(CLEANUP_NAME_KEY)) .filter(Objects::nonNull) .filter(cleanupPolicies -> cleanupPolicies.contains(cleanupPolicyName)) .isPresent(); }
Example #29
Source File: MavenFacetImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@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()); }
Example #30
Source File: MavenProxyRepositoryApiRequestToConfigurationConverter.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public Configuration convert(final MavenProxyRepositoryApiRequest request) { Configuration configuration = super.convert(request); configuration.attributes("maven").set("versionPolicy", request.getMaven().getVersionPolicy()); configuration.attributes("maven").set("layoutPolicy", request.getMaven().getLayoutPolicy()); return configuration; }