Search in sources :

Example 11 with ModuleToImport

use of com.android.tools.idea.gradle.project.ModuleToImport 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)

Example 12 with ModuleToImport

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

the class ModulesListModelTest method testCanOverrideDefaultSelection.

public void testCanOverrideDefaultSelection() {
    ModuleToImport nullLocation = new ModuleToImport("somename", null, NO_DEPS);
    ModuleToImport existing = new ModuleToImport(EXISTING_MODULE, myModule2.location, NO_DEPS);
    setModules(myModule1, nullLocation, existing);
    myModel.setSelected(nullLocation, true);
    myModel.setSelected(existing, true);
    assertTrue(myModel.isSelected(myModule1));
    assertFalse(myModel.isSelected(nullLocation));
    assertTrue(myModel.isSelected(existing));
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 13 with ModuleToImport

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

the class ModulesListModelTest method testUncheckedByDefaultModuleDependencies.

public void testUncheckedByDefaultModuleDependencies() {
    ModuleToImport existing = new ModuleToImport(EXISTING_MODULE, myModule2.location, Suppliers.ofInstance(ImmutableSet.of(myModule1.name)));
    setModules(myModule1, existing);
    assertEquals(OK, myModel.getModuleState(myModule1));
    myModel.setSelected(existing, true);
    assertEquals(REQUIRED, myModel.getModuleState(myModule1));
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 14 with ModuleToImport

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

the class ModulesListModelTest method testModuleExistsValidation.

public void testModuleExistsValidation() {
    ModuleToImport conflicting = new ModuleToImport(EXISTING_MODULE, myModule2.location, NO_DEPS);
    setModules(myModule1, conflicting);
    assertEquals(ALREADY_EXISTS, myModel.getModuleState(conflicting));
    myModel.setModuleName(conflicting, NEW_NAME);
    assertEquals(OK, myModel.getModuleState(conflicting));
}
Also used : ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport)

Example 15 with ModuleToImport

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

the class ModulesListModelTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Void, IOException>() {

        @Override
        public Void compute() throws IOException {
            myTempDir = VfsUtil.findFileByIoFile(Files.createTempDir(), true);
            assert myTempDir != null;
            VirtualFile module1vf = VfsUtil.createDirectoryIfMissing(myTempDir, "module1");
            VirtualFile module2vf = VfsUtil.createDirectoryIfMissing(myTempDir, "module2");
            assert module1vf != null && module2vf != null;
            myModule1 = new ModuleToImport(module1vf.getName(), module1vf, NO_DEPS);
            myModule2 = new ModuleToImport(module2vf.getName(), module2vf, Suppliers.ofInstance(ImmutableSet.of(module1vf.getName())));
            VirtualFile existingModule = VfsUtil.createDirectoryIfMissing(getProject().getBaseDir(), EXISTING_MODULE);
            if (existingModule == null) {
                throw new IOException("Unable to create fake module directory");
            }
            existingModule.createChildData(this, "empty_file");
            return null;
        }
    });
    myModel = new ModuleListModel(getProject());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleToImport(com.android.tools.idea.gradle.project.ModuleToImport) ModuleListModel(com.android.tools.idea.npw.importing.ModuleListModel) IOException(java.io.IOException)

Aggregations

ModuleToImport (com.android.tools.idea.gradle.project.ModuleToImport)17 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 IOException (java.io.IOException)3 VisibleForTesting (com.android.annotations.VisibleForTesting)1 ModuleImporter (com.android.tools.idea.gradle.project.ModuleImporter)1 ModuleListModel (com.android.tools.idea.npw.importing.ModuleListModel)1 Function (com.google.common.base.Function)1 Project (com.intellij.openapi.project.Project)1 File (java.io.File)1 Collection (java.util.Collection)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1