Skip to content

Commit d88c258

Browse files
authored
Derive icon previews from font files for built-in icons (#5820)
* Derive icon previews from font files for built-in icons * Do not analyze testData * Make dart analyze more selective * Disable some failing tests
1 parent 7104256 commit d88c258

File tree

19 files changed

+3408
-193
lines changed

19 files changed

+3408
-193
lines changed

flutter-idea/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ sourceSets {
9696
]
9797
test.resources.srcDirs = [
9898
"src/main/resources",
99-
"testData/unit",
99+
"testData",
100100
"testSrc/unit"
101101
]
102102
}
@@ -117,4 +117,10 @@ check.dependsOn verifyPlugin
117117

118118
test {
119119
useJUnit()
120+
testLogging {
121+
events "failed"
122+
exceptionFormat "full"
123+
showCauses true
124+
showStackTraces true
125+
}
120126
}

src/io/flutter/editor/FlutterIconLineMarkerProvider.java

Lines changed: 119 additions & 46 deletions
Large diffs are not rendered by default.

src/io/flutter/sdk/FlutterSdkUtil.java

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@
4040
import javax.swing.*;
4141
import java.io.File;
4242
import java.io.IOException;
43-
import java.util.Arrays;
44-
import java.util.HashSet;
45-
import java.util.LinkedHashSet;
46-
import java.util.Set;
43+
import java.net.URI;
44+
import java.net.URISyntaxException;
45+
import java.util.*;
4746

4847
public class FlutterSdkUtil {
4948
/**
@@ -260,40 +259,19 @@ public static void enableDartSdk(@NotNull final Project project) {
260259
@Nullable
261260
public static String guessFlutterSdkFromPackagesFile(@NotNull Module module) {
262261
// First, look for .dart_tool/package_config.json
263-
for (PubRoot pubRoot : PubRoots.forModule(module)) {
264-
final VirtualFile configFile = pubRoot.getPackageConfigFile();
265-
if (configFile == null) {
266-
continue;
267-
}
268-
// parse it
269-
try {
270-
final String contents = new String(configFile.contentsToByteArray(true /* cache contents */));
271-
final JsonElement element = new JsonParser().parse(contents);
272-
if (element == null) {
262+
final JsonArray packages = getPackagesFromPackageConfig(PubRoots.forModule(module));
263+
for (int i = 0; i < packages.size(); i++) {
264+
final JsonObject pack = packages.get(i).getAsJsonObject();
265+
if ("flutter".equals(JsonUtils.getStringMember(pack, "name"))) {
266+
final String uri = JsonUtils.getStringMember(pack, "rootUri");
267+
if (uri == null) {
273268
continue;
274269
}
275-
final JsonObject json = element.getAsJsonObject();
276-
if (JsonUtils.getIntMember(json, "configVersion") < 2) continue;
277-
final JsonArray packages = json.getAsJsonArray("packages");
278-
if (packages == null || packages.size() == 0) {
270+
final String path = extractSdkPathFromUri(uri, false);
271+
if (path == null) {
279272
continue;
280273
}
281-
for (int i = 0; i < packages.size(); i++) {
282-
final JsonObject pack = packages.get(i).getAsJsonObject();
283-
if ("flutter".equals(JsonUtils.getStringMember(pack, "name"))) {
284-
final String uri = JsonUtils.getStringMember(pack, "rootUri");
285-
if (uri == null) {
286-
continue;
287-
}
288-
final String path = extractSdkPathFromUri(uri, false);
289-
if (path == null) {
290-
continue;
291-
}
292-
return path;
293-
}
294-
}
295-
}
296-
catch (IOException ignored) {
274+
return path;
297275
}
298276
}
299277

@@ -315,6 +293,54 @@ public static String guessFlutterSdkFromPackagesFile(@NotNull Module module) {
315293
return null;
316294
}
317295

296+
@Nullable
297+
public static String getPathToCupertinoIconsPackage(@NotNull Project project) {
298+
final JsonArray packages = getPackagesFromPackageConfig(PubRoots.forProject(project));
299+
for (int i = 0; i < packages.size(); i++) {
300+
final JsonObject pack = packages.get(i).getAsJsonObject();
301+
if ("cupertino_icons".equals(JsonUtils.getStringMember(pack, "name"))) {
302+
final String uri = JsonUtils.getStringMember(pack, "rootUri");
303+
if (uri == null) {
304+
continue;
305+
}
306+
try {
307+
return new URI(uri).getPath();
308+
}
309+
catch (URISyntaxException ignored) {
310+
}
311+
}
312+
}
313+
return null;
314+
}
315+
316+
private static JsonArray getPackagesFromPackageConfig(@NotNull List<PubRoot> pubRoots) {
317+
final JsonArray entries = new JsonArray();
318+
for (PubRoot pubRoot : pubRoots) {
319+
final VirtualFile configFile = pubRoot.getPackageConfigFile();
320+
if (configFile == null) {
321+
continue;
322+
}
323+
// parse it
324+
try {
325+
final String contents = new String(configFile.contentsToByteArray(true /* cache contents */));
326+
final JsonElement element = new JsonParser().parse(contents);
327+
if (element == null) {
328+
continue;
329+
}
330+
final JsonObject json = element.getAsJsonObject();
331+
if (JsonUtils.getIntMember(json, "configVersion") < 2) continue;
332+
final JsonArray packages = json.getAsJsonArray("packages");
333+
if (packages == null || packages.size() == 0) {
334+
continue;
335+
}
336+
entries.addAll(packages);
337+
}
338+
catch (IOException ignored) {
339+
}
340+
}
341+
return entries;
342+
}
343+
318344
@VisibleForTesting
319345
public static String parseFlutterSdkPath(String packagesFileContent) {
320346
for (String line : packagesFileContent.split("\n")) {
277 KB
Binary file not shown.

0 commit comments

Comments
 (0)