*/
package org.sonar.process;
+import java.util.Arrays;
import java.util.Collections;
import java.util.EnumMap;
-import java.util.HashSet;
+import java.util.EnumSet;
import java.util.Map;
import java.util.Set;
import javax.annotation.Nullable;
if (states.length == 1) {
return Collections.singleton(states[0]);
}
- Set<State> res = new HashSet<>(states.length);
- Collections.addAll(res, states);
- return res;
+ return EnumSet.copyOf(Arrays.asList(states));
}
private State state = INIT;
*/
package org.sonar.server.computation.filemove;
-import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Set;
import javax.annotation.CheckForNull;
-import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.log.Logger;
private static class ElectedMatches implements Iterable<Match> {
private final List<Match> matches;
private final Set<String> matchedFileKeys;
- private final Predicate<Match> notAlreadyMatched = new Predicate<Match>() {
- @Override
- public boolean apply(@Nonnull Match input) {
- return !(matchedFileKeys.contains(input.getDbKey()) || matchedFileKeys.contains(input.getReportKey()));
- }
- };
public ElectedMatches(MatchesByScore matchesByScore, Set<String> dbFileKeys, Map<String, File> reportFileSourcesByKey) {
this.matches = new ArrayList<>(matchesByScore.getSize());
}
public List<Match> filter(Iterable<Match> matches) {
- return from(matches).filter(notAlreadyMatched).toList();
+ return from(matches).filter(this::notAlreadyMatched).toList();
+ }
+
+ private boolean notAlreadyMatched(Match input) {
+ return !(matchedFileKeys.contains(input.getDbKey()) || matchedFileKeys.contains(input.getReportKey()));
}
@Override
public interface SourceSimilarity {
- // TODO verify algorithm http://stackoverflow.com/questions/6087281/similarity-score-levenshtein
- // the higher the more similar. Order is not important (TODO to be verified). 100% = same source.
- // Range: between 0 and 100 (TODO to be verified)
+ /**
+ * the higher the more similar. Order is not important (TODO to be verified). 100% = same source.
+ * Range: between 0 and 100
+ */
<T extends Object> int score(List<T> left, List<T> right);
}
// transformation cost for each letter in s0
for (int i = 1; i < len0; i++) {
// matching current letters in both strings
- int match = (left.get(i - 1).equals(right.get(j - 1))) ? 0 : 1;
+ int match = left.get(i - 1).equals(right.get(j - 1)) ? 0 : 1;
// computing cost for each transformation
int costReplace = cost[i - 1] + match;
package org.sonar.server.computation.step;
import com.google.common.base.Strings;
-import java.util.Calendar;
+import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import javax.annotation.CheckForNull;
}
private static String formatDate(long date) {
- return DateUtils.formatDate(org.apache.commons.lang.time.DateUtils.truncate(new Date(date), Calendar.SECOND));
+ return DateUtils.formatDate(Date.from(new Date(date).toInstant().truncatedTo(ChronoUnit.SECONDS)));
}
private static String getPropertyValue(@Nullable String qualifier, Settings settings, int index) {
*/
package org.sonar.server.plugins;
-import org.sonar.api.SonarQubeVersion;
+import org.sonar.api.SonarRuntime;
import org.sonar.api.server.ServerSide;
import org.sonar.core.platform.PluginRepository;
@ServerSide
public class WebServerExtensionInstaller extends ServerExtensionInstaller {
- public WebServerExtensionInstaller(SonarQubeVersion sonarQubeVersion, PluginRepository pluginRepository) {
- super(sonarQubeVersion, pluginRepository, ServerSide.class);
+ public WebServerExtensionInstaller(SonarRuntime sonarRuntime, PluginRepository pluginRepository) {
+ super(sonarRuntime, pluginRepository, ServerSide.class);
}
}
import java.util.List;
+@FunctionalInterface
public interface ContainerPopulator<T extends ContainerPopulator.Container> {
void populateContainer(T container);
@VisibleForTesting
protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
- List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
}
public void purgeAnalyses(List<IdUuidPair> analysisUuids) {
- List<List<Long>> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
" where e.snapshot_id is not null and e.analysis_uuid is null");
massUpdate.update("UPDATE events SET analysis_uuid=? WHERE snapshot_id=? and analysis_uuid is null");
massUpdate.rowPluralName("analysis uuid of root component events");
- massUpdate.execute(this::handle);
+ massUpdate.execute(PopulateAnalysisUuidOnEvents::handle);
}
- private boolean handle(Select.Row row, SqlStatement update) throws SQLException {
+ private static boolean handle(Select.Row row, SqlStatement update) throws SQLException {
long snapshotId = row.getLong(1);
String snapshotUuid = row.getString(2);
massUpdate.select("SELECT sn.id, sn.project_id, sn.root_project_id from snapshots sn where sn.component_uuid is null or sn.root_component_uuid is null");
massUpdate.update("UPDATE snapshots SET component_uuid=?, root_component_uuid=? WHERE id=?");
massUpdate.rowPluralName("snapshots");
- massUpdate.execute((row, update) -> this.handle(componentUuidById, row, update));
+ massUpdate.execute((row, update) -> handle(componentUuidById, row, update));
}
- private boolean handle(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
+ private static boolean handle(Map<Long, String> componentUuidById, Select.Row row, SqlStatement update) throws SQLException {
long id = row.getLong(1);
long componentId = row.getLong(2);
long rootProjectId = row.getLong(3);