Search in sources :

Example 11 with ArtifactDependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.

the class BuildScriptModelTest method testParseDependencies.

public void testParseDependencies() throws IOException {
    String text = "buildscript {\n" + "  dependencies {\n" + "    classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)

Example 12 with ArtifactDependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.

the class BuildScriptModelTest method testEditDependency.

public void testEditDependency() throws IOException {
    String text = "buildscript {\n" + "  dependencies {\n" + "    classpath 'com.android.tools.build:gradle:2.0.0-alpha2'\n" + "  }\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    DependenciesModel dependenciesModel = buildModel.buildscript().dependencies();
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    ArtifactDependencyModel actual = dependencies.get(0);
    expected.assertMatches(actual);
    actual.setVersion("2.0.1");
    expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.1");
    expected.assertMatches(actual);
    assertTrue(buildModel.isModified());
    applyChanges(buildModel);
    assertFalse(buildModel.isModified());
    buildModel.reparse();
    dependencies = buildModel.buildscript().dependencies().artifacts();
    assertThat(dependencies).hasSize(1);
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)

Example 13 with ArtifactDependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project android by JetBrains.

the class BuildScriptModelTest method testAddDependency.

public void testAddDependency() throws IOException {
    String text = "";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    BuildScriptModel buildScriptModel = buildModel.buildscript();
    DependenciesModel dependenciesModel = buildScriptModel.dependencies();
    assertFalse(buildScriptModel.hasValidPsiElement());
    assertFalse(dependenciesModel.hasValidPsiElement());
    assertThat(dependenciesModel.artifacts()).isEmpty();
    dependenciesModel.addArtifact("classpath", "com.android.tools.build:gradle:2.0.0-alpha2");
    List<ArtifactDependencyModel> dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    ExpectedArtifactDependency expected = new ExpectedArtifactDependency("classpath", "gradle", "com.android.tools.build", "2.0.0-alpha2");
    expected.assertMatches(dependencies.get(0));
    assertTrue(buildModel.isModified());
    applyChanges(buildModel);
    assertFalse(buildModel.isModified());
    buildModel.reparse();
    buildScriptModel = buildModel.buildscript();
    dependenciesModel = buildScriptModel.dependencies();
    assertTrue(buildScriptModel.hasValidPsiElement());
    assertTrue(dependenciesModel.hasValidPsiElement());
    dependencies = dependenciesModel.artifacts();
    assertThat(dependencies).hasSize(1);
    expected.assertMatches(dependencies.get(0));
}
Also used : ExpectedArtifactDependency(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) DependenciesModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)

Example 14 with ArtifactDependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel in project freeline by alibaba.

the class FreelineUtil method installFreeline.

private static void installFreeline(final Project project, final FreelineStatus status, final PsiFile psiFile, final GradleDependencyEntity dependencyEntity) {
    needReformatCode = false;
    CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {

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

                @Override
                public void run() {
                    if (!status.isExistClasspath()) {
                        Collection<VirtualFile> collection = status.getGradleBuildFiles();
                        if (dependencyEntity != null) {
                            for (VirtualFile file : collection) {
                                GradleBuildModel model = GradleBuildModel.parseBuildFile(file, project);
                                List<ArtifactDependencyModel> artifactDependencyModels = model.buildscript().dependencies().artifacts();
                                for (ArtifactDependencyModel model1 : artifactDependencyModels) {
                                    ArtifactDependencyModelWrapper wrapper = new ArtifactDependencyModelWrapper(model1);
                                    if (wrapper.group().equals(Constant.ANDROID_GRADLE_TOOL_GROUP_NAME)) {
                                        ArtifactDependencySpec spec = new ArtifactDependencySpec(dependencyEntity.getArtifactId(), dependencyEntity.getGroupId(), dependencyEntity.getNewestReleaseVersion());
                                        model.buildscript().dependencies().addArtifact("classpath", spec);
                                        model.applyChanges();
                                        needReformatCode = true;
                                        status.setClasspathFile(file);
                                        break;
                                    }
                                }
                                if (status.isExistClasspath()) {
                                    break;
                                }
                            }
                        }
                    }
                    if (!status.isExistPlugin()) {
                        if (psiFile != null && psiFile instanceof GroovyFile) {
                            GradleUtil.applyPlugin(project, (GroovyFile) psiFile, Constant.FREELINE_PLUGIN_ID);
                        }
                    }
                }
            });
        }
    });
    if (needReformatCode && status.getClasspathFile() != null) {
        DocumentUtil.reformatCode(project, status.getClasspathFile());
    }
    LogUtil.d("Sync Project Finish, start download freeline.zip.");
    initFreeline(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) ArtifactDependencySpec(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)

Example 15 with ArtifactDependencyModel

use of com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel 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)

Aggregations

ArtifactDependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel)28 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)17 DependenciesModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependenciesModel)12 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)6 GradleVersion (com.android.ide.common.repository.GradleVersion)5 PsArtifactDependencySpec (com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec)5 File (java.io.File)5 ArtifactDependencySpec (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)4 PsParsedDependencies (com.android.tools.idea.gradle.structure.model.PsParsedDependencies)4 RepositoryUrlManager (com.android.tools.idea.templates.RepositoryUrlManager)4 Module (com.intellij.openapi.module.Module)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 GradleCoordinate (com.android.ide.common.repository.GradleCoordinate)3 ExpectedArtifactDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyTest.ExpectedArtifactDependency)3 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 Nullable (org.jetbrains.annotations.Nullable)3 DependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)2 PsProject (com.android.tools.idea.gradle.structure.model.PsProject)2