From 5214de8cc260b47b130d863ddeba87b7d204239b Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 28 Apr 2014 13:02:29 +0200 Subject: [PATCH] SONAR-5237 - moved DB part of stack to sonar-core --- .../cluster/LocalNonBlockingWorkQueue.java | 23 +- .../org/sonar/core}/cluster/WorkQueue.java | 2 +- .../main/java/org/sonar/core}/db/BaseDao.java | 49 +-- .../src/main/java/org/sonar/core}/db/Dao.java | 6 +- .../src/main/java/org/sonar/core}/db/Dto.java | 2 +- .../org/sonar/core/rule/RuleConstants.java | 26 ++ .../java/org/sonar/core/rule/RuleDao.java | 51 +-- .../java/org/sonar/core/rule/RuleDto.java | 11 +- .../java/org/sonar/core/rule/RuleMapper.java | 4 +- .../LocalNonBlockingWorkQueueTest.java | 4 +- .../java/org/sonar/core/rule/RuleDaoTest.java | 7 +- .../org/sonar/server/rule2/RuleConstants.java | 7 - .../java/org/sonar/server/rule2/RuleDao.java | 26 -- .../java/org/sonar/server/rule2/RuleDto.java | 344 ------------------ .../java/org/sonar/server/rule2/RuleImpl.java | 19 + .../org/sonar/server/rule2/RuleIndex.java | 34 +- .../org/sonar/server/rule2/RuleQuery.java | 19 + .../org/sonar/server/rule2/RuleService.java | 2 + .../org/sonar/server/search/BaseIndex.java | 5 +- .../server/search/IndexSynchronizer.java | 3 +- .../sonar/server/rule/RegisterRulesTest.java | 12 +- .../org/sonar/server/rule2/RuleIndexTest.java | 2 +- .../sonar/server/search/BaseIndexTest.java | 3 +- 23 files changed, 213 insertions(+), 448 deletions(-) rename {sonar-server/src/main/java/org/sonar/server => sonar-core/src/main/java/org/sonar/core}/cluster/LocalNonBlockingWorkQueue.java (68%) rename {sonar-server/src/main/java/org/sonar/server => sonar-core/src/main/java/org/sonar/core}/cluster/WorkQueue.java (97%) rename {sonar-server/src/main/java/org/sonar/server => sonar-core/src/main/java/org/sonar/core}/db/BaseDao.java (73%) rename {sonar-server/src/main/java/org/sonar/server => sonar-core/src/main/java/org/sonar/core}/db/Dao.java (93%) rename {sonar-server/src/main/java/org/sonar/server => sonar-core/src/main/java/org/sonar/core}/db/Dto.java (97%) create mode 100644 sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java rename {sonar-server/src/test/java/org/sonar/server => sonar-core/src/test/java/org/sonar/core}/cluster/LocalNonBlockingWorkQueueTest.java (97%) delete mode 100644 sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java similarity index 68% rename from sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java rename to sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java index c3c53600c41..25b10c399ec 100644 --- a/sonar-server/src/main/java/org/sonar/server/cluster/LocalNonBlockingWorkQueue.java +++ b/sonar-core/src/main/java/org/sonar/core/cluster/LocalNonBlockingWorkQueue.java @@ -1,4 +1,25 @@ -package org.sonar.server.cluster; +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.cluster; + +import org.sonar.core.cluster.WorkQueue; import java.io.Serializable; import java.util.Map; diff --git a/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java b/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java similarity index 97% rename from sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java rename to sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java index 79c3b520dc9..e3790f642b9 100644 --- a/sonar-server/src/main/java/org/sonar/server/cluster/WorkQueue.java +++ b/sonar-core/src/main/java/org/sonar/core/cluster/WorkQueue.java @@ -17,7 +17,7 @@ * 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.cluster; +package org.sonar.core.cluster; import java.io.Serializable; diff --git a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java b/sonar-core/src/main/java/org/sonar/core/db/BaseDao.java similarity index 73% rename from sonar-server/src/main/java/org/sonar/server/db/BaseDao.java rename to sonar-core/src/main/java/org/sonar/core/db/BaseDao.java index 21a2270ef63..e10bbf6cfdb 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/BaseDao.java +++ b/sonar-core/src/main/java/org/sonar/core/db/BaseDao.java @@ -17,40 +17,47 @@ * 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.db; +package org.sonar.core.db; import org.apache.ibatis.session.SqlSession; +import org.sonar.core.cluster.WorkQueue; import org.sonar.core.persistence.MyBatis; -import org.sonar.server.cluster.WorkQueue; import java.io.Serializable; -public abstract class BaseDao, K extends Serializable> implements Dao { +public abstract class BaseDao, K extends Serializable, M extends Dao> + implements Dao { - private MyBatis myBatis; - private WorkQueue workQueue; + protected MyBatis mybatis; + private WorkQueue queue; protected BaseDao(WorkQueue workQueue, MyBatis myBatis) { - this.myBatis = myBatis; - this.workQueue = workQueue; + this.mybatis = myBatis; + this.queue = workQueue; } protected abstract String getIndexName(); + protected abstract Class getMapperClass(); + + private M getMapper(SqlSession session) { + return session.getMapper(getMapperClass()); + } + protected void enqueInsert(K key) { - this.workQueue.enqueInsert(this.getIndexName(), key); + this.queue.enqueInsert(this.getIndexName(), key); } protected void enqueUpdate(K key) { - this.workQueue.enqueUpdate(this.getIndexName(), key); + this.queue.enqueUpdate(this.getIndexName(), key); } protected void enqueDelete(K key) { - this.workQueue.enqueDelete(this.getIndexName(), key); + this.queue.enqueDelete(this.getIndexName(), key); } protected MyBatis getMyBatis(){ - return this.myBatis; + return this.mybatis; } @Override @@ -58,36 +65,32 @@ public abstract class BaseDao, K extends Serializable> implemen public E getByKey(K key) { E item = null; SqlSession session = getMyBatis().openSession(); - item = (E) session.getMapper(this.getClass()).getByKey(key); + item = getMapper(session).getByKey(key); MyBatis.closeQuietly(session); return item; } @Override - public E update(E item) { + public void update(E item) { SqlSession session = getMyBatis().openSession(); - E result = null; try { - result = (E) session.getMapper(this.getClass()).update(item); + getMapper(session).update(item); session.commit(); - } finally { this.enqueUpdate(item.getKey()); + } finally { MyBatis.closeQuietly(session); - return result; } } @Override - public E insert(E item) { + public void insert(E item) { SqlSession session = getMyBatis().openSession(); - E result = null; try { - result = (E) session.getMapper(this.getClass()).insert(item); + getMapper(session).insert(item); session.commit(); + this.enqueInsert(item.getKey()); } finally { MyBatis.closeQuietly(session); - this.enqueInsert(item.getKey()); - return result; } } @@ -100,7 +103,7 @@ public abstract class BaseDao, K extends Serializable> implemen public void deleteByKey(K key) { SqlSession session = getMyBatis().openSession(); try { - session.getMapper(this.getClass()).deleteByKey(key); + getMapper(session).deleteByKey(key); session.commit(); } finally { MyBatis.closeQuietly(session); diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dao.java b/sonar-core/src/main/java/org/sonar/core/db/Dao.java similarity index 93% rename from sonar-server/src/main/java/org/sonar/server/db/Dao.java rename to sonar-core/src/main/java/org/sonar/core/db/Dao.java index e3fad2e59f5..458d2b703e2 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/Dao.java +++ b/sonar-core/src/main/java/org/sonar/core/db/Dao.java @@ -17,7 +17,7 @@ * 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.db; +package org.sonar.core.db; import java.io.Serializable; import java.util.Collection; @@ -26,9 +26,9 @@ public interface Dao, K extends Serializable> { public E getByKey(K key); - public E update(E item); + public void update(E item); - public E insert(E item); + public void insert(E item); public void delete(E item); diff --git a/sonar-server/src/main/java/org/sonar/server/db/Dto.java b/sonar-core/src/main/java/org/sonar/core/db/Dto.java similarity index 97% rename from sonar-server/src/main/java/org/sonar/server/db/Dto.java rename to sonar-core/src/main/java/org/sonar/core/db/Dto.java index 483a276f175..2ac53d71222 100644 --- a/sonar-server/src/main/java/org/sonar/server/db/Dto.java +++ b/sonar-core/src/main/java/org/sonar/core/db/Dto.java @@ -17,7 +17,7 @@ * 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.db; +package org.sonar.core.db; import java.io.Serializable; diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java new file mode 100644 index 00000000000..636a6dcd67c --- /dev/null +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleConstants.java @@ -0,0 +1,26 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.core.rule; + +public interface RuleConstants { + + public static final String INDEX_NAME = "rules"; + public static final String ES_TYPE = "rule"; +} diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java index 3b5677fc9b9..1c87168d8b5 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDao.java @@ -24,6 +24,8 @@ import org.apache.ibatis.session.SqlSession; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; import org.sonar.api.rule.RuleKey; +import org.sonar.core.cluster.WorkQueue; +import org.sonar.core.db.BaseDao; import org.sonar.core.persistence.MyBatis; import javax.annotation.CheckForNull; @@ -33,12 +35,22 @@ import java.util.List; import static com.google.common.collect.Lists.newArrayList; -public class RuleDao implements BatchComponent, ServerComponent { +public class RuleDao extends BaseDao + implements BatchComponent, ServerComponent { - private MyBatis mybatis; - public RuleDao(MyBatis mybatis) { - this.mybatis = mybatis; + public RuleDao(MyBatis mybatis, WorkQueue queue) { + super(queue, mybatis); + } + + @Override + protected String getIndexName() { + return RuleConstants.INDEX_NAME; + } + + @Override + protected Class getMapperClass() { + return RuleMapper.class; } public List selectAll() { @@ -131,29 +143,18 @@ public class RuleDao implements BatchComponent, ServerComponent { getMapper(session).update(rule); } - public void update(RuleDto rule) { - SqlSession session = mybatis.openSession(); - try { - update(rule, session); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } +// public RuleDto update(RuleDto rule) { +// return super.update(rule); +// } +// +// public RuleDto insert(RuleDto ruleToInsert) { +// return super.insert(ruleToInsert); +// } public void insert(RuleDto ruleToInsert, SqlSession session) { getMapper(session).insert(ruleToInsert); } - public void insert(RuleDto ruleToInsert) { - SqlSession session = mybatis.openSession(); - try { - insert(ruleToInsert, session); - session.commit(); - } finally { - MyBatis.closeQuietly(session); - } - } public void insert(Collection rules) { SqlSession session = mybatis.openBatchSession(); @@ -307,4 +308,10 @@ public class RuleDao implements BatchComponent, ServerComponent { } return dtos; } + + @Override + public Collection insertsSince(Long timestamp) { + // TODO Auto-generated method stub + return null; + } } diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java index 8bb8f4e38b5..78dd41c99a5 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleDto.java @@ -19,6 +19,9 @@ */ package org.sonar.core.rule; +import org.sonar.api.rule.RuleKey; + +import org.sonar.core.db.Dto; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ReflectionToStringBuilder; @@ -30,7 +33,7 @@ import javax.annotation.Nullable; import java.util.Date; -public final class RuleDto { +public final class RuleDto implements Dto{ public static final Integer DISABLED_CHARACTERISTIC_ID = -1; @@ -61,6 +64,12 @@ public final class RuleDto { private Date createdAt; private Date updatedAt; + @Override + public RuleKey getKey() { + return RuleKey.of(this.getRepositoryKey(), this.getRuleKey()); + } + + @Deprecated public Integer getId() { return id; } diff --git a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java index e31b14e04aa..536071017eb 100644 --- a/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/rule/RuleMapper.java @@ -21,10 +21,12 @@ package org.sonar.core.rule; import org.apache.ibatis.annotations.Param; import org.sonar.api.rule.RuleKey; +import org.sonar.core.db.Dao; import java.util.List; -public interface RuleMapper { +public interface RuleMapper extends Dao{ + List selectAll(); List selectEnablesAndNonManual(); diff --git a/sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java b/sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java similarity index 97% rename from sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java rename to sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java index 117db387a9a..c352f14cb44 100644 --- a/sonar-server/src/test/java/org/sonar/server/cluster/LocalNonBlockingWorkQueueTest.java +++ b/sonar-core/src/test/java/org/sonar/core/cluster/LocalNonBlockingWorkQueueTest.java @@ -17,7 +17,9 @@ * 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.cluster; +package org.sonar.core.cluster; + +import org.sonar.core.cluster.LocalNonBlockingWorkQueue; import org.junit.Test; diff --git a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java index 6386962c054..8b6aaf45095 100644 --- a/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/rule/RuleDaoTest.java @@ -19,6 +19,8 @@ */ package org.sonar.core.rule; +import org.sonar.core.cluster.WorkQueue; + import com.google.common.base.Function; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; @@ -34,6 +36,8 @@ import org.sonar.core.persistence.AbstractDaoTestCase; import java.util.List; +import static org.mockito.Mockito.mock; + import static com.google.common.collect.Lists.newArrayList; import static org.fest.assertions.Assertions.assertThat; @@ -43,7 +47,8 @@ public class RuleDaoTest extends AbstractDaoTestCase { @Before public void createDao() throws Exception { - dao = new RuleDao(getMyBatis()); + WorkQueue queue = mock(WorkQueue.class); + dao = new RuleDao(getMyBatis(), queue); } @Test diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java deleted file mode 100644 index 98abd6f7979..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleConstants.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sonar.server.rule2; - -public interface RuleConstants { - - public static final String INDEX_NAME = "rules"; - public static final String ES_TYPE = "rule"; -} diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java deleted file mode 100644 index 3bc9875c398..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDao.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.sonar.server.rule2; - -import java.util.Collection; - -import org.sonar.core.persistence.MyBatis; -import org.sonar.server.cluster.WorkQueue; -import org.sonar.api.rule.RuleKey; -import org.sonar.server.db.BaseDao; - -public class RuleDao extends BaseDao { - - protected RuleDao(WorkQueue workQueue, MyBatis myBatis) { - super(workQueue, myBatis); - } - - @Override - protected String getIndexName() { - return RuleConstants.INDEX_NAME; - } - - @Override - public Collection insertsSince(Long timestamp) { - // TODO Auto-generated method stub - return null; - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java deleted file mode 100644 index 621de3ae268..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleDto.java +++ /dev/null @@ -1,344 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 SonarSource - * mailto:contact AT sonarsource DOT com - * - * SonarQube is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * SonarQube is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.server.rule2; - -import org.sonar.api.rule.RuleKey; - -import org.sonar.core.rule.SeverityUtil; -import org.sonar.server.db.Dto; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.commons.lang.builder.ReflectionToStringBuilder; -import org.apache.commons.lang.builder.ToStringStyle; -import org.sonar.check.Cardinality; - -import javax.annotation.CheckForNull; -import javax.annotation.Nullable; - -import java.util.Date; - -public final class RuleDto implements Dto { - - public static final Integer DISABLED_CHARACTERISTIC_ID = -1; - - private String repositoryKey; - private String ruleKey; - private String description; - private String status; - private String name; - private String configKey; - private Integer severity; - private Cardinality cardinality; - private String language; - private Integer parentId; - private String noteData; - private String noteUserLogin; - private Date noteCreatedAt; - private Date noteUpdatedAt; - private Integer subCharacteristicId; - private Integer defaultSubCharacteristicId; - private String remediationFunction; - private String defaultRemediationFunction; - private String remediationCoefficient; - private String defaultRemediationCoefficient; - private String remediationOffset; - private String defaultRemediationOffset; - private String effortToFixDescription; - private Date createdAt; - private Date updatedAt; - - @Override - public RuleKey getKey() { - return RuleKey.of(this.getRepositoryKey(), this.getRuleKey()); - } - - public String getRepositoryKey() { - return repositoryKey; - } - - public RuleDto setRepositoryKey(String repositoryKey) { - this.repositoryKey = repositoryKey; - return this; - } - - public String getRuleKey() { - return ruleKey; - } - - public RuleDto setRuleKey(String ruleKey) { - this.ruleKey = ruleKey; - return this; - } - - public String getDescription() { - return description; - } - - public RuleDto setDescription(String description) { - this.description = description; - return this; - } - - public String getStatus() { - return status; - } - - public RuleDto setStatus(String status) { - this.status = status; - return this; - } - - public String getName() { - return name; - } - - public RuleDto setName(String name) { - this.name = name; - return this; - } - - public String getConfigKey() { - return configKey; - } - - public RuleDto setConfigKey(String configKey) { - this.configKey = configKey; - return this; - } - - public Integer getSeverity() { - return severity; - } - - public String getSeverityString() { - return SeverityUtil.getSeverityFromOrdinal(severity); - } - - public RuleDto setSeverity(String severity) { - this.severity = SeverityUtil.getOrdinalFromSeverity(severity); - return this; - } - - public RuleDto setSeverity(Integer severity) { - this.severity = severity; - return this; - } - - - public Cardinality getCardinality() { - return cardinality; - } - - public RuleDto setCardinality(Cardinality cardinality) { - this.cardinality = cardinality; - return this; - } - - public String getLanguage() { - return language; - } - - public RuleDto setLanguage(String language) { - this.language = language; - return this; - } - - @CheckForNull - public Integer getParentId() { - return parentId; - } - - public RuleDto setParentId(@Nullable Integer parentId) { - this.parentId = parentId; - return this; - } - - public String getNoteData() { - return noteData; - } - - public RuleDto setNoteData(String noteData) { - this.noteData = noteData; - return this; - } - - public String getNoteUserLogin() { - return noteUserLogin; - } - - public RuleDto setNoteUserLogin(String noteUserLogin) { - this.noteUserLogin = noteUserLogin; - return this; - } - - public Date getNoteCreatedAt() { - return noteCreatedAt; - } - - public RuleDto setNoteCreatedAt(Date noteCreatedAt) { - this.noteCreatedAt = noteCreatedAt; - return this; - } - - public Date getNoteUpdatedAt() { - return noteUpdatedAt; - } - - public RuleDto setNoteUpdatedAt(Date noteUpdatedAt) { - this.noteUpdatedAt = noteUpdatedAt; - return this; - } - - @CheckForNull - public Integer getSubCharacteristicId() { - return subCharacteristicId; - } - - public RuleDto setSubCharacteristicId(@Nullable Integer subCharacteristicId) { - this.subCharacteristicId = subCharacteristicId; - return this; - } - - @CheckForNull - public Integer getDefaultSubCharacteristicId() { - return defaultSubCharacteristicId; - } - - public RuleDto setDefaultSubCharacteristicId(@Nullable Integer defaultSubCharacteristicId) { - this.defaultSubCharacteristicId = defaultSubCharacteristicId; - return this; - } - - @CheckForNull - public String getRemediationFunction() { - return remediationFunction; - } - - public RuleDto setRemediationFunction(@Nullable String remediationFunction) { - this.remediationFunction = remediationFunction; - return this; - } - - @CheckForNull - public String getDefaultRemediationFunction() { - return defaultRemediationFunction; - } - - public RuleDto setDefaultRemediationFunction(@Nullable String defaultRemediationFunction) { - this.defaultRemediationFunction = defaultRemediationFunction; - return this; - } - - @CheckForNull - public String getRemediationCoefficient() { - return remediationCoefficient; - } - - public RuleDto setRemediationCoefficient(@Nullable String remediationCoefficient) { - this.remediationCoefficient = remediationCoefficient; - return this; - } - - @CheckForNull - public String getDefaultRemediationCoefficient() { - return defaultRemediationCoefficient; - } - - public RuleDto setDefaultRemediationCoefficient(@Nullable String defaultRemediationCoefficient) { - this.defaultRemediationCoefficient = defaultRemediationCoefficient; - return this; - } - - @CheckForNull - public String getRemediationOffset() { - return remediationOffset; - } - - public RuleDto setRemediationOffset(@Nullable String remediationOffset) { - this.remediationOffset = remediationOffset; - return this; - } - - @CheckForNull - public String getDefaultRemediationOffset() { - return defaultRemediationOffset; - } - - public RuleDto setDefaultRemediationOffset(@Nullable String defaultRemediationOffset) { - this.defaultRemediationOffset = defaultRemediationOffset; - return this; - } - - @CheckForNull - public String getEffortToFixDescription() { - return effortToFixDescription; - } - - public RuleDto setEffortToFixDescription(@Nullable String effortToFixDescription) { - this.effortToFixDescription = effortToFixDescription; - return this; - } - - public Date getCreatedAt() { - return createdAt; - } - - public RuleDto setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - return this; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public RuleDto setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - return this; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof RuleDto)) { - return false; - } - if (this == obj) { - return true; - } - RuleDto other = (RuleDto) obj; - return new EqualsBuilder() - .append(repositoryKey, other.getRepositoryKey()) - .append(ruleKey, other.getRuleKey()) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(repositoryKey) - .append(ruleKey) - .toHashCode(); - } - - @Override - public String toString() { - return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString(); - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java index 89ccff40a50..865ba63d1bd 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleImpl.java @@ -1,3 +1,22 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.server.rule2; import org.sonar.api.rule.Severity; diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java index d7bda890e89..e30f7e29ec1 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleIndex.java @@ -1,17 +1,37 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.server.rule2; import org.elasticsearch.common.settings.ImmutableSettings; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.sonar.api.rule.RuleKey; -import org.sonar.core.persistence.MyBatis; +import org.sonar.core.cluster.WorkQueue; import org.sonar.core.profiling.Profiling; -import org.sonar.server.cluster.WorkQueue; +import org.sonar.core.rule.RuleConstants; +import org.sonar.core.rule.RuleDao; +import org.sonar.core.db.Dao; import org.sonar.server.search.BaseIndex; import java.io.IOException; @@ -25,8 +45,8 @@ public class RuleIndex extends BaseIndex { private static final Logger LOG = LoggerFactory.getLogger(RuleIndex.class); - public RuleIndex(WorkQueue workQueue, RuleDao dao, Profiling profiling) { - super(workQueue, dao, profiling); + public RuleIndex(WorkQueue queue, RuleDao dao, Profiling profiling) { + super(queue, dao, profiling); } @Override diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleQuery.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleQuery.java index 2a7cc349988..d526c2839dd 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleQuery.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleQuery.java @@ -1,3 +1,22 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ package org.sonar.server.rule2; public class RuleQuery { diff --git a/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java b/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java index a9087216fd8..dfd0835e3cf 100644 --- a/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java +++ b/sonar-server/src/main/java/org/sonar/server/rule2/RuleService.java @@ -20,6 +20,8 @@ package org.sonar.server.rule2; import org.sonar.api.rule.RuleKey; +import org.sonar.core.rule.RuleDao; +import org.sonar.core.rule.RuleDto; import org.sonar.server.search.Hit; import javax.annotation.CheckForNull; diff --git a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java index 9eaf598196e..1d6529238e0 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java +++ b/sonar-server/src/main/java/org/sonar/server/search/BaseIndex.java @@ -33,12 +33,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.core.persistence.MyBatis; +import org.sonar.core.cluster.WorkQueue; +import org.sonar.core.db.Dao; import org.sonar.core.profiling.Profiling; import org.sonar.core.profiling.Profiling.Level; import org.sonar.core.profiling.StopWatch; -import org.sonar.server.cluster.WorkQueue; -import org.sonar.server.db.Dao; import java.io.Serializable; import java.util.Collection; diff --git a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java index 0547675b535..de2d4bc0d9f 100644 --- a/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java +++ b/sonar-server/src/main/java/org/sonar/server/search/IndexSynchronizer.java @@ -19,9 +19,10 @@ */ package org.sonar.server.search; +import org.sonar.core.cluster.WorkQueue; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.server.cluster.WorkQueue; import java.io.Serializable; diff --git a/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java b/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java index 01c35e4d405..6707ea13852 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule/RegisterRulesTest.java @@ -34,6 +34,8 @@ import org.sonar.api.server.rule.RulesDefinition; import org.sonar.api.utils.DateUtils; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.System2; +import org.sonar.core.cluster.LocalNonBlockingWorkQueue; +import org.sonar.core.cluster.WorkQueue; import org.sonar.core.persistence.AbstractDaoTestCase; import org.sonar.core.persistence.MyBatis; import org.sonar.core.qualityprofile.db.ActiveRuleDao; @@ -50,7 +52,11 @@ import java.util.Date; import static org.fest.assertions.Assertions.assertThat; import static org.fest.assertions.Fail.fail; -import static org.mockito.Mockito.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) public class RegisterRulesTest extends AbstractDaoTestCase { @@ -85,14 +91,16 @@ public class RegisterRulesTest extends AbstractDaoTestCase { ActiveRuleDao activeRuleDao; CharacteristicDao characteristicDao; System2 system; + WorkQueue queue; Date date = DateUtils.parseDateTime("2014-03-17T19:10:03+0100"); @Before public void before() { system = mock(System2.class); + queue = mock(WorkQueue.class); when(system.now()).thenReturn(date.getTime()); myBatis = getMyBatis(); - ruleDao = new RuleDao(myBatis); + ruleDao = new RuleDao(myBatis, queue); ruleTagDao = new RuleTagDao(myBatis); activeRuleDao = new ActiveRuleDao(myBatis); ruleTagOperations = new RuleTagOperations(ruleTagDao, esRuleTags); diff --git a/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexTest.java b/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexTest.java index a1e21f995b8..f356961ddef 100644 --- a/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexTest.java +++ b/sonar-server/src/test/java/org/sonar/server/rule2/RuleIndexTest.java @@ -19,7 +19,7 @@ */ package org.sonar.server.rule2; -import org.sonar.server.cluster.LocalNonBlockingWorkQueue; +import org.sonar.core.cluster.LocalNonBlockingWorkQueue; import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode; import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner; diff --git a/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java b/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java index 0f75176d5e1..46232717b59 100644 --- a/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java +++ b/sonar-server/src/test/java/org/sonar/server/search/BaseIndexTest.java @@ -19,8 +19,6 @@ */ package org.sonar.server.search; -import org.sonar.server.cluster.LocalNonBlockingWorkQueue; - import com.github.tlrx.elasticsearch.test.annotations.ElasticsearchNode; import com.github.tlrx.elasticsearch.test.support.junit.runners.ElasticsearchRunner; import org.elasticsearch.client.transport.NoNodeAvailableException; @@ -32,6 +30,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.api.config.Settings; +import org.sonar.core.cluster.LocalNonBlockingWorkQueue; import org.sonar.core.profiling.Profiling; import java.io.Serializable; -- 2.39.5