Browse Source

Bugzilla 35619: remove dependency on sun internal base64 encoder

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@440476 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 19 years ago
parent
commit
52831c9ad4
7 changed files with 129 additions and 91 deletions
  1. +2
    -1
      CONTRIBUTORS
  2. +2
    -0
      WHATSNEW
  3. +0
    -10
      build.xml
  4. +8
    -4
      contributors.xml
  5. +6
    -74
      src/main/org/apache/tools/ant/taskdefs/Get.java
  6. +5
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java
  7. +106
    -0
      src/main/org/apache/tools/ant/util/Base64Converter.java

+ 2
- 1
CONTRIBUTORS View File

@@ -245,9 +245,10 @@ Victor Toni
Waldek Herka Waldek Herka
Will Wang Will Wang
William Ferguson William Ferguson
Wolf Siberski
Wolfgang Baer
Wolfgang Frech Wolfgang Frech
Wolfgang Werner Wolfgang Werner
Wolf Siberski
Yohann Roussel Yohann Roussel
Yuji Yamano Yuji Yamano
Yves Martin Yves Martin


+ 2
- 0
WHATSNEW View File

@@ -28,6 +28,8 @@ Other changes:
* trim the driver attribute on the <sql> task. Bugzilla report 21228. * trim the driver attribute on the <sql> task. Bugzilla report 21228.
* Allow (jar) files as well as directories to be given to jdepend. * Allow (jar) files as well as directories to be given to jdepend.
Bugzilla report 28865. Bugzilla report 28865.
* Convert SplashTask to use NOT sun internal classes.
Bugzilla report 35619.


Changes from Ant 1.6.5 to Ant 1.7.0Beta1 Changes from Ant 1.6.5 to Ant 1.7.0Beta1
======================================== ========================================


+ 0
- 10
build.xml View File

@@ -190,13 +190,6 @@
<filename name="${ant.package}/taskdefs/email/UUMailer*"/> <filename name="${ant.package}/taskdefs/email/UUMailer*"/>
</selector> </selector>


<selector id="needs.sun.b64">
<or>
<filename name="${optional.package}/splash/SplashTask*"/>
<filename name="${optional.package}/splash/SplashScreenTest.java"/>
</or>
</selector>

<!-- depends on external libraries --> <!-- depends on external libraries -->
<selector id="needs.trax"> <selector id="needs.trax">
<or> <or>
@@ -503,8 +496,6 @@
</and> </and>
</condition> </condition>


<available property="base64.present" classname="sun.misc.BASE64Encoder"/>

<property name="build.tests.resolved" location="${build.tests}"/> <property name="build.tests.resolved" location="${build.tests}"/>
<condition property="tests.are.on.system.classpath"> <condition property="tests.are.on.system.classpath">
<or> <or>
@@ -651,7 +642,6 @@
<selector refid="needs.jdk1.5+" unless="jdk1.5+"/> <selector refid="needs.jdk1.5+" unless="jdk1.5+"/>
<selector refid="not.in.kaffe" if="kaffe"/> <selector refid="not.in.kaffe" if="kaffe"/>
<selector refid="needs.sun.uue" unless="sunuue.present"/> <selector refid="needs.sun.uue" unless="sunuue.present"/>
<selector refid="needs.sun.b64" unless="base64.present"/>


<selector refid="needs.trax" unless="trax.present"/> <selector refid="needs.trax" unless="trax.present"/>
<selector refid="needs.apache-resolver" unless="apache.resolver.present"/> <selector refid="needs.apache-resolver" unless="apache.resolver.present"/>


+ 8
- 4
contributors.xml View File

@@ -970,17 +970,21 @@
<first>William</first> <first>William</first>
<last>Ferguson</last> <last>Ferguson</last>
</name> </name>
<name>
<first>Wolf</first>
<last>Siberski</last>
</name>
<name> <name>
<first>Wolfgang</first> <first>Wolfgang</first>
<last>Frech</last>
<last>Baer</last>
</name> </name>
<name> <name>
<first>Wolfgang</first> <first>Wolfgang</first>
<last>Werner</last>
<last>Frech</last>
</name> </name>
<name> <name>
<first>Wolf</first>
<last>Siberski</last>
<first>Wolfgang</first>
<last>Werner</last>
</name> </name>
<name> <name>
<first>Yohann</first> <first>Yohann</first>


+ 6
- 74
src/main/org/apache/tools/ant/taskdefs/Get.java View File

@@ -336,80 +336,12 @@ public class Get extends Task {
this.pword = p; this.pword = p;
} }


/*********************************************************************
* BASE 64 encoding of a String or an array of bytes.
*
* Based on RFC 1421.
*
*********************************************************************/

protected static class Base64Converter {

public final char[] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/'}; // 56 to 63

public String encode(String s) {
return encode(s.getBytes());
}

public String encode(byte[] octetString) {
int bits24;
int bits6;

char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
int outIndex = 0;
int i = 0;

while ((i + 3) <= octetString.length) {
// store the octets
bits24 = (octetString[i++] & 0xFF) << 16;
bits24 |= (octetString[i++] & 0xFF) << 8;
bits24 |= octetString[i++];

bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0000003F);
out[outIndex++] = alphabet[bits6];
}
if (octetString.length - i == 2) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits24 |= (octetString[i + 1] & 0xFF) << 8;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = alphabet[bits6];

// padding
out[outIndex++] = '=';
} else if (octetString.length - i == 1) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = alphabet[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = alphabet[bits6];

// padding
out[outIndex++] = '=';
out[outIndex++] = '=';
}
return new String(out);
}
}
/**
* Provide this for Backward Compatibility.
*/
protected static class Base64Converter
extends org.apache.tools.ant.util.Base64Converter {}


public interface DownloadProgress { public interface DownloadProgress {
/** /**


+ 5
- 2
src/main/org/apache/tools/ant/taskdefs/optional/splash/SplashTask.java View File

@@ -28,6 +28,7 @@ import javax.swing.ImageIcon;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.Base64Converter;


/** /**
* Creates a splash screen. The splash screen is displayed * Creates a splash screen. The splash screen is displayed
@@ -141,9 +142,11 @@ public class SplashTask extends Task {


conn = url.openConnection(); conn = url.openConnection();
if (user != null && user.length() > 0) { if (user != null && user.length() > 0) {
// converted from sun internal classes to
// new Base64Converter
// utility class extracted from Get task
String encodedcreds = String encodedcreds =
new sun.misc.BASE64Encoder().encode(
(new String(user + ":" + password)).getBytes());
new Base64Converter().encode(user + ":" + password);
conn.setRequestProperty("Proxy-Authorization", conn.setRequestProperty("Proxy-Authorization",
encodedcreds); encodedcreds);
} }


+ 106
- 0
src/main/org/apache/tools/ant/util/Base64Converter.java View File

@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant.util;

/**
* BASE 64 encoding of a String or an array of bytes.
*
* Based on RFC 1421.
*
**/
public class Base64Converter {

private final static char[] ALPHABET = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/'}; // 56 to 63

/** Provided for BC purposes */
public static final char[] alphabet = ALPHABET;


/**
* Encode a string into base64 encoding.
* @param s the string to encode.
* @return the encoded string.
*/
public String encode(String s) {
return encode(s.getBytes());
}

/**
* Encode a byte array into base64 encoding.
* @param octetString the byte array to encode.
* @return the encoded string.
*/
public String encode(byte[] octetString) {
int bits24;
int bits6;

char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
int outIndex = 0;
int i = 0;

while ((i + 3) <= octetString.length) {
// store the octets
bits24 = (octetString[i++] & 0xFF) << 16;
bits24 |= (octetString[i++] & 0xFF) << 8;
bits24 |= octetString[i++];

bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x0000003F);
out[outIndex++] = ALPHABET[bits6];
}
if (octetString.length - i == 2) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits24 |= (octetString[i + 1] & 0xFF) << 8;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x00000FC0) >> 6;
out[outIndex++] = ALPHABET[bits6];

// padding
out[outIndex++] = '=';
} else if (octetString.length - i == 1) {
// store the octets
bits24 = (octetString[i] & 0xFF) << 16;
bits6 = (bits24 & 0x00FC0000) >> 18;
out[outIndex++] = ALPHABET[bits6];
bits6 = (bits24 & 0x0003F000) >> 12;
out[outIndex++] = ALPHABET[bits6];

// padding
out[outIndex++] = '=';
out[outIndex++] = '=';
}
return new String(out);
}
}

Loading…
Cancel
Save