do not pack library zip of plugin if scope is 'test' or 'provided'
[fedora-idea.git] / plugins / devkit / src / build / PluginBuildUtil.java
blobd9f3e85005d4e5469993fa715813a774bfde773a
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.devkit.build;
18 import com.intellij.openapi.application.ApplicationManager;
19 import com.intellij.openapi.module.Module;
20 import com.intellij.openapi.module.ModuleManager;
21 import com.intellij.openapi.module.StdModuleTypes;
22 import com.intellij.openapi.projectRoots.Sdk;
23 import com.intellij.openapi.roots.*;
24 import com.intellij.openapi.roots.libraries.Library;
25 import com.intellij.openapi.util.Computable;
26 import com.intellij.util.ArrayUtil;
27 import org.jetbrains.annotations.NonNls;
28 import org.jetbrains.annotations.Nullable;
29 import org.jetbrains.idea.devkit.projectRoots.IdeaJdk;
30 import org.jetbrains.idea.devkit.projectRoots.Sandbox;
32 import java.io.File;
33 import java.io.IOException;
34 import java.util.ArrayList;
35 import java.util.Set;
37 /**
38 * User: anna
39 * Date: Nov 24, 2004
41 public class PluginBuildUtil {
42 private PluginBuildUtil() {
45 @NonNls @Nullable public static String getPluginExPath(Module module) {
46 final Sdk jdk = IdeaJdk.findIdeaJdk(ModuleRootManager.getInstance(module).getSdk());
47 if (jdk == null) {
48 return null;
50 String sandboxHome = ((Sandbox)jdk.getSdkAdditionalData()).getSandboxHome();
51 if (sandboxHome == null) return null;
52 try {
53 sandboxHome = new File(sandboxHome).getCanonicalPath();
55 catch (IOException e) {
56 return null;
58 return sandboxHome + File.separator + "plugins" + File.separator + module.getName();
61 public static void getDependencies(Module module, Set<Module> modules) {
62 for (Module dependency : ModuleRootManager.getInstance(module).getDependencies()) {
63 if (dependency.getModuleType() == StdModuleTypes.JAVA) {
64 if (modules.add(dependency)) {
65 getDependencies(dependency, modules);
71 public static Module[] getWrongSetDependencies(final Module module) {
72 return ApplicationManager.getApplication().runReadAction(new Computable<Module[]>() {
73 public Module[] compute() {
74 ArrayList<Module> result = new ArrayList<Module>();
75 final Module[] projectModules = ModuleManager.getInstance(module.getProject()).getModules();
76 for (Module projectModule : projectModules) {
77 if (ArrayUtil.find(ModuleRootManager.getInstance(projectModule).getDependencies(), module) > -1) {
78 result.add(projectModule);
81 return result.toArray(new Module[result.size()]);
83 });
86 public static void getLibraries(Module module, Set<Library> libs) {
87 OrderEntry[] orderEntries = ModuleRootManager.getInstance(module).getOrderEntries();
88 for (OrderEntry orderEntry : orderEntries) {
89 if (orderEntry instanceof LibraryOrderEntry) {
90 LibraryOrderEntry libEntry = (LibraryOrderEntry)orderEntry;
91 Library lib = libEntry.getLibrary();
92 final DependencyScope scope = libEntry.getScope();
93 if (lib == null || (scope != DependencyScope.COMPILE && scope != DependencyScope.RUNTIME)) continue;
94 libs.add(lib);