Search in sources :

Example 1 with CompilerProjectExtension

use of com.intellij.openapi.roots.CompilerProjectExtension in project intellij-community by JetBrains.

the class ArtifactUtil method getDefaultArtifactOutputPath.

@Nullable
public static String getDefaultArtifactOutputPath(@NotNull String artifactName, @NotNull final Project project) {
    final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(project);
    if (extension == null)
        return null;
    String outputUrl = extension.getCompilerOutputUrl();
    if (outputUrl == null || outputUrl.length() == 0) {
        final VirtualFile baseDir = project.getBaseDir();
        if (baseDir == null)
            return null;
        outputUrl = baseDir.getUrl() + "/out";
    }
    return VfsUtilCore.urlToPath(outputUrl) + "/artifacts/" + FileUtil.sanitizeFileName(artifactName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CompilerProjectExtension

use of com.intellij.openapi.roots.CompilerProjectExtension in project intellij-community by JetBrains.

the class ProjectOpenProcessorBase method doOpenProject.

@Nullable
public Project doOpenProject(@NotNull VirtualFile virtualFile, Project projectToClose, boolean forceOpenInNewFrame) {
    try {
        getBuilder().setUpdate(false);
        final WizardContext wizardContext = new WizardContext(null);
        if (virtualFile.isDirectory()) {
            final String[] supported = getSupportedExtensions();
            for (VirtualFile file : getFileChildren(virtualFile)) {
                if (canOpenFile(file, supported)) {
                    virtualFile = file;
                    break;
                }
            }
        }
        wizardContext.setProjectFileDirectory(virtualFile.getParent().getPath());
        if (!doQuickImport(virtualFile, wizardContext))
            return null;
        if (wizardContext.getProjectName() == null) {
            if (wizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
                wizardContext.setProjectName(IdeBundle.message("project.import.default.name", getName()) + ProjectFileType.DOT_DEFAULT_EXTENSION);
            } else {
                wizardContext.setProjectName(IdeBundle.message("project.import.default.name.dotIdea", getName()));
            }
        }
        Project defaultProject = ProjectManager.getInstance().getDefaultProject();
        Sdk jdk = ProjectRootManager.getInstance(defaultProject).getProjectSdk();
        if (jdk == null) {
            jdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
        }
        wizardContext.setProjectJdk(jdk);
        final String dotIdeaFilePath = wizardContext.getProjectFileDirectory() + File.separator + Project.DIRECTORY_STORE_FOLDER;
        final String projectFilePath = wizardContext.getProjectFileDirectory() + File.separator + wizardContext.getProjectName() + ProjectFileType.DOT_DEFAULT_EXTENSION;
        File dotIdeaFile = new File(dotIdeaFilePath);
        File projectFile = new File(projectFilePath);
        String pathToOpen;
        if (wizardContext.getProjectStorageFormat() == StorageScheme.DEFAULT) {
            pathToOpen = projectFilePath;
        } else {
            pathToOpen = dotIdeaFile.getParent();
        }
        boolean shouldOpenExisting = false;
        boolean importToProject = true;
        if (projectFile.exists() || dotIdeaFile.exists()) {
            if (ApplicationManager.getApplication().isHeadlessEnvironment()) {
                shouldOpenExisting = true;
                importToProject = true;
            } else {
                String existingName;
                if (dotIdeaFile.exists()) {
                    existingName = "an existing project";
                    pathToOpen = dotIdeaFile.getParent();
                } else {
                    existingName = "'" + projectFile.getName() + "'";
                    pathToOpen = projectFilePath;
                }
                int result = Messages.showYesNoCancelDialog(projectToClose, IdeBundle.message("project.import.open.existing", existingName, projectFile.getParent(), virtualFile.getName()), IdeBundle.message("title.open.project"), IdeBundle.message("project.import.open.existing.openExisting"), IdeBundle.message("project.import.open.existing.reimport"), CommonBundle.message("button.cancel"), Messages.getQuestionIcon());
                if (result == Messages.CANCEL)
                    return null;
                shouldOpenExisting = result == Messages.YES;
                importToProject = !shouldOpenExisting;
            }
        }
        final Project projectToOpen;
        if (shouldOpenExisting) {
            try {
                projectToOpen = ProjectManagerEx.getInstanceEx().loadProject(pathToOpen);
            } catch (Exception e) {
                return null;
            }
        } else {
            projectToOpen = ProjectManagerEx.getInstanceEx().newProject(wizardContext.getProjectName(), pathToOpen, true, false);
        }
        if (projectToOpen == null)
            return null;
        if (importToProject) {
            if (!getBuilder().validate(projectToClose, projectToOpen)) {
                return null;
            }
            projectToOpen.save();
            ApplicationManager.getApplication().runWriteAction(() -> {
                Sdk jdk1 = wizardContext.getProjectJdk();
                if (jdk1 != null) {
                    NewProjectUtil.applyJdkToProject(projectToOpen, jdk1);
                }
                String projectDirPath = wizardContext.getProjectFileDirectory();
                String path = StringUtil.endsWithChar(projectDirPath, '/') ? projectDirPath + "classes" : projectDirPath + "/classes";
                CompilerProjectExtension extension = CompilerProjectExtension.getInstance(projectToOpen);
                if (extension != null) {
                    extension.setCompilerOutputUrl(getUrl(path));
                }
            });
            getBuilder().commit(projectToOpen, null, ModulesProvider.EMPTY_MODULES_PROVIDER);
        }
        if (!forceOpenInNewFrame) {
            NewProjectUtil.closePreviousProject(projectToClose);
        }
        ProjectUtil.updateLastProjectLocation(pathToOpen);
        ProjectManagerEx.getInstanceEx().openProject(projectToOpen);
        return projectToOpen;
    } finally {
        getBuilder().cleanup();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) Project(com.intellij.openapi.project.Project) WizardContext(com.intellij.ide.util.projectWizard.WizardContext) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) File(java.io.File) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CompilerProjectExtension

use of com.intellij.openapi.roots.CompilerProjectExtension in project intellij-plugins by JetBrains.

the class OsgiRunConfigurationEditor method resetEditorFrom.

@Override
protected void resetEditorFrom(@NotNull OsgiRunConfiguration osgiRunConfiguration) {
    myRunConfiguration = osgiRunConfiguration;
    myVmOptions.setText(osgiRunConfiguration.getVmParameters());
    myProgramParameters.setText(osgiRunConfiguration.getProgramParameters());
    myFrameworkInstances.setSelectedItem(osgiRunConfiguration.getInstanceToUse());
    myClassPathAllBundles.setSelected(osgiRunConfiguration.isIncludeAllBundlesInClassPath());
    if (myCurrentRunPropertiesEditor != null) {
        myCurrentRunPropertiesEditor.resetEditorFrom(osgiRunConfiguration);
    }
    // I deliberately set the list of modules as the last step here as
    // the framework specific modules are cleaned out when you change the framework instance
    // so the framework instance should be changed first
    List<SelectedBundle> modules = osgiRunConfiguration.getBundlesToDeploy();
    RunConfigurationTableModel model = getTableModel();
    while (model.getRowCount() > 0) {
        model.removeBundleAt(0);
    }
    for (SelectedBundle module : modules) {
        model.addBundle(module);
    }
    myBundlesTable.getColumnModel().getColumn(1).setPreferredWidth(200);
    myFrameworkStartLevel.setValue(osgiRunConfiguration.getFrameworkStartLevel());
    myDefaultStartLevel.setValue(osgiRunConfiguration.getDefaultStartLevel());
    boolean useUserDefinedFields = !osgiRunConfiguration.isGenerateWorkingDir();
    myWorkingDirField.setText(osgiRunConfiguration.getWorkingDir());
    if (myWorkingDirField.getText().length() == 0) {
        final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(myProject);
        if (extension != null) {
            final VirtualFilePointer outputDirPointer = extension.getCompilerOutputPointer();
            if (outputDirPointer != null) {
                myWorkingDirField.setText(VfsUtilCore.urlToPath(outputDirPointer.getUrl() + "/run.osgi/"));
            }
        }
    }
    myWorkingDirField.setEnabled(useUserDefinedFields);
    myUserDefinedDir.setSelected(useUserDefinedFields);
    myOsmorcControlledDir.setSelected(!useUserDefinedFields);
    myJrePathEditor.setPathOrName(osgiRunConfiguration.getAlternativeJrePath(), osgiRunConfiguration.isUseAlternativeJre());
}
Also used : CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer)

Example 4 with CompilerProjectExtension

use of com.intellij.openapi.roots.CompilerProjectExtension in project android by JetBrains.

the class NewProjectSetupTest method verifyCompilerOutputUrl.

private void verifyCompilerOutputUrl() {
    CompilerProjectExtension compilerProjectExtension = CompilerProjectExtension.getInstance(getProject());
    assertNotNull(compilerProjectExtension);
    assertNotNull(compilerProjectExtension.getCompilerOutputUrl());
}
Also used : CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension)

Example 5 with CompilerProjectExtension

use of com.intellij.openapi.roots.CompilerProjectExtension in project android by JetBrains.

the class NewProjectSetupTest method setUp.

@Override
protected void setUp() throws Exception {
    super.setUp();
    Project project = getProject();
    LanguageLevelProjectExtension.getInstance(project).setLanguageLevel(JDK_1_6);
    CompilerProjectExtension compilerProjectExtension = CompilerProjectExtension.getInstance(project);
    assertNotNull(compilerProjectExtension);
    assertNull(compilerProjectExtension.getCompilerOutputUrl());
    ProjectTypeService.setProjectType(project, null);
    myNewProjectSetup = new NewProjectSetup();
}
Also used : Project(com.intellij.openapi.project.Project) CompilerProjectExtension(com.intellij.openapi.roots.CompilerProjectExtension)

Aggregations

CompilerProjectExtension (com.intellij.openapi.roots.CompilerProjectExtension)6 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IOException (java.io.IOException)2 Nullable (org.jetbrains.annotations.Nullable)2 WizardContext (com.intellij.ide.util.projectWizard.WizardContext)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProjectEx (com.intellij.openapi.project.ex.ProjectEx)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)1 LanguageLevel (com.intellij.pom.java.LanguageLevel)1 File (java.io.File)1