View Javadoc
1   /*
2    * (C) Copyright 2006-2014 Nuxeo SA (http://nuxeo.com/) and contributors.
3    *
4    * All rights reserved. This program and the accompanying materials
5    * are made available under the terms of the GNU Lesser General Public License
6    * (LGPL) version 2.1 which accompanies this distribution, and is available at
7    * http://www.gnu.org/licenses/lgpl-2.1.html
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * Contributors:
15   *     bstefanescu, jcarsique
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   * TODO NXBT-258
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 }