import org.sonar.api.utils.SonarException;
import org.sonar.home.cache.FileCache;
-import javax.annotation.CheckForNull;
-
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
try {
LOG.info("Install JDBC driver");
String[] nameAndHash = downloadJdbcDriverIndex();
- if (nameAndHash != null) {
+ if (nameAndHash.length > 0) {
String filename = nameAndHash[0];
String hash = nameAndHash[1];
}
}
- @CheckForNull
private String[] downloadJdbcDriverIndex() {
String url = "/deploy/jdbc-driver.txt";
try {
String indexContent = serverClient.request(url);
// File is empty when H2 is used
if (Strings.isNullOrEmpty(indexContent)) {
- return null;
+ return new String[]{};
}
return indexContent.split("\\|");
} catch (Exception e) {
import org.sonar.api.task.Task;
import org.sonar.api.task.TaskComponent;
import org.sonar.api.task.TaskDefinition;
-import org.sonar.api.task.TaskExtension;
import org.sonar.api.utils.SonarException;
import org.sonar.batch.scan.ScanTask;
import org.sonar.batch.tasks.ListTask;
*/
package org.sonar.batch.scan;
-import org.sonar.api.BatchComponent;
-import org.sonar.batch.qualitygate.GenerateQualityGateEvents;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.sonar.api.BatchExtension;
+import org.sonar.api.BatchComponent;
import org.sonar.api.batch.InstantiationStrategy;
import org.sonar.api.batch.bootstrap.ProjectDefinition;
import org.sonar.api.batch.rule.CheckFactory;
import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner;
import org.sonar.batch.phases.PhaseExecutor;
import org.sonar.batch.phases.PhasesTimeProfiler;
+import org.sonar.batch.qualitygate.GenerateQualityGateEvents;
import org.sonar.batch.qualitygate.QualityGateProvider;
import org.sonar.batch.qualitygate.QualityGateVerifier;
import org.sonar.batch.rule.*;
return false;
}
- public boolean setProject(DefaultIssue issue, String key, IssueChangeContext context) {
- if (!Objects.equal(key, issue.projectKey())) {
- issue.setProjectKey(key);
+ public boolean setProject(DefaultIssue issue, @Nullable String projectKey, IssueChangeContext context) {
+ if (!Objects.equal(projectKey, issue.projectKey())) {
+ issue.setProjectKey(projectKey);
issue.setUpdateDate(context.date());
issue.setChanged(true);
return true;
return projectKey;
}
- public DefaultIssue setProjectKey(String projectKey) {
+ public DefaultIssue setProjectKey(@Nullable String projectKey) {
this.projectKey = projectKey;
return this;
}
public DefaultIssue createManualIssue(String componentKey, RuleKey ruleKey, @Nullable Integer line, @Nullable String message, @Nullable String severity,
@Nullable Double effortToFix, UserSession userSession) {
verifyLoggedIn(userSession);
- ResourceDto resourceDto = resourceDao.getResource(ResourceQuery.create().setKey(componentKey));
+ ResourceDto component = resourceDao.getResource(ResourceQuery.create().setKey(componentKey));
ResourceDto project = resourceDao.getRootProjectByComponentKey(componentKey);
- if (resourceDto == null || project == null) {
+ if (component == null || project == null) {
throw new IllegalArgumentException("Unknown component: " + componentKey);
}
+ if (!authorizationDao.isAuthorizedComponentKey(component.getKey(), userSession.userId(), UserRole.USER)) {
+ // TODO throw unauthorized
+ throw new IllegalStateException("User does not have the required role");
+ }
+ if (!org.sonar.server.rule.Rule.MANUAL_REPOSITORY_KEY.equals(ruleKey.repository())) {
+ throw new IllegalArgumentException("Issues can be created only on rules marked as 'manual': " + ruleKey);
+ }
+ Rule rule = findRule(ruleKey);
DefaultIssue issue = (DefaultIssue) new DefaultIssueBuilder()
- .componentKey(resourceDto.getKey())
+ .componentKey(component.getKey())
.projectKey(project.getKey())
.line(line)
- .message(message)
+ .message(!Strings.isNullOrEmpty(message) ? message : rule.getName())
.severity(Objects.firstNonNull(severity, Severity.MAJOR))
.effortToFix(effortToFix)
.ruleKey(ruleKey)
.reporter(UserSession.get().login())
.build();
- if (!authorizationDao.isAuthorizedComponentKey(resourceDto.getKey(), userSession.userId(), UserRole.USER)) {
- // TODO throw unauthorized
- throw new IllegalStateException("User does not have the required role");
- }
- if (!org.sonar.server.rule.Rule.MANUAL_REPOSITORY_KEY.equals(issue.ruleKey().repository())) {
- throw new IllegalArgumentException("Issues can be created only on rules marked as 'manual': " + issue.ruleKey());
- }
-
- Rule rule = ruleFinder.findByKey(issue.ruleKey());
- if (rule == null) {
- throw new IllegalArgumentException("Unknown rule: " + issue.ruleKey());
- }
- if (Strings.isNullOrEmpty(issue.message())) {
- issue.setMessage(rule.getName());
- }
-
Date now = new Date();
issue.setCreationDate(now);
issue.setUpdateDate(now);
issueStorage.save(issue);
- dryRunCache.reportResourceModification(resourceDto.getKey());
+ dryRunCache.reportResourceModification(component.getKey());
return issue;
}
+ private Rule findRule (RuleKey ruleKey) {
+ Rule rule = ruleFinder.findByKey(ruleKey);
+ if (rule == null) {
+ throw new IllegalArgumentException("Unknown rule: " + ruleKey);
+ }
+ return rule;
+ }
+
public IssueQueryResult loadIssue(String issueKey) {
IssueQueryResult result = finder.find(IssueQuery.builder().issueKeys(Arrays.asList(issueKey)).requiredRole(UserRole.USER).build());
if (result.issues().size() != 1) {
+++ /dev/null
-/*
- * 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.platform;
-
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
-
-import java.io.File;
-
-/**
- * Search fo the Sonar installation directory in the following ordered steps :
- * <ol>
- * <li>system property SONAR_HOME</li>
- * <li>environment variable SONAR_HOME</li>
- * </ol>
- *
- * @since 2.12
- *
- * TODO Delete it as it's now useless (SONAR_HOME is set by Tomcat)
- */
-final class SonarHome {
-
- private SonarHome() {
- // only static methods
- }
-
- static Supplier<File> homeSupplier = Suppliers.memoize(new Supplier<File>() {
- public File get() {
- File home = locate();
- System.setProperty(CoreProperties.SONAR_HOME, home.getAbsolutePath());
- return home;
- }
- });
-
- static File getHome() {
- return homeSupplier.get();
- }
-
- static File locate() {
- String value = System.getProperty(CoreProperties.SONAR_HOME);
- if (StringUtils.isBlank(value)) {
- value = System.getenv(CoreProperties.SONAR_HOME);
- }
-
- if (StringUtils.isBlank(value)) {
- throw new IllegalStateException("The system property or env variable " + CoreProperties.SONAR_HOME + " is not set");
- }
-
- File dir = new File(value);
- if (!dir.isDirectory() || !dir.exists()) {
- throw new IllegalStateException(CoreProperties.SONAR_HOME + " is not valid: " + value + ". Please fix the env variable/system " +
- "property " + CoreProperties.SONAR_HOME);
- }
- return dir;
- }
-}
NewController controller = context.createController("api/qprofiles")
.setDescription("Quality profiles management");
- controller.createAction("restore_default")
+ NewAction restoreDefault = controller.createAction("restore_default")
.setDescription("Restore default profiles")
.setSince("4.4")
- .setHandler(qProfileBackupWsHandler)
- .createParam("language", "Restore default profiles for this language");
+ .setHandler(qProfileBackupWsHandler);
+ restoreDefault.createParam("language")
+ .setDescription("Restore default profiles for this language");
+
controller.done();
}
}
WebService.Action restoreProfiles = controller.action("restore_default");
assertThat(restoreProfiles).isNotNull();
- assertThat(restoreProfiles.handler()).isNotNull();
+ assertThat(restoreProfiles.handler()).isSameAs(qProfileBackupWsHandler);
assertThat(restoreProfiles.since()).isEqualTo("4.4");
assertThat(restoreProfiles.isPost()).isFalse();
assertThat(restoreProfiles.isInternal()).isFalse();