Skip to content

Commit a88f92d

Browse files
committed
checkpoint
1 parent 8b3e997 commit a88f92d

File tree

76 files changed

+9089
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+9089
-2
lines changed

flutter-idea/testSrc

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2016 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.sdk;
7+
8+
import com.intellij.execution.ExecutionException;
9+
import com.jetbrains.lang.dart.sdk.DartSdk;
10+
import io.flutter.dart.DartPlugin;
11+
import io.flutter.testing.FlutterModuleFixture;
12+
import io.flutter.testing.ProjectFixture;
13+
import io.flutter.testing.Testing;
14+
import org.junit.Rule;
15+
import org.junit.Test;
16+
17+
import static org.junit.Assert.*;
18+
19+
public class FlutterSdkUtilTest {
20+
@Rule
21+
public ProjectFixture projectFixture = Testing.makeCodeInsightModule();
22+
23+
@Rule
24+
public FlutterModuleFixture flutterFixture = new FlutterModuleFixture(projectFixture);
25+
26+
@Test
27+
public void shouldInstallFlutterSDK() throws ExecutionException {
28+
// All of FlutterTestUtils is exercised before getting here.
29+
assertTrue("Test jig setup failed", true);
30+
31+
// Verify Flutter SDK is installed correctly.
32+
final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(projectFixture.getProject());
33+
assertNotNull(flutterSdk);
34+
final String path = System.getProperty("flutter.sdk");
35+
assertEquals("Incorrect Flutter SDK path", flutterSdk.getHomePath(), path);
36+
37+
// Verify Dart SDK is the one distributed with Flutter.
38+
final DartSdk dartSdk = DartPlugin.getDartSdk(projectFixture.getProject());
39+
assertNotNull(dartSdk);
40+
assertTrue("Dart SDK not found in Flutter SDK installation", dartSdk.getHomePath().startsWith(flutterSdk.getHomePath()));
41+
42+
// Check SDK utilities.
43+
final String toolPath = FlutterSdkUtil.pathToFlutterTool(flutterSdk.getHomePath());
44+
assertEquals("Incorrect path to flutter command", toolPath, path + "/bin/flutter");
45+
assertTrue(FlutterSdkUtil.isFlutterSdkHome(path));
46+
}
47+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2017 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.testing;
7+
8+
import com.intellij.openapi.Disposable;
9+
import com.intellij.openapi.module.Module;
10+
import com.jetbrains.lang.dart.util.DartTestUtils;
11+
import io.flutter.sdk.FlutterSdk;
12+
import org.junit.rules.ExternalResource;
13+
14+
/**
15+
* Provides a Flutter Module with the Flutter SDK configured.
16+
*
17+
* <p>Depends on a {@link ProjectFixture} already being installed.
18+
*/
19+
public class FlutterModuleFixture extends ExternalResource {
20+
private final ProjectFixture parent;
21+
private final Disposable testRoot = () -> {};
22+
private final boolean realSdk;
23+
24+
public FlutterModuleFixture(ProjectFixture parent) {
25+
this(parent, true);
26+
}
27+
28+
public FlutterModuleFixture(ProjectFixture parent, boolean realSdk) {
29+
this.parent = parent;
30+
this.realSdk = realSdk;
31+
}
32+
33+
@Override
34+
protected void before() throws Exception {
35+
Testing.runOnDispatchThread(() -> {
36+
FlutterTestUtils.configureFlutterSdk(parent.getModule(), testRoot, realSdk);
37+
if (realSdk) {
38+
final FlutterSdk sdk = FlutterSdk.getFlutterSdk(parent.getProject());
39+
assert (sdk != null);
40+
final String path = sdk.getHomePath();
41+
final String dartSdkPath = path + "/bin/cache/dart-sdk";
42+
System.setProperty("dart.sdk", dartSdkPath);
43+
}
44+
DartTestUtils.configureDartSdk(parent.getModule(), testRoot, realSdk);
45+
});
46+
}
47+
48+
@Override
49+
protected void after() {
50+
testRoot.dispose();
51+
}
52+
53+
public Module getModule() {
54+
return parent.getModule();
55+
}
56+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright 2017 The Chromium Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style license that can be
4+
* found in the LICENSE file.
5+
*/
6+
package io.flutter.testing;
7+
8+
import com.intellij.openapi.Disposable;
9+
import com.intellij.openapi.application.ApplicationManager;
10+
import com.intellij.openapi.application.PathManager;
11+
import com.intellij.openapi.module.Module;
12+
import com.intellij.openapi.roots.impl.libraries.ApplicationLibraryTable;
13+
import com.intellij.openapi.roots.libraries.Library;
14+
import com.intellij.openapi.util.Disposer;
15+
import com.intellij.openapi.util.io.FileUtil;
16+
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
17+
import com.intellij.util.PathUtil;
18+
import io.flutter.dart.DartPlugin;
19+
import io.flutter.sdk.FlutterSdk;
20+
import io.flutter.sdk.FlutterSdkUtil;
21+
import org.jetbrains.annotations.NotNull;
22+
import org.junit.Assert;
23+
24+
import java.io.File;
25+
import java.util.Collections;
26+
27+
public class FlutterTestUtils {
28+
public static final String BASE_TEST_DATA_PATH = findTestDataPath();
29+
public static final String SDK_HOME_PATH = BASE_TEST_DATA_PATH + "/sdk";
30+
31+
public static void configureFlutterSdk(@NotNull final Module module, @NotNull final Disposable disposable, final boolean realSdk) {
32+
final String sdkHome;
33+
if (realSdk) {
34+
sdkHome = System.getProperty("flutter.sdk");
35+
if (sdkHome == null) {
36+
Assert.fail("To run tests that use the flutter tools you need to add '-Dflutter.sdk=[real SDK home]' to the VM Options field of " +
37+
"the corresponding JUnit run configuration (Run | Edit Configurations)");
38+
}
39+
if (!FlutterSdkUtil.isFlutterSdkHome(sdkHome)) {
40+
Assert.fail("Incorrect path to the Flutter SDK (" + sdkHome + ") is set as '-Dflutter.sdk' VM option of " +
41+
"the corresponding JUnit run configuration (Run | Edit Configurations)");
42+
}
43+
VfsRootAccess.allowRootAccess(disposable, sdkHome);
44+
}
45+
else {
46+
sdkHome = SDK_HOME_PATH;
47+
}
48+
49+
ApplicationManager.getApplication().runWriteAction(() -> {
50+
FlutterSdkUtil.setFlutterSdkPath(module.getProject(), sdkHome);
51+
DartPlugin.enableDartSdk(module);
52+
});
53+
54+
Disposer.register(disposable, () -> ApplicationManager.getApplication().runWriteAction(() -> {
55+
if (!module.isDisposed()) {
56+
DartPlugin.disableDartSdk(Collections.singletonList(module));
57+
}
58+
59+
final ApplicationLibraryTable libraryTable = ApplicationLibraryTable.getApplicationTable();
60+
final Library library = libraryTable.getLibraryByName(FlutterSdk.FLUTTER_SDK_GLOBAL_LIB_NAME);
61+
if (library != null) {
62+
libraryTable.removeLibrary(library);
63+
}
64+
}));
65+
}
66+
67+
private static String findTestDataPath() {
68+
if (new File(PathManager.getHomePath() + "/contrib").isDirectory()) {
69+
// started from IntelliJ IDEA Ultimate project
70+
return FileUtil.toSystemIndependentName(PathManager.getHomePath() + "/contrib/flutter-intellij/testData");
71+
}
72+
73+
final File f = new File("testData");
74+
if (f.isDirectory()) {
75+
// started from flutter plugin project
76+
return FileUtil.toSystemIndependentName(f.getAbsolutePath());
77+
}
78+
79+
final String parentPath = PathUtil.getParentPath(PathManager.getHomePath());
80+
81+
if (new File(parentPath + "/intellij-plugins").isDirectory()) {
82+
// started from IntelliJ IDEA Community Edition + flutter plugin project
83+
return FileUtil.toSystemIndependentName(parentPath + "/intellij-plugins/flutter-intellij/testData");
84+
}
85+
86+
if (new File(parentPath + "/contrib").isDirectory()) {
87+
// started from IntelliJ IDEA Community + flutter plugin project
88+
return FileUtil.toSystemIndependentName(parentPath + "/contrib/flutter-intellij/testData");
89+
}
90+
91+
return "";
92+
}
93+
}

0 commit comments

Comments
 (0)