import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.scm.BlameCommand;
import java.io.File;
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public class GitBlameCommand implements BlameCommand, BatchComponent {
+public class GitBlameCommand implements BlameCommand {
private static final Logger LOG = LoggerFactory.getLogger(GitBlameCommand.class);
private final CommandExecutor commandExecutor;
import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.scm.BlameCommand;
import java.util.Date;
import java.util.List;
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public class XooBlameCommand implements BlameCommand, BatchComponent {
+public class XooBlameCommand implements BlameCommand {
private static final String SCM_EXTENSION = ".scm";
<version>${project.version}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.codehaus.sonar.plugins</groupId>
- <artifactId>sonar-git-plugin</artifactId>
- <version>${project.version}</version>
- <type>sonar-plugin</type>
- </dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-squid</artifactId>
"org.codehaus.sonar:sonar": {
"sonar.jira.project.key": "SONAR"
}
- },
- "fileDataPerPath": {}
+ }
}
}
}
],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
"sonar.jira.project.key": "SONAR",
"sonar.jira.login.secured": "john"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.project.key": "SONAR",
"sonar.jira.login.secured": "john"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.project.key": "SONAR-APPLICATION",
"sonar.jira.login.secured": "john"
}
- },
- "fileDataPerPath": {}
+ }
}
}
},
"activeRules": [],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
}
},
"activeRules": [],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
}
},
"activeRules": [],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
}
},
"activeRules": [],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
}
},
"activeRules": [],
- "settingsByModule": {},
- "fileDataPerPath": {}
+ "settingsByModule": {}
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
"sonar.jira.login.secured": "john",
"sonar.coverage.exclusions": "**/*.java"
}
- },
- "fileDataPerPath": {}
+ }
}
<type>sonar-plugin</type>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.codehaus.sonar.plugins</groupId>
- <artifactId>sonar-git-plugin</artifactId>
- <type>sonar-plugin</type>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>org.sonatype.jsw-binaries</groupId>
<artifactId>jsw-binaries</artifactId>
private Map<String, QProfile> qprofilesByLanguage = new HashMap<String, QProfile>();
private Collection<ActiveRule> activeRules = new ArrayList<ActiveRule>();
private Map<String, Map<String, String>> settingsByModule = new HashMap<String, Map<String, String>>();
- private Map<String, Map<String, FileData>> fileDataByModuleAndPath = new HashMap<String, Map<String, FileData>>();
+ private Map<String, FileData> fileDataPerPath = new HashMap<String, FileData>();
public Map<String, String> settings(String projectKey) {
return settingsByModule.containsKey(projectKey) ? settingsByModule.get(projectKey) : Collections.<String, String>emptyMap();
Map<String, String> existingSettings = settingsByModule.get(projectKey);
if (existingSettings == null) {
existingSettings = new HashMap<String, String>();
- settingsByModule.put(projectKey, existingSettings);
}
existingSettings.putAll(settings);
+ settingsByModule.put(projectKey, existingSettings);
return this;
}
return this;
}
- public Map<String, FileData> fileDataByPath(String projectKey) {
- return fileDataByModuleAndPath.containsKey(projectKey) ? fileDataByModuleAndPath.get(projectKey) : Collections.<String, FileData>emptyMap();
- }
-
- public ProjectReferentials addFileData(String projectKey, String path, FileData fileData) {
- Map<String, FileData> existingFileDataByPath = fileDataByModuleAndPath.get(projectKey);
- if (existingFileDataByPath == null) {
- existingFileDataByPath = new HashMap<String, FileData>();
- fileDataByModuleAndPath.put(projectKey, existingFileDataByPath);
- }
- existingFileDataByPath.put(path, fileData);
- return this;
+ public Map<String, FileData> fileDataPerPath() {
+ return fileDataPerPath;
}
@CheckForNull
- public FileData fileData(String projectKey, String path) {
- return fileDataByPath(projectKey).get(path);
+ public FileData fileDataPerPath(String path) {
+ return fileDataPerPath.get(path);
}
public long timestamp() {
activeRule.addParam("param1", "value1");
ref.addActiveRule(activeRule);
ref.setTimestamp(10);
- ref.addFileData("foo", "src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
+ ref.fileDataPerPath().put("src/main/java/Foo.java", new FileData("xyz", "1=12345,2=3456", "1=345,2=345", "1=henryju,2=gaudin"));
System.out.println(ref.toJson());
JSONAssert
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule,language:java,params:{param1:value1}}],"
+ "settingsByModule:{foo:{prop1:value1,prop2:value2,prop:value}},"
- + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}",
+ + "fileDataPerPath:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}",
ref.toJson(), true);
}
+ "qprofilesByLanguage:{java:{key:\"squid-java\",name:Java,language:java,rulesUpdatedAt:\"Mar 14, 1984 12:00:00 AM\"}},"
+ "activeRules:[{repositoryKey:repo,ruleKey:rule,name:Rule,severity:MAJOR,internalKey:rule1,language:java,params:{param1:value1}}],"
+ "settingsByModule:{foo:{prop:value}},"
- + "fileDataByModuleAndPath:{foo:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}}");
+ + "fileDataPerPath:{\"src/main/java/Foo.java\":{hash:xyz,scmLastCommitDatetimesByLine:\"1\u003d12345,2\u003d3456\",scmRevisionsByLine:\"1\u003d345,2\u003d345\",scmAuthorsByLine:\"1\u003dhenryju,2\u003dgaudin\"}}}");
assertThat(ref.timestamp()).isEqualTo(1);
assertThat(qProfile.rulesUpdatedAt()).isEqualTo(new SimpleDateFormat("dd/MM/yyyy").parse("14/03/1984"));
assertThat(ref.settings("foo")).includes(MapAssert.entry("prop", "value"));
- assertThat(ref.fileData("foo", "src/main/java/Foo.java").hash()).isEqualTo("xyz");
- assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
- assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
- assertThat(ref.fileData("foo", "src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").hash()).isEqualTo("xyz");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmAuthorsByLine()).isEqualTo("1=henryju,2=gaudin");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmLastCommitDatetimesByLine()).isEqualTo("1=12345,2=3456");
+ assertThat(ref.fileDataPerPath("src/main/java/Foo.java").scmRevisionsByLine()).isEqualTo("1=345,2=345");
}
}
import org.sonar.api.batch.TimeMachineQuery;
import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.MeasureModel;
+import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.Metric;
import javax.annotation.Nullable;
import javax.persistence.Query;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
return jpaQuery.getResultList();
}
+ // Temporary implementation for SONAR-5473
+ public List<MeasureModel> query(String resourceKey, Integer... metricIds) {
+ StringBuilder sb = new StringBuilder();
+ Map<String, Object> params = Maps.newHashMap();
+
+ sb.append("SELECT m");
+ sb.append(" FROM ")
+ .append(MeasureModel.class.getSimpleName())
+ .append(" m, ")
+ .append(ResourceModel.class.getSimpleName())
+ .append(" r, ")
+ .append(Snapshot.class.getSimpleName())
+ .append(" s WHERE m.snapshotId=s.id AND s.resourceId=r.id AND r.kee=:kee AND s.status=:status AND s.qualifier<>:lib");
+ params.put("kee", resourceKey);
+ params.put("status", Snapshot.STATUS_PROCESSED);
+ params.put("lib", Qualifiers.LIBRARY);
+
+ sb.append(" AND m.characteristicId IS NULL");
+ sb.append(" AND m.personId IS NULL");
+ sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL");
+ if (metricIds.length > 0) {
+ sb.append(" AND m.metricId IN (:metricIds) ");
+ params.put("metricIds", Arrays.asList(metricIds));
+ }
+ sb.append(" AND s.last=true ");
+ sb.append(" ORDER BY s.createdAt ");
+
+ Query jpaQuery = session.createQuery(sb.toString());
+
+ for (Map.Entry<String, Object> entry : params.entrySet()) {
+ jpaQuery.setParameter(entry.getKey(), entry.getValue());
+ }
+ return jpaQuery.getResultList();
+ }
+
public Map<Integer, Metric> getMetricsById(TimeMachineQuery query) {
Collection<Metric> metrics = metricFinder.findAll(query.getMetricKeys());
Map<Integer, Metric> result = Maps.newHashMap();
package org.sonar.batch.referential;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Maps;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.database.DatabaseSession;
import org.sonar.api.database.model.MeasureModel;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Metric;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.utils.KeyValueFormat;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.batch.DefaultTimeMachine;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.bootstrap.TaskProperties;
import org.sonar.batch.protocol.input.FileData;
import org.sonar.batch.protocol.input.ProjectReferentials;
import org.sonar.batch.rule.ModuleQProfiles;
-import org.sonar.core.source.SnapshotDataTypes;
-import org.sonar.core.source.db.SnapshotDataDao;
-import org.sonar.core.source.db.SnapshotDataDto;
-
-import javax.persistence.Query;
+import org.sonar.batch.scan.filesystem.PreviousFileHashLoader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.util.Arrays;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
private final ServerClient serverClient;
private final AnalysisMode analysisMode;
- private final SnapshotDataDao dao;
- private final DatabaseSession session;
+ private final PreviousFileHashLoader fileHashLoader;
+ private final MetricFinder metricFinder;
+ private final DefaultTimeMachine defaultTimeMachine;
- public DefaultProjectReferentialsLoader(DatabaseSession session, ServerClient serverClient, AnalysisMode analysisMode,
- SnapshotDataDao dao) {
- this.session = session;
+ public DefaultProjectReferentialsLoader(ServerClient serverClient, AnalysisMode analysisMode, PreviousFileHashLoader fileHashLoader, MetricFinder finder,
+ DefaultTimeMachine defaultTimeMachine) {
this.serverClient = serverClient;
this.analysisMode = analysisMode;
- this.dao = dao;
+ this.fileHashLoader = fileHashLoader;
+ this.metricFinder = finder;
+ this.defaultTimeMachine = defaultTimeMachine;
}
@Override
url += "&preview=" + analysisMode.isPreview();
ProjectReferentials ref = ProjectReferentials.fromJson(serverClient.request(url));
- for (ProjectDefinition module : reactor.getProjects()) {
-
- for (Map.Entry<String, String> hashByPaths : hashByRelativePath(module.getKeyWithBranch()).entrySet()) {
- String path = hashByPaths.getKey();
- String hash = hashByPaths.getValue();
- String lastCommits = null;
- String revisions = null;
- String authors = null;
- List<Object[]> measuresByKey = query(projectKey + ":" + path, CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY, CoreMetrics.SCM_REVISIONS_BY_LINE_KEY,
- CoreMetrics.SCM_AUTHORS_BY_LINE_KEY);
- for (Object[] measureByKey : measuresByKey) {
- if (measureByKey[0].equals(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE_KEY)) {
- lastCommits = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);
- } else if (measureByKey[0].equals(CoreMetrics.SCM_REVISIONS_BY_LINE_KEY)) {
- revisions = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_REVISIONS_BY_LINE);
- } else if (measureByKey[0].equals(CoreMetrics.SCM_AUTHORS_BY_LINE_KEY)) {
- authors = ((MeasureModel) measureByKey[1]).getData(CoreMetrics.SCM_AUTHORS_BY_LINE);
- }
+ Integer lastCommitsId = metricFinder.findByKey(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE.key()).getId();
+ Integer revisionsId = metricFinder.findByKey(CoreMetrics.SCM_REVISIONS_BY_LINE.key()).getId();
+ Integer authorsId = metricFinder.findByKey(CoreMetrics.SCM_AUTHORS_BY_LINE.key()).getId();
+ for (Map.Entry<String, String> hashByPaths : fileHashLoader.hashByRelativePath().entrySet()) {
+ String path = hashByPaths.getKey();
+ String hash = hashByPaths.getValue();
+ String lastCommits = null;
+ String revisions = null;
+ String authors = null;
+ List<MeasureModel> measures = defaultTimeMachine.query(projectKey + ":" + path, lastCommitsId, revisionsId, authorsId);
+ for (MeasureModel m : measures) {
+ if (m.getMetricId() == lastCommitsId) {
+ lastCommits = m.getData(CoreMetrics.SCM_LAST_COMMIT_DATETIMES_BY_LINE);
+ } else if (m.getMetricId() == revisionsId) {
+ revisions = m.getData(CoreMetrics.SCM_REVISIONS_BY_LINE);
+ }
+ if (m.getMetricId() == authorsId) {
+ authors = m.getData(CoreMetrics.SCM_AUTHORS_BY_LINE);
}
- ref.addFileData(projectKey, path, new FileData(hash, lastCommits, revisions, authors));
}
+ ref.fileDataPerPath().put(path, new FileData(hash, lastCommits, revisions, authors));
}
return ref;
}
-
- public Map<String, String> hashByRelativePath(String projectKey) {
- Map<String, String> map = Maps.newHashMap();
- Collection<SnapshotDataDto> selectSnapshotData = dao.selectSnapshotDataByComponentKey(
- projectKey,
- Arrays.asList(SnapshotDataTypes.FILE_HASHES)
- );
- if (!selectSnapshotData.isEmpty()) {
- SnapshotDataDto snapshotDataDto = selectSnapshotData.iterator().next();
- String data = snapshotDataDto.getData();
- map = KeyValueFormat.parse(data);
- }
- return map;
- }
-
- public List<Object[]> query(String resourceKey, String... metricKeys) {
- StringBuilder sb = new StringBuilder();
- Map<String, Object> params = Maps.newHashMap();
-
- sb.append("SELECT met.key, m");
- sb.append(" FROM ")
- .append(MeasureModel.class.getSimpleName())
- .append(" m, ")
- .append(Metric.class.getSimpleName())
- .append(" met, ")
- .append(ResourceModel.class.getSimpleName())
- .append(" r, ")
- .append(Snapshot.class.getSimpleName())
- .append(" s WHERE met.id=m.metricId AND m.snapshotId=s.id AND s.resourceId=r.id AND r.key=:kee AND s.status=:status AND s.qualifier<>:lib");
- params.put("kee", resourceKey);
- params.put("status", Snapshot.STATUS_PROCESSED);
- params.put("lib", Qualifiers.LIBRARY);
-
- sb.append(" AND m.characteristicId IS NULL");
- sb.append(" AND m.personId IS NULL");
- sb.append(" AND m.ruleId IS NULL AND m.rulePriority IS NULL");
- if (metricKeys.length > 0) {
- sb.append(" AND met.key IN (:metricKeys) ");
- params.put("metricKeys", Arrays.asList(metricKeys));
- }
- sb.append(" AND s.last=true ");
- sb.append(" ORDER BY s.createdAt ");
-
- Query jpaQuery = session.createQuery(sb.toString());
-
- for (Map.Entry<String, Object> entry : params.entrySet()) {
- jpaQuery.setParameter(entry.getKey(), entry.getValue());
- }
- return jpaQuery.getResultList();
- }
}
FileMetadata.Metadata metadata = FileMetadata.INSTANCE.read(inputFile.file(), fs.encoding());
inputFile.setLines(metadata.lines);
inputFile.setHash(metadata.hash);
- inputFile.setStatus(statusDetection.status(inputFile.moduleKey(), inputFile.relativePath(), metadata.hash));
+ inputFile.setStatus(statusDetection.status(inputFile.relativePath(), metadata.hash));
if (analysisMode.isIncremental() && inputFile.status() == InputFile.Status.SAME) {
return null;
}
this.projectReferentials = projectReferentials;
}
- InputFile.Status status(String projectKey, String relativePath, String hash) {
- FileData fileDataPerPath = projectReferentials.fileData(projectKey, relativePath);
+ InputFile.Status status(String relativePath, String hash) {
+ FileData fileDataPerPath = projectReferentials.fileDataPerPath(relativePath);
if (fileDataPerPath == null) {
return InputFile.Status.ADDED;
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.fs.FileSystem;
import org.sonar.api.batch.fs.InputFile;
import org.sonar.api.batch.fs.InputFile.Status;
private static final Pattern NON_ASCII_CHARS = Pattern.compile("[^\\x00-\\x7F]");
private static final Pattern ACCENT_CODES = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
- private final ProjectDefinition projectDefinition;
private final ScmActivityConfiguration configuration;
private final FileSystem fs;
private final ProjectReferentials projectReferentials;
- public ScmActivitySensor(ProjectDefinition projectDefinition, ScmActivityConfiguration configuration,
- ProjectReferentials projectReferentials, FileSystem fs) {
- this.projectDefinition = projectDefinition;
+ public ScmActivitySensor(ScmActivityConfiguration configuration, ProjectReferentials projectReferentials, FileSystem fs) {
this.configuration = configuration;
this.projectReferentials = projectReferentials;
this.fs = fs;
List<InputFile> filesToBlame = new LinkedList<InputFile>();
for (InputFile f : fs.inputFiles(fs.predicates().all())) {
- FileData fileData = projectReferentials.fileData(projectDefinition.getKeyWithBranch(), f.relativePath());
+ FileData fileData = projectReferentials.fileDataPerPath(f.relativePath());
if (f.status() == Status.SAME
&& fileData != null
&& fileData.scmAuthorsByLine() != null
import org.junit.Test;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.bootstrap.ProjectReactor;
-import org.sonar.api.database.DatabaseSession;
+import org.sonar.api.measures.Metric;
+import org.sonar.api.measures.MetricFinder;
+import org.sonar.batch.DefaultTimeMachine;
import org.sonar.batch.bootstrap.AnalysisMode;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.batch.bootstrap.TaskProperties;
import org.sonar.batch.rule.ModuleQProfiles;
-import org.sonar.core.source.db.SnapshotDataDao;
+import org.sonar.batch.scan.filesystem.PreviousFileHashLoader;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
public void prepare() {
serverClient = mock(ServerClient.class);
analysisMode = mock(AnalysisMode.class);
- loader = new DefaultProjectReferentialsLoader(mock(DatabaseSession.class), serverClient, analysisMode, mock(SnapshotDataDao.class));
+ MetricFinder metricFinder = mock(MetricFinder.class);
+ when(metricFinder.findByKey(anyString())).thenReturn(new Metric().setId(1));
+ loader = new DefaultProjectReferentialsLoader(serverClient, analysisMode, mock(PreviousFileHashLoader.class), metricFinder, mock(DefaultTimeMachine.class));
when(serverClient.request(anyString())).thenReturn("");
reactor = new ProjectReactor(ProjectDefinition.create().setKey("foo"));
taskProperties = new TaskProperties(Maps.<String, String>newHashMap(), "");
when(langDetection.language(any(InputFile.class))).thenReturn("java");
// status
- when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a"))
+ when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a"))
.thenReturn(InputFile.Status.ADDED);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
when(langDetection.language(any(InputFile.class))).thenReturn("java");
// status
- when(statusDetection.status("foo", "src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a"))
+ when(statusDetection.status("src/main/java/foo/Bar.java", "6c1d64c0b3555892fe7273e954f6fb5a"))
.thenReturn(InputFile.Status.ADDED);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
when(langDetection.language(any(InputFile.class))).thenReturn("php");
// status
- when(statusDetection.status("foo", "src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a"))
+ when(statusDetection.status("src/Bar.php", "6c1d64c0b3555892fe7273e954f6fb5a"))
.thenReturn(InputFile.Status.ADDED);
InputFileBuilder builder = new InputFileBuilder("struts", new PathResolver(),
@Test
public void detect_status() throws Exception {
ProjectReferentials ref = new ProjectReferentials();
- ref.addFileData("foo", "src/Foo.java", new FileData("ABCDE", null, null, null));
- ref.addFileData("foo", "src/Bar.java", new FileData("FGHIJ", null, null, null));
+ ref.fileDataPerPath().put("src/Foo.java", new FileData("ABCDE", null, null, null));
+ ref.fileDataPerPath().put("src/Bar.java", new FileData("FGHIJ", null, null, null));
StatusDetection statusDetection = new StatusDetection(ref);
- assertThat(statusDetection.status("foo", "src/Foo.java", "ABCDE")).isEqualTo(InputFile.Status.SAME);
- assertThat(statusDetection.status("foo", "src/Foo.java", "XXXXX")).isEqualTo(InputFile.Status.CHANGED);
- assertThat(statusDetection.status("foo", "src/Other.java", "QWERT")).isEqualTo(InputFile.Status.ADDED);
+ assertThat(statusDetection.status("src/Foo.java", "ABCDE")).isEqualTo(InputFile.Status.SAME);
+ assertThat(statusDetection.status("src/Foo.java", "XXXXX")).isEqualTo(InputFile.Status.CHANGED);
+ assertThat(statusDetection.status("src/Other.java", "QWERT")).isEqualTo(InputFile.Status.ADDED);
}
}