Search in sources :

Example 1 with MockJdkWrapper

use of com.intellij.openapi.projectRoots.impl.MockJdkWrapper in project intellij-community by JetBrains.

the class JavaModuleFixtureBuilderImpl method initModule.

@Override
protected void initModule(final Module module) {
    super.initModule(module);
    ModuleRootModificationUtil.updateModel(module, model -> {
        LibraryTable libraryTable = model.getModuleLibraryTable();
        for (Lib lib : myLibraries) {
            Library library = libraryTable.createLibrary(lib.getName());
            Library.ModifiableModel libraryModel = library.getModifiableModel();
            boolean success = false;
            try {
                for (OrderRootType rootType : OrderRootType.getAllTypes()) {
                    for (String root : lib.getRoots(rootType)) {
                        VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(root);
                        if (vRoot != null && OrderRootType.CLASSES.equals(rootType) && !vRoot.isDirectory()) {
                            VirtualFile jar = JarFileSystem.getInstance().refreshAndFindFileByPath(root + "!/");
                            if (jar != null) {
                                vRoot = jar;
                            }
                        }
                        if (vRoot != null) {
                            libraryModel.addRoot(vRoot, rootType);
                        }
                    }
                }
                success = true;
            } finally {
                if (!success) {
                    Disposer.dispose(libraryModel);
                }
            }
            libraryModel.commit();
        }
        final Sdk jdk;
        if (myJdk != null) {
            VfsRootAccess.allowRootAccess(module, myJdk);
            jdk = JavaSdk.getInstance().createJdk(module.getName() + "_jdk", myJdk, false);
            ((ProjectJdkImpl) jdk).setVersionString(StringUtil.notNullize(IdeaTestUtil.getMockJdkVersion(myJdk), "java 1.5"));
        } else {
            jdk = IdeaTestUtil.getMockJdk17();
        }
        model.setSdk(new MockJdkWrapper(CompilerConfigurationImpl.getTestsExternalCompilerHome(), jdk));
        if (myLanguageLevel != null) {
            model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
        } else if (myMockJdkLevel == MockJdkLevel.jdk15) {
            model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_5);
        }
    });
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        if (entry instanceof LibraryOrderEntry) {
            Library library = ((LibraryOrderEntry) entry).getLibrary();
            libraryCreated(library, module);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) MockJdkWrapper(com.intellij.openapi.projectRoots.impl.MockJdkWrapper) Library(com.intellij.openapi.roots.libraries.Library) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 MockJdkWrapper (com.intellij.openapi.projectRoots.impl.MockJdkWrapper)1 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1