private PropertyDefinitions addComponentFromAnnotationProperty(
     Object component, String defaultCategory) {
   Properties annotations = AnnotationUtils.getAnnotation(component, Properties.class);
   if (annotations != null) {
     for (Property property : annotations.value()) {
       addProperty(property, defaultCategory);
     }
   }
   Property annotation = AnnotationUtils.getAnnotation(component, Property.class);
   if (annotation != null) {
     addProperty(annotation, defaultCategory);
   }
   return this;
 }
Beispiel #2
0
 public static boolean isInstantiationStrategy(Object extension, String strategy) {
   InstantiationStrategy annotation =
       AnnotationUtils.getAnnotation(extension, InstantiationStrategy.class);
   if (annotation != null) {
     return strategy.equals(annotation.value());
   }
   return InstantiationStrategy.PER_PROJECT.equals(strategy);
 }
 public static String getRuleKey(Class annotatedClass) {
   String key = null;
   org.sonar.check.Rule ruleAnnotation =
       AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class);
   if (ruleAnnotation != null) {
     key = ruleAnnotation.key();
   }
   return StringUtils.defaultIfEmpty(key, annotatedClass.getCanonicalName());
 }
Beispiel #4
0
 public static boolean supportsEnvironment(Object extension, EnvironmentInformation environment) {
   SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
   if (env == null) {
     return true;
   }
   for (String supported : env.value()) {
     if (StringUtils.equalsIgnoreCase(environment.getKey(), supported)) {
       return true;
     }
   }
   return false;
 }
Beispiel #5
0
 private static Phase.Name evaluatePhase(Object extension) {
   Object extensionToEvaluate;
   if (extension instanceof SensorWrapper) {
     extensionToEvaluate = ((SensorWrapper) extension).wrappedSensor();
   } else {
     extensionToEvaluate = extension;
   }
   Phase phaseAnnotation = AnnotationUtils.getAnnotation(extensionToEvaluate, Phase.class);
   if (phaseAnnotation != null) {
     return phaseAnnotation.name();
   }
   return Phase.Name.DEFAULT;
 }
Beispiel #6
0
 private Rule create(String repositoryKey, Class annotatedClass) {
   org.sonar.check.Rule ruleAnnotation =
       AnnotationUtils.getAnnotation(annotatedClass, org.sonar.check.Rule.class);
   if (ruleAnnotation != null) {
     return toRule(repositoryKey, annotatedClass, ruleAnnotation);
   }
   LOG.warn(
       "The class "
           + annotatedClass.getCanonicalName()
           + " should be annotated with "
           + Rule.class);
   return null;
 }
 private static boolean isLinear(AnalyzerMessage issue) {
   String ruleKey;
   RspecKey rspecKeyAnnotation =
       AnnotationUtils.getAnnotation(issue.getCheck().getClass(), RspecKey.class);
   if (rspecKeyAnnotation != null) {
     ruleKey = rspecKeyAnnotation.value();
   } else {
     ruleKey = AnnotationUtils.getAnnotation(issue.getCheck().getClass(), Rule.class).key();
   }
   try {
     URL resource =
         CheckVerifier.class.getResource(
             "/org/sonar/l10n/java/rules/squid/" + ruleKey + "_java.json");
     if (resource == null) {
       throw new IOException();
     }
     String json = Resources.toString(resource, Charsets.UTF_8);
     return LINEAR_FUNC_PATTERN.matcher(json).find();
   } catch (IOException e) {
     // Failed to open json file, as this is not part of API yet, we should not fail because of
     // this
   }
   return false;
 }
Beispiel #8
0
 public static boolean isMavenExtensionOnly(Object extension) {
   SupportedEnvironment env = AnnotationUtils.getAnnotation(extension, SupportedEnvironment.class);
   return env != null
       && env.value().length == 1
       && StringUtils.equalsIgnoreCase("maven", env.value()[0]);
 }
Beispiel #9
0
 public static boolean supportsPreview(Object extension) {
   return AnnotationUtils.getAnnotation(extension, DryRunIncompatible.class) == null;
 }
 public static boolean isBatchSide(Object extension) {
   return AnnotationUtils.getAnnotation(extension, BatchSide.class) != null;
 }