From 9b6947ff11202ef6a87bcd8d03572ee591841453 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 12 Sep 2017 15:11:51 +0300 Subject: [PATCH] [java] extends project model modifier API with an ability to add exported dependencies --- .../roots/impl/IdeaProjectModelModifier.java | 2 +- .../openapi/roots/impl/OrderEntryUtil.java | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/java/java-impl/src/com/intellij/openapi/roots/impl/IdeaProjectModelModifier.java b/java/java-impl/src/com/intellij/openapi/roots/impl/IdeaProjectModelModifier.java index 1f1e3c5beb89..1429d2a71f96 100644 --- a/java/java-impl/src/com/intellij/openapi/roots/impl/IdeaProjectModelModifier.java +++ b/java/java-impl/src/com/intellij/openapi/roots/impl/IdeaProjectModelModifier.java @@ -64,7 +64,7 @@ public class IdeaProjectModelModifier extends JavaProjectModelModifier { @Override public Promise addLibraryDependency(@NotNull Module from, @NotNull Library library, @NotNull DependencyScope scope, boolean exported) { - OrderEntryUtil.addLibraryToRoots(from, library); + OrderEntryUtil.addLibraryToRoots(from, library, scope, exported); return Promises.resolvedPromise(null); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java index 1e6350e97211..265fd03a1137 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/OrderEntryUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2016 JetBrains s.r.o. + * Copyright 2000-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.openapi.roots.impl; import com.intellij.openapi.module.Module; @@ -32,8 +31,7 @@ import java.util.ArrayList; import java.util.List; public class OrderEntryUtil { - private OrderEntryUtil() { - } + private OrderEntryUtil() { } @Nullable public static LibraryOrderEntry findLibraryOrderEntry(@NotNull ModuleRootModel model, @Nullable Library library) { @@ -137,9 +135,13 @@ public class OrderEntryUtil { } public static void addLibraryToRoots(@NotNull Module module, @NotNull Library library) { - final ModuleRootManager manager = ModuleRootManager.getInstance(module); - final ModifiableRootModel rootModel = manager.getModifiableModel(); + addLibraryToRoots(module, library, DependencyScope.COMPILE, false); + } + public static void addLibraryToRoots(@NotNull Module module, @NotNull Library library, @NotNull DependencyScope scope, boolean exported) { + final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel(); + + final LibraryOrderEntry entry; if (library.getTable() == null) { final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary(); final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel(); @@ -150,10 +152,17 @@ public class OrderEntryUtil { } } libraryModel.commit(); + entry = rootModel.findLibraryOrderEntry(jarLibrary); } else { - rootModel.addLibraryEntry(library); + entry = rootModel.addLibraryEntry(library); } + + if (entry != null) { + entry.setScope(scope); + entry.setExported(exported); + } + rootModel.commit(); }