]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10555 enforce at API level that project version is never null
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 21 Aug 2018 15:51:29 +0000 (17:51 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 3 Oct 2018 07:28:22 +0000 (09:28 +0200)
63 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/api/measurecomputer/MeasureComputerContextImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/Component.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilder.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DepthTraversalTypeAwareCrawler.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MapBasedDbIdsRepository.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/PathAwareCrawler.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectAttributes.java [new file with mode: 0644]
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ReportAttributes.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/DuplicationRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/IntegrateCrossProjectDuplications.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/filemove/MutableMovedFilesRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/IntegrateIssuesVisitor.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitor.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/ShortBranchIssuesLoader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerMergeBranchInputFactory.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactory.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/MapBasedRawMeasureRepository.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceHashRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/HighlightingLineReader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/linereader/SymbolsLineReader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/DuplicationDataMeasuresStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadCrossProjectDuplicationsRepositoryStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistFileSourcesStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistTestsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderPathAwareVisitor.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/CallRecorderTypeAwareVisitor.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/MutableDbIdsRepositoryRule.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/TreeComponentProvider.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsComponent.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPostOrderDepthTraversalTypeAwareCrawlerTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsPreOrderDepthTraversalTypeAwareCrawlerTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ViewsVisitorsCrawlerTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/MovedIssueVisitorTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/issue/TrackerRawInputFactoryTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/measure/MeasureRepositoryRule.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistComponentsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistLiveMeasuresStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java

index 02ccfa25b248a67de9a61deca2c864463fcc5c68..80f660c3cd736eff82ae0634a35b048e4e8d20c8 100644 (file)
@@ -169,7 +169,7 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
     checkArgument(definition.getOutputMetrics().contains(metric.getKey()), "Only metrics in %s can be used to add measures. Metric '%s' is not allowed.",
       definition.getOutputMetrics(), metric.getKey());
     if (measureRepository.getRawMeasure(internalComponent, metric).isPresent()) {
-      throw new UnsupportedOperationException(String.format("A measure on metric '%s' already exists on component '%s'", metric.getKey(), internalComponent.getKey()));
+      throw new UnsupportedOperationException(String.format("A measure on metric '%s' already exists on component '%s'", metric.getKey(), internalComponent.getDbKey()));
     }
   }
 
@@ -180,7 +180,7 @@ public class MeasureComputerContextImpl implements MeasureComputerContext {
 
   private static Component newComponent(org.sonar.ce.task.projectanalysis.component.Component component) {
     return new ComponentImpl(
-      component.getKey(),
+      component.getDbKey(),
       Component.Type.valueOf(component.getType().name()),
       component.getType() == org.sonar.ce.task.projectanalysis.component.Component.Type.FILE
         ? new ComponentImpl.FileAttributesImpl(component.getFileAttributes().getLanguageKey(), component.getFileAttributes().isUnitTest())
index dd11b363d3f697ff21289ec31d13c4f32e907393..622922c9e56b192fb91623021b12b75775d97adc 100644 (file)
@@ -112,7 +112,7 @@ public class BranchPersisterImpl implements BranchPersister {
     branchDto.setUuidPath(UUID_PATH_OF_ROOT);
     branchDto.setModuleUuidPath(UUID_PATH_SEPARATOR + branchUuid + UUID_PATH_SEPARATOR);
     branchDto.setMainBranchProjectUuid(mainBranchProjectUuid);
-    branchDto.setDbKey(treeRootHolder.getRoot().getKey());
+    branchDto.setDbKey(treeRootHolder.getRoot().getDbKey());
     branchDto.setCreatedAt(new Date(system2.now()));
     dbClient.componentDao().insert(dbSession, branchDto);
     return branchDto;
index e76ee80f181da3ff9e325dd504d51c99a0384b45..c56727e0b165aafe482056f3a40e0e3dfb13f9fe 100644 (file)
@@ -80,15 +80,14 @@ public interface Component {
    * It may differ from keys listed in scanner report
    * when analyzing a branch.
    */
-  String getKey();
+  String getDbKey();
 
   /**
    * Returns the key as it will be displayed in the ui.
    * If legacy branch feature is used, the key will contain the branch name
    * If new branch feature is used, the key will not contain the branch name
    */
-  // TODO to be renamed getKey() and rename existing getKey to getDbKey
-  String getPublicKey();
+  String getKey();
 
   /**
    * The component name.
@@ -103,6 +102,13 @@ public interface Component {
 
   List<Component> getChildren();
 
+  /**
+   * Returns the attributes specific to components of type {@link Type#PROJECT}.
+   *
+   * @throws IllegalStateException when the component's type is not {@link Type#PROJECT}.
+   */
+  ProjectAttributes getProjectAttributes();
+
   /**
    * Returns the attributes specific to components of type {@link Type#PROJECT}, {@link Type#MODULE},
    * {@link Type#DIRECTORY} or {@link Type#FILE}.
index a84693e9f422659b512825855f25fe8683d83c0c..944229f410435351e12267aa42b8389651cc35c1 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.ce.task.projectanalysis.component;
 
+import com.google.common.base.MoreObjects;
 import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.List;
@@ -39,14 +40,15 @@ public class ComponentImpl implements Component {
   private final Type type;
   private final Status status;
   private final String name;
+  private final String dbKey;
   private final String key;
-  private final String publicKey;
   private final String uuid;
 
   @CheckForNull
   private final String description;
   private final List<Component> children;
   @CheckForNull
+  private final ProjectAttributes projectAttributes;
   private final ReportAttributes reportAttributes;
   @CheckForNull
   private final FileAttributes fileAttributes;
@@ -54,11 +56,12 @@ public class ComponentImpl implements Component {
   private ComponentImpl(Builder builder) {
     this.type = builder.type;
     this.status = builder.status;
-    this.key = builder.key;
-    this.publicKey = builder.publicKey;
+    this.dbKey = builder.dbKey;
+    this.key = MoreObjects.firstNonNull(builder.key, builder.dbKey);
     this.name = builder.name;
     this.description = builder.description;
     this.uuid = builder.uuid;
+    this.projectAttributes = builder.projectAttributes;
     this.reportAttributes = builder.reportAttributes;
     this.fileAttributes = builder.fileAttributes;
     this.children = ImmutableList.copyOf(builder.children);
@@ -80,13 +83,13 @@ public class ComponentImpl implements Component {
   }
 
   @Override
-  public String getKey() {
-    return key;
+  public String getDbKey() {
+    return dbKey;
   }
 
   @Override
-  public String getPublicKey() {
-    return publicKey;
+  public String getKey() {
+    return key;
   }
 
   @Override
@@ -105,6 +108,12 @@ public class ComponentImpl implements Component {
     return children;
   }
 
+  @Override
+  public ProjectAttributes getProjectAttributes() {
+    checkState(this.type == Type.PROJECT, "Only component of type PROJECT have a ProjectAttributes object");
+    return this.projectAttributes;
+  }
+
   @Override
   public ReportAttributes getReportAttributes() {
     return this.reportAttributes;
@@ -137,7 +146,8 @@ public class ComponentImpl implements Component {
 
   public static final class Builder {
 
-    private static final String KEY_CANNOT_BE_NULL = "key can't be null";
+    private static final String DB_KEY_CANNOT_BE_NULL = "DB key can't be null";
+    private static final String KEY_CANNOT_BE_NULL = "Key can't be null";
     private static final String UUID_CANNOT_BE_NULL = "uuid can't be null";
     private static final String REPORT_ATTRIBUTES_CANNOT_BE_NULL = "reportAttributes can't be null";
     private static final String NAME_CANNOT_BE_NULL = "name can't be null";
@@ -145,10 +155,11 @@ public class ComponentImpl implements Component {
 
     private final Type type;
     private Status status;
+    private ProjectAttributes projectAttributes;
     private ReportAttributes reportAttributes;
     private String uuid;
+    private String dbKey;
     private String key;
-    private String publicKey;
     private String name;
     private String description;
     private FileAttributes fileAttributes;
@@ -158,11 +169,6 @@ public class ComponentImpl implements Component {
       this.type = requireNonNull(type, "type can't be null");
     }
 
-    public Builder setReportAttributes(ReportAttributes reportAttributes) {
-      this.reportAttributes = requireNonNull(reportAttributes, REPORT_ATTRIBUTES_CANNOT_BE_NULL);
-      return this;
-    }
-
     public Builder setUuid(String s) {
       this.uuid = requireNonNull(s, UUID_CANNOT_BE_NULL);
       return this;
@@ -178,13 +184,13 @@ public class ComponentImpl implements Component {
       return this;
     }
 
-    public Builder setKey(String s) {
-      this.key = requireNonNull(s, KEY_CANNOT_BE_NULL);
+    public Builder setDbKey(String s) {
+      this.dbKey = requireNonNull(s, DB_KEY_CANNOT_BE_NULL);
       return this;
     }
 
-    public Builder setPublicKey(String publicKey) {
-      this.publicKey = requireNonNull(publicKey);
+    public Builder setKey(String key) {
+      this.key = requireNonNull(key, KEY_CANNOT_BE_NULL);
       return this;
     }
 
@@ -198,6 +204,17 @@ public class ComponentImpl implements Component {
       return this;
     }
 
+    public Builder setProjectAttributes(ProjectAttributes projectAttributes) {
+      checkProjectAttributes(projectAttributes);
+      this.projectAttributes = projectAttributes;
+      return this;
+    }
+
+    public Builder setReportAttributes(ReportAttributes reportAttributes) {
+      this.reportAttributes = requireNonNull(reportAttributes, REPORT_ATTRIBUTES_CANNOT_BE_NULL);
+      return this;
+    }
+
     public Builder setFileAttributes(@Nullable FileAttributes fileAttributes) {
       this.fileAttributes = fileAttributes;
       return this;
@@ -214,23 +231,32 @@ public class ComponentImpl implements Component {
     public ComponentImpl build() {
       requireNonNull(reportAttributes, REPORT_ATTRIBUTES_CANNOT_BE_NULL);
       requireNonNull(uuid, UUID_CANNOT_BE_NULL);
-      requireNonNull(key, KEY_CANNOT_BE_NULL);
+      requireNonNull(dbKey, DB_KEY_CANNOT_BE_NULL);
       requireNonNull(name, NAME_CANNOT_BE_NULL);
       requireNonNull(status, STATUS_CANNOT_BE_NULL);
+      checkProjectAttributes(this.projectAttributes);
       return new ComponentImpl(this);
     }
+
+    private void checkProjectAttributes(@Nullable ProjectAttributes projectAttributes) {
+      checkArgument(type != Type.PROJECT ^ projectAttributes != null, "ProjectAttributes must and can only be set for type PROJECT");
+    }
   }
 
   @Override
   public String toString() {
     return "ComponentImpl{" +
-      "key='" + key + '\'' +
-      ", type=" + type +
-      ", uuid='" + uuid + '\'' +
+      "type=" + type +
+      ", status=" + status +
       ", name='" + name + '\'' +
+      ", dbKey='" + dbKey + '\'' +
+      ", key='" + key + '\'' +
+      ", uuid='" + uuid + '\'' +
       ", description='" + description + '\'' +
-      ", fileAttributes=" + fileAttributes +
+      ", children=" + children +
+      ", projectAttributes=" + projectAttributes +
       ", reportAttributes=" + reportAttributes +
+      ", fileAttributes=" + fileAttributes +
       '}';
   }
 
index bc605c43db23ef0b6561340ab2f409767336a015..a388d71c3ddb887e40ac8bee554e9e0cb1e35cb5 100644 (file)
@@ -101,12 +101,11 @@ public class ComponentTreeBuilder {
         String projectPublicKey = publicKeyGenerator.generateKey(component, null);
         ComponentImpl.Builder builder = ComponentImpl.builder(Component.Type.PROJECT)
           .setUuid(uuid)
-          .setKey(projectKey)
-          .setPublicKey(projectPublicKey)
+          .setDbKey(projectKey)
+          .setKey(projectPublicKey)
           .setStatus(convertStatus(component.getStatus()))
-          .setReportAttributes(createAttributesBuilder(component, scmBasePath)
-            .setVersion(createProjectVersion(component))
-            .build())
+          .setProjectAttributes(new ProjectAttributes(createProjectVersion(component)))
+          .setReportAttributes(createAttributesBuilder(component, scmBasePath).build())
           .addChildren(buildChildren(component, component, scmBasePath));
         setNameAndDescription(component, builder);
         return builder.build();
@@ -116,8 +115,8 @@ public class ComponentTreeBuilder {
         String modulePublicKey = publicKeyGenerator.generateKey(component, null);
         return ComponentImpl.builder(Component.Type.MODULE)
           .setUuid(uuidSupplier.apply(moduleKey))
-          .setKey(moduleKey)
-          .setPublicKey(modulePublicKey)
+          .setDbKey(moduleKey)
+          .setKey(modulePublicKey)
           .setName(nameOfOthers(component, modulePublicKey))
           .setStatus(convertStatus(component.getStatus()))
           .setDescription(trimToNull(component.getDescription()))
@@ -131,8 +130,8 @@ public class ComponentTreeBuilder {
         String publicKey = publicKeyGenerator.generateKey(closestModule, component);
         return ComponentImpl.builder(convertDirOrFileType(component.getType()))
           .setUuid(uuidSupplier.apply(key))
-          .setKey(key)
-          .setPublicKey(publicKey)
+          .setDbKey(key)
+          .setKey(publicKey)
           .setName(nameOfOthers(component, publicKey))
           .setStatus(convertStatus(component.getStatus()))
           .setDescription(trimToNull(component.getDescription()))
@@ -153,8 +152,8 @@ public class ComponentTreeBuilder {
   private static ComponentImpl.Builder changedComponentBuilder(Component component) {
     return ComponentImpl.builder(component.getType())
       .setUuid(component.getUuid())
+      .setDbKey(component.getDbKey())
       .setKey(component.getKey())
-      .setPublicKey(component.getPublicKey())
       .setStatus(component.getStatus())
       .setReportAttributes(component.getReportAttributes())
       .setName(component.getName())
@@ -181,6 +180,7 @@ public class ComponentTreeBuilder {
 
   private static Component buildChangedProject(Component component) {
     return changedComponentBuilder(component)
+      .setProjectAttributes(new ProjectAttributes(component.getProjectAttributes().getVersion()))
       .addChildren(buildChangedComponentChildren(component))
       .build();
   }
@@ -268,7 +268,6 @@ public class ComponentTreeBuilder {
 
   private static ReportAttributes.Builder createAttributesBuilder(ScannerReport.Component component, @Nullable String scmBasePath) {
     return ReportAttributes.newBuilder(component.getRef())
-      .setVersion(trimToNull(component.getVersion()))
       .setPath(trimToNull(component.getPath()))
       .setScmPath(computeScmPath(scmBasePath, component.getProjectRelativePath()));
   }
index 6a36afaf7404b3089dc32b99ec5f4ab34f0509b5..9f20ce4c548f2bd95eeb23ff2f61676321e9a0ba 100644 (file)
@@ -38,7 +38,7 @@ public final class DepthTraversalTypeAwareCrawler implements ComponentCrawler {
     try {
       visitImpl(component);
     } catch (RuntimeException e) {
-      VisitException.rethrowOrWrap(e, "Visit of Component {key=%s,uuid=%s,type=%s} failed", component.getKey(), component.getUuid(), component.getType());
+      VisitException.rethrowOrWrap(e, "Visit of Component {key=%s,uuid=%s,type=%s} failed", component.getDbKey(), component.getUuid(), component.getType());
     }
   }
 
index 153faca37ac5ff9b838805e488347f0bcd044c6b..4b8e8f3c1fd0c81fec5c6f0c3e3afb4b394b5f79 100644 (file)
@@ -46,7 +46,7 @@ public final class MapBasedDbIdsRepository<T> implements MutableDbIdsRepository
     T ref = componentToKey.apply(component);
     Long existingComponentId = componentIdsByRef.get(ref);
     checkState(existingComponentId == null,
-      "Component id '%s' is already registered in repository for Component '%s', can not set new id '%s'", existingComponentId, component.getKey(), componentId);
+      "Component id '%s' is already registered in repository for Component '%s', can not set new id '%s'", existingComponentId, component.getDbKey(), componentId);
     componentIdsByRef.put(ref, componentId);
     return this;
   }
@@ -55,7 +55,7 @@ public final class MapBasedDbIdsRepository<T> implements MutableDbIdsRepository
   public long getComponentId(Component component) {
     T ref = componentToKey.apply(component);
     Long componentId = componentIdsByRef.get(ref);
-    checkState(componentId != null, "No component id registered in repository for Component '%s'", component.getKey());
+    checkState(componentId != null, "No component id registered in repository for Component '%s'", component.getDbKey());
     return componentId;
   }
 
index ac1e3cba6153af6ba7a008d677f993e8963d971a..1477db0d487b362e09712d42fa6943d6d483b895 100644 (file)
@@ -52,7 +52,7 @@ public final class PathAwareCrawler<T> implements ComponentCrawler {
       VisitException.rethrowOrWrap(
         e,
         "Visit failed for Component {key=%s,type=%s} %s",
-        component.getKey(), component.getType(), new ComponentPathPrinter<>(stack));
+        component.getDbKey(), component.getType(), new ComponentPathPrinter<>(stack));
     }
   }
 
@@ -174,7 +174,7 @@ public final class PathAwareCrawler<T> implements ComponentCrawler {
       @Override
       @Nonnull
       public String apply(@Nonnull PathAwareVisitor.PathElement<?> input) {
-        return format("%s(type=%s)", input.getComponent().getKey(), input.getComponent().getType());
+        return format("%s(type=%s)", input.getComponent().getDbKey(), input.getComponent().getType());
       }
     }
   }
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectAttributes.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectAttributes.java
new file mode 100644 (file)
index 0000000..2c6d381
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.ce.task.projectanalysis.component;
+
+import java.util.Objects;
+
+public class ProjectAttributes {
+  private final String version;
+
+  public ProjectAttributes(String version) {
+    this.version = Objects.requireNonNull(version, "version can't be null");
+  }
+
+  public String getVersion() {
+    return version;
+  }
+
+  @Override
+  public String toString() {
+    return "ProjectAttributes{" +
+      "version='" + version + '\'' +
+      '}';
+  }
+}
index 0bee43d86a2d307f9931568c4578886da81f2ad5..4dd5834e351a6ba93271fd5fa12d8487cb9bac17 100644 (file)
@@ -31,15 +31,12 @@ import javax.annotation.concurrent.Immutable;
 public class ReportAttributes {
   private final int ref;
   @CheckForNull
-  private final String version;
-  @CheckForNull
   private final String path;
   @CheckForNull
   private final String scmPath;
 
   private ReportAttributes(Builder builder) {
     this.ref = builder.ref;
-    this.version = builder.version;
     this.path = builder.path;
     this.scmPath = builder.scmPath;
   }
@@ -51,8 +48,6 @@ public class ReportAttributes {
   public static class Builder {
     private final int ref;
     @CheckForNull
-    private String version;
-    @CheckForNull
     private String path;
     @CheckForNull
     private String scmPath;
@@ -61,11 +56,6 @@ public class ReportAttributes {
       this.ref = ref;
     }
 
-    public Builder setVersion(@Nullable String version) {
-      this.version = version;
-      return this;
-    }
-
     public Builder setPath(@Nullable String path) {
       this.path = path;
       return this;
@@ -88,14 +78,6 @@ public class ReportAttributes {
     return ref;
   }
 
-  /**
-   * The project or module version as defined in the batch report.
-   */
-  @CheckForNull
-  public String getVersion() {
-    return this.version;
-  }
-
   /**
    * The path of the report component, must be non null for module, directories and files.
    */
@@ -118,7 +100,6 @@ public class ReportAttributes {
   public String toString() {
     return "ReportAttributes{" +
       "ref=" + ref +
-      ", version='" + version + '\'' +
       ", path='" + path + '\'' +
       ", scmPath='" + scmPath + '\'' +
       '}';
index cb5058b71cfd77c3a58426f504d0e434c06bb154..93d831ed1c0c9ba38b5301943e15321e1b198e30 100644 (file)
@@ -74,7 +74,7 @@ public class VisitorsCrawler implements ComponentCrawler {
       VisitException.rethrowOrWrap(
         e,
         "Visit of Component {key=%s,type=%s} failed",
-        component.getKey(), component.getType());
+        component.getDbKey(), component.getType());
     }
   }
 
@@ -113,7 +113,7 @@ public class VisitorsCrawler implements ComponentCrawler {
 
   private void visitNode(Component component, VisitorWrapper visitor) {
     Profiler profiler = Profiler.create(Loggers.get(visitor.getWrappedVisitor().getClass()))
-      .startTrace("Visiting component {}", component.getKey());
+      .startTrace("Visiting component {}", component.getDbKey());
     visitor.visitAny(component);
     switch (component.getType()) {
       case PROJECT:
index ed735787f421410ba00250bd58b59454b07ac697..4b40a0041988070f38f29568c7583ee08afbcfa8 100644 (file)
@@ -169,7 +169,7 @@ public final class Duplication {
         return "";
       }
       if (duplicate instanceof InProjectDuplicate) {
-        return ((InProjectDuplicate) duplicate).getFile().getKey();
+        return ((InProjectDuplicate) duplicate).getFile().getDbKey();
       }
       if (duplicate instanceof CrossProjectDuplicate) {
         return ((CrossProjectDuplicate) duplicate).getFileKey();
index c8255471fc0011ede82f52fd9061ed199abd6d5f..8709d4e4f556a14e8e1d3c776be8e8b1b40d7fc2 100644 (file)
@@ -24,7 +24,6 @@ import com.google.common.collect.Multimap;
 import java.util.Collection;
 import java.util.Collections;
 import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
@@ -40,7 +39,7 @@ public class DuplicationRepositoryImpl implements DuplicationRepository {
   public Iterable<Duplication> getDuplications(Component file) {
     checkFileComponentArgument(file);
 
-    Collection<Duplication> res = this.duplications.asMap().get(file.getKey());
+    Collection<Duplication> res = this.duplications.asMap().get(file.getDbKey());
     if (res == null) {
       return Collections.emptyList();
     }
@@ -52,7 +51,7 @@ public class DuplicationRepositoryImpl implements DuplicationRepository {
     checkFileComponentArgument(file);
     checkNotNull(duplication, "duplication can not be null");
 
-    duplications.put(file.getKey(), duplication);
+    duplications.put(file.getDbKey(), duplication);
   }
 
   private static void checkFileComponentArgument(Component file) {
index cb7ba545a949ad4029e5f314814c9becb471a6dc..968af4ae3e4849580531d3fb277d6f078042e178 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.duplications.index.CloneGroup;
 import org.sonar.duplications.index.CloneIndex;
 import org.sonar.duplications.index.ClonePart;
 import org.sonar.duplications.index.PackedMemoryCloneIndex;
-import org.sonar.ce.task.projectanalysis.component.Component;
 
 import static com.google.common.collect.FluentIterable.from;
 
@@ -88,7 +87,7 @@ public class IntegrateCrossProjectDuplications {
     for (CloneGroup duplication : duplications) {
       cloneGroupCount++;
       if (cloneGroupCount > MAX_CLONE_GROUP_PER_FILE) {
-        LOGGER.warn("Too many duplication groups on file {}. Keeping only the first {} groups.", file.getKey(), MAX_CLONE_GROUP_PER_FILE);
+        LOGGER.warn("Too many duplication groups on file {}. Keeping only the first {} groups.", file.getDbKey(), MAX_CLONE_GROUP_PER_FILE);
         break;
       }
       addDuplication(file, duplication);
@@ -170,7 +169,7 @@ public class IntegrateCrossProjectDuplications {
     public boolean apply(@Nonnull ClonePart input) {
       if (counter == MAX_CLONE_PART_PER_GROUP) {
         LOGGER.warn("Too many duplication references on file {} for block at line {}. Keeping only the first {} references.",
-          file.getKey(), originPart.getStartLine(), MAX_CLONE_PART_PER_GROUP);
+          file.getDbKey(), originPart.getStartLine(), MAX_CLONE_PART_PER_GROUP);
       }
       boolean res = counter <= MAX_CLONE_GROUP_PER_FILE;
       counter++;
index 56a519030754ec520da51a9ee0ff9bce8f21d033..0b81525933e7c0f9756017eee45caa6c421bfd7d 100644 (file)
@@ -180,7 +180,7 @@ public class FileMoveDetectionStep implements ComputationStep {
       new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
         @Override
         public void visitFile(Component file) {
-          builder.put(file.getKey(), file);
+          builder.put(file.getDbKey(), file);
         }
       }).visit(root);
     return builder.build();
index dc7b0a6785aeff3f83d2d370d5dba52048df9057..7b266032dc49fbc700ce1eb1b5a283a46ffbec51 100644 (file)
@@ -23,7 +23,6 @@ import com.google.common.base.Optional;
 import java.util.HashMap;
 import java.util.Map;
 import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.Component;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
@@ -38,11 +37,11 @@ public class MutableMovedFilesRepositoryImpl implements MutableMovedFilesReposit
     requireNonNull(originalFile, "originalFile can't be null");
     checkArgument(file.getType() == Component.Type.FILE, "file must be of type FILE");
 
-    OriginalFile existingOriginalFile = originalFiles.get(file.getKey());
+    OriginalFile existingOriginalFile = originalFiles.get(file.getDbKey());
     checkState(existingOriginalFile == null || existingOriginalFile.equals(originalFile),
       "Original file %s already registered for file %s. Unable to register %s.", existingOriginalFile, file, originalFile);
     if (existingOriginalFile == null) {
-      originalFiles.put(file.getKey(), originalFile);
+      originalFiles.put(file.getDbKey(), originalFile);
     }
   }
 
@@ -53,6 +52,6 @@ public class MutableMovedFilesRepositoryImpl implements MutableMovedFilesReposit
       return Optional.absent();
     }
 
-    return Optional.fromNullable(originalFiles.get(file.getKey()));
+    return Optional.fromNullable(originalFiles.get(file.getDbKey()));
   }
 }
index 738bdf38c8a160069cf021c3c7e3d62e3ee7757d..ce353962c150b7ad875486580669c25aacec1e48 100644 (file)
@@ -69,7 +69,7 @@ public class IntegrateIssuesVisitor extends TypeAwareVisitorAdapter {
       copyIssues(component, tracking.issuesToCopy(), cacheAppender);
       issueVisitors.afterComponent(component);
     } catch (Exception e) {
-      throw new IllegalStateException(String.format("Fail to process issues of component '%s'", component.getKey()), e);
+      throw new IllegalStateException(String.format("Fail to process issues of component '%s'", component.getDbKey()), e);
     }
   }
 
index 3ebe858b77f42d7482a2e6b26491e44d9a2c0e98..65400962c4c540508c2164f7ee450e90210345bd 100644 (file)
@@ -25,7 +25,6 @@ import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.IssueChangeContext;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository;
 import org.sonar.ce.task.projectanalysis.filemove.MovedFilesRepository.OriginalFile;
 import org.sonar.server.issue.IssueFieldsSetter;
@@ -60,7 +59,7 @@ public class MovedIssueVisitor extends IssueVisitor {
     // changes the issue's component uuid, add a change and set issue as changed to enforce it is persisted to DB
     issueUpdater.setIssueMoved(issue, component.getUuid(), IssueChangeContext.createUser(new Date(analysisMetadataHolder.getAnalysisDate()), null));
     // other fields (such as module, modulePath, componentKey) are read-only and set/reset for consistency only
-    issue.setComponentKey(component.getPublicKey());
+    issue.setComponentKey(component.getKey());
     issue.setModuleUuid(null);
     issue.setModuleUuidPath(null);
   }
index b943350ce1c1b75bb8b10754cd4f8071b4f7e31d..bb1c6d3788d2625bde831bd7871655b383c8e89e 100644 (file)
@@ -52,7 +52,7 @@ public class ShortBranchIssuesLoader {
   }
 
   public Collection<ShortBranchIssue> loadCandidateIssuesForMergingInTargetBranch(Component component) {
-    String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getKey());
+    String componentKey = ComponentDto.removeBranchAndPullRequestFromKey(component.getDbKey());
     Set<String> uuids = shortBranchComponentsWithIssues.getUuids(componentKey);
     if (uuids.isEmpty()) {
       return Collections.emptyList();
index e5c2e42f5b85dac5df871e41796d94e6873c7cd5..fbfe9028f5738648c98b37976f9fc4413dfdcfe0 100644 (file)
@@ -46,7 +46,7 @@ public class TrackerMergeBranchInputFactory {
   }
 
   public Input<DefaultIssue> create(Component component) {
-    String mergeBranchComponentUuid = mergeBranchComponentUuids.getUuid(component.getKey());
+    String mergeBranchComponentUuid = mergeBranchComponentUuids.getUuid(component.getDbKey());
     return new MergeLazyInput(component.getType(), mergeBranchComponentUuid);
   }
 
index 0ee7f7e1e4952223dd5108064533fc3c298c28d0..4da888394716419952dc1b16f7561fa3be49552a 100644 (file)
@@ -259,9 +259,9 @@ public class TrackerRawInputFactory {
       issue.setResolution(null);
       issue.setStatus(Issue.STATUS_OPEN);
       issue.setComponentUuid(component.getUuid());
-      issue.setComponentKey(component.getPublicKey());
+      issue.setComponentKey(component.getKey());
       issue.setProjectUuid(treeRootHolder.getRoot().getUuid());
-      issue.setProjectKey(treeRootHolder.getRoot().getPublicKey());
+      issue.setProjectKey(treeRootHolder.getRoot().getKey());
       return issue;
     }
 
index bed4573b235f0215c726376972511d94c30f9b0d..1fd083edc6e348810bc5ec5c9a447fd91efb6f42 100644 (file)
@@ -32,8 +32,6 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.ce.task.projectanalysis.metric.Metric;
-import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.metric.Metric;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.collect.FluentIterable.from;
@@ -80,7 +78,7 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository
       throw new UnsupportedOperationException(
         format(
           "a measure can be set only once for a specific Component (key=%s), Metric (key=%s). Use update method",
-          component.getKey(),
+          component.getDbKey(),
           metric.getKey()));
     }
     add(component, metric, measure, OverridePolicy.OVERRIDE);
@@ -96,7 +94,7 @@ public final class MapBasedRawMeasureRepository<T> implements MeasureRepository
       throw new UnsupportedOperationException(
         format(
           "a measure can be updated only if one already exists for a specific Component (key=%s), Metric (key=%s). Use add method",
-          component.getKey(),
+          component.getDbKey(),
           metric.getKey()));
     }
     add(component, metric, measure, OverridePolicy.OVERRIDE);
index 5c1b9ff65d4870b559fb7b1390b2c36dd0923842..4a0bcde36f69ea844f042277c69ba7e12b50b6ad 100644 (file)
@@ -29,8 +29,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.source.FileSourceDto;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.ce.task.projectanalysis.component.Component;
-import org.sonar.ce.task.projectanalysis.component.MergeBranchComponentUuids;
 
 public class ScmInfoDbLoader {
   private static final Logger LOGGER = Loggers.get(ScmInfoDbLoader.class);
@@ -69,7 +67,7 @@ public class ScmInfoDbLoader {
     // at this point, it's the first analysis but had copyFromPrevious flag true
     Branch branch = analysisMetadataHolder.getBranch();
     if (branch.getMergeBranchUuid().isPresent()) {
-      return Optional.ofNullable(mergeBranchComponentUuid.getUuid(file.getKey()));
+      return Optional.ofNullable(mergeBranchComponentUuid.getUuid(file.getDbKey()));
     }
 
     return Optional.empty();
index 10d5a5f651f1d5183d7a7f5378c631803bec06e5..116f72dbe27bdaa09d31593233303bfdb23ac45d 100644 (file)
@@ -72,7 +72,7 @@ public class ScmInfoRepositoryImpl implements ScmInfoRepository {
     ScannerReport.Changesets changesets = scannerReportReader.readChangesets(component.getReportAttributes().getRef());
 
     if (changesets == null) {
-      LOGGER.trace("No SCM info for file '{}'", component.getKey());
+      LOGGER.trace("No SCM info for file '{}'", component.getDbKey());
       // SCM not available. It might have been available before - copy information for unchanged lines but don't keep author and revision.
       return generateAndMergeDb(component, false);
     }
@@ -85,7 +85,7 @@ public class ScmInfoRepositoryImpl implements ScmInfoRepository {
   }
 
   private static Optional<ScmInfo> getScmInfoFromReport(Component file, ScannerReport.Changesets changesets) {
-    LOGGER.trace("Reading SCM info from report for file '{}'", file.getKey());
+    LOGGER.trace("Reading SCM info from report for file '{}'", file.getDbKey());
     return Optional.of(new ReportScmInfo(changesets));
   }
 
index 77495e7c33b4207c35a3e194259a655d8afae6cc..554766872056e7e0ec52f2c6b72720b89d05c896 100644 (file)
@@ -25,7 +25,6 @@ import javax.annotation.Nullable;
 import org.sonar.ce.task.projectanalysis.component.Component;
 import org.sonar.core.hash.SourceHashComputer;
 import org.sonar.core.util.CloseableIterator;
-import org.sonar.ce.task.projectanalysis.component.Component;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkState;
@@ -44,12 +43,12 @@ public class SourceHashRepositoryImpl implements SourceHashRepository {
   @Override
   public String getRawSourceHash(Component file) {
     checkComponentArgument(file);
-    if (rawSourceHashesByKey.containsKey(file.getKey())) {
-      return checkSourceHash(file.getKey(), rawSourceHashesByKey.get(file.getKey()));
+    if (rawSourceHashesByKey.containsKey(file.getDbKey())) {
+      return checkSourceHash(file.getDbKey(), rawSourceHashesByKey.get(file.getDbKey()));
     } else {
       String newSourceHash = computeRawSourceHash(file);
-      rawSourceHashesByKey.put(file.getKey(), newSourceHash);
-      return checkSourceHash(file.getKey(), newSourceHash);
+      rawSourceHashesByKey.put(file.getDbKey(), newSourceHash);
+      return checkSourceHash(file.getDbKey(), newSourceHash);
     }
   }
 
index b4f71abadf4e7599b8c5ae0c3abda129e6c029b5..8a5839717077443d88dc2b4435cb0b55b3c47525 100644 (file)
@@ -78,7 +78,7 @@ public class HighlightingLineReader implements LineReader {
       processHighlightings(lineBuilder);
     } catch (RangeOffsetConverterException e) {
       isHighlightingValid = false;
-      LOG.warn(format("Inconsistency detected in Highlighting data. Highlighting will be ignored for file '%s'", file.getKey()), e);
+      LOG.warn(format("Inconsistency detected in Highlighting data. Highlighting will be ignored for file '%s'", file.getDbKey()), e);
     }
   }
 
index c3e1f746921c57f89e76ab5ea3e3e55df454bea0..1b75dbb3c539504c65dd1f68636c1a0c6edef7f9 100644 (file)
@@ -70,7 +70,7 @@ public class SymbolsLineReader implements LineReader {
       processSymbols(lineBuilder);
     } catch (RangeOffsetConverter.RangeOffsetConverterException e) {
       areSymbolsValid = false;
-      LOG.warn(format("Inconsistency detected in Symbols data. Symbols will be ignored for file '%s'", file.getKey()), e);
+      LOG.warn(format("Inconsistency detected in Symbols data. Symbols will be ignored for file '%s'", file.getDbKey()), e);
     }
   }
 
index 98e8a907702634d24f47b2ae07de77ca64bc558b..4446004e861f16fb8d0d4fba4248bdabeccface1 100644 (file)
@@ -82,7 +82,7 @@ public class DuplicationDataMeasuresStep implements ComputationStep {
     }
 
     private void computeDuplications(Component component, Iterable<Duplication> duplications) {
-      String duplicationXml = createXmlDuplications(component.getKey(), duplications);
+      String duplicationXml = createXmlDuplications(component.getDbKey(), duplications);
       measureRepository.add(
         component,
         duplicationDataMetric,
@@ -110,7 +110,7 @@ public class DuplicationDataMeasuresStep implements ComputationStep {
         appendDuplication(xml, componentKey, duplicate);
       } else if (duplicate instanceof InProjectDuplicate) {
         // Duplication is on a different file
-        appendDuplication(xml, ((InProjectDuplicate) duplicate).getFile().getKey(), duplicate);
+        appendDuplication(xml, ((InProjectDuplicate) duplicate).getFile().getDbKey(), duplicate);
       } else if (duplicate instanceof CrossProjectDuplicate) {
         // componentKey is only set for cross project duplications
         String crossProjectComponentKey = ((CrossProjectDuplicate) duplicate).getFileKey();
index a6867957d8c00026016269f328c5af5046c13bca..7436fd53a1f69058ab8ff8bf90290423290eab24 100644 (file)
@@ -99,7 +99,7 @@ public class LoadCrossProjectDuplicationsRepositoryStep implements ComputationSt
       List<CpdTextBlock> cpdTextBlocks;
       try (CloseableIterator<CpdTextBlock> blocksIt = reportReader.readCpdTextBlocks(file.getReportAttributes().getRef())) {
         cpdTextBlocks = newArrayList(blocksIt);
-        LOGGER.trace("Found {} cpd blocks on file {}", cpdTextBlocks.size(), file.getKey());
+        LOGGER.trace("Found {} cpd blocks on file {}", cpdTextBlocks.size(), file.getDbKey());
         if (cpdTextBlocks.isEmpty()) {
           return;
         }
@@ -112,8 +112,8 @@ public class LoadCrossProjectDuplicationsRepositoryStep implements ComputationSt
       }
 
       Collection<Block> duplicatedBlocks = from(dtos).transform(DtoToBlock.INSTANCE).toList();
-      Collection<Block> originBlocks = from(cpdTextBlocks).transform(new CpdTextBlockToBlock(file.getKey())).toList();
-      LOGGER.trace("Found {} duplicated cpd blocks on file {}", duplicatedBlocks.size(), file.getKey());
+      Collection<Block> originBlocks = from(cpdTextBlocks).transform(new CpdTextBlockToBlock(file.getDbKey())).toList();
+      LOGGER.trace("Found {} duplicated cpd blocks on file {}", duplicatedBlocks.size(), file.getDbKey());
 
       integrateCrossProjectDuplications.computeCpd(file, originBlocks, duplicatedBlocks);
     }
index 11047e44c90517e70e45c0bf62661148ba79b92b..7e11474941aa8d6cb27eca017c3669db4171d90b 100644 (file)
@@ -84,9 +84,8 @@ public class LoadPeriodsStep implements ComputationStep {
 
   @CheckForNull
   private Period buildPeriod(Component projectOrView, DbSession session) {
-    boolean isReportType = projectOrView.getType().isReportType();
     PeriodResolver periodResolver = new PeriodResolver(dbClient, session, projectOrView.getUuid(), analysisMetadataHolder.getAnalysisDate(),
-      isReportType ? projectOrView.getReportAttributes().getVersion() : null);
+      projectOrView.getProjectAttributes().getVersion());
 
     Configuration config = configRepository.getConfiguration();
     Period period = periodResolver.resolve(config);
index 05b899b3abbe4329ea3df9e2fc0f17829ceb83cf..cb0407c3293d0bd884d81af133f8d742ad7a4b4c 100644 (file)
@@ -76,14 +76,14 @@ public class PersistAnalysisStep implements ComputationStep {
 
     @Override
     public void visitProject(Component project) {
-      SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project, true);
+      SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project);
       updateSnapshotPeriods(snapshot);
       persist(snapshot, dbSession);
     }
 
     @Override
     public void visitView(Component view) {
-      SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false);
+      SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view);
       updateSnapshotPeriods(snapshot);
       persist(snapshot, dbSession);
     }
@@ -98,11 +98,11 @@ public class PersistAnalysisStep implements ComputationStep {
       snapshotDto.setPeriodDate(period.getSnapshotDate());
     }
 
-    private SnapshotDto createAnalysis(String snapshotUuid, Component component, boolean setVersion) {
+    private SnapshotDto createAnalysis(String snapshotUuid, Component component) {
       String componentUuid = component.getUuid();
       return new SnapshotDto()
         .setUuid(snapshotUuid)
-        .setVersion(setVersion ? component.getReportAttributes().getVersion() : null)
+        .setVersion(component.getType() == Component.Type.PROJECT ? component.getProjectAttributes().getVersion() : null)
         .setComponentUuid(componentUuid)
         .setLast(false)
         .setStatus(SnapshotDto.STATUS_UNPROCESSED)
index 639b6110fa037ec7d28b1d09a0b5c60d9b526565..60887b42c4c1559e2b17f4a9254259805ded172b 100644 (file)
@@ -143,7 +143,7 @@ public class PersistComponentsStep implements ComputationStep {
   }
 
   private static boolean isRootPrivate(Component root, Map<String, ComponentDto> existingDtosByKeys) {
-    String rootKey = root.getKey();
+    String rootKey = root.getDbKey();
     ComponentDto rootDto = existingDtosByKeys.get(rootKey);
     if (rootDto == null) {
       if (Component.Type.VIEW == root.getType()) {
@@ -159,7 +159,7 @@ public class PersistComponentsStep implements ComputationStep {
    * disabled components.
    */
   private Map<String, ComponentDto> indexExistingDtosByKey(DbSession session) {
-    return dbClient.componentDao().selectAllComponentsFromProjectKey(session, treeRootHolder.getRoot().getKey())
+    return dbClient.componentDao().selectAllComponentsFromProjectKey(session, treeRootHolder.getRoot().getDbKey())
       .stream()
       .collect(Collectors.toMap(ComponentDto::getDbKey, Function.identity()));
   }
@@ -386,7 +386,7 @@ public class PersistComponentsStep implements ComputationStep {
     }
 
     private ComponentDto createBase(Component component) {
-      String componentKey = component.getKey();
+      String componentKey = component.getDbKey();
       String componentUuid = component.getUuid();
 
       ComponentDto componentDto = new ComponentDto();
index 3e7c0641dff369868b5096860d36e9ac53b2c278..df8f4cd621e38e3126bddd458f8447fe2c65a4d3 100644 (file)
@@ -101,13 +101,11 @@ public class PersistEventsStep implements ComputationStep {
     }
 
     private void saveVersionEvent(DbSession session, Component component, Long analysisDate) {
-      String version = component.getReportAttributes().getVersion();
-      if (version != null) {
-        deletePreviousEventsHavingSameVersion(session, version, component);
-        dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate)
-          .setName(version)
-          .setCategory(EventDto.CATEGORY_VERSION));
-      }
+      String version = component.getProjectAttributes().getVersion();
+      deletePreviousEventsHavingSameVersion(session, version, component);
+      dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate)
+        .setName(version)
+        .setCategory(EventDto.CATEGORY_VERSION));
     }
 
     private void deletePreviousEventsHavingSameVersion(DbSession session, String version, Component component) {
index 2ad2e2a72f873ff8adc498a00f8c7553afe3c5b1..c8deeaed8b699436b04b4f4038a3b2d0f67d09de 100644 (file)
@@ -97,7 +97,7 @@ public class PersistFileSourcesStep implements ComputationStep {
         FileSourceDataComputer.Data fileSourceData = fileSourceDataComputer.compute(file);
         persistSource(fileSourceData, file);
       } catch (Exception e) {
-        throw new IllegalStateException(String.format("Cannot persist sources of %s", file.getKey()), e);
+        throw new IllegalStateException(String.format("Cannot persist sources of %s", file.getDbKey()), e);
       }
     }
 
index 41ba395ace20f3b52d7e2491719d3ec091cdee5c..32552d25a07303b6089a055f63488d112b0a9e6e 100644 (file)
@@ -98,7 +98,7 @@ public class PersistTestsStep implements ComputationStep {
       this.session = session;
       this.existingFileSourcesByUuid = new HashMap<>();
       this.projectUuid = treeRootHolder.getRoot().getUuid();
-      this.projectKey = treeRootHolder.getRoot().getKey();
+      this.projectKey = treeRootHolder.getRoot().getDbKey();
       session.select("org.sonar.db.source.FileSourceMapper.selectHashesForProject",
         ImmutableMap.of("projectUuid", treeRootHolder.getRoot().getUuid(), "dataType", Type.TEST),
         context -> {
@@ -118,7 +118,7 @@ public class PersistTestsStep implements ComputationStep {
       Multimap<String, DbFileSources.Test.Builder> testsByName = buildDbTests(component.getReportAttributes().getRef());
       Table<String, String, DbFileSources.Test.CoveredFile.Builder> coveredFilesByName = loadCoverageDetails(component.getReportAttributes().getRef());
       List<DbFileSources.Test> tests = addCoveredFilesToTests(testsByName, coveredFilesByName);
-      if (checkIfThereAreUnprocessedCoverageDetails(testsByName, coveredFilesByName, component.getKey())) {
+      if (checkIfThereAreUnprocessedCoverageDetails(testsByName, coveredFilesByName, component.getDbKey())) {
         hasUnprocessedCoverageDetails = true;
       }
 
index 907f2bc790ce61c18e4d0417022021f133d2584e..60625f3c169fb248d2fb966a6639383c4a423edb 100644 (file)
@@ -100,7 +100,7 @@ public class QualityGateEventsStep implements ComputationStep {
     }
 
     if (!baseMeasure.get().hasQualityGateStatus()) {
-      LOGGER.warn(String.format("Previous Quality gate status for project %s is not a supported value. Can not compute Quality Gate event", project.getKey()));
+      LOGGER.warn(String.format("Previous Quality gate status for project %s is not a supported value. Can not compute Quality Gate event", project.getDbKey()));
       checkNewQualityGate(project, rawStatus);
       return;
     }
@@ -131,8 +131,8 @@ public class QualityGateEventsStep implements ComputationStep {
     Notification notification = new Notification("alerts")
       .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
       .setFieldValue("projectName", project.getName())
-      .setFieldValue("projectKey", project.getPublicKey())
-      .setFieldValue("projectVersion", project.getReportAttributes().getVersion())
+      .setFieldValue("projectKey", project.getKey())
+      .setFieldValue("projectVersion", project.getProjectAttributes().getVersion())
       .setFieldValue("alertName", label)
       .setFieldValue("alertText", rawStatus.getText())
       .setFieldValue("alertLevel", rawStatus.getStatus().toString())
index 851b2301e126774b19d323f7077aad77aeb5868c..b58363ef726d9d069f4e7cc33d1e11fa78765c0a 100644 (file)
@@ -154,8 +154,8 @@ public class SendIssueNotificationsStep implements ComputationStep {
     changeNotification.setRuleName(rules.getByKey(issue.ruleKey()).getName());
     changeNotification.setIssue(issue);
     changeNotification.setAssignee(usersDtoByUuids.get(issue.assignee()));
-    changeNotification.setProject(project.getPublicKey(), project.getName(), getBranchName(), getPullRequest());
-    getComponentKey(issue).ifPresent(c -> changeNotification.setComponent(c.getPublicKey(), c.getName()));
+    changeNotification.setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest());
+    getComponentKey(issue).ifPresent(c -> changeNotification.setComponent(c.getKey(), c.getName()));
     notificationStatistics.issueChangesDeliveries += service.deliver(changeNotification);
     notificationStatistics.issueChanges++;
   }
@@ -164,8 +164,8 @@ public class SendIssueNotificationsStep implements ComputationStep {
     NewIssuesStatistics.Stats globalStatistics = statistics.globalStatistics();
     NewIssuesNotification notification = newIssuesNotificationFactory
       .newNewIssuesNotification()
-      .setProject(project.getPublicKey(), project.getName(), getBranchName(), getPullRequest())
-      .setProjectVersion(project.getReportAttributes().getVersion())
+      .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest())
+      .setProjectVersion(project.getProjectAttributes().getVersion())
       .setAnalysisDate(new Date(analysisDate))
       .setStatistics(project.getName(), globalStatistics)
       .setDebt(Duration.create(globalStatistics.effort().getOnLeak()));
@@ -185,8 +185,8 @@ public class SendIssueNotificationsStep implements ComputationStep {
           .newMyNewIssuesNotification()
           .setAssignee(userDtoByUuid.get(assigneeUuid));
         myNewIssuesNotification
-          .setProject(project.getPublicKey(), project.getName(), getBranchName(), getPullRequest())
-          .setProjectVersion(project.getReportAttributes().getVersion())
+          .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest())
+          .setProjectVersion(project.getProjectAttributes().getVersion())
           .setAnalysisDate(new Date(analysisDate))
           .setStatistics(project.getName(), assigneeStatistics)
           .setDebt(Duration.create(assigneeStatistics.effort().getOnLeak()));
@@ -212,7 +212,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
         new TypeAwareVisitorAdapter(CrawlerDepthLimit.LEAVES, POST_ORDER) {
           @Override
           public void visitAny(Component component) {
-            builder.put(component.getKey(), component);
+            builder.put(component.getDbKey(), component);
           }
         }).visit(this.treeRootHolder.getRoot());
       this.componentsByDbKey = builder.build();
index 4dbe0f0253e673dff025abc815e17354f02b7d0a..ce0b6ecc83b08b461500558496682c851366630b 100644 (file)
@@ -76,7 +76,7 @@ public class ValidateProjectStep implements ComputationStep {
   public void execute(ComputationStep.Context context) {
     try (DbSession dbSession = dbClient.openSession(false)) {
       Component root = treeRootHolder.getRoot();
-      List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getKey());
+      List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(dbSession, root.getDbKey());
       Map<String, ComponentDto> baseModulesByKey = from(baseModules).uniqueIndex(ComponentDto::getDbKey);
       ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(dbSession, dbClient.componentDao(), baseModulesByKey);
       new DepthTraversalTypeAwareCrawler(visitor).visit(root);
@@ -111,7 +111,7 @@ public class ValidateProjectStep implements ComputationStep {
     @Override
     public void visitProject(Component rawProject) {
       this.rawProject = rawProject;
-      String rawProjectKey = rawProject.getKey();
+      String rawProjectKey = rawProject.getDbKey();
 
       Optional<ComponentDto> baseProject = loadBaseComponent(rawProjectKey);
       validateAnalysisDate(baseProject);
@@ -132,8 +132,8 @@ public class ValidateProjectStep implements ComputationStep {
 
     @Override
     public void visitModule(Component rawModule) {
-      String rawProjectKey = rawProject.getKey();
-      String rawModuleKey = rawModule.getKey();
+      String rawProjectKey = rawProject.getDbKey();
+      String rawModuleKey = rawModule.getDbKey();
       validateBatchKey(rawModule);
 
       Optional<ComponentDto> baseModule = loadBaseComponent(rawModuleKey);
index 822a25f67eb665a2d1b33dc07e94dd278d101070..237b7b3efc13d5199d74ad10dcf17e39993df774 100644 (file)
@@ -70,7 +70,7 @@ public class BranchPersisterImplTest {
     treeRootHolder.setRoot(BRANCH);
 
     // add main branch in project table and in metadata
-    ComponentDto dto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey());
+    ComponentDto dto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getDbKey());
     analysisMetadataHolder.setProject(Project.from(dto));
     dbTester.getDbClient().componentDao().insert(dbTester.getSession(), dto);
 
@@ -91,7 +91,7 @@ public class BranchPersisterImplTest {
     treeRootHolder.setRoot(BRANCH);
 
     // add main branch in project table and in metadata
-    ComponentDto dto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getKey());
+    ComponentDto dto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), MAIN.getUuid()).setDbKey(MAIN.getDbKey());
     analysisMetadataHolder.setProject(Project.from(dto));
     dbTester.getDbClient().componentDao().insert(dbTester.getSession(), dto);
 
index 84a56af22779c0b828c02bbf9f807f7d307dc1f2..692fa3fbb1ad31858d4ea8e629163b4e1fc992c0 100644 (file)
@@ -35,7 +35,7 @@ class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter<Integer> {
     super(maxDepth, order, new SimpleStackElementFactory<Integer>() {
       @Override
       public Integer createForAny(Component component) {
-        return component.getType().isReportType() ? component.getReportAttributes().getRef() : Integer.valueOf(component.getKey());
+        return component.getType().isReportType() ? component.getReportAttributes().getRef() : Integer.valueOf(component.getDbKey());
       }
     });
   }
@@ -86,7 +86,7 @@ class CallRecorderPathAwareVisitor extends PathAwareVisitorAdapter<Integer> {
   }
 
   private static PathAwareCallRecord viewsCallRecord(Component component, Path<Integer> path, String method) {
-    return PathAwareCallRecord.viewsCallRecord(method, component.getKey(), path.current(), getParent(path), path.root(),
+    return PathAwareCallRecord.viewsCallRecord(method, component.getDbKey(), path.current(), getParent(path), path.root(),
       toValueList(path));
   }
 
index 3974f9cecee189ec3d5de46635ecd04326622408..163b038cd1758d1c8459c62d7874a596b976930a 100644 (file)
@@ -74,7 +74,7 @@ class CallRecorderTypeAwareVisitor extends TypeAwareVisitorAdapter {
   }
 
   private static CallRecord viewsCallRecord(Component component, String method) {
-    return CallRecord.viewsCallRecord(method, component.getKey());
+    return CallRecord.viewsCallRecord(method, component.getDbKey());
   }
 
 }
index d23a0e4baa47b6e58bbac8132b53dfb3a5a42ca4..8ed18389fc006f9f378b3c36d62a16d2992600f4 100644 (file)
@@ -30,6 +30,7 @@ import static com.google.common.base.Strings.repeat;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.fail;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
+import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
 import static org.sonar.ce.task.projectanalysis.component.ComponentImpl.builder;
 
 public class ComponentImplTest {
@@ -44,7 +45,7 @@ public class ComponentImplTest {
   public void verify_key_uuid_and_name() {
     ComponentImpl component = buildSimpleComponent(FILE, KEY).setUuid(UUID).setName("name").build();
 
-    assertThat(component.getKey()).isEqualTo(KEY);
+    assertThat(component.getDbKey()).isEqualTo(KEY);
     assertThat(component.getUuid()).isEqualTo(UUID);
     assertThat(component.getName()).isEqualTo("name");
   }
@@ -69,7 +70,7 @@ public class ComponentImplTest {
 
     builder(Component.Type.DIRECTORY)
       .setName("DIR")
-      .setKey(KEY)
+      .setDbKey(KEY)
       .setUuid(UUID)
       .setReportAttributes(ReportAttributes.newBuilder(1).build())
       .build();
@@ -86,7 +87,7 @@ public class ComponentImplTest {
   public void set_uuid_throws_NPE_if_component_arg_is_Null() {
     expectedException.expect(NullPointerException.class);
 
-    builder(FILE).setKey(null);
+    builder(FILE).setDbKey(null);
   }
 
   @Test
@@ -100,7 +101,7 @@ public class ComponentImplTest {
   public void build_without_uuid_throws_NPE_if_component_arg_is_Null() {
     expectedException.expect(NullPointerException.class);
 
-    builder(FILE).setKey(KEY).build();
+    builder(FILE).setDbKey(KEY).build();
   }
 
   @Test
@@ -198,14 +199,14 @@ public class ComponentImplTest {
   public void build_with_child() {
     ComponentImpl child = builder(FILE)
       .setName("CHILD_NAME")
-      .setKey("CHILD_KEY")
+      .setDbKey("CHILD_KEY")
       .setUuid("CHILD_UUID")
       .setStatus(Status.UNAVAILABLE)
       .setReportAttributes(ReportAttributes.newBuilder(2).build())
       .build();
     ComponentImpl componentImpl = builder(Component.Type.DIRECTORY)
       .setName("DIR")
-      .setKey(KEY)
+      .setDbKey(KEY)
       .setUuid(UUID)
       .setStatus(Status.UNAVAILABLE)
       .setReportAttributes(ReportAttributes.newBuilder(1).build())
@@ -214,7 +215,7 @@ public class ComponentImplTest {
 
     assertThat(componentImpl.getChildren()).hasSize(1);
     Component childReloaded = componentImpl.getChildren().iterator().next();
-    assertThat(childReloaded.getKey()).isEqualTo("CHILD_KEY");
+    assertThat(childReloaded.getDbKey()).isEqualTo("CHILD_KEY");
     assertThat(childReloaded.getUuid()).isEqualTo("CHILD_UUID");
     assertThat(childReloaded.getType()).isEqualTo(FILE);
   }
@@ -237,13 +238,16 @@ public class ComponentImplTest {
     assertThat(builder.build().hashCode()).isEqualTo(UUID.hashCode());
   }
 
-  private static ComponentImpl.Builder buildSimpleComponent(Component.Type type, String key) {
-    return builder(type)
-      .setName("name_" + key)
-      .setKey(key)
+  private static ComponentImpl.Builder buildSimpleComponent(Component.Type type, String dbKey) {
+    ComponentImpl.Builder builder = builder(type)
+      .setName("name_" + dbKey)
+      .setDbKey(dbKey)
       .setStatus(Status.UNAVAILABLE)
-      .setUuid("uuid_" + key)
-      .setReportAttributes(ReportAttributes.newBuilder(key.hashCode())
-        .build());
+      .setUuid("uuid_" + dbKey)
+      .setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build());
+    if (type == PROJECT) {
+      builder.setProjectAttributes(new ProjectAttributes("version_1"));
+    }
+    return builder;
   }
 }
index a598a179dbb72994df2ab34ea4569df9aeebb1ba..8dede61058308842f9804b93830926e63342d000 100644 (file)
@@ -101,14 +101,14 @@ public class ComponentTreeBuilderTest {
       .build());
 
     assertThat(root.getUuid()).isEqualTo("generated_K1_uuid");
-    assertThat(root.getKey()).isEqualTo("generated_K1");
-    assertThat(root.getPublicKey()).isEqualTo("public_K1");
+    assertThat(root.getDbKey()).isEqualTo("generated_K1");
+    assertThat(root.getKey()).isEqualTo("public_K1");
     assertThat(root.getType()).isEqualTo(Component.Type.PROJECT);
     assertThat(root.getName()).isEqualTo(nameInReport);
     assertThat(root.getDescription()).isEqualTo(descriptionInReport);
     assertThat(root.getReportAttributes().getRef()).isEqualTo(42);
     assertThat(root.getReportAttributes().getPath()).isNull();
-    assertThat(root.getReportAttributes().getVersion()).isEqualTo("6.5");
+    assertThat(root.getProjectAttributes().getVersion()).isEqualTo("6.5");
     assertThatFileAttributesAreNotSet(root);
   }
 
@@ -154,7 +154,7 @@ public class ComponentTreeBuilderTest {
       .setType(PROJECT)
       .build(), baseAnalysis);
 
-    assertThat(root.getReportAttributes().getVersion()).isEqualTo("6.5");
+    assertThat(root.getProjectAttributes().getVersion()).isEqualTo("6.5");
   }
 
   @Test
@@ -165,7 +165,7 @@ public class ComponentTreeBuilderTest {
       .setVersion("")
       .build(), baseAnalysis);
 
-    assertThat(root.getReportAttributes().getVersion()).isEqualTo("6.5");
+    assertThat(root.getProjectAttributes().getVersion()).isEqualTo("6.5");
   }
 
   @Test
@@ -174,7 +174,7 @@ public class ComponentTreeBuilderTest {
       .setType(PROJECT)
       .build());
 
-    assertThat(root.getReportAttributes().getVersion()).isEqualTo("not provided");
+    assertThat(root.getProjectAttributes().getVersion()).isEqualTo("not provided");
   }
 
   @Test
@@ -345,23 +345,23 @@ public class ComponentTreeBuilderTest {
       .setLines(1));
 
     Component root = call(project);
-    assertThat(root.getKey()).isEqualTo("generated_" + projectInDb.getKey());
-    assertThat(root.getPublicKey()).isEqualTo("public_" + projectInDb.getKey());
+    assertThat(root.getDbKey()).isEqualTo("generated_" + projectInDb.getKey());
+    assertThat(root.getKey()).isEqualTo("public_" + projectInDb.getKey());
     assertThat(root.getChildren()).hasSize(1);
 
     Component module = root.getChildren().iterator().next();
-    assertThat(module.getKey()).isEqualTo("generated_M");
-    assertThat(module.getPublicKey()).isEqualTo("public_M");
+    assertThat(module.getDbKey()).isEqualTo("generated_M");
+    assertThat(module.getKey()).isEqualTo("public_M");
     assertThat(module.getChildren()).hasSize(1);
 
     Component directory = module.getChildren().iterator().next();
-    assertThat(directory.getKey()).isEqualTo("generated_M:src/js");
-    assertThat(directory.getPublicKey()).isEqualTo("public_M:src/js");
+    assertThat(directory.getDbKey()).isEqualTo("generated_M:src/js");
+    assertThat(directory.getKey()).isEqualTo("public_M:src/js");
     assertThat(directory.getChildren()).hasSize(1);
 
     Component file = directory.getChildren().iterator().next();
-    assertThat(file.getKey()).isEqualTo("generated_M:src/js/Foo.js");
-    assertThat(file.getPublicKey()).isEqualTo("public_M:src/js/Foo.js");
+    assertThat(file.getDbKey()).isEqualTo("generated_M:src/js/Foo.js");
+    assertThat(file.getKey()).isEqualTo("public_M:src/js/Foo.js");
     assertThat(file.getChildren()).isEmpty();
   }
 
@@ -474,36 +474,36 @@ public class ComponentTreeBuilderTest {
 
     Component root = call(project);
     Map<Integer, Component> componentsByRef = indexComponentByRef(root);
-    assertThat(componentsByRef.get(11).getKey()).isEqualTo("generated_module 1");
-    assertThat(componentsByRef.get(11).getPublicKey()).isEqualTo("public_module 1");
-    assertThat(componentsByRef.get(12).getKey()).isEqualTo("generated_module 2");
-    assertThat(componentsByRef.get(12).getPublicKey()).isEqualTo("public_module 2");
-    assertThat(componentsByRef.get(13).getKey()).isEqualTo("generated_module 3");
-    assertThat(componentsByRef.get(13).getPublicKey()).isEqualTo("public_module 3");
-    assertThat(componentsByRef.get(21).getKey()).startsWith("generated_project 1:");
-    assertThat(componentsByRef.get(21).getPublicKey()).startsWith("public_project 1:");
-    assertThat(componentsByRef.get(22).getKey()).startsWith("generated_module 1:");
-    assertThat(componentsByRef.get(22).getPublicKey()).startsWith("public_module 1:");
-    assertThat(componentsByRef.get(23).getKey()).startsWith("generated_module 2:");
-    assertThat(componentsByRef.get(23).getPublicKey()).startsWith("public_module 2:");
-    assertThat(componentsByRef.get(24).getKey()).startsWith("generated_module 3:");
-    assertThat(componentsByRef.get(24).getPublicKey()).startsWith("public_module 3:");
-    assertThat(componentsByRef.get(31).getKey()).startsWith("generated_project 1:");
-    assertThat(componentsByRef.get(31).getPublicKey()).startsWith("public_project 1:");
-    assertThat(componentsByRef.get(32).getKey()).startsWith("generated_module 1:");
-    assertThat(componentsByRef.get(32).getPublicKey()).startsWith("public_module 1:");
-    assertThat(componentsByRef.get(33).getKey()).startsWith("generated_module 2:");
-    assertThat(componentsByRef.get(33).getPublicKey()).startsWith("public_module 2:");
-    assertThat(componentsByRef.get(34).getKey()).startsWith("generated_module 3:");
-    assertThat(componentsByRef.get(34).getPublicKey()).startsWith("public_module 3:");
-    assertThat(componentsByRef.get(35).getKey()).startsWith("generated_project 1:");
-    assertThat(componentsByRef.get(35).getPublicKey()).startsWith("public_project 1:");
-    assertThat(componentsByRef.get(36).getKey()).startsWith("generated_module 1:");
-    assertThat(componentsByRef.get(36).getPublicKey()).startsWith("public_module 1:");
-    assertThat(componentsByRef.get(37).getKey()).startsWith("generated_module 2:");
-    assertThat(componentsByRef.get(37).getPublicKey()).startsWith("public_module 2:");
-    assertThat(componentsByRef.get(38).getKey()).startsWith("generated_module 3:");
-    assertThat(componentsByRef.get(38).getPublicKey()).startsWith("public_module 3:");
+    assertThat(componentsByRef.get(11).getDbKey()).isEqualTo("generated_module 1");
+    assertThat(componentsByRef.get(11).getKey()).isEqualTo("public_module 1");
+    assertThat(componentsByRef.get(12).getDbKey()).isEqualTo("generated_module 2");
+    assertThat(componentsByRef.get(12).getKey()).isEqualTo("public_module 2");
+    assertThat(componentsByRef.get(13).getDbKey()).isEqualTo("generated_module 3");
+    assertThat(componentsByRef.get(13).getKey()).isEqualTo("public_module 3");
+    assertThat(componentsByRef.get(21).getDbKey()).startsWith("generated_project 1:");
+    assertThat(componentsByRef.get(21).getKey()).startsWith("public_project 1:");
+    assertThat(componentsByRef.get(22).getDbKey()).startsWith("generated_module 1:");
+    assertThat(componentsByRef.get(22).getKey()).startsWith("public_module 1:");
+    assertThat(componentsByRef.get(23).getDbKey()).startsWith("generated_module 2:");
+    assertThat(componentsByRef.get(23).getKey()).startsWith("public_module 2:");
+    assertThat(componentsByRef.get(24).getDbKey()).startsWith("generated_module 3:");
+    assertThat(componentsByRef.get(24).getKey()).startsWith("public_module 3:");
+    assertThat(componentsByRef.get(31).getDbKey()).startsWith("generated_project 1:");
+    assertThat(componentsByRef.get(31).getKey()).startsWith("public_project 1:");
+    assertThat(componentsByRef.get(32).getDbKey()).startsWith("generated_module 1:");
+    assertThat(componentsByRef.get(32).getKey()).startsWith("public_module 1:");
+    assertThat(componentsByRef.get(33).getDbKey()).startsWith("generated_module 2:");
+    assertThat(componentsByRef.get(33).getKey()).startsWith("public_module 2:");
+    assertThat(componentsByRef.get(34).getDbKey()).startsWith("generated_module 3:");
+    assertThat(componentsByRef.get(34).getKey()).startsWith("public_module 3:");
+    assertThat(componentsByRef.get(35).getDbKey()).startsWith("generated_project 1:");
+    assertThat(componentsByRef.get(35).getKey()).startsWith("public_project 1:");
+    assertThat(componentsByRef.get(36).getDbKey()).startsWith("generated_module 1:");
+    assertThat(componentsByRef.get(36).getKey()).startsWith("public_module 1:");
+    assertThat(componentsByRef.get(37).getDbKey()).startsWith("generated_module 2:");
+    assertThat(componentsByRef.get(37).getKey()).startsWith("public_module 2:");
+    assertThat(componentsByRef.get(38).getDbKey()).startsWith("generated_module 3:");
+    assertThat(componentsByRef.get(38).getKey()).startsWith("public_module 3:");
   }
 
   @Test
@@ -652,114 +652,6 @@ public class ComponentTreeBuilderTest {
     assertThat(file.getDescription()).isEqualTo("d");
   }
 
-  @Test
-  public void versions_of_module_directory_and_file_are_set_from_report_if_present() {
-    ScannerReport.Component project = newBuilder()
-      .setType(PROJECT)
-      .setRef(1)
-      .addChildRef(2)
-      .build();
-    scannerComponentProvider.add(newBuilder()
-      .setRef(2)
-      .setType(MODULE)
-      .setVersion("v1")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setVersion("v2")
-      .setPath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
-      .setType(FILE)
-      .setVersion("v3")
-      .setPath("src/js/Foo.js")
-      .setLines(1));
-
-    Component root = call(project);
-
-    Component module = root.getChildren().iterator().next();
-    assertThat(module.getReportAttributes().getVersion()).isEqualTo("v1");
-
-    Component directory = module.getChildren().iterator().next();
-    assertThat(directory.getReportAttributes().getVersion()).isEqualTo("v2");
-
-    Component file = directory.getChildren().iterator().next();
-    assertThat(file.getReportAttributes().getVersion()).isEqualTo("v3");
-  }
-
-  @Test
-  public void versions_of_module_directory_and_file_are_null_if_absent_from_report() {
-    ScannerReport.Component project = newBuilder()
-      .setType(PROJECT)
-      .setRef(1)
-      .addChildRef(2)
-      .build();
-    scannerComponentProvider.add(newBuilder()
-      .setRef(2)
-      .setType(MODULE)
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setPath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
-      .setType(FILE)
-      .setPath("src/js/Foo.js")
-      .setLines(1));
-
-    Component root = call(project);
-
-    Component module = root.getChildren().iterator().next();
-    assertThat(module.getReportAttributes().getVersion()).isNull();
-
-    Component directory = module.getChildren().iterator().next();
-    assertThat(directory.getReportAttributes().getVersion()).isNull();
-
-    Component file = directory.getChildren().iterator().next();
-    assertThat(file.getReportAttributes().getVersion()).isNull();
-  }
-
-  @Test
-  public void versions_of_module_directory_and_file_are_null_if_empty_in_report() {
-    ScannerReport.Component project = newBuilder()
-      .setType(PROJECT)
-      .setRef(1)
-      .addChildRef(2)
-      .build();
-    scannerComponentProvider.add(newBuilder()
-      .setRef(2)
-      .setType(MODULE)
-      .setVersion("")
-      .addChildRef(3));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(3)
-      .setType(DIRECTORY)
-      .setVersion("")
-      .setPath("src/js")
-      .addChildRef(4));
-    scannerComponentProvider.add(newBuilder()
-      .setRef(4)
-      .setType(FILE)
-      .setVersion("")
-      .setPath("src/js/Foo.js")
-      .setLines(1));
-
-    Component root = call(project);
-
-    Component module = root.getChildren().iterator().next();
-    assertThat(module.getReportAttributes().getVersion()).isNull();
-
-    Component directory = module.getChildren().iterator().next();
-    assertThat(directory.getReportAttributes().getVersion()).isNull();
-
-    Component file = directory.getChildren().iterator().next();
-    assertThat(file.getReportAttributes().getVersion()).isNull();
-  }
-
   @Test
   public void only_nb_of_lines_is_mandatory_on_file_attributes() {
     ScannerReport.Component project = newBuilder()
index 5f141c0ec003f2089bfec542ce15b48f8b5dc5f5..ba4ca7785439853f769ee7d0b7f7fd46ce5c2cd3 100644 (file)
@@ -52,7 +52,7 @@ public class MutableDbIdsRepositoryRule extends ExternalResource implements Muta
       @Nullable
       @Override
       public String apply(Component input) {
-        return input.getType().isReportType() ? String.valueOf(input.getReportAttributes().getRef()) : input.getKey();
+        return input.getType().isReportType() ? String.valueOf(input.getReportAttributes().getRef()) : input.getDbKey();
       }
     });
   }
index c19a122fcb97dc97a8d6957907a2f52e47535f51..87bd16bb9924a55ff525c7493128003c7d17d80e 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.component;
 import com.google.common.collect.ImmutableList;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
@@ -42,7 +43,7 @@ public class ReportComponent implements Component {
     .setPublicKey("PUBLIC_PROJECT_KEY")
     .setUuid("PROJECT_UUID")
     .setName("Project Name")
-    .setVersion("1.0-SNAPSHOT")
+    .setProjectVersion("1.0-SNAPSHOT")
     .build();
 
   private final Type type;
@@ -53,6 +54,7 @@ public class ReportComponent implements Component {
   private final String key;
   private final String publicKey;
   private final String uuid;
+  private final ProjectAttributes projectAttributes;
   private final ReportAttributes reportAttributes;
   private final FileAttributes fileAttributes;
   private final List<Component> children;
@@ -65,8 +67,8 @@ public class ReportComponent implements Component {
     this.name = builder.name == null ? String.valueOf(builder.key) : builder.name;
     this.description = builder.description;
     this.uuid = builder.uuid;
+    this.projectAttributes = Optional.ofNullable(builder.projectVersion).map(ProjectAttributes::new).orElse(null);
     this.reportAttributes = ReportAttributes.newBuilder(builder.ref)
-      .setVersion(builder.version)
       .setPath(builder.path)
       .build();
     this.fileAttributes = builder.fileAttributes == null ? DEFAULT_FILE_ATTRIBUTES : builder.fileAttributes;
@@ -92,7 +94,7 @@ public class ReportComponent implements Component {
   }
 
   @Override
-  public String getKey() {
+  public String getDbKey() {
     if (key == null) {
       throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef()));
     }
@@ -100,7 +102,7 @@ public class ReportComponent implements Component {
   }
 
   @Override
-  public String getPublicKey() {
+  public String getKey() {
     if (publicKey == null) {
       throw new UnsupportedOperationException(String.format("Component key of ref '%d' has not be fed yet", this.reportAttributes.getRef()));
     }
@@ -123,6 +125,12 @@ public class ReportComponent implements Component {
     return children;
   }
 
+  @Override
+  public ProjectAttributes getProjectAttributes() {
+    checkState(this.type == Type.PROJECT);
+    return this.projectAttributes;
+  }
+
   @Override
   public ReportAttributes getReportAttributes() {
     return this.reportAttributes;
@@ -188,7 +196,7 @@ public class ReportComponent implements Component {
     private String key;
     private String publicKey;
     private String name;
-    private String version;
+    private String projectVersion;
     private String description;
     private String path;
     private FileAttributes fileAttributes;
@@ -198,6 +206,9 @@ public class ReportComponent implements Component {
       checkArgument(type.isReportType(), "Component type must be a report type");
       this.type = type;
       this.ref = ref;
+      if (type == Type.PROJECT) {
+        this.projectVersion = "toBeDefined";
+      }
     }
 
     public Builder setStatus(Status s) {
@@ -225,8 +236,9 @@ public class ReportComponent implements Component {
       return this;
     }
 
-    public Builder setVersion(@Nullable String s) {
-      this.version = s;
+    public Builder setProjectVersion(String s) {
+      checkProjectVersion(s);
+      this.projectVersion = s;
       return this;
     }
 
@@ -255,8 +267,13 @@ public class ReportComponent implements Component {
     }
 
     public ReportComponent build() {
+      checkProjectVersion(this.projectVersion);
       return new ReportComponent(this);
     }
+
+    private void checkProjectVersion(@Nullable String s) {
+      checkArgument(type != Type.PROJECT ^ s != null, "Project version must and can only be set on Project");
+    }
   }
 
 }
index 10e49e301ea2be533f2b7d012cb4fad0367e3c7a..7b390817724990cca595255c28a96458e77d1a39 100644 (file)
@@ -34,7 +34,7 @@ public final class TreeComponentProvider extends AbstractComponentProvider {
   }
 
   private static String getRef(Component component) {
-    return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getKey();
+    return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getDbKey();
   }
 
   @Override
index e75b2500d894cb36cfe4b1754bbcf2f63449e26e..d53b1c12f2d1a0d04d8fb4a65dc37584e0d5a598 100644 (file)
@@ -148,7 +148,7 @@ public class ViewsComponent implements Component {
   }
 
   @Override
-  public String getKey() {
+  public String getDbKey() {
     return key;
   }
 
@@ -156,8 +156,8 @@ public class ViewsComponent implements Component {
    * Views has no branch feature, the public key is the same as the key
    */
   @Override
-  public String getPublicKey() {
-    return getKey();
+  public String getKey() {
+    return getDbKey();
   }
 
   @Override
@@ -177,6 +177,11 @@ public class ViewsComponent implements Component {
     return children;
   }
 
+  @Override
+  public ProjectAttributes getProjectAttributes() {
+    throw new IllegalStateException("A component of type " + type + " does not have project attributes");
+  }
+
   @Override
   public ReportAttributes getReportAttributes() {
     throw new IllegalStateException("A component of type " + type + " does not have report attributes");
index 4a5eb544c267f9c96e7de14b1ef2f3ccdcea2663..1ad4d0c95b337980ca441b09cbfcd6ecbeda3901 100644 (file)
@@ -181,7 +181,7 @@ public class ViewsPostOrderDepthTraversalTypeAwareCrawlerTest {
   }
 
   private static CallRecord viewsCallRecord(String methodName, Component component) {
-    return CallRecord.viewsCallRecord(methodName, component.getKey());
+    return CallRecord.viewsCallRecord(methodName, component.getDbKey());
   }
 
 }
index 1dc433925e37ff7ef1eb9eb2bf8fd68e43b89ab8..241516551f24e843237abba3e23389fb64fa894c 100644 (file)
@@ -181,7 +181,7 @@ public class ViewsPreOrderDepthTraversalTypeAwareCrawlerTest {
   }
 
   private static CallRecord viewsCallRecord(String methodName, Component component) {
-    return CallRecord.viewsCallRecord(methodName, component.getKey());
+    return CallRecord.viewsCallRecord(methodName, component.getDbKey());
   }
 
 }
index cf21f803887b938d81bcbfb079fa4e58393a7d11..21f4de8844e703ae3f0447e90908ff654acfb8a1 100644 (file)
@@ -154,7 +154,7 @@ public class ViewsVisitorsCrawlerTest {
       super(maxDepth, order, new SimpleStackElementFactory<Integer>() {
         @Override
         public Integer createForAny(Component component) {
-          return Integer.valueOf(component.getKey());
+          return Integer.valueOf(component.getDbKey());
         }
       });
     }
index 44d1f55c37a9fa77f37c5dfda95321398b93756a..b607a26399e1b51ca59e1ba28e726be492337cad 100644 (file)
@@ -296,7 +296,7 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, null);
-    insertFiles(file1.getKey(), file2.getKey());
+    insertFiles(file1.getDbKey(), file2.getDbKey());
     setFilesInReport(file2, file1);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -311,8 +311,8 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, CONTENT1);
-    ComponentDto[] dtos = insertFiles(file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
+    ComponentDto[] dtos = insertFiles(file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
     setFilesInReport(file2);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -331,8 +331,8 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, LESS_CONTENT1);
-    insertFiles(file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
+    insertFiles(file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
     setFilesInReport(file2);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -350,8 +350,8 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, CONTENT1);
-    insertFiles(file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT_EMPTY);
+    insertFiles(file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT_EMPTY);
     setFilesInReport(file2);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -367,8 +367,8 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, CONTENT1);
-    insertFiles(key -> newComponentDto(key).setPath(null), file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
+    insertFiles(key -> newComponentDto(key).setPath(null), file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
     setFilesInReport(file2);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -384,8 +384,8 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, CONTENT_EMPTY);
-    insertFiles(file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
+    insertFiles(file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
     setFilesInReport(file2);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -403,8 +403,8 @@ public class FileMoveDetectionStepTest {
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, CONTENT1);
     Component file3 = fileComponent(FILE_3_REF, CONTENT1);
-    insertFiles(file1.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
+    insertFiles(file1.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
     setFilesInReport(file2, file3);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -421,9 +421,9 @@ public class FileMoveDetectionStepTest {
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, null);
     Component file3 = fileComponent(FILE_3_REF, CONTENT1);
-    insertFiles(file1.getKey(), file2.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
-    insertContentOfFileInDb(file2.getKey(), CONTENT1);
+    insertFiles(file1.getDbKey(), file2.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
+    insertContentOfFileInDb(file2.getDbKey(), CONTENT1);
     setFilesInReport(file3);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -439,9 +439,9 @@ public class FileMoveDetectionStepTest {
     analysisMetadataHolder.setBaseAnalysis(ANALYSIS);
     Component file1 = fileComponent(FILE_1_REF, null);
     Component file2 = fileComponent(FILE_2_REF, null);
-    insertFiles(file1.getKey(), file2.getKey());
-    insertContentOfFileInDb(file1.getKey(), null);
-    insertContentOfFileInDb(file2.getKey(), null);
+    insertFiles(file1.getDbKey(), file2.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), null);
+    insertContentOfFileInDb(file2.getDbKey(), null);
 
     TestComputationStepContext context = new TestComputationStepContext();
     underTest.execute(context);
@@ -465,11 +465,11 @@ public class FileMoveDetectionStepTest {
     Component file4 = fileComponent(5, new String[] {"a", "b"});
     Component file5 = fileComponent(6, null);
     Component file6 = fileComponent(7, LESS_CONTENT2);
-    ComponentDto[] dtos = insertFiles(file1.getKey(), file2.getKey(), file4.getKey(), file5.getKey());
-    insertContentOfFileInDb(file1.getKey(), CONTENT1);
-    insertContentOfFileInDb(file2.getKey(), LESS_CONTENT1);
-    insertContentOfFileInDb(file4.getKey(), new String[] {"e", "f", "g", "h", "i"});
-    insertContentOfFileInDb(file5.getKey(), CONTENT2);
+    ComponentDto[] dtos = insertFiles(file1.getDbKey(), file2.getDbKey(), file4.getDbKey(), file5.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), CONTENT1);
+    insertContentOfFileInDb(file2.getDbKey(), LESS_CONTENT1);
+    insertContentOfFileInDb(file4.getDbKey(), new String[] {"e", "f", "g", "h", "i"});
+    insertContentOfFileInDb(file5.getDbKey(), CONTENT2);
     setFilesInReport(file3, file4, file6);
 
     TestComputationStepContext context = new TestComputationStepContext();
@@ -495,9 +495,9 @@ public class FileMoveDetectionStepTest {
     Component file2 = fileComponent(FILE_2_REF, null);
     Component file3 = fileComponent(FILE_3_REF, arrayOf(118));
     Component file4 = fileComponent(5, arrayOf(25));
-    insertFiles(file1.getKey(), file2.getKey());
-    insertContentOfFileInDb(file1.getKey(), arrayOf(100));
-    insertContentOfFileInDb(file2.getKey(), arrayOf(30));
+    insertFiles(file1.getDbKey(), file2.getDbKey());
+    insertContentOfFileInDb(file1.getDbKey(), arrayOf(100));
+    insertContentOfFileInDb(file2.getDbKey(), arrayOf(30));
     setFilesInReport(file3, file4);
 
     TestComputationStepContext context = new TestComputationStepContext();
index 3589f98ea8d274c738c75ef70cabe38ed47904ba..b828407587f0ab50fa1c1180ff85b13c615e0050 100644 (file)
@@ -119,7 +119,7 @@ public class MovedIssueVisitorTest {
     underTest.onIssue(FILE, issue);
 
     verify(issue).setComponentUuid(FILE.getUuid());
-    verify(issue).setComponentKey(FILE.getPublicKey());
+    verify(issue).setComponentKey(FILE.getKey());
     verify(issue).setModuleUuid(null);
     verify(issue).setModuleUuidPath(null);
     verify(issue).setChanged(true);
index 390f6d8035f634a9b5f246a9f2f64ada03a0a64a..2e5d7c4b1cee5ddf206581a8e92f9402ea025cb9 100644 (file)
@@ -345,8 +345,8 @@ public class TrackerRawInputFactoryTest {
   }
 
   private void assertInitializedIssue(DefaultIssue issue) {
-    assertThat(issue.projectKey()).isEqualTo(PROJECT.getPublicKey());
-    assertThat(issue.componentKey()).isEqualTo(FILE.getPublicKey());
+    assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey());
+    assertThat(issue.componentKey()).isEqualTo(FILE.getKey());
     assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid());
     assertThat(issue.resolution()).isNull();
     assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
@@ -357,8 +357,8 @@ public class TrackerRawInputFactoryTest {
   }
 
   private void assertInitializedExternalIssue(DefaultIssue issue) {
-    assertThat(issue.projectKey()).isEqualTo(PROJECT.getPublicKey());
-    assertThat(issue.componentKey()).isEqualTo(FILE.getPublicKey());
+    assertThat(issue.projectKey()).isEqualTo(PROJECT.getKey());
+    assertThat(issue.componentKey()).isEqualTo(FILE.getKey());
     assertThat(issue.componentUuid()).isEqualTo(FILE.getUuid());
     assertThat(issue.resolution()).isNull();
     assertThat(issue.status()).isEqualTo(Issue.STATUS_OPEN);
index 3f304f5d15dbf8f0bd0afaa0b55f895d95b7dbfd..968f75f43ac33bc25a24da574c2f759137d9a246 100644 (file)
@@ -334,7 +334,7 @@ public class MeasureRepositoryRule extends ExternalResource implements MeasureRe
   }
 
   private static String getRef(Component component) {
-    return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getKey();
+    return component.getType().isReportType() ? String.valueOf(component.getReportAttributes().getRef()) : component.getDbKey();
   }
 
   private static class MatchMetric implements Predicate<Map.Entry<InternalKey, Measure>> {
index 18b8500bf7dedc1005622df72c91b505858d9181..5bf7c351493fd690421716aea6abafaa0ca80d47 100644 (file)
@@ -95,7 +95,7 @@ public class ScmInfoDbLoaderTest {
     String hash = computeSourceHash(1);
     when(branch.getMergeBranchUuid()).thenReturn(Optional.of("mergeBranchUuid"));
 
-    when(mergeBranchComponentUuids.getUuid(FILE.getKey())).thenReturn(mergeFileUuid);
+    when(mergeBranchComponentUuids.getUuid(FILE.getDbKey())).thenReturn(mergeFileUuid);
     addFileSourceInDb("henry", DATE_1, "rev-1", hash, mergeFileUuid);
 
     DbScmInfo scmInfo = underTest.getScmInfo(FILE).get();
index 308b99140429ab29a76e406cf317820dc28ce82f..eb8414db81004df552375a917af6dd6d076dea4c 100644 (file)
@@ -502,8 +502,8 @@ public class BuildComponentTreeStepTest {
   private void verifyComponent(int ref, String key, String publicKey, @Nullable String uuid) {
     Map<Integer, Component> componentsByRef = indexAllComponentsInTreeByRef(treeRootHolder.getRoot());
     Component component = componentsByRef.get(ref);
-    assertThat(component.getKey()).isEqualTo(key);
-    assertThat(component.getPublicKey()).isEqualTo(publicKey);
+    assertThat(component.getDbKey()).isEqualTo(key);
+    assertThat(component.getKey()).isEqualTo(publicKey);
     if (uuid != null) {
       assertThat(component.getUuid()).isEqualTo(uuid);
     } else {
index 4efb2491c4c01cd3c7d2470819b64780eb96a378..adfb980b2d1ade7b16b93b4bc20eac9d26063687 100644 (file)
@@ -423,7 +423,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   private void setupRoot(ComponentDto project, String version) {
-    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setVersion(version).build());
+    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setProjectVersion(version).build());
     when(settingsRepository.getConfiguration()).thenReturn(settings.asConfig());
   }
 
index 1ed10710631bd6e6cdb0222e24ce8448709a3546..e3c51850649fd54db4e31090e1b8ca74e787b946 100644 (file)
@@ -55,7 +55,7 @@ public class PersistComponentsStepTest {
     String projectKey = randomAlphabetic(20);
 
     doReturn(component).when(treeRootHolder).getRoot();
-    doReturn(projectKey).when(component).getKey();
+    doReturn(projectKey).when(component).getDbKey();
     doReturn(componentDao).when(dbClient).componentDao();
     doReturn(emptyList()).when(componentDao).selectAllComponentsFromProjectKey(any(DbSession.class), eq(projectKey));
 
index 3fb6a435a965d7b3bcbc7905abde82072f08a0c3..dd7b2adc02516b29d4d0e156a86c8d7b711726c6 100644 (file)
@@ -50,12 +50,16 @@ import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.MODULE;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
+import static org.sonar.db.event.EventDto.CATEGORY_ALERT;
+import static org.sonar.db.event.EventDto.CATEGORY_PROFILE;
+import static org.sonar.db.event.EventDto.CATEGORY_VERSION;
 
 public class PersistEventsStepTest extends BaseStepTest {
 
   private static final long NOW = 1225630680000L;
   private static final ReportComponent ROOT = builder(PROJECT, 1)
     .setUuid("ABCD")
+    .setProjectVersion("version_1")
     .addChildren(
       builder(MODULE, 2)
         .setUuid("BCDE")
@@ -100,12 +104,39 @@ public class PersistEventsStepTest extends BaseStepTest {
   }
 
   @Test
-  public void nothing_to_do_when_no_events_in_report() {
-    treeRootHolder.setRoot(ROOT);
+  public void create_version_event() {
+    when(system2.now()).thenReturn(NOW);
+    Component project = builder(PROJECT, 1)
+      .setUuid("ABCD")
+      .setProjectVersion("1.0")
+      .addChildren(
+        builder(MODULE, 2)
+          .setUuid("BCDE")
+          .addChildren(
+            builder(DIRECTORY, 3)
+              .setUuid("Q")
+              .addChildren(
+                builder(FILE, 4)
+                  .setUuid("Z")
+                  .build())
+              .build())
+          .build())
+      .build();
+    treeRootHolder.setRoot(project);
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isZero();
+    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(1);
+    List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
+    assertThat(eventDtos).hasSize(1);
+    EventDto eventDto = eventDtos.iterator().next();
+    assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
+    assertThat(eventDto.getName()).isEqualTo("1.0");
+    assertThat(eventDto.getDescription()).isNull();
+    assertThat(eventDto.getCategory()).isEqualTo(CATEGORY_VERSION);
+    assertThat(eventDto.getData()).isNull();
+    assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
+    assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
   }
 
   @Test
@@ -117,14 +148,16 @@ public class PersistEventsStepTest extends BaseStepTest {
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(1);
+    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(2);
     List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
-    assertThat(eventDtos).hasSize(1);
-    EventDto eventDto = eventDtos.iterator().next();
+    assertThat(eventDtos)
+      .extracting(EventDto::getCategory)
+      .containsOnly(CATEGORY_ALERT, CATEGORY_VERSION);
+    EventDto eventDto = eventDtos.stream().filter(t -> CATEGORY_ALERT.equals(t.getCategory())).findAny().get();
     assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
     assertThat(eventDto.getName()).isEqualTo(alert.getName());
     assertThat(eventDto.getDescription()).isEqualTo(alert.getDescription());
-    assertThat(eventDto.getCategory()).isEqualTo(EventDto.CATEGORY_ALERT);
+    assertThat(eventDto.getCategory()).isEqualTo(CATEGORY_ALERT);
     assertThat(eventDto.getData()).isNull();
     assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
     assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
@@ -139,10 +172,12 @@ public class PersistEventsStepTest extends BaseStepTest {
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(1);
+    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(2);
     List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
-    assertThat(eventDtos).hasSize(1);
-    EventDto eventDto = eventDtos.iterator().next();
+    assertThat(eventDtos)
+      .extracting(EventDto::getCategory)
+      .containsOnly(CATEGORY_PROFILE, CATEGORY_VERSION);
+    EventDto eventDto = eventDtos.stream().filter(t -> CATEGORY_PROFILE.equals(t.getCategory())).findAny().get();
     assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
     assertThat(eventDto.getName()).isEqualTo(profile.getName());
     assertThat(eventDto.getDescription()).isEqualTo(profile.getDescription());
@@ -152,42 +187,6 @@ public class PersistEventsStepTest extends BaseStepTest {
     assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
   }
 
-  @Test
-  public void create_version_event() {
-    when(system2.now()).thenReturn(NOW);
-    Component project = builder(PROJECT, 1)
-      .setUuid("ABCD")
-      .setVersion("1.0")
-      .addChildren(
-        builder(MODULE, 2)
-          .setUuid("BCDE")
-          .addChildren(
-            builder(DIRECTORY, 3)
-              .setUuid("Q")
-              .addChildren(
-                builder(FILE, 4)
-                  .setUuid("Z")
-                  .build())
-              .build())
-          .build())
-      .build();
-    treeRootHolder.setRoot(project);
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(dbTester.countRowsOfTable(dbTester.getSession(), "events")).isEqualTo(1);
-    List<EventDto> eventDtos = dbTester.getDbClient().eventDao().selectByComponentUuid(dbTester.getSession(), ROOT.getUuid());
-    assertThat(eventDtos).hasSize(1);
-    EventDto eventDto = eventDtos.iterator().next();
-    assertThat(eventDto.getComponentUuid()).isEqualTo(ROOT.getUuid());
-    assertThat(eventDto.getName()).isEqualTo("1.0");
-    assertThat(eventDto.getDescription()).isNull();
-    assertThat(eventDto.getCategory()).isEqualTo(EventDto.CATEGORY_VERSION);
-    assertThat(eventDto.getData()).isNull();
-    assertThat(eventDto.getDate()).isEqualTo(analysisMetadataHolder.getAnalysisDate());
-    assertThat(eventDto.getCreatedAt()).isEqualTo(NOW);
-  }
-
   @Test
   public void keep_one_event_by_version() {
     ComponentDto projectDto = dbTester.components().insertPublicProject();
@@ -199,7 +198,7 @@ public class PersistEventsStepTest extends BaseStepTest {
 
     Component project = builder(PROJECT, 1)
       .setUuid(projectDto.uuid())
-      .setVersion("1.5-SNAPSHOT")
+      .setProjectVersion("1.5-SNAPSHOT")
       .addChildren(
         builder(MODULE, 2)
           .setUuid("BCDE")
@@ -232,7 +231,7 @@ public class PersistEventsStepTest extends BaseStepTest {
   private EventDto newVersionEventDto(ComponentDto project, long date, String name) {
     return new EventDto().setUuid(uuidFactory.create()).setComponentUuid(project.uuid())
       .setAnalysisUuid("analysis_uuid")
-      .setCategory(EventDto.CATEGORY_VERSION)
+      .setCategory(CATEGORY_VERSION)
       .setName(name).setDate(date).setCreatedAt(date);
   }
 
index 53a143118bd3dc630b39c3b5a039c63cc1fff4c2..c5f6ff47cbfe2bf39a2cc8c6e201c494edccfec9 100644 (file)
@@ -249,7 +249,7 @@ public class PersistLiveMeasuresStepTest extends BaseStepTest {
           .build())
       .build();
     treeRootHolder.setRoot(project);
-    analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getKey(), project.getName(), project.getDescription(), emptyList()));
+    analysisMetadataHolder.setProject(new Project(project.getUuid(), project.getDbKey(), project.getName(), project.getDescription(), emptyList()));
 
     // components as persisted in db
     ComponentDto projectDto = insertComponent("project-key", "project-uuid");
index 25157a69c85728d01c6add6dfa5664e5ca1e87f2..32bb8fcfab67a6f4f36955f04d7e4c8111d9910c 100644 (file)
@@ -59,8 +59,11 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.WARN;
 
 public class QualityGateEventsStepTest {
-  private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("uuid 1").setKey("key 1")
-    .addChildren(ReportComponent.builder(Component.Type.MODULE, 2).setVersion("V1.9").build())
+  private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1)
+    .setUuid("uuid 1")
+    .setKey("key 1")
+    .setProjectVersion("V1.9")
+    .addChildren(ReportComponent.builder(Component.Type.MODULE, 2).build())
     .build();
   private static final String INVALID_ALERT_STATUS = "trololo";
   private static final String ALERT_TEXT = "alert text";
@@ -89,7 +92,7 @@ public class QualityGateEventsStepTest {
   @Before
   public void setUp() {
     when(metricRepository.getByKey(ALERT_STATUS_KEY)).thenReturn(alertStatusMetric);
-    analysisMetadataHolder.setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList()));
+    analysisMetadataHolder.setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getDbKey(), PROJECT_COMPONENT.getName(), PROJECT_COMPONENT.getDescription(), emptyList()));
     analysisMetadataHolder.setBranch(mock(Branch.class));
     treeRootHolder.setRoot(PROJECT_COMPONENT);
   }
@@ -194,9 +197,9 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
     assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name());
     assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
@@ -249,9 +252,9 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
     assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name());
     assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
@@ -279,9 +282,9 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(branchName);
 
     reset(measureRepository, eventRepository, notificationService);
@@ -301,9 +304,9 @@ public class QualityGateEventsStepTest {
     verify(notificationService).deliver(notificationArgumentCaptor.capture());
     Notification notification = notificationArgumentCaptor.getValue();
     assertThat(notification.getType()).isEqualTo("alerts");
-    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getReportAttributes().getVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(null);
 
     reset(measureRepository, eventRepository, notificationService);
index 4ce74afaa5a1cda29c123534e3ea75186d67fbaf..3eab52bb7cee5928ac3496d62e81622e44165445 100644 (file)
@@ -107,8 +107,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
 
     Component file = ReportComponent.builder(Component.Type.FILE, 4).setUuid("DEFG").setKey("MODULE_KEY:src/main/java/dir/Foo.java").build();
     Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 3).setUuid("CDEF").setKey("MODULE_KEY:src/main/java/dir").addChildren(file).build();
-    Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").setVersion("1.1").addChildren(directory).build();
-    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setVersion("1.0").addChildren(module).build();
+    Component module = ReportComponent.builder(Component.Type.MODULE, 2).setUuid("BCDE").setKey("MODULE_KEY").addChildren(directory).build();
+    Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).setProjectVersion("1.0").addChildren(module).build();
     treeRootHolder.setRoot(project);
 
     dbIdsRepository.setComponentId(project, projectDto.getId());
index 0c4c2db21e293107edead5a335dbc460d0cbc2a5..65affe6d83af6eeab713e7a4f5ab8fb633ac0ac3 100644 (file)
@@ -27,7 +27,6 @@ import java.util.Map;
 import java.util.Random;
 import java.util.stream.IntStream;
 import java.util.stream.Stream;
-import org.apache.commons.lang.RandomStringUtils;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -63,6 +62,7 @@ import static java.util.Arrays.stream;
 import static java.util.Collections.shuffle;
 import static java.util.stream.Collectors.toList;
 import static java.util.stream.Stream.concat;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.apache.commons.lang.math.RandomUtils.nextInt;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.ArgumentCaptor.forClass;
@@ -96,7 +96,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
 
   private static final Component FILE = builder(Type.FILE, 11).build();
   private static final Component PROJECT = builder(Type.PROJECT, 1)
-    .setVersion(RandomStringUtils.randomAlphanumeric(10))
+    .setProjectVersion(randomAlphanumeric(10))
     .addChildren(FILE).build();
 
   @Rule
@@ -157,7 +157,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     underTest.execute(context);
 
     verify(notificationService).deliver(newIssuesNotificationMock);
-    verify(newIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null, null);
+    verify(newIssuesNotificationMock).setProject(PROJECT.getKey(), PROJECT.getName(), null, null);
     verify(newIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
     verify(newIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any());
     verify(newIssuesNotificationMock).setDebt(ISSUE_DURATION);
@@ -283,7 +283,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     verify(notificationService).deliver(newIssuesNotificationMock);
     verify(notificationService).deliver(myNewIssuesNotificationMock);
     verify(myNewIssuesNotificationMock).setAssignee(any(UserDto.class));
-    verify(myNewIssuesNotificationMock).setProject(PROJECT.getPublicKey(), PROJECT.getName(), null, null);
+    verify(myNewIssuesNotificationMock).setProject(PROJECT.getKey(), PROJECT.getName(), null, null);
     verify(myNewIssuesNotificationMock).setAnalysisDate(new Date(ANALYSE_DATE));
     verify(myNewIssuesNotificationMock).setStatistics(eq(PROJECT.getName()), any(NewIssuesStatistics.Stats.class));
     verify(myNewIssuesNotificationMock).setDebt(ISSUE_DURATION);
@@ -417,8 +417,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
   @Test
   public void dont_send_issues_change_notification_for_hotspot() {
     UserDto user = db.users().insertUser();
-    ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getKey()).setLongName(PROJECT.getName());
-    ComponentDto file = newFileDto(project).setDbKey(FILE.getKey()).setLongName(FILE.getName());
+    ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName());
+    ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName());
     RuleDefinitionDto ruleDefinitionDto = newRule();
     DefaultIssue issue = prepareIssue(ANALYSE_DATE, user, project, file, ruleDefinitionDto, RuleType.SECURITY_HOTSPOT);
 
@@ -436,8 +436,8 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
 
   private void sendIssueChangeNotification(long issueCreatedAt) {
     UserDto user = db.users().insertUser();
-    ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getKey()).setLongName(PROJECT.getName());
-    ComponentDto file = newFileDto(project).setDbKey(FILE.getKey()).setLongName(FILE.getName());
+    ComponentDto project = newPrivateProjectDto(newOrganizationDto()).setDbKey(PROJECT.getDbKey()).setLongName(PROJECT.getName());
+    ComponentDto file = newFileDto(project).setDbKey(FILE.getDbKey()).setLongName(FILE.getName());
     RuleDefinitionDto ruleDefinitionDto = newRule();
     RuleType randomTypeExceptHotspot = RuleType.values()[nextInt(RuleType.values().length - 1)];
     DefaultIssue issue = prepareIssue(issueCreatedAt, user, project, file, ruleDefinitionDto, randomTypeExceptHotspot);