Search in sources :

Example 96 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-plugins by JetBrains.

the class BndProjectImporter method setupProject.

public void setupProject() {
    LanguageLevel sourceLevel = LanguageLevel.parse(myWorkspace.getProperty(JAVAC_SOURCE));
    if (sourceLevel != null) {
        LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(sourceLevel);
    }
    String targetLevel = myWorkspace.getProperty(JAVAC_TARGET);
    CompilerConfiguration.getInstance(myProject).setProjectBytecodeTarget(targetLevel);
    // compilation options (see Project#getCommonJavac())
    JpsJavaCompilerOptions javacOptions = JavacConfiguration.getOptions(myProject, JavacConfiguration.class);
    javacOptions.DEBUGGING_INFO = booleanProperty(myWorkspace.getProperty("javac.debug", "true"));
    javacOptions.DEPRECATION = booleanProperty(myWorkspace.getProperty("java.deprecation"));
    javacOptions.ADDITIONAL_OPTIONS_STRING = myWorkspace.getProperty("java.options", "");
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) JpsJavaCompilerOptions(org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions)

Example 97 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-plugins by JetBrains.

the class BndProjectImporter method createModule.

private ModifiableRootModel createModule(ModifiableModuleModel moduleModel, Project project, LanguageLevel projectLevel) throws Exception {
    String name = project.getName();
    Module module = moduleModel.findModuleByName(name);
    if (module == null) {
        String path = project.getBase().getPath() + File.separator + name + ModuleFileType.DOT_DEFAULT_EXTENSION;
        module = moduleModel.newModule(path, StdModuleTypes.JAVA.getId());
    }
    ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
    for (ContentEntry entry : rootModel.getContentEntries()) {
        rootModel.removeContentEntry(entry);
    }
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof ModuleJdkOrderEntry || entry instanceof ModuleSourceOrderEntry)) {
            rootModel.removeOrderEntry(entry);
        }
    }
    rootModel.inheritSdk();
    ContentEntry contentEntry = rootModel.addContentEntry(url(project.getBase()));
    for (File src : project.getSourcePath()) {
        contentEntry.addSourceFolder(url(src), false);
    }
    File testSrc = project.getTestSrc();
    if (testSrc != null) {
        contentEntry.addSourceFolder(url(testSrc), true);
    }
    contentEntry.addExcludeFolder(url(project.getTarget()));
    LanguageLevel sourceLevel = LanguageLevel.parse(project.getProperty(JAVAC_SOURCE));
    if (sourceLevel == projectLevel)
        sourceLevel = null;
    rootModel.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(sourceLevel);
    CompilerModuleExtension compilerExt = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerExt.inheritCompilerOutputPath(false);
    compilerExt.setExcludeOutput(true);
    compilerExt.setCompilerOutputPath(url(project.getSrcOutput()));
    compilerExt.setCompilerOutputPathForTests(url(project.getTestOutput()));
    String targetLevel = project.getProperty(JAVAC_TARGET);
    CompilerConfiguration.getInstance(myProject).setBytecodeTargetLevel(module, targetLevel);
    OsmorcFacet facet = OsmorcFacet.getInstance(module);
    if (project.isNoBundles() && facet != null) {
        FacetUtil.deleteFacet(facet);
        facet = null;
    } else if (!project.isNoBundles() && facet == null) {
        facet = FacetUtil.addFacet(module, OsmorcFacetType.getInstance());
    }
    if (facet != null) {
        OsmorcFacetConfiguration facetConfig = facet.getConfiguration();
        facetConfig.setManifestGenerationMode(ManifestGenerationMode.Bnd);
        facetConfig.setBndFileLocation(FileUtil.getRelativePath(path(project.getBase()), path(project.getPropertiesFile()), '/'));
        Map.Entry<String, Attrs> bsn = project.getBundleSymbolicName();
        File bundle = project.getOutputFile(bsn != null ? bsn.getKey() : name, project.getBundleVersion());
        facetConfig.setJarFileLocation(path(bundle), OutputPathType.SpecificOutputPath);
        facetConfig.setDoNotSynchronizeWithMaven(true);
    }
    return rootModel;
}
Also used : Attrs(aQute.bnd.header.Attrs) OsmorcFacetConfiguration(org.osmorc.facet.OsmorcFacetConfiguration) OsmorcFacet(org.osmorc.facet.OsmorcFacet) LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 98 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-plugins by JetBrains.

the class BndProjectImporter method createProjectStructure.

private void createProjectStructure() {
    if (myProject.isDisposed()) {
        return;
    }
    ApplicationManager.getApplication().runWriteAction(() -> {
        LanguageLevel projectLevel = LanguageLevelProjectExtension.getInstance(myProject).getLanguageLevel();
        Map<Project, ModifiableRootModel> rootModels = ContainerUtil.newHashMap();
        ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel();
        LibraryTable.ModifiableModel libraryModel = ProjectLibraryTable.getInstance(myProject).getModifiableModel();
        try {
            for (Project project : myProjects) {
                try {
                    rootModels.put(project, createModule(moduleModel, project, projectLevel));
                } catch (Exception e) {
                    // should not happen, since project.prepare() is already called
                    LOG.error(e);
                }
            }
            for (Project project : myProjects) {
                try {
                    setDependencies(moduleModel, libraryModel, rootModels.get(project), project);
                } catch (Exception e) {
                    // should not happen, since project.prepare() is already called
                    LOG.error(e);
                }
            }
        } finally {
            libraryModel.commit();
            ModifiableModelCommitter.multiCommit(rootModels.values(), moduleModel);
        }
    });
}
Also used : Project(aQute.bnd.build.Project) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) LanguageLevel(com.intellij.pom.java.LanguageLevel) IOException(java.io.IOException)

Aggregations

LanguageLevel (com.intellij.pom.java.LanguageLevel)98 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)21 Nullable (org.jetbrains.annotations.Nullable)14 Module (com.intellij.openapi.module.Module)13 NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)7 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 IOException (java.io.IOException)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Lexer (com.intellij.lexer.Lexer)3 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2