Search in sources :

Example 1 with EclipseClasspathStorageProvider

use of org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider in project intellij-community by JetBrains.

the class EclipseClasspathTest method setUpModule.

static Module setUpModule(final String path, @NotNull final Project project) throws Exception {
    final File classpathFile = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
    String fileText = FileUtil.loadFile(classpathFile).replaceAll("\\$ROOT\\$", project.getBaseDir().getPath());
    if (!SystemInfo.isWindows) {
        fileText = fileText.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
    }
    final Element classpathElement = JDOMUtil.load(fileText);
    final Module module = WriteCommandAction.runWriteCommandAction(null, (Computable<Module>) () -> {
        String imlPath = path + "/" + EclipseProjectFinder.findProjectName(path) + ModuleManagerImpl.IML_EXTENSION;
        return ModuleManager.getInstance(project).newModule(imlPath, StdModuleTypes.JAVA.getId());
    });
    ModuleRootModificationUtil.updateModel(module, model -> {
        try {
            EclipseClasspathReader classpathReader = new EclipseClasspathReader(path, project, null);
            classpathReader.init(model);
            classpathReader.readClasspath(model, classpathElement);
            new EclipseClasspathStorageProvider().assertCompatible(model);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    return module;
}
Also used : EclipseClasspathStorageProvider(org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider) Element(org.jdom.Element) EclipseClasspathReader(org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JDOMException(org.jdom.JDOMException) IOException(java.io.IOException)

Aggregations

Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 IOException (java.io.IOException)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 EclipseClasspathStorageProvider (org.jetbrains.idea.eclipse.config.EclipseClasspathStorageProvider)1 EclipseClasspathReader (org.jetbrains.idea.eclipse.conversion.EclipseClasspathReader)1