@@ -20,10 +20,10 @@ | |||
package org.sonar.server.batch; | |||
public class Messages { | |||
public static final String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."; | |||
private Messages() { | |||
// constants | |||
} | |||
public static final String NO_PERMISSION = "You're not authorized to execute any SonarQube analysis. Please contact your SonarQube administrator."; | |||
} |
@@ -192,12 +192,12 @@ public class AppAction implements RequestHandler { | |||
} | |||
@CheckForNull | |||
private String formatMeasure(Map<String, MeasureDto> measuresByMetricKey, Metric metric) { | |||
private static String formatMeasure(Map<String, MeasureDto> measuresByMetricKey, Metric metric) { | |||
MeasureDto measure = measuresByMetricKey.get(metric.getKey()); | |||
return formatMeasure(measure, metric); | |||
} | |||
private String formatMeasure(@Nullable MeasureDto measure, Metric metric) { | |||
private static String formatMeasure(@Nullable MeasureDto measure, Metric metric) { | |||
if (measure == null) { | |||
return null; | |||
} |
@@ -48,6 +48,17 @@ import static com.google.common.collect.FluentIterable.from; | |||
*/ | |||
public class NewEffortCalculator { | |||
/** | |||
* Changelog have to be sorted from newest to oldest. | |||
* Null date should be the first as this happen when technical debt has changed since previous analysis. | |||
*/ | |||
private static final Comparator<FieldDiffs> CHANGE_ORDERING = Ordering.natural().reverse().nullsFirst().onResultOf(new Function<FieldDiffs, Date>() { | |||
@Override | |||
public Date apply(@Nonnull FieldDiffs dto) { | |||
return dto.creationDate(); | |||
} | |||
}); | |||
public long calculate(DefaultIssue issue, Collection<IssueChangeDto> debtChangelog, Period period) { | |||
if (issue.creationDate().getTime() > period.getSnapshotDate() + 1000L) { | |||
return MoreObjects.firstNonNull(issue.effortInMinutes(), 0L); | |||
@@ -100,17 +111,6 @@ public class NewEffortCalculator { | |||
return diffs.diffs().get(IssueUpdater.TECHNICAL_DEBT); | |||
} | |||
/** | |||
* Changelog have to be sorted from newest to oldest. | |||
* Null date should be the first as this happen when technical debt has changed since previous analysis. | |||
*/ | |||
private static final Comparator<FieldDiffs> CHANGE_ORDERING = Ordering.natural().reverse().nullsFirst().onResultOf(new Function<FieldDiffs, Date>() { | |||
@Override | |||
public Date apply(@Nonnull FieldDiffs dto) { | |||
return dto.creationDate(); | |||
} | |||
}); | |||
private enum ToFieldDiffs implements Function<IssueChangeDto, FieldDiffs> { | |||
INSTANCE; | |||
@Override |
@@ -82,7 +82,7 @@ public abstract class BaseIndexer implements Startable { | |||
} | |||
public void index() { | |||
index(lastUpdatedAtParam -> doIndex(lastUpdatedAtParam)); | |||
index(this::doIndex); | |||
} | |||
protected abstract long doIndex(long lastUpdatedAt); |
@@ -42,10 +42,51 @@ public class NewIndex { | |||
public static final int DEFAULT_NUMBER_OF_SHARDS = 5; | |||
private final String indexName; | |||
private final Settings.Builder settings = DefaultIndexSettings.defaults(); | |||
private final Map<String, NewIndexType> types = new LinkedHashMap<>(); | |||
NewIndex(String indexName) { | |||
Preconditions.checkArgument(StringUtils.isAllLowerCase(indexName), "Index name must be lower-case: " + indexName); | |||
this.indexName = indexName; | |||
} | |||
public void refreshHandledByIndexer() { | |||
getSettings().put("index.refresh_interval", "-1"); | |||
} | |||
public String getName() { | |||
return indexName; | |||
} | |||
public Settings.Builder getSettings() { | |||
return settings; | |||
} | |||
public NewIndexType createType(String typeName) { | |||
NewIndexType type = new NewIndexType(typeName); | |||
types.put(typeName, type); | |||
return type; | |||
} | |||
public Map<String, NewIndexType> getTypes() { | |||
return types; | |||
} | |||
public void configureShards(org.sonar.api.config.Settings settings) { | |||
boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE); | |||
int shards = settings.getInt(format("sonar.search.%s.shards", indexName)); | |||
if (shards == 0) { | |||
shards = DEFAULT_NUMBER_OF_SHARDS; | |||
} | |||
int replicas = settings.getInt(format("sonar.search.%s.replicas", indexName)); | |||
if (replicas == 0) { | |||
replicas = clusterMode ? 1 : 0; | |||
} | |||
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards); | |||
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas); | |||
} | |||
public static class NewIndexType { | |||
private final String name; | |||
private final Map<String, Object> attributes = new TreeMap<>(); | |||
@@ -268,44 +309,5 @@ public class NewIndex { | |||
} | |||
} | |||
private final String indexName; | |||
private final Settings.Builder settings = DefaultIndexSettings.defaults(); | |||
private final Map<String, NewIndexType> types = new LinkedHashMap<>(); | |||
NewIndex(String indexName) { | |||
Preconditions.checkArgument(StringUtils.isAllLowerCase(indexName), "Index name must be lower-case: " + indexName); | |||
this.indexName = indexName; | |||
} | |||
public String getName() { | |||
return indexName; | |||
} | |||
public Settings.Builder getSettings() { | |||
return settings; | |||
} | |||
public NewIndexType createType(String typeName) { | |||
NewIndexType type = new NewIndexType(typeName); | |||
types.put(typeName, type); | |||
return type; | |||
} | |||
public Map<String, NewIndexType> getTypes() { | |||
return types; | |||
} | |||
public void configureShards(org.sonar.api.config.Settings settings) { | |||
boolean clusterMode = settings.getBoolean(ProcessProperties.CLUSTER_ACTIVATE); | |||
int shards = settings.getInt(format("sonar.search.%s.shards", indexName)); | |||
if (shards == 0) { | |||
shards = DEFAULT_NUMBER_OF_SHARDS; | |||
} | |||
int replicas = settings.getInt(format("sonar.search.%s.replicas", indexName)); | |||
if (replicas == 0) { | |||
replicas = clusterMode ? 1 : 0; | |||
} | |||
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, shards); | |||
getSettings().put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, replicas); | |||
} | |||
} |
@@ -102,7 +102,7 @@ public class SearchOptions { | |||
*/ | |||
@Deprecated | |||
public SearchOptions disableLimit() { | |||
this.limit = 999999; | |||
this.limit = 999_999; | |||
return this; | |||
} | |||
@@ -44,21 +44,19 @@ public enum SearchAdditionalField { | |||
public static final String ALL_ALIAS = "_all"; | |||
static final EnumSet<SearchAdditionalField> ALL_ADDITIONAL_FIELDS = EnumSet.allOf(SearchAdditionalField.class); | |||
private final String label; | |||
SearchAdditionalField(String label) { | |||
this.label = label; | |||
} | |||
private static final Map<String, SearchAdditionalField> BY_LABELS = new HashMap<>(); | |||
static { | |||
for (SearchAdditionalField f : values()) { | |||
BY_LABELS.put(f.label, f); | |||
} | |||
} | |||
private final String label; | |||
SearchAdditionalField(String label) { | |||
this.label = label; | |||
} | |||
@CheckForNull | |||
public static SearchAdditionalField findByLabel(String label) { | |||
return BY_LABELS.get(label); |
@@ -93,16 +93,6 @@ public class Views { | |||
return widgetsPerId.get(id); | |||
} | |||
public List<ViewProxy<Widget>> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage, String[] availableMeasures) { | |||
List<ViewProxy<Widget>> result = Lists.newArrayList(); | |||
for (ViewProxy<Widget> proxy : widgets) { | |||
if (accept(proxy, null, resourceScope, resourceQualifier, resourceLanguage)) { | |||
result.add(proxy); | |||
} | |||
} | |||
return result; | |||
} | |||
public List<ViewProxy<Widget>> getWidgets() { | |||
return Lists.newArrayList(widgets); | |||
} |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.updatecenter; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -57,6 +57,17 @@ import static org.elasticsearch.index.query.QueryBuilders.termsQuery; | |||
@ComputeEngineSide | |||
public class UserIndex { | |||
/** | |||
* Convert an Elasticsearch result (a map) to an {@link UserDoc}. It's | |||
* used for {@link org.sonar.server.es.SearchResult}. | |||
*/ | |||
private static final Function<Map<String, Object>, UserDoc> DOC_CONVERTER = new NonNullInputFunction<Map<String, Object>, UserDoc>() { | |||
@Override | |||
protected UserDoc doApply(Map<String, Object> input) { | |||
return new UserDoc(input); | |||
} | |||
}; | |||
private final EsClient esClient; | |||
public UserIndex(EsClient esClient) { | |||
@@ -146,14 +157,4 @@ public class UserIndex { | |||
return new SearchResult<>(request.get(), DOC_CONVERTER); | |||
} | |||
/** | |||
* Convert an Elasticsearch result (a map) to an {@link UserDoc}. It's | |||
* used for {@link org.sonar.server.es.SearchResult}. | |||
*/ | |||
private static final Function<Map<String, Object>, UserDoc> DOC_CONVERTER = new NonNullInputFunction<Map<String, Object>, UserDoc>() { | |||
@Override | |||
protected UserDoc doApply(Map<String, Object> input) { | |||
return new UserDoc(input); | |||
} | |||
}; | |||
} |
@@ -0,0 +1,58 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class DisabledComponentsHolderImplTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
DisabledComponentsHolderImpl underTest = new DisabledComponentsHolderImpl(); | |||
@Test | |||
public void set_and_get_uuids() { | |||
underTest.setUuids(asList("U1", "U2")); | |||
assertThat(underTest.getUuids()).containsExactly("U1", "U2"); | |||
} | |||
@Test | |||
public void setUuids_fails_if_called_twice() { | |||
underTest.setUuids(asList("U1", "U2")); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("UUIDs have already been set in repository"); | |||
underTest.setUuids(asList("U1", "U2")); | |||
} | |||
@Test | |||
public void getUuids_fails_if_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("UUIDs have not been set in repository"); | |||
underTest.getUuids(); | |||
} | |||
} |
@@ -46,6 +46,7 @@ import static org.sonar.process.ProcessProperties.PATH_WEB; | |||
public class AppFileSystem implements FileSystem { | |||
private static final Logger LOG = LoggerFactory.getLogger(AppFileSystem.class); | |||
private static final EnumSet<FileVisitOption> FOLLOW_LINKS = EnumSet.of(FileVisitOption.FOLLOW_LINKS); | |||
private static final String DEFAULT_DATA_DIRECTORY_NAME = "data"; | |||
private static final String DEFAULT_WEB_DIRECTORY_NAME = "web"; | |||
private static final String DEFAULT_LOGS_DIRECTORY_NAME = "logs"; | |||
@@ -118,8 +119,6 @@ public class AppFileSystem implements FileSystem { | |||
} | |||
} | |||
private static final EnumSet<FileVisitOption> FOLLOW_LINKS = EnumSet.of(FileVisitOption.FOLLOW_LINKS); | |||
private static void createOrCleanTempDirectory(Props props, String propKey) throws IOException { | |||
File dir = props.nonNullValueAsFile(propKey); | |||
LOG.info("Cleaning or creating temp directory {}", dir.getAbsolutePath()); |
@@ -26,7 +26,6 @@ import java.util.Collection; | |||
import java.util.IdentityHashMap; | |||
import java.util.Map; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nonnull; | |||
public class Tracking<RAW extends Trackable, BASE extends Trackable> { | |||
@@ -39,19 +38,9 @@ public class Tracking<RAW extends Trackable, BASE extends Trackable> { | |||
private final Collection<RAW> raws; | |||
private final Collection<BASE> bases; | |||
private final Predicate<RAW> unmatchedRawPredicate = new Predicate<RAW>() { | |||
@Override | |||
public boolean apply(@Nonnull RAW raw) { | |||
return !rawToBase.containsKey(raw); | |||
} | |||
}; | |||
private final Predicate<RAW> unmatchedRawPredicate = raw -> !rawToBase.containsKey(raw); | |||
private final Predicate<BASE> unmatchedBasePredicate = new Predicate<BASE>() { | |||
@Override | |||
public boolean apply(@Nonnull BASE raw) { | |||
return !baseToRaw.containsKey(raw); | |||
} | |||
}; | |||
private final Predicate<BASE> unmatchedBasePredicate = raw -> !baseToRaw.containsKey(raw); | |||
public Tracking(Input<RAW> rawInput, Input<BASE> baseInput) { | |||
this.raws = rawInput.getIssues(); |
@@ -0,0 +1,24 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2016 SonarSource SA | |||
* mailto:contact 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. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.core.util.stream; | |||
import javax.annotation.ParametersAreNonnullByDefault; | |||
@@ -23,7 +23,6 @@ import com.google.common.base.Predicate; | |||
import com.google.common.collect.Iterators; | |||
import java.util.NoSuchElementException; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.utils.MessageException; | |||
@@ -45,22 +44,12 @@ public final class DialectUtils { | |||
@CheckForNull | |||
private static Dialect findByJdbcUrl(final String jdbcConnectionUrl) { | |||
return findDialect(new Predicate<Dialect>() { | |||
@Override | |||
public boolean apply(@Nullable Dialect dialect) { | |||
return dialect != null && dialect.matchesJdbcURL(StringUtils.trimToEmpty(jdbcConnectionUrl)); | |||
} | |||
}); | |||
return findDialect(dialect -> dialect != null && dialect.matchesJdbcURL(StringUtils.trimToEmpty(jdbcConnectionUrl))); | |||
} | |||
@CheckForNull | |||
private static Dialect findById(final String dialectId) { | |||
return findDialect(new Predicate<Dialect>() { | |||
@Override | |||
public boolean apply(@Nullable Dialect dialect) { | |||
return dialect != null && dialect.getId().equals(dialectId); | |||
} | |||
}); | |||
return findDialect(dialect -> dialect != null && dialect.getId().equals(dialectId)); | |||
} | |||
@CheckForNull |
@@ -22,7 +22,6 @@ package org.sonar.db.purge; | |||
import com.google.common.annotations.VisibleForTesting; | |||
import java.util.ArrayList; | |||
import java.util.Collections; | |||
import java.util.Comparator; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
@@ -67,12 +66,7 @@ public class PurgeProfiler { | |||
public void dump(long totalTime, Logger logger) { | |||
List<Entry<String, Long>> data = new ArrayList<>(durations.entrySet()); | |||
Collections.sort(data, new Comparator<Entry<String, Long>>() { | |||
@Override | |||
public int compare(Entry<String, Long> o1, Entry<String, Long> o2) { | |||
return o2.getValue().compareTo(o1.getValue()); | |||
} | |||
}); | |||
Collections.sort(data, (o1, o2) -> o2.getValue().compareTo(o1.getValue())); | |||
double percent = totalTime / 100.0; | |||
for (Entry<String, Long> entry : truncateList(data)) { | |||
StringBuilder sb = new StringBuilder(); |
@@ -25,8 +25,6 @@ import org.apache.commons.lang.StringUtils; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.version.BaseDataChange; | |||
import org.sonar.db.version.MassUpdate; | |||
import org.sonar.db.version.Select; | |||
import org.sonar.db.version.SqlStatement; | |||
/** | |||
* See http://jira.sonarsource.com/browse/SONAR-5758 | |||
@@ -44,16 +42,13 @@ public class DeleteUnescapedActivities extends BaseDataChange { | |||
MassUpdate massUpdate = context.prepareMassUpdate(); | |||
massUpdate.select("select id,data_field from activities where log_type='QPROFILE'"); | |||
massUpdate.update("delete from activities where id=?"); | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Select.Row row, SqlStatement update) throws SQLException { | |||
String csv = row.getNullableString(2); | |||
if (isUnescaped(csv)) { | |||
update.setLong(1, row.getNullableLong(1)); | |||
return true; | |||
} | |||
return false; | |||
massUpdate.execute((row, update) -> { | |||
String csv = row.getNullableString(2); | |||
if (isUnescaped(csv)) { | |||
update.setLong(1, row.getNullableLong(1)); | |||
return true; | |||
} | |||
return false; | |||
}); | |||
} | |||
@@ -238,12 +238,9 @@ public class FeedFileSources extends BaseDataChange { | |||
@Override | |||
public void execute(Context context) throws SQLException { | |||
RowReader<Long> simpleLongReader = new RowReader<Long>() { | |||
@Override | |||
public Long read(Row row) throws SQLException { | |||
Long longValue = row.getNullableLong(1); | |||
return longValue == null ? Long.valueOf(0L) : longValue; | |||
} | |||
RowReader<Long> simpleLongReader = row -> { | |||
Long longValue = row.getNullableLong(1); | |||
return longValue == null ? Long.valueOf(0L) : longValue; | |||
}; | |||
Long revisionMetricId = context.prepareSelect("SELECT id FROM metrics WHERE name = 'revisions_by_line'").get(simpleLongReader); | |||
Long authorMetricId = context.prepareSelect("SELECT id FROM metrics WHERE name = 'authors_by_line'").get(simpleLongReader); | |||
@@ -287,6 +284,6 @@ public class FeedFileSources extends BaseDataChange { | |||
} | |||
private static long zeroIfNull(@Nullable Long value) { | |||
return value == null ? 0L : value.longValue(); | |||
return value == null ? 0L : value; | |||
} | |||
} |
@@ -25,8 +25,6 @@ import org.sonar.api.utils.System2; | |||
import org.sonar.db.Database; | |||
import org.sonar.db.version.BaseDataChange; | |||
import org.sonar.db.version.MassUpdate; | |||
import org.sonar.db.version.Select; | |||
import org.sonar.db.version.SqlStatement; | |||
public class FeedIssueLongDates extends BaseDataChange { | |||
@@ -45,26 +43,23 @@ public class FeedIssueLongDates extends BaseDataChange { | |||
massUpdate.select("SELECT i.id, i.created_at, i.updated_at FROM issues i WHERE created_at_ms IS NULL"); | |||
massUpdate.update("UPDATE issues SET created_at_ms=?, updated_at_ms=? WHERE id=?"); | |||
massUpdate.rowPluralName("issues"); | |||
massUpdate.execute(new MassUpdate.Handler() { | |||
@Override | |||
public boolean handle(Select.Row row, SqlStatement update) throws SQLException { | |||
Long id = row.getNullableLong(1); | |||
Date createdAt = row.getNullableDate(2); | |||
Date updatedAt = row.getNullableDate(3); | |||
massUpdate.execute((row, update) -> { | |||
Long id = row.getNullableLong(1); | |||
Date createdAt = row.getNullableDate(2); | |||
Date updatedAt = row.getNullableDate(3); | |||
if (createdAt == null) { | |||
update.setLong(1, now); | |||
} else { | |||
update.setLong(1, Math.min(now, createdAt.getTime())); | |||
} | |||
if (updatedAt == null) { | |||
update.setLong(2, now); | |||
} else { | |||
update.setLong(2, Math.min(now, updatedAt.getTime())); | |||
} | |||
update.setLong(3, id); | |||
return true; | |||
if (createdAt == null) { | |||
update.setLong(1, now); | |||
} else { | |||
update.setLong(1, Math.min(now, createdAt.getTime())); | |||
} | |||
if (updatedAt == null) { | |||
update.setLong(2, now); | |||
} else { | |||
update.setLong(2, Math.min(now, updatedAt.getTime())); | |||
} | |||
update.setLong(3, id); | |||
return true; | |||
}); | |||
} | |||
@@ -36,12 +36,7 @@ public final class Search { | |||
private final List<Integer> list = new ArrayList<>(); | |||
private final List<Node> innerNodes = new ArrayList<>(); | |||
private static final Comparator<Node> DEPTH_COMPARATOR = new Comparator<Node>() { | |||
@Override | |||
public int compare(Node o1, Node o2) { | |||
return o2.depth - o1.depth; | |||
} | |||
}; | |||
private static final Comparator<Node> DEPTH_COMPARATOR = (o1, o2) -> o2.depth - o1.depth; | |||
private Search(SuffixTree tree, TextSet text, Collector reporter) { | |||
this.tree = tree; |
@@ -35,16 +35,12 @@ import org.sonar.duplications.index.CloneIndex; | |||
public final class SuffixTreeCloneDetectionAlgorithm { | |||
private static final Comparator<Block> BLOCK_COMPARATOR = (o1, o2) -> o1.getIndexInFile() - o2.getIndexInFile(); | |||
private SuffixTreeCloneDetectionAlgorithm() { | |||
// only statics | |||
} | |||
private static final Comparator<Block> BLOCK_COMPARATOR = new Comparator<Block>() { | |||
@Override | |||
public int compare(Block o1, Block o2) { | |||
return o1.getIndexInFile() - o2.getIndexInFile(); | |||
} | |||
}; | |||
public static List<CloneGroup> detect(CloneIndex cloneIndex, Collection<Block> fileBlocks) { | |||
if (fileBlocks.isEmpty()) { | |||
return Collections.emptyList(); |
@@ -37,12 +37,12 @@ import java.nio.charset.StandardCharsets; | |||
import java.security.Key; | |||
import java.security.SecureRandom; | |||
final class AesCipher extends Cipher { | |||
final class AesCipher implements Cipher { | |||
// Can't be increased because of Java 6 policy files : | |||
// https://confluence.terena.org/display/~visser/No+256+bit+ciphers+for+Java+apps | |||
// http://java.sun.com/javase/6/webnotes/install/jre/README | |||
public static final int KEY_SIZE_IN_BITS = 128; | |||
static final int KEY_SIZE_IN_BITS = 128; | |||
private static final String CRYPTO_KEY = "AES"; | |||
@@ -53,18 +53,18 @@ final class AesCipher extends Cipher { | |||
} | |||
@Override | |||
String encrypt(String clearText) { | |||
public String encrypt(String clearText) { | |||
try { | |||
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); | |||
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, loadSecretFile()); | |||
return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes("UTF-8"))); | |||
return Base64.encodeBase64String(cipher.doFinal(clearText.getBytes(StandardCharsets.UTF_8.name()))); | |||
} catch (Exception e) { | |||
throw Throwables.propagate(e); | |||
} | |||
} | |||
@Override | |||
String decrypt(String encryptedText) { | |||
public String decrypt(String encryptedText) { | |||
try { | |||
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY); | |||
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile()); |
@@ -23,14 +23,14 @@ import org.apache.commons.codec.binary.Base64; | |||
import java.nio.charset.StandardCharsets; | |||
final class Base64Cipher extends Cipher { | |||
final class Base64Cipher implements Cipher { | |||
@Override | |||
String encrypt(String clearText) { | |||
public String encrypt(String clearText) { | |||
return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8)); | |||
} | |||
@Override | |||
String decrypt(String encryptedText) { | |||
public String decrypt(String encryptedText) { | |||
return new String(Base64.decodeBase64(encryptedText), StandardCharsets.UTF_8); | |||
} | |||
} |
@@ -19,7 +19,7 @@ | |||
*/ | |||
package org.sonar.api.config; | |||
abstract class Cipher { | |||
abstract String encrypt(String clearText); | |||
abstract String decrypt(String encryptedText); | |||
interface Cipher { | |||
String encrypt(String clearText); | |||
String decrypt(String encryptedText); | |||
} |
@@ -29,10 +29,6 @@ import org.apache.commons.lang.StringUtils; | |||
*/ | |||
public final class Qualifiers { | |||
private Qualifiers() { | |||
// only static methods | |||
} | |||
/** | |||
* Root views. Scope of views is Scopes.PROJECT | |||
*/ | |||
@@ -69,6 +65,10 @@ public final class Qualifiers { | |||
// ugly, should be replaced by "natures" | |||
public static final String UNIT_TEST_FILE = "UTS"; | |||
private Qualifiers() { | |||
// only static methods | |||
} | |||
/** | |||
* @param resource not nullable | |||
*/ |
@@ -53,98 +53,6 @@ import java.util.Map; | |||
@Immutable | |||
public class ResourceType { | |||
/** | |||
* Builder used to create {@link ResourceType} objects. | |||
*/ | |||
public static class Builder { | |||
private static final String SUPPORTS_MEASURE_FILTERS = "supportsMeasureFilters"; | |||
private String qualifier; | |||
private String iconPath; | |||
private boolean hasSourceCode = false; | |||
private final Map<String, String> properties = Maps.newHashMap(); | |||
/** | |||
* Creates a new {@link Builder} | |||
* | |||
* @param qualifier | |||
*/ | |||
public Builder(String qualifier) { | |||
this.qualifier = qualifier; | |||
} | |||
/** | |||
* Relative path of the icon used to represent the resource type. | |||
* | |||
* @param iconPath path to icon, relative to context of web-application (e.g. "/images/q/DIR.png") | |||
*/ | |||
public Builder setIconPath(@Nullable String iconPath) { | |||
this.iconPath = iconPath; | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 3.0. Use {@link #setProperty(String, String)} with "supportsMeasureFilters" set to "true". | |||
*/ | |||
@Deprecated | |||
public Builder availableForFilters() { | |||
setProperty(SUPPORTS_MEASURE_FILTERS, "true"); | |||
return this; | |||
} | |||
/** | |||
* Tells that the resources of this type will have source code. | |||
*/ | |||
public Builder hasSourceCode() { | |||
this.hasSourceCode = true; | |||
return this; | |||
} | |||
/** | |||
* Sets a property on the resource type. See the description of {@link ResourceType} class for more information. | |||
* | |||
* @since 3.0 | |||
*/ | |||
public Builder setProperty(String key, String value) { | |||
Preconditions.checkNotNull(key); | |||
Preconditions.checkNotNull(value); | |||
properties.put(key, value); | |||
// for backward-compatibility since version 3.4 | |||
if ("availableForFilters".equals(key)) { | |||
properties.put(SUPPORTS_MEASURE_FILTERS, value); | |||
} | |||
return this; | |||
} | |||
/** | |||
* @since 3.2 | |||
*/ | |||
public Builder setProperty(String key, boolean value) { | |||
return setProperty(key, String.valueOf(value)); | |||
} | |||
/** | |||
* Creates an instance of {@link ResourceType} based on all information given to the builder. | |||
*/ | |||
public ResourceType build() { | |||
if (Strings.isNullOrEmpty(iconPath)) { | |||
iconPath = "/images/q/" + qualifier + ".png"; | |||
} | |||
return new ResourceType(this); | |||
} | |||
} | |||
/** | |||
* Creates a new {@link Builder} | |||
* | |||
* @param qualifier | |||
*/ | |||
public static Builder builder(String qualifier) { | |||
Preconditions.checkNotNull(qualifier); | |||
Preconditions.checkArgument(qualifier.length() <= 10, "Qualifier is limited to 10 characters"); | |||
return new Builder(qualifier); | |||
} | |||
private final String qualifier; | |||
private final String iconPath; | |||
private final boolean hasSourceCode; | |||
@@ -234,4 +142,92 @@ public class ResourceType { | |||
public String toString() { | |||
return qualifier; | |||
} | |||
/** | |||
* Creates a new {@link Builder} | |||
*/ | |||
public static Builder builder(String qualifier) { | |||
Preconditions.checkNotNull(qualifier); | |||
Preconditions.checkArgument(qualifier.length() <= 10, "Qualifier is limited to 10 characters"); | |||
return new Builder(qualifier); | |||
} | |||
/** | |||
* Builder used to create {@link ResourceType} objects. | |||
*/ | |||
public static class Builder { | |||
private static final String SUPPORTS_MEASURE_FILTERS = "supportsMeasureFilters"; | |||
private String qualifier; | |||
private String iconPath; | |||
private boolean hasSourceCode = false; | |||
private final Map<String, String> properties = Maps.newHashMap(); | |||
/** | |||
* Creates a new {@link Builder} | |||
*/ | |||
public Builder(String qualifier) { | |||
this.qualifier = qualifier; | |||
} | |||
/** | |||
* Relative path of the icon used to represent the resource type. | |||
* | |||
* @param iconPath path to icon, relative to context of web-application (e.g. "/images/q/DIR.png") | |||
*/ | |||
public Builder setIconPath(@Nullable String iconPath) { | |||
this.iconPath = iconPath; | |||
return this; | |||
} | |||
/** | |||
* @deprecated since 3.0. Use {@link #setProperty(String, String)} with "supportsMeasureFilters" set to "true". | |||
*/ | |||
@Deprecated | |||
public Builder availableForFilters() { | |||
setProperty(SUPPORTS_MEASURE_FILTERS, "true"); | |||
return this; | |||
} | |||
/** | |||
* Tells that the resources of this type will have source code. | |||
*/ | |||
public Builder hasSourceCode() { | |||
this.hasSourceCode = true; | |||
return this; | |||
} | |||
/** | |||
* Sets a property on the resource type. See the description of {@link ResourceType} class for more information. | |||
* | |||
* @since 3.0 | |||
*/ | |||
public Builder setProperty(String key, String value) { | |||
Preconditions.checkNotNull(key); | |||
Preconditions.checkNotNull(value); | |||
properties.put(key, value); | |||
// for backward-compatibility since version 3.4 | |||
if ("availableForFilters".equals(key)) { | |||
properties.put(SUPPORTS_MEASURE_FILTERS, value); | |||
} | |||
return this; | |||
} | |||
/** | |||
* @since 3.2 | |||
*/ | |||
public Builder setProperty(String key, boolean value) { | |||
return setProperty(key, String.valueOf(value)); | |||
} | |||
/** | |||
* Creates an instance of {@link ResourceType} based on all information given to the builder. | |||
*/ | |||
public ResourceType build() { | |||
if (Strings.isNullOrEmpty(iconPath)) { | |||
iconPath = "/images/q/" + qualifier + ".png"; | |||
} | |||
return new ResourceType(this); | |||
} | |||
} | |||
} |
@@ -20,7 +20,6 @@ | |||
package org.sonar.api.resources; | |||
import com.google.common.annotations.Beta; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Preconditions; | |||
import com.google.common.base.Predicate; | |||
import com.google.common.collect.Collections2; | |||
@@ -192,12 +191,7 @@ public class ResourceTypes { | |||
} | |||
public List<ResourceType> getChildren(String qualifier) { | |||
return Lists.transform(getChildrenQualifiers(qualifier), new Function<String, ResourceType>() { | |||
@Override | |||
public ResourceType apply(String s) { | |||
return typeByQualifier.get(s); | |||
} | |||
}); | |||
return Lists.transform(getChildrenQualifiers(qualifier), typeByQualifier::get); | |||
} | |||
public List<String> getLeavesQualifiers(String qualifier) { |
@@ -34,10 +34,6 @@ import org.apache.commons.lang.StringUtils; | |||
*/ | |||
public final class Scopes { | |||
private Scopes() { | |||
// only static methods | |||
} | |||
/** | |||
* For example view, subview, project, module or library. Persisted in database. | |||
*/ | |||
@@ -71,6 +67,10 @@ public final class Scopes { | |||
public static final String[] SORTED_SCOPES = {PROJECT, DIRECTORY, FILE, PROGRAM_UNIT, BLOCK_UNIT}; | |||
private Scopes() { | |||
// only static methods | |||
} | |||
public static boolean isProject(final Resource resource) { | |||
return StringUtils.equals(PROJECT, resource.getScope()); | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.api.rules; | |||
import com.google.common.base.Function; | |||
import com.google.common.collect.Lists; | |||
import java.util.ArrayList; | |||
import java.util.Date; | |||
@@ -288,13 +287,10 @@ public class ActiveRule implements Cloneable { | |||
final ActiveRule clone = new ActiveRule(getRulesProfile(), getRule(), getSeverity()); | |||
clone.setInheritance(getInheritance()); | |||
if (activeRuleParams != null && !activeRuleParams.isEmpty()) { | |||
clone.setActiveRuleParams(Lists.transform(activeRuleParams, new Function<ActiveRuleParam, ActiveRuleParam>() { | |||
@Override | |||
public ActiveRuleParam apply(ActiveRuleParam input) { | |||
ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) input.clone(); | |||
activeRuleParamClone.setActiveRule(clone); | |||
return activeRuleParamClone; | |||
} | |||
clone.setActiveRuleParams(Lists.transform(activeRuleParams, input -> { | |||
ActiveRuleParam activeRuleParamClone = (ActiveRuleParam) input.clone(); | |||
activeRuleParamClone.setActiveRule(clone); | |||
return activeRuleParamClone; | |||
})); | |||
} | |||
return clone; |
@@ -27,13 +27,15 @@ import javax.annotation.Nullable; | |||
* @since 3.2 | |||
*/ | |||
public final class DefaultGroups { | |||
private DefaultGroups() { | |||
} | |||
public static final String ANYONE = "Anyone"; | |||
public static final String ADMINISTRATORS = "sonar-administrators"; | |||
public static final String USERS = "sonar-users"; | |||
private DefaultGroups() { | |||
// only statics | |||
} | |||
public static boolean isAnyone(@Nullable String groupName) { | |||
return ANYONE.equalsIgnoreCase(groupName); | |||
} |
@@ -19,7 +19,6 @@ | |||
*/ | |||
package org.sonar.api.server.ws; | |||
import com.google.common.base.Function; | |||
import com.google.common.base.Joiner; | |||
import com.google.common.collect.ImmutableList; | |||
import com.google.common.collect.ImmutableMap; | |||
@@ -28,14 +27,12 @@ import com.google.common.collect.Sets; | |||
import java.io.IOException; | |||
import java.net.URL; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.Arrays; | |||
import java.util.Collection; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Map; | |||
import java.util.Set; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nonnull; | |||
import javax.annotation.Nullable; | |||
import javax.annotation.concurrent.Immutable; | |||
import org.apache.commons.io.FilenameUtils; | |||
@@ -50,6 +47,7 @@ import static com.google.common.base.Preconditions.checkArgument; | |||
import static com.google.common.base.Preconditions.checkState; | |||
import static com.google.common.base.Strings.isNullOrEmpty; | |||
import static java.lang.String.format; | |||
import static java.util.Arrays.asList; | |||
/** | |||
* Defines a web service. Note that contrary to the deprecated {@link org.sonar.api.web.Webservice} | |||
@@ -668,7 +666,7 @@ public interface WebService extends Definable<WebService.Context> { | |||
* @since 4.4 | |||
*/ | |||
public NewParam setPossibleValues(@Nullable Object... values) { | |||
return setPossibleValues(values == null ? Collections.emptyList() : Arrays.asList(values)); | |||
return setPossibleValues(values == null ? Collections.emptyList() : asList(values)); | |||
} | |||
/** | |||
@@ -715,12 +713,7 @@ public interface WebService extends Definable<WebService.Context> { | |||
private final String paramValue; | |||
private static final Map<String, SelectionMode> BY_VALUE = Maps.uniqueIndex(Arrays.asList(values()), new Function<SelectionMode, String>() { | |||
@Override | |||
public String apply(@Nonnull SelectionMode input) { | |||
return input.paramValue; | |||
} | |||
}); | |||
private static final Map<String, SelectionMode> BY_VALUE = Maps.uniqueIndex(asList(values()), input -> input.paramValue); | |||
SelectionMode(String paramValue) { | |||
this.paramValue = paramValue; |
@@ -209,6 +209,7 @@ public final class ZipUtils { | |||
} | |||
} | |||
@FunctionalInterface | |||
public interface ZipEntryFilter { | |||
boolean accept(ZipEntry entry); | |||
} |
@@ -24,7 +24,6 @@ import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.io.InputStreamReader; | |||
import java.nio.charset.StandardCharsets; | |||
import java.util.concurrent.Callable; | |||
import java.util.concurrent.ExecutorService; | |||
import java.util.concurrent.Executors; | |||
import java.util.concurrent.Future; | |||
@@ -80,12 +79,7 @@ public class CommandExecutor { | |||
final Process finalProcess = process; | |||
executorService = Executors.newSingleThreadExecutor(); | |||
Future<Integer> ft = executorService.submit(new Callable<Integer>() { | |||
@Override | |||
public Integer call() throws Exception { | |||
return finalProcess.waitFor(); | |||
} | |||
}); | |||
Future<Integer> ft = executorService.submit(() -> finalProcess.waitFor()); | |||
int exitCode; | |||
if (timeoutMilliseconds < 0) { | |||
exitCode = ft.get(); |
@@ -19,6 +19,7 @@ | |||
*/ | |||
package org.sonar.api.utils.command; | |||
@FunctionalInterface | |||
public interface StreamConsumer { | |||
void consumeLine(String line); |
@@ -27,7 +27,7 @@ import javax.annotation.Nullable; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
class ListInterceptor extends LogInterceptor { | |||
class ListInterceptor implements LogInterceptor { | |||
private final List<String> logs = new ArrayList<>(); | |||
private final ListMultimap<LoggerLevel, String> logsByLevel = ArrayListMultimap.create(); |
@@ -21,15 +21,15 @@ package org.sonar.api.utils.log; | |||
import javax.annotation.Nullable; | |||
abstract class LogInterceptor { | |||
interface LogInterceptor { | |||
abstract void log(LoggerLevel level, String msg); | |||
void log(LoggerLevel level, String msg); | |||
abstract void log(LoggerLevel level, String msg, @Nullable Object arg); | |||
void log(LoggerLevel level, String msg, @Nullable Object arg); | |||
abstract void log(LoggerLevel level, String msg, @Nullable Object arg1, @Nullable Object arg2); | |||
void log(LoggerLevel level, String msg, @Nullable Object arg1, @Nullable Object arg2); | |||
abstract void log(LoggerLevel level, String msg, Object... args); | |||
void log(LoggerLevel level, String msg, Object... args); | |||
abstract void log(LoggerLevel level, String msg, Throwable thrown); | |||
void log(LoggerLevel level, String msg, Throwable thrown); | |||
} |
@@ -22,7 +22,7 @@ package org.sonar.api.utils.log; | |||
/** | |||
* Log interceptor that does nothing, so production-ready! | |||
*/ | |||
class NullInterceptor extends LogInterceptor { | |||
class NullInterceptor implements LogInterceptor { | |||
static final NullInterceptor NULL_INSTANCE = new NullInterceptor(); | |||
@@ -30,27 +30,27 @@ class NullInterceptor extends LogInterceptor { | |||
} | |||
@Override | |||
void log(LoggerLevel level, String msg) { | |||
public void log(LoggerLevel level, String msg) { | |||
// nothing | |||
} | |||
@Override | |||
void log(LoggerLevel level, String msg, Object arg) { | |||
public void log(LoggerLevel level, String msg, Object arg) { | |||
// nothing | |||
} | |||
@Override | |||
void log(LoggerLevel level, String msg, Object arg1, Object arg2) { | |||
public void log(LoggerLevel level, String msg, Object arg1, Object arg2) { | |||
// nothing | |||
} | |||
@Override | |||
void log(LoggerLevel level, String msg, Object... args) { | |||
public void log(LoggerLevel level, String msg, Object... args) { | |||
// nothing | |||
} | |||
@Override | |||
void log(LoggerLevel level, String msg, Throwable thrown) { | |||
public void log(LoggerLevel level, String msg, Throwable thrown) { | |||
// nothing | |||
} | |||
} |