import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import org.sonar.core.persistence.MyBatis;
import javax.annotation.CheckForNull;
-
import java.util.List;
-public class CharacteristicDao implements BatchComponent, ServerComponent {
+public class CharacteristicDao implements BatchComponent, ServerComponent {
private final MyBatis mybatis;
}
@CheckForNull
- public CharacteristicDto selectById(Integer id) {
+ public CharacteristicDto selectById(int id) {
SqlSession session = mybatis.openSession();
CharacteristicMapper mapper = session.getMapper(CharacteristicMapper.class);
try {
CharacteristicDto selectByKey(String key);
- CharacteristicDto selectById(Integer id);
+ CharacteristicDto selectById(int id);
CharacteristicDto selectByRuleId(Integer ruleId);
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.api.resources;
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @since 1.10
+ * @deprecated see method comments
+ */
+@Deprecated
+public final class ProjectUtils {
+
+ private ProjectUtils() {
+ // utility class with only static methods
+ }
+
+ /**
+ * @deprecated since 2.6 use JavaUtils.getTargetVersion() instead.
+ */
+ @Deprecated
+ public static String getJavaVersion(Project project) {
+ String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.target") : null;
+ return StringUtils.isNotBlank(version) ? version : "1.5";
+ }
+
+ /**
+ * @deprecated since 2.6 use JavaUtils.getSourceVersion() instead.
+ */
+ @Deprecated
+ public static String getJavaSourceVersion(Project project) {
+ String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.source") : null;
+ return StringUtils.isNotBlank(version) ? version : "1.5";
+ }
+
+ /**
+ * @since 2.7
+ * @deprecated in 4.2. Replaced by org.sonar.api.resources.InputFileUtils#toFiles()
+ */
+ @Deprecated
+ public static List<java.io.File> toIoFiles(Collection<InputFile> inputFiles) {
+ List<java.io.File> files = Lists.newArrayList();
+ for (InputFile inputFile : inputFiles) {
+ files.add(inputFile.getFile());
+ }
+ return files;
+ }
+}
public static final int DEFAULT_HEIGHT = 200;
- private Map<String, String> params;
+ private final Map<String, String> params;
/**
* Creates a ChartParameter based on a list of parameters
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.api.charts;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.api.resources;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.Collection;
-import java.util.List;
-
-/**
- * TODO Actually this class incorrectly named, because provides information not about project, but about Java project.
- * And seems that only core plugins use this class.
- *
- * @since 1.10
- */
-public final class ProjectUtils {
-
- private ProjectUtils() {
- // utility class with only static methods
- }
-
- /**
- * @deprecated since 2.6 use JavaUtils.getTargetVersion() instead.
- */
- @Deprecated
- public static String getJavaVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.target") : null;
- return StringUtils.isNotBlank(version) ? version : "1.5";
- }
-
- /**
- * @deprecated since 2.6 use JavaUtils.getSourceVersion() instead.
- */
- @Deprecated
- public static String getJavaSourceVersion(Project project) {
- String version = project.getConfiguration() != null ? project.getConfiguration().getString("sonar.java.source") : null;
- return StringUtils.isNotBlank(version) ? version : "1.5";
- }
-
- /**
- * @since 2.7
- */
- public static List<java.io.File> toIoFiles(Collection<InputFile> inputFiles) {
- List<java.io.File> files = Lists.newArrayList();
- for (InputFile inputFile : inputFiles) {
- files.add(inputFile.getFile());
- }
- return files;
- }
-}
import org.sonar.api.ServerComponent;
import org.sonar.api.charts.Chart;
+import javax.annotation.CheckForNull;
import java.util.Map;
public final class ChartFactory implements ServerComponent {
private static final Logger LOG = LoggerFactory.getLogger(ChartFactory.class);
- private Map<String, Chart> chartsByKey = Maps.newHashMap();
+ private final Map<String, Chart> chartsByKey = Maps.newHashMap();
public ChartFactory(Chart[] charts) {
// DO NOT SUPPRESS : used by picocontainer if no charts
}
+ @CheckForNull
public Chart getChart(String key) {
return chartsByKey.get(key);
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.charts;
+
+import javax.annotation.ParametersAreNonnullByDefault;
private static final String BULK_EXECUTE_FAILED = "Execution of bulk operation failed";
private static final String BULK_INTERRUPTED = "Interrupted during bulk operation";
-
private static final String PROFILE_DOMAIN = "es";
private static final Logger LOG = LoggerFactory.getLogger(ESIndex.class);
- private ESNode searchNode;
+ private final ESNode node;
+ private final Profiling profiling;
private Client client;
- private Profiling profiling;
- public ESIndex(ESNode searchNode, Profiling profiling) {
- this.searchNode = searchNode;
+ public ESIndex(ESNode node, Profiling profiling) {
+ this.node = node;
this.profiling = profiling;
}
@Override
public void start() {
- this.client = searchNode.client();
+ this.client = node.client();
}
@Override
public void stop() {
- if(client != null) {
+ if (client != null) {
client.close();
}
}
public void bulkIndex(String index, String type, String[] ids, BytesStream[] sources) {
BulkRequestBuilder builder = new BulkRequestBuilder(client);
- for (int i=0; i<ids.length; i++) {
+ for (int i = 0; i < ids.length; i++) {
builder.add(client.prepareIndex(index, type, ids[i]).setSource(sources[i].bytes()));
}
StopWatch watch = createWatch();
public void bulkIndex(String index, String type, String[] ids, BytesStream[] sources, String[] parentIds) {
BulkRequestBuilder builder = new BulkRequestBuilder(client);
- for (int i=0; i<ids.length; i++) {
+ for (int i = 0; i < ids.length; i++) {
builder.add(client.prepareIndex(index, type, ids[i]).setParent(parentIds[i]).setSource(sources[i].bytes()));
}
StopWatch watch = createWatch();
throw new IllegalArgumentException("Could not load unexisting file at " + resourcePath);
}
addMapping(index, type, IOUtils.toString(resource));
- } catch(IOException ioException) {
+ } catch (IOException ioException) {
throw new IllegalArgumentException("Problem loading file at " + resourcePath, ioException);
}
}
IndicesAdminClient indices = client.admin().indices();
StopWatch watch = createWatch();
try {
- if (! indices.exists(indices.prepareExists(index).request()).get().isExists()) {
+ if (!indices.exists(indices.prepareExists(index).request()).get().isExists()) {
indices.prepareCreate(index)
.execute().actionGet();
}
watch = createWatch();
try {
indices.putMapping(Requests.putMappingRequest(index).type(type).source(mapping)).actionGet();
- } catch(ElasticSearchParseException parseException) {
+ } catch (ElasticSearchParseException parseException) {
throw new IllegalArgumentException("Invalid mapping file", parseException);
} finally {
watch.stop("put mapping on index '%s' for type '%s'", index, type);
private String builderToString(SearchRequestBuilder builder) {
try {
return builder.internalBuilder().toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)
- .humanReadable(false).string();
+ .humanReadable(false).string();
} catch (IOException ioException) {
LOG.warn("Could not serialize request: " + builder.internalBuilder().toString(), ioException);
return "<IOException in serialize>";
BulkResponse bulkResponse = client.bulk(builder.setRefresh(true).request()).get();
if (bulkResponse.hasFailures()) {
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
- if(bulkItemResponse.isFailed()) {
+ if (bulkItemResponse.isFailed()) {
throw new IllegalStateException("Bulk operation partially executed: " + bulkItemResponse.getFailure().getMessage());
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonar.server.exceptions;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.group;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.core.user.*;
-import org.sonar.server.exceptions.NotFoundException;
-
-import java.util.List;
-
-import static com.google.common.collect.Lists.newArrayList;
-
-public class GroupMembershipFinder implements ServerComponent {
-
- private final UserDao userDao;
- private final GroupMembershipDao groupMembershipDao;
-
- public GroupMembershipFinder(UserDao userDao, GroupMembershipDao groupMembershipDao) {
- this.userDao = userDao;
- this.groupMembershipDao = groupMembershipDao;
- }
-
- public GroupMembershipQueryResult find(GroupMembershipQuery query) {
- Long userId = userId(query.login());
- int pageSize = query.pageSize();
- int pageIndex = query.pageIndex();
-
- int offset = (pageIndex - 1) * pageSize;
- // Add one to page size in order to be able to know if there's more results or not
- int limit = pageSize + 1;
- List<GroupMembershipDto> dtos = groupMembershipDao.selectGroups(query, userId, offset, limit);
- boolean hasMoreResults = false;
- if (dtos.size() == limit) {
- hasMoreResults = true;
- // Removed last entry as it's only need to know if there more results or not
- dtos.remove(dtos.size() - 1);
- }
- return new GroupMembershipQueryResult(toGroupMembership(dtos), hasMoreResults);
- }
-
- private Long userId(String login) {
- UserDto userDto = userDao.selectActiveUserByLogin(login);
- if (userDto == null) {
- throw new NotFoundException("User '"+ login +"' does not exists.");
- }
- return userDto.getId();
- }
-
- private List<GroupMembership> toGroupMembership(List<GroupMembershipDto> dtos) {
- List<GroupMembership> groups = newArrayList();
- for (GroupMembershipDto groupMembershipDto : dtos) {
- groups.add(groupMembershipDto.toGroupMembership());
- }
- return groups;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.group;
-
-import org.sonar.core.user.GroupMembership;
-
-import java.util.List;
-
-public class GroupMembershipQueryResult {
-
- private List<GroupMembership> groups;
- private boolean hasMoreResults;
-
- public GroupMembershipQueryResult(List<GroupMembership> groups, boolean hasMoreResults) {
- this.groups = groups;
- this.hasMoreResults = hasMoreResults;
- }
-
- public List<GroupMembership> groups() {
- return groups;
- }
-
- public boolean hasMoreResults() {
- return hasMoreResults;
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.group;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.core.user.GroupMembershipQuery;
-import org.sonar.server.util.RubyUtils;
-
-import java.util.Map;
-
-/**
- * Used by ruby code <pre>Internal.group_membership</pre>
- */
-public class InternalGroupMembershipService implements ServerComponent {
-
- private static final String SELECTED_MEMBERSHIP = "selected";
- private static final String DESELECTED_MEMBERSHIP = "deselected";
-
- private final GroupMembershipFinder finder;
-
- public InternalGroupMembershipService(GroupMembershipFinder finder) {
- this.finder = finder;
- }
-
- public GroupMembershipQueryResult find(Map<String, Object> params) {
- return finder.find(parseQuery(params));
- }
-
- private GroupMembershipQuery parseQuery(Map<String, Object> params) {
- GroupMembershipQuery.Builder builder = GroupMembershipQuery.builder();
- builder.membership(membership(params));
- builder.groupSearch((String) params.get("query"));
- builder.pageIndex(RubyUtils.toInteger(params.get("page")));
- builder.pageSize(RubyUtils.toInteger(params.get("pageSize")));
- builder.login((String) params.get("user"));
- return builder.build();
- }
-
- private String membership(Map<String, Object> params) {
- String selected = (String) params.get("selected");
- if (SELECTED_MEMBERSHIP.equals(selected)) {
- return GroupMembershipQuery.IN;
- } else if (DESELECTED_MEMBERSHIP.equals(selected)) {
- return GroupMembershipQuery.OUT;
- } else {
- return GroupMembershipQuery.ANY;
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.
- */
-
-@ParametersAreNonnullByDefault
-package org.sonar.server.group;
-
-import javax.annotation.ParametersAreNonnullByDefault;
-
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.core.i18n.DefaultI18n;
import org.sonar.core.issue.IssueUpdater;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import java.io.Serializable;
import java.util.List;
private static final String ISSUE_CHANGELOG_FIELD = "issue.changelog.field.";
private final DefaultI18n defaultI18n;
- private final TechnicalDebtFormatter technicalDebtFormatter;
+ private final DebtFormatter debtFormatter;
- public IssueChangelogFormatter(DefaultI18n defaultI18n, TechnicalDebtFormatter technicalDebtFormatter) {
+ public IssueChangelogFormatter(DefaultI18n defaultI18n, DebtFormatter debtFormatter) {
this.defaultI18n = defaultI18n;
- this.technicalDebtFormatter = technicalDebtFormatter;
+ this.debtFormatter = debtFormatter;
}
public List<String> format(Locale locale, FieldDiffs diffs) {
String oldValueString = oldValue != null && !"".equals(oldValue) ? oldValue.toString() : null;
if (IssueUpdater.TECHNICAL_DEBT.equals(key)) {
if (newValueString != null) {
- newValueString = technicalDebtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(newValueString)));
+ newValueString = debtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(newValueString)));
}
if (oldValueString != null) {
- oldValueString = technicalDebtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(oldValueString)));
+ oldValueString = debtFormatter.format(locale, WorkDayDuration.fromLong(Long.parseLong(oldValueString)));
}
}
return new IssueChangelogDiffFormat(oldValueString, newValueString);
import org.sonar.server.issue.IssueChangelog;
import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueService;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import org.sonar.server.user.UserSession;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-
import java.util.Arrays;
import java.util.Date;
import java.util.List;
private final IssueService issueService;
private final IssueChangelogService issueChangelogService;
private final ActionService actionService;
- private final TechnicalDebtFormatter technicalDebtFormatter;
+ private final DebtFormatter debtFormatter;
private final DefaultTechnicalDebtManager technicalDebtManager;
private final I18n i18n;
public IssueShowWsHandler(IssueFinder issueFinder, IssueService issueService, IssueChangelogService issueChangelogService, ActionService actionService,
- TechnicalDebtFormatter technicalDebtFormatter, DefaultTechnicalDebtManager technicalDebtManager, I18n i18n) {
+ DebtFormatter debtFormatter, DefaultTechnicalDebtManager technicalDebtManager, I18n i18n) {
this.issueFinder = issueFinder;
this.issueService = issueService;
this.issueChangelogService = issueChangelogService;
this.actionService = actionService;
- this.technicalDebtFormatter = technicalDebtFormatter;
+ this.debtFormatter = debtFormatter;
this.technicalDebtManager = technicalDebtManager;
this.i18n = i18n;
}
.prop("severity", issue.severity())
.prop("author", issue.authorLogin())
.prop("actionPlan", actionPlanKey)
- .prop("debt", technicalDebt != null ? technicalDebtFormatter.format(UserSession.get().locale(), technicalDebt) : null)
+ .prop("debt", technicalDebt != null ? debtFormatter.format(UserSession.get().locale(), technicalDebt) : null)
.prop("actionPlanName", actionPlanKey != null ? result.actionPlan(issue).name() : null)
.prop("creationDate", DateUtils.formatDateTime(issue.creationDate()))
.prop("fCreationDate", formatDate(issue.creationDate()))
import org.sonar.server.charts.ChartFactory;
import org.sonar.server.component.DefaultComponentFinder;
import org.sonar.server.component.DefaultRubyComponentService;
-import org.sonar.server.qualityprofile.ProfilesManager;
import org.sonar.server.db.EmbeddedDatabaseFactory;
import org.sonar.server.db.migrations.DatabaseMigration;
import org.sonar.server.db.migrations.DatabaseMigrations;
import org.sonar.server.db.migrations.DatabaseMigrator;
import org.sonar.server.es.ESIndex;
import org.sonar.server.es.ESNode;
-import org.sonar.server.group.GroupMembershipFinder;
-import org.sonar.server.group.InternalGroupMembershipService;
import org.sonar.server.issue.*;
import org.sonar.server.issue.filter.IssueFilterService;
import org.sonar.server.issue.filter.IssueFilterWs;
import org.sonar.server.source.ws.SourcesShowWsHandler;
import org.sonar.server.source.ws.SourcesWs;
import org.sonar.server.startup.*;
-import org.sonar.server.technicaldebt.InternalRubyTechnicalDebtService;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
+import org.sonar.server.technicaldebt.DebtService;
import org.sonar.server.text.MacroInterpreter;
import org.sonar.server.text.RubyTextService;
-import org.sonar.server.ui.*;
-import org.sonar.server.user.DefaultUserService;
-import org.sonar.server.user.NewUserNotifier;
+import org.sonar.server.ui.JRubyI18n;
+import org.sonar.server.ui.JRubyProfiling;
+import org.sonar.server.ui.PageDecorations;
+import org.sonar.server.ui.Views;
+import org.sonar.server.user.*;
import org.sonar.server.util.*;
import org.sonar.server.ws.ListingWs;
import org.sonar.server.ws.WebServiceEngine;
servicesContainer.addSingleton(DefaultUserService.class);
// groups
- servicesContainer.addSingleton(InternalGroupMembershipService.class);
+ servicesContainer.addSingleton(GroupMembershipService.class);
servicesContainer.addSingleton(GroupMembershipFinder.class);
// permissions
servicesContainer.addSingleton(RuleTagsWs.class);
// technical debt
- servicesContainer.addSingleton(InternalRubyTechnicalDebtService.class);
+ servicesContainer.addSingleton(DebtService.class);
servicesContainer.addSingleton(TechnicalDebtModelSynchronizer.class);
servicesContainer.addSingleton(TechnicalDebtModelRepository.class);
servicesContainer.addSingleton(TechnicalDebtXMLImporter.class);
servicesContainer.addSingleton(TechnicalDebtConverter.class);
- servicesContainer.addSingleton(TechnicalDebtFormatter.class);
+ servicesContainer.addSingleton(DebtFormatter.class);
servicesContainer.addSingleton(DefaultTechnicalDebtManager.class);
// source
startupContainer.addSingleton(RenameDeprecatedPropertyKeys.class);
startupContainer.addSingleton(LogServerId.class);
startupContainer.addSingleton(RegisterServletFilters.class);
- startupContainer.addSingleton(CleanDryRunCache.class);
+ startupContainer.addSingleton(CleanPreviewAnalysisCache.class);
startupContainer.startComponents();
startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
*/
public final class MimeTypes {
private MimeTypes() {
+ // only static methods
}
+ public static final String JSON = "application/json";
+ public static final String XML = "application/xml";
+ public static final String DEFAULT = "application/octet-stream";
+
private static final Map<String, String> MAP = new ImmutableMap.Builder<String, String>()
- .put("json", "application/json")
+ .put("json", JSON)
.put("zip", "application/zip")
.put("tgz", "application/tgz")
.put("ps", "application/postscript")
.put("xls", "application/vnd.ms-excel")
.put("ppt", "application/vnd.ms-powerpoint")
.put("tar", "application/x-tar")
- .put("xml", "application/xml")
+ .put("xml", XML)
.put("dtd", "application/xml-dtd")
.put("xslt", "application/xslt+xml")
.put("bmp", "image/bmp")
.put("tsv", "text/tab-separated-values")
.build();
- public static final String DEFAULT = "application/octet-stream";
-
public static String getByFilename(String filename) {
String extension = FilenameUtils.getExtension(filename);
String mime = null;
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.startup;
-
-import org.sonar.core.preview.PreviewCache;
-
-/**
- * @since 4.0
- */
-public class CleanDryRunCache {
-
- private PreviewCache dryRunCache;
-
- public CleanDryRunCache(PreviewCache dryRunCache) {
- this.dryRunCache = dryRunCache;
- }
-
- public void start() {
- dryRunCache.cleanAll();
- }
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.startup;
+
+import org.picocontainer.Startable;
+import org.sonar.core.preview.PreviewCache;
+
+/**
+ * @since 4.0
+ */
+public class CleanPreviewAnalysisCache implements Startable {
+
+ private final PreviewCache cache;
+
+ public CleanPreviewAnalysisCache(PreviewCache cache) {
+ this.cache = cache;
+ }
+
+ @Override
+ public void start() {
+ cache.cleanAll();
+ }
+
+ @Override
+ public void stop() {
+ // nothing
+ }
+}
package org.sonar.server.startup;
import com.google.common.collect.ImmutableMap;
+import org.picocontainer.Startable;
import org.slf4j.LoggerFactory;
import org.sonar.api.CoreProperties;
import org.sonar.api.platform.Server;
import java.text.SimpleDateFormat;
-public final class ServerMetadataPersister {
+public final class ServerMetadataPersister implements Startable {
private final Server server;
private final PersistentSettings persistentSettings;
this.persistentSettings = persistentSettings;
}
+ @Override
public void start() {
LoggerFactory.getLogger(getClass()).debug("Persisting server metadata");
persistentSettings.saveProperties(ImmutableMap.of(
CoreProperties.SERVER_VERSION, server.getVersion(),
CoreProperties.SERVER_STARTTIME, new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(server.getStartedAt())));
}
+
+ @Override
+ public void stop() {
+ // nothing
+ }
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.technicaldebt;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.api.issue.internal.WorkDayDuration;
+import org.sonar.core.i18n.DefaultI18n;
+
+import java.util.Locale;
+
+public class DebtFormatter implements ServerComponent {
+
+ private final DefaultI18n defaultI18n;
+
+ public DebtFormatter(DefaultI18n defaultI18n) {
+ this.defaultI18n = defaultI18n;
+ }
+
+ public String format(Locale locale, WorkDayDuration technicalDebt) {
+ StringBuilder message = new StringBuilder();
+ if (technicalDebt.days() > 0) {
+ message.append(defaultI18n.message(locale, "issue.technical_debt.x_days", null, technicalDebt.days()));
+ }
+ if (technicalDebt.hours() > 0) {
+ if (message.length() > 0) {
+ message.append(" ");
+ }
+ message.append(defaultI18n.message(locale, "issue.technical_debt.x_hours", null, technicalDebt.hours()));
+ }
+ // Do not display minutes if days is not null to not have too much information
+ if (technicalDebt.minutes() > 0 && technicalDebt.days() == 0) {
+ if (message.length() > 0) {
+ message.append(" ");
+ }
+ message.append(defaultI18n.message(locale, "issue.technical_debt.x_minutes", null, technicalDebt.minutes()));
+ }
+ return message.toString();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.technicaldebt;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.api.issue.internal.WorkDayDuration;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.technicaldebt.server.Characteristic;
+import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
+import org.sonar.server.user.UserSession;
+
+import javax.annotation.CheckForNull;
+import java.util.List;
+
+public class DebtService implements ServerComponent {
+
+ private final DebtFormatter debtFormatter;
+ private final DefaultTechnicalDebtManager finder;
+
+ public DebtService(DebtFormatter debtFormatter, DefaultTechnicalDebtManager finder) {
+ this.debtFormatter = debtFormatter;
+ this.finder = finder;
+ }
+
+ public String format(WorkDayDuration technicalDebt) {
+ return debtFormatter.format(UserSession.get().locale(), technicalDebt);
+ }
+
+ public WorkDayDuration toTechnicalDebt(String technicalDebtInLong) {
+ return WorkDayDuration.fromLong(Long.parseLong(technicalDebtInLong));
+ }
+
+ public List<Characteristic> findRootCharacteristics() {
+ return finder.findRootCharacteristics();
+ }
+
+ public Characteristic findRequirement(Rule rule) {
+ return finder.findRequirementByRule(rule);
+ }
+
+ @CheckForNull
+ public Characteristic findCharacteristic(int id) {
+ return finder.findCharacteristicById(id);
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.technicaldebt;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.issue.internal.WorkDayDuration;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
-import org.sonar.server.user.UserSession;
-
-import java.util.List;
-
-public class InternalRubyTechnicalDebtService implements ServerComponent {
-
- private final TechnicalDebtFormatter technicalDebtFormatter;
- private final DefaultTechnicalDebtManager finder;
-
- public InternalRubyTechnicalDebtService(TechnicalDebtFormatter technicalDebtFormatter, DefaultTechnicalDebtManager finder) {
- this.technicalDebtFormatter = technicalDebtFormatter;
- this.finder = finder;
- }
-
- public String format(WorkDayDuration technicalDebt) {
- return technicalDebtFormatter.format(UserSession.get().locale(), technicalDebt);
- }
-
- public WorkDayDuration toTechnicalDebt(String technicalDebtInLong) {
- return WorkDayDuration.fromLong(Long.parseLong(technicalDebtInLong));
- }
-
- public List<Characteristic> findRootCharacteristics() {
- return finder.findRootCharacteristics();
- }
-
- public Characteristic findRequirement(Rule rule) {
- return finder.findRequirementByRule(rule);
- }
-
- public Characteristic findCharacteristic(Integer id) {
- return finder.findCharacteristicById(id);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.technicaldebt;
-
-import org.sonar.api.ServerComponent;
-import org.sonar.api.issue.internal.WorkDayDuration;
-import org.sonar.core.i18n.DefaultI18n;
-
-import java.util.Locale;
-
-public class TechnicalDebtFormatter implements ServerComponent {
-
- private final DefaultI18n defaultI18n;
-
- public TechnicalDebtFormatter(DefaultI18n defaultI18n) {
- this.defaultI18n = defaultI18n;
- }
-
- public String format(Locale locale, WorkDayDuration technicalDebt) {
- StringBuilder message = new StringBuilder();
- if (technicalDebt.days() > 0) {
- message.append(defaultI18n.message(locale, "issue.technical_debt.x_days", null, technicalDebt.days()));
- }
- if (technicalDebt.hours() > 0) {
- if (message.length() > 0) {
- message.append(" ");
- }
- message.append(defaultI18n.message(locale, "issue.technical_debt.x_hours", null, technicalDebt.hours()));
- }
- // Do not display minutes if days is not null to not have too much information
- if (technicalDebt.minutes() > 0 && technicalDebt.days() == 0) {
- if (message.length() > 0) {
- message.append(" ");
- }
- message.append(defaultI18n.message(locale, "issue.technical_debt.x_minutes", null, technicalDebt.minutes()));
- }
- return message.toString();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.ui;
-
-import org.sonar.api.security.LoginPasswordAuthenticator;
-import org.sonar.api.security.SecurityRealm;
-
-/**
- * Provides backward compatibility for {@link org.sonar.api.CoreProperties#CORE_AUTHENTICATOR_CLASS}.
- *
- * @since 2.14
- */
-class CompatibilityRealm extends SecurityRealm {
- private final LoginPasswordAuthenticator authenticator;
-
- public CompatibilityRealm(LoginPasswordAuthenticator authenticator) {
- this.authenticator = authenticator;
- }
-
- @Override
- public void init() {
- authenticator.init();
- }
-
- @Override
- public String getName() {
- return "CompatibilityRealm[" + authenticator.getClass().getName() + "]";
- }
-
- @Override
- public LoginPasswordAuthenticator getLoginPasswordAuthenticator() {
- return authenticator;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.ui;
-
-import org.sonar.jpa.session.DatabaseSessionFactory;
-import org.sonar.server.platform.Platform;
-
-import java.io.IOException;
-import javax.servlet.*;
-
-public class DatabaseSessionFilter implements Filter {
- @Override
- public void init(FilterConfig filterConfig) throws ServletException {
- // nothing to do
- }
-
- @Override
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
- chain.doFilter(request, response);
-
- DatabaseSessionFactory sessionFactory = Platform.component(DatabaseSessionFactory.class);
- if (sessionFactory != null) {
- sessionFactory.clear();
- }
- }
-
- @Override
- public void destroy() {
- // nothing to do
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.ui;
-
-import org.apache.commons.lang.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.ServerComponent;
-import org.sonar.api.config.Settings;
-import org.sonar.api.security.LoginPasswordAuthenticator;
-import org.sonar.api.security.SecurityRealm;
-import org.sonar.api.utils.SonarException;
-
-/**
- * @since 2.14
- */
-public class SecurityRealmFactory implements ServerComponent {
-
- private static final Logger INFO = LoggerFactory.getLogger("org.sonar.INFO");
-
- private final boolean ignoreStartupFailure;
- private final SecurityRealm realm;
-
- public SecurityRealmFactory(Settings settings, SecurityRealm[] realms, LoginPasswordAuthenticator[] authenticators) {
- ignoreStartupFailure = settings.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE);
- String realmName = settings.getString(CoreProperties.CORE_AUTHENTICATOR_REALM);
- String className = settings.getString(CoreProperties.CORE_AUTHENTICATOR_CLASS);
- SecurityRealm selectedRealm = null;
- if (!StringUtils.isEmpty(realmName)) {
- selectedRealm = selectRealm(realms, realmName);
- if (selectedRealm == null) {
- throw new SonarException("Realm '" + realmName + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_REALM + "' in conf/sonar.properties");
- }
- }
- if (selectedRealm == null && !StringUtils.isEmpty(className)) {
- LoginPasswordAuthenticator authenticator = selectAuthenticator(authenticators, className);
- if (authenticator == null) {
- throw new SonarException("Authenticator '" + className + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_CLASS
- + "' in conf/sonar.properties");
- }
- selectedRealm = new CompatibilityRealm(authenticator);
- }
- realm = selectedRealm;
- }
-
- public SecurityRealmFactory(Settings settings, LoginPasswordAuthenticator[] authenticators) {
- this(settings, null, authenticators);
- }
-
- public SecurityRealmFactory(Settings settings, SecurityRealm[] realms) {
- this(settings, realms, null);
- }
-
- public SecurityRealmFactory(Settings settings) {
- this(settings, null, null);
- }
-
- public void start() {
- if (realm != null) {
- try {
- INFO.info("Security realm: " + realm.getName());
- realm.init();
- INFO.info("Security realm started");
- } catch (RuntimeException e) {
- if (ignoreStartupFailure) {
- INFO.error("IGNORED - Security realm fails to start: " + e.getMessage());
- } else {
- throw new SonarException("Security realm fails to start: " + e.getMessage(), e);
- }
- }
- }
- }
-
- public SecurityRealm getRealm() {
- return realm;
- }
-
- private static SecurityRealm selectRealm(SecurityRealm[] realms, String realmName) {
- if (realms != null) {
- for (SecurityRealm realm : realms) {
- if (StringUtils.equals(realmName, realm.getName())) {
- return realm;
- }
- }
- }
- return null;
- }
-
- private static LoginPasswordAuthenticator selectAuthenticator(LoginPasswordAuthenticator[] authenticators, String className) {
- if (authenticators != null) {
- for (LoginPasswordAuthenticator lpa : authenticators) {
- if (lpa.getClass().getName().equals(className)) {
- return lpa;
- }
- }
- }
- return null;
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.sonar.api.security.LoginPasswordAuthenticator;
+import org.sonar.api.security.SecurityRealm;
+
+/**
+ * Provides backward compatibility for {@link org.sonar.api.CoreProperties#CORE_AUTHENTICATOR_CLASS}.
+ *
+ * @since 2.14
+ */
+class CompatibilityRealm extends SecurityRealm {
+ private final LoginPasswordAuthenticator authenticator;
+
+ public CompatibilityRealm(LoginPasswordAuthenticator authenticator) {
+ this.authenticator = authenticator;
+ }
+
+ @Override
+ public void init() {
+ authenticator.init();
+ }
+
+ @Override
+ public String getName() {
+ return "CompatibilityRealm[" + authenticator.getClass().getName() + "]";
+ }
+
+ @Override
+ public LoginPasswordAuthenticator getLoginPasswordAuthenticator() {
+ return authenticator;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.sonar.jpa.session.DatabaseSessionFactory;
+import org.sonar.server.platform.Platform;
+
+import javax.servlet.*;
+import java.io.IOException;
+
+public class DatabaseSessionFilter implements Filter {
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ // nothing to do
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ chain.doFilter(request, response);
+
+ DatabaseSessionFactory sessionFactory = Platform.component(DatabaseSessionFactory.class);
+ if (sessionFactory != null) {
+ sessionFactory.clear();
+ }
+ }
+
+ @Override
+ public void destroy() {
+ // nothing to do
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.core.user.*;
+import org.sonar.server.exceptions.NotFoundException;
+
+import java.util.List;
+
+import static com.google.common.collect.Lists.newArrayList;
+
+public class GroupMembershipFinder implements ServerComponent {
+
+ public static class Membership {
+ private List<GroupMembership> groups;
+ private boolean hasMoreResults;
+
+ private Membership(List<GroupMembership> groups, boolean hasMoreResults) {
+ this.groups = groups;
+ this.hasMoreResults = hasMoreResults;
+ }
+
+ public List<GroupMembership> groups() {
+ return groups;
+ }
+
+ public boolean hasMoreResults() {
+ return hasMoreResults;
+ }
+ }
+
+ private final UserDao userDao;
+ private final GroupMembershipDao groupMembershipDao;
+
+ public GroupMembershipFinder(UserDao userDao, GroupMembershipDao groupMembershipDao) {
+ this.userDao = userDao;
+ this.groupMembershipDao = groupMembershipDao;
+ }
+
+ public Membership find(GroupMembershipQuery query) {
+ Long userId = userId(query.login());
+ int pageSize = query.pageSize();
+ int pageIndex = query.pageIndex();
+
+ int offset = (pageIndex - 1) * pageSize;
+ // Add one to page size in order to be able to know if there's more results or not
+ int limit = pageSize + 1;
+ List<GroupMembershipDto> dtos = groupMembershipDao.selectGroups(query, userId, offset, limit);
+ boolean hasMoreResults = false;
+ if (dtos.size() == limit) {
+ hasMoreResults = true;
+ // Removed last entry as it's only need to know if there more results or not
+ dtos.remove(dtos.size() - 1);
+ }
+ return new Membership(toGroupMembership(dtos), hasMoreResults);
+ }
+
+ private Long userId(String login) {
+ UserDto userDto = userDao.selectActiveUserByLogin(login);
+ if (userDto == null) {
+ throw new NotFoundException("User '" + login + "' does not exists.");
+ }
+ return userDto.getId();
+ }
+
+ private List<GroupMembership> toGroupMembership(List<GroupMembershipDto> dtos) {
+ List<GroupMembership> groups = newArrayList();
+ for (GroupMembershipDto groupMembershipDto : dtos) {
+ groups.add(groupMembershipDto.toGroupMembership());
+ }
+ return groups;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.sonar.api.ServerComponent;
+import org.sonar.core.user.GroupMembershipQuery;
+import org.sonar.server.util.RubyUtils;
+
+import java.util.Map;
+
+/**
+ * Used by ruby code <pre>Internal.group_membership</pre>
+ */
+public class GroupMembershipService implements ServerComponent {
+
+ private static final String SELECTED_MEMBERSHIP = "selected";
+ private static final String DESELECTED_MEMBERSHIP = "deselected";
+
+ private final GroupMembershipFinder finder;
+
+ public GroupMembershipService(GroupMembershipFinder finder) {
+ this.finder = finder;
+ }
+
+ public GroupMembershipFinder.Membership find(Map<String, Object> params) {
+ return finder.find(parseQuery(params));
+ }
+
+ private GroupMembershipQuery parseQuery(Map<String, Object> params) {
+ GroupMembershipQuery.Builder builder = GroupMembershipQuery.builder();
+ builder.membership(membership(params));
+ builder.groupSearch((String) params.get("query"));
+ builder.pageIndex(RubyUtils.toInteger(params.get("page")));
+ builder.pageSize(RubyUtils.toInteger(params.get("pageSize")));
+ builder.login((String) params.get("user"));
+ return builder.build();
+ }
+
+ private String membership(Map<String, Object> params) {
+ String selected = (String) params.get("selected");
+ if (SELECTED_MEMBERSHIP.equals(selected)) {
+ return GroupMembershipQuery.IN;
+ } else if (DESELECTED_MEMBERSHIP.equals(selected)) {
+ return GroupMembershipQuery.OUT;
+ } else {
+ return GroupMembershipQuery.ANY;
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.ServerComponent;
+import org.sonar.api.config.Settings;
+import org.sonar.api.security.LoginPasswordAuthenticator;
+import org.sonar.api.security.SecurityRealm;
+import org.sonar.api.utils.SonarException;
+
+/**
+ * @since 2.14
+ */
+public class SecurityRealmFactory implements ServerComponent {
+
+ private static final Logger INFO = LoggerFactory.getLogger("org.sonar.INFO");
+
+ private final boolean ignoreStartupFailure;
+ private final SecurityRealm realm;
+
+ public SecurityRealmFactory(Settings settings, SecurityRealm[] realms, LoginPasswordAuthenticator[] authenticators) {
+ ignoreStartupFailure = settings.getBoolean(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE);
+ String realmName = settings.getString(CoreProperties.CORE_AUTHENTICATOR_REALM);
+ String className = settings.getString(CoreProperties.CORE_AUTHENTICATOR_CLASS);
+ SecurityRealm selectedRealm = null;
+ if (!StringUtils.isEmpty(realmName)) {
+ selectedRealm = selectRealm(realms, realmName);
+ if (selectedRealm == null) {
+ throw new SonarException("Realm '" + realmName + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_REALM + "' in conf/sonar.properties");
+ }
+ }
+ if (selectedRealm == null && !StringUtils.isEmpty(className)) {
+ LoginPasswordAuthenticator authenticator = selectAuthenticator(authenticators, className);
+ if (authenticator == null) {
+ throw new SonarException("Authenticator '" + className + "' not found. Please check the property '" + CoreProperties.CORE_AUTHENTICATOR_CLASS
+ + "' in conf/sonar.properties");
+ }
+ selectedRealm = new CompatibilityRealm(authenticator);
+ }
+ realm = selectedRealm;
+ }
+
+ public SecurityRealmFactory(Settings settings, LoginPasswordAuthenticator[] authenticators) {
+ this(settings, null, authenticators);
+ }
+
+ public SecurityRealmFactory(Settings settings, SecurityRealm[] realms) {
+ this(settings, realms, null);
+ }
+
+ public SecurityRealmFactory(Settings settings) {
+ this(settings, null, null);
+ }
+
+ public void start() {
+ if (realm != null) {
+ try {
+ INFO.info("Security realm: " + realm.getName());
+ realm.init();
+ INFO.info("Security realm started");
+ } catch (RuntimeException e) {
+ if (ignoreStartupFailure) {
+ INFO.error("IGNORED - Security realm fails to start: " + e.getMessage());
+ } else {
+ throw new SonarException("Security realm fails to start: " + e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ public SecurityRealm getRealm() {
+ return realm;
+ }
+
+ private static SecurityRealm selectRealm(SecurityRealm[] realms, String realmName) {
+ if (realms != null) {
+ for (SecurityRealm realm : realms) {
+ if (StringUtils.equals(realmName, realm.getName())) {
+ return realm;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static LoginPasswordAuthenticator selectAuthenticator(LoginPasswordAuthenticator[] authenticators, String className) {
+ if (authenticators != null) {
+ for (LoginPasswordAuthenticator lpa : authenticators) {
+ if (lpa.getClass().getName().equals(className)) {
+ return lpa;
+ }
+ }
+ }
+ return null;
+ }
+
+}
import org.sonar.api.server.ws.Response;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.utils.text.XmlWriter;
+import org.sonar.server.plugins.MimeTypes;
import javax.annotation.CheckForNull;
import java.io.ByteArrayOutputStream;
@Override
public JsonWriter newJsonWriter() {
- stream.setMediaType("application/json");
+ stream.setMediaType(MimeTypes.JSON);
return JsonWriter.of(new OutputStreamWriter(stream.output()));
}
@Override
public XmlWriter newXmlWriter() {
- stream.setMediaType("application/xml");
+ stream.setMediaType(MimeTypes.XML);
return XmlWriter.of(new OutputStreamWriter(stream.output()));
}
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.exceptions.ServerException;
+import org.sonar.server.plugins.MimeTypes;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStreamWriter;
ServletResponse.ServletStream stream = response.stream();
stream.reset();
stream.setStatus(status);
- stream.setMediaType("application/json");
+ stream.setMediaType(MimeTypes.JSON);
JsonWriter json = JsonWriter.of(new OutputStreamWriter(stream.output()));
try {
json.beginObject();
end
def self.technical_debt
- component(Java::OrgSonarServerTechnicaldebt::InternalRubyTechnicalDebtService.java_class)
+ component(Java::OrgSonarServerTechnicaldebt::DebtService.java_class)
end
def self.profiling
end
def self.group_membership
- component(Java::OrgSonarServerGroup::InternalGroupMembershipService.java_class)
+ component(Java::OrgSonarServerUser::GroupMembershipService.java_class)
end
def self.quality_profiles
def system_info
system_info=[]
- add_property(system_info, 'System date') {java.util.Date.new()}
- add_property(system_info, 'JVM Vendor') {java.lang.management.ManagementFactory.getRuntimeMXBean().getVmVendor()}
- add_property(system_info, 'JVM Name') {java.lang.management.ManagementFactory.getRuntimeMXBean().getVmName()}
- add_property(system_info, 'JVM Version') {java.lang.management.ManagementFactory.getRuntimeMXBean().getVmVersion() }
- add_property(system_info, 'Java Version') {java_property('java.runtime.version') }
- add_property(system_info, 'Java Home') {java_property('java.home')}
- add_property(system_info, 'JIT Compiler') {java_property('java.compiler')}
- add_property(system_info, 'Application Server Container') {$servlet_context.getServerInfo() }
- add_property(system_info, 'User Name') {java_property('user.name')}
- add_property(system_info, 'User TimeZone') {java_property('user.timezone')}
- add_property(system_info, 'OS') {"#{java_property('os.name')} / #{java_property('os.arch')} / #{java_property('os.version')}"}
- add_property(system_info, 'Processors') {java.lang.Runtime.getRuntime().availableProcessors()}
- add_property(system_info, 'System Classpath') {java.lang.management.ManagementFactory.getRuntimeMXBean().getClassPath()}
- add_property(system_info, 'Boot Classpath') {java.lang.management.ManagementFactory.getRuntimeMXBean().getBootClassPath() }
- add_property(system_info, 'Library Path') {java.lang.management.ManagementFactory.getRuntimeMXBean().getLibraryPath() }
+ add_property(system_info, 'System date') { java.util.Date.new() }
+ add_property(system_info, 'JVM Vendor') { java.lang.management.ManagementFactory.getRuntimeMXBean().getVmVendor() }
+ add_property(system_info, 'JVM Name') { java.lang.management.ManagementFactory.getRuntimeMXBean().getVmName() }
+ add_property(system_info, 'JVM Version') { java.lang.management.ManagementFactory.getRuntimeMXBean().getVmVersion() }
+ add_property(system_info, 'Java Version') { java_property('java.runtime.version') }
+ add_property(system_info, 'Java Home') { java_property('java.home') }
+ add_property(system_info, 'JIT Compiler') { java_property('java.compiler') }
+ add_property(system_info, 'Application Server Container') { $servlet_context.getServerInfo() }
+ add_property(system_info, 'User Name') { java_property('user.name') }
+ add_property(system_info, 'User TimeZone') { java_property('user.timezone') }
+ add_property(system_info, 'OS') { "#{java_property('os.name')} / #{java_property('os.arch')} / #{java_property('os.version')}" }
+ add_property(system_info, 'Processors') { java.lang.Runtime.getRuntime().availableProcessors() }
+ add_property(system_info, 'System Classpath') { java.lang.management.ManagementFactory.getRuntimeMXBean().getClassPath() }
+ add_property(system_info, 'Boot Classpath') { java.lang.management.ManagementFactory.getRuntimeMXBean().getBootClassPath() }
+ add_property(system_info, 'Library Path') { java.lang.management.ManagementFactory.getRuntimeMXBean().getLibraryPath() }
system_info
end
def system_statistics
system_statistics=[]
- add_property(system_statistics, 'Total Memory') {"#{java.lang.Runtime.getRuntime().totalMemory() / 1000000} MB"}
- add_property(system_statistics, 'Free Memory') {"#{java.lang.Runtime.getRuntime().freeMemory() / 1000000} MB"}
- add_property(system_statistics, 'Max Memory') {"#{java.lang.Runtime.getRuntime().maxMemory() / 1000000} MB"}
- add_property(system_statistics, 'Heap') {"#{java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()}"}
- add_property(system_statistics, 'Non Heap') {"#{java.lang.management.ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()}"}
- add_property(system_statistics, 'System Load Average (last minute)') {system_load_average()}
- add_property(system_statistics, 'Loaded Classes (currently/total/unloaded)') {"#{java.lang.management.ManagementFactory.getClassLoadingMXBean().getLoadedClassCount()} / #{java.lang.management.ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount()} / #{java.lang.management.ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount()}"}
- add_property(system_statistics, 'Start Time') {"#{format_date(java.util.Date.new(java.lang.management.ManagementFactory.getRuntimeMXBean().getStartTime()))}"}
- add_property(system_statistics, 'Threads (total/peak/daemon)') {"#{java.lang.management.ManagementFactory.getThreadMXBean().getThreadCount()} / #{java.lang.management.ManagementFactory.getThreadMXBean().getPeakThreadCount()} / #{java.lang.management.ManagementFactory.getThreadMXBean().getDaemonThreadCount() }" }
+ add_property(system_statistics, 'Total Memory') { "#{java.lang.Runtime.getRuntime().totalMemory() / 1000000} MB" }
+ add_property(system_statistics, 'Free Memory') { "#{java.lang.Runtime.getRuntime().freeMemory() / 1000000} MB" }
+ add_property(system_statistics, 'Max Memory') { "#{java.lang.Runtime.getRuntime().maxMemory() / 1000000} MB" }
+ add_property(system_statistics, 'Heap') { "#{java.lang.management.ManagementFactory.getMemoryMXBean().getHeapMemoryUsage()}" }
+ add_property(system_statistics, 'Non Heap') { "#{java.lang.management.ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage()}" }
+ add_property(system_statistics, 'System Load Average (last minute)') { system_load_average() }
+ add_property(system_statistics, 'Loaded Classes (currently/total/unloaded)') { "#{java.lang.management.ManagementFactory.getClassLoadingMXBean().getLoadedClassCount()} / #{java.lang.management.ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount()} / #{java.lang.management.ManagementFactory.getClassLoadingMXBean().getUnloadedClassCount()}" }
+ add_property(system_statistics, 'Start Time') { "#{format_date(java.util.Date.new(java.lang.management.ManagementFactory.getRuntimeMXBean().getStartTime()))}" }
+ add_property(system_statistics, 'Threads (total/peak/daemon)') { "#{java.lang.management.ManagementFactory.getThreadMXBean().getThreadCount()} / #{java.lang.management.ManagementFactory.getThreadMXBean().getPeakThreadCount()} / #{java.lang.management.ManagementFactory.getThreadMXBean().getDaemonThreadCount() }" }
system_statistics
end
def sonar_info
sonar_info=[]
- add_property(sonar_info, 'Server ID') {sonar_property(ServerIdConfigurationController::PROPERTY_SERVER_ID)}
- add_property(sonar_info, 'Version') {org.sonar.server.platform.Platform.getServer().getVersion()}
- add_property(sonar_info, 'Started at') {org.sonar.server.platform.Platform.getServer().getStartedAt()}
- add_property(sonar_info, 'Database') {"#{jdbc_metadata. getDatabaseProductName()} #{jdbc_metadata. getDatabaseProductVersion()}"}
- add_property(sonar_info, 'Database URL') {sonar_property('sonar.jdbc.url')}
- add_property(sonar_info, 'Database Login') {sonar_property('sonar.jdbc.username')}
- add_property(sonar_info, 'Database Driver') {"#{jdbc_metadata.getDriverName()} #{jdbc_metadata.getDriverVersion()}"}
- add_property(sonar_info, 'Database Driver Class') {sonar_property('sonar.jdbc.driverClassName')}
- add_property(sonar_info, 'Database Dialect (Hibernate)') {"#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getId()} (#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getHibernateDialectClass().getName()})"}
- add_property(sonar_info, 'External User Authentication') {realm_name}
- add_property(sonar_info, 'Automatic User Creation') {sonar_property(org.sonar.api.CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS)}
- add_property(sonar_info, 'Allow Users to Sign Up') {sonar_property(org.sonar.api.CoreProperties.CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY)}
- add_property(sonar_info, 'Force Authentication') {sonar_property(org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY)}
+ add_property(sonar_info, 'Server ID') { sonar_property(ServerIdConfigurationController::PROPERTY_SERVER_ID) }
+ add_property(sonar_info, 'Version') { org.sonar.server.platform.Platform.getServer().getVersion() }
+ add_property(sonar_info, 'Started at') { org.sonar.server.platform.Platform.getServer().getStartedAt() }
+ add_property(sonar_info, 'Database') { "#{jdbc_metadata.getDatabaseProductName()} #{jdbc_metadata.getDatabaseProductVersion()}" }
+ add_property(sonar_info, 'Database URL') { sonar_property('sonar.jdbc.url') }
+ add_property(sonar_info, 'Database Login') { sonar_property('sonar.jdbc.username') }
+ add_property(sonar_info, 'Database Driver') { "#{jdbc_metadata.getDriverName()} #{jdbc_metadata.getDriverVersion()}" }
+ add_property(sonar_info, 'Database Driver Class') { sonar_property('sonar.jdbc.driverClassName') }
+ add_property(sonar_info, 'Database Dialect (Hibernate)') { "#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getId()} (#{Java::OrgSonarServerUi::JRubyFacade.getInstance().getDatabase().getDialect().getHibernateDialectClass().getName()})" }
+ add_property(sonar_info, 'External User Authentication') { realm_name }
+ add_property(sonar_info, 'Automatic User Creation') { sonar_property(org.sonar.api.CoreProperties.CORE_AUTHENTICATOR_CREATE_USERS) }
+ add_property(sonar_info, 'Allow Users to Sign Up') { sonar_property(org.sonar.api.CoreProperties.CORE_ALLOW_USERS_TO_SIGNUP_PROPERTY) }
+ add_property(sonar_info, 'Force Authentication') { sonar_property(org.sonar.api.CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY) }
sonar_info
end
def sonar_plugins
sonar_plugins=[]
- Java::OrgSonarServerUi::JRubyFacade.getInstance().getPluginsMetadata().select{|plugin| !plugin.isCore()}.sort.each do |plugin|
- add_property(sonar_plugins, plugin.getName()) {plugin.getVersion()}
+ Java::OrgSonarServerUi::JRubyFacade.getInstance().getPluginsMetadata().select { |plugin| !plugin.isCore() }.sort.each do |plugin|
+ add_property(sonar_plugins, plugin.getName()) { plugin.getVersion() }
end
sonar_plugins
end
system_properties=[]
keys=java.lang.System.getProperties().keySet().sort
keys.each do |key|
- add_property(system_properties, key) {java.lang.System.getProperty(key)}
+ add_property(system_properties, key) { java.lang.System.getProperty(key) }
end
system_properties
end
-
private
def java_property(key)
end
def format_double(d)
- (d * 10).to_i / 10.0
+ (d * 10).to_i / 10.0
end
def format_date(date)
end
def realm_name
- realm_factory = Api::Utils.java_facade.getCoreComponentByClassname('org.sonar.server.ui.SecurityRealmFactory')
+ realm_factory = Api::Utils.java_facade.getCoreComponentByClassname('org.sonar.server.user.SecurityRealmFactory')
if realm_factory && realm_factory.getRealm()
realm_factory.getRealm().getName()
else
def self.realm
if @@realm.nil?
- realm_factory = Api::Utils.java_facade.getCoreComponentByClassname('org.sonar.server.ui.SecurityRealmFactory')
+ realm_factory = Api::Utils.java_facade.getCoreComponentByClassname('org.sonar.server.user.SecurityRealmFactory')
if realm_factory
component = realm_factory.getRealm()
@@realm = component ? PluginRealm.new(component) : DefaultRealm.new
</filter>
<filter>
<filter-name>DatabaseSessionFilter</filter-name>
- <filter-class>org.sonar.server.ui.DatabaseSessionFilter</filter-class>
+ <filter-class>org.sonar.server.user.DatabaseSessionFilter</filter-class>
</filter>
<filter>
<filter-name>UserSessionFilter</filter-name>
package org.sonar.server.db;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class EmbeddedDatabaseFactoryTest {
- private Settings settings;
-
- @Before
- public void initSettings() {
- settings = new Settings();
- }
+ Settings settings = new Settings();
@Test
public void should_start_and_stop_tcp_h2_database() throws Exception {
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.group;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.core.user.*;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class GroupMembershipFinderTest {
-
- @Mock
- UserDao userDao;
-
- @Mock
- GroupMembershipDao groupMembershipDao;
-
- GroupMembershipFinder finder;
-
- @Before
- public void setUp() throws Exception {
- when(userDao.selectActiveUserByLogin("arthur")).thenReturn(new UserDto().setId(100L).setName("arthur"));
- finder = new GroupMembershipFinder(userDao, groupMembershipDao);
- }
-
- @Test
- public void find() throws Exception {
- GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").build();
- when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(
- newArrayList(new GroupMembershipDto().setId(1L).setName("users").setUserId(100L))
- );
-
- GroupMembershipQueryResult result = finder.find(query);
- assertThat(result.groups()).hasSize(1);
- assertThat(result.hasMoreResults()).isFalse();
-
- GroupMembership group = result.groups().get(0);
- assertThat(group.id()).isEqualTo(1);
- assertThat(group.name()).isEqualTo("users");
- assertThat(group.isMember()).isTrue();
- }
-
- @Test
- public void find_with_paging() throws Exception {
- GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(3).pageSize(10).build();
- finder.find(query);
-
- ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
- ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
- verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
-
- assertThat(argumentOffset.getValue()).isEqualTo(20);
- assertThat(argumentLimit.getValue()).isEqualTo(11);
- }
-
- @Test
- public void find_with_paging_having_more_results() throws Exception {
- GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(1).pageSize(2).build();
- when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(newArrayList(
- new GroupMembershipDto().setId(1L).setName("group1"),
- new GroupMembershipDto().setId(2L).setName("group2"),
- new GroupMembershipDto().setId(3L).setName("group3"))
- );
- GroupMembershipQueryResult result = finder.find(query);
-
- ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
- ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
- verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
-
- assertThat(argumentOffset.getValue()).isEqualTo(0);
- assertThat(argumentLimit.getValue()).isEqualTo(3);
- assertThat(result.hasMoreResults()).isTrue();
- }
-
- @Test
- public void find_with_paging_having_no_more_results() throws Exception {
- GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(1).pageSize(10).build();
- when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(newArrayList(
- new GroupMembershipDto().setId(1L).setName("group1"),
- new GroupMembershipDto().setId(2L).setName("group2"),
- new GroupMembershipDto().setId(3L).setName("group3"),
- new GroupMembershipDto().setId(4L).setName("group4"))
- );
- GroupMembershipQueryResult result = finder.find(query);
-
- ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
- ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
- verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
-
- assertThat(argumentOffset.getValue()).isEqualTo(0);
- assertThat(argumentLimit.getValue()).isEqualTo(11);
- assertThat(result.hasMoreResults()).isFalse();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.group;
-
-import com.google.common.collect.ImmutableMap;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.core.persistence.AbstractDaoTestCase;
-import org.sonar.core.user.GroupMembership;
-import org.sonar.core.user.GroupMembershipDao;
-import org.sonar.core.user.UserDao;
-import org.sonar.server.exceptions.NotFoundException;
-
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
-
-/**
- * Use BbUnit tests because there's no IT on this feature for the moment
- */
-public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
-
- private InternalGroupMembershipService service;
-
- @Before
- public void before() throws Exception {
- GroupMembershipDao groupMembershipDao = new GroupMembershipDao(getMyBatis());
- UserDao userDao = new UserDao(getMyBatis());
- GroupMembershipFinder finder = new GroupMembershipFinder(userDao, groupMembershipDao);
- service = new InternalGroupMembershipService(finder);
- }
-
- @Test
- public void find_all_member_groups() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "all"));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(3);
- check(result.get(0), "sonar-administrators", false);
- check(result.get(1), "sonar-reviewers", false);
- check(result.get(2), "sonar-users", true);
- }
-
- @Test
- public void find_all_member_groups_when_no_selected_parameter() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1"));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(3);
- check(result.get(0), "sonar-administrators", false);
- check(result.get(1), "sonar-reviewers", false);
- check(result.get(2), "sonar-users", true);
- }
-
- @Test
- public void find_member_groups() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "selected"));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(1);
- check(result.get(0), "sonar-users", true);
- }
-
- @Test
- public void find_not_member_groups() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "deselected"));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(2);
- check(result.get(0), "sonar-administrators", false);
- check(result.get(1), "sonar-reviewers", false);
- }
-
- @Test
- public void find_with_paging_with_more_results() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "all",
- "page", 1,
- "pageSize", 2
- ));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(2);
- assertThat(queryResult.hasMoreResults()).isTrue();
- }
-
- @Test
- public void find_with_paging_with_no_more_results() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "all",
- "page", 3,
- "pageSize", 1
- ));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(1);
- assertThat(queryResult.hasMoreResults()).isFalse();
- }
-
- @Test
- public void fail_if_user_not_found() {
- setupData("shared");
-
- try {
- service.find(ImmutableMap.<String, Object>of(
- "user", "user_not_existing",
- "selected", "all"));
- fail();
- } catch (Exception e) {
- assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("User 'user_not_existing' does not exists.");
- }
- }
-
- @Test
- public void find_matched_groups_name() {
- setupData("shared");
-
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "all",
- "query", "user"));
- List<GroupMembership> result = queryResult.groups();
- assertThat(result).hasSize(1);
- check(result.get(0), "sonar-users", true);
-
- queryResult = service.find(ImmutableMap.<String, Object>of(
- "user", "user1",
- "selected", "all",
- "query", "sonar"));
- result = queryResult.groups();
- assertThat(result).hasSize(3);
- }
-
- private void check(GroupMembership groupMembership, String expectedName, boolean isMember) {
- assertThat(groupMembership.name()).isEqualTo(expectedName);
- assertThat(groupMembership.isMember()).isEqualTo(isMember);
- }
-}
import org.sonar.api.issue.internal.FieldDiffs;
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.core.i18n.DefaultI18n;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import java.util.List;
import java.util.Locale;
private static final Locale DEFAULT_LOCALE = Locale.getDefault();
@Mock
- private DefaultI18n defaultI18n;
+ private DefaultI18n i18n;
@Mock
- private TechnicalDebtFormatter technicalDebtFormatter;
+ private DebtFormatter debtFormatter;
private IssueChangelogFormatter formatter;
@Before
- public void before(){
- formatter = new IssueChangelogFormatter(defaultI18n, technicalDebtFormatter);
+ public void before() {
+ formatter = new IssueChangelogFormatter(i18n, debtFormatter);
}
@Test
- public void format_field_diffs_with_new_and_old_value(){
+ public void format_field_diffs_with_new_and_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "BLOCKER", "INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_field_diffs_with_only_new_value(){
+ public void format_field_diffs_with_only_new_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", null, "INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_field_diffs_with_only_old_value(){
+ public void format_field_diffs_with_only_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "BLOCKER", null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_field_diffs_without_value(){
+ public void format_field_diffs_without_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", null, null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_field_diffs_with_empty_old_value(){
+ public void format_field_diffs_with_empty_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "", null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_technical_debt_with_old_and_new_value(){
+ public void format_technical_debt_with_old_and_new_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", "500", "10000");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 5, 0))).thenReturn("5 hours");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 5, 0))).thenReturn("5 hours");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_technical_debt_with_new_value_only(){
+ public void format_technical_debt_with_new_value_only() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", null, "10000");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
}
@Test
- public void format_technical_debt_without_value(){
+ public void format_technical_debt_without_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", null, null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
import org.sonar.server.issue.IssueChangelog;
import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueService;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import org.sonar.server.user.MockUserSession;
import org.sonar.server.user.UserSession;
ActionService actionService;
@Mock
- TechnicalDebtFormatter technicalDebtFormatter;
+ DebtFormatter debtFormatter;
@Mock
DefaultTechnicalDebtManager technicalDebtManager;
when(i18n.message(any(Locale.class), eq("created"), eq((String) null))).thenReturn("Created");
- tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtFormatter, technicalDebtManager, i18n)));
+ tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, debtFormatter, technicalDebtManager, i18n)));
}
@Test
.setTechnicalDebt(technicalDebt);
issues.add(issue);
- when(technicalDebtFormatter.format(any(Locale.class), eq(technicalDebt))).thenReturn("2 hours 1 minutes");
+ when(debtFormatter.format(any(Locale.class), eq(technicalDebt))).thenReturn("2 hours 1 minutes");
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.startup;
+
+import org.junit.Test;
+import org.sonar.core.preview.PreviewCache;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class CleanPreviewAnalysisCacheTest {
+ @Test
+ public void clean_cache_on_startup() throws Exception {
+ PreviewCache cache = mock(PreviewCache.class);
+ CleanPreviewAnalysisCache cleaner = new CleanPreviewAnalysisCache(cache);
+
+ cleaner.start();
+ verify(cache).cleanAll();
+ cleaner.stop();
+ }
+}
import java.util.Date;
import java.util.TimeZone;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class ServerMetadataPersisterTest {
- private TimeZone initialTimeZone;
- private PersistentSettings persistentSettings;
+ TimeZone initialTimeZone;
+ PersistentSettings persistentSettings;
@Before
public void fixTimeZone() {
persister.start();
verify(persistentSettings).saveProperties(ImmutableMap.of(
- CoreProperties.SERVER_ID, "123",
- CoreProperties.SERVER_VERSION, "3.2",
- CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"));
+ CoreProperties.SERVER_ID, "123",
+ CoreProperties.SERVER_VERSION, "3.2",
+ CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"));
+
+ persister.stop();
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.technicaldebt;
+
+import org.junit.Test;
+import org.sonar.api.issue.internal.WorkDayDuration;
+import org.sonar.core.i18n.DefaultI18n;
+
+import java.util.Locale;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class DebtFormatterTest {
+
+ private static final Locale DEFAULT_LOCALE = Locale.getDefault();
+
+ DefaultI18n i18n = mock(DefaultI18n.class);
+ DebtFormatter formatter = new DebtFormatter(i18n);
+
+ @Test
+ public void format() {
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_days", null, 5)).thenReturn("5 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_hours", null, 2)).thenReturn("2 hours");
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_minutes", null, 1)).thenReturn("1 minutes");
+
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 5))).isEqualTo("5 days");
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 0))).isEqualTo("2 hours");
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 0, 0))).isEqualTo("1 minutes");
+
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 5))).isEqualTo("5 days 2 hours");
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 0))).isEqualTo("2 hours 1 minutes");
+ assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 5))).isEqualTo("5 days 2 hours");
+ }
+
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.technicaldebt;
+
+import org.junit.Test;
+import org.sonar.api.issue.internal.WorkDayDuration;
+import org.sonar.api.rules.Rule;
+import org.sonar.api.technicaldebt.server.Characteristic;
+import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
+import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
+
+import java.util.List;
+import java.util.Locale;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+public class DebtServiceTest {
+
+ DebtFormatter debtFormatter = mock(DebtFormatter.class);
+ DefaultTechnicalDebtManager finder = mock(DefaultTechnicalDebtManager.class);
+ DebtService service = new DebtService(debtFormatter, finder);
+
+ @Test
+ public void format() {
+ WorkDayDuration technicalDebt = WorkDayDuration.of(5, 0, 0);
+ service.format(technicalDebt);
+ verify(debtFormatter).format(any(Locale.class), eq(technicalDebt));
+ }
+
+ @Test
+ public void to_technical_debt() {
+ assertThat(service.toTechnicalDebt("500")).isEqualTo(WorkDayDuration.of(0, 5, 0));
+ }
+
+ @Test
+ public void find_root_characteristics() {
+ List<Characteristic> rootCharacteristics = newArrayList();
+ when(finder.findRootCharacteristics()).thenReturn(rootCharacteristics);
+ assertThat(service.findRootCharacteristics()).isEqualTo(rootCharacteristics);
+ }
+
+ @Test
+ public void find_requirement() {
+ Rule rule = Rule.create("repo", "key");
+ Characteristic requirement = new DefaultCharacteristic();
+ when(finder.findRequirementByRule(rule)).thenReturn(requirement);
+ assertThat(service.findRequirement(rule)).isEqualTo(requirement);
+ }
+
+ @Test
+ public void find_characteristic() {
+ Characteristic characteristic = new DefaultCharacteristic();
+ when(finder.findCharacteristicById(1)).thenReturn(characteristic);
+ assertThat(service.findCharacteristic(1)).isEqualTo(characteristic);
+ }
+
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.technicaldebt;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.issue.internal.WorkDayDuration;
-import org.sonar.api.rules.Rule;
-import org.sonar.api.technicaldebt.server.Characteristic;
-import org.sonar.api.technicaldebt.server.internal.DefaultCharacteristic;
-import org.sonar.core.technicaldebt.DefaultTechnicalDebtManager;
-
-import java.util.List;
-import java.util.Locale;
-
-import static com.google.common.collect.Lists.newArrayList;
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class InternalRubyTechnicalDebtServiceTest {
-
- @Mock
- TechnicalDebtFormatter technicalDebtFormatter;
-
- @Mock
- DefaultTechnicalDebtManager finder;
-
- private InternalRubyTechnicalDebtService service;
-
- @Before
- public void before() {
- service = new InternalRubyTechnicalDebtService(technicalDebtFormatter, finder);
- }
-
- @Test
- public void format() {
- WorkDayDuration technicalDebt = WorkDayDuration.of(5, 0, 0);
- service.format(technicalDebt);
- verify(technicalDebtFormatter).format(any(Locale.class), eq(technicalDebt));
- }
-
- @Test
- public void to_technical_debt() {
- assertThat(service.toTechnicalDebt("500")).isEqualTo(WorkDayDuration.of(0, 5, 0));
- }
-
- @Test
- public void find_root_characteristics() {
- List<Characteristic> rootCharacteristics = newArrayList();
- when(finder.findRootCharacteristics()).thenReturn(rootCharacteristics);
- assertThat(service.findRootCharacteristics()).isEqualTo(rootCharacteristics);
- }
-
- @Test
- public void find_requirement() {
- Rule rule = Rule.create("repo", "key");
- Characteristic requirement = new DefaultCharacteristic();
- when(finder.findRequirementByRule(rule)).thenReturn(requirement);
- assertThat(service.findRequirement(rule)).isEqualTo(requirement);
- }
-
- @Test
- public void find_characteristic() {
- Characteristic characteristic = new DefaultCharacteristic();
- when(finder.findCharacteristicById(1)).thenReturn(characteristic);
- assertThat(service.findCharacteristic(1)).isEqualTo(characteristic);
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.technicaldebt;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
-import org.sonar.api.issue.internal.WorkDayDuration;
-import org.sonar.core.i18n.DefaultI18n;
-
-import java.util.Locale;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.when;
-
-@RunWith(MockitoJUnitRunner.class)
-public class TechnicalDebtFormatterTest {
-
- private static final Locale DEFAULT_LOCALE = Locale.getDefault();
-
- @Mock
- private DefaultI18n defaultI18n;
-
- private TechnicalDebtFormatter formatter;
-
- @Before
- public void before() {
- formatter = new TechnicalDebtFormatter(defaultI18n);
- }
-
- @Test
- public void format() {
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_days", null, 5)).thenReturn("5 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_hours", null, 2)).thenReturn("2 hours");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_minutes", null, 1)).thenReturn("1 minutes");
-
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 5))).isEqualTo("5 days");
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 0))).isEqualTo("2 hours");
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 0, 0))).isEqualTo("1 minutes");
-
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 5))).isEqualTo("5 days 2 hours");
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 0))).isEqualTo("2 hours 1 minutes");
- assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(1, 2, 5))).isEqualTo("5 days 2 hours");
- }
-
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.ui;
-
-import org.junit.Test;
-import org.sonar.api.security.LoginPasswordAuthenticator;
-
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-public class CompatibilityRealmTest {
-
- @Test
- public void shouldDelegate() {
- LoginPasswordAuthenticator authenticator = mock(LoginPasswordAuthenticator.class);
- CompatibilityRealm realm = new CompatibilityRealm(authenticator);
- realm.init();
- verify(authenticator).init();
- assertThat(realm.getLoginPasswordAuthenticator(), is(authenticator));
- assertThat(realm.getName(), is("CompatibilityRealm[" + authenticator.getClass().getName() + "]"));
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 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.ui;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.config.Settings;
-import org.sonar.api.security.LoginPasswordAuthenticator;
-import org.sonar.api.security.SecurityRealm;
-import org.sonar.api.utils.SonarException;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-public class SecurityRealmFactoryTest {
-
- private Settings settings;
-
- @Before
- public void setUp() {
- settings = new Settings();
- }
-
- /**
- * Typical usage.
- */
- @Test
- public void should_select_realm_and_start() {
- SecurityRealm realm = spy(new FakeRealm());
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
-
- SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm});
- factory.start();
- assertThat(factory.getRealm(), is(realm));
- verify(realm).init();
- }
-
- @Test
- public void do_not_fail_if_no_realms() {
- SecurityRealmFactory factory = new SecurityRealmFactory(settings);
- factory.start();
- assertThat(factory.getRealm(), nullValue());
- }
-
- @Test
- public void realm_not_found() {
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, "Fake");
-
- try {
- new SecurityRealmFactory(settings);
- fail();
- } catch (SonarException e) {
- assertThat(e.getMessage(), containsString("Realm 'Fake' not found."));
- }
- }
-
- @Test
- public void should_provide_compatibility_for_authenticator() {
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
- LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
-
- SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[]{authenticator});
- SecurityRealm realm = factory.getRealm();
- assertThat(realm, instanceOf(CompatibilityRealm.class));
- }
-
- @Test
- public void should_take_precedence_over_authenticator() {
- SecurityRealm realm = new FakeRealm();
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
- LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
-
- SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm},
- new LoginPasswordAuthenticator[]{authenticator});
- assertThat(factory.getRealm(), is(realm));
- }
-
- @Test
- public void authenticator_not_found() {
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, "Fake");
-
- try {
- new SecurityRealmFactory(settings);
- fail();
- } catch (SonarException e) {
- assertThat(e.getMessage(), containsString("Authenticator 'Fake' not found."));
- }
- }
-
- @Test
- public void ignore_startup_failure() {
- SecurityRealm realm = spy(new AlwaysFailsRealm());
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
-
- new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
- verify(realm).init();
- }
-
- @Test
- public void should_fail() {
- SecurityRealm realm = spy(new AlwaysFailsRealm());
- settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
-
- try {
- new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
- fail();
- } catch (SonarException e) {
- assertThat(e.getCause(), instanceOf(IllegalStateException.class));
- assertThat(e.getMessage(), containsString("Security realm fails to start"));
- }
- }
-
- private static class AlwaysFailsRealm extends FakeRealm {
- @Override
- public void init() {
- throw new IllegalStateException();
- }
- }
-
- private static class FakeRealm extends SecurityRealm {
- @Override
- public LoginPasswordAuthenticator getLoginPasswordAuthenticator() {
- return null;
- }
- }
-
- private static class FakeAuthenticator implements LoginPasswordAuthenticator {
- public void init() {
- }
-
- public boolean authenticate(String login, String password) {
- return false;
- }
- }
-
-}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.junit.Test;
+import org.sonar.api.security.LoginPasswordAuthenticator;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class CompatibilityRealmTest {
+
+ @Test
+ public void shouldDelegate() {
+ LoginPasswordAuthenticator authenticator = mock(LoginPasswordAuthenticator.class);
+ CompatibilityRealm realm = new CompatibilityRealm(authenticator);
+ realm.init();
+ verify(authenticator).init();
+ assertThat(realm.getLoginPasswordAuthenticator(), is(authenticator));
+ assertThat(realm.getName(), is("CompatibilityRealm[" + authenticator.getClass().getName() + "]"));
+ }
+
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.sonar.core.user.*;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
+
+public class GroupMembershipFinderTest {
+
+ UserDao userDao = mock(UserDao.class);
+ GroupMembershipDao groupMembershipDao = mock(GroupMembershipDao.class);
+ GroupMembershipFinder finder;
+
+ @Before
+ public void setUp() throws Exception {
+ when(userDao.selectActiveUserByLogin("arthur")).thenReturn(new UserDto().setId(100L).setName("arthur"));
+ finder = new GroupMembershipFinder(userDao, groupMembershipDao);
+ }
+
+ @Test
+ public void find() throws Exception {
+ GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").build();
+ when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(
+ newArrayList(new GroupMembershipDto().setId(1L).setName("users").setUserId(100L))
+ );
+
+ GroupMembershipFinder.Membership result = finder.find(query);
+ assertThat(result.groups()).hasSize(1);
+ assertThat(result.hasMoreResults()).isFalse();
+
+ GroupMembership group = result.groups().get(0);
+ assertThat(group.id()).isEqualTo(1);
+ assertThat(group.name()).isEqualTo("users");
+ assertThat(group.isMember()).isTrue();
+ }
+
+ @Test
+ public void find_with_paging() throws Exception {
+ GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(3).pageSize(10).build();
+ finder.find(query);
+
+ ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
+ ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
+ verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
+
+ assertThat(argumentOffset.getValue()).isEqualTo(20);
+ assertThat(argumentLimit.getValue()).isEqualTo(11);
+ }
+
+ @Test
+ public void find_with_paging_having_more_results() throws Exception {
+ GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(1).pageSize(2).build();
+ when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(newArrayList(
+ new GroupMembershipDto().setId(1L).setName("group1"),
+ new GroupMembershipDto().setId(2L).setName("group2"),
+ new GroupMembershipDto().setId(3L).setName("group3"))
+ );
+ GroupMembershipFinder.Membership result = finder.find(query);
+
+ ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
+ ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
+ verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
+
+ assertThat(argumentOffset.getValue()).isEqualTo(0);
+ assertThat(argumentLimit.getValue()).isEqualTo(3);
+ assertThat(result.hasMoreResults()).isTrue();
+ }
+
+ @Test
+ public void find_with_paging_having_no_more_results() throws Exception {
+ GroupMembershipQuery query = GroupMembershipQuery.builder().login("arthur").pageIndex(1).pageSize(10).build();
+ when(groupMembershipDao.selectGroups(eq(query), anyLong(), anyInt(), anyInt())).thenReturn(newArrayList(
+ new GroupMembershipDto().setId(1L).setName("group1"),
+ new GroupMembershipDto().setId(2L).setName("group2"),
+ new GroupMembershipDto().setId(3L).setName("group3"),
+ new GroupMembershipDto().setId(4L).setName("group4"))
+ );
+ GroupMembershipFinder.Membership result = finder.find(query);
+
+ ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
+ ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
+ verify(groupMembershipDao).selectGroups(eq(query), anyLong(), argumentOffset.capture(), argumentLimit.capture());
+
+ assertThat(argumentOffset.getValue()).isEqualTo(0);
+ assertThat(argumentLimit.getValue()).isEqualTo(11);
+ assertThat(result.hasMoreResults()).isFalse();
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.sonar.core.persistence.AbstractDaoTestCase;
+import org.sonar.core.user.GroupMembership;
+import org.sonar.core.user.GroupMembershipDao;
+import org.sonar.core.user.UserDao;
+import org.sonar.server.exceptions.NotFoundException;
+
+import java.util.List;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.fest.assertions.Fail.fail;
+
+/**
+ * Use BbUnit tests because there's no IT on this feature for the moment
+ */
+public class GroupMembershipServiceTest extends AbstractDaoTestCase {
+
+ GroupMembershipService service;
+
+ @Before
+ public void before() throws Exception {
+ GroupMembershipDao membershipDao = new GroupMembershipDao(getMyBatis());
+ UserDao userDao = new UserDao(getMyBatis());
+ GroupMembershipFinder finder = new GroupMembershipFinder(userDao, membershipDao);
+ service = new GroupMembershipService(finder);
+ }
+
+ @Test
+ public void find_all_member_groups() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "all"));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(3);
+ check(result.get(0), "sonar-administrators", false);
+ check(result.get(1), "sonar-reviewers", false);
+ check(result.get(2), "sonar-users", true);
+ }
+
+ @Test
+ public void find_all_member_groups_when_no_selected_parameter() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1"));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(3);
+ check(result.get(0), "sonar-administrators", false);
+ check(result.get(1), "sonar-reviewers", false);
+ check(result.get(2), "sonar-users", true);
+ }
+
+ @Test
+ public void find_member_groups() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "selected"));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(1);
+ check(result.get(0), "sonar-users", true);
+ }
+
+ @Test
+ public void find_not_member_groups() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "deselected"));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(2);
+ check(result.get(0), "sonar-administrators", false);
+ check(result.get(1), "sonar-reviewers", false);
+ }
+
+ @Test
+ public void find_with_paging_with_more_results() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "all",
+ "page", 1,
+ "pageSize", 2
+ ));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(2);
+ assertThat(queryResult.hasMoreResults()).isTrue();
+ }
+
+ @Test
+ public void find_with_paging_with_no_more_results() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "all",
+ "page", 3,
+ "pageSize", 1
+ ));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(1);
+ assertThat(queryResult.hasMoreResults()).isFalse();
+ }
+
+ @Test
+ public void fail_if_user_not_found() {
+ setupData("shared");
+
+ try {
+ service.find(ImmutableMap.<String, Object>of(
+ "user", "user_not_existing",
+ "selected", "all"));
+ fail();
+ } catch (Exception e) {
+ assertThat(e).isInstanceOf(NotFoundException.class).hasMessage("User 'user_not_existing' does not exists.");
+ }
+ }
+
+ @Test
+ public void find_matched_groups_name() {
+ setupData("shared");
+
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "all",
+ "query", "user"));
+ List<GroupMembership> result = queryResult.groups();
+ assertThat(result).hasSize(1);
+ check(result.get(0), "sonar-users", true);
+
+ queryResult = service.find(ImmutableMap.<String, Object>of(
+ "user", "user1",
+ "selected", "all",
+ "query", "sonar"));
+ result = queryResult.groups();
+ assertThat(result).hasSize(3);
+ }
+
+ private void check(GroupMembership groupMembership, String expectedName, boolean isMember) {
+ assertThat(groupMembership.name()).isEqualTo(expectedName);
+ assertThat(groupMembership.isMember()).isEqualTo(isMember);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 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.user;
+
+import org.junit.Test;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.config.Settings;
+import org.sonar.api.security.LoginPasswordAuthenticator;
+import org.sonar.api.security.SecurityRealm;
+import org.sonar.api.utils.SonarException;
+
+import static org.fest.assertions.Assertions.assertThat;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+
+public class SecurityRealmFactoryTest {
+
+ Settings settings = new Settings();
+
+ /**
+ * Typical usage.
+ */
+ @Test
+ public void should_select_realm_and_start() {
+ SecurityRealm realm = spy(new FakeRealm());
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
+
+ SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm});
+ factory.start();
+ assertThat(factory.getRealm()).isSameAs(realm);
+ verify(realm).init();
+ }
+
+ @Test
+ public void do_not_fail_if_no_realms() {
+ SecurityRealmFactory factory = new SecurityRealmFactory(settings);
+ factory.start();
+ assertThat(factory.getRealm()).isNull();
+ }
+
+ @Test
+ public void realm_not_found() {
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, "Fake");
+
+ try {
+ new SecurityRealmFactory(settings);
+ fail();
+ } catch (SonarException e) {
+ assertThat(e.getMessage()).contains("Realm 'Fake' not found.");
+ }
+ }
+
+ @Test
+ public void should_provide_compatibility_for_authenticator() {
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
+ LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
+
+ SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[]{authenticator});
+ SecurityRealm realm = factory.getRealm();
+ assertThat(realm).isInstanceOf(CompatibilityRealm.class);
+ }
+
+ @Test
+ public void should_take_precedence_over_authenticator() {
+ SecurityRealm realm = new FakeRealm();
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
+ LoginPasswordAuthenticator authenticator = new FakeAuthenticator();
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
+
+ SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm},
+ new LoginPasswordAuthenticator[]{authenticator});
+ assertThat(factory.getRealm()).isSameAs(realm);
+ }
+
+ @Test
+ public void authenticator_not_found() {
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, "Fake");
+
+ try {
+ new SecurityRealmFactory(settings);
+ fail();
+ } catch (SonarException e) {
+ assertThat(e.getMessage()).contains("Authenticator 'Fake' not found.");
+ }
+ }
+
+ @Test
+ public void ignore_startup_failure() {
+ SecurityRealm realm = spy(new AlwaysFailsRealm());
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_IGNORE_STARTUP_FAILURE, true);
+
+ new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
+ verify(realm).init();
+ }
+
+ @Test
+ public void should_fail() {
+ SecurityRealm realm = spy(new AlwaysFailsRealm());
+ settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_REALM, realm.getName());
+
+ try {
+ new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
+ fail();
+ } catch (SonarException e) {
+ assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Security realm fails to start");
+ }
+ }
+
+ private static class AlwaysFailsRealm extends FakeRealm {
+ @Override
+ public void init() {
+ throw new IllegalStateException();
+ }
+ }
+
+ private static class FakeRealm extends SecurityRealm {
+ @Override
+ public LoginPasswordAuthenticator getLoginPasswordAuthenticator() {
+ return null;
+ }
+ }
+
+ private static class FakeAuthenticator implements LoginPasswordAuthenticator {
+ public void init() {
+ }
+
+ public boolean authenticate(String login, String password) {
+ return false;
+ }
+ }
+
+}
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.utils.text.XmlWriter;
+import org.sonar.server.plugins.MimeTypes;
import javax.annotation.CheckForNull;
assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unexpected\"}]}");
assertThat(response.stream().httpStatus()).isEqualTo(500);
- assertThat(response.stream().mediaType()).isEqualTo("application/json");
+ assertThat(response.stream().mediaType()).isEqualTo(MimeTypes.JSON);
}
static class SystemWebService implements WebService {
+++ /dev/null
-<dataset>
-
- <groups id="100" name="sonar-administrators"/>
- <groups id="101" name="sonar-users" />
- <groups id="102" name="sonar-reviewers" />
-
- <!-- user 1 is in users group -->
- <groups_users user_id="200" group_id="101"/>
-
- <!-- user 2 is in all groups -->
- <groups_users user_id="201" group_id="100"/>
- <groups_users user_id="201" group_id="101"/>
- <groups_users user_id="201" group_id="102"/>
-
- <!-- user 3 is in no group -->
-
-
- <users id="200" login="user1" name="user1"/>
- <users id="201" login="user2" name="user2"/>
- <users id="202" login="user3" name="user3"/>
-
-</dataset>
--- /dev/null
+<dataset>
+
+ <groups id="100" name="sonar-administrators"/>
+ <groups id="101" name="sonar-users"/>
+ <groups id="102" name="sonar-reviewers"/>
+
+ <!-- user 1 is in users group -->
+ <groups_users user_id="200" group_id="101"/>
+
+ <!-- user 2 is in all groups -->
+ <groups_users user_id="201" group_id="100"/>
+ <groups_users user_id="201" group_id="101"/>
+ <groups_users user_id="201" group_id="102"/>
+
+ <!-- user 3 is in no group -->
+
+
+ <users id="200" login="user1" name="user1"/>
+ <users id="201" login="user2" name="user2"/>
+ <users id="202" login="user3" name="user3"/>
+
+</dataset>