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();
}
Aggregations