*/
package org.sonar.plugins.core.issue;
-import java.util.Collection;
-
+import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.resources.Resource;
import org.sonar.batch.scan.LastSnapshots;
import org.sonar.plugins.core.issue.tracking.StringText;
import org.sonar.plugins.core.issue.tracking.StringTextComparator;
-
+import java.util.Collection;
public class SourceHashHolder {
}
public String getSource() {
- if (! sourceInitialized) {
- source = index.getSource(resource);
+ if (!sourceInitialized) {
+ source = StringUtils.defaultString(index.getSource(resource), "");
sourceInitialized = true;
}
return source;
}
public String getReferenceSource() {
- if (! referenceSourceInitialized) {
+ if (!referenceSourceInitialized) {
if (resource != null) {
referenceSource = lastSnapshots.getSource(resource);
}
}
private void initHashesIfNull(Object required) {
- if(required == null) {
+ if (required == null) {
initHashes();
}
}
return getHashedSource().getLinesForHash(getHashedReference().getHash(originLine));
}
}
-
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.CharMatcher;
import com.google.common.io.Files;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.sonar.api.BatchComponent;
import org.sonar.api.CoreProperties;
import org.sonar.api.batch.SonarIndex;
*/
public class ComponentIndexer implements BatchComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(ComponentIndexer.class);
+
private final Languages languages;
private final Settings settings;
private final SonarIndex sonarIndex;
migration.migrateIfNeeded(module, fs);
boolean shouldImportSource = settings.getBoolean(CoreProperties.CORE_IMPORT_SOURCES_PROPERTY);
+ if (!shouldImportSource) {
+ LOG.warn("Not importing source will prevent issues to be properly tracked between consecutive analyses");
+ }
for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
String languageKey = inputFile.language();
boolean unitTest = InputFile.Type.TEST == inputFile.type();
public abstract void setSource(Resource reference, String source);
/**
- * @return source code associated with a specified resource, <code>null</code> if not available
+ * @return source code associated with a specified resource, <code>null</code> if not available
+ * (for example when sonar.importSources=false)
* @since 2.9
*/
+ @CheckForNull
public abstract String getSource(Resource resource);
public abstract Project getProject();