Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update with new alizer #485

Merged
merged 2 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.intellij.openapi.project.Project;
import com.redhat.devtools.alizer.api.Language;
import com.redhat.devtools.alizer.api.LanguageRecognizerBuilder;
import com.redhat.devtools.alizer.api.RecognizerFactory;
import com.redhat.devtools.intellij.common.utils.ExecHelper;
import com.redhat.devtools.intellij.common.utils.YAMLHelper;
import com.redhat.devtools.intellij.tektoncd.Constants;
Expand All @@ -35,6 +35,9 @@
import io.fabric8.tekton.pipeline.v1beta1.ClusterTask;
import io.fabric8.tekton.pipeline.v1beta1.Pipeline;
import io.fabric8.tekton.pipeline.v1beta1.Task;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand All @@ -47,8 +50,6 @@
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import static com.redhat.devtools.intellij.tektoncd.Constants.APP_K8S_IO_VERSION;
Expand Down Expand Up @@ -115,7 +116,7 @@ public List<HubItem> getAllHubItems() {

private List<HubItem> getHubItems(Predicate<ResourceData> filter) {
try {
List<Language> languages = new LanguageRecognizerBuilder().build().analyze(project.getBasePath());
List<Language> languages = new RecognizerFactory().createLanguageRecognizer().analyze(project.getBasePath());
return retrieveAllResources().stream()
.filter(filter)
.map(HubItem::new)
Expand All @@ -141,7 +142,7 @@ public List<HubItem> getAllPipelineHubItems() {

public List<HubItem> getRecommendedHubItems() {
try {
List<Language> languages = new LanguageRecognizerBuilder().build().analyze(project.getBasePath());
List<Language> languages = new RecognizerFactory().createLanguageRecognizer().analyze(project.getBasePath());
List<String> hubItemsAlreadyInstalled = getAllInstalledHubItems().stream()
.map(task -> task.getMetadata().getName())
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData;
import com.redhat.devtools.intellij.tektoncd.hub.model.ResourceVersionData;
import com.redhat.devtools.intellij.tektoncd.hub.model.Tag;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;


import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
Expand All @@ -29,8 +29,8 @@ public class HubItemScoreTest {

@Test
public void Compare_2HubItems_VerifyCalculatedScoreWithOnlyName() {
Language lang = new Language("First", Collections.emptyList(), 99.0);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0);
Language lang = new Language("First", Collections.emptyList(), 99.0, false);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0, false);
List<Language> languages = Arrays.asList(lang, lang2);

HubItem hubItem1 = buildHubItem("Second", "", Collections.emptyList());
Expand All @@ -43,8 +43,8 @@ public void Compare_2HubItems_VerifyCalculatedScoreWithOnlyName() {

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithOnlyName() {
Language lang = new Language("First", Collections.emptyList(), 99.0);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0);
Language lang = new Language("First", Collections.emptyList(), 99.0, false);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0, false);
List<Language> languages = Arrays.asList(lang, lang2);

HubItem hubItem1 = buildHubItem("Second", "", Collections.emptyList());
Expand All @@ -56,8 +56,8 @@ public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithOnlyName() {

@Test
public void Compare_2HubItems_VerifyCalculatedScoreWithAliases() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0);
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, false);
List<Language> languages = Arrays.asList(lang, lang2);

HubItem hubItem1 = buildHubItem("alias1", "", Collections.emptyList());
Expand All @@ -70,8 +70,8 @@ public void Compare_2HubItems_VerifyCalculatedScoreWithAliases() {

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithAliases() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0);
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, false);
List<Language> languages = Arrays.asList(lang, lang2);

HubItem hubItem1 = buildHubItem("alias1", "", Collections.emptyList());
Expand All @@ -83,8 +83,8 @@ public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithAliases() {

@Test
public void Compare_2HubItems_VerifyCalculatedScoreWithFrameworks() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList());
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList());
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList(), false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList(), false);
List<Language> languages = Arrays.asList(lang, lang2);

Tag tag = buildTag("framework1");
Expand All @@ -101,8 +101,8 @@ public void Compare_2HubItems_VerifyCalculatedScoreWithFrameworks() {

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithFrameworks() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList());
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList());
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList(), false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList(), false);
List<Language> languages = Arrays.asList(lang, lang2);

Tag tag = buildTag("framework1");
Expand All @@ -116,8 +116,8 @@ public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithFrameworks() {

@Test
public void Compare_2HubItems_VerifyCalculatedScoreWithDescription() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList());
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList());
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList(), false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList(), false);
List<Language> languages = Arrays.asList(lang, lang2);

Tag tag2 = buildTag("framework2");
Expand All @@ -133,8 +133,8 @@ public void Compare_2HubItems_VerifyCalculatedScoreWithDescription() {

@Test
public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithDescription() {
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList());
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList());
Language lang = new Language("First", Arrays.asList("alias1", "alias2"), 99.0, Arrays.asList("framework1"), Collections.emptyList(), false);
Language lang2 = new Language("Second", Arrays.asList("alias3", "alias4"), 1.0, Arrays.asList("framework2"), Collections.emptyList(), false);
List<Language> languages = Arrays.asList(lang, lang2);

HubItem hubItem1 = buildHubItem("name", "this is the first item for the first language", Collections.emptyList());
Expand All @@ -146,9 +146,9 @@ public void Compare_1HubItemAndValue_VerifyCalculatedScoreWithDescription() {

@Test
public void Compare_ListWith3HubItems_OrderedList() {
Language lang = new Language("First", Collections.emptyList(), 50.0);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0);
Language lang3 = new Language("Third", Collections.emptyList(), 49.0);
Language lang = new Language("First", Collections.emptyList(), 50.0, false);
Language lang2 = new Language("Second", Collections.emptyList(), 1.0, false);
Language lang3 = new Language("Third", Collections.emptyList(), 49.0, false);
List<Language> languages = Arrays.asList(lang, lang2, lang3);

HubItem hubItem1 = buildHubItem("Second", "", Collections.emptyList());
Expand Down Expand Up @@ -183,4 +183,4 @@ private HubItem buildHubItem(String name, String description, List<Tag> tags) {
HubItem hubItem = new HubItem(resourceData);
return hubItem;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import com.redhat.devtools.alizer.api.Language;
import com.redhat.devtools.alizer.api.LanguageRecognizer;
import com.redhat.devtools.alizer.api.LanguageRecognizerBuilder;
import com.redhat.devtools.alizer.api.RecognizerFactory;
import com.redhat.devtools.intellij.tektoncd.BaseTest;
import com.redhat.devtools.intellij.tektoncd.hub.api.ResourceApi;
import com.redhat.devtools.intellij.tektoncd.hub.model.ResourceData;
Expand All @@ -21,14 +21,14 @@
import com.redhat.devtools.intellij.tektoncd.tree.ClusterTasksNode;
import com.redhat.devtools.intellij.tektoncd.tree.PipelinesNode;
import io.fabric8.kubernetes.client.Watch;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockedConstruction;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.redhat.devtools.intellij.tektoncd.Constants.KIND_PIPELINE;
import static com.redhat.devtools.intellij.tektoncd.Constants.KIND_TASK;
Expand All @@ -46,7 +46,7 @@ public class HubModelTest extends BaseTest {

private PipelinesNode pipelinesNode;
private ClusterTasksNode clusterTasksNode;
private LanguageRecognizerBuilder languageRecognizerBuilder;
private RecognizerFactory recognizerFactory;
private LanguageRecognizer languageRecognizer;
private Language languageJAVA, languageUnknown;
private ResourceData resourceDataJAVA, resourceDataGO, resourceDataNET;
Expand All @@ -64,11 +64,11 @@ public void setUp() throws Exception {
when(tkn.watchClusterTasks(any())).thenReturn(watch);
pipelinesNode = mock(PipelinesNode.class);
clusterTasksNode = mock(ClusterTasksNode.class);
languageRecognizerBuilder = mock(LanguageRecognizerBuilder.class);
recognizerFactory = mock(RecognizerFactory.class);
languageRecognizer = mock(LanguageRecognizer.class);
when(languageRecognizerBuilder.build()).thenReturn(languageRecognizer);
languageJAVA = new Language("java", Collections.emptyList(), 1.0);
languageUnknown = new Language("Unknown", Collections.emptyList(), 1.0);
when(recognizerFactory.createLanguageRecognizer()).thenReturn(languageRecognizer);
languageJAVA = new Language("java", Collections.emptyList(), 1.0, true);
languageUnknown = new Language("Unknown", Collections.emptyList(), 1.0, false);
resourceApi = mock(ResourceApi.class);

resourceDataJAVA = mock(ResourceData.class);
Expand Down Expand Up @@ -104,8 +104,8 @@ public void GetAllPipelineHubItems_RemoteHubContainsPipelineResources_ListWithAl
resources.addDataItem(resourceDataNET);
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageJAVA);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -122,8 +122,8 @@ public void GetAllPipelineHubItems_RemoteHubContainsPipelineResources_ListWithAl
public void GetAllPipelineHubItems_RemoteHubHasNoPipelineResources_EmptyList() throws IOException {
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageJAVA);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -139,8 +139,8 @@ public void GetAllPipelineHubItems_RemoteHubHasNoPipelineResources_EmptyList() t
public void GetAllTaskHubItems_RemoteHubContainsTaskResources_ListWithAllTasks() throws IOException {
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageJAVA);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -160,8 +160,8 @@ public void GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList() throws IO
resources.addDataItem(resourceDataNET);
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageJAVA);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -177,8 +177,8 @@ public void GetAllTaskHubItems_RemoteHubHasNoTaskResources_EmptyList() throws IO
public void GetRecommendedHubItems_LanguagesHasHubItemsRelated_FilteredList() throws IOException {
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageJAVA);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -195,8 +195,8 @@ public void GetRecommendedHubItems_LanguagesHasHubItemsRelated_FilteredList() th
public void GetRecommendedHubItems_LanguagesHasNoHubItemsRelated_EmptyList() throws IOException {
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
try(MockedConstruction<LanguageRecognizerBuilder> languageRecognizerBuilderMockedConstruction = mockConstruction(LanguageRecognizerBuilder.class,
(mock, context) -> when(mock.build()).thenReturn(languageRecognizer))) {
try(MockedConstruction<RecognizerFactory> languageRecognizerBuilderMockedConstruction = mockConstruction(RecognizerFactory.class,
(mock, context) -> when(mock.createLanguageRecognizer()).thenReturn(languageRecognizer))) {

List<Language> languages = Arrays.asList(languageUnknown);
when(languageRecognizer.analyze(anyString())).thenReturn(languages);
Expand All @@ -212,9 +212,9 @@ public void GetRecommendedHubItems_LanguagesHasNoHubItemsRelated_EmptyList() thr
public void GetInstalledHubItems_NoInstalledItems_EmptyList() {
try(MockedConstruction<ResourceApi> resourceApiMockedConstruction = mockConstruction(ResourceApi.class,
(mock, context) -> when(mock.resourceList(anyInt())).thenReturn(resources))) {
HubModel model = new HubModel(project, tkn, null);
List<HubItem> recommendedItems = model.getInstalledHubItems();
assertEquals(0, recommendedItems.size());
HubModel model = new HubModel(project, tkn, null);
List<HubItem> recommendedItems = model.getInstalledHubItems();
assertEquals(0, recommendedItems.size());
}
}

Expand Down Expand Up @@ -254,4 +254,4 @@ public void GetIsPipelineView_CallerIsAClusterTasksNode_True() {
assertTrue(model.getIsPipelineView());
}

}
}