use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.
the class AdtWorkspaceForm method validate.
@Override
public boolean validate() throws ConfigurationException {
for (Map.Entry<String, File> entry : myPathMap.entrySet()) {
String path = entry.getKey();
File file = entry.getValue();
if (file == null || file.getPath().trim().isEmpty()) {
throw new ConfigurationException("Enter a value for workspace path " + path);
} else if (!file.exists()) {
throw new ConfigurationException(file.getPath() + " does not exist");
}
}
return super.validate();
}
use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.
the class NewProjectWizardDynamic method runFinish.
private void runFinish() {
if (ApplicationManager.getApplication().isUnitTestMode()) {
return;
}
GradleProjectImporter projectImporter = GradleProjectImporter.getInstance();
String rootPath = getState().get(PROJECT_LOCATION_KEY);
if (rootPath == null) {
LOG.error("No root path specified for project");
return;
}
File rootLocation = new File(rootPath);
File wrapperPropertiesFilePath = GradleWrapper.getDefaultPropertiesFilePath(rootLocation);
try {
GradleWrapper.get(wrapperPropertiesFilePath).updateDistributionUrl(SdkConstants.GRADLE_LATEST_VERSION);
} catch (IOException e) {
// Unlikely to happen. Continue with import, the worst-case scenario is that sync fails and the error message has a "quick fix".
LOG.warn("Failed to update Gradle wrapper file", e);
}
String projectName = getState().get(APPLICATION_NAME_KEY);
if (projectName == null) {
projectName = "Unnamed Project";
}
// Pick the highest language level of all the modules/form factors.
// We have to pick the language level up front while creating the project rather than
// just reacting to it during sync, because otherwise the user gets prompted with
// a changing-language-level-requires-reopening modal dialog box and have to reload
// the project
LanguageLevel initialLanguageLevel = null;
for (FormFactor factor : FormFactor.values()) {
Object version = getState().get(FormFactorUtils.getLanguageLevelKey(factor));
if (version != null) {
LanguageLevel level = LanguageLevel.parse(version.toString());
if (level != null && (initialLanguageLevel == null || level.isAtLeast(initialLanguageLevel))) {
initialLanguageLevel = level;
}
}
}
// This is required for Android plugin in IDEA
if (!IdeInfo.getInstance().isAndroidStudio()) {
final Sdk jdk = IdeSdks.getInstance().getJdk();
if (jdk != null) {
ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(myProject).setProjectSdk(jdk));
}
}
try {
GradleSyncListener listener = new PostStartupGradleSyncListener(() -> {
Iterable<File> targetFiles = myState.get(TARGET_FILES_KEY);
assert targetFiles != null;
TemplateUtils.reformatAndRearrange(myProject, targetFiles);
Collection<File> filesToOpen = myState.get(FILES_TO_OPEN_KEY);
assert filesToOpen != null;
TemplateUtils.openEditors(myProject, filesToOpen, true);
});
GradleProjectImporter.Request request = new GradleProjectImporter.Request();
request.setLanguageLevel(initialLanguageLevel).setProject(myProject);
projectImporter.importProject(projectName, rootLocation, request, listener);
} catch (IOException | ConfigurationException e) {
Messages.showErrorDialog(e.getMessage(), ERROR_MSG_TITLE);
LOG.error(e);
}
}
use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.
the class AndroidModuleConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
VirtualFile file = getGradleBuildFile(myModule);
if (file != null && !ensureFilesWritable(myModule.getProject(), file)) {
throw new ConfigurationException(String.format("Build file %1$s is not writable", file.getPath()));
}
myModuleEditor.apply();
}
use of com.intellij.openapi.options.ConfigurationException in project android by JetBrains.
the class AndroidProjectConfigurable method apply.
@Override
public void apply() throws ConfigurationException {
if (myGradleBuildFile == null) {
return;
}
VirtualFile file = myGradleBuildFile.getFile();
if (!ReadonlyStatusHandler.ensureFilesWritable(myProject, file)) {
throw new ConfigurationException(String.format("Build file %1$s is not writable", file.getPath()));
}
CommandProcessor.getInstance().runUndoTransparentAction(() -> {
try {
ActionRunner.runInsideWriteAction(() -> {
for (BuildFileKey key : PROJECT_PROPERTIES) {
if (key == BuildFileKey.GRADLE_WRAPPER_VERSION || !myModifiedKeys.contains(key)) {
continue;
}
Object value = myProjectProperties.get(key);
if (value != null) {
myGradleBuildFile.setValue(key, value);
} else {
myGradleBuildFile.removeValue(null, key);
}
}
Object wrapperVersion = myProjectProperties.get(BuildFileKey.GRADLE_WRAPPER_VERSION);
GradleWrapper gradleWrapper = GradleWrapper.find(myProject);
if (wrapperVersion != null && gradleWrapper != null) {
boolean updated = gradleWrapper.updateDistributionUrlAndDisplayFailure(wrapperVersion.toString());
if (updated) {
VirtualFile virtualFile = gradleWrapper.getPropertiesFile();
if (virtualFile != null) {
virtualFile.refresh(false, false);
}
}
}
myModifiedKeys.clear();
});
} catch (Exception e) {
LOG.error("Error while applying changes", e);
}
});
}
use of com.intellij.openapi.options.ConfigurationException in project intellij-plugins by JetBrains.
the class FlexTestUtils method createConfigEditor.
public static FlexProjectConfigurationEditor createConfigEditor(final Module... modules) {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Map<Module, ModifiableRootModel> models = new FactoryMap<Module, ModifiableRootModel>() {
@Override
protected ModifiableRootModel create(final Module module) {
final ModifiableRootModel result = ModuleRootManager.getInstance(module).getModifiableModel();
Disposer.register(module, new Disposable() {
@Override
public void dispose() {
if (!result.isDisposed()) {
result.dispose();
}
}
});
return result;
}
};
return new FlexProjectConfigurationEditor(modules[0].getProject(), new FlexProjectConfigurationEditor.ProjectModifiableModelProvider() {
@Override
public Module[] getModules() {
return modules;
}
@Override
public ModifiableRootModel getModuleModifiableModel(Module module) {
return models.get(module);
}
@Override
public void addListener(FlexBCConfigurator.Listener listener, Disposable parentDisposable) {
// ignore
}
@Override
public void commitModifiableModels() throws ConfigurationException {
ApplicationManager.getApplication().runWriteAction(() -> {
for (ModifiableRootModel model : models.values()) {
if (model.isChanged()) {
model.commit();
}
}
});
}
public Library findSourceLibraryForLiveName(final String name, final String level) {
return findSourceLibrary(name, level);
}
public Library findSourceLibrary(final String name, final String level) {
return getLibrariesTable(level).getLibraryByName(name);
}
private LibraryTable getLibrariesTable(final String level) {
if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
return ApplicationLibraryTable.getApplicationTable();
} else {
assert LibraryTablesRegistrar.PROJECT_LEVEL.equals(level);
return ProjectLibraryTable.getInstance(modules[0].getProject());
}
}
});
}
Aggregations