PageRenderTime 41ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ant/src/org/apache/hadoop/hive/ant/GetVersionPref.java

#
Java | 94 lines | 41 code | 14 blank | 39 comment | 4 complexity | 9867398c0bd8921213e37848b25a0563 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. package org.apache.hadoop.hive.ant;
  19. import org.apache.tools.ant.AntClassLoader;
  20. import org.apache.tools.ant.BuildException;
  21. import org.apache.tools.ant.Task;
  22. import org.apache.tools.ant.Project;
  23. import java.util.regex.Pattern;
  24. import java.util.regex.Matcher;
  25. import java.io.*;
  26. /**
  27. * Implementation of the ant task <getversionpref property="nameoftheproperty" input="versionstring"/>.
  28. *
  29. * This ant task takes an input version string (e.g. 0.17.2) and set an ant property (whose name
  30. * is specified in the property attribute) with the version prefix. For 0.17.2, the version prefix
  31. * is 0.17. Similarly, for 0.18.0, the version prefix is 0.18. The version prefix is the first two
  32. * components of the version string.
  33. */
  34. public class GetVersionPref extends Task {
  35. /**
  36. * The name of the property that gets the version prefix.
  37. */
  38. protected String property;
  39. /**
  40. * The input string that contains the version string.
  41. */
  42. protected String input;
  43. public void setProperty(String property) {
  44. this.property = property;
  45. }
  46. public String getProperty() {
  47. return property;
  48. }
  49. public void setInput(String input) {
  50. this.input = input;
  51. }
  52. public String getInput() {
  53. return input;
  54. }
  55. /**
  56. * Executes the ant task <getversionperf>.
  57. *
  58. * It extracts the version prefix using regular expressions on the version string. It then sets
  59. * the property in the project with the extracted prefix. The property is set to an empty string
  60. * in case no match is found for the prefix regular expression (which will happen in case the
  61. * version string does not conform to the version format).
  62. */
  63. @Override
  64. public void execute() throws BuildException {
  65. if (property == null) {
  66. throw new BuildException("No property specified");
  67. }
  68. if (input == null) {
  69. throw new BuildException("No input stringspecified");
  70. }
  71. try {
  72. Pattern p = Pattern.compile("^(\\d+\\.\\d+).*");
  73. Matcher m = p.matcher(input);
  74. getProject().setProperty(property, m.matches() ? m.group(1) : "");
  75. }
  76. catch (Exception e) {
  77. throw new BuildException("Failed with: " + e.getMessage());
  78. }
  79. }
  80. }