*/
package org.sonar.batch.phases;
+
+import org.sonar.batch.util.BatchUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.events.SensorExecutionHandler;
import org.sonar.api.batch.events.SensorsPhaseHandler;
@Override
public void onSensorExecution(SensorExecutionEvent event) {
if (event.isStart()) {
- profiler.startInfo("Sensor " + event.getSensor());
+ profiler.startInfo("Sensor " + BatchUtils.describe(event.getSensor()));
} else {
profiler.stopInfo();
}
*/
package org.sonar.batch.phases;
+import org.sonar.batch.util.BatchUtils;
+
import com.google.common.collect.Lists;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
logPostJobs(postJobs);
for (PostJob postJob : postJobs) {
- LOG.info("Executing post-job {}", postJob.toString());
+ LOG.info("Executing post-job {}", BatchUtils.describe(postJob));
eventBus.fireEvent(new PostJobExecutionEvent(postJob, true));
postJob.executeOn(project, context);
eventBus.fireEvent(new PostJobExecutionEvent(postJob, false));
}
}
- private void logPostJobs(Collection<PostJob> postJobs) {
+ private static void logPostJobs(Collection<PostJob> postJobs) {
if (LOG.isDebugEnabled()) {
LOG.debug("Post-jobs : {}", StringUtils.join(postJobs, " -> "));
}
import com.google.common.base.Strings;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
throw new IllegalStateException("Encoding not supported", e);
}
}
+
+ public static String describe(Object o) {
+ try {
+ if (o.getClass().getMethod("toString").getDeclaringClass() != Object.class) {
+ return o.toString();
+ }
+ } catch (Exception e) {
+ // fallback
+ }
+
+ return o.getClass().getName();
+ }
}
assertThat(BatchUtils.encodeForUrl("foo")).isEqualTo("foo");
assertThat(BatchUtils.encodeForUrl("foo&bar")).isEqualTo("foo%26bar");
}
+
+ @Test
+
+ public void testDescribe() {
+ Object withToString = new Object() {
+ @Override
+ public String toString() {
+ return "desc";
+ }
+ };
+
+ Object withoutToString = new Object();
+
+ assertThat(BatchUtils.describe(withToString)).isEqualTo(("desc"));
+ assertThat(BatchUtils.describe(withoutToString)).isEqualTo("java.lang.Object");
+ }
}