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

Cleanup: introduce some static strings into PubRoot #7844

Merged
merged 1 commit into from
Dec 4, 2024
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
14 changes: 7 additions & 7 deletions flutter-idea/src/io/flutter/pub/PubRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
package io.flutter.pub;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project;
Expand All @@ -34,10 +33,11 @@
* That is, a directory containing (at a minimum) a pubspec.yaml file.
*/
public class PubRoot {
public static final String ANALYSIS_OPTIONS_YAML = "analysis_options.yaml";
public static final String DOT_DART_TOOL = ".dart_tool";
public static final String DOT_PACKAGES = ".packages";
public static final String PUBSPEC_YAML = "pubspec.yaml";

private static final Logger LOG = Logger.getInstance(PubRoot.class);

@NotNull
private final VirtualFile root;

Expand Down Expand Up @@ -176,7 +176,7 @@ public String getRelativePath(@NotNull VirtualFile file) {
return path.substring(root.length() + 1);
}

private static final String /*@NotNull*/ [] TEST_DIRS = new String[] { // TODO 2022.1
private static final String /*@NotNull*/[] TEST_DIRS = new String[]{ // TODO 2022.1
"/test/",
"/integration_test/",
"/test_driver/",
Expand Down Expand Up @@ -266,7 +266,7 @@ public boolean isNonEditableFlutterModule() {

@Nullable
public VirtualFile getPackageConfigFile() {
final VirtualFile tools = root.findChild(".dart_tool");
final VirtualFile tools = root.findChild(DOT_DART_TOOL);
if (tools == null || !tools.isDirectory()) {
return null;
}
Expand All @@ -280,7 +280,7 @@ public VirtualFile getPackageConfigFile() {
@Nullable
public VirtualFile getPackagesFile() {
// Obsolete by Flutter 2.0
final VirtualFile packages = root.findChild(".packages");
final VirtualFile packages = root.findChild(DOT_PACKAGES);
if (packages != null && !packages.isDirectory()) {
return packages;
}
Expand Down
4 changes: 2 additions & 2 deletions flutter-idea/src/io/flutter/run/MainFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ private static boolean isAppDir(@NotNull VirtualFile dir, @NotNull Project proje
assert(!WorkspaceCache.getInstance(project).isBazel());
return dir.isDirectory() && (
dir.findChild(PubRoot.PUBSPEC_YAML) != null ||
dir.findChild(".dart_tool") != null ||
dir.findChild(".packages") != null
dir.findChild(PubRoot.DOT_DART_TOOL) != null ||
dir.findChild(PubRoot.DOT_PACKAGES) != null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setUp() throws Exception {
final VirtualFile contentRoot = allContentRoots[0];
final VirtualFile pubspec = contentRoot.createChildData(this, PubRoot.PUBSPEC_YAML);
pubspec.setBinaryContent(SamplePubspec.getBytes(StandardCharsets.UTF_8));
final VirtualFile dartTool = contentRoot.createChildDirectory(this, ".dart_tool");
final VirtualFile dartTool = contentRoot.createChildDirectory(this, PubRoot.DOT_DART_TOOL);
final VirtualFile config = dartTool.createChildData(this, "package_config.json");
config.setBinaryContent(SampleConfig.getBytes(StandardCharsets.UTF_8));
}
Expand All @@ -58,15 +58,16 @@ public void tearDown() throws Exception {
final VirtualFile root = Objects.requireNonNull(ModuleRootManager.getInstance(getModule())).getContentRoots()[0];
assert root != null;
final VirtualFile pubspec = root.findChild(PubRoot.PUBSPEC_YAML);
final VirtualFile dartTool = root.findChild(".dart_tool");
final VirtualFile dartTool = root.findChild(PubRoot.DOT_DART_TOOL);
if (pubspec != null && dartTool != null) {
final VirtualFile config = dartTool.findChild("package_config.json");
WriteAction.run(() -> {
pubspec.delete(this);
if (config != null) config.delete(this);
dartTool.delete(this);
});
final List<String> toUnexclude = Arrays.asList(root.getUrl() + "/build", root.getUrl() + "/.pub", root.getUrl() + "/.dart_tool");
final List<String> toUnexclude =
Arrays.asList(root.getUrl() + "/build", root.getUrl() + "/.pub", root.getUrl() + "/" + PubRoot.DOT_DART_TOOL);
ModuleRootModificationUtil.updateExcludedFolders(getModule(), root, toUnexclude, Collections.emptyList());
}
}
Expand Down
Loading