Skip to content

Commit

Permalink
Fix some quality flaws
Browse files Browse the repository at this point in the history
  • Loading branch information
henryju committed Jun 30, 2015
1 parent 3f109b1 commit 0063b92
Show file tree
Hide file tree
Showing 16 changed files with 162 additions and 175 deletions.
2 changes: 1 addition & 1 deletion microbenchmark-template/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar</artifactId>
<version>5.1-SNAPSHOT</version>
<version>5.2-SNAPSHOT</version>
</parent>
<artifactId>microbenchmark-template</artifactId>
<packaging>jar</packaging>
Expand Down
Expand Up @@ -20,6 +20,11 @@
package org.sonar.microbenchmark;

import com.google.protobuf.CodedOutputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang.RandomStringUtils;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand All @@ -38,12 +43,6 @@
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.sonar.server.source.db.FileSourceDb;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
*
* See https://code.google.com/p/xxhash/ and https://github.com/jpountz/lz4-java
Expand Down Expand Up @@ -79,7 +78,7 @@ public void setup() throws Exception {
.setSource(RandomStringUtils.randomAlphanumeric(10))
.setHighlighting(RandomStringUtils.randomAlphanumeric(20))
.setSymbols(RandomStringUtils.randomAlphanumeric(20))
.addAllDuplications(Arrays.asList(12,13,15))
.addAllDuplication(Arrays.asList(12, 13, 15))
.build());
}
data = builder.build();
Expand Down
Expand Up @@ -24,6 +24,21 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonWriter;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.Externalizable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand All @@ -41,22 +56,6 @@
import org.sonar.batch.protocol.Constants;
import org.sonar.batch.protocol.output.BatchReport;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.Externalizable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(1)
Expand Down Expand Up @@ -103,7 +102,7 @@ public void write_protobuf() throws Exception {
issueBuilder.setMsg("this is the message of issue " + i);
issueBuilder.setLine(i);
issueBuilder.setAuthorLogin("someone");
issueBuilder.addAllTags(Arrays.asList("tag" + i, "othertag" + i));
issueBuilder.addAllTag(Arrays.asList("tag" + i, "othertag" + i));
issueBuilder.build().writeDelimitedTo(out);
}
}
Expand Down
Expand Up @@ -22,6 +22,15 @@
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
import org.apache.commons.lang.ClassUtils;
import org.sonar.api.batch.CheckProject;
import org.sonar.api.batch.DependedUpon;
Expand All @@ -31,7 +40,6 @@
import org.sonar.api.batch.postjob.PostJobContext;
import org.sonar.api.batch.sensor.Sensor;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.core.platform.ComponentContainer;
import org.sonar.api.resources.Project;
import org.sonar.api.utils.AnnotationUtils;
import org.sonar.api.utils.dag.DirectAcyclicGraph;
Expand All @@ -40,17 +48,7 @@
import org.sonar.batch.sensor.DefaultSensorContext;
import org.sonar.batch.sensor.SensorOptimizer;
import org.sonar.batch.sensor.SensorWrapper;

import javax.annotation.Nullable;

import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.sonar.core.platform.ComponentContainer;

/**
* @since 2.6
Expand Down Expand Up @@ -245,7 +243,7 @@ private void evaluateMethod(Object extension, Method method, List<Object> result
}
}

private void checkAnnotatedMethod(Method method) {
private static void checkAnnotatedMethod(Method method) {
if (!Modifier.isPublic(method.getModifiers())) {
throw new IllegalStateException("Annotated method must be public:" + method);
}
Expand All @@ -254,7 +252,7 @@ private void checkAnnotatedMethod(Method method) {
}
}

private boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
private static boolean shouldKeep(Class type, Object extension, @Nullable Project project, @Nullable ExtensionMatcher matcher) {
boolean keep = (ClassUtils.isAssignable(extension.getClass(), type)
|| (org.sonar.api.batch.Sensor.class.equals(type) && ClassUtils.isAssignable(extension.getClass(), Sensor.class)))
&& (matcher == null || matcher.accept(extension));
Expand Down
Expand Up @@ -19,7 +19,6 @@
*/
package org.sonar.batch.bootstrap;

import org.sonar.home.cache.PersistentCache;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
Expand All @@ -29,17 +28,6 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.core.util.DefaultHttpDownloader;

import javax.annotation.Nullable;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -50,6 +38,16 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.BatchSide;
import org.sonar.api.utils.HttpDownloader;
import org.sonar.batch.bootstrapper.EnvironmentInformation;
import org.sonar.core.util.DefaultHttpDownloader;
import org.sonar.home.cache.PersistentCache;

/**
* Replace the deprecated org.sonar.batch.ServerMetadata
Expand Down Expand Up @@ -180,7 +178,7 @@ public RuntimeException handleHttpException(HttpDownloader.HttpException he) {
return new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]", he.getResponseCode(), he.getUri()), he);
}

private String tryParseAsJsonError(String responseContent) {
private static String tryParseAsJsonError(String responseContent) {
try {
JsonParser parser = new JsonParser();
JsonObject obj = parser.parse(responseContent).getAsJsonObject();
Expand Down
Expand Up @@ -19,6 +19,8 @@
*/
package org.sonar.batch.deprecated;

import java.io.Serializable;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.batch.AnalysisMode;
Expand All @@ -44,9 +46,6 @@
import org.sonar.batch.sensor.DefaultSensorContext;
import org.sonar.batch.sensor.coverage.CoverageExclusions;

import java.io.Serializable;
import java.util.Collection;

public class DeprecatedSensorContext extends DefaultSensorContext implements SensorContext {

private static final Logger LOG = LoggerFactory.getLogger(DeprecatedSensorContext.class);
Expand Down Expand Up @@ -82,7 +81,7 @@ public boolean index(Resource resource, Resource parentReference) {
return true;
}

private void logWarning() {
private static void logWarning() {
if (LOG.isDebugEnabled()) {
LOG.debug("Plugins are no more responsible for indexing physical resources like directories and files. This is now handled by the platform.", new SonarException(
"Plugin should not index physical resources"));
Expand Down
Expand Up @@ -22,6 +22,8 @@
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.design.Dependency;
Expand All @@ -38,9 +40,6 @@
import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.sensor.coverage.CoverageExclusions;

import java.util.Collection;
import java.util.List;

public class DefaultDecoratorContext implements DecoratorContext {

private static final String SAVE_MEASURE_METHOD = "saveMeasure";
Expand Down Expand Up @@ -111,7 +110,7 @@ public <M> M getMeasures(MeasuresFilter<M> filter) {
}

private <M> Collection<Measure> getMeasuresOfASingleMetric(MeasuresFilters.MetricFilter<M> filter) {
String metricKey = ((MeasuresFilters.MetricFilter<M>) filter).filterOnMetricKey();
String metricKey = filter.filterOnMetricKey();
return measuresByMetric.get(metricKey);
}

Expand Down
Expand Up @@ -70,7 +70,7 @@ public void dump(Properties props) {
categories.putAll(profilingPerBatchStep);

for (Map.Entry<Object, AbstractTimeProfiling> batchStep : categories.entrySet()) {
props.setProperty(batchStep.getKey().toString(), "" + batchStep.getValue().totalTime());
props.setProperty(batchStep.getKey().toString(), Long.toString(batchStep.getValue().totalTime()));
}

for (Map.Entry<Object, AbstractTimeProfiling> batchStep : sortByDescendingTotalTime(categories).entrySet()) {
Expand Down
Expand Up @@ -19,12 +19,11 @@
*/
package org.sonar.batch.profiling;

import org.sonar.api.utils.System2;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.sonar.api.utils.System2;

public class PhaseProfiling extends AbstractTimeProfiling {

Expand Down Expand Up @@ -76,7 +75,7 @@ public void merge(PhaseProfiling other) {
public void dump(Properties props) {
double percent = this.totalTime() / 100.0;
for (ItemProfiling itemProfiling : profilingPerItem.values()) {
props.setProperty(itemProfiling.itemName(), "" + itemProfiling.totalTime());
props.setProperty(itemProfiling.itemName(), Long.toString(itemProfiling.totalTime()));
}
for (ItemProfiling itemProfiling : truncate(sortByDescendingTotalTime(profilingPerItem).values())) {
println(" o " + itemProfiling.itemName() + ": ", percent, itemProfiling);
Expand Down

0 comments on commit 0063b92

Please sign in to comment.