1. /*
  2. * Copyright 2001-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. package org.apache.tools.ant.taskdefs.condition;
  18. import org.apache.tools.ant.BuildException;
  19. import org.apache.tools.ant.ProjectComponent;
  20. /**
  21. * Condition that tests whether a given property has been set.
  22. *
  23. * @since Ant 1.5
  24. * @version $Revision: 1.7.2.4 $
  25. */
  26. public class IsSet extends ProjectComponent implements Condition {
  27. private String property;
  28. /**
  29. * Set the property attribute
  30. *
  31. * @param p the property name
  32. */
  33. public void setProperty(String p) {
  34. property = p;
  35. }
  36. /**
  37. * @return true if the property exists
  38. * @exception BuildException if the property attribute is not set
  39. */
  40. public boolean eval() throws BuildException {
  41. if (property == null) {
  42. throw new BuildException("No property specified for isset "
  43. + "condition");
  44. }
  45. return getProject().getProperty(property) != null;
  46. }
  47. }