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 org.apache.tools.ant.BuildException;
20 import org.apache.tools.ant.Task;
21 import org.apache.tools.ant.taskdefs.Sequential;
22 import org.nuxeo.build.maven.AntBuildMojo;
23
24
25
26
27 public class ProfileTask extends Sequential {
28
29 public String name;
30
31 public String activate;
32
33 public String group;
34
35 public String defaultProfile;
36
37 public void setName(String name) {
38 if (activate != null) {
39 throw new BuildException("Name and activate properties are exclusive. You cannot specify both.");
40 }
41 if (group != null) {
42 throw new BuildException("group and name properties are exclusive. You cannot specify both.");
43 }
44 if (defaultProfile != null) {
45 throw new BuildException("Default and name properties are exclusive. You cannot specify both.");
46 }
47 this.name = name;
48 }
49
50 public void setActivate(String activate) {
51 if (name != null) {
52 throw new BuildException("Name and activate properties are exclusive. You cannot specify both.");
53 }
54 if (group != null) {
55 throw new BuildException("group and activate properties are exclusive. You cannot specify both.");
56 }
57 if (defaultProfile != null) {
58 throw new BuildException("Default and activate properties are exclusive. You cannot specify both.");
59 }
60 this.activate = activate;
61 }
62
63 public void setGroup(String group) {
64 if (name != null) {
65 throw new BuildException("Group and name properties are exclusive. You cannot specify both.");
66 }
67 if (activate != null) {
68 throw new BuildException("Group and activate properties are exclusive. You cannot specify both.");
69 }
70 this.group = group;
71 }
72
73 public void setDefault(String defaultProfile) {
74 if (name != null) {
75 throw new BuildException("default and name properties are exclusive. You cannot specify both.");
76 }
77 if (activate != null) {
78 throw new BuildException("default and activate properties are exclusive. You cannot specify both.");
79 }
80 this.defaultProfile = defaultProfile;
81 }
82
83 @Override
84 public void addTask(Task nestedTask) {
85 if (activate != null) {
86 throw new BuildException("Cannot use nested elements when specifying activate attribute.");
87 }
88 super.addTask(nestedTask);
89 }
90
91 @Override
92 public void execute() throws BuildException {
93 AntProfileManager mgr = AntBuildMojo.getInstance().getAntProfileManager();
94 if (mgr.isProfileActive(name)) {
95 super.execute();
96 } else if (group != null) {
97 String[] profiles = group.split("\\s*,\\s*");
98 mgr.addGroup(profiles, activate);
99 } else if (activate != null) {
100 mgr.activateProfiles(activate);
101 }
102 }
103
104 }