get-m2.xml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?xml version="1.0"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  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. Build file to fetch maven2 tasks; extracted from (Ant's) fetch.xml
  19. =======================================================================
  20. -->
  21. <project name="get-m2" default="get-m2" basedir=".">
  22. <description>
  23. This build file downloads the Maven2 Ant tasks,
  24. and installs them in the location specified by the m2.dest.dir property.
  25. You may need to set proxy settings. On Java1.5, Ant tries to get
  26. this from the OS, unless you use the -noproxy option.
  27. Proxies can be configured manually setting the JVM proxy values in the
  28. ANT_OPTS environment variable.
  29. For example, to set the proxy up in the tcsh shell, the command would be
  30. something like:
  31. For csh/tcsh:
  32. setenv ANT_OPTS "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080"
  33. For bash:
  34. export ANT_OPTS="-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080"
  35. For Windows, set the environment variable in the appropriate dialog box
  36. and open a new console. or, by hand
  37. set ANT_OPTS = -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080
  38. </description>
  39. <property file="get-m2.properties" />
  40. <property name="m2.antlib.resource"
  41. value="org/apache/maven/artifact/ant/antlib.xml" />
  42. <property name="m2.antlib.uri"
  43. value="antlib:org.apache.maven.artifact.ant" />
  44. <macrodef name="require">
  45. <attribute name="property" />
  46. <sequential>
  47. <fail unless="@{property}">$${@{property}} not specified</fail>
  48. </sequential>
  49. </macrodef>
  50. <target name="probe-m2">
  51. <require property="m2.dest.dir" />
  52. <require property="m2.jar.name" />
  53. <!-- Look for M2 ant tasks in our classpath-->
  54. <property name="m2.artifact" location="${m2.dest.dir}/${m2.jar.name}" />
  55. <available property="m2.antlib.found" resource="${m2.antlib.resource}" />
  56. <condition property="m2.antlib.typefound">
  57. <typefound name="${m2.antlib.uri}:artifact" />
  58. </condition>
  59. <available property="m2.artifact.found" file="${m2.artifact}" type="file" />
  60. </target>
  61. <target name="download-m2" depends="probe-m2" unless="m2.artifact.found">
  62. <require property="m2.antlib.url" />
  63. <echo>Downloading to ${m2.dest.dir}</echo>
  64. <mkdir dir="${m2.dest.dir}" />
  65. <!-- fetch M2 ant tasks into our repository, if it is not there-->
  66. <get src="${m2.antlib.url}"
  67. dest="${m2.artifact}"
  68. verbose="true"
  69. usetimestamp="false" />
  70. </target>
  71. <target name="dont-validate-m2-checksum" depends="probe-m2"
  72. if="m2.artifact.found">
  73. <property name="checksum.equal" value="true" />
  74. </target>
  75. <target name="validate-m2-checksum"
  76. depends="download-m2,dont-validate-m2-checksum"
  77. if="m2.sha1.checksum" unless="m2.artifact.found">
  78. <checksum file="${m2.artifact}"
  79. algorithm="SHA"
  80. property="${m2.sha1.checksum}"
  81. verifyProperty="checksum.equal" />
  82. </target>
  83. <target name="checksum-mismatch" depends="validate-m2-checksum"
  84. if="m2.sha1.checksum" unless="checksum.equal">
  85. <delete file="${m2.artifact}" />
  86. <fail>
  87. Failed to verify the downloaded file ${m2.antlib.url}" against the checksum
  88. coded into libraries.properties.
  89. The local copy has been deleted, for security reasons
  90. </fail>
  91. </target>
  92. <target name="checksum-match" depends="checksum-mismatch"
  93. unless="m2.antlib.found">
  94. <taskdef classpath="${m2.artifact}" resource="${m2.antlib.resource}"
  95. uri="${m2.antlib.uri}" />
  96. </target>
  97. <target name="get-m2" depends="checksum-match"
  98. description="Download the Maven2 Ant tasks" />
  99. </project>