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

Define proto module system #1819

Merged
merged 4 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions flutter-intellij-community.iml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@
</library>
</orderEntry>
<orderEntry type="library" name="snakeyaml" level="project" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
5 changes: 4 additions & 1 deletion flutter-studio/flutter-studio.iml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
<orderEntry type="module" module-name="gradle" scope="TEST" />
<orderEntry type="library" scope="TEST" name="truth" level="project" />
<orderEntry type="module" module-name="flutter-intellij-community" />
<orderEntry type="module" module-name="project-system" />
<orderEntry type="module" module-name="project-system-gradle" />
<orderEntry type="module" module-name="android-ndk" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious - these were added automatically by IntelliJ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. They are all required by new code.

</component>
</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void run() {
ApplicationInfo info = ApplicationInfo.getInstance();
if ("Google".equals(info.getCompanyName())) {
String version = info.getFullVersion();
if (version.startsWith("2.") || (version.contains("Beta") && !version.endsWith("7"))) {
if (version.startsWith("2.")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This likely address #1824 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I updated the intro to make that clear.

reportVersionIncompatibility(info);
}
else if (version.contains("Canary")) {
Expand Down
73 changes: 73 additions & 0 deletions flutter-studio/src/io/flutter/project/FlutterProjectSystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2018 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
package io.flutter.project;

import com.android.tools.idea.projectsystem.AndroidModuleSystem;
import com.android.tools.idea.projectsystem.AndroidProjectSystem;
import com.android.tools.idea.projectsystem.ProjectSystemSyncManager;
import com.android.tools.idea.projectsystem.gradle.GradleProjectSystem;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.nio.file.Path;

public class FlutterProjectSystem implements AndroidProjectSystem {
@NotNull final private GradleProjectSystem gradleProjectSystem;

public FlutterProjectSystem(Project project) {
gradleProjectSystem = new GradleProjectSystem(project);
}

@Nullable
@Override
public VirtualFile getDefaultApkFile() {
return gradleProjectSystem.getDefaultApkFile(); // TODO find the flutter binary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this todo:? If so, can you provide more context (for whoever comes through here net)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

}

@NotNull
@Override
public Path getPathToAapt() {
return gradleProjectSystem.getPathToAapt();
}

@Override
public void buildProject() {
// flutter build ?
}

@Override
public boolean allowsFileCreation() {
return true; // Enable File>New>New Module
}

@NotNull
@Override
public AndroidModuleSystem getModuleSystem(@NotNull Module module) {
return gradleProjectSystem.getModuleSystem(module);
}

@Override
public boolean upgradeProjectToSupportInstantRun() {
return false; // Already done.
}

@NotNull
@Override
public String mergeBuildFiles(@NotNull String dependencies,
@NotNull String destinationContents,
@Nullable String supportLibVersionFilter) {
return gradleProjectSystem.mergeBuildFiles(dependencies, destinationContents, supportLibVersionFilter);
}

@NotNull
@Override
public ProjectSystemSyncManager getSyncManager() {
return gradleProjectSystem.getSyncManager();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@
*/
package io.flutter.project;

//import com.android.tools.idea.projectsystem.*;
//import com.android.tools.idea.projectsystem.gradle.GradleProjectSystem;

import com.android.tools.idea.projectsystem.AndroidProjectSystem;
import com.android.tools.idea.projectsystem.AndroidProjectSystemProvider;
import com.intellij.openapi.project.Project;
import io.flutter.utils.FlutterModuleUtils;
import org.jetbrains.annotations.NotNull;

// This is needed in 3.1 builds but not 3.0.
public class FlutterProjectSystemProvider /*implements AndroidProjectSystemProvider*/ {
public class FlutterProjectSystemProvider implements AndroidProjectSystemProvider {
final private Project myProject;

public FlutterProjectSystemProvider(Project project) {
myProject = project;
}

//@Override
@Override
public boolean isApplicable() {
return FlutterModuleUtils.hasFlutterModule(myProject);
}

@NotNull
//@Override
@Override
public String getId() {
return "flutter-project";
}

//@NotNull
//@Override
//public AndroidProjectSystem getProjectSystem() {
// return new GradleProjectSystem(myProject);
//}
@NotNull
@Override
public AndroidProjectSystem getProjectSystem() {
return new FlutterProjectSystem(myProject);
}
}
6 changes: 5 additions & 1 deletion product-matrix.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"ideaVersion": "171.4408382",
"dartPluginVersion": "171.4424.10",
"sinceBuild": "171.1",
"untilBuild": "171.*"
"untilBuild": "171.*",
"filesToSkip": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"flutter-studio/src/io/flutter/project/FlutterProjectSystemProvider.java",
"flutter-studio/src/io/flutter/project/FlutterProjectSystem.java"
]
},
{
"name": "Android Studio",
Expand Down
2 changes: 1 addition & 1 deletion resources/META-INF/studio-contribs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</extensions>

<extensions defaultExtensionNs="com.android.project">
<!-- projectsystem implementation="io.flutter.project.FlutterProjectSystemProvider"/ -->
<projectsystem implementation="io.flutter.project.FlutterProjectSystemProvider"/>
</extensions>

<extensions defaultExtensionNs="com.intellij">
Expand Down
38 changes: 38 additions & 0 deletions resources/META-INF/studio-contribs.xml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!-- Defines Android Studio IDE-specific contributions and implementations. -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to look into a system to generate plugin.xml and studio-contribs.xml from the templates and remove the others from source control. Or, have a task on travis fail if changes are made to one file but not to the the other (template and non-template), else they risk getting out of sync.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this sounds good, lets open an issue to track.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to get into the habit of using plugin gen.

Adding a fail-safe check to travis sounds good, too. See #1842.

<idea-plugin>

<extensions defaultExtensionNs="com.android">
<!-- Add Flutter module types to the New Module wizard -->
<moduleDescriptionProvider implementation="io.flutter.module.FlutterDescriptionProvider"/>
</extensions>

<extensions defaultExtensionNs="com.android.project">
@PROJECTSYSTEM@
</extensions>

<extensions defaultExtensionNs="com.intellij">
<!-- TODO(messick): Remove this extension if the class is never needed. -->
<androidStudioInitializer implementation="io.flutter.FlutterStudioInitializer"/>
</extensions>

<actions>

<!-- Define the 'New Flutter Project' menu item -->
<action id="flutter.NewProject" class="io.flutter.actions.FlutterNewProjectAction"
text="New Flutter Project..."
description="Create a new Flutter project">
<add-to-group group-id="NewProjectOrModuleGroup" anchor="after" relative-to-action="NewProject"/>
</action>

<!-- The icon isn't being used here, but the same syntax works for menu items -->
<!-- We can't change it in a StartupActivity because those don't run until a project is opened -->
<action id="flutter.NewProject.welcome" class="io.flutter.actions.FlutterNewProjectAction"
text="Start a new Flutter project"
icon="FlutterIcons.Flutter"
description="Create a new Flutter project">
<add-to-group group-id="WelcomeScreen.QuickStart.IDEA" anchor="after" relative-to-action="WelcomeScreen.CreateNewProject"/>
</action>

</actions>

</idea-plugin>
40 changes: 31 additions & 9 deletions tool/plugin/lib/plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,20 @@ List<String> findJavaFiles(String path) {
.toList();
}

Future<File> genPluginXml(BuildSpec spec, String destDir) async {
var file = await new File(p.join(rootPath, destDir, 'META-INF/plugin.xml'))
.create(recursive: true);
var dest = file.openWrite();
Future<bool> genPluginFiles(BuildSpec spec, String destDir) async {
//TODO(devoncarew): Move the change log to a separate file and insert it here.
await new File(p.join(rootPath, 'resources/META-INF/plugin.xml.template'))
var result = await genPluginXml(spec, destDir, 'META-INF/plugin.xml');
if (result == null) return false;
result = await genPluginXml(spec, destDir, 'META-INF/studio-contribs.xml');
if (result == null) return false;
return true;
}

Future<File> genPluginXml(BuildSpec spec, String destDir, String path) async {
var file =
await new File(p.join(rootPath, destDir, path)).create(recursive: true);
var dest = file.openWrite();
await new File(p.join(rootPath, 'resources', '$path.template'))
.openRead()
.transform(UTF8.decoder)
.transform(new LineSplitter())
Expand Down Expand Up @@ -291,6 +299,11 @@ String substitueTemplateVariables(String line, BuildSpec spec) {
return spec.isSynthetic
? 'com.intellij.modules.androidstudio'
: 'com.android.tools.apk';
case 'PROJECTSYSTEM':
// Temporary work-around for 3.0 vs 3.1 AS incompatibility.
return spec.version == '3.1'
? '<projectsystem implementation="io.flutter.project.FlutterProjectSystemProvider"/>'
: '';
default:
throw 'unknown template variable: $name';
}
Expand Down Expand Up @@ -523,7 +536,13 @@ class BuildCommand extends ProductCommand {

separator('Building flutter-intellij.jar');
await removeAll('build');
for (var file in spec.filesToSkip) {
await new File(file).rename('$file~');
}
result = await runner.javac2(spec);
for (var file in spec.filesToSkip) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block may want to be in a finally block, so that it's performed even if there are exceptions out of the compile stage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

await new File('$file~').rename(file);
}
if (result != 0) {
return new Future(() => result);
}
Expand All @@ -534,7 +553,7 @@ class BuildCommand extends ProductCommand {
copyResources(from: 'gen', to: 'build/classes');
copyResources(
from: 'third_party/intellij-plugins-dart/src', to: 'build/classes');
await genPluginXml(spec, 'build/classes');
await genPluginFiles(spec, 'build/classes');

// create the jars
createDir('build/flutter-intellij/lib');
Expand Down Expand Up @@ -625,7 +644,8 @@ compile
return await exec('ant', args.split(new RegExp(r'\s')));
} on ProcessException catch (x) {
if (x.message == 'No such file or directory') {
log('\nThe build command requires ant to be installed. '
log(
'\nThe build command requires ant to be installed. '
'\nPlease ensure ant is on your \$PATH.',
indent: false);
exit(x.errorCode);
Expand All @@ -649,6 +669,7 @@ class BuildSpec {
final String untilBuild;
final String pluginId = 'io.flutter';
final String release;
final List<String> filesToSkip;

ArtifactManager artifacts = new ArtifactManager();

Expand All @@ -663,7 +684,8 @@ class BuildSpec {
ideaVersion = json['ideaVersion'],
dartPluginVersion = json['dartPluginVersion'],
sinceBuild = json['sinceBuild'],
untilBuild = json['untilBuild'] {
untilBuild = json['untilBuild'],
filesToSkip = json['filesToSkip'] ?? [] {
createArtifacts();
}

Expand Down Expand Up @@ -795,7 +817,7 @@ class GenCommand extends ProductCommand {
var spec = new SyntheticBuildSpec.fromJson(json.first, release, json.last);
log('writing pluginl.xml');
var value = 1;
var result = await genPluginXml(spec, 'resources');
var result = await genPluginFiles(spec, 'resources');
if (result != null) {
log('writing .travis.yml');
genTravisYml(specs);
Expand Down
2 changes: 1 addition & 1 deletion tool/plugin/test/plugin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void main() {
});
var spec = cmd.specs[0];
await removeAll('../../build/classes');
await genPluginXml(spec, 'build/classes');
await genPluginFiles(spec, 'build/classes');
var file = new File("../../build/classes/META-INF/plugin.xml");
expect(file.existsSync(), isTrue);
var content = file.readAsStringSync();
Expand Down