1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.nuxeo.build.ant.profile;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23
24 import org.apache.tools.ant.Project;
25
26 import org.nuxeo.build.ant.AntClient;
27
28
29
30
31 public class AntProfileManager {
32
33 protected Map<String, Profile> profiles = new HashMap<>();
34
35 protected List<ProfileGroup> groups = new ArrayList<>();
36
37 public AntProfileManager() {
38 }
39
40 public List<String> getActiveProfiles() {
41 List<String> result = new ArrayList<>();
42 for (Profile p : profiles.values()) {
43 if (p.isActive()) {
44 result.add(p.getName());
45 }
46 }
47 return result;
48 }
49
50 public void addGroup(@SuppressWarnings("hiding") String[] profiles, String defaultProfile) {
51 groups.add(new ProfileGroup(this, profiles, defaultProfile));
52 }
53
54 public void addProfile(Profile profile) {
55 profiles.put(profile.getName(), profile);
56 }
57
58 public boolean isProfileActive(String profileName) {
59 Profile profile = profiles.get(profileName);
60 if (profile != null) {
61 return profile.isActive();
62 }
63 return false;
64 }
65
66 public boolean isAnyProfileActive(List<String> profileNames) {
67 for (String profileName : profileNames) {
68 if (isProfileActive(profileName)) {
69 return true;
70 }
71 }
72 return false;
73 }
74
75 public void activateProfile(String profile, boolean isActive) {
76 if (isActive) {
77 AntClient.getInstance().log("Activating Ant profile: " + profile, Project.MSG_DEBUG);
78 } else {
79 AntClient.getInstance().log("Disabling Ant profile: " + profile, Project.MSG_DEBUG);
80 }
81 getOrCreateProfile(profile).setActive(isActive);
82 }
83
84 public Profile getOrCreateProfile(String profileName) {
85 Profile profile = profiles.get(profileName);
86 if (profile == null) {
87 profile = new Profile(profileName);
88 profiles.put(profileName, profile);
89 }
90 return profile;
91 }
92
93 public void activateProfiles(String config) {
94 String[] ar = config.split("\\s*,\\s*");
95 for (String key : ar) {
96 if (key.startsWith("-")) {
97 activateProfile(key.substring(1), false);
98 } else if (key.startsWith("+")) {
99 activateProfile(key.substring(1), true);
100 } else {
101 activateProfile(key, true);
102 }
103 }
104 }
105
106 }