List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.andromda.cartridges.gui.GuiUtils.java
/** * Parses the validator name for a tagged value. * //from ww w.j av a 2 s . co m * @param validatorTaggedValue * @return validatorTaggedValue * @throws IllegalArgumentException when the input string does not match the required pattern */ public static String parseValidatorName(final String validatorTaggedValue) { if (validatorTaggedValue == null) { throw new IllegalArgumentException("Validator tagged value cannot be null"); } // isn't it an annotation ? if (StringUtils.startsWith(validatorTaggedValue, GuiUtils.ANNOTATION_VALIDATOR_PREFIX)) { return validatorTaggedValue; } // check if the input tagged value matches the required pattern if (!GuiUtils.VALIDATOR_TAGGEDVALUE_PATTERN.matcher(validatorTaggedValue).matches()) { throw new IllegalArgumentException("Illegal validator tagged value: " + validatorTaggedValue); } final int leftParen = validatorTaggedValue.indexOf('('); return (leftParen == -1) ? validatorTaggedValue : validatorTaggedValue.substring(0, leftParen); }
From source file:org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin.java
protected String calculateIndexRemoteUrl(RemoteRepository remoteRepository) { if (StringUtils.startsWith(remoteRepository.getRemoteIndexUrl(), "http")) { String baseUrl = remoteRepository.getRemoteIndexUrl(); return baseUrl.endsWith("/") ? StringUtils.substringBeforeLast(baseUrl, "/") : baseUrl; }// ww w. ja v a 2 s . c o m String baseUrl = StringUtils.endsWith(remoteRepository.getUrl(), "/") ? StringUtils.substringBeforeLast(remoteRepository.getUrl(), "/") : remoteRepository.getUrl(); baseUrl = StringUtils.isEmpty(remoteRepository.getRemoteIndexUrl()) ? baseUrl + "/.index" : baseUrl + "/" + remoteRepository.getRemoteIndexUrl(); return baseUrl; }
From source file:org.apache.archiva.admin.repository.runtime.DefaultRedbackRuntimeConfigurationAdmin.java
@Override public String getString(String key) { if (UserConfigurationKeys.USER_MANAGER_IMPL.equals(key)) { // possible false for others than archiva user manager return getRedbackRuntimeConfiguration().getUserManagerImpls().get(0); }/*from w w w . ja v a 2 s. com*/ if (StringUtils.startsWith(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY)) { RedbackRuntimeConfiguration redbackRuntimeConfiguration = getRedbackRuntimeConfiguration(); int index = redbackRuntimeConfiguration.getLdapGroupMappings().indexOf(new LdapGroupMapping( StringUtils.substringAfter(key, UserConfigurationKeys.LDAP_GROUPS_ROLE_START_KEY))); if (index > -1) { return StringUtils .join(redbackRuntimeConfiguration.getLdapGroupMappings().get(index).getRoleNames(), ','); } } RedbackRuntimeConfiguration conf = getRedbackRuntimeConfiguration(); if (conf.getConfigurationProperties().containsKey(key)) { return conf.getConfigurationProperties().get(key); } String value = userConfiguration.getString(key); if (value == null) { return null; } conf.getConfigurationProperties().put(key, value); try { updateRedbackRuntimeConfiguration(conf); } catch (RepositoryAdminException e) { log.error("fail to save RedbackRuntimeConfiguration: {}", e.getMessage(), e); throw new RuntimeException(e.getMessage(), e); } return value; }
From source file:org.apache.archiva.configuration.DefaultArchivaConfiguration.java
@SuppressWarnings("unchecked") private Configuration load() { // TODO: should this be the same as section? make sure unnamed sections still work (eg, sys properties) Registry subset = registry.getSubset(KEY); if (subset.getString("version") == null) { // a little autodetection of v1, even if version is omitted (this was previously allowed) if (subset.getSubset("repositoryScanning").isEmpty()) { // only for empty, or v < 1 subset = readDefaultConfiguration(); }//from w w w . j a va 2s .c o m } Configuration config = new ConfigurationRegistryReader().read(subset); config.getRepositoryGroups(); config.getRepositoryGroupsAsMap(); if (!config.getRepositories().isEmpty()) { for (V1RepositoryConfiguration r : config.getRepositories()) { r.setScanned(r.isIndexed()); if (StringUtils.startsWith(r.getUrl(), "file://")) { r.setLocation(r.getUrl().substring(7)); config.addManagedRepository(r); } else if (StringUtils.startsWith(r.getUrl(), "file:")) { r.setLocation(r.getUrl().substring(5)); config.addManagedRepository(r); } else if (StringUtils.isEmpty(r.getUrl())) { // in case of empty url we can consider it as a managed one // check if location is null //file://${appserver.base}/repositories/${id} if (StringUtils.isEmpty(r.getLocation())) { r.setLocation("file://${appserver.base}/repositories/" + r.getId()); } config.addManagedRepository(r); } else { RemoteRepositoryConfiguration repo = new RemoteRepositoryConfiguration(); repo.setId(r.getId()); repo.setLayout(r.getLayout()); repo.setName(r.getName()); repo.setUrl(r.getUrl()); config.addRemoteRepository(repo); } } // Prevent duplicate repositories from showing up. config.getRepositories().clear(); registry.removeSubset(KEY + ".repositories"); } if (!CollectionUtils.isEmpty(config.getRemoteRepositories())) { List<RemoteRepositoryConfiguration> remoteRepos = config.getRemoteRepositories(); for (RemoteRepositoryConfiguration repo : remoteRepos) { // [MRM-582] Remote Repositories with empty <username> and <password> fields shouldn't be created in configuration. if (StringUtils.isBlank(repo.getUsername())) { repo.setUsername(null); } if (StringUtils.isBlank(repo.getPassword())) { repo.setPassword(null); } } } if (!config.getProxyConnectors().isEmpty()) { // Fix Proxy Connector Settings. // Create a copy of the list to read from (to prevent concurrent modification exceptions) List<ProxyConnectorConfiguration> proxyConnectorList = new ArrayList<>(config.getProxyConnectors()); // Remove the old connector list. config.getProxyConnectors().clear(); for (ProxyConnectorConfiguration connector : proxyConnectorList) { // Fix policies boolean connectorValid = true; Map<String, String> policies = new HashMap<>(); // Make copy of policies policies.putAll(connector.getPolicies()); // Clear out policies connector.getPolicies().clear(); // Work thru policies. cleaning them up. for (Entry<String, String> entry : policies.entrySet()) { String policyId = entry.getKey(); String setting = entry.getValue(); // Upgrade old policy settings. if ("releases".equals(policyId) || "snapshots".equals(policyId)) { if ("ignored".equals(setting)) { setting = AbstractUpdatePolicy.ALWAYS; } else if ("disabled".equals(setting)) { setting = AbstractUpdatePolicy.NEVER; } } else if ("cache-failures".equals(policyId)) { if ("ignored".equals(setting)) { setting = CachedFailuresPolicy.NO; } else if ("cached".equals(setting)) { setting = CachedFailuresPolicy.YES; } } else if ("checksum".equals(policyId)) { if ("ignored".equals(setting)) { setting = ChecksumPolicy.IGNORE; } } // Validate existance of policy key. if (policyExists(policyId)) { Policy policy = findPolicy(policyId); // Does option exist? if (!policy.getOptions().contains(setting)) { setting = policy.getDefaultOption(); } connector.addPolicy(policyId, setting); } else { // Policy key doesn't exist. Don't add it to golden version. log.warn("Policy [{}] does not exist.", policyId); } } if (connectorValid) { config.addProxyConnector(connector); } } // Normalize the order fields in the proxy connectors. Map<String, java.util.List<ProxyConnectorConfiguration>> proxyConnectorMap = config .getProxyConnectorAsMap(); for (List<ProxyConnectorConfiguration> connectors : proxyConnectorMap.values()) { // Sort connectors by order field. Collections.sort(connectors, ProxyConnectorConfigurationOrderComparator.getInstance()); // Normalize the order field values. int order = 1; for (ProxyConnectorConfiguration connector : connectors) { connector.setOrder(order++); } } } return config; }
From source file:org.apache.archiva.consumers.functors.ConsumerWantsFilePredicate.java
private boolean wantsFile(RepositoryContentConsumer consumer, String relativePath) { // Test excludes first. List<String> excludes = consumer.getExcludes(); if (excludes != null) { for (String pattern : excludes) { if (SelectorUtils.matchPath(pattern, relativePath, isCaseSensitive)) { // Definately does NOT WANT FILE. return false; }//from www .jav a 2s.com } } if (managedRepository != null) { String indexDirectory = managedRepository.getIndexDirectory(); if (StringUtils.startsWith(relativePath, indexDirectory)) { logger.debug("ignore file {} part of the index directory {}", relativePath, indexDirectory); return false; } } // Now test includes. for (String pattern : consumer.getIncludes()) { if (SelectorUtils.matchPath(pattern, relativePath, isCaseSensitive)) { // Specifically WANTS FILE. return true; } } // Not included, and Not excluded? Default to EXCLUDE. return false; }
From source file:org.apache.archiva.indexer.maven.search.MavenRepositorySearch.java
private IndexingContext getIndexingContext(String id) { String repoId;/*from ww w . j av a2s .com*/ if (StringUtils.startsWith(id, "remote-")) { repoId = StringUtils.substringAfter(id, "remote-"); } else { repoId = id; } Repository repo = repositoryRegistry.getRepository(repoId); if (repo == null) { return null; } else { if (repo.getIndexingContext() != null) { try { return repo.getIndexingContext().getBaseContext(IndexingContext.class); } catch (UnsupportedBaseContextException e) { return null; } } else { return null; } } }
From source file:org.apache.archiva.indexer.maven.search.MavenRepositorySearch.java
/** * calculate baseUrl without the context and base Archiva Url * * @param artifactInfo/*from w w w . j a va 2 s.co m*/ * @return */ protected String getBaseUrl(ArtifactInfo artifactInfo, List<String> selectedRepos) throws RepositoryAdminException { StringBuilder sb = new StringBuilder(); if (StringUtils.startsWith(artifactInfo.getContext(), "remote-")) { // it's a remote index result we search a managed which proxying this remote and on which // current user has read karma String managedRepoId = getManagedRepoId( StringUtils.substringAfter(artifactInfo.getContext(), "remote-"), selectedRepos); if (managedRepoId != null) { sb.append('/').append(managedRepoId); artifactInfo.setContext(managedRepoId); } } else { sb.append('/').append(artifactInfo.getContext()); } sb.append('/').append(StringUtils.replaceChars(artifactInfo.getGroupId(), '.', '/')); sb.append('/').append(artifactInfo.getArtifactId()); sb.append('/').append(artifactInfo.getVersion()); sb.append('/').append(artifactInfo.getArtifactId()); sb.append('-').append(artifactInfo.getVersion()); if (StringUtils.isNotBlank(artifactInfo.getClassifier())) { sb.append('-').append(artifactInfo.getClassifier()); } // maven-plugin packaging is a jar if (StringUtils.equals("maven-plugin", artifactInfo.getPackaging())) { sb.append("jar"); } else { sb.append('.').append(artifactInfo.getPackaging()); } return sb.toString(); }
From source file:org.apache.archiva.indexer.search.MavenRepositorySearch.java
/** * calculate baseUrl without the context and base Archiva Url * * @param artifactInfo// w ww. jav a2 s . c om * @return */ protected String getBaseUrl(ArtifactInfo artifactInfo, List<String> selectedRepos) throws RepositoryAdminException { StringBuilder sb = new StringBuilder(); if (StringUtils.startsWith(artifactInfo.context, "remote-")) { // it's a remote index result we search a managed which proxying this remote and on which // current user has read karma String managedRepoId = getManagedRepoId(StringUtils.substringAfter(artifactInfo.context, "remote-"), selectedRepos); if (managedRepoId != null) { sb.append('/').append(managedRepoId); artifactInfo.context = managedRepoId; } } else { sb.append('/').append(artifactInfo.context); } sb.append('/').append(StringUtils.replaceChars(artifactInfo.groupId, '.', '/')); sb.append('/').append(artifactInfo.artifactId); sb.append('/').append(artifactInfo.version); sb.append('/').append(artifactInfo.artifactId); sb.append('-').append(artifactInfo.version); if (StringUtils.isNotBlank(artifactInfo.classifier)) { sb.append('-').append(artifactInfo.classifier); } // maven-plugin packaging is a jar if (StringUtils.equals("maven-plugin", artifactInfo.packaging)) { sb.append("jar"); } else { sb.append('.').append(artifactInfo.packaging); } return sb.toString(); }
From source file:org.apache.archiva.metadata.repository.cassandra.CassandraMetadataRepository.java
@Override public Collection<String> getNamespaces(final String repoId, final String namespaceId) throws MetadataResolutionException { QueryResult<OrderedRows<String, String, String>> result = HFactory // .createRangeSlicesQuery(keyspace, ss, ss, ss) // .setColumnFamily(cassandraArchivaManager.getNamespaceFamilyName()) // .setColumnNames(NAME.toString()) // .addEqualsExpression(REPOSITORY_NAME.toString(), repoId) // .execute();//from w ww .jav a 2 s. c om List<String> namespaces = new ArrayList<>(result.get().getCount()); for (Row<String, String, String> row : result.get()) { String currentNamespace = getStringValue(row.getColumnSlice(), NAME.toString()); if (StringUtils.startsWith(currentNamespace, namespaceId) // && (StringUtils.length(currentNamespace) > StringUtils.length(namespaceId))) { // store after namespaceId '.' but before next '.' // call org namespace org.apache.maven.shared -> stored apache String calledNamespace = StringUtils.endsWith(namespaceId, ".") ? namespaceId : namespaceId + "."; String storedNamespace = StringUtils.substringAfter(currentNamespace, calledNamespace); storedNamespace = StringUtils.substringBefore(storedNamespace, "."); namespaces.add(storedNamespace); } } return namespaces; }
From source file:org.apache.archiva.metadata.repository.cassandra.CassandraMetadataRepository.java
protected List<MailingList> getMailingLists(String projectVersionMetadataKey) { List<MailingList> mailingLists = new ArrayList<>(); QueryResult<OrderedRows<String, String, String>> result = HFactory .createRangeSlicesQuery(cassandraArchivaManager.getKeyspace(), ss, ss, ss) // .setColumnFamily(cassandraArchivaManager.getMailingListFamilyName()) // .setColumnNames(NAME.toString()) // .setRowCount(Integer.MAX_VALUE) // .addEqualsExpression("projectVersionMetadataModel.key", projectVersionMetadataKey) // .execute();//from w ww. j a v a 2 s. co m for (Row<String, String, String> row : result.get()) { ColumnFamilyResult<String, String> columnFamilyResult = this.mailingListTemplate .queryColumns(row.getKey()); MailingList mailingList = new MailingList(); mailingList.setName(columnFamilyResult.getString(NAME.toString())); mailingList.setMainArchiveUrl(columnFamilyResult.getString("mainArchiveUrl")); mailingList.setPostAddress(columnFamilyResult.getString("postAddress")); mailingList.setSubscribeAddress(columnFamilyResult.getString("subscribeAddress")); mailingList.setUnsubscribeAddress(columnFamilyResult.getString("unsubscribeAddress")); List<String> otherArchives = new ArrayList<>(); for (String columnName : columnFamilyResult.getColumnNames()) { if (StringUtils.startsWith(columnName, "otherArchive.")) { otherArchives.add(columnFamilyResult.getString(columnName)); } } mailingList.setOtherArchives(otherArchives); mailingLists.add(mailingList); } return mailingLists; }