Search in sources :

Example 1 with ArtifactDependencyModelWrapper

use of com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper in project freeline by alibaba.

the class UpdateAction method resultHandle.

/**
 * 处理结果
 *
 * @param entity
 * @param gradleBuildModels
 */
private void resultHandle(final GradleDependencyEntity entity, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
    String localVersion = null;
    StringBuilder builder = new StringBuilder();
    for (GradleBuildModel file : gradleBuildModels.keySet()) {
        List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
        for (ArtifactDependencyModel dependencyModel1 : models) {
            ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
            if (isClasspathLibrary(dependencyModel) || isDependencyLibrary(dependencyModel)) {
                if (isClasspathLibrary(dependencyModel)) {
                    localVersion = dependencyModel.version();
                }
                builder.append(dependencyModel.configurationName()).append(" '").append(dependencyModel.group()).append(":").append(dependencyModel.name()).append(":").append(dependencyModel.version()).append("'").append("<br/>");
            }
        }
    }
    if (Utils.notEmpty(localVersion)) {
        int compare = localVersion.compareTo(entity.getVersion());
        final CheckUpdateDialog dialog = new CheckUpdateDialog();
        dialog.getButtonOK().setEnabled(compare < 0);
        dialog.setServerVersion(entity.getGroupId(), entity.getArtifactId(), entity.getVersion());
        dialog.setServerUpdateTime(entity.getUpdateTime());
        dialog.setLocalVersion(builder.toString());
        dialog.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                updateAction(entity.getVersion(), gradleBuildModels);
                dialog.dispose();
            }
        });
        dialog.showDialog();
    } else {
        NotificationUtils.infoNotification("please add freeline dependency first");
    }
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) CheckUpdateDialog(com.antfortune.freeline.idea.views.CheckUpdateDialog) ArtifactDependencyModelWrapper(com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper)

Example 2 with ArtifactDependencyModelWrapper

use of com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper in project freeline by alibaba.

the class UpdateAction method updateAction.

/**
 * 更新操作
 *
 * @param newVersion
 * @param gradleBuildModels
 */
protected void updateAction(final String newVersion, final Map<GradleBuildModel, List<ArtifactDependencyModel>> gradleBuildModels) {
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    for (GradleBuildModel file : gradleBuildModels.keySet()) {
                        List<ArtifactDependencyModel> models = gradleBuildModels.get(file);
                        for (ArtifactDependencyModel dependencyModel1 : models) {
                            ArtifactDependencyModelWrapper dependencyModel = new ArtifactDependencyModelWrapper(dependencyModel1);
                            if (isClasspathLibrary(dependencyModel)) {
                                dependencyModel1.setVersion(newVersion);
                            }
                            if (isDependencyLibrary(dependencyModel)) {
                                file.dependencies().remove(dependencyModel1);
                            }
                        }
                        file.applyChanges();
                    }
                    GradleUtil.executeTask(currentProject, "initFreeline", "-Pmirror", new ExternalSystemTaskNotificationListenerAdapter() {

                        @Override
                        public void onTaskOutput(@NotNull ExternalSystemTaskId id, @NotNull String text, boolean stdOut) {
                            super.onTaskOutput(id, text, stdOut);
                        }
                    });
                }
            });
        }
    });
}
Also used : ExternalSystemTaskId(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) ExternalSystemTaskNotificationListenerAdapter(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter) ArtifactDependencyModelWrapper(com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper)

Aggregations

GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)2 ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)2 ArtifactDependencyModelWrapper (com.antfortune.freeline.idea.models.ArtifactDependencyModelWrapper)2 CheckUpdateDialog (com.antfortune.freeline.idea.views.CheckUpdateDialog)1 ExternalSystemTaskId (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskId)1 ExternalSystemTaskNotificationListenerAdapter (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListenerAdapter)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1