Rule rule = ruleFinder.findByKey(issue.ruleKey());
if (manualIssue) {
// Manual rules are not declared in Quality profiles, so no need to check ActiveRule
- boolean isRemovedRule = (rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus()));
+ boolean isRemovedRule = rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus());
issue.setEndOfLife(forceEndOfLife || isRemovedRule);
issue.setOnDisabledRule(isRemovedRule);
} else {
if (nullValuesYList || nbrPoints == 1) {
return null;
}
- double n0 = (((nbrPoints) * (sumXY)) - ((sumX) * (sumY)));
- double d = (((nbrPoints) * (sumXPower2)) - ((sumX) * (sumX)));
- double n1 = (((sumY) * (sumXPower2)) - ((sumX) * (sumXY)));
+ double n0 = ((nbrPoints * sumXY) - (sumX * sumY));
+ double d = ((nbrPoints * sumXPower2) - (sumX * sumX));
+ double n1 = ((sumY * sumXPower2) - (sumX * sumXY));
SlopeData result = new SlopeData();
if (sumXPower2 == 0 || sumYPower2 == 0) {
result.setCorrelationRate(0.0);
} else {
- result.setCorrelationRate((sumXY) / (Math.sqrt(sumXPower2 * sumYPower2)));
+ result.setCorrelationRate(sumXY / Math.sqrt(sumXPower2 * sumYPower2));
}
return result;
// for each measure, search equivalent past measure
for (Measure measure : context.getMeasures(MeasuresFilters.all())) {
// compare with past measure
- Integer metricId = (measure.getMetric().getId() != null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId());
- Integer characteristicId = (measure.getCharacteristic() != null ? measure.getCharacteristic().getId() : null);
+ Integer metricId = measure.getMetric().getId() != null ? measure.getMetric().getId() : metricFinder.findByKey(measure.getMetric().getKey()).getId();
+ Integer characteristicId = measure.getCharacteristic() != null ? measure.getCharacteristic().getId() : null;
Integer personId = measure.getPersonId();
- Integer ruleId = (measure instanceof RuleMeasure ? ((RuleMeasure) measure).getRule().getId() : null);
+ Integer ruleId = measure instanceof RuleMeasure ? ((RuleMeasure) measure).getRule().getId() : null;
Object[] pastMeasure = pastMeasuresByKey.get(new MeasureKey(metricId, characteristicId, personId, ruleId));
if (updateVariation(measure, pastMeasure, index)) {
boolean updateVariation(Measure measure, Object[] pastMeasure, int index) {
if (pastMeasure != null && PastMeasuresLoader.hasValue(pastMeasure) && measure.getValue() != null) {
- double variation = (measure.getValue().doubleValue() - PastMeasuresLoader.getValue(pastMeasure));
+ double variation = measure.getValue() - PastMeasuresLoader.getValue(pastMeasure);
measure.setVariation(index, variation);
return true;
}
}
public static boolean isType(Object extension, Class<?> extensionClass) {
- Class clazz = (extension instanceof Class ? (Class) extension : extension.getClass());
+ Class clazz = extension instanceof Class ? (Class) extension : extension.getClass();
return extensionClass.isAssignableFrom(clazz);
}
}
try {
return IOUtils.toString(inputSupplier.getInput(), "UTF-8");
} catch (HttpDownloader.HttpException e) {
- throw (wrapHttpException ? handleHttpException(e) : e);
+ throw wrapHttpException ? handleHttpException(e) : e;
} catch (IOException e) {
throw new SonarException(String.format("Unable to request: %s", pathStartingWithSlash), e);
}
}
public Date getDate() {
- return (projectSnapshot != null ? projectSnapshot.getCreatedAt() : null);
+ return projectSnapshot != null ? projectSnapshot.getCreatedAt() : null;
}
public String getMode() {
}
Integer getProjectSnapshotId() {
- return (projectSnapshot != null ? projectSnapshot.getId() : null);
+ return projectSnapshot != null ? projectSnapshot.getId() : null;
}
public String getQualifier() {
- return (projectSnapshot != null ? projectSnapshot.getQualifier() : null);
+ return projectSnapshot != null ? projectSnapshot.getQualifier() : null;
}
public Date getTargetDate() {
.setMaxResults(1)
.getResultList();
- return (snapshots.isEmpty() ? null : snapshots.get(0));
+ return snapshots.isEmpty() ? null : snapshots.get(0);
}
}
\ No newline at end of file
if (snapshots.isEmpty()) {
snapshots = session.getResults(Snapshot.class, "resourceId", resourceId, "version", version, "scope", Scopes.PROJECT, "qualifier", Qualifiers.LIBRARY);
}
- return (snapshots.isEmpty() ? null : snapshots.get(0));
+ return snapshots.isEmpty() ? null : snapshots.get(0);
}
/**
@Override
public boolean addIssue(Issue issue) {
- return scanIssues.initAndAddIssue(((DefaultIssue) issue));
+ return scanIssues.initAndAddIssue((DefaultIssue) issue);
}
@SuppressWarnings("unchecked")
}
}
if (!deprecatedFilters.isEmpty()) {
- Violation v = (violation != null ? violation : deprecatedViolations.toViolation(issue));
+ Violation v = violation != null ? violation : deprecatedViolations.toViolation(issue);
return !deprecatedFilters.isIgnored(v);
}
return true;
package org.sonar.batch.scan;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.AndFileFilter;
private static final String PROPERTY_OLD_TESTS = "tests";
private static final String PROPERTY_OLD_BINARIES = "binaries";
private static final String PROPERTY_OLD_LIBRARIES = "libraries";
- private static final Map<String, String> DEPRECATED_PROPS_TO_NEW_PROPS = new HashMap<String, String>() {
- {
- put(PROPERTY_OLD_SOURCES, PROPERTY_SOURCES);
- put(PROPERTY_OLD_TESTS, PROPERTY_TESTS);
- put(PROPERTY_OLD_BINARIES, PROPERTY_BINARIES);
- put(PROPERTY_OLD_LIBRARIES, PROPERTY_LIBRARIES);
- }
- };
+ private static final Map<String, String> DEPRECATED_PROPS_TO_NEW_PROPS = ImmutableMap.of(
+ PROPERTY_OLD_SOURCES, PROPERTY_SOURCES,
+ PROPERTY_OLD_TESTS, PROPERTY_TESTS,
+ PROPERTY_OLD_BINARIES, PROPERTY_BINARIES,
+ PROPERTY_OLD_LIBRARIES, PROPERTY_LIBRARIES
+ );
/**
* @since 1.4
.name("rule_repository").value(issue.ruleKey().repository())
.name("rule_name").value(ruleName(issue.ruleKey()))
.name("switched_off").value(Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution()))
- .name("is_new").value((issue.isNew()))
+ .name("is_new").value(issue.isNew())
.name("created_at").value(DateUtils.formatDateTime(issue.creationDate()))
.endObject();
}
}
public boolean accept(File file, Context context) {
- PathPattern[] inclusionPatterns = (context.type() == FileType.TEST ? testInclusions() : sourceInclusions());
+ PathPattern[] inclusionPatterns = context.type() == FileType.TEST ? testInclusions() : sourceInclusions();
if (inclusionPatterns.length > 0) {
boolean matchInclusion = false;
for (PathPattern pattern : inclusionPatterns) {
return false;
}
}
- PathPattern[] exclusionPatterns = (context.type() == FileType.TEST ? testExclusions() : sourceExclusions());
+ PathPattern[] exclusionPatterns = context.type() == FileType.TEST ? testExclusions() : sourceExclusions();
for (PathPattern pattern : exclusionPatterns) {
if (pattern.match(context)) {
return false;
public boolean isIgnored(Resource resource) {
if (ResourceUtils.isFile(resource)) {
- PathPattern[] inclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testInclusions() : sourceInclusions());
+ PathPattern[] inclusionPatterns = ResourceUtils.isUnitTestClass(resource) ? testInclusions() : sourceInclusions();
if (isIgnoredByInclusions(resource, inclusionPatterns)) {
return true;
}
- PathPattern[] exclusionPatterns = (ResourceUtils.isUnitTestClass(resource) ? testExclusions() : sourceExclusions());
+ PathPattern[] exclusionPatterns = ResourceUtils.isUnitTestClass(resource) ? testExclusions() : sourceExclusions();
return isIgnoredByExclusions(resource, exclusionPatterns);
}
return false;
public String getDescription(String repositoryKey, String ruleKey, Locale locale) {
String relatedProperty = new StringBuilder().append(RULE_PREFIX).append(repositoryKey).append(".").append(ruleKey).append(NAME_SUFFIX).toString();
- Locale localeWithoutCountry = (locale.getCountry() == null ? locale : new Locale(locale.getLanguage()));
+ Locale localeWithoutCountry = locale.getCountry() == null ? locale : new Locale(locale.getLanguage());
String ruleDescriptionFilePath = "rules/" + repositoryKey + "/" + ruleKey + ".html";
String description = i18nManager.messageFromFile(localeWithoutCountry, ruleDescriptionFilePath, relatedProperty, true);
if (description == null) {
}
public void setCloseDate(DefaultIssue issue, @Nullable Date d, IssueChangeContext context) {
- Date dateWithoutMilliseconds = (d == null ? null : DateUtils.truncate(d, Calendar.SECOND));
+ Date dateWithoutMilliseconds = d == null ? null : DateUtils.truncate(d, Calendar.SECOND);
if (!Objects.equal(dateWithoutMilliseconds, issue.closeDate())) {
issue.setCloseDate(d);
issue.setUpdateDate(context.date());
}
static boolean isValid(MeasureFilter filter, MeasureFilterContext context) {
- boolean valid = (Strings.isNullOrEmpty(filter.getBaseResourceKey()) || context.getBaseSnapshot()!=null);
- valid &= (filter.getBaseResourceId()==null || context.getBaseSnapshot()!=null);
+ boolean valid = Strings.isNullOrEmpty(filter.getBaseResourceKey()) || context.getBaseSnapshot()!=null;
+ valid &= filter.getBaseResourceId()==null || context.getBaseSnapshot()!=null;
valid &= !(filter.isOnBaseResourceChildren() && context.getBaseSnapshot() == null);
valid &= !(filter.isOnFavourites() && context.getUserId() == null);
valid &= validateMeasureConditions(filter);
if (filter.isOnBaseResourceChildren()) {
sb.append(" AND s.parent_snapshot_id=").append(baseSnapshot.getId());
} else {
- Long rootSnapshotId = (baseSnapshot.getRootId() != null ? baseSnapshot.getRootId() : baseSnapshot.getId());
+ Long rootSnapshotId = baseSnapshot.getRootId() != null ? baseSnapshot.getRootId() : baseSnapshot.getId();
sb.append(" AND s.root_snapshot_id=").append(rootSnapshotId);
sb.append(" AND s.path LIKE '").append(StringUtils.defaultString(baseSnapshot.getPath())).append(baseSnapshot.getId()).append(".%'");
}
} catch (UnsupportedClassVersionError e) {
throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e);
- } catch (Throwable e) {
+ } catch (Exception e) {
throw new SonarException("Fail to build the classloader of " + plugin.getKey(), e);
}
}
} catch (UnsupportedClassVersionError e) {
throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e);
- } catch (Throwable e) {
+ } catch (Exception e) {
throw new SonarException("Fail to extend the plugin " + plugin.getBasePlugin() + " for " + plugin.getKey(), e);
}
}
} catch (UnsupportedClassVersionError e) {
throw new SonarException("The plugin " + plugin.getKey() + " is not supported with Java " + SystemUtils.JAVA_VERSION_TRIMMED, e);
- } catch (Throwable e) {
+ } catch (Exception e) {
throw new SonarException("Fail to load plugin " + plugin.getKey(), e);
}
}
public final class CommandException extends RuntimeException {
- private transient Command command = null;
+ private final Command command;
public CommandException(Command command, String message, @Nullable Throwable throwable) {
super(message + " [command: " + command + "]", throwable);