Skip to content

Commit 9dc73d3

Browse files
Merge pull request #5060 from microsoft/cache/referencebook
apply new cache framework in Azure SDK Reference Book
2 parents 4e05cbf + c123680 commit 9dc73d3

File tree

8 files changed

+39
-63
lines changed

8 files changed

+39
-63
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
package com.microsoft.azure.toolkit.intellij.common.preload;
7+
8+
import com.intellij.openapi.application.ApplicationManager;
9+
import com.intellij.openapi.application.PreloadingActivity;
10+
import com.intellij.openapi.progress.ProgressIndicator;
11+
import com.microsoft.azure.toolkit.lib.common.cache.Preloader;
12+
import lombok.extern.java.Log;
13+
14+
@Log
15+
public class AzurePreloadingActivity extends PreloadingActivity {
16+
17+
@Override
18+
public void preload(@org.jetbrains.annotations.NotNull final ProgressIndicator indicator) {
19+
// Using progress manager as azure task manager is not initialized
20+
ApplicationManager.getApplication().executeOnPooledThread(Preloader::load);
21+
}
22+
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-intellij-plugin-lib/src/main/resources/META-INF/azure-intellij-plugin-lib.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<extensionPoints>
33
</extensionPoints>
44
<extensions defaultExtensionNs="com.intellij">
5+
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.common.preload.AzurePreloadingActivity"/>
56
</extensions>
67
<actions>
78
</actions>

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
id 'java'
33
id "org.jetbrains.intellij"
4+
id "io.freefair.aspectj.post-compile-weaving"
45
}
56

67
group 'com.microsoft.azuretools'
@@ -26,6 +27,8 @@ dependencies {
2627
exclude group: "com.fasterxml.jackson", module: "jackson-bom"
2728
}
2829

29-
implementation project(':azure-intellij-plugin-lib')
30-
implementation "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
30+
compile project(':azure-intellij-plugin-lib')
31+
compile "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
32+
33+
aspect "com.microsoft.azure:azure-toolkit-common-lib:0.5.0-SNAPSHOT"
3134
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/dependencesurvey/activity/AzurePreloadingActivity.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/referencebook/AzureSdkTreePanel.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ private void filter(final String text) {
9595
this.loadData(this.services, filters);
9696
}
9797

98-
public void refresh() {
99-
final AzureSdkLibraryService service = AzureSdkLibraryService.getInstance();
98+
public void refresh(boolean... force) {
10099
try {
101-
service.reloadAzureSDKArtifacts();
102-
this.services = service.getServices();
100+
this.services = AzureSdkLibraryService.loadAzureSdkServices(force);
103101
this.filter.debounce();
104102
Optional.ofNullable(this.lastNodePath).ifPresent(p -> TreeUtil.selectPath(this.tree, p));
105103
} catch (final IOException e) {
@@ -176,7 +174,7 @@ public final void actionPerformed(@NotNull final AnActionEvent e) {
176174
this.loading = true;
177175
ActivityTracker.getInstance().inc();
178176
AzureTaskManager.getInstance().runLater(() -> {
179-
AzureSdkTreePanel.this.refresh();
177+
AzureSdkTreePanel.this.refresh(true);
180178
this.loading = false;
181179
});
182180
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/java/com/microsoft/azure/toolkit/intellij/azuresdk/service/AzureSdkLibraryService.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,23 @@
1111
import com.fasterxml.jackson.databind.ObjectReader;
1212
import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
1313
import com.microsoft.azure.toolkit.intellij.azuresdk.model.AzureSdkServiceEntity;
14+
import com.microsoft.azure.toolkit.lib.common.cache.Cacheable;
15+
import com.microsoft.azure.toolkit.lib.common.cache.Preload;
1416

1517
import java.io.IOException;
1618
import java.net.URL;
17-
import java.util.ArrayList;
18-
import java.util.Collections;
1919
import java.util.List;
2020

2121
public class AzureSdkLibraryService {
2222
private static final ObjectMapper mapper = new YAMLMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
2323
private static final String SDK_METADATA_URL = "https://raw.githubusercontent.com/Azure/azure-sdk-for-java/master/sdk/spring/spring-reference.yml";
24-
private List<AzureSdkServiceEntity> services = new ArrayList<>();
2524

26-
public static AzureSdkLibraryService getInstance() {
27-
return Holder.instance;
28-
}
29-
30-
public List<AzureSdkServiceEntity> getServices() {
31-
return Collections.unmodifiableList(services);
32-
}
33-
34-
public void reloadAzureSDKArtifacts() throws IOException {
25+
@Preload
26+
@Cacheable(value = "sdk-services", condition = "!(force&&force[0])")
27+
public static List<AzureSdkServiceEntity> loadAzureSdkServices(boolean... force) throws IOException {
3528
final URL destination = new URL(SDK_METADATA_URL);
3629
final ObjectReader reader = mapper.readerFor(AzureSdkServiceEntity.class);
3730
final MappingIterator<AzureSdkServiceEntity> data = reader.readValues(destination);
38-
synchronized (this) {
39-
this.services = data.readAll();
40-
}
41-
}
42-
43-
private static class Holder {
44-
private static final AzureSdkLibraryService instance = new AzureSdkLibraryService();
31+
return data.readAll();
4532
}
4633
}

PluginsAndFeatures/azure-toolkit-for-intellij/azure-sdk-reference-book/src/main/resources/META-INF/azure-sdk-reference-book.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<idea-plugin>
22
<extensionPoints>
33
</extensionPoints>
4-
<extensions defaultExtensionNs="com.intellij">
5-
<preloadingActivity implementation="com.microsoft.azure.toolkit.intellij.azuresdk.dependencesurvey.activity.AzurePreloadingActivity"/>
6-
</extensions>
74
<actions>
85
<action id="AzureToolkit.OpenSdkReferenceBook"
96
class="com.microsoft.azure.toolkit.intellij.azuresdk.referencebook.OpenReferenceBookAction"

PluginsAndFeatures/azure-toolkit-for-intellij/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ configurations {
9898
apply plugin: 'java'
9999

100100
dependencies {
101-
implementation project(':azure-intellij-plugin-lib')
102-
implementation project(':azure-sdk-reference-book')
101+
compile project(':azure-intellij-plugin-lib')
102+
compile project(':azure-sdk-reference-book')
103103
compile 'com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre8'
104104
compile 'commons-io:commons-io:2.7'
105105
compile group: 'org.apache.commons', name: 'commons-text', version: '1.8'

0 commit comments

Comments
 (0)