3 * Copyright (C) 2009-2022 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.component;
22 import javax.annotation.CheckForNull;
23 import javax.annotation.Nullable;
24 import javax.annotation.concurrent.Immutable;
26 import static com.google.common.base.Preconditions.checkArgument;
27 import static org.apache.commons.lang.StringUtils.abbreviate;
28 import static org.apache.commons.lang.StringUtils.trimToNull;
29 import static org.sonar.db.component.ComponentValidator.MAX_COMPONENT_NAME_LENGTH;
32 * The attributes specific to a Component of type {@link Component.Type#FILE}.
35 public class FileAttributes {
36 private final boolean unitTest;
38 private final String languageKey;
39 private final boolean markedAsUnchanged;
40 private final int lines;
41 private String oldName;
43 public FileAttributes(boolean unitTest, @Nullable String languageKey, int lines) {
44 this(unitTest, languageKey, lines, false, null);
47 public FileAttributes(boolean unitTest, @Nullable String languageKey, int lines, boolean markedAsUnchanged, @Nullable String oldName) {
48 this.unitTest = unitTest;
49 this.languageKey = languageKey;
50 this.markedAsUnchanged = markedAsUnchanged;
51 checkArgument(lines > 0, "Number of lines must be greater than zero");
53 this.oldName = formatOldName(oldName);
56 public boolean isMarkedAsUnchanged() {
57 return markedAsUnchanged;
60 public boolean isUnitTest() {
65 public String getLanguageKey() {
70 public String getOldName() {
75 * Number of lines of the file, can never be less than 1
77 public int getLines() {
82 public String toString() {
83 return "FileAttributes{" +
84 "languageKey='" + languageKey + '\'' +
85 ", unitTest=" + unitTest +
87 ", markedAsUnchanged=" + markedAsUnchanged +
88 ", oldName=" + oldName +
92 private String formatOldName(@Nullable String name) {
93 return abbreviate(trimToNull(name), MAX_COMPONENT_NAME_LENGTH);