-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONAR-9551 Add attribute to view to detect applications
- Loading branch information
1 parent
d275093
commit 0ce3af0
Showing
7 changed files
with
186 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...main/java/org/sonar/server/computation/task/projectanalysis/component/ViewAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.component; | ||
|
||
import java.util.Arrays; | ||
import javax.annotation.concurrent.Immutable; | ||
import org.sonar.api.resources.Qualifiers; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
@Immutable | ||
public class ViewAttributes { | ||
|
||
public enum Type { | ||
PORTFOLIO(Qualifiers.VIEW), APPLICATION(Qualifiers.APP); | ||
|
||
private final String qualifier; | ||
|
||
Type(String qualifier) { | ||
this.qualifier = qualifier; | ||
} | ||
|
||
public String getQualifier() { | ||
return qualifier; | ||
} | ||
|
||
public static Type fromQualifier(String qualifier) { | ||
return Arrays.stream(values()) | ||
.filter(type -> type.getQualifier().equals(qualifier)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalStateException(String.format("Qualifier '%s' is not supported", qualifier))); | ||
} | ||
} | ||
|
||
private final Type type; | ||
|
||
public ViewAttributes(Type type) { | ||
this.type = requireNonNull(type, "Type cannot be null"); | ||
} | ||
|
||
public Type getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "viewAttributes{" + | ||
"type='" + type + '\'' + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../java/org/sonar/server/computation/task/projectanalysis/component/ViewAttributesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* SonarQube | ||
* Copyright (C) 2009-2017 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.server.computation.task.projectanalysis.component; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
import org.sonar.api.resources.Qualifiers; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.APPLICATION; | ||
import static org.sonar.server.computation.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO; | ||
|
||
public class ViewAttributesTest { | ||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
private ViewAttributes underTest; | ||
|
||
@Test | ||
public void create_portfolio() { | ||
underTest = new ViewAttributes(PORTFOLIO); | ||
|
||
assertThat(underTest.getType()).isEqualTo(PORTFOLIO); | ||
assertThat(underTest.getType().getQualifier()).isEqualTo(Qualifiers.VIEW); | ||
} | ||
|
||
@Test | ||
public void create_application() { | ||
underTest = new ViewAttributes(APPLICATION); | ||
|
||
assertThat(underTest.getType()).isEqualTo(APPLICATION); | ||
assertThat(underTest.getType().getQualifier()).isEqualTo(Qualifiers.APP); | ||
} | ||
|
||
@Test | ||
public void type_from_qualifier() { | ||
assertThat(ViewAttributes.Type.fromQualifier(Qualifiers.VIEW)).isEqualTo(PORTFOLIO); | ||
assertThat(ViewAttributes.Type.fromQualifier(Qualifiers.APP)).isEqualTo(APPLICATION); | ||
} | ||
|
||
@Test | ||
public void fail_if_unknown_view_qualifier() { | ||
expectedException.expect(IllegalStateException.class); | ||
expectedException.expectMessage("Qualifier 'TRK' is not supported"); | ||
|
||
ViewAttributes.Type.fromQualifier(Qualifiers.PROJECT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters