@Override public void updateDataModel() { myWizardContext.setProjectBuilder(myModuleBuilder); myWizardContext.setProjectName(myNamePathComponent.getNameValue()); myWizardContext.setProjectFileDirectory(myNamePathComponent.getPath()); myFormatPanel.updateData(myWizardContext); if (myModuleBuilder != null) { myModuleNameLocationComponent.updateDataModel(myModuleBuilder); if (myModuleBuilder instanceof TemplateModuleBuilder) { myWizardContext.setProjectStorageFormat(StorageScheme.DIRECTORY_BASED); } } if (mySettingsStep != null) { mySettingsStep.updateDataModel(); } }
@Override public void updateDataModel() { myWizardContext.setProjectName(myNamePathComponent.getNameValue()); myWizardContext.setProjectFileDirectory(myNamePathComponent.getPath()); myFormatPanel.updateData(myWizardContext); ModuleBuilder moduleBuilder = (ModuleBuilder)myWizardContext.getProjectBuilder(); if (moduleBuilder != null) { myModuleNameLocationComponent.updateDataModel(moduleBuilder); if (moduleBuilder instanceof TemplateModuleBuilder) { myWizardContext.setProjectStorageFormat(StorageScheme.DIRECTORY_BASED); } } if (mySettingsStep != null) { mySettingsStep.updateDataModel(); } }
private static boolean isSameProject(String path, @NotNull Project project) { IProjectStore projectStore = (IProjectStore)ServiceKt.getStateStore(project); String toOpen = FileUtil.toSystemIndependentName(path); String existing = projectStore.getProjectFilePath(); String existingBaseDir = projectStore.getProjectBasePath(); if (existingBaseDir == null) { // could be null if not yet initialized return false; } final File openFile = new File(toOpen); if (openFile.isDirectory()) { return FileUtil.pathsEqual(toOpen, existingBaseDir); } if (StorageScheme.DIRECTORY_BASED == projectStore.getStorageScheme()) { // todo: check if IPR is located not under the project base dir return FileUtil.pathsEqual(FileUtil.toSystemIndependentName(openFile.getParentFile().getPath()), existingBaseDir); } return FileUtil.pathsEqual(toOpen, existing); }
public ConversionContextImpl(String projectPath) throws CannotConvertException { myProjectFile = new File(projectPath); File modulesFile; if (myProjectFile.isDirectory()) { myStorageScheme = StorageScheme.DIRECTORY_BASED; myProjectBaseDir = myProjectFile; mySettingsBaseDir = new File(myProjectBaseDir.getAbsolutePath(), Project.DIRECTORY_STORE_FOLDER); modulesFile = new File(mySettingsBaseDir, "modules.xml"); myWorkspaceFile = new File(mySettingsBaseDir, "workspace.xml"); } else { myStorageScheme = StorageScheme.DEFAULT; myProjectBaseDir = myProjectFile.getParentFile(); modulesFile = myProjectFile; myWorkspaceFile = new File(StringUtil.trimEnd(projectPath, ProjectFileType.DOT_DEFAULT_EXTENSION) + WorkspaceFileType.DOT_DEFAULT_EXTENSION); } myModuleFiles = modulesFile.exists() ? findModuleFiles(JDomConvertingUtil.loadDocument(modulesFile).getRootElement()) : new File[0]; myPerformedConversionIds = loadPerformedConversionIds(); }
@Override @Nullable public ComponentManagerSettingsImpl createProjectSettings(@NotNull final String fileName) { try { File file; if (myStorageScheme == StorageScheme.DEFAULT) { file = myProjectFile; } else { file = new File(mySettingsBaseDir, fileName); } return new ComponentManagerSettingsImpl(file, this); } catch (CannotConvertException e) { LOG.info(e); return null; } }
@Override public void updateDataModel() { myWizardContext.setProjectBuilder(myModuleBuilder); myWizardContext.setProjectName(myNamePathComponent.getNameValue()); myWizardContext.setProjectFileDirectory(myNamePathComponent.getPath()); myFormatPanel.updateData(myWizardContext); if (myModuleBuilder != null) { final String moduleName = getModuleName(); myModuleBuilder.setName(moduleName); myModuleBuilder.setModuleFilePath( FileUtil.toSystemIndependentName(myModuleFileLocation.getText()) + "/" + moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION); myModuleBuilder.setContentEntryPath(FileUtil.toSystemIndependentName(getModuleContentRoot())); if (myModuleBuilder instanceof TemplateModuleBuilder) { myWizardContext.setProjectStorageFormat(StorageScheme.DIRECTORY_BASED); } } if (mySettingsStep != null) { mySettingsStep.updateDataModel(); } }
protected ProjectImpl(@NotNull ProjectManagerImpl manager, @NotNull String filePath, boolean isOptimiseTestLoadSpeed, String projectName) { super(ApplicationManager.getApplication(), "Project "+(projectName == null ? filePath : projectName)); putUserData(CREATION_TIME, System.nanoTime()); getPicoContainer().registerComponentInstance(Project.class, this); if (!isDefault()) { getStateStore().setProjectFilePath(filePath); } myOptimiseTestLoadSpeed = isOptimiseTestLoadSpeed; myManager = manager; myName = isDefault() ? TEMPLATE_PROJECT_NAME : projectName == null ? getStateStore().getProjectName() : projectName; if (!isDefault() && projectName != null && getStateStore().getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) { myOldName = ""; // new project } }
private static boolean isSameProject(String path, Project p) { final IProjectStore projectStore = ((ProjectEx)p).getStateStore(); String toOpen = FileUtil.toSystemIndependentName(path); String existing = FileUtil.toSystemIndependentName(projectStore.getProjectFilePath()); final VirtualFile existingBaseDir = projectStore.getProjectBaseDir(); if (existingBaseDir == null) return false; // could be null if not yet initialized final File openFile = new File(toOpen); if (openFile.isDirectory()) { return FileUtil.pathsEqual(toOpen, existingBaseDir.getPath()); } if (StorageScheme.DIRECTORY_BASED == projectStore.getStorageScheme()) { // todo: check if IPR is located not under the project base dir return FileUtil.pathsEqual(FileUtil.toSystemIndependentName(openFile.getParentFile().getPath()), existingBaseDir.getPath()); } return FileUtil.pathsEqual(toOpen, existing); }
public String getProjectConfigurationMessage(final Project project) { final StorageScheme storageScheme = ((ProjectEx) project).getStateStore().getStorageScheme(); boolean isDirectoryBased = StorageScheme.DIRECTORY_BASED.equals(storageScheme); final String[] parts = new String[] {"Content roots of all modules", "all immediate descendants of project base directory", Project.DIRECTORY_STORE_FOLDER + " directory contents"}; final StringBuilder sb = new StringBuilder(parts[0]); if (isDirectoryBased) { sb.append(", "); } else { sb.append(", and "); } sb.append(parts[1]); if (isDirectoryBased) { sb.append(", and "); sb.append(parts[2]); } return sb.toString(); }
public static PsiFile[] getPsiFiles(final Project project, final Collection<VirtualFile> selectedFiles) { ArrayList<PsiFile> result = new ArrayList<PsiFile>(); PsiManager psiManager = PsiManager.getInstance(project); VirtualFile projectFileDir = null; final StorageScheme storageScheme = ((ProjectEx) project).getStateStore().getStorageScheme(); if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) { VirtualFile baseDir = project.getBaseDir(); if (baseDir != null) { projectFileDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); } } for (VirtualFile file : selectedFiles) { if (file.isValid()) { if (isUnderProjectFileDir(projectFileDir, file) || !isFileUnderSourceRoot(project, file)) { continue; } PsiFile psiFile = psiManager.findFile(file); if (psiFile != null) result.add(psiFile); } } return PsiUtilCore.toPsiFileArray(result); }
@Override @Nullable public VirtualFile getVcsRootFor(final VirtualFile file) { if (myBaseDir != null && PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class) .isValidAncestor(myBaseDir, file)) { return myBaseDir; } final VirtualFile contentRoot = ProjectRootManager.getInstance(myProject).getFileIndex().getContentRootForFile(file); if (contentRoot != null) { return contentRoot; } final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme(); if (StorageScheme.DIRECTORY_BASED.equals(storageScheme) && (myBaseDir != null)) { final VirtualFile ideaDir = myBaseDir.findChild(Project.DIRECTORY_STORE_FOLDER); if (ideaDir != null && ideaDir.isValid() && ideaDir.isDirectory()) { if (VfsUtilCore.isAncestor(ideaDir, file, false)) { return ideaDir; } } } return null; }
@Nullable private ComponentManagerSettingsImpl createProjectSettings(final String fileName) { try { File file; if (myStorageScheme == StorageScheme.DEFAULT) { file = myProjectFile; } else { file = new File(mySettingsBaseDir, fileName); } return new ComponentManagerSettingsImpl(file, this); } catch (CannotConvertException e) { LOG.info(e); return null; } }
@Override public RunManagerSettingsImpl getRunManagerSettings() throws CannotConvertException { if (myRunManagerSettings == null) { if (myStorageScheme == StorageScheme.DEFAULT) { myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, myProjectFile, null, this); } else { final File[] files = new File(mySettingsBaseDir, "runConfigurations").listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory() && file.getName().endsWith(".xml"); } }); myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, null, files, this); } } return myRunManagerSettings; }
@Override public ProjectLibrariesSettingsImpl getProjectLibrariesSettings() throws CannotConvertException { if (myProjectLibrariesSettings == null) { if (myStorageScheme == StorageScheme.DEFAULT) { myProjectLibrariesSettings = new ProjectLibrariesSettingsImpl(myProjectFile, null, this); } else { final File librariesDir = new File(mySettingsBaseDir, "libraries"); final File[] files = librariesDir.exists() ? librariesDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return !file.isDirectory() && file.getName().endsWith(".xml"); } }) : ArrayUtil.EMPTY_FILE_ARRAY; myProjectLibrariesSettings = new ProjectLibrariesSettingsImpl(null, files, this); } } return myProjectLibrariesSettings; }
@NotNull public String getNewProjectFilePath() { if (myWizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) { return myWizardContext.getProjectFileDirectory() + File.separator + myWizardContext.getProjectName() + ProjectFileType.DOT_DEFAULT_EXTENSION; } else { return myWizardContext.getProjectFileDirectory(); } }
public Set<File> getAllProjectFiles() { final HashSet<File> files = new HashSet<File>(Arrays.asList(myModuleFiles)); if (myStorageScheme == StorageScheme.DEFAULT) { files.add(myProjectFile); files.add(myWorkspaceFile); } else { addFilesRecursively(mySettingsBaseDir, files); } return files; }
@Override public RunManagerSettingsImpl getRunManagerSettings() throws CannotConvertException { if (myRunManagerSettings == null) { if (myStorageScheme == StorageScheme.DEFAULT) { myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, myProjectFile, null, this); } else { final File[] files = new File(mySettingsBaseDir, "runConfigurations").listFiles(FileFilters.filesWithExtension("xml")); myRunManagerSettings = new RunManagerSettingsImpl(myWorkspaceFile, null, files, this); } } return myRunManagerSettings; }
@Override public ProjectLibrariesSettingsImpl getProjectLibrariesSettings() throws CannotConvertException { if (myProjectLibrariesSettings == null) { myProjectLibrariesSettings = myStorageScheme == StorageScheme.DEFAULT ? new ProjectLibrariesSettingsImpl(myProjectFile, null, this) : new ProjectLibrariesSettingsImpl(null, getSettingsXmlFiles("libraries"), this); } return myProjectLibrariesSettings; }
@Override public ArtifactsSettingsImpl getArtifactsSettings() throws CannotConvertException { if (myArtifactsSettings == null) { myArtifactsSettings = myStorageScheme == StorageScheme.DEFAULT ? new ArtifactsSettingsImpl(myProjectFile, null, this) : new ArtifactsSettingsImpl(null, getSettingsXmlFiles("artifacts"), this); } return myArtifactsSettings; }
public boolean isConversionNeeded() throws CannotConvertException { if (myContext.isConversionAlreadyPerformed(myProvider)) return false; myProcessProjectFile = myContext.getStorageScheme() == StorageScheme.DEFAULT && myProjectFileConverter != null && myProjectFileConverter.isConversionNeeded(myContext.getProjectSettings()); myProcessWorkspaceFile = myWorkspaceConverter != null && myContext.getWorkspaceFile().exists() && myWorkspaceConverter.isConversionNeeded(myContext.getWorkspaceSettings()); myModulesFilesToProcess.clear(); if (myModuleFileConverter != null) { for (File moduleFile : myContext.getModuleFiles()) { if (moduleFile.exists() && myModuleFileConverter.isConversionNeeded(myContext.getModuleSettings(moduleFile))) { myModulesFilesToProcess.add(moduleFile); } } } myProcessRunConfigurations = myRunConfigurationsConverter != null && myRunConfigurationsConverter.isConversionNeeded(myContext.getRunManagerSettings()); myProcessProjectLibraries = myProjectLibrariesConverter != null && myProjectLibrariesConverter.isConversionNeeded(myContext.getProjectLibrariesSettings()); myArtifacts = myArtifactsConverter != null && myArtifactsConverter.isConversionNeeded(myContext.getArtifactsSettings()); return myProcessProjectFile || myProcessWorkspaceFile || myProcessRunConfigurations || myProcessProjectLibraries || !myModulesFilesToProcess.isEmpty() || myConverter.isConversionNeeded(); }
private static void doCreate(@NotNull AddModuleWizard wizard) throws IOException { // TODO: Now we need to add as module if file does not exist ProjectBuilder projectBuilder = wizard.getProjectBuilder(); try { File projectFilePath = new File(wizard.getNewProjectFilePath()); File projectDirPath = projectFilePath.isDirectory() ? projectFilePath : projectFilePath.getParentFile(); LOG.assertTrue(projectDirPath != null, "Cannot create project in '" + projectFilePath + "': no parent file exists"); ensureExists(projectDirPath); if (StorageScheme.DIRECTORY_BASED == wizard.getStorageScheme()) { File ideaDirPath = new File(projectDirPath, DIRECTORY_STORE_FOLDER); ensureExists(ideaDirPath); } boolean unitTestMode = ApplicationManager.getApplication().isUnitTestMode(); ProjectManagerEx projectManager = ProjectManagerEx.getInstanceEx(); Project project = projectManager.newProject(wizard.getProjectName(), projectDirPath.getPath(), true, false); if (project == null) { return; } if (!unitTestMode) { project.save(); } if (projectBuilder != null) { if (!projectBuilder.validate(null, project)) { return; } projectBuilder.commit(project, null, EMPTY_MODULES_PROVIDER); } if (!unitTestMode) { project.save(); } } finally { if (projectBuilder != null) { projectBuilder.cleanup(); } } }
@NotNull @NonNls @Override public String getLocationHash() { String str = getPresentableUrl(); if (str == null) str = getName(); final String prefix = getStateStore().getStorageScheme() == StorageScheme.DIRECTORY_BASED ? "" : getName(); return prefix + Integer.toHexString(str.hashCode()); }
public boolean isToSaveProjectName() { if (!isDefault()) { final IProjectStore stateStore = getStateStore(); if (stateStore.getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) { final VirtualFile baseDir = stateStore.getProjectBaseDir(); if (baseDir != null && baseDir.isValid()) { return myOldName != null && !myOldName.equals(getName()); } } } return false; }
@Override public void update(AnActionEvent e) { final Presentation presentation = e.getPresentation(); final Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext()); boolean visible = project != null; if (project instanceof ProjectEx) { visible = ((ProjectEx)project).getStateStore().getStorageScheme() != StorageScheme.DIRECTORY_BASED; } presentation.setVisible(visible); }
private boolean isInDirectoryBasedRoot(final VirtualFile file) { if (file == null) return false; final StorageScheme storageScheme = ((ProjectEx) myProject).getStateStore().getStorageScheme(); if (StorageScheme.DIRECTORY_BASED.equals(storageScheme)) { final VirtualFile baseDir = myProject.getBaseDir(); if (baseDir == null) return false; final VirtualFile ideaDir = baseDir.findChild(Project.DIRECTORY_STORE_FOLDER); return ideaDir != null && ideaDir.isValid() && ideaDir.isDirectory() && VfsUtil.isAncestor(ideaDir, file, false); } return false; }
public boolean isConversionNeeded() throws CannotConvertException { if (myContext.isConversionAlreadyPerformed(myProvider)) return false; myProcessProjectFile = myContext.getStorageScheme() == StorageScheme.DEFAULT && myProjectFileConverter != null && myProjectFileConverter.isConversionNeeded(myContext.getProjectSettings()); myProcessWorkspaceFile = myWorkspaceConverter != null && myContext.getWorkspaceFile().exists() && myWorkspaceConverter.isConversionNeeded(myContext.getWorkspaceSettings()); myModulesFilesToProcess.clear(); if (myModuleFileConverter != null) { for (File moduleFile : myContext.getModuleFiles()) { if (moduleFile.exists() && myModuleFileConverter.isConversionNeeded(myContext.getModuleSettings(moduleFile))) { myModulesFilesToProcess.add(moduleFile); } } } myProcessRunConfigurations = myRunConfigurationsConverter != null && myRunConfigurationsConverter.isConversionNeeded(myContext.getRunManagerSettings()); myProcessProjectLibraries = myProjectLibrariesConverter != null && myProjectLibrariesConverter.isConversionNeeded(myContext.getProjectLibrariesSettings()); return myProcessProjectFile || myProcessWorkspaceFile || myProcessRunConfigurations || myProcessProjectLibraries || !myModulesFilesToProcess.isEmpty() || myConverter.isConversionNeeded(); }
public void updateData(WizardContext context) { StorageScheme format = FILE_BASED.equals(myStorageFormatCombo.getSelectedItem()) ? StorageScheme.DEFAULT : StorageScheme.DIRECTORY_BASED; context.setProjectStorageFormat(format); setDefaultFormat(isDefault()); }
@NotNull public StorageScheme getStorageScheme() { return myWizardContext.getProjectStorageFormat(); }
@NotNull StorageScheme getStorageScheme();
public static boolean isDirectoryBased(@NotNull Project project) { IComponentStore store = ServiceKt.getStateStore(project); return store instanceof IProjectStore && StorageScheme.DIRECTORY_BASED.equals(((IProjectStore)store).getStorageScheme()); }
public void setProjectStorageFormat(StorageScheme format) { myProjectStorageFormat = format; }
public StorageScheme getProjectStorageFormat() { return myProjectStorageFormat; }
@NotNull @Override public StorageScheme getStorageScheme() { return myStorageScheme; }
private void init(final ProjectSdksModel model) { myPanel = new JPanel(new GridBagLayout()); myPanel.setPreferredSize(new Dimension(700, 500)); if (((ProjectEx)myProject).getStateStore().getStorageScheme().equals(StorageScheme.DIRECTORY_BASED)) { final JPanel namePanel = new JPanel(new BorderLayout()); final JLabel label = new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT); namePanel.add(label, BorderLayout.NORTH); myProjectName = new JTextField(); myProjectName.setColumns(40); final JPanel nameFieldPanel = new JPanel(); nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS)); nameFieldPanel.add(Box.createHorizontalStrut(4)); nameFieldPanel.add(myProjectName); namePanel.add(nameFieldPanel, BorderLayout.CENTER); final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT)); wrapper.add(namePanel); wrapper.setAlignmentX(0); myPanel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 0, 10, 0), 0, 0)); } myProjectJdkConfigurable = new ProjectJdkConfigurable(myProject, model); myPanel.add(myProjectJdkConfigurable.createComponent(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(4, 4, 0, 0), 0, 0)); myPanel.add(myWholePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(4, 0, 0, 0), 0, 0)); myProjectCompilerOutput.getTextField().getDocument().addDocumentListener(new DocumentAdapter() { @Override protected void textChanged(DocumentEvent e) { if (myFreeze) return; myModulesConfigurator.processModuleCompilerOutputChanged(getCompilerOutputUrl()); } }); }