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. package org.apache.tools.ant.types.selectors;
  18. import java.io.File;
  19. /**
  20. * Selector that filters files based on whether they are newer than
  21. * a matching file in another directory tree. It can contain a mapper
  22. * element, so isn't available as an ExtendSelector (since those
  23. * parameters can't hold other elements).
  24. *
  25. * @since 1.5
  26. */
  27. public class DependSelector extends MappingSelector {
  28. /**
  29. * Creates a new <code>DependSelector</code> instance.
  30. *
  31. */
  32. public DependSelector() {
  33. }
  34. /**
  35. * @return a string describing this object
  36. */
  37. public String toString() {
  38. StringBuffer buf = new StringBuffer("{dependselector targetdir: ");
  39. if (targetdir == null) {
  40. buf.append("NOT YET SET");
  41. } else {
  42. buf.append(targetdir.getName());
  43. }
  44. buf.append(" granularity: ");
  45. buf.append(granularity);
  46. if (map != null) {
  47. buf.append(" mapper: ");
  48. buf.append(map.toString());
  49. } else if (mapperElement != null) {
  50. buf.append(" mapper: ");
  51. buf.append(mapperElement.toString());
  52. }
  53. buf.append("}");
  54. return buf.toString();
  55. }
  56. /**
  57. * this test is our selection test that compared the file with the destfile
  58. * @param srcfile the source file
  59. * @param destfile the destination file
  60. * @return true if destination is out of date
  61. */
  62. public boolean selectionTest(File srcfile, File destfile) {
  63. boolean selected = SelectorUtils.isOutOfDate(srcfile, destfile,
  64. granularity);
  65. return selected;
  66. }
  67. }