aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java325
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java297
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java63
3 files changed, 0 insertions, 685 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java
deleted file mode 100644
index 942b9657ab4..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/ResourceModel.java
+++ /dev/null
@@ -1,325 +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.api.database.model;
-
-import java.io.Serializable;
-import java.util.Date;
-import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.sonar.api.database.BaseIdentifiable;
-
-public class ResourceModel extends BaseIdentifiable implements Cloneable, Serializable {
-
- public static final String SCOPE_PROJECT = "PRJ";
- public static final String QUALIFIER_PROJECT_TRUNK = "TRK";
-
- public static final int DESCRIPTION_COLUMN_SIZE = 2000;
- public static final int NAME_COLUMN_SIZE = 256;
- public static final int KEY_SIZE = 400;
- public static final int PATH_SIZE = 2000;
-
- private String name;
- private String longName;
- private String description;
- private Boolean enabled = Boolean.TRUE;
- private String scope;
- private String qualifier;
- private String key;
- private String deprecatedKey;
- private String languageKey;
- private Integer rootId;
- private String path;
- private Integer copyResourceId;
- private Integer personId;
- private Date createdAt;
- private String uuid;
- private String projectUuid;
- private String moduleUuid;
- private String moduleUuidPath;
-
- /**
- * Default constructor
- */
- public ResourceModel() {
- this.createdAt = new Date();
- }
-
- public ResourceModel(String scope, String key, String qualifier, Integer rootId, String name) {
- this(scope, key, qualifier, rootId, null, name);
- }
-
- /**
- * <p>Creates a resource model</p>
- *
- * @param scope the scope the rule will apply on
- * @param key the rule key. This is the name of the resource, including the path
- * @param qualifier the resource qualifier
- * @param rootId the rootId for the resource
- * @param path the path of the resource
- * @param name the short name of the resource
- */
- public ResourceModel(String scope, String key, String qualifier, Integer rootId, @Nullable String path, String name) {
- // call this to have the "createdAt" field initialized
- this();
- this.scope = scope;
- this.key = key;
- this.rootId = rootId;
- this.path = path;
- this.name = name;
- this.qualifier = qualifier;
- }
-
- /**
- * Only available at project level.
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * Sets the resource description, truncated to DESCRIPTION_COLUMN_SIZE
- */
- public void setDescription(String description) {
- this.description = StringUtils.abbreviate(description, DESCRIPTION_COLUMN_SIZE);
- }
-
- public String getName() {
- return name;
- }
-
- /**
- * Sets the resource name, truncated to NAME_COLUMN_SIZE
- */
- public void setName(String name) {
- this.name = StringUtils.abbreviate(name, NAME_COLUMN_SIZE);
- if (this.longName == null) {
- this.longName = this.name;
- }
- }
-
- public String getLongName() {
- return longName;
- }
-
- /**
- * Sets the long name of the resource, truncated to NAME_COLUMN_SIZE
- */
- public void setLongName(String s) {
- if (StringUtils.isBlank(s)) {
- this.longName = name;
- } else {
- this.longName = StringUtils.abbreviate(s, NAME_COLUMN_SIZE);
- }
- }
-
- public Boolean getEnabled() {
- return enabled;
- }
-
- public void setEnabled(Boolean enabled) {
- this.enabled = enabled;
- }
-
- public String getScope() {
- return scope;
- }
-
- public void setScope(String scope) {
- this.scope = scope;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getDeprecatedKey() {
- return deprecatedKey;
- }
-
- public String getLanguageKey() {
- return languageKey;
- }
-
- public void setLanguageKey(String lang) {
- this.languageKey = lang;
- }
-
- public Integer getCopyResourceId() {
- return copyResourceId;
- }
-
- public void setCopyResourceId(Integer i) {
- this.copyResourceId = i;
- }
-
- /**
- * @since 2.14
- */
- public Integer getPersonId() {
- return personId;
- }
-
- /**
- * @since 2.14
- */
- public ResourceModel setPersonId(Integer i) {
- this.personId = i;
- return this;
- }
-
- /**
- * @throws IllegalArgumentException if the key is longer than KEY_SIZE
- */
- public void setKey(String key) {
- checkSize(key);
- this.key = key;
- }
-
- private static void checkSize(String key) {
- if (key.length() > KEY_SIZE) {
- throw new IllegalArgumentException("Resource key is too long, max is " + KEY_SIZE + " characters. Got : " + key);
- }
- }
-
- /**
- * @throws IllegalArgumentException if the key is longer than KEY_SIZE
- */
- public void setDeprecatedKey(String deprecatedKey) {
- checkSize(deprecatedKey);
- this.deprecatedKey = deprecatedKey;
- }
-
- public Integer getRootId() {
- return rootId;
- }
-
- public void setRootId(Integer rootId) {
- this.rootId = rootId;
- }
-
- public String getPath() {
- return path;
- }
-
- public ResourceModel setPath(@Nullable String path) {
- if (path != null && path.length() > PATH_SIZE) {
- throw new IllegalArgumentException("Resource path is too long, max is " + PATH_SIZE + " characters. Got : " + path);
- }
- this.path = path;
- return this;
- }
-
- public String getQualifier() {
- return qualifier;
- }
-
- public void setQualifier(String qualifier) {
- this.qualifier = qualifier;
- }
-
- public Date getCreatedAt() {
- return createdAt; // NOSONAR May expose internal representation by returning reference to mutable object
- }
-
- public void setCreatedAt(Date createdAt) {
- this.createdAt = createdAt; // NOSONAR May expose internal representation by returning reference to mutable object
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public String getProjectUuid() {
- return projectUuid;
- }
-
- public void setProjectUuid(String projectUuid) {
- this.projectUuid = projectUuid;
- }
-
- public String getModuleUuid() {
- return moduleUuid;
- }
-
- public void setModuleUuid(String moduleUuid) {
- this.moduleUuid = moduleUuid;
- }
-
- public String getModuleUuidPath() {
- return moduleUuidPath;
- }
-
- public void setModuleUuidPath(String moduleUuidPath) {
- this.moduleUuidPath = moduleUuidPath;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof ResourceModel)) {
- return false;
- }
- if (this == obj) {
- return true;
- }
- ResourceModel other = (ResourceModel) obj;
- return new EqualsBuilder()
- .append(key, other.key)
- .append(enabled, other.enabled)
- .append(rootId, other.rootId)
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(key)
- .append(enabled)
- .append(rootId)
- .toHashCode();
- }
-
- @Override
- public String toString() {
- return new ToStringBuilder(this)
- .append("id", getId())
- .append("key", key)
- .append("deprecatedKey", deprecatedKey)
- .append("scope", scope)
- .append("qualifier", qualifier)
- .append("name", name)
- .append("longName", longName)
- .append("lang", languageKey)
- .append("enabled", enabled)
- .append("rootId", rootId)
- .append("path", path)
- .append("copyResourceId", copyResourceId)
- .append("personId", personId)
- .append("createdAt", createdAt)
- .toString();
- }
-
-}
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java
deleted file mode 100644
index a8294b03edc..00000000000
--- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java
+++ /dev/null
@@ -1,297 +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.api.database.model;
-
-import java.io.Serializable;
-import java.util.Date;
-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.api.database.BaseIdentifiable;
-
-import static org.sonar.api.utils.DateUtils.dateToLong;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
-public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable {
-
- /**
- * This status is set on the snapshot at the beginning of the batch
- */
- public static final String STATUS_UNPROCESSED = "U";
-
- /**
- * This status is set on the snapshot at the end of the batch
- */
- public static final String STATUS_PROCESSED = "P";
-
- private Integer resourceId;
- private Long buildDate;
- private Long createdAt;
- private String version;
- private Boolean last = Boolean.FALSE;
- private String status = STATUS_UNPROCESSED;
- private Integer purgeStatus;
- private String scope;
- private String path;
- private Integer depth;
- private String qualifier;
- private Integer rootId;
- private Integer parentId;
- private Integer rootProjectId;
- private String period1Mode;
- private String period2Mode;
- private String period3Mode;
- private String period4Mode;
- private String period5Mode;
- private String period1Param;
- private String period2Param;
- private String period3Param;
- private String period4Param;
- private String period5Param;
- private Long period1Date;
- private Long period2Date;
- private Long period3Date;
- private Long period4Date;
- private Long period5Date;
-
- public Snapshot() {
-
- }
-
- public Snapshot setBuildDateMs(Long d) {
- this.buildDate = d;
- return this;
- }
-
- public Date getCreatedAt() {
- return longToDate(createdAt);
- }
-
- public Snapshot setCreatedAt(Date createdAt) {
- this.createdAt = dateToLong(createdAt);
- return this;
- }
-
- public Long getCreatedAtMs() {
- return createdAt;
- }
-
- public Snapshot setCreatedAtMs(Long createdAt) {
- this.createdAt = createdAt;
- return this;
- }
-
- public Integer getResourceId() {
- return resourceId;
- }
-
- public Snapshot setResourceId(Integer resourceId) {
- this.resourceId = resourceId;
- return this;
- }
-
- public final Snapshot setResource(ResourceModel resource) {
- this.resourceId = resource.getId();
- this.scope = resource.getScope();
- this.qualifier = resource.getQualifier();
- return this;
- }
-
- public String getVersion() {
- return version;
- }
-
- public Snapshot setVersion(String version) {
- this.version = version;
- return this;
- }
-
- public Integer getParentId() {
- return parentId;
- }
-
- public Snapshot setParentId(Integer i) {
- this.parentId = i;
- return this;
- }
-
- public Boolean getLast() {
- return last;
- }
-
- public Snapshot setLast(Boolean last) {
- this.last = last;
- return this;
- }
-
- public String getStatus() {
- return status;
- }
-
- public Snapshot setStatus(String status) {
- this.status = status;
- return this;
- }
-
- public String getScope() {
- return scope;
- }
-
- public Snapshot setScope(String scope) {
- this.scope = scope;
- return this;
- }
-
- public String getQualifier() {
- return qualifier;
- }
-
- public Snapshot setQualifier(String qualifier) {
- this.qualifier = qualifier;
- return this;
- }
-
- public Integer getRootId() {
- return rootId;
- }
-
- public Snapshot setRootId(Integer i) {
- this.rootId = i;
- return this;
- }
-
- public String getPath() {
- return path;
- }
-
- public Snapshot setPath(String path) {
- this.path = path;
- return this;
- }
-
- public Integer getDepth() {
- return depth;
- }
-
- /**
- * Sets the depth of the snapshot
- *
- * @throws IllegalArgumentException when depth is negative
- */
- public void setDepth(Integer depth) {
- if (depth != null && depth < 0) {
- throw new IllegalArgumentException("depth can not be negative : " + depth);
- }
- this.depth = depth;
- }
-
- public Integer getRootProjectId() {
- return rootProjectId;
- }
-
- public Snapshot setRootProjectId(Integer rootProjectId) {
- this.rootProjectId = rootProjectId;
- return this;
- }
-
- public String getPeriodMode(int index) {
- switch (index) {
- case 1:
- return period1Mode;
- case 2:
- return period2Mode;
- case 3:
- return period3Mode;
- case 4:
- return period4Mode;
- case 5:
- return period5Mode;
- default:
- throw newPeriodIndexOutOfBoundsException("periodMode");
- }
- }
-
- public String getPeriodModeParameter(int periodIndex) {
- switch (periodIndex) {
- case 1:
- return period1Param;
- case 2:
- return period2Param;
- case 3:
- return period3Param;
- case 4:
- return period4Param;
- case 5:
- return period5Param;
- default:
- throw newPeriodIndexOutOfBoundsException("periodParameter");
- }
- }
-
- public Long getPeriodDateMs(int periodIndex) {
- switch (periodIndex) {
- case 1:
- return period1Date;
- case 2:
- return period2Date;
- case 3:
- return period3Date;
- case 4:
- return period4Date;
- case 5:
- return period5Date;
- default:
- throw newPeriodIndexOutOfBoundsException("periodDate");
- }
- }
-
- private static IndexOutOfBoundsException newPeriodIndexOutOfBoundsException(String field) {
- return new IndexOutOfBoundsException(String.format("Index of Snapshot.%s is between 1 and 5", field));
- }
-
- @Override
- public boolean equals(Object obj) {
- if (!(obj instanceof Snapshot)) {
- return false;
- }
- if (this == obj) {
- return true;
- }
- Snapshot other = (Snapshot) obj;
- return new EqualsBuilder()
- .append(resourceId, other.getResourceId())
- .append(createdAt, other.getCreatedAtMs())
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(resourceId)
- .append(createdAt)
- .toHashCode();
- }
-
- @Override
- public String toString() {
- return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
- }
-}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java
deleted file mode 100644
index adcbe3466a3..00000000000
--- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java
+++ /dev/null
@@ -1,63 +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.api.database.model;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-public class SnapshotTest {
-
- @Test
- public void testGetDate() {
- Snapshot snapshot = new Snapshot();
- assertNull(snapshot.getCreatedAtMs());
-
- Long now = System.currentTimeMillis();
- snapshot.setCreatedAtMs(now);
- assertEquals(now, snapshot.getCreatedAtMs());
- }
-
- @Test
- public void testGetVersion() {
- Snapshot snapshot = new Snapshot();
- assertNull(snapshot.getVersion());
-
- snapshot.setVersion("1.0");
- assertEquals("1.0", snapshot.getVersion());
- }
-
- @Test
- public void testGetStatus() {
- Snapshot snapshot = new Snapshot();
- assertNotNull(snapshot.getStatus());
- assertEquals(Snapshot.STATUS_UNPROCESSED, snapshot.getStatus());
- }
-
- @Test
- public void testGetLast() {
- Snapshot snapshot = new Snapshot();
- assertNotNull(snapshot.getLast());
- assertEquals(Boolean.FALSE, snapshot.getLast());
- }
-
-}