private static Collection<? extends PackagingSourceItem> createClasspathItems(
      ArtifactEditorContext editorContext, Artifact artifact, @NotNull Module module) {
    final List<PackagingSourceItem> items = new ArrayList<PackagingSourceItem>();
    final ModuleRootModel rootModel = editorContext.getModulesProvider().getRootModel(module);
    List<Library> libraries = new ArrayList<Library>();
    for (OrderEntry orderEntry : rootModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryEntry = (LibraryOrderEntry) orderEntry;
        final Library library = libraryEntry.getLibrary();
        final DependencyScope scope = libraryEntry.getScope();
        if (library != null && scope.isForProductionRuntime()) {
          libraries.add(library);
        }
      }
    }

    for (Module toAdd : getNotAddedModules(editorContext, artifact, module)) {
      items.add(new ModuleOutputSourceItem(toAdd));
    }

    for (Library library : getNotAddedLibraries(editorContext, artifact, libraries)) {
      items.add(new LibrarySourceItem(library));
    }
    return items;
  }
Exemple #2
0
 private static void assertModuleLibDepPath(
     LibraryOrderEntry lib, OrderRootType type, List<String> paths) {
   if (paths == null) return;
   assertUnorderedPathsAreEqual(Arrays.asList(lib.getRootUrls(type)), paths);
   // also check the library because it may contain slight different set of urls (e.g. with
   // duplicates)
   assertUnorderedPathsAreEqual(Arrays.asList(lib.getLibrary().getUrls(type)), paths);
 }
 private void syncExistingAndRemoveObsolete(
     @NotNull IdeModifiableModelsProvider modelsProvider,
     @NotNull Map<Set<String>, LibraryDependencyData> moduleLibrariesToImport,
     @NotNull Map<String, LibraryDependencyData> projectLibrariesToImport,
     @NotNull Set<LibraryDependencyData> toImport,
     @NotNull Map<OrderEntry, OrderAware> orderEntryDataMap,
     @NotNull ModifiableRootModel moduleRootModel,
     boolean hasUnresolvedLibraries) {
   for (OrderEntry entry : moduleRootModel.getOrderEntries()) {
     if (entry instanceof ModuleLibraryOrderEntryImpl) {
       ModuleLibraryOrderEntryImpl moduleLibraryOrderEntry = (ModuleLibraryOrderEntryImpl) entry;
       Library library = moduleLibraryOrderEntry.getLibrary();
       if (library == null) {
         LOG.warn(
             "Skipping module-level library entry because it doesn't have backing Library object. Entry: "
                 + entry);
         continue;
       }
       final VirtualFile[] libraryFiles = library.getFiles(OrderRootType.CLASSES);
       final Set<String> moduleLibraryKey = ContainerUtilRt.newHashSet(libraryFiles.length);
       for (VirtualFile file : libraryFiles) {
         moduleLibraryKey.add(
             ExternalSystemApiUtil.getLocalFileSystemPath(file)
                 + moduleLibraryOrderEntry.getScope().name());
       }
       LibraryDependencyData existing = moduleLibrariesToImport.remove(moduleLibraryKey);
       if (existing == null || !StringUtil.equals(existing.getInternalName(), library.getName())) {
         moduleRootModel.removeOrderEntry(entry);
       } else {
         orderEntryDataMap.put(entry, existing);
         syncExistingLibraryDependency(
             modelsProvider,
             existing,
             library,
             moduleRootModel,
             moduleLibraryOrderEntry.getOwnerModule());
         toImport.remove(existing);
       }
     } else if (entry instanceof LibraryOrderEntry) {
       LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
       String libraryName = libraryOrderEntry.getLibraryName();
       LibraryDependencyData existing =
           projectLibrariesToImport.remove(libraryName + libraryOrderEntry.getScope().name());
       if (existing != null) {
         toImport.remove(existing);
         orderEntryDataMap.put(entry, existing);
       } else if (!hasUnresolvedLibraries) {
         // There is a possible case that a project has been successfully imported from external
         // model and after
         // that network/repo goes down. We don't want to drop existing binary mappings then.
         moduleRootModel.removeOrderEntry(entry);
       }
     }
   }
 }
 private static void setLibraryScope(
     @NotNull LibraryOrderEntry orderEntry,
     @NotNull Library lib,
     @NotNull Module module,
     @NotNull LibraryDependencyData dependencyData) {
   orderEntry.setExported(dependencyData.isExported());
   orderEntry.setScope(dependencyData.getScope());
   LOG.debug(
       String.format(
           "Configuring library '%s' of module '%s' to be%s exported and have scope %s",
           lib,
           module.getName(),
           dependencyData.isExported() ? " not" : "",
           dependencyData.getScope()));
 }
 private void importMissing(
     @NotNull Set<LibraryDependencyData> toImport,
     @NotNull ModifiableRootModel moduleRootModel,
     @NotNull LibraryTable moduleLibraryTable,
     @NotNull LibraryTable libraryTable,
     @NotNull Module module) {
   for (LibraryDependencyData dependencyData : toImport) {
     LibraryData libraryData = dependencyData.getTarget();
     if (libraryData.isUnresolved()) {
       continue;
     }
     switch (dependencyData.getLevel()) {
       case MODULE:
         @SuppressWarnings("ConstantConditions")
         Library moduleLib = moduleLibraryTable.createLibrary(dependencyData.getName());
         Library.ModifiableModel libModel = moduleLib.getModifiableModel();
         try {
           Map<OrderRootType, Collection<File>> files =
               myLibraryManager.prepareLibraryFiles(libraryData);
           myLibraryManager.registerPaths(files, libModel, dependencyData.getName());
         } finally {
           libModel.commit();
         }
         break;
       case PROJECT:
         final Library projectLib = libraryTable.getLibraryByName(dependencyData.getName());
         if (projectLib == null) {
           assert false;
           continue;
         }
         LibraryOrderEntry orderEntry = moduleRootModel.addLibraryEntry(projectLib);
         LOG.info(
             String.format(
                 "Adding library dependency '%s' to module '%s'",
                 projectLib.getName(), module.getName()));
         orderEntry.setExported(dependencyData.isExported());
         orderEntry.setScope(dependencyData.getScope());
         LOG.info(
             String.format(
                 "Configuring library dependency '%s' of module '%s' to be%s exported and have scope %s",
                 projectLib.getName(),
                 module.getName(),
                 dependencyData.isExported() ? " not" : "",
                 dependencyData.getScope()));
     }
   }
 }
 @Nullable
 private static LibraryOrderEntry findLibraryOrderEntry(
     @NotNull ModifiableRootModel moduleRootModel,
     @NotNull Library library,
     @NotNull DependencyScope scope) {
   LibraryOrderEntry candidate = null;
   for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) {
     if (orderEntry instanceof LibraryOrderEntry) {
       final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
       if (library == libraryOrderEntry.getLibrary()) {
         return libraryOrderEntry;
       }
       if (library.equals(libraryOrderEntry.getLibrary())) {
         if (libraryOrderEntry.getScope() == scope) {
           return libraryOrderEntry;
         } else {
           candidate = libraryOrderEntry;
         }
       }
     }
   }
   return candidate;
 }
Exemple #7
0
 protected void assertModuleLibDepScope(String moduleName, String depName, DependencyScope scope) {
   LibraryOrderEntry dep = getModuleLibDep(moduleName, depName);
   assertEquals(scope, dep.getScope());
 }
 public LibraryRuntimeClasspathScope(Project project, LibraryOrderEntry entry) {
   super(project);
   myIndex = ProjectRootManager.getInstance(project).getFileIndex();
   Collections.addAll(myEntries, entry.getFiles(BinariesOrderRootType.getInstance()));
 }