Skip to content

Commit

Permalink
SONAR-8631 Only publish input files used by sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
dbmeneses committed Jan 27, 2017
1 parent eea589c commit e606937
Show file tree
Hide file tree
Showing 84 changed files with 866 additions and 954 deletions.
3 changes: 2 additions & 1 deletion it/it-tests/src/test/java/it/analysis/MultiLanguageTest.java
Expand Up @@ -61,7 +61,8 @@ public void test_sonar_runner_inspection() {
SonarScanner build = SonarScanner.create().setProjectDir(ItUtils.projectDir("analysis/xoo-multi-languages"));
BuildResult result = orchestrator.executeBuild(build);

assertThat(result.getLogs()).contains("2 files indexed");
// 4 files: 1 .xoo, 1.xoo2, 2 .measures
assertThat(result.getLogs()).contains("4 files indexed");
assertThat(result.getLogs()).contains("Quality profile for xoo: one-issue-per-line");
assertThat(result.getLogs()).contains("Quality profile for xoo2: one-issue-per-line-xoo2");

Expand Down
Expand Up @@ -22,7 +22,6 @@
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputPath;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;

Expand Down
Expand Up @@ -488,7 +488,9 @@ public interface CoreProperties {

/**
* @since 5.1
* @deprecated since 6.3. No longer taken into consideration as all files are always imported.
*/
@Deprecated
String IMPORT_UNKNOWN_FILES_KEY = "sonar.import_unknown_files";

/**
Expand Down
Expand Up @@ -29,6 +29,6 @@ public interface FilePredicate {
/**
* Test if provided file is valid for this predicate
*/
boolean apply(IndexedFile inputFile);
boolean apply(InputFile inputFile);

}
Expand Up @@ -20,7 +20,6 @@
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.scan.filesystem.PathResolver;
import org.sonar.api.utils.PathUtils;
Expand All @@ -44,7 +43,7 @@ class AbsolutePathPredicate extends AbstractFilePredicate {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
return path.equals(f.absolutePath());
}

Expand Down
Expand Up @@ -20,12 +20,11 @@
package org.sonar.api.batch.fs.internal;

import com.google.common.collect.Iterables;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.InputFile;

/**
* Partial implementation of {@link FilePredicate}.
* Partial implementation of {@link OptimizedFilePredicate}.
* @since 5.1
*/
public abstract class AbstractFilePredicate implements OptimizedFilePredicate {
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

import java.util.ArrayList;
Expand Down Expand Up @@ -61,7 +60,7 @@ public static FilePredicate create(Collection<FilePredicate> predicates) {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
for (OptimizedFilePredicate predicate : predicates) {
if (!predicate.apply(f)) {
return false;
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Predicate;
import java.util.stream.StreamSupport;

import javax.annotation.Nullable;
Expand All @@ -55,7 +56,7 @@ public class DefaultFileSystem implements FileSystem {
private Path workDir;
private Charset encoding;
protected final FilePredicates predicates;
private InputFilePredicate defaultPredicate;
private Predicate<InputFile> defaultPredicate;

/**
* Only for testing
Expand Down Expand Up @@ -110,7 +111,7 @@ public DefaultFileSystem setWorkDir(File d) {
return this;
}

public DefaultFileSystem setDefaultPredicate(@Nullable InputFilePredicate predicate) {
public DefaultFileSystem setDefaultPredicate(@Nullable Predicate<InputFile> predicate) {
this.defaultPredicate = predicate;
return this;
}
Expand Down Expand Up @@ -161,7 +162,7 @@ public Iterable<InputFile> inputFiles(FilePredicate predicate) {
Iterable<InputFile> iterable = OptimizedFilePredicateAdapter.create(predicate).get(cache);
if (defaultPredicate != null) {
return StreamSupport.stream(iterable.spliterator(), false)
.filter(defaultPredicate::apply)::iterator;
.filter(defaultPredicate::test)::iterator;
}
return iterable;
}
Expand Down Expand Up @@ -279,6 +280,7 @@ public InputDir inputDir(String relativePath) {
return dirMap.get(relativePath);
}

@Override
public InputModule module() {
return module;
}
Expand Down
Expand Up @@ -36,8 +36,11 @@ public class DefaultIndexedFile extends DefaultInputComponent implements Indexed
private String language;
private final Type type;

/**
* Testing purposes only!
*/
public DefaultIndexedFile(String moduleKey, Path moduleBaseDir, String relativePath) {
this(moduleKey, moduleBaseDir, relativePath, TestInputFileBuilder.batchId++);
this(moduleKey, moduleBaseDir, relativePath, TestInputFileBuilder.nextBatchId());
}

public DefaultIndexedFile(String moduleKey, Path moduleBaseDir, String relativePath, int batchId) {
Expand Down
Expand Up @@ -35,7 +35,7 @@ public class DefaultInputDir extends DefaultInputComponent implements InputDir {
private Path moduleBaseDir;

public DefaultInputDir(String moduleKey, String relativePath) {
this(moduleKey, relativePath, TestInputFileBuilder.batchId++);
this(moduleKey, relativePath, TestInputFileBuilder.nextBatchId());
}

public DefaultInputDir(String moduleKey, String relativePath, int batchId) {
Expand Down
Expand Up @@ -24,7 +24,7 @@
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.function.Function;
import java.util.function.Consumer;

import javax.annotation.CheckForNull;
import org.sonar.api.batch.fs.InputFile;
Expand All @@ -36,12 +36,13 @@
*/
public class DefaultInputFile extends DefaultInputComponent implements InputFile {
private final DefaultIndexedFile indexedFile;
private final Function<DefaultInputFile, Metadata> metadataGenerator;
private final Consumer<DefaultInputFile> metadataGenerator;
private Status status;
private Charset charset;
private Metadata metadata;
private boolean publish = false;

public DefaultInputFile(DefaultIndexedFile indexedFile, Function<DefaultInputFile, Metadata> metadataGenerator) {
public DefaultInputFile(DefaultIndexedFile indexedFile, Consumer<DefaultInputFile> metadataGenerator) {
super(indexedFile.batchId());
this.indexedFile = indexedFile;
this.metadataGenerator = metadataGenerator;
Expand All @@ -50,10 +51,18 @@ public DefaultInputFile(DefaultIndexedFile indexedFile, Function<DefaultInputFil

private void checkMetadata() {
if (metadata == null) {
setMetadata(metadataGenerator.apply(this));
metadataGenerator.accept(this);
}
}

public void setPublish(boolean publish) {
this.publish = publish;
}

public boolean publish() {
return publish;
}

@Override
public String relativePath() {
return indexedFile.relativePath();
Expand Down Expand Up @@ -253,7 +262,7 @@ private int findLine(int globalOffset) {
return Math.abs(Arrays.binarySearch(originalLineOffsets(), globalOffset) + 1);
}

private DefaultInputFile setMetadata(Metadata metadata) {
public DefaultInputFile setMetadata(Metadata metadata) {
this.metadata = metadata;
return this;
}
Expand Down
Expand Up @@ -30,8 +30,11 @@ public class DefaultInputModule extends DefaultInputComponent implements InputMo
private final String moduleKey;
private final ProjectDefinition definition;

/**
* For testing only!
*/
public DefaultInputModule(String moduleKey) {
this(ProjectDefinition.create().setKey(moduleKey), TestInputFileBuilder.batchId++);
this(ProjectDefinition.create().setKey(moduleKey), TestInputFileBuilder.nextBatchId());
}

public DefaultInputModule(ProjectDefinition definition, int batchId) {
Expand Down
Expand Up @@ -21,7 +21,6 @@

import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

import java.util.Collections;
Expand All @@ -31,7 +30,7 @@ class FalsePredicate extends AbstractFilePredicate {
static final FilePredicate FALSE = new FalsePredicate();

@Override
public boolean apply(IndexedFile inputFile) {
public boolean apply(InputFile inputFile) {
return false;
}

Expand Down
Expand Up @@ -24,7 +24,7 @@
import org.sonar.api.batch.fs.InputComponent;

public interface InputComponentTree {
public Collection<InputComponent> getChildren(InputComponent module);
Collection<InputComponent> getChildren(InputComponent module);

public InputComponent getParent(InputComponent module);
InputComponent getParent(InputComponent module);
}

This file was deleted.

Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

/**
* @since 4.2
Expand All @@ -32,7 +32,7 @@ class LanguagePredicate extends AbstractFilePredicate {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
return language.equals(f.language());
}
}
Expand Up @@ -20,7 +20,7 @@
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

/**
* @since 4.2
Expand All @@ -34,7 +34,7 @@ class NotPredicate extends AbstractFilePredicate {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
return !predicate.apply(f);
}

Expand Down
Expand Up @@ -20,7 +20,7 @@
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

class OptimizedFilePredicateAdapter extends AbstractFilePredicate {

Expand All @@ -31,7 +31,7 @@ private OptimizedFilePredicateAdapter(FilePredicate unoptimizedPredicate) {
}

@Override
public boolean apply(IndexedFile inputFile) {
public boolean apply(InputFile inputFile) {
return unoptimizedPredicate.apply(inputFile);
}

Expand Down
Expand Up @@ -21,7 +21,7 @@

import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.batch.fs.FilePredicate;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -56,7 +56,7 @@ public static FilePredicate create(Collection<FilePredicate> predicates) {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
for (FilePredicate predicate : predicates) {
if (predicate.apply(f)) {
return true;
Expand Down
Expand Up @@ -19,7 +19,7 @@
*/
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;

/**
* @since 4.2
Expand All @@ -33,7 +33,7 @@ class PathPatternPredicate extends AbstractFilePredicate {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
return pattern.match(f);
}

Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.sonar.api.batch.fs.internal;

import org.sonar.api.batch.fs.FileSystem.Index;
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.utils.PathUtils;

Expand All @@ -43,7 +42,7 @@ public String path() {
}

@Override
public boolean apply(IndexedFile f) {
public boolean apply(InputFile f) {
return path.equals(f.relativePath());
}

Expand Down

0 comments on commit e606937

Please sign in to comment.