Search in sources :

Example 96 with CheckForNull

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));
    }
}
Also used : PermissionTemplateDto(org.sonar.db.permission.template.PermissionTemplateDto) DefaultTemplatesResolverImpl(org.sonar.server.permission.ws.template.DefaultTemplatesResolverImpl) ArrayList(java.util.ArrayList) DefaultTemplates(org.sonar.db.organization.DefaultTemplates) CheckForNull(javax.annotation.CheckForNull)

Example 97 with CheckForNull

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;
}
Also used : RuleParamType(org.sonar.api.server.rule.RuleParamType) CheckForNull(javax.annotation.CheckForNull)

Example 98 with CheckForNull

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);
}
Also used : MissingResourceException(java.util.MissingResourceException) ResourceBundle(java.util.ResourceBundle) CheckForNull(javax.annotation.CheckForNull)

Example 99 with CheckForNull

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;
}
Also used : File(java.io.File) CheckForNull(javax.annotation.CheckForNull)

Example 100 with CheckForNull

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;
    }
}
Also used : Path(java.nio.file.Path) CheckForNull(javax.annotation.CheckForNull)

Aggregations

CheckForNull (javax.annotation.CheckForNull)149 IOException (java.io.IOException)18 Tree (org.apache.jackrabbit.oak.api.Tree)16 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)12 ArrayList (java.util.ArrayList)9 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)9 Stopwatch (com.google.common.base.Stopwatch)8 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)8 Date (java.util.Date)7 SnapshotDto (org.sonar.db.component.SnapshotDto)7 Period (org.sonar.server.computation.task.projectanalysis.period.Period)7 File (java.io.File)6 SQLException (java.sql.SQLException)6 DocumentStoreException (org.apache.jackrabbit.oak.plugins.document.DocumentStoreException)6 ExecutionException (java.util.concurrent.ExecutionException)5 ValidationModel (org.apache.sling.validation.model.ValidationModel)5 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)4 Root (org.apache.jackrabbit.oak.api.Root)4 Utils.resolveCommitRevision (org.apache.jackrabbit.oak.plugins.document.util.Utils.resolveCommitRevision)4 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)4