*/
package org.sonar.plugins.core.sensors;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.DependsUpon;
-import org.sonar.api.batch.Event;
-import org.sonar.api.batch.TimeMachine;
-import org.sonar.api.batch.TimeMachineQuery;
+import org.sonar.api.batch.*;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
TimeMachineQuery query = new TimeMachineQuery(resource).setOnlyLastAnalysis(true).setMetrics(CoreMetrics.ALERT_STATUS);
List<Measure> measures = timeMachine.getMeasures(query);
- Measure pastStatus = (measures != null && measures.size() == 1 ? measures.get(0) : null);
+ Measure pastStatus = measures != null && measures.size() == 1 ? measures.get(0) : null;
String alertText = currentStatus.getAlertText();
Level alertLevel = currentStatus.getDataAsLevel();
String alertName = null;
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();
}
public void filter() {
- boolean visible = (tree.getItemCount() == 0 && !filters.hasKeyword());
+ boolean visible = tree.getItemCount() == 0 && !filters.hasKeyword();
for (int index = 0; index < tree.getItemCount(); index++) {
Library lib = (Library) tree.getItem(index);
visible |= !lib.filter(filters.getKeywordFilter().getKeyword(), filters.isTestFiltered());
}
public List<Bucket> getChildren() {
- return (children == null ? Collections.<Bucket>emptyList() : children);
+ return children == null ? Collections.<Bucket>emptyList() : children;
}
public Bucket getParent() {
}
private static boolean isFiltered(Violation violation, ViolationQuery.SwitchMode mode) {
- return (mode == ViolationQuery.SwitchMode.BOTH
+ return mode == ViolationQuery.SwitchMode.BOTH
|| (mode == ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff())
- || (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff()));
+ || (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff());
}
@Override
boolean excluded = checkExclusion(resource, parentBucket);
if (!excluded) {
- Snapshot snapshot = persistence.saveResource(currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null));
+ Resource parentSnapshot = parentBucket != null ? parentBucket.getResource() : null;
+ Snapshot snapshot = persistence.saveResource(currentProject, resource, parentSnapshot);
if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
graph.addComponent(resource, snapshot);
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.events.DecoratorExecutionHandler;
-import org.sonar.api.batch.events.DecoratorsPhaseHandler;
-import org.sonar.api.batch.events.InitializerExecutionHandler;
-import org.sonar.api.batch.events.InitializersPhaseHandler;
-import org.sonar.api.batch.events.MavenPhaseHandler;
-import org.sonar.api.batch.events.PostJobExecutionHandler;
-import org.sonar.api.batch.events.PostJobsPhaseHandler;
-import org.sonar.api.batch.events.ProjectAnalysisHandler;
-import org.sonar.api.batch.events.SensorExecutionHandler;
-import org.sonar.api.batch.events.SensorsPhaseHandler;
+import org.sonar.api.batch.events.*;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.TimeUtils;
import org.sonar.batch.events.BatchStepHandler;
import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate;
public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler,
- SensorsPhaseHandler, PostJobsPhaseHandler, MavenPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler {
+ SensorsPhaseHandler, PostJobsPhaseHandler, MavenPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler {
static final Logger LOG = LoggerFactory.getLogger(PhasesSumUpTimeProfiler.class);
private static final int TEXT_RIGHT_PAD = 60;
} else {
for (Decorator decorator : decoratorsProfiler.getDurations().keySet()) {
currentModuleProfiling.getProfilingPerPhase(Phases.Phase.DECORATOR)
- .getProfilingPerItem(decorator).setTotalTime(decoratorsProfiler.getDurations().get(decorator));
+ .getProfilingPerItem(decorator).setTotalTime(decoratorsProfiler.getDurations().get(decorator));
}
currentModuleProfiling.getProfilingPerPhase(Phases.Phase.DECORATOR).stop();
}
public void onInitializersPhase(InitializersPhaseEvent event) {
if (event.isStart()) {
currentModuleProfiling.addPhaseProfiling(Phases.Phase.INIT);
- }
- else {
+ } else {
currentModuleProfiling.getProfilingPerPhase(Phases.Phase.INIT).stop();
}
}
public void onBatchStep(BatchStepEvent event) {
if (event.isStart()) {
currentModuleProfiling.addBatchStepProfiling(event.stepName());
- }
- else {
+ } else {
currentModuleProfiling.getProfilingPerBatchStep(event.stepName()).stop();
}
}
import javax.annotation.Nullable;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class MeasureFilterFactory implements ServerComponent {
filter.setResourceScopes(toList(properties.get("scopes")));
filter.setResourceQualifiers(toList(properties.get("qualifiers")));
filter.setResourceLanguages(toList(properties.get("languages")));
- MeasureFilterCondition condition = alertToCondition((toList(properties.get("alertLevels"))));
+ MeasureFilterCondition condition = alertToCondition(toList(properties.get("alertLevels")));
if (condition != null) {
filter.addCondition(condition);
}
column = "p.created_at";
break;
case METRIC:
- if (metric.isNumericType()) {
- column = (period != null ? "pmsort.variation_value_" + period : "pmsort.value");
- } else {
- column = "pmsort.text_value";
- }
+ column = getMetricColumn();
break;
default:
throw new IllegalArgumentException("Unsupported sorting: " + field);
}
return column;
}
+
+ private String getMetricColumn(){
+ if (metric.isNumericType()) {
+ return period != null ? "pmsort.variation_value_" + period : "pmsort.value";
+ } else {
+ return "pmsort.text_value";
+ }
+ }
}
class ExceptionHandling {
+ private ExceptionHandling(){
+ // Hide public constructor
+ }
+
static RuntimeException handle(Exception e, Log log) throws MojoExecutionException {
Throwable source = e;
- if (e.getClass().getName().equals("org.sonar.runner.impl.RunnerException") && e.getCause() != null) {
+ if ("org.sonar.runner.impl.RunnerException".equals(e.getClass().getName()) && e.getCause() != null) {
source = e.getCause();
}
log.error(source.getMessage());
import org.sonar.api.rules.Rule;
import javax.persistence.*;
+
import java.util.Collections;
import java.util.List;
public Double getPropertyValue(String key, Double defaultValue) {
CharacteristicProperty property = getProperty(key);
- Double value = (property != null ? property.getValue() : null);
+ Double value = property != null ? property.getValue() : null;
return value == null ? defaultValue : value;
}
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+import java.util.concurrent.*;
/**
* Synchronously execute a native command line. It's much more limited than the Apache Commons Exec library.
final Process finalProcess = process;
executorService = Executors.newSingleThreadExecutor();
Future<Integer> ft = executorService.submit(new Callable<Integer>() {
+ @Override
public Integer call() throws Exception {
return finalProcess.waitFor();
}
import org.sonar.server.platform.PersistentSettings;
import javax.annotation.Nullable;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
return (SonarConfig) xStream.fromXML(inputStream);
} catch (IOException e) {
- throw new RuntimeException("Can't read xml", e);
+ throw new IllegalStateException("Can't read xml", e);
}
}
public class HttpException extends RuntimeException {
private final int httpCode;
- private String l10nKey;
- private Collection<Object> l10nParams;
+ private final String l10nKey;
+ private final Collection<Object> l10nParams;
public HttpException(int httpCode) {
this.httpCode = httpCode;
+ this.l10nKey = null;
+ this.l10nParams = null;
}
public HttpException(int httpCode, String message) {
super(message);
this.httpCode = httpCode;
+ this.l10nKey = null;
+ this.l10nParams = null;
}
public HttpException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) {
import org.slf4j.LoggerFactory;
import org.sonar.api.web.ServletFilter;
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
+import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
this.chain = chain;
}
+ @Override
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
if (iterator == null) {
iterator = filters.iterator();
import org.sonar.api.ServerComponent;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.Server;
-import org.sonar.api.utils.SonarException;
import org.sonar.api.utils.TimeProfiler;
import org.sonar.core.plugins.DefaultPluginMetadata;
import org.sonar.core.plugins.PluginInstaller;
FileUtils.deleteDirectory(trashDir);
}
} catch (IOException e) {
- throw new SonarException("Fail to clean the plugin trash directory: " + trashDir, e);
+ throw new IllegalStateException("Fail to clean the plugin trash directory: " + trashDir, e);
}
}
File masterFile = new File(fileSystem.getUserPluginsDir(), metadata.getFile().getName());
FileUtils.moveFileToDirectory(masterFile, fileSystem.getRemovedPluginsDir(), true);
} catch (IOException e) {
- throw new SonarException("Fail to uninstall plugin: " + pluginKey, e);
+ throw new IllegalStateException("Fail to uninstall plugin: " + pluginKey, e);
}
}
}
try {
FileUtils.moveFileToDirectory(file, fileSystem.getUserPluginsDir(), false);
} catch (IOException e) {
- throw new SonarException("Fail to cancel plugin uninstalls", e);
+ throw new IllegalStateException("Fail to cancel plugin uninstalls", e);
}
}
}
installer.install(plugin, pluginDeployDir);
} catch (IOException e) {
- throw new RuntimeException("Fail to deploy the plugin " + plugin, e);
+ throw new IllegalStateException("Fail to deploy the plugin " + plugin, e);
}
}
FileUtils.copyFile(driver, deployedDriver);
} catch (IOException e) {
- throw new RuntimeException("Can not copy the JDBC driver from " + driver + " to " + deployedDriver, e);
+ throw new IllegalStateException("Can not copy the JDBC driver from " + driver + " to " + deployedDriver, e);
}
}
File deployedDriverIndex = fileSystem.getDeployedJdbcDriverIndex();
private File deployDir;
private PluginDeployer deployer;
private Server server = mock(Server.class);
- private UpdateCenterMatrixFactory updateCenterMatrixFactory;
@Before
public void start() {
public abstract class Detector {
- public final double probability;
+ private final double probability;
public Detector(double probability) {
if (probability < 0 || probability > 1) {
}
public static String toQueryParam(Date d, boolean includeTime) {
- String format = (includeTime ? DATETIME_FORMAT : DATE_FORMAT);
+ String format = includeTime ? DATETIME_FORMAT : DATE_FORMAT;
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(d);
}