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