Search in sources :

Example 1 with NewProjectImportGradleSyncListener

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

the class AdtImportBuilder method commit.

@Nullable
@Override
public List<Module> commit(Project project, @Nullable ModifiableModuleModel model, ModulesProvider modulesProvider, @Nullable ModifiableArtifactModel artifactModel) {
    File destDir = getBaseDirPath(project);
    try {
        if (!destDir.exists()) {
            boolean ok = destDir.mkdirs();
            if (!ok) {
                throw new IOException("Could not create destination directory");
            }
        }
        // Re-read the project here since one of the wizard steps can have modified the importer options,
        // and that affects the imported state (for example, if you enable/disable the replace-lib-with-dependency
        // options, the set of modules can change)
        readProjects();
        if (!myImporter.getErrors().isEmpty()) {
            return null;
        }
        myImporter.exportProject(destDir, true);
        project.getBaseDir().refresh(false, true);
    } catch (IOException e) {
        Logger.getInstance(AdtImportBuilder.class).error(e);
        return null;
    }
    try {
        NewProjectImportGradleSyncListener syncListener = new NewProjectImportGradleSyncListener() {

            @Override
            public void syncSucceeded(@NotNull Project project) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    activateProjectView(project);
                    openSummary(project);
                });
            }

            @Override
            public void syncFailed(@NotNull Project project, @NotNull String errorMessage) {
                ApplicationManager.getApplication().invokeLater(() -> {
                    createTopLevelProjectAndOpen(project);
                    openSummary(project);
                });
            }
        };
        GradleProjectImporter importer = GradleProjectImporter.getInstance();
        if (myCreateProject) {
            GradleProjectImporter.Request request = new GradleProjectImporter.Request().setProject(project);
            importer.importProject(project.getName(), destDir, request, syncListener);
        } else {
            GradleSyncInvoker.getInstance().requestProjectSyncAndSourceGeneration(project, syncListener);
        }
    } catch (ConfigurationException e) {
        Messages.showErrorDialog(project, e.getMessage(), e.getTitle());
    } catch (Throwable e) {
        Messages.showErrorDialog(project, e.getMessage(), "ADT Project Import");
    }
    return Collections.emptyList();
}
Also used : NewProjectImportGradleSyncListener(com.android.tools.idea.gradle.project.importing.NewProjectImportGradleSyncListener) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectImporter(com.android.tools.idea.gradle.project.importing.GradleProjectImporter) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleProjectImporter (com.android.tools.idea.gradle.project.importing.GradleProjectImporter)1 NewProjectImportGradleSyncListener (com.android.tools.idea.gradle.project.importing.NewProjectImportGradleSyncListener)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1