@@ -51,9 +51,11 @@ public class CustomMessageSensor extends AbstractDeprecatedXooRuleSensor { | |||
@Override | |||
protected void processFile(InputFile inputFile, org.sonar.api.resources.File sonarFile, SensorContext context, RuleKey ruleKey, String languageKey) { | |||
Issuable issuable = perspectives.as(Issuable.class, sonarFile); | |||
issuable.addIssue(issuable.newIssueBuilder() | |||
.ruleKey(ruleKey) | |||
.message(settings.getString(MESSAGE_PROPERTY)) | |||
.build()); | |||
if (issuable != null) { | |||
issuable.addIssue(issuable.newIssueBuilder() | |||
.ruleKey(ruleKey) | |||
.message(settings.getString(MESSAGE_PROPERTY)) | |||
.build()); | |||
} | |||
} | |||
} |
@@ -61,10 +61,12 @@ public class ReportFiles { | |||
public void deleteAll() { | |||
File dir = reportDir(); | |||
try { | |||
FileUtils.deleteDirectory(dir); | |||
} catch (Exception e) { | |||
throw new IllegalStateException(format("Fail to delete directory: %s", dir.getAbsolutePath()), e); | |||
if (dir.exists()) { | |||
try { | |||
FileUtils.cleanDirectory(dir); | |||
} catch (Exception e) { | |||
throw new IllegalStateException(format("Fail to clean directory: %s", dir.getAbsolutePath()), e); | |||
} | |||
} | |||
} | |||
@@ -206,7 +206,7 @@ public class RuleIndex extends BaseIndex<Rule, RuleDto, RuleKey> { | |||
String queryString = query.getQueryText(); | |||
// Human readable type of querying | |||
qb.should(QueryBuilders.simpleQueryString(query.getQueryText()) | |||
qb.should(QueryBuilders.simpleQueryStringQuery(query.getQueryText()) | |||
.field(RuleNormalizer.RuleField.NAME.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 20f) | |||
.field(RuleNormalizer.RuleField.HTML_DESCRIPTION.field() + "." + IndexField.SEARCH_WORDS_SUFFIX, 3f) | |||
.defaultOperator(SimpleQueryStringBuilder.Operator.AND) |
@@ -20,11 +20,10 @@ | |||
package org.sonar.server.search.action; | |||
import com.google.common.collect.ImmutableList; | |||
import java.util.List; | |||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | |||
import org.sonar.server.search.Index; | |||
import java.util.List; | |||
public class RefreshIndex extends IndexAction<RefreshRequest> { | |||
public RefreshIndex(String indexType) { | |||
@@ -40,7 +39,6 @@ public class RefreshIndex extends IndexAction<RefreshRequest> { | |||
public List<RefreshRequest> doCall(Index index) { | |||
return ImmutableList.of( | |||
new RefreshRequest() | |||
.force(false) | |||
.indices(index.getIndexName())); | |||
} | |||
} |
@@ -0,0 +1,60 @@ | |||
/* | |||
* SonarQube, open source software quality management tool. | |||
* Copyright (C) 2008-2014 SonarSource | |||
* mailto:contact AT sonarsource DOT com | |||
* | |||
* SonarQube 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. | |||
* | |||
* SonarQube 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; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class CeTaskTest { | |||
@Test | |||
public void build() { | |||
CeTask.Builder builder = new CeTask.Builder(); | |||
builder.setType("TYPE_1"); | |||
builder.setUuid("UUID_1"); | |||
builder.setSubmitterLogin("LOGIN_1"); | |||
builder.setComponentKey("COMPONENT_KEY_1"); | |||
builder.setComponentUuid("COMPONENT_UUID_1"); | |||
builder.setComponentName("The component"); | |||
CeTask task = builder.build(); | |||
assertThat(task.getType()).isEqualTo("TYPE_1"); | |||
assertThat(task.getUuid()).isEqualTo("UUID_1"); | |||
assertThat(task.getSubmitterLogin()).isEqualTo("LOGIN_1"); | |||
assertThat(task.getComponentKey()).isEqualTo("COMPONENT_KEY_1"); | |||
assertThat(task.getComponentUuid()).isEqualTo("COMPONENT_UUID_1"); | |||
assertThat(task.getComponentName()).isEqualTo("The component"); | |||
} | |||
@Test | |||
public void equals_and_hashCode_on_uuid() { | |||
CeTask.Builder builder1 = new CeTask.Builder().setType("TYPE_1").setUuid("UUID_1"); | |||
CeTask task1 = builder1.build(); | |||
CeTask task1bis = builder1.build(); | |||
CeTask task2 = new CeTask.Builder().setType("TYPE_1").setUuid("UUID_2").build(); | |||
assertThat(task1.equals(task1)).isTrue(); | |||
assertThat(task1.equals(task1bis)).isTrue(); | |||
assertThat(task1.equals(task2)).isFalse(); | |||
assertThat(task1.hashCode()).isEqualTo(task1.hashCode()); | |||
assertThat(task1.hashCode()).isEqualTo(task1bis.hashCode()); | |||
} | |||
} |
@@ -0,0 +1,96 @@ | |||
package org.sonar.server.computation; | |||
import java.io.File; | |||
import java.io.IOException; | |||
import org.apache.commons.io.FileUtils; | |||
import org.h2.util.IOUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.process.ProcessProperties; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class ReportFilesTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
File reportDir; | |||
Settings settings = new Settings(); | |||
ReportFiles underTest = new ReportFiles(settings); | |||
@Before | |||
public void setUp() throws IOException { | |||
File dataDir = temp.newFolder(); | |||
reportDir = new File(dataDir, "ce/reports"); | |||
settings.setProperty(ProcessProperties.PATH_DATA, dataDir.getCanonicalPath()); | |||
} | |||
@Test | |||
public void save_report() throws IOException { | |||
underTest.save("TASK_1", IOUtils.getInputStreamFromString("{binary}")); | |||
assertThat(FileUtils.readFileToString(new File(reportDir, "TASK_1.zip"))).isEqualTo("{binary}"); | |||
} | |||
@Test | |||
public void deleteIfExists_uuid_does_not_exist() { | |||
// do not fail, does nothing | |||
underTest.deleteIfExists("TASK_1"); | |||
} | |||
@Test | |||
public void deleteIfExists() throws IOException { | |||
File report = new File(reportDir, "TASK_1.zip"); | |||
FileUtils.touch(report); | |||
assertThat(report).exists(); | |||
underTest.deleteIfExists("TASK_1"); | |||
assertThat(report).doesNotExist(); | |||
} | |||
/** | |||
* List the zip files contained in the report directory | |||
*/ | |||
@Test | |||
public void listUuids() throws IOException { | |||
FileUtils.touch(new File(reportDir, "TASK_1.zip")); | |||
FileUtils.touch(new File(reportDir, "TASK_2.zip")); | |||
FileUtils.touch(new File(reportDir, "something.else")); | |||
assertThat(underTest.listUuids()).containsOnly("TASK_1", "TASK_2"); | |||
} | |||
@Test | |||
public void listUuids_dir_does_not_exist_yet() throws IOException { | |||
FileUtils.deleteQuietly(reportDir); | |||
assertThat(underTest.listUuids()).isEmpty(); | |||
} | |||
@Test | |||
public void deleteAll() throws IOException { | |||
FileUtils.touch(new File(reportDir, "TASK_1.zip")); | |||
FileUtils.touch(new File(reportDir, "TASK_2.zip")); | |||
FileUtils.touch(new File(reportDir, "something.else")); | |||
underTest.deleteAll(); | |||
// directory still exists but is empty | |||
assertThat(reportDir).exists().isDirectory(); | |||
assertThat(reportDir.listFiles()).isEmpty(); | |||
} | |||
@Test | |||
public void deleteAll_dir_does_not_exist_yet() throws IOException { | |||
FileUtils.deleteQuietly(reportDir); | |||
underTest.deleteAll(); | |||
assertThat(reportDir).doesNotExist(); | |||
} | |||
} |
@@ -19,14 +19,13 @@ | |||
*/ | |||
package org.sonar.server.search.action; | |||
import java.util.List; | |||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.sonar.server.search.Index; | |||
import org.sonar.server.search.IndexDefinition; | |||
import java.util.List; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.junit.Assert.fail; | |||
import static org.mockito.Mockito.mock; | |||
@@ -69,6 +68,5 @@ public class RefreshIndexTest { | |||
RefreshRequest request = requests.get(0); | |||
assertThat(request.indices()).containsOnly(TEST_INDEX.getIndexName()); | |||
assertThat(request.force()).isFalse(); | |||
} | |||
} |