Skip to content

Commit

Permalink
add : install freeline automatic
Browse files Browse the repository at this point in the history
  • Loading branch information
pengwei1024 authored and aa5279aa committed Dec 7, 2016
1 parent 3b21b25 commit 54aeaeb
Show file tree
Hide file tree
Showing 33 changed files with 698 additions and 238 deletions.
6 changes: 5 additions & 1 deletion android-studio-plugin/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>com.apkfuns.plugin.freeline</id>
<name>Freeline Plugin</name>
<version>1.0.9.1</version>
<version>1.1.0</version>
<vendor email="" url="https://github.com/alibaba/freeline/tree/master/android-studio-plugin">act262、舞影凌风</vendor>

<description><![CDATA[
Expand All @@ -21,6 +21,10 @@

<change-notes><![CDATA[
<ul>
<li>
<b>1.1.0</b><br/>
add Automatic integration
</li>
<li>
<b>1.0.9</b><br/>
add default run action shortcut、support jdk 1.7+
Expand Down
23 changes: 2 additions & 21 deletions android-studio-plugin/src/actions/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import utils.NotificationUtils;
import utils.DocumentUtil;

import java.io.File;

Expand All @@ -21,33 +20,15 @@ public abstract class BaseAction extends AnAction {

@Override
public final void actionPerformed(AnActionEvent anActionEvent) {
saveDocument();
DocumentUtil.saveDocument();
this.anActionEvent = anActionEvent;
this.currentProject = DataKeys.PROJECT.getData(anActionEvent.getDataContext());
this.projectDir = new File(currentProject.getBasePath());
actionPerformed();
}

private void saveDocument() {
FileDocumentManager.getInstance().saveAllDocuments();
ApplicationManager.getApplication().saveSettings();
}

public abstract void actionPerformed();

/**
* 检查Freeline是否存在
*
* @return
*/
protected boolean checkFreelineExist() {
File pyFile = new File(projectDir, "freeline.py");
if (pyFile.exists()) {
return true;
}
NotificationUtils.errorNotification("please install Freeline first");
return false;
}

/**
* 异步执行
Expand Down
3 changes: 2 additions & 1 deletion android-studio-plugin/src/actions/FreelineRunAction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package actions;

import utils.FreelineUtil;
import utils.NotificationUtils;
import utils.Utils;
import views.FreelineTerminal;
Expand All @@ -10,7 +11,7 @@
public class FreelineRunAction extends BaseAction {
@Override
public void actionPerformed() {
if (checkFreelineExist()) {
if (FreelineUtil.checkInstall(currentProject)) {
String python = Utils.getPythonLocation();
if (python == null) {
NotificationUtils.errorNotification("command 'python' not found");
Expand Down
26 changes: 5 additions & 21 deletions android-studio-plugin/src/actions/UpdateAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,16 @@
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import models.ArtifactDependencyModelWrapper;
import models.GradleDependencyEntity;
import models.GetServerCallback;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.util.GradleConstants;
import utils.GradleUtil;
import utils.NotificationUtils;
import utils.StreamUtil;
import utils.Utils;
import utils.*;
import views.CheckUpdateDialog;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

/**
Expand All @@ -37,10 +28,9 @@ public class UpdateAction extends BaseAction implements GetServerCallback {

@Override
public void actionPerformed() {
if (checkFreelineExist()) {
FreelineUtil.hasInitFreeline(currentProject);
if (FreelineUtil.checkInstall(currentProject)) {
asyncTask(new GetServerVersion(this));
} else {
GradleUtil.executeTask(currentProject, "initFreeline", "-Pmirror", null);
}
}

Expand Down Expand Up @@ -160,8 +150,7 @@ public void onSuccess(final GradleDependencyEntity entity) {
invokeLater(new Runnable() {
@Override
public void run() {
Collection<VirtualFile> gradleFiles = FilenameIndex.getVirtualFilesByName(currentProject,
GradleConstants.DEFAULT_SCRIPT_NAME, GlobalSearchScope.allScope(currentProject));
Collection<VirtualFile> gradleFiles = GradleUtil.getAllGradleFile(currentProject);
Map<GradleBuildModel, List<ArtifactDependencyModel>> fileListMap = new HashMap<>();
for (VirtualFile file : gradleFiles) {
GradleBuildModel model = GradleBuildModel.parseBuildFile(file, currentProject);
Expand Down Expand Up @@ -198,12 +187,7 @@ public void run() {
return;
}
try {
URL url = new URL("http://jcenter.bintray.com/com/antfortune/freeline/gradle/maven-metadata.xml");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5 * 1000);
conn.setRequestMethod("GET");
InputStream inStream = conn.getInputStream();
String result = StreamUtil.inputStream2String(inStream);
String result = FreelineUtil.syncGetFreelineVersion();
if (result != null && result.trim().length() != 0) {
GradleDependencyEntity entity = GradleDependencyEntity.parse(result);
if (entity != null && Utils.notEmpty(entity.getVersion())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import utils.FreeUtil;
import utils.FreelineUtil;

/**
* Freeline Configuration Factory
Expand All @@ -27,7 +27,7 @@ public RunConfiguration createTemplateConfiguration(@NotNull Project project) {
@Override
public boolean isApplicable(@NotNull Project project) {
// enabled only had init project
return FreeUtil.hadInitFreeline(project);
return FreelineUtil.hadInitFreeline(project);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import utils.FreeUtil;
import utils.FreelineUtil;

/**
* Freeline run configuration implementation
Expand All @@ -34,7 +34,7 @@ public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (!FreeUtil.hadInitFreeline(getProject())) {
if (!FreelineUtil.hadInitFreeline(getProject())) {
throw new RuntimeConfigurationException("Not yet initialize freeline code", "Warning");
}
}
Expand All @@ -58,7 +58,7 @@ private class FreeRunState extends CommandLineState {
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
if (!FreeUtil.hadInitFreeline(getProject())) {
if (!FreelineUtil.hadInitFreeline(getProject())) {
throw new CantRunException("Not yet initialized freeline code");
}
// here just run one command: python freeline.py
Expand Down
6 changes: 5 additions & 1 deletion android-studio-plugin/src/icons/PluginIcons.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ public class PluginIcons {
public static final Icon ICON_TOOL_WINDOW = OpenTerminal;

private static Icon load(String path) {
return IconLoader.getIcon(path, PluginIcons.class);
try {
return IconLoader.getIcon(path, PluginIcons.class);
} catch (IllegalStateException e) {
return null;
}
}

private static Icon androidLoad(String path) {
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Created by pengwei on 16/9/14.
* 兼容android studio不同版本
* 2.1.2之前版本name()方法返回string, 之后返回GradleNullableValue
*/
public class ArtifactDependencyModelWrapper {

Expand Down
24 changes: 24 additions & 0 deletions android-studio-plugin/src/models/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package models;

/**
* Created by pengwei on 2016/10/22.
*/
public interface Constant {

boolean DEBUG_MODE = true;

// groupId
String FREELINE_CLASSPATH_GROUP = "com.antfortune.freeline";
// artifactId
String FREELINE_CLASSPATH_ARTIFACT = "gradle";
// plugin name
String FREELINE_PLUGIN_ID = "com.antfortune.freeline";

// root folder
String FREELINE_ROOT_FOLDER = "freeline";
String FREELINE_ROOT_FOLDER_CORE = "freeline_core";
String FREELINE_PYTHON = "freeline.py";

// gradle tool
String ANDROID_GRADLE_TOOL_GROUP_NAME = "com.android.tools.build";
}
82 changes: 82 additions & 0 deletions android-studio-plugin/src/models/FreelineStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package models;

import com.intellij.openapi.vfs.VirtualFile;
import utils.LogUtil;

import java.util.Collection;

/**
* Created by pengwei on 2016/10/31.
*/
public class FreelineStatus {
Collection<VirtualFile> gradleBuildFiles;
boolean existClasspath = false;
private VirtualFile classpathFile;
boolean existPlugin = false;
private VirtualFile pluginFile;
// mac下只有freeline文件夹 + freeline.py , win下有freeline.py + freeline/ + freeline_core/
boolean existFreelineCore = false;

public FreelineStatus setClasspathFile(VirtualFile classpathFile) {
this.classpathFile = classpathFile;
if (classpathFile != null) {
existClasspath = true;
}
return this;
}

public FreelineStatus setPluginFile(VirtualFile pluginFile) {
this.pluginFile = pluginFile;
if (pluginFile != null) {
existPlugin = true;
}
return this;
}

public FreelineStatus setExistFreelineCore(boolean existFreelineCore) {
this.existFreelineCore = existFreelineCore;
return this;
}

public boolean isExistClasspath() {
return existClasspath;
}

public VirtualFile getClasspathFile() {
return classpathFile;
}

public boolean isExistPlugin() {
return existPlugin;
}

public VirtualFile getPluginFile() {
return pluginFile;
}

public boolean isExistFreelineCore() {
return existFreelineCore;
}

/**
* 是否初始化Freeline
* 满足一下三个条件
* 1. 存在classpath 'com.antfortune.freeline:gradle:*'
* 2. 存在apply plugin: 'com.antfortune.freeline'
* 3. 存在freeline_core、release_tools、freeline.py
* @return
*/
public boolean hasInitFreeline() {
LogUtil.d("existClasspath=%s,existPlugin=%s,existFreelineCore=%s", existClasspath, existPlugin, existFreelineCore);
return existClasspath && existPlugin && existFreelineCore;
}

public Collection<VirtualFile> getGradleBuildFiles() {
return gradleBuildFiles;
}

public FreelineStatus setGradleBuildFiles(Collection<VirtualFile> gradleBuildFiles) {
this.gradleBuildFiles = gradleBuildFiles;
return this;
}
}
30 changes: 30 additions & 0 deletions android-studio-plugin/src/utils/DialogUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package utils;

import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.ui.Messages;

import javax.swing.*;

/**
* Created by pengwei on 2016/11/2.
*/
public final class DialogUtil {

/**
* 创建普通对话框
* @param message
* @param okText
* @param cancelText
* @return
*/
public static boolean createDialog(String message, String okText, String cancelText) {
DialogBuilder builder = new DialogBuilder();
builder.setTitle("Dialog Message");
builder.resizable(false);
builder.setCenterPanel(new JLabel(message, Messages.getInformationIcon(), SwingConstants.CENTER));
builder.addOkAction().setText(okText);
builder.addCancelAction().setText(cancelText);
builder.setButtonsAlignment(SwingConstants.CENTER);
return builder.show() == 0;
}
}
18 changes: 18 additions & 0 deletions android-studio-plugin/src/utils/DocumentUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package utils;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileEditor.FileDocumentManager;

/**
* Created by pengwei on 2016/11/1.
*/
public class DocumentUtil {

/**
* 保存文档和设置
*/
public static void saveDocument() {
FileDocumentManager.getInstance().saveAllDocuments();
ApplicationManager.getApplication().saveSettings();
}
}
Loading

0 comments on commit 54aeaeb

Please sign in to comment.