Search in sources :

Example 26 with ArtifactDependencyModel

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

the class DependencySetupTest method WithUnresolvedDependencies.

// Fails in Bazel PSQ because of missing dependencies in the prebuilt Android SDK.
public void WithUnresolvedDependencies() throws Exception {
    loadSimpleApplication();
    File buildFilePath = getBuildFilePath("app");
    VirtualFile buildFile = findFileByIoFile(buildFilePath, true);
    assertNotNull(buildFile);
    boolean versionChanged = false;
    Project project = getProject();
    GradleBuildModel buildModel = GradleBuildModel.parseBuildFile(buildFile, project);
    for (ArtifactDependencyModel artifact : buildModel.dependencies().artifacts()) {
        if ("com.android.support".equals(artifact.group().value()) && "appcompat-v7".equals(artifact.name().value())) {
            artifact.setVersion("100.0.0");
            versionChanged = true;
            break;
        }
    }
    assertTrue(versionChanged);
    runWriteCommandAction(project, buildModel::applyChanges);
    LocalFileSystem.getInstance().refresh(false);
    SyncMessagesStub syncMessages = SyncMessagesStub.replaceSyncMessagesService(project);
    requestSyncAndWait();
    SyncMessage reportedMessage = syncMessages.getFirstReportedMessage();
    assertNotNull(reportedMessage);
    String[] text = reportedMessage.getText();
    assertThat(text).isNotEmpty();
    assertEquals("Failed to resolve: com.android.support:appcompat-v7:100.0.0", text[0]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SyncMessage(com.android.tools.idea.gradle.project.sync.messages.SyncMessage) Project(com.intellij.openapi.project.Project) GradleUtil.getAndroidProject(com.android.tools.idea.gradle.util.GradleUtil.getAndroidProject) SyncMessagesStub(com.android.tools.idea.gradle.project.sync.messages.SyncMessagesStub) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File)

Example 27 with ArtifactDependencyModel

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

the class FreelineUtil method getFreelineStatus.

/**
 * 获取freeline安装状态
 *
 * @param project
 * @return
 */
public static FreelineStatus getFreelineStatus(@NotNull Project project) {
    FreelineStatus status = new FreelineStatus();
    Collection<VirtualFile> gradleFiles = GradleUtil.getAllGradleFile(project);
    status.setGradleBuildFiles(gradleFiles);
    for (VirtualFile file : gradleFiles) {
        if (!status.isExistClasspath()) {
            GradleBuildModel model = GradleBuildModel.parseBuildFile(file, project);
            if (model != null) {
                List<ArtifactDependencyModel> classPaths = model.buildscript().dependencies().artifacts();
                for (ArtifactDependencyModel classpath : classPaths) {
                    ArtifactDependencyModelWrapper wrapper = new ArtifactDependencyModelWrapper(classpath);
                    if (wrapper.group().equals(Constant.FREELINE_CLASSPATH_GROUP) && wrapper.name().equals(Constant.FREELINE_CLASSPATH_ARTIFACT)) {
                        status.setClasspathFile(file);
                        break;
                    }
                }
            }
        }
        // 正则二次判断是否存在Freeline classpath
        if (!status.isExistClasspath() && regularExistFreelineClassPath(file)) {
            status.setClasspathFile(file);
        }
        if (!status.isExistPlugin()) {
            GradleBuildFile gradleBuildFile = new GradleBuildFile(file, project);
            if (gradleBuildFile != null) {
                List<String> plugins = gradleBuildFile.getPlugins();
                if (plugins.contains(Constant.FREELINE_PLUGIN_ID)) {
                    status.setPluginFile(file);
                }
            }
        }
        if (status.isExistClasspath() && status.isExistPlugin()) {
            break;
        }
    }
    File baseFile = new File(project.getBasePath());
    if (new File(baseFile, Constant.FREELINE_ROOT_FOLDER).exists() && new File(baseFile, Constant.FREELINE_PYTHON).exists()) {
        if (SystemInfo.isWindows) {
            if (new File(baseFile, Constant.FREELINE_ROOT_FOLDER_CORE).exists()) {
                status.setExistFreelineCore(true);
            }
        } else {
            status.setExistFreelineCore(true);
        }
    }
    return status;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) ArtifactDependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencyModel) GradleBuildFile(com.android.tools.idea.gradle.parser.GradleBuildFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) File(java.io.File)

Example 28 with ArtifactDependencyModel

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

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