You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Brian Ewins <Br...@i-documentsystems.com> on 2003/02/10 12:47:29 UTC

Sun Binary License stuff.

Hi,
    I was playing with this code to see if I could make a Sun license 
clickthrough for non-redistributable stuff, much discussed this last 
week. The idea was to allow something like this in your maven.xml:

<sun:download artifact="activation-1.1.jar"/>

... which would download the jar from sun and install it in your local 
repo, if you agree to the license. The zip 'bundles' that the jars come 
in should be cached so that multiple jars can be extracted from a bundle 
without multiple downloads/license agreements - eg if you grab the 'XML 
Summer Pack', it contains 5 libraries.
Anyway, I tried to do this in jelly and ran into trouble. I couldn't see 
how to get the zip download saved out to a file, which is trivial in 
java. Anyone got any ideas? The problem area is marked 'FIXME' - you 
should be able to try this code out and see the license for the JAF 
displayed. There's no GUI involved, although clearly Sun's license text 
would make more sense in a GUI.

  <goal name="sun">
      <sun:download artifact="jsf-api-1.0ea2.jar"/>     
  </goal>

  <define:taglib uri="sun">
    <!-- main entry point. request an artifact -->
    <define:tag name="download">
      <j:set var="workDir" value="${maven.home}/sun/work"/>
      <j:set var="bundleDir" value="${maven.home}/sun/bundles"/>
      <!-- identify bundle -->
      <j:choose>
    <j:when test="${artifact=='jsf-api-1.0ea2.jar'}">     
      <!-- here's one I prepared earlier ... the bundleId is the JAF-->
      <!-- but I had JSF sitting round for testing -->
      <j:set var="bundleId" value="7037"/>
      <j:set var="artifactPath" value="jsf1.0ea2/lib/jsf-api.jar"/>
      <j:set var="artifactDirectory" value="jsf"/>
    </j:when>
    <j:otherwise>
      <echo>this failure should be handled better...</echo>
    </j:otherwise>
      </j:choose>
     
      <!-- download bundle if required -->
      <util:file name="${bundleDir}/${bundleId}.zip" var="bundle"/>
      <sun:getBundle bundleId="${bundleId}"
             bundle="${bundle}"/>
      <j:if test="${bundle.exists()}">
    <unzip src="${bundlePath}" dest="${workDir}">
      <patternset>
        <include name="${artifactPath}"/>
      </patternset>
    </unzip>
   
    <mkdir dir="${maven.repo.local}/${artifactDirectory}/jars/"/>
    <move file="${workDir}/${artifactPath}"
          
tofile="${maven.repo.local}/${artifactDirectory}/jars/${artifact}"/>
      </j:if>
    </define:tag>

    <!-- download a bundle if required and the license is agreed. -->
    <define:tag name="getBundle">
      <j:if test="${not(bundle.exists())}">
    <http:session>
      <http:post var="display" 
uri="http://java.sun.com/webapps/download/Display" followRedirects="true">
        <http:parameter name="BundleId" value="${bundleId}"/>
        <http:parameter name="button" value="Continue"/>
      </http:post>
      <j:set var="page" value="${display.responseBodyAsString}"/>
      <!-- read the parameters from the license page -->
         
      <!-- this is a mess, but stuff like indexOf(x,ticketIdStart) didnt 
work -->
      <j:set var="temp" 
value="${page.substring(page.indexOf('TicketId'))}"/>
      <j:set var="temp" 
value="${temp.substring(temp.indexOf('&quot;',9))}"/>
      <j:set var="ticketId" 
value="${temp.substring(1,temp.indexOf('&quot;',1))}"/>
      <echo>ticketId was ${ticketId}</echo>
      <j:set var="temp" value="${page.substring(page.indexOf('Referer'))}"/>
      <j:set var="temp" 
value="${temp.substring(temp.indexOf('&quot;',8))}"/>
      <j:set var="referer" 
value="${temp.substring(1,temp.indexOf('&quot;',1))}"/>
      <echo>referer was ${referer}</echo>
     
      <echo>---------- BEGIN LICENSE ----------</echo>
      <sun:doLicense page="${page}"/>
      <echo>---------- END LICENSE ------------</echo>
     
      <!-- confirm users agreement to the license -->
      <echo>READ THE TERMS ABOVE CAREFULLY.</echo>
      <interaction:ask question="If you agree to these terms, type 'ACCEPT'"
            default="REJECT"
            answer="licenseAccepted"/>
      <j:choose>
        <j:when test="${licenseAccepted=='ACCEPT'}">
          <echo>Downloading zip file</echo>
          <!-- FIXME: doing the http:post dance here is easy. however, -->
          <!-- I dont know how to get the inputstream from -->
          <!-- an http:post response saved into 'bundle' -->
        </j:when>
        <j:otherwise>
          <echo>Download cancelled.</echo>
        </j:otherwise>
      </j:choose>
    </http:session>
      </j:if>
    </define:tag>

    <!-- Display the license page as text -->
    <!-- I kept getting empty documents using the html parser, this is 
fugly but works -->
    <define:tag name="doLicense">
      <!-- display the license. -->
      <j:set var="text" value="${page.substring(page.indexOf('&lt;!-- 
START license insert --&gt;'))}"/>
      <j:set var="text" value="${text.substring(0,text.indexOf('&lt;!-- 
END license insert --&gt;'))}"/>
      <sun:doMixed text="${text}"/>
    </define:tag>
   
    <!-- recursively remove markup from the license -->
    <define:tag name="doMixed">
      <j:choose>
    <j:when test="${text.indexOf('&lt;') != '-1'}">
      <sun:doText text="${text.substring(0,text.indexOf('&lt;'))}"/>
      <sun:doTag text="${text.substring(text.indexOf('&lt;'))}"/>
    </j:when>
    <j:otherwise>
      <sun:doText text="${text}"/>
    </j:otherwise>
      </j:choose>
    </define:tag>

    <!-- recursively remove markup from the license -->
    <define:tag name="doText">
      <j:choose>
    <j:when test="${text.indexOf('&amp;') != 
'-1'}">${text.substring(0,text.indexOf('&amp;'))}<sun:doEntity 
text="${text.substring(text.indexOf('&amp;'))}"/>
    </j:when>
    <j:otherwise>${text}</j:otherwise>
      </j:choose>
    </define:tag>

    <!-- recursively remove markup from the license -->
    <define:tag name="doTag">
      <sun:doMixed 
text="${text.substring(text.indexOf('&gt;')).substring(1)}"/>
    </define:tag>

    <!-- recursively remove markup from the license -->
    <define:tag name="doEntity">
      <j:choose>
    <j:when test="${text.startsWith('&amp;quot;')}">${'"'}<sun:doText 
text="${text.substring(6)}"/>
    </j:when>
    <j:when test="${text.startsWith('&amp;nbsp;')}">${' '}<sun:doText 
text="${text.substring(6)}"/>
    </j:when>
    <j:when test="${text.startsWith('&amp;copy;')}">${'(c)'}<sun:doText 
text="${text.substring(6)}"/>
    </j:when>
    <j:when test="${text.startsWith('&amp;apos;')}">${"'"}<sun:doText 
text="${text.substring(6)}"/>
    </j:when>
      </j:choose>
    </define:tag>

  </define:taglib>






Privacy and Confidentiality Notice

------------------------------------------------

The information contained in this E-Mail message is intended only for the person or persons to whom it is addressed.  Such information is confidential and privileged and no mistake in transmission is intended to waive or compromise such privilege.  If you have received it in error, please destroy it and notify us on the telephone number printed above.  If you do not receive complete and legible copies, please telephone us immediately. Any opinions expressed herein including attachments are those of the author only. i-documentsystems Ltd. does not accept responsibility for the accuracy or completeness of the information provided or for any changes to this Email, however made, after it was sent. (Please note that it is your responsibility to scan this message for viruses).