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

Fix analysis.setContextRoots failed when DAS launched from Android Studio #304

Merged
merged 6 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ dependency_overrides:
path: ../../../custom_lint_builder
custom_lint_core:
path: ../../../custom_lint_core
custom_lint_visitor:
path: ../../../custom_lint_visitor
2 changes: 2 additions & 0 deletions packages/custom_lint/example/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ dependency_overrides:
path: ../../custom_lint_core
custom_lint_example_lint:
path: example_lint
custom_lint_visitor:
path: ../../custom_lint_visitor
33 changes: 33 additions & 0 deletions packages/custom_lint/example_plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
build/
33 changes: 33 additions & 0 deletions packages/custom_lint/example_plugin/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "17025dd88227cd9532c33fa78f5250d548d87e9a"
channel: "stable"

project_type: plugin

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
- platform: macos
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
- platform: web
create_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a
base_revision: 17025dd88227cd9532c33fa78f5250d548d87e9a

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
3 changes: 3 additions & 0 deletions packages/custom_lint/example_plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1
EricSchlichting marked this conversation as resolved.
Show resolved Hide resolved

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions packages/custom_lint/example_plugin/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
15 changes: 15 additions & 0 deletions packages/custom_lint/example_plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# example_plugin

A new Flutter plugin project.

## Getting Started

This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/to/develop-plugins),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev), which offers tutorials,
samples, guidance on mobile development, and a full API reference.

11 changes: 11 additions & 0 deletions packages/custom_lint/example_plugin/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include: ../../../analysis_options.yaml

analyzer:
plugins:
- custom_lint

linter:
rules:
public_member_api_docs: false
avoid_print: false
unreachable_from_main: false
21 changes: 21 additions & 0 deletions packages/custom_lint/example_plugin/lib/example_plugin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

import 'package:flutter/widgets.dart';
import 'package:riverpod/riverpod.dart';

import 'example_plugin_platform_interface.dart';

class ExamplePlugin {
Future<String?> getPlatformVersion() {
return ExamplePluginPlatform.instance.getPlatformVersion();
}

Future<Widget?> getWidget() {
return ExamplePluginPlatform.instance.getWidget();
}
}

// expect_lint: riverpod_final_provider
ProviderBase<int> provider = Provider((ref) => 0);

// expect_lint: riverpod_final_provider
Provider<int> provider2 = Provider((ref) => 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';

import 'example_plugin_platform_interface.dart';

/// An implementation of [ExamplePluginPlatform] that uses method channels.
class MethodChannelExamplePlugin extends ExamplePluginPlatform {
/// The method channel used to interact with the native platform.
@visibleForTesting
final methodChannel = const MethodChannel('example_plugin');

@override
Future<String?> getPlatformVersion() async {
final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
return version;
}

@override
Future<Widget> getWidget() async {
final widgetToCreate = await methodChannel.invokeMethod<String>('getWidget');
return widgetToCreate == 'SizedBox' ? const SizedBox.shrink() : Container();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/widgets.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

import 'example_plugin_method_channel.dart';

abstract class ExamplePluginPlatform extends PlatformInterface {
/// Constructs a ExamplePluginPlatform.
ExamplePluginPlatform() : super(token: _token);

static final Object _token = Object();

static ExamplePluginPlatform _instance = MethodChannelExamplePlugin();

/// The default instance of [ExamplePluginPlatform] to use.
///
/// Defaults to [MethodChannelExamplePlugin].
static ExamplePluginPlatform get instance => _instance;

/// Platform-specific implementations should set this with their own
/// platform-specific class that extends [ExamplePluginPlatform] when
/// they register themselves.
static set instance(ExamplePluginPlatform instance) {
PlatformInterface.verifyToken(instance, _token);
_instance = instance;
}

Future<String?> getPlatformVersion() {
throw UnimplementedError('platformVersion() has not been implemented.');
}

Future<Widget?> getWidget() {
throw UnimplementedError('getWidget() has not been implemented.');
}
}
32 changes: 32 additions & 0 deletions packages/custom_lint/example_plugin/lib/example_plugin_web.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// In order to *not* need this ignore, consider extracting the "web" version
// of your plugin as a separate package, instead of inlining it in the same
// package as the core of your plugin.
// ignore: avoid_web_libraries_in_flutter

import 'package:flutter/cupertino.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
import 'package:web/web.dart' as web;

import 'example_plugin_platform_interface.dart';

/// A web implementation of the ExamplePluginPlatform of the ExamplePlugin plugin.
class ExamplePluginWeb extends ExamplePluginPlatform {
/// Constructs a ExamplePluginWeb
ExamplePluginWeb();

static void registerWith(Registrar registrar) {
ExamplePluginPlatform.instance = ExamplePluginWeb();
}

/// Returns a [String] containing the version of the platform.
@override
Future<String?> getPlatformVersion() async {
final version = web.window.navigator.userAgent;
return version;
}

@override
Future<Widget?> getWidget() {
return Future.value(const SizedBox.shrink());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Cocoa
import FlutterMacOS

public class ExamplePlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "example_plugin", binaryMessenger: registrar.messenger)
let instance = ExamplePlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "getPlatformVersion":
result("macOS " + ProcessInfo.processInfo.operatingSystemVersionString)
case "getWidget":
result("Container");
default:
result(FlutterMethodNotImplemented)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTrackingDomains</key>
<array/>
<key>NSPrivacyCollectedDataTypes</key>
<array/>
<key>NSPrivacyTracking</key>
<false/>
</dict>
</plist>
30 changes: 30 additions & 0 deletions packages/custom_lint/example_plugin/macos/example_plugin.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint example_plugin.podspec` to validate before publishing.
#
Pod::Spec.new do |s|
s.name = 'example_plugin'
s.version = '0.0.1'
s.summary = 'A new Flutter plugin project.'
s.description = <<-DESC
A new Flutter plugin project.
DESC
s.homepage = 'http://example.com'
s.license = { :file => '../LICENSE' }
s.author = { 'Your Company' => '[email protected]' }

s.source = { :path => '.' }
s.source_files = 'Classes/**/*'

# If your plugin requires a privacy manifest, for example if it collects user
# data, update the PrivacyInfo.xcprivacy file to describe your plugin's
# privacy impact, and then uncomment this line. For more information,
# see https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
# s.resource_bundles = {'example_plugin_privacy' => ['Resources/PrivacyInfo.xcprivacy']}

s.dependency 'FlutterMacOS'

s.platform = :osx, '10.11'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
end
31 changes: 31 additions & 0 deletions packages/custom_lint/example_plugin/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: custom_lint_example_plugin
version: 0.0.1

environment:
sdk: ^3.6.0
flutter: '>=3.3.0'

dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter
plugin_platform_interface: ^2.0.2
riverpod: ^2.0.0
web: ^0.5.1

dev_dependencies:
custom_lint:
custom_lint_example_lint:
path: ../example/example_lint
flutter_test:
sdk: flutter

flutter:
plugin:
platforms:
macos:
pluginClass: ExamplePlugin
web:
pluginClass: ExamplePluginWeb
fileName: example_plugin_web.dart
8 changes: 8 additions & 0 deletions packages/custom_lint/example_plugin/pubspec_overrides.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# melos_managed_dependency_overrides: custom_lint,custom_lint_core,custom_lint_visitor
dependency_overrides:
custom_lint:
path: ..
custom_lint_core:
path: ../../custom_lint_core
custom_lint_visitor:
path: ../../custom_lint_visitor
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:custom_lint_example_plugin/example_plugin_method_channel.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

final platform = MethodChannelExamplePlugin();
const channel = MethodChannel('example_plugin');

setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
channel,
(methodCall) async {
return '42';
},
);
});

tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
});

test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}
33 changes: 33 additions & 0 deletions packages/custom_lint/example_plugin/test/example_plugin_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:custom_lint_example_plugin/example_plugin.dart';
import 'package:custom_lint_example_plugin/example_plugin_method_channel.dart';
import 'package:custom_lint_example_plugin/example_plugin_platform_interface.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';

class MockExamplePluginPlatform
with MockPlatformInterfaceMixin
implements ExamplePluginPlatform {

@override
Future<String?> getPlatformVersion() => Future.value('42');

@override
Future<Widget?> getWidget() => Future.value(const SizedBox.shrink());
}

void main() {
final initialPlatform = ExamplePluginPlatform.instance;

test('$MethodChannelExamplePlugin is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelExamplePlugin>());
});

test('getPlatformVersion', () async {
final examplePlugin = ExamplePlugin();
final fakePlatform = MockExamplePluginPlatform();
ExamplePluginPlatform.instance = fakePlatform;

expect(await examplePlugin.getPlatformVersion(), '42');
});
}
Loading