Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-10257 Generate SCM Info for changed lines
- Loading branch information
Showing
15 changed files
with
927 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...src/main/java/org/sonar/server/computation/task/projectanalysis/scm/GeneratedScmInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,82 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2018 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.computation.task.projectanalysis.scm; | |||
|
|||
import java.util.Map; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
|
|||
import static com.google.common.base.Preconditions.checkState; | |||
|
|||
public class GeneratedScmInfo implements ScmInfo { | |||
private final ScmInfoImpl delegate; | |||
|
|||
public GeneratedScmInfo(Map<Integer, Changeset> changesets) { | |||
delegate = new ScmInfoImpl(changesets); | |||
} | |||
|
|||
public static ScmInfo create(long analysisDate, Set<Integer> lines) { | |||
checkState(!lines.isEmpty(), "No changesets"); | |||
|
|||
Changeset changeset = Changeset.newChangesetBuilder() | |||
.setDate(analysisDate) | |||
.build(); | |||
Map<Integer, Changeset> changesets = lines.stream() | |||
.collect(Collectors.toMap(x -> x, i -> changeset)); | |||
return new GeneratedScmInfo(changesets); | |||
} | |||
|
|||
public static ScmInfo create(long analysisDate, Set<Integer> lines, ScmInfo dbScmInfo) { | |||
checkState(!lines.isEmpty(), "No changesets"); | |||
|
|||
Changeset changeset = Changeset.newChangesetBuilder() | |||
.setDate(analysisDate) | |||
.build(); | |||
Map<Integer, Changeset> changesets = lines.stream() | |||
.collect(Collectors.toMap(x -> x, i -> changeset)); | |||
|
|||
dbScmInfo.getAllChangesets().entrySet().stream() | |||
.filter(e -> !lines.contains(e.getKey())) | |||
.forEach(e -> changesets.put(e.getKey(), e.getValue())); | |||
|
|||
return new GeneratedScmInfo(changesets); | |||
} | |||
|
|||
@Override | |||
public Changeset getLatestChangeset() { | |||
return delegate.getLatestChangeset(); | |||
} | |||
|
|||
@Override | |||
public Changeset getChangesetForLine(int lineNumber) { | |||
return delegate.getChangesetForLine(lineNumber); | |||
} | |||
|
|||
@Override | |||
public boolean hasChangesetForLine(int lineNumber) { | |||
return delegate.hasChangesetForLine(lineNumber); | |||
} | |||
|
|||
@Override | |||
public Map<Integer, Changeset> getAllChangesets() { | |||
return delegate.getAllChangesets(); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.