diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-02-18 15:24:01 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-02-18 15:24:01 +0100 |
commit | 318df64dc365d1bd21b6576f9a00f29bda66882a (patch) | |
tree | e2c246660f2c94aa7dee11ad44f4d6a4d08df8f6 /sonar-plugin-api | |
parent | 7f646b72d3c5dc7700c36188ece84ad6e205fc53 (diff) | |
parent | 8640ce8dee1ff1f515d8c8b8564e0c53e5d6b5ec (diff) | |
download | sonarqube-318df64dc365d1bd21b6576f9a00f29bda66882a.tar.gz sonarqube-318df64dc365d1bd21b6576f9a00f29bda66882a.zip |
Merge branch 'master' into feature/branding
Diffstat (limited to 'sonar-plugin-api')
12 files changed, 228 insertions, 79 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java index 8c802c2ca98..eb4db71fe41 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java @@ -26,6 +26,9 @@ import org.sonar.api.database.model.Snapshot; import javax.persistence.*; import java.util.Date; +import static com.google.common.base.Preconditions.checkNotNull; +import static org.sonar.api.utils.DateUtils.longToDate; + /** * @since 1.10 */ @@ -46,10 +49,10 @@ public class Event extends BaseIdentifiable { private String category; @Column(name = "event_date", updatable = true, nullable = false) - private Date date; + private Long date; - @Column(name = "created_at", updatable = true, nullable = true) - private Date createdAt; + @Column(name = "created_at", updatable = true, nullable = false) + private Long createdAt; @Column(name = "event_data", updatable = true, nullable = true) private String data; @@ -103,11 +106,11 @@ public class Event extends BaseIdentifiable { } public Date getDate() { - return date; + return longToDate(date); } public void setDate(Date date) { - this.date = date; + this.date = date.getTime(); } public Snapshot getSnapshot() { @@ -115,19 +118,17 @@ public class Event extends BaseIdentifiable { } public Date getCreatedAt() { - return createdAt; + return new Date(createdAt); } public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; + this.createdAt = createdAt.getTime(); } public final void setSnapshot(Snapshot snapshot) { - this.snapshot = snapshot; - if (snapshot != null) { - this.date = (snapshot.getCreatedAtMs() == null ? null : new Date(snapshot.getCreatedAtMs())); - this.resourceId = snapshot.getResourceId(); - } + this.snapshot = checkNotNull(snapshot, "it is not possible to set a null snapshot linked to an event"); + this.date = snapshot.getCreatedAtMs(); + this.resourceId = snapshot.getResourceId(); } public Integer getResourceId() { diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java index b75209e1538..6a5463e67f9 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SensorContext.java @@ -30,6 +30,7 @@ import org.sonar.api.resources.Resource; import org.sonar.api.rules.Violation; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.io.Serializable; import java.util.Collection; @@ -191,14 +192,23 @@ public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext // ----------- DEPENDENCIES BETWEEN RESOURCES -------------- /** - * Build a new dependency : from depends upon to. The dependency is NOT saved. The method saveDependency() must still be executed. + * @deprecated since 5.1 use {@link #newDependency()} */ Dependency saveDependency(Dependency dependency); + /** + * @deprecated since 5.1 Sensors should not read but only save data + */ Set<Dependency> getDependencies(); + /** + * @deprecated since 5.1 Sensors should not read but only save data + */ Collection<Dependency> getIncomingDependencies(Resource to); + /** + * @deprecated since 5.1 Sensors should not read but only save data + */ Collection<Dependency> getOutgoingDependencies(Resource from); // ----------- FILE SOURCES -------------- @@ -242,7 +252,7 @@ public interface SensorContext extends org.sonar.api.batch.sensor.SensorContext * @param date the event date * @return the created event */ - Event createEvent(Resource resource, String name, String description, String category, Date date); + Event createEvent(Resource resource, String name, @Nullable String description, String category, @Nullable Date date); /** * Deletes an event diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java index f21b83bab5f..6714ed9c1bb 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/SonarIndex.java @@ -30,6 +30,7 @@ import org.sonar.api.rules.Violation; import org.sonar.graph.DirectedGraphAccessor; import javax.annotation.CheckForNull; +import javax.annotation.Nullable; import java.util.Collection; import java.util.Date; @@ -155,7 +156,7 @@ public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Depe public abstract void deleteEvent(Event event); - public abstract Event addEvent(Resource resource, String name, String description, String category, Date date); + public abstract Event addEvent(Resource resource, String name, String description, String category, @Nullable Date date); public final Collection<Dependency> getOutgoingDependencies(Resource from) { return getOutgoingEdges(from); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java index b36786c2333..a1de94d8b3f 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/SensorContext.java @@ -24,7 +24,7 @@ import org.sonar.api.batch.CpdMapping; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.rule.ActiveRules; -import org.sonar.api.batch.sensor.dependency.Dependency; +import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.duplication.NewDuplication; import org.sonar.api.batch.sensor.highlighting.HighlightingBuilder; import org.sonar.api.batch.sensor.issue.Issue; @@ -82,7 +82,6 @@ public interface SensorContext { /** * Builder to define highlighting of a file. - * @since 4.5 */ HighlightingBuilder highlightingBuilder(InputFile inputFile); @@ -90,7 +89,6 @@ public interface SensorContext { /** * Builder to define symbol references in a file. - * @since 4.5 */ SymbolTableBuilder symbolTableBuilder(InputFile inputFile); @@ -99,7 +97,6 @@ public interface SensorContext { /** * Builder to manually register duplication in a file. This can be used in addition to {@link CpdMapping} extension point. * Don't forget to call {@link NewDuplication#save()}. - * @since 5.1 */ NewDuplication newDuplication(); @@ -108,21 +105,18 @@ public interface SensorContext { /** * Create a new coverage report. * Don't forget to call {@link Coverage#save()} once all parameters are provided. - * @since 5.0 */ Coverage newCoverage(); /** * Create a new test case execution report. * Don't forget to call {@link TestCaseExecution#save()} once all parameters are provided. - * @since 5.0 */ TestCaseExecution newTestCaseExecution(); /** * Create a new test case coverage report. * Don't forget to call {@link TestCaseCoverage#save()} once all parameters are provided. - * @since 5.0 */ TestCaseCoverage newTestCaseCoverage(); @@ -130,9 +124,8 @@ public interface SensorContext { /** * Create a new dependency. - * Don't forget to call {@link Dependency#save()} once all parameters are provided. - * @since 5.0 + * Don't forget to call {@link NewDependency#save()} once all parameters are provided. */ - Dependency newDependency(); + NewDependency newDependency(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java index 87bd3029fbd..56185acaf3a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/Dependency.java @@ -19,36 +19,19 @@ */ package org.sonar.api.batch.sensor.dependency; -import com.google.common.annotations.Beta; -import org.sonar.api.batch.fs.InputFile; /** - * @since 5.0 + * @since 5.1 */ -@Beta public interface Dependency { - InputFile from(); + String fromKey(); - Dependency from(InputFile from); - - InputFile to(); - - Dependency to(InputFile to); + String toKey(); /** * Default weight value is 1. */ int weight(); - /** - * Set the weight of the dependency. - */ - Dependency weight(int weight); - - /** - * Save the dependency. - */ - void save(); - } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java new file mode 100644 index 00000000000..8d62a2f6516 --- /dev/null +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/NewDependency.java @@ -0,0 +1,45 @@ +/* + * 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.batch.sensor.dependency; + +import org.sonar.api.batch.fs.InputFile; + +/** + * Builder to create new Dependency. + * Should not be implemented by client. + * @since 5.1 + */ +public interface NewDependency { + + NewDependency from(InputFile from); + + NewDependency to(InputFile to); + + /** + * Set the weight of the dependency. If not set default weight is 1. + */ + NewDependency weight(int weight); + + /** + * Save the dependency. It is not permitted so save several time a dependency between two same files. + */ + void save(); + +} diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java index c7ab2fcc997..9dcb3d34ece 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/sensor/dependency/internal/DefaultDependency.java @@ -23,16 +23,18 @@ import com.google.common.base.Preconditions; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.sensor.SensorStorage; import org.sonar.api.batch.sensor.dependency.Dependency; +import org.sonar.api.batch.sensor.dependency.NewDependency; import org.sonar.api.batch.sensor.internal.DefaultStorable; import javax.annotation.Nullable; -public class DefaultDependency extends DefaultStorable implements Dependency { +public class DefaultDependency extends DefaultStorable implements Dependency, NewDependency { - private InputFile from; - private InputFile to; + private String fromKey; + private String toKey; private int weight = 1; public DefaultDependency() { @@ -44,21 +46,21 @@ public class DefaultDependency extends DefaultStorable implements Dependency { } @Override - public Dependency from(InputFile from) { + public DefaultDependency from(InputFile from) { Preconditions.checkNotNull(from, "InputFile should be non null"); - this.from = from; + this.fromKey = ((DefaultInputFile) from).key(); return this; } @Override - public Dependency to(InputFile to) { + public DefaultDependency to(InputFile to) { Preconditions.checkNotNull(to, "InputFile should be non null"); - this.to = to; + this.toKey = ((DefaultInputFile) to).key(); return this; } @Override - public Dependency weight(int weight) { + public DefaultDependency weight(int weight) { Preconditions.checkArgument(weight > 1, "weight should be greater than 1"); this.weight = weight; return this; @@ -66,20 +68,30 @@ public class DefaultDependency extends DefaultStorable implements Dependency { @Override public void doSave() { - Preconditions.checkState(!this.from.equals(this.to), "From and To can't be the same inputFile"); - Preconditions.checkNotNull(this.from, "From inputFile can't be null"); - Preconditions.checkNotNull(this.to, "To inputFile can't be null"); + Preconditions.checkState(!this.fromKey.equals(this.toKey), "From and To can't be the same inputFile"); + Preconditions.checkNotNull(this.fromKey, "From inputFile can't be null"); + Preconditions.checkNotNull(this.toKey, "To inputFile can't be null"); storage.store((Dependency) this); } @Override - public InputFile from() { - return this.from; + public String fromKey() { + return this.fromKey; + } + + public DefaultDependency setFromKey(String fromKey) { + this.fromKey = fromKey; + return this; } @Override - public InputFile to() { - return this.to; + public String toKey() { + return this.toKey; + } + + public DefaultDependency setToKey(String toKey) { + this.toKey = toKey; + return this; } @Override @@ -87,6 +99,11 @@ public class DefaultDependency extends DefaultStorable implements Dependency { return this.weight; } + public DefaultDependency setWeight(int weight) { + this.weight = weight; + return this; + } + // For testing purpose @Override @@ -102,8 +119,8 @@ public class DefaultDependency extends DefaultStorable implements Dependency { } DefaultDependency rhs = (DefaultDependency) obj; return new EqualsBuilder() - .append(from, rhs.from) - .append(to, rhs.to) + .append(fromKey, rhs.fromKey) + .append(toKey, rhs.toKey) .append(weight, rhs.weight) .isEquals(); } @@ -111,8 +128,8 @@ public class DefaultDependency extends DefaultStorable implements Dependency { @Override public int hashCode() { return new HashCodeBuilder(27, 45). - append(from). - append(to). + append(fromKey). + append(toKey). append(weight). toHashCode(); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java index 0e0f316d532..d0f53d44024 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java @@ -102,7 +102,15 @@ public final class License { @VisibleForTesting boolean isExpired(Date now) { Date date = getExpirationDate(); - return date != null && !date.after(org.apache.commons.lang.time.DateUtils.truncate(now, Calendar.DATE)); + if (date == null) { + return false; + } + // SONAR-6079 include last day + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.DAY_OF_MONTH, 1); + cal.add(Calendar.SECOND, -1); + return now.after(cal.getTime()); } @Nullable diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java index 5b7537f20da..bc965583881 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/design/Dependency.java @@ -50,11 +50,25 @@ public class Dependency implements Edge<Resource> { return from; } + /** + * For internal use only + */ + public void setFrom(Resource from) { + this.from = from; + } + @Override public Resource getTo() { return to; } + /** + * For internal use only + */ + public void setTo(Resource to) { + this.to = to; + } + public String getUsage() { return usage; } @@ -105,26 +119,26 @@ public class Dependency implements Edge<Resource> { } Dependency other = (Dependency) obj; return new EqualsBuilder() - .append(from, other.from) - .append(to, other.to) - .isEquals(); + .append(from, other.from) + .append(to, other.to) + .isEquals(); } @Override public int hashCode() { return new HashCodeBuilder(17, 37) - .append(from) - .append(to) - .toHashCode(); + .append(from) + .append(to) + .toHashCode(); } @Override public String toString() { return new ToStringBuilder(this) - .append("from", from) - .append("to", to) - .append("weight", weight) - .append("usage", usage) - .toString(); + .append("from", from) + .append("to", to) + .append("weight", weight) + .append("usage", usage) + .toString(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java index 19ce2aa8fc8..80d273a13ed 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/resources/ResourceUtils.java @@ -120,8 +120,17 @@ public final class ResourceUtils { /** * @return whether a resource is a unit test class + * @deprecated since 5.1 use {@link #isUnitTestFile(Resource)} */ + @Deprecated public static boolean isUnitTestClass(Resource resource) { + return isUnitTestFile(resource); + } + + /** + * @return whether a resource is a unit test class + */ + public static boolean isUnitTestFile(Resource resource) { return Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier()); } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java index 4ddf32cd622..f26cad3ae4c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/server/rule/RulesDefinition.java @@ -293,6 +293,61 @@ public interface RulesDefinition extends ServerExtension { */ public static final String UNIT_TESTABILITY = "UNIT_TESTABILITY"; + /** + * Related to characteristic ACCESSIBILITY + */ + public static final String USABILITY_ACCESSIBILITY = "USABILITY_ACCESSIBILITY"; + + /** + * Related to characteristic ACCESSIBILITY + */ + public static final String USABILITY_COMPLIANCE = "USABILITY_COMPLIANCE"; + + /** + * Related to characteristic ACCESSIBILITY + */ + public static final String USABILITY_EASE_OF_USE = "USABILITY_EASE_OF_USE"; + + /** + * Related to characteristic REUSABILITY + */ + public static final String REUSABILITY_COMPLIANCE = "REUSABILITY_COMPLIANCE"; + + /** + * Related to characteristic PORTABILITY + */ + public static final String PORTABILITY_COMPLIANCE = "PORTABILITY_COMPLIANCE"; + + /** + * Related to characteristic MAINTAINABILITY + */ + public static final String MAINTAINABILITY_COMPLIANCE = "MAINTAINABILITY_COMPLIANCE"; + + /** + * Related to characteristic SECURITY + */ + public static final String SECURITY_COMPLIANCE = "SECURITY_COMPLIANCE"; + + /** + * Related to characteristic EFFICIENCY + */ + public static final String EFFICIENCY_COMPLIANCE = "EFFICIENCY_COMPLIANCE"; + + /** + * Related to characteristic CHANGEABILITY + */ + public static final String CHANGEABILITY_COMPLIANCE = "CHANGEABILITY_COMPLIANCE"; + + /** + * Related to characteristic RELIABILITY + */ + public static final String RELIABILITY_COMPLIANCE = "RELIABILITY_COMPLIANCE"; + + /** + * Related to characteristic TESTABILITY + */ + public static final String TESTABILITY_COMPLIANCE = "TESTABILITY_COMPLIANCE"; + private SubCharacteristics() { // only constants } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java index 305132e5251..ed490dd9ee7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java @@ -23,6 +23,9 @@ import org.apache.commons.codec.binary.Base64; import org.junit.Test; import org.sonar.api.utils.DateUtils; +import java.util.Calendar; +import java.util.TimeZone; + import static org.assertj.core.api.Assertions.assertThat; public class LicenseTest { @@ -131,10 +134,20 @@ public class LicenseTest { public void isExpired() { License license = License.readPlainText(V2_FORMAT); - assertThat(license.isExpired(DateUtils.parseDate("2013-06-23"))).isTrue(); - assertThat(license.isExpired(DateUtils.parseDate("2012-05-18"))).isTrue(); - assertThat(license.isExpired(DateUtils.parseDateTime("2012-05-18T15:50:45+0100"))).isTrue(); assertThat(license.isExpired(DateUtils.parseDate("2011-01-01"))).isFalse(); + Calendar sameDay = Calendar.getInstance(TimeZone.getDefault()); + sameDay.setTime(DateUtils.parseDate("2012-05-18")); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + sameDay.set(Calendar.HOUR_OF_DAY, 15); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + sameDay.set(Calendar.HOUR_OF_DAY, 23); + sameDay.set(Calendar.MINUTE, 59); + sameDay.set(Calendar.SECOND, 59); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + // The day after + sameDay.add(Calendar.SECOND, 1); + assertThat(license.isExpired(sameDay.getTime())).isTrue(); + assertThat(license.isExpired(DateUtils.parseDate("2013-06-23"))).isTrue(); } @Test |