*/
package org.sonar.batch.repository;
-import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
+import org.sonar.api.utils.MessageException;
+import org.sonarqube.ws.QualityProfiles.SearchWsResponse;
import org.sonar.batch.util.BatchUtils;
import org.apache.commons.io.IOUtils;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import java.io.InputStream;
import java.util.List;
-import static com.google.common.base.Preconditions.checkState;
-
public class DefaultQualityProfileLoader implements QualityProfileLoader {
private static final String WS_URL = "/api/qualityprofiles/search.protobuf";
@Override
public List<QualityProfile> loadDefault(@Nullable String profileName, @Nullable MutableBoolean fromCache) {
String url = WS_URL + "?defaults=true";
- if(profileName != null) {
+ if (profileName != null) {
url += "&profileName=" + BatchUtils.encodeForUrl(profileName);
}
return loadResource(url, fromCache);
}
List<QualityProfile> profilesList = profiles.getProfilesList();
- checkState(profilesList != null && !profilesList.isEmpty(),
- "No quality profiles has been found this project, you probably don't have any language plugin suitable for this analysis.");
+ if (profilesList == null || profilesList.isEmpty()) {
+ throw MessageException.of("No quality profiles have been found, you probably don't have any language plugin installed.");
+ }
return profilesList;
}
*/
package org.sonar.batch.repository.language;
+import org.picocontainer.Startable;
+
import org.sonar.api.resources.Languages;
import javax.annotation.CheckForNull;
* Languages repository using {@link Languages}
* @since 4.4
*/
-public class DefaultLanguagesRepository implements LanguagesRepository {
+public class DefaultLanguagesRepository implements LanguagesRepository, Startable {
private Languages languages;
this.languages = languages;
}
+ @Override
public void start() {
if (languages.all().length == 0) {
throw new IllegalStateException("No language plugins are installed.");
return result;
}
+ @Override
+ public void stop() {
+ // nothing to do
+ }
+
}
*/
package org.sonar.batch.scan;
-import org.sonar.batch.analysis.DefaultAnalysisMode;
+import org.sonar.api.utils.MessageException;
+import org.sonar.batch.analysis.DefaultAnalysisMode;
import com.google.common.base.Joiner;
import java.util.ArrayList;
validateBranch(validationMessages, branch);
if (!validationMessages.isEmpty()) {
- throw new IllegalStateException("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages));
+ throw MessageException.of("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages));
}
}
*/
package org.sonar.batch.mediumtest.fs;
+import org.sonar.api.utils.MessageException;
+
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
public void testProjectBuilderWithNewLine() throws IOException {
File baseDir = prepareProject();
- exception.expect(IllegalStateException.class);
+ exception.expect(MessageException.class);
exception.expectMessage("is not a valid branch name");
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
thrown.expect(IllegalStateException.class);
thrown.expectMessage(
- "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask: org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask has unsatisfied dependency 'class org.sonar.api.issue.action.Actions'");
+ "Unable to load component class org.sonar.batch.mediumtest.tasks.TasksMediumTest$BrokenTask");
tester.newTask()
.properties(ImmutableMap.<String, String>builder()
*/
package org.sonar.batch.repository;
-import org.sonarqube.ws.QualityProfiles;
+import org.sonar.api.utils.MessageException;
+import org.sonarqube.ws.QualityProfiles;
import com.google.common.io.Resources;
import org.sonarqube.ws.QualityProfiles.SearchWsResponse.QualityProfile;
import org.sonar.batch.cache.WSLoaderResult;
InputStream is = createEncodedQP();
when(ws.loadStream(anyString())).thenReturn(new WSLoaderResult<InputStream>(is, false));
- exception.expect(IllegalStateException.class);
+ exception.expect(MessageException.class);
exception.expectMessage("No quality profiles");
qpLoader.load("project", null, null);
import static org.mockito.Mockito.when;
+import org.sonar.api.utils.MessageException;
+
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
validator.validate(createProjectReactor("project/key"));
when(mode.isIssues()).thenReturn(false);
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("is not a valid project or module key");
validator.validate(createProjectReactor("project/key"));
}
public void fail_with_invalid_key() {
ProjectReactor reactor = createProjectReactor("foo$bar");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"foo$bar\" is not a valid project or module key");
validator.validate(reactor);
}
public void fail_with_backslash_in_key() {
ProjectReactor reactor = createProjectReactor("foo\\bar");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"foo\\bar\" is not a valid project or module key");
validator.validate(reactor);
}
@Test
public void fail_with_invalid_branch() {
ProjectReactor reactor = createProjectReactor("foo", "bran#ch");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"bran#ch\" is not a valid branch name");
validator.validate(reactor);
}
@Test
public void fail_with_colon_in_branch() {
ProjectReactor reactor = createProjectReactor("foo", "bran:ch");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"bran:ch\" is not a valid branch name");
validator.validate(reactor);
}
public void fail_with_only_digits() {
ProjectReactor reactor = createProjectReactor("12345");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"12345\" is not a valid project or module key");
validator.validate(reactor);
}
ProjectReactor reactor = createProjectReactor("foo");
settings.setProperty("sonar.phase", "phase");
- thrown.expect(IllegalStateException.class);
+ thrown.expect(MessageException.class);
thrown.expectMessage("\"sonar.phase\" is deprecated");
validator.validate(reactor);
}
try {
return super.getComponent(componentKeyOrType, annotation);
} catch (Throwable t) {
- throw new IllegalStateException("Unable to load component " + componentKeyOrType + ": " + t.getMessage(), t);
+ throw new IllegalStateException("Unable to load component " + componentKeyOrType, t);
}
}