1. /*
  2. * Copyright 2002-2004 The Apache Software Foundation
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. *
  16. */
  17. /*
  18. * Since the initial version of this file was deveolped on the clock on
  19. * an NSF grant I should say the following boilerplate:
  20. *
  21. * This material is based upon work supported by the National Science
  22. * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
  23. * conclusions or recommendations expressed in this material are those
  24. * of the author and do not necessarily reflect the views of the
  25. * National Science Foundation.
  26. */
  27. package org.apache.tools.ant.taskdefs.optional.unix;
  28. import org.apache.tools.ant.BuildException;
  29. /**
  30. * Chgrp equivalent for unix-like environments.
  31. *
  32. *
  33. * @since Ant 1.6
  34. *
  35. * @ant.task category="filesystem"
  36. */
  37. public class Chgrp extends AbstractAccessTask {
  38. private boolean haveGroup = false;
  39. /**
  40. * Chgrp task for setting unix group of a file.
  41. */
  42. public Chgrp() {
  43. super.setExecutable("chgrp");
  44. }
  45. /**
  46. * Set the group atribute.
  47. *
  48. * @param group The new group for the file(s) or directory(ies)
  49. */
  50. public void setGroup(String group) {
  51. createArg().setValue(group);
  52. haveGroup = true;
  53. }
  54. /**
  55. * Ensure that all the required arguments and other conditions have
  56. * been set.
  57. */
  58. protected void checkConfiguration() {
  59. if (!haveGroup) {
  60. throw new BuildException("Required attribute group not set in "
  61. + "chgrp", getLocation());
  62. }
  63. super.checkConfiguration();
  64. }
  65. /**
  66. * We don't want to expose the executable atribute, so overide it.
  67. *
  68. * @param e User supplied executable that we won't accept.
  69. */
  70. public void setExecutable(String e) {
  71. throw new BuildException(getTaskType()
  72. + " doesn\'t support the executable"
  73. + " attribute", getLocation());
  74. }
  75. }