Flex IDE: import application settings from IDEA, import settings from IDEA project

This commit is contained in:
Kirill.Safonov
2011-09-28 18:42:20 +04:00
parent dbe9ad7442
commit a4076b0908
22 changed files with 144 additions and 48 deletions
@@ -57,4 +57,6 @@ public interface ConversionContext {
@Nullable
ComponentManagerSettings getProjectRootManagerSettings();
File[] getModuleFiles();
}
@@ -20,6 +20,7 @@ import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
@@ -44,5 +45,10 @@ public abstract class ConverterProvider {
public abstract String getConversionDescription();
@NotNull
public abstract ProjectConverter createConverter(@NotNull ConversionContext context);
public abstract ProjectConverter createConverter(@NotNull ConversionContext context);
@Nullable
public String getConversionDialogText(ConversionContext context) {
return null;
}
}
@@ -64,4 +64,6 @@ public interface ModuleSettings extends ComponentManagerSettings {
Collection<ModuleSettings> getAllModuleDependencies();
boolean hasModuleLibrary(String libraryName);
List<Element> getOrderEntries();
}
@@ -26,6 +26,11 @@ import java.util.Collections;
* @author nik
*/
public abstract class ProjectConverter {
public boolean isConversionNeeded() {
return true;
}
@Nullable
public ConversionProcessor<ProjectSettings> createProjectFileConverter() {
return null;
@@ -118,6 +118,7 @@ public class ConversionContextImpl implements ConversionContext {
return myProjectBaseDir;
}
@Override
public File[] getModuleFiles() {
return myModuleFiles;
}
@@ -49,6 +49,10 @@ public class ConversionRunner {
}
public boolean isConversionNeeded() throws CannotConvertException {
if (!myConverter.isConversionNeeded()) {
return false;
}
myProcessProjectFile = myContext.getStorageScheme() == StorageScheme.DEFAULT && myProjectFileConverter != null
&& myProjectFileConverter.isConversionNeeded(myContext.getProjectSettings());
@@ -165,7 +165,8 @@ public class ModuleSettingsImpl extends ComponentManagerSettingsImpl implements
return null;
}
private List<Element> getOrderEntries() {
@Override
public List<Element> getOrderEntries() {
final Element component = getComponentElement(MODULE_ROOT_MANAGER_COMPONENT);
return JDOMUtil.getChildren(component, OrderEntryFactory.ORDER_ENTRY_ELEMENT_NAME);
}
@@ -66,11 +66,17 @@ public class ConvertProjectDialog extends DialogWrapper {
myBackupDir = ProjectConversionUtil.getBackupDir(context.getProjectBaseDir());
myTextPane.setSize(new Dimension(350, Integer.MAX_VALUE));
final String message = IdeBundle.message("label.text.project.has.older.format",
context.getProjectFile().getName(),
ApplicationNamesInfo.getInstance().getProductName(),
myBackupDir.getAbsolutePath());
Messages.configureMessagePaneUi(myTextPane, message, false);
StringBuilder message = new StringBuilder("<html>");
if (myConversionRunners.size() == 1 && myConversionRunners.get(0).getProvider().getConversionDialogText(context) != null) {
message.append(myConversionRunners.get(0).getProvider().getConversionDialogText(context));
}
else {
message.append(IdeBundle.message("conversion.dialog.text.1", context.getProjectFile().getName(),
ApplicationNamesInfo.getInstance().getProductName()));
}
message.append(IdeBundle.message("conversion.dialog.text.2", myBackupDir.getAbsolutePath()));
message.append("</html>");
Messages.configureMessagePaneUi(myTextPane, message.toString(), false);
myTextPane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
@@ -52,16 +52,16 @@ public class ProjectJdkImpl extends UserDataHolderBase implements JDOMExternaliz
private ProjectJdkImpl myOrigin = null;
private SdkAdditionalData myAdditionalData = null;
private SdkType mySdkType;
@NonNls private static final String ELEMENT_NAME = "name";
@NonNls private static final String ATTRIBUTE_VALUE = "value";
@NonNls private static final String ELEMENT_TYPE = "type";
@NonNls private static final String ELEMENT_VERSION = "version";
@NonNls public static final String ELEMENT_NAME = "name";
@NonNls public static final String ATTRIBUTE_VALUE = "value";
@NonNls public static final String ELEMENT_TYPE = "type";
@NonNls public static final String ELEMENT_VERSION = "version";
@NonNls private static final String ELEMENT_ROOTS = "roots";
@NonNls private static final String ELEMENT_ROOT = "root";
@NonNls private static final String ELEMENT_PROPERTY = "property";
@NonNls private static final String VALUE_JDKHOME = "jdkHome";
@NonNls private static final String ATTRIBUTE_FILE = "file";
@NonNls private static final String ELEMENT_HOMEPATH = "homePath";
@NonNls public static final String ELEMENT_HOMEPATH = "homePath";
@NonNls private static final String ELEMENT_ADDITIONAL = "additional";
public ProjectJdkImpl(String name, SdkType sdkType) {
@@ -59,7 +59,7 @@ public class ProjectJdkTableImpl extends ProjectJdkTable implements PersistentSt
private final MessageListenerList<Listener> myListenerList;
@NonNls private static final String ELEMENT_JDK = "jdk";
@NonNls public static final String ELEMENT_JDK = "jdk";
private final Map<String, ProjectJdkImpl> myCachedProjectJdks = new HashMap<String, ProjectJdkImpl>();
private final MessageBus myMessageBus;
@@ -63,7 +63,7 @@ public class ProjectRootUtil {
*/
@NonNls public static final String EJB_ROOT = "ejb";
@NonNls private static final String ATTRIBUTE_TYPE = "type";
@NonNls private static final String ELEMENT_ROOT = "root";
@NonNls public static final String ELEMENT_ROOT = "root";
private ProjectRootUtil() {
}
@@ -38,7 +38,7 @@ public class SimpleProjectRoot implements ProjectRoot, JDOMExternalizable {
private VirtualFile myFile;
private final VirtualFile[] myFileArrray = new VirtualFile[1];
private boolean myInitialized = false;
@NonNls private static final String ATTRIBUTE_URL = "url";
@NonNls public static final String ATTRIBUTE_URL = "url";
SimpleProjectRoot(@NotNull VirtualFile file) {
myFile = file;
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.NonNls;
* @author dsl
*/
public class InheritedJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implements InheritedJdkOrderEntry, ClonableOrderEntry, WritableOrderEntry {
@NonNls static final String ENTRY_TYPE = "inheritedJdk";
@NonNls public static final String ENTRY_TYPE = "inheritedJdk";
private final MyJdkTableListener myJdkTableListener = new MyJdkTableListener();
private final MyProjectJdkListener myListener = new MyProjectJdkListener();
@@ -37,9 +37,9 @@ public class ModuleJdkOrderEntryImpl extends LibraryOrderEntryBaseImpl implement
ClonableOrderEntry,
ModuleJdkOrderEntry,
ProjectJdkTable.Listener {
@NonNls static final String ENTRY_TYPE = "jdk";
@NonNls private static final String JDK_NAME_ATTR = "jdkName";
@NonNls private static final String JDK_TYPE_ATTR = "jdkType";
@NonNls public static final String ENTRY_TYPE = "jdk";
@NonNls public static final String JDK_NAME_ATTR = "jdkName";
@NonNls public static final String JDK_TYPE_ATTR = "jdkType";
private Sdk myJdk;
private String myJdkName;
@@ -40,7 +40,7 @@ public class ModuleLibraryOrderEntryImpl extends LibraryOrderEntryBaseImpl imple
private final Library myLibrary;
@NonNls public static final String ENTRY_TYPE = "module-library";
private boolean myExported;
@NonNls private static final String EXPORTED_ATTR = "exported";
@NonNls public static final String EXPORTED_ATTR = "exported";
//cloning
private ModuleLibraryOrderEntryImpl(Library library, RootModelImpl rootModel, boolean isExported, DependencyScope scope) {
@@ -73,8 +73,8 @@ import java.util.concurrent.ConcurrentMap;
public class ProjectRootManagerImpl extends ProjectRootManagerEx implements ProjectComponent, JDOMExternalizable {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.projectRoots.impl.ProjectRootManagerImpl");
@NonNls private static final String PROJECT_JDK_NAME_ATTR = "project-jdk-name";
@NonNls private static final String PROJECT_JDK_TYPE_ATTR = "project-jdk-type";
@NonNls public static final String PROJECT_JDK_NAME_ATTR = "project-jdk-name";
@NonNls public static final String PROJECT_JDK_TYPE_ATTR = "project-jdk-type";
private final ProjectEx myProject;
@@ -66,7 +66,7 @@ public class ApplicationLibraryTable extends LibraryTableBase implements Exporta
return true;
}
private static String getExternalFileName() {
public static String getExternalFileName() {
return "applicationLibraries";
}
@@ -38,7 +38,7 @@ public class JarDirectories implements JDOMExternalizable {
@NonNls private static final String JAR_DIRECTORY_ELEMENT = "jarDirectory";
@NonNls private static final String URL_ATTR = "url";
@NonNls private static final String RECURSIVE_ATTR = "recursive";
@NonNls public static final String RECURSIVE_ATTR = "recursive";
@NonNls private static final String ROOT_TYPE_ATTR = "type";
public static final OrderRootType DEFAULT_JAR_DIRECTORY_TYPE = OrderRootType.CLASSES;
@@ -56,10 +56,10 @@ import java.util.*;
public class LibraryImpl implements LibraryEx.ModifiableModelEx, LibraryEx {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.impl.impl.LibraryImpl");
@NonNls public static final String LIBRARY_NAME_ATTR = "name";
@NonNls private static final String LIBRARY_TYPE_ATTR = "type";
@NonNls private static final String ROOT_PATH_ELEMENT = "root";
@NonNls public static final String LIBRARY_TYPE_ATTR = "type";
@NonNls public static final String ROOT_PATH_ELEMENT = "root";
@NonNls public static final String ELEMENT = "library";
@NonNls private static final String PROPERTIES_ELEMENT = "properties";
@NonNls public static final String PROPERTIES_ELEMENT = "properties";
private static final SkipDefaultValuesSerializationFilters SERIALIZATION_FILTERS = new SkipDefaultValuesSerializationFilters();
private String myName;
private final LibraryTable myLibraryTable;
@@ -18,6 +18,7 @@ package com.intellij.openapi.application;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.PlatformUtils;
import com.intellij.util.SystemProperties;
import com.intellij.util.ui.UIUtil;
import com.intellij.ui.AppUIUtil;
@@ -26,6 +27,8 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.PropertyResourceBundle;
/**
@@ -43,12 +46,14 @@ public class ConfigImportHelper {
File oldConfigDir = findOldConfigDir(newConfigPath);
do {
ImportOldConfigsPanel dlg;
if (UIUtil.hasJdk6Dialogs()) {
dlg = new ImportOldConfigsPanel(oldConfigDir);
}
else {
dlg = new ImportOldConfigsPanel(oldConfigDir, JOptionPane.getRootFrame());
ImportOldConfigsPanel dlg = getCustomDialog(oldConfigDir);
if (dlg == null) {
if (UIUtil.hasJdk6Dialogs()) {
dlg = new ImportOldConfigsPanel(oldConfigDir);
}
else {
dlg = new ImportOldConfigsPanel(oldConfigDir, JOptionPane.getRootFrame());
}
}
UIUtil.setToolkitModal(dlg);
@@ -67,6 +72,33 @@ public class ConfigImportHelper {
while (true);
}
@Nullable
private static ImportOldConfigsPanel getCustomDialog(File oldConfigDir) {
try {
Class customDialogClass =
Class.forName("com.intellij.openapi.application." + PlatformUtils.getPlatformPrefix() + "ImportOldConfigsPanel");
if (customDialogClass != null) {
if (ImportOldConfigsPanel.class.isAssignableFrom(customDialogClass)) {
Constructor constructor = customDialogClass.getDeclaredConstructor(File.class);
if (constructor != null) {
return (ImportOldConfigsPanel)constructor.newInstance(oldConfigDir);
}
}
}
}
catch (ClassNotFoundException ignored) {
}
catch (NoSuchMethodException ignored) {
}
catch (InvocationTargetException ignored) {
}
catch (InstantiationException ignored) {
}
catch (IllegalAccessException ignored) {
}
return null;
}
private static File findOldConfigDir(String newConfigPath) {
final File configDir = new File(newConfigPath);
final File selectorDir = SystemInfo.isMac ? configDir : configDir.getParentFile();
@@ -67,17 +67,16 @@ public class ImportOldConfigsPanel extends JDialog {
group.add(myRbImportAuto);
myRbDoNotImport.setSelected(true);
final ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance();
final String productName = namesInfo.getProductName().equals("IDEA") ? namesInfo.getFullProductName() : namesInfo.getProductName();
mySuggestLabel.setText(ApplicationBundle.message("label.you.can.import", productName));
myRbDoNotImport.setText(ApplicationBundle.message("radio.do.not.import", productName));
final String productName = getProductName(false);
mySuggestLabel.setText(getTitleLabel(productName));
myRbDoNotImport.setText(getDoNotImportLabel(productName));
if(myGuessedOldConfig != null) {
myRbImportAuto.setText(ApplicationBundle.message("radio.import.auto", myGuessedOldConfig.getAbsolutePath().replace(SystemProperties.getUserHome(), "~")));
myRbImportAuto.setText(getAutoImportLabel(myGuessedOldConfig));
myRbImportAuto.setSelected(true);
} else {
myRbImportAuto.setVisible(false);
}
myHomeLabel.setText(ApplicationBundle.message("editbox.installation.home", productName));
myHomeLabel.setText(getHomeLabel(productName));
myRbImport.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
@@ -138,6 +137,11 @@ public class ImportOldConfigsPanel extends JDialog {
setLocation((parentSize.width - ownSize.width) / 2, (parentSize.height - ownSize.height) / 2);
}
protected String getProductName(boolean full) {
ApplicationNamesInfo namesInfo = ApplicationNamesInfo.getInstance();
return full || namesInfo.getProductName().equals("IDEA") ? namesInfo.getFullProductName() : namesInfo.getProductName();
}
@Nullable
private static String findPreviousInstallationWindows(String productName) {
String programFiles = System.getenv("ProgramFiles");
@@ -178,34 +182,32 @@ public class ImportOldConfigsPanel extends JDialog {
private void close() {
if (isImportEnabled()) {
final String productWithVendor = ApplicationNamesInfo.getInstance().getFullProductName();
final String productWithVendor = getProductName(true);
String instHome = myPrevInstallation.getText();
if ("".equals(instHome)) {
JOptionPane.showMessageDialog(this,
ApplicationBundle.message("error.please.select.previous.installation.home", productWithVendor),
getEmptyHomeErrorText(productWithVendor),
ApplicationBundle.message("title.installation.home.required"), JOptionPane.ERROR_MESSAGE);
return;
}
if (PathManager.getHomePath().equals(instHome)) {
JOptionPane.showMessageDialog(this,
ApplicationBundle.message("error.selected.current.installation.home",
productWithVendor, productWithVendor),
getCurrentHomeErrorText(productWithVendor),
ApplicationBundle.message("title.installation.home.required"), JOptionPane.ERROR_MESSAGE);
return;
}
if (myRbImport.isSelected() && !ConfigImportHelper.isInstallationHomeOrConfig(instHome)) {
JOptionPane.showMessageDialog(this,
ApplicationBundle.message("error.does.not.appear.to.be.installation.home", instHome,
productWithVendor),
getInvalidHomeErrorText(productWithVendor, instHome),
ApplicationBundle.message("title.installation.home.required"), JOptionPane.ERROR_MESSAGE);
return;
}
if (!new File(instHome).canRead()) {
JOptionPane.showMessageDialog(this,
ApplicationBundle.message("error.no.read.permissions", instHome),
getInaccessibleHomeErrorText(instHome),
ApplicationBundle.message("title.installation.home.required"), JOptionPane.ERROR_MESSAGE);
return;
}
@@ -230,4 +232,39 @@ public class ImportOldConfigsPanel extends JDialog {
ImportOldConfigsPanel dlg = new ImportOldConfigsPanel(null);
dlg.setVisible(true);
}
protected String getInaccessibleHomeErrorText(String instHome) {
return ApplicationBundle.message("error.no.read.permissions", instHome);
}
protected String getInvalidHomeErrorText(String productWithVendor, String instHome) {
return ApplicationBundle.message("error.does.not.appear.to.be.installation.home", instHome,
productWithVendor);
}
protected String getCurrentHomeErrorText(String productWithVendor) {
return ApplicationBundle.message("error.selected.current.installation.home",
productWithVendor, productWithVendor);
}
protected String getEmptyHomeErrorText(String productWithVendor) {
return ApplicationBundle.message("error.please.select.previous.installation.home", productWithVendor);
}
protected String getHomeLabel(String productName) {
return ApplicationBundle.message("editbox.installation.home", productName);
}
protected String getAutoImportLabel(File guessedOldConfig) {
return ApplicationBundle.message("radio.import.auto", guessedOldConfig.getAbsolutePath().replace(SystemProperties.getUserHome(), "~"));
}
protected String getDoNotImportLabel(String productName) {
return ApplicationBundle.message("radio.do.not.import", productName);
}
protected String getTitleLabel(String productName) {
return ApplicationBundle.message("label.you.can.import", productName);
}
}
@@ -234,8 +234,8 @@ error.project.file.is.corrupted=Project file is corrupted
title.cannot.convert.project=Cannot Convert Project
dialog.title.convert.project=Convert Project
label.text.project.has.older.format=<html><body>The project ''{0}'' has an older format and will be converted. You may not be able to open the project with earlier versions of {1}. <a href="details">Details</a><br/>\
Old versions of project files will be saved to: ''{2}''</body></html>
conversion.dialog.text.1=The project ''{0}'' has an older format and will be converted. You may not be able to open the project with earlier versions of {1}.
conversion.dialog.text.2=<b> </b><a href=\"details\">Details...</a><br/><br/>Old versions of project files will be saved to: ''{0}''
message.text.unlock.read.only.files=<html><body>The following files are read only. {0} will unlock them.<br>{1}</body></html>
error.message.cannot.make.files.writable=Cannot make the following files writable:\n{0}
error.cannot.convert.project=Cannot convert project: {0}