Search in sources :

Example 1 with AndroidGradleNotification

use of com.android.tools.idea.gradle.project.AndroidGradleNotification in project android by JetBrains.

the class GoToApkLocationTask method execute.

@Override
public void execute(@NotNull GradleInvocationResult result) {
    try {
        File apkPath = getExistingApkPath();
        AndroidGradleNotification notification = AndroidGradleNotification.getInstance(myProject);
        if (result.isBuildSuccessful()) {
            if (ShowFilePathAction.isSupported()) {
                notification.showBalloon(myNotificationTitle, "APK(s) generated successfully.", INFORMATION, new GoToPathHyperlink(apkPath));
            } else {
                String msg = String.format("APK(s) location is\n%1$s.", apkPath.getPath());
                notification.showBalloon(myNotificationTitle, msg, INFORMATION);
            }
        } else {
            String msg = "Errors while building APK. You can find the errors in the 'Messages' view.";
            notification.showBalloon(myNotificationTitle, msg, ERROR);
        }
    } finally {
        // See https://code.google.com/p/android/issues/detail?id=195369
        GradleBuildInvoker.getInstance(myProject).remove(this);
    }
}
Also used : AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) File(java.io.File)

Example 2 with AndroidGradleNotification

use of com.android.tools.idea.gradle.project.AndroidGradleNotification in project android by JetBrains.

the class ProjectSubset method addResultAndPopulateProject.

/**
   * Adds the module in the given search results to the IDE. If the search result indicates the variant where the file is, this method
   * will select such variant in the Android model.
   *
   * @param result          the search result.
   * @param projectInfo     information about the project.
   * @param selectedModules all the modules to be included in the project.
   * @param file            the file to include in the project.
   */
private void addResultAndPopulateProject(@NotNull ModuleSearchResult result, @NotNull DataNode<ProjectData> projectInfo, @NotNull List<DataNode<ModuleData>> selectedModules, @NotNull File file) {
    DataNode<ModuleData> moduleNode = result.moduleNode;
    String moduleName = getNameOf(moduleNode);
    String text;
    if (result.selected) {
        String tmp = String.format("File '%1$s' is already in module '%2$s'", file.getName(), moduleName);
        SourceFileContainerInfo containerInfo = result.containerInfo;
        if (containerInfo != null) {
            containerInfo.updateSelectedVariantIn(moduleNode);
            Variant variant = containerInfo.variant;
            if (variant != null) {
                tmp += String.format(", variant '%1$s'", variant.getName());
            }
        }
        text = tmp;
    } else {
        text = String.format("Module '%1$s' was added to the project.", moduleName);
        SourceFileContainerInfo containerInfo = result.containerInfo;
        if (containerInfo != null) {
            containerInfo.updateSelectedVariantIn(moduleNode);
        }
        selectedModules.add(moduleNode);
        setSelection(selectedModules);
    }
    invokeLaterIfNeeded(() -> {
        AndroidGradleNotification notification = AndroidGradleNotification.getInstance(myProject);
        notification.showBalloon(MODULE_LOOKUP_MESSAGE_TITLE, text, INFORMATION);
    });
    populate(myProject, projectInfo, selectedModules, DEFAULT_REQUEST);
}
Also used : Variant(com.android.builder.model.Variant) SourceFileContainerInfo(com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification)

Example 3 with AndroidGradleNotification

use of com.android.tools.idea.gradle.project.AndroidGradleNotification in project android by JetBrains.

the class ProjectSubset method findAndIncludeModuleContainingSourceFile.

/**
   * Finds and includes the module that contains the given file.
   * <p>
   * When using the "Project Subset" feature it is possible that the user knows which file she wants to edit but not the module where
   * such file is. This method tries to find the module that includes the given file in the folders that it marked as "source", either
   * production or test code.
   * </p>
   * <p>
   * The search is based on the Gradle models for both Android and Java modules. If the search finds more than one module that might contain
   * the file, the IDE will display a dialog where the user can see the potential matches and choose the module to include in the project.
   * </p>
   *
   * @param virtualFile the given file.
   */
public void findAndIncludeModuleContainingSourceFile(@NotNull VirtualFile virtualFile) {
    DataNode<ProjectData> projectInfo = DataNodeCaches.getInstance(myProject).getCachedProjectData();
    if (projectInfo == null) {
        return;
    }
    Collection<DataNode<ModuleData>> moduleInfos = findAll(projectInfo, MODULE);
    if (!moduleInfos.isEmpty()) {
        File file = virtualToIoFile(virtualFile);
        new Task.Modal(myProject, "Looking up Module", false) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                List<ModuleSearchResult> results = Lists.newArrayList();
                String[] storedSelection = getSelection();
                Set<String> selection = storedSelection != null ? Sets.newHashSet(storedSelection) : Sets.newHashSet();
                List<DataNode<ModuleData>> selectedModules = Lists.newArrayList();
                int doneCount = 0;
                for (DataNode<ModuleData> moduleNode : moduleInfos) {
                    indicator.setFraction(++doneCount / moduleInfos.size());
                    ModuleData module = moduleNode.getData();
                    String name = module.getExternalName();
                    boolean selected = selection.contains(name);
                    if (selected) {
                        // This module is already included in the project. We need to mark it as "selected" so when we are done searching we don't
                        // exclude it by accident.
                        selectedModules.add(moduleNode);
                    }
                    ModuleSearchResult result = containsSourceFile(moduleNode, file, selected);
                    if (result != null) {
                        // Even though the module is already included, we add it to the search results, because the module might not be the one that
                        // actually contains the file, and the user might need to exclude it in the case that the module that contains the file has
                        // the same path as the already-included module.
                        results.add(result);
                    }
                }
                int resultCount = results.size();
                if (resultCount == 0) {
                    // Nothing found.
                    invokeLaterIfNeeded(() -> {
                        String text = String.format("Unable to find a module containing the file '%1$s' in a source directory.", file.getName());
                        AndroidGradleNotification notification = AndroidGradleNotification.getInstance(ProjectSubset.this.myProject);
                        notification.showBalloon(MODULE_LOOKUP_MESSAGE_TITLE, text, ERROR);
                    });
                } else if (resultCount == 1) {
                    // If there is one result,just apply it.
                    addResultAndPopulateProject(results.get(0), projectInfo, selectedModules, file);
                } else {
                    // We need to let user decide which modules to include.
                    showModuleSelectionDialog(results, projectInfo, selectedModules, file);
                }
            }
        }.queue();
    }
}
Also used : Task(com.intellij.openapi.progress.Task) DataNode(com.intellij.openapi.externalSystem.model.DataNode) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) ProjectData(com.intellij.openapi.externalSystem.model.project.ProjectData)

Example 4 with AndroidGradleNotification

use of com.android.tools.idea.gradle.project.AndroidGradleNotification in project android by JetBrains.

the class HttpProxySettingsCleanUpTask method doCleanUp.

@Override
void doCleanUp(@NotNull Project project) {
    HttpConfigurable ideHttpProxySettings = HttpConfigurable.getInstance();
    if (!ideHttpProxySettings.USE_HTTP_PROXY || isEmpty(ideHttpProxySettings.PROXY_HOST)) {
        return;
    }
    GradleProperties properties;
    try {
        properties = new GradleProperties(project);
    } catch (IOException e) {
        getLogger().info("Failed to read gradle.properties file", e);
        // Let sync continue, even though it may fail.
        return;
    }
    ProxySettings gradleProxySettings = properties.getHttpProxySettings();
    ProxySettings ideProxySettings = new ProxySettings(ideHttpProxySettings);
    if (!ideProxySettings.equals(gradleProxySettings)) {
        ProxySettingsDialog dialog = new ProxySettingsDialog(project, ideProxySettings);
        if (dialog.showAndGet()) {
            dialog.applyProxySettings(properties.getProperties());
            try {
                properties.save();
            } catch (IOException e) {
                Throwable root = getRootCause(e);
                String cause = root.getMessage();
                String errMsg = "Failed to save HTTP proxy settings to gradle.properties file.";
                if (isNotEmpty(cause)) {
                    if (!cause.endsWith(".")) {
                        cause += ".";
                    }
                    errMsg += String.format("\nCause: %1$s", cause);
                }
                AndroidGradleNotification notification = AndroidGradleNotification.getInstance(project);
                notification.showBalloon("Proxy Settings", errMsg, ERROR);
                getLogger().info("Failed to save changes to gradle.properties file", root);
            }
        }
    }
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) GradleProperties(com.android.tools.idea.gradle.util.GradleProperties) ProxySettings(com.android.tools.idea.gradle.util.ProxySettings) AndroidGradleNotification(com.android.tools.idea.gradle.project.AndroidGradleNotification) IOException(java.io.IOException) ProxySettingsDialog(com.android.tools.idea.gradle.project.ProxySettingsDialog)

Aggregations

AndroidGradleNotification (com.android.tools.idea.gradle.project.AndroidGradleNotification)4 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)2 File (java.io.File)2 Variant (com.android.builder.model.Variant)1 ProxySettingsDialog (com.android.tools.idea.gradle.project.ProxySettingsDialog)1 SourceFileContainerInfo (com.android.tools.idea.gradle.project.model.AndroidModuleModel.SourceFileContainerInfo)1 GradleProperties (com.android.tools.idea.gradle.util.GradleProperties)1 ProxySettings (com.android.tools.idea.gradle.util.ProxySettings)1 DataNode (com.intellij.openapi.externalSystem.model.DataNode)1 ProjectData (com.intellij.openapi.externalSystem.model.project.ProjectData)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HttpConfigurable (com.intellij.util.net.HttpConfigurable)1 IOException (java.io.IOException)1