use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class OpenInAndroidStudioAction method findProjectFile.
// A plugin contains an example app, which needs to be opened when the native Android is to be edited.
// In the case of an app that contains a plugin the flutter_app/flutter_plugin/example/android should be opened when
// 'Open in Android Studio' is requested.
protected static VirtualFile findProjectFile(@Nullable AnActionEvent e) {
if (e != null) {
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (file != null && file.exists()) {
// We have a selection. Check if it is within a plugin.
final Project project = e.getProject();
assert (project != null);
final VirtualFile projectDir = project.getBaseDir();
for (PubRoot root : PubRoots.forProject(project)) {
if (root.isFlutterPlugin()) {
VirtualFile rootFile = root.getRoot();
VirtualFile aFile = file;
while (aFile != null) {
if (aFile.equals(rootFile)) {
// We know a plugin resource is selected. Find the example app for it.
for (VirtualFile child : rootFile.getChildren()) {
if (isExampleWithAndroidWithApp(child)) {
return child.findChild("android");
}
}
}
if (aFile.equals(projectDir)) {
aFile = null;
} else {
aFile = aFile.getParent();
}
}
}
}
if (isProjectFileName(file.getName())) {
return getProjectForFile(file);
}
// Return null if this is an ios folder.
if (FlutterExternalIdeActionGroup.isWithinIOsDirectory(file, project)) {
return null;
}
}
final Project project = e.getProject();
if (project != null) {
return getProjectForFile(findStudioProjectFile(project));
}
}
return null;
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class InspectorPanel method setActivate.
void setActivate(boolean enabled) {
if (!enabled) {
onIsolateStopped();
isActive = false;
return;
}
if (isActive) {
// Already activated.
return;
}
isActive = true;
assert (getInspectorService() != null);
getInspectorService().addClient(this);
final ArrayList<String> rootDirectories = new ArrayList<>();
for (PubRoot root : getFlutterApp().getPubRoots()) {
rootDirectories.add(root.getRoot().getCanonicalPath());
}
getInspectorService().setPubRootDirectories(rootDirectories);
getInspectorService().isWidgetTreeReady().thenAccept((Boolean ready) -> {
if (ready) {
recomputeTreeRoot();
}
});
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class TestFields method getSuggestedName.
/**
* Generates a name for these test settings, if they are valid.
*/
@NotNull
public String getSuggestedName(@NotNull Project project, @NotNull String defaultName) {
switch(getScope()) {
case NAME:
final String name = getTestName();
if (name == null)
return defaultName;
return name;
case FILE:
final VirtualFile file = getFileOrDir();
if (file == null)
return defaultName;
return "tests in " + file.getName();
case DIRECTORY:
final String relativePath = getRelativePath(project);
if (relativePath != null)
return "tests in " + relativePath;
// check if it's the pub root itself.
final PubRoot root = getPubRoot(project);
if (root != null && root.getRoot().equals(getFileOrDir())) {
return "all tests in " + root.getRoot().getName();
}
}
return defaultName;
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class TestFields method run.
/**
* Starts running the tests.
*/
ProcessHandler run(@NotNull Project project, @NotNull RunMode mode) throws ExecutionException {
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
if (sdk == null) {
throw new ExecutionException("The Flutter SDK is not configured");
}
final VirtualFile fileOrDir = getFileOrDir();
if (fileOrDir == null) {
throw new ExecutionException("File or directory not found");
}
final String testName = getTestName();
final PubRoot root = getPubRoot(project);
if (root == null) {
throw new ExecutionException("Test file isn't within a Flutter pub root");
}
return sdk.flutterTest(root, fileOrDir, testName, mode).startProcess(project);
}
use of io.flutter.pub.PubRoot in project flutter-intellij by flutter.
the class TestLaunchState method create.
static TestLaunchState create(@NotNull ExecutionEnvironment env, @NotNull TestConfig config) throws ExecutionException {
final TestFields fields = config.getFields();
try {
fields.checkRunnable(env.getProject());
} catch (RuntimeConfigurationError e) {
throw new ExecutionException(e);
}
final VirtualFile fileOrDir = fields.getFileOrDir();
assert (fileOrDir != null);
final PubRoot pubRoot = fields.getPubRoot(env.getProject());
assert (pubRoot != null);
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(env.getProject());
assert (sdk != null);
final boolean testConsoleEnabled = sdk.getVersion().flutterTestSupportsMachineMode();
final TestLaunchState launcher = new TestLaunchState(env, config, fileOrDir, pubRoot, testConsoleEnabled);
DaemonConsoleView.install(launcher, env, pubRoot.getRoot());
return launcher;
}
Aggregations