protected Module createModule(final String name) { final Module module = super.createModule(name); final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel(); final LibraryTable.ModifiableModel modifiableModel = model.getModuleLibraryTable().getModifiableModel(); final Library library = modifiableModel.createLibrary("junit"); final Library.ModifiableModel libModel = library.getModifiableModel(); libModel.addRoot( VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))), OrderRootType.CLASSES); libModel.commit(); model.commit(); return module; }
public Library createOrGetXtendJavaLibrary( final ModifiableRootModel rootModel, final Module module) { LibraryTablesRegistrar _instance = LibraryTablesRegistrar.getInstance(); Project _project = module.getProject(); LibraryTable _libraryTable = _instance.getLibraryTable(_project); Library[] _libraries = _libraryTable.getLibraries(); LibraryTablesRegistrar _instance_1 = LibraryTablesRegistrar.getInstance(); LibraryTable _libraryTable_1 = _instance_1.getLibraryTable(); Library[] _libraries_1 = _libraryTable_1.getLibraries(); final Iterable<Library> libraryTable = Iterables.<Library>concat( ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries)), ((Iterable<? extends Library>) Conversions.doWrapArray(_libraries_1))); final Function1<Library, Boolean> _function = new Function1<Library, Boolean>() { @Override public Boolean apply(final Library it) { String _name = it.getName(); boolean _startsWith = false; if (_name != null) { _startsWith = _name.startsWith(XtendLibraryDescription.XTEND_LIBRARY_NAME); } return Boolean.valueOf(_startsWith); } }; final Iterable<Library> xtendLibs = IterableExtensions.<Library>filter(libraryTable, _function); boolean _isEmpty = IterableExtensions.isEmpty(xtendLibs); boolean _not = (!_isEmpty); if (_not) { final Function1<Library, Boolean> _function_1 = new Function1<Library, Boolean>() { @Override public Boolean apply(final Library it) { String _name = it.getName(); return Boolean.valueOf( Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME)); } }; boolean _exists = IterableExtensions.<Library>exists(xtendLibs, _function_1); if (_exists) { final Function1<Library, Boolean> _function_2 = new Function1<Library, Boolean>() { @Override public Boolean apply(final Library it) { String _name = it.getName(); return Boolean.valueOf( Objects.equal(_name, XtendLibraryDescription.XTEND_LIBRARY_NAME)); } }; return IterableExtensions.<Library>findFirst(xtendLibs, _function_2); } else { return IterableExtensions.<Library>head(xtendLibs); } } else { final NewLibraryConfiguration libDescr = this.xtendLibDescr.createLibraryDescription(); LibraryTable _moduleLibraryTable = rootModel.getModuleLibraryTable(); final LibraryTable.ModifiableModel model = _moduleLibraryTable.getModifiableModel(); String _defaultLibraryName = libDescr.getDefaultLibraryName(); final Library createdLib = model.createLibrary(_defaultLibraryName); final Library.ModifiableModel libModel = createdLib.getModifiableModel(); HashMap<OrderRootType, List<String>> _libraryRoots = this.xtendLibDescr.libraryRoots(); final Procedure2<OrderRootType, List<String>> _function_3 = new Procedure2<OrderRootType, List<String>>() { @Override public void apply(final OrderRootType type, final List<String> roots) { final Procedure1<String> _function = new Procedure1<String>() { @Override public void apply(final String it) { libModel.addRoot(it, type); } }; IterableExtensions.<String>forEach(roots, _function); } }; MapExtensions.<OrderRootType, List<String>>forEach(_libraryRoots, _function_3); libModel.commit(); model.commit(); return createdLib; } }