use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class PermissionTemplateService method findTemplate.
/**
* Return the permission template for the given component. If no template key pattern match then consider default
* template for the component qualifier.
*/
@CheckForNull
private PermissionTemplateDto findTemplate(DbSession dbSession, String organizationUuid, ComponentDto component) {
List<PermissionTemplateDto> allPermissionTemplates = dbClient.permissionTemplateDao().selectAll(dbSession, organizationUuid, null);
List<PermissionTemplateDto> matchingTemplates = new ArrayList<>();
for (PermissionTemplateDto permissionTemplateDto : allPermissionTemplates) {
String keyPattern = permissionTemplateDto.getKeyPattern();
if (StringUtils.isNotBlank(keyPattern) && component.getKey().matches(keyPattern)) {
matchingTemplates.add(permissionTemplateDto);
}
}
checkAtMostOneMatchForComponentKey(component.getKey(), matchingTemplates);
if (matchingTemplates.size() == 1) {
return matchingTemplates.get(0);
}
DefaultTemplates defaultTemplates = dbClient.organizationDao().getDefaultTemplates(dbSession, organizationUuid).orElseThrow(() -> new IllegalStateException(format("No Default templates defined for organization with uuid '%s'", organizationUuid)));
String qualifier = component.qualifier();
DefaultTemplatesResolverImpl.ResolvedDefaultTemplates resolvedDefaultTemplates = defaultTemplatesResolver.resolve(defaultTemplates);
if (Qualifiers.PROJECT.equals(qualifier)) {
return dbClient.permissionTemplateDao().selectByUuid(dbSession, resolvedDefaultTemplates.getProject());
} else if (Qualifiers.VIEW.equals(qualifier)) {
String viewDefaultTemplateUuid = resolvedDefaultTemplates.getView().orElseThrow(() -> new IllegalStateException("Attempt to create a view when Governance plugin is not installed"));
return dbClient.permissionTemplateDao().selectByUuid(dbSession, viewDefaultTemplateUuid);
} else {
throw new IllegalArgumentException(format("Qualifier '%s' is not supported", qualifier));
}
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class RuleActivator method validateParam.
@CheckForNull
private String validateParam(RuleParamDto ruleParam, @Nullable String value) {
if (value != null) {
RuleParamType ruleParamType = RuleParamType.parse(ruleParam.getType());
if (ruleParamType.multiple()) {
List<String> values = newArrayList(Splitter.on(",").split(value));
typeValidations.validate(values, ruleParamType.type(), ruleParamType.values());
} else {
typeValidations.validate(value, ruleParamType.type(), ruleParamType.values());
}
}
return value;
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class DefaultI18n method message.
@Override
@CheckForNull
public String message(Locale locale, String key, @Nullable String defaultValue, Object... parameters) {
String bundleKey = propertyToBundles.get(key);
String value = null;
if (bundleKey != null) {
try {
ResourceBundle resourceBundle = ResourceBundle.getBundle(bundleKey, locale, classloader, control);
value = resourceBundle.getString(key);
} catch (MissingResourceException e1) {
// ignore
}
}
if (value == null) {
value = defaultValue;
}
return formatMessage(value, parameters);
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class FileCache method get.
/**
* Look for a file in the cache by its filename and md5 checksum. If the file is not
* present then return null.
*/
@CheckForNull
public File get(String filename, String hash) {
File cachedFile = new File(new File(dir, hash), filename);
if (cachedFile.exists()) {
return cachedFile;
}
logger.debug(String.format("No file found in the cache with name %s and hash %s", filename, hash));
return null;
}
use of javax.annotation.CheckForNull in project sonarqube by SonarSource.
the class PathResolver method relativePath.
/**
* Similar to {@link Path#relativize(Path)} except that:
* <ul>
* <li>null is returned if file is not a child of dir
* <li>the resulting path is converted to use Unix separators
* </ul>
* @since 6.0
*/
@CheckForNull
public String relativePath(Path dir, Path file) {
Path baseDir = dir.normalize();
Path path = file.normalize();
if (!path.startsWith(baseDir)) {
return null;
}
try {
Path relativized = baseDir.relativize(path);
return FilenameUtils.separatorsToUnix(relativized.toString());
} catch (IllegalArgumentException e) {
return null;
}
}
Aggregations