Search in sources :

Example 1 with ModuleImporter

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

the class ImportSourceLocationStep method checkPath.

@NotNull
@VisibleForTesting
protected PathValidationResult checkPath(@NotNull String path) {
    path = path.trim();
    if (Strings.isNullOrEmpty(path)) {
        return PageStatus.EMPTY_PATH.result();
    }
    VirtualFile vfile = VfsUtil.findFileByIoFile(new File(path), false);
    if (vfile == null || !vfile.exists()) {
        return PageStatus.DOES_NOT_EXIST.result();
    } else if (isProjectOrModule(vfile)) {
        return PageStatus.IS_PROJECT_OR_MODULE.result();
    }
    ModuleImporter kind = ModuleImporter.importerForLocation(myContext, vfile);
    if (!kind.isValid()) {
        return PageStatus.NOT_ADT_OR_GRADLE.result();
    }
    return new PathValidationResult(PageStatus.OK, vfile, kind, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleImporter(com.android.tools.idea.gradle.project.ModuleImporter) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VisibleForTesting(com.android.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ModuleImporter

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

the class SourceToGradleModuleStep method createDependentSteps.

@NotNull
@Override
protected Collection<? extends ModelWizardStep> createDependentSteps() {
    WizardContext context = getModel().getContext();
    ArrayList<ModelWizardStep> wrappedSteps = new ArrayList<>();
    for (ModuleImporter importer : ModuleImporter.getAllImporters(context)) {
        for (ModuleWizardStep inputStep : importer.createWizardSteps()) {
            wrappedSteps.add(new ModuleWizardStepAdapter(context, inputStep));
        }
    }
    return wrappedSteps;
}
Also used : ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ModuleImporter(com.android.tools.idea.gradle.project.ModuleImporter) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) ArrayList(java.util.ArrayList) ModelWizardStep(com.android.tools.idea.wizard.model.ModelWizardStep) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ModuleImporter

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

the class SourceToGradleModuleStep method checkPath.

@NotNull
@VisibleForTesting
PathValidationResult checkPath(@NotNull String path) {
    if (Strings.isNullOrEmpty(path)) {
        return PathValidationResult.ofType(EMPTY_PATH);
    }
    VirtualFile vFile = VfsUtil.findFileByIoFile(new File(path), false);
    if (vFile == null || !vFile.exists()) {
        return PathValidationResult.ofType(DOES_NOT_EXIST);
    } else if (isProjectOrModule(vFile)) {
        return PathValidationResult.ofType(IS_PROJECT_OR_MODULE);
    }
    ModuleImporter importer = ModuleImporter.importerForLocation(getModel().getContext(), vFile);
    if (!importer.isValid()) {
        return PathValidationResult.ofType(NOT_ADT_OR_GRADLE);
    }
    Collection<ModuleToImport> modules = ApplicationManager.getApplication().runReadAction((Computable<Collection<ModuleToImport>>) () -> {
        try {
            return importer.findModules(vFile);
        } catch (IOException e) {
            Logger.getInstance(SourceToGradleModuleStep.class).error(e);
            return null;
        }
    });
    if (modules == null) {
        return PathValidationResult.ofType(INTERNAL_ERROR);
    }
    Set<String> missingSourceModuleNames = Sets.newTreeSet();
    for (ModuleToImport module : modules) {
        if (module.location == null || !module.location.exists()) {
            missingSourceModuleNames.add(module.name);
        }
    }
    if (!missingSourceModuleNames.isEmpty()) {
        return new PathValidationResult(MISSING_SUBPROJECTS, vFile, importer, modules, missingSourceModuleNames);
    }
    return new PathValidationResult(OK, vFile, importer, modules, null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport) ModuleImporter(com.android.tools.idea.gradle.project.ModuleImporter) Collection(java.util.Collection) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) VisibleForTesting(com.android.annotations.VisibleForTesting) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)3 NotNull (org.jetbrains.annotations.NotNull)3 VisibleForTesting (com.android.annotations.VisibleForTesting)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 ModuleToImport (com.android.tools.idea.gradle.project.ModuleToImport)1 ModelWizardStep (com.android.tools.idea.wizard.model.ModelWizardStep)1 ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 WizardContext (com.intellij.ide.util.projectWizard.WizardContext)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1