--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.log;
+
+/**
+ * @since 4.4
+ */
+public interface Log {
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.log;
+
+import org.apache.commons.io.output.ByteArrayOutputStream;
+import org.sonar.core.persistence.Dto;
+import org.sonar.core.log.db.LogKey;
+
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @since 4.4
+ */
+public class LogDto extends Dto<LogKey> {
+
+ public static enum Type {
+ CHANGE, LOG
+ }
+
+ public static enum Status {
+ OK, FAIL
+ }
+
+ private Date time;
+ private Type type;
+ private Status status;
+ private Long executionTime;
+ private String author;
+ private String data;
+
+ private LogDto(Date time, Type type) {
+ this.time = time;
+ this.type = type;
+ }
+
+ @Override
+ public LogKey getKey() {
+ return LogKey.of(time, type, author);
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public LogDto setTime(Date time) {
+ this.time = time;
+ return this;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public LogDto setType(Type type) {
+ this.type = type;
+ return this;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public LogDto setStatus(Status status) {
+ this.status = status;
+ return this;
+ }
+
+ public Long getExecutionTime() {
+ return executionTime;
+ }
+
+ public LogDto setExecutionTime(Long executionTime) {
+ this.executionTime = executionTime;
+ return this;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public LogDto setAuthor(String author) {
+ this.author = author;
+ return this;
+ }
+
+ public Map getPayload() {
+ try {
+ byte[] bytes = this.data.getBytes();
+ ObjectInputStream ois = new ObjectInputStream(
+ new ByteArrayInputStream(bytes));
+ Map payload = (Map) ois.readObject();
+ ois.close();
+ return payload;
+ } catch (Exception e) {
+ throw new IllegalStateException("Could not read payload from DB.", e);
+ }
+ }
+
+ public LogDto setPayload(Map payload) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(payload);
+ oos.close();
+ this.data = new String(baos.toByteArray());
+ } catch (Exception e) {
+ throw new IllegalStateException("Could not write payload from DB.", e);
+ }
+ return this;
+ }
+
+ public LogDto changeLog() {
+ return new LogDto(new Date(), Type.CHANGE);
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.log.db;
+
+import com.google.common.base.Preconditions;
+import org.sonar.core.log.LogDto;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @since 4.4
+ */
+public class LogKey implements Serializable {
+
+ private Date time;
+ private LogDto.Type type;
+ private String author;
+
+ public LogKey(Date time, LogDto.Type type, String author) {
+ this.time = time;
+ this.type = type;
+ this.author = author;
+ }
+
+ /**
+ * Create a key. Parameters are NOT null.
+ */
+ public static LogKey of(Date time, LogDto.Type type, String author) {
+ Preconditions.checkArgument(time != null, "Time must be set");
+ Preconditions.checkArgument(type != null, "Type must be set");
+ Preconditions.checkArgument(author != null, "Author must be set");
+ return new LogKey(time, type, author);
+ }
+
+ /**
+ * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised
+ * if the format is not valid.
+ */
+ public static LogKey parse(String s) {
+ String[] split = s.split(":");
+ Preconditions.checkArgument(split.length == 3, "Invalid log key: " + s);
+ return LogKey.of(new Date(Long.getLong(split[0])),
+ LogDto.Type.valueOf(split[1]), split[2]);
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public LogDto.Type getType() {
+ return type;
+ }
+
+ public void setType(LogDto.Type type) {
+ this.type = type;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.core.log.db;
+
+import org.sonar.core.log.LogDto;
+
+/**
+ * @since 4.4
+ */
+public interface LogMapper {
+
+ void insert(LogDto rule);
+
+}
import org.sonar.core.issue.db.IssueFilterMapper;
import org.sonar.core.issue.db.IssueMapper;
import org.sonar.core.issue.db.IssueStatsMapper;
+import org.sonar.core.log.LogDto;
+import org.sonar.core.log.db.LogMapper;
import org.sonar.core.measure.db.MeasureDto;
import org.sonar.core.measure.db.MeasureFilterDto;
import org.sonar.core.measure.db.MeasureFilterMapper;
loadAlias(conf, "QualityProfile", QualityProfileDto.class);
loadAlias(conf, "ActiveRule", ActiveRuleDto.class);
loadAlias(conf, "ActiveRuleParam", ActiveRuleParamDto.class);
+ loadAlias(conf, "Log", LogDto.class);
// AuthorizationMapper has to be loaded before IssueMapper because this last one used it
loadMapper(conf, "org.sonar.core.user.AuthorizationMapper");
loadMapper(conf, ResourceMapper.class);
loadMapper(conf, "org.sonar.core.permission.PermissionMapper");
- Class<?>[] mappers = {ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
+ Class<?>[] mappers = {LogMapper.class, ActiveDashboardMapper.class, AuthorMapper.class, DashboardMapper.class,
DependencyMapper.class, DuplicationMapper.class, GraphDtoMapper.class,
IssueMapper.class, IssueStatsMapper.class, IssueChangeMapper.class, IssueFilterMapper.class, IssueFilterFavouriteMapper.class,
LoadedTemplateMapper.class, MeasureFilterMapper.class, PermissionTemplateMapper.class, PropertiesMapper.class, PurgeMapper.class,
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="org.sonar.core.log.LogMapper">
+ <insert id="insert" parameterType="Log" useGeneratedKeys="false">
+ insert into logs
+ (time_field,type_field,status_field,execution_time_field,author_field,data_field)
+ values (#{time}, #{type}, #{status}, #{executionTime}, #{author}, #{data})
+ </insert>
+</mapper>
+
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log;
-
-/**
- * @since 4.4
- */
-public interface Log {
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log;
-
-import org.apache.commons.io.output.ByteArrayOutputStream;
-import org.sonar.core.persistence.Dto;
-import org.sonar.server.log.db.LogKey;
-import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
-
-import java.io.ByteArrayInputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.Date;
-import java.util.Map;
-
-/**
- * @since 4.4
- */
-public class LogDto extends Dto<LogKey> {
-
- public static enum Type {
- CHANGE, LOG
- }
-
- public static enum Status {
- OK, FAIL
- }
-
- private Date time;
- private Type type;
- private Status status;
- private Long executionTime;
- private String author;
- private String data;
-
- private LogDto(Date time, Type type) {
- this.time = time;
- this.type = type;
- }
-
- @Override
- public LogKey getKey() {
- return LogKey.of(time, type, author);
- }
-
- public Date getTime() {
- return time;
- }
-
- public LogDto setTime(Date time) {
- this.time = time;
- return this;
- }
-
- public Type getType() {
- return type;
- }
-
- public LogDto setType(Type type) {
- this.type = type;
- return this;
- }
-
- public Status getStatus() {
- return status;
- }
-
- public LogDto setStatus(Status status) {
- this.status = status;
- return this;
- }
-
- public Long getExecutionTime() {
- return executionTime;
- }
-
- public LogDto setExecutionTime(Long executionTime) {
- this.executionTime = executionTime;
- return this;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public LogDto setAuthor(String author) {
- this.author = author;
- return this;
- }
-
- public Map getPayload() {
- try {
- byte[] bytes = Base64Coder.decode(this.data);
- ObjectInputStream ois = new ObjectInputStream(
- new ByteArrayInputStream(bytes));
- Map payload = (Map) ois.readObject();
- ois.close();
- return payload;
- } catch (Exception e) {
- throw new IllegalStateException("Could not read payload from DB.", e);
- }
- }
-
- public LogDto setPayload(Map payload) {
- try {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(payload);
- oos.close();
- this.data = new String(Base64Coder.encode(baos.toByteArray()));
- } catch (Exception e) {
- throw new IllegalStateException("Could not write payload from DB.", e);
- }
- return this;
- }
-
- public LogDto changeLog() {
- return new LogDto(new Date(), Type.CHANGE);
- }
-}
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.utils.System2;
+import org.sonar.core.log.LogDto;
+import org.sonar.core.log.db.LogKey;
+import org.sonar.core.log.db.LogMapper;
import org.sonar.core.persistence.DbSession;
import org.sonar.server.db.BaseDao;
-import org.sonar.server.log.LogDto;
import org.sonar.server.search.IndexDefinition;
/**
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log.db;
-
-import com.google.common.base.Preconditions;
-import org.sonar.server.log.LogDto;
-
-import java.io.Serializable;
-import java.util.Date;
-
-/**
- * @since 4.4
- */
-public class LogKey implements Serializable {
-
- private Date time;
- private LogDto.Type type;
- private String author;
-
- public LogKey(Date time, LogDto.Type type, String author) {
- this.time = time;
- this.type = type;
- this.author = author;
- }
-
- /**
- * Create a key. Parameters are NOT null.
- */
- public static LogKey of(Date time, LogDto.Type type, String author) {
- Preconditions.checkArgument(time != null, "Time must be set");
- Preconditions.checkArgument(type != null, "Type must be set");
- Preconditions.checkArgument(author != null, "Author must be set");
- return new LogKey(time, type, author);
- }
-
- /**
- * Create a key from a string representation (see {@link #toString()}. An {@link IllegalArgumentException} is raised
- * if the format is not valid.
- */
- public static LogKey parse(String s) {
- String[] split = s.split(":");
- Preconditions.checkArgument(split.length == 3, "Invalid log key: " + s);
- return LogKey.of(new Date(Long.getLong(split[0])),
- LogDto.Type.valueOf(split[1]), split[2]);
- }
-
- public Date getTime() {
- return time;
- }
-
- public void setTime(Date time) {
- this.time = time;
- }
-
- public LogDto.Type getType() {
- return type;
- }
-
- public void setType(LogDto.Type type) {
- this.type = type;
- }
-
- public String getAuthor() {
- return author;
- }
-
- public void setAuthor(String author) {
- this.author = author;
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.log.db;
-
-/**
- * @since 4.4
- */
-public interface LogMapper {
-
-}
import org.elasticsearch.common.settings.Settings;
import org.sonar.core.cluster.WorkQueue;
-import org.sonar.server.log.Log;
-import org.sonar.server.log.LogDto;
-import org.sonar.server.log.db.LogKey;
+import org.sonar.core.log.Log;
+import org.sonar.core.log.LogDto;
+import org.sonar.core.log.db.LogKey;
import org.sonar.server.search.BaseIndex;
import org.sonar.server.search.ESNode;
import org.sonar.server.search.IndexDefinition;
import org.elasticsearch.action.update.UpdateRequest;
import org.sonar.server.db.DbClient;
-import org.sonar.server.log.LogDto;
-import org.sonar.server.log.db.LogKey;
+import org.sonar.core.log.LogDto;
+import org.sonar.core.log.db.LogKey;
import org.sonar.server.search.BaseNormalizer;
import org.sonar.server.search.IndexDefinition;
import org.sonar.server.search.BaseDoc;
import org.sonar.server.search.IndexUtils;
+import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;