ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Jar.java ManifestTask.java
Date Sun, 16 Feb 2003 02:03:06 GMT
conor       2003/02/15 18:03:06

  Modified:    src/main/org/apache/tools/ant/taskdefs Jar.java
                        ManifestTask.java
  Log:
  Read/Write manifests in UTF-8
  
  PR:	17075
  
  Revision  Changes    Path
  1.68      +16 -12    ant/src/main/org/apache/tools/ant/taskdefs/Jar.java
  
  Index: Jar.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Jar.java,v
  retrieving revision 1.67
  retrieving revision 1.68
  diff -u -w -u -r1.67 -r1.68
  --- Jar.java	12 Feb 2003 09:05:04 -0000	1.67
  +++ Jar.java	16 Feb 2003 02:03:06 -0000	1.68
  @@ -58,7 +58,7 @@
   import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.FileOutputStream;
  -import java.io.FileReader;
  +import java.io.FileInputStream;
   import java.io.IOException;
   import java.io.InputStream;
   import java.io.InputStreamReader;
  @@ -204,7 +204,7 @@
        * or the name of a jar added through a fileset. If its the name of an added
        * jar, the task expects the manifest to be in the jar at META-INF/MANIFEST.MF.
        *
  -     * @param manifestFile
  +     * @param manifestFile the manifest file to use.
        */
       public void setManifest(File manifestFile) {
           if (!manifestFile.exists()) {
  @@ -218,18 +218,20 @@
       private Manifest getManifest(File manifestFile) {
   
           Manifest newManifest = null;
  -        Reader r = null;
  +        FileInputStream fis = null;
  +        InputStreamReader isr = null;
           try {
  -            r = new FileReader(manifestFile);
  -            newManifest = getManifest(r);
  +            fis = new FileInputStream(manifestFile);
  +            isr = new InputStreamReader(fis, "UTF-8");
  +            newManifest = getManifest(isr);
           } catch (IOException e) {
               throw new BuildException("Unable to read manifest file: "
                                        + manifestFile
                                        + " (" + e.getMessage() + ")", e);
           } finally {
  -            if (r != null) {
  +            if (isr != null) {
                   try {
  -                    r.close();
  +                    isr.close();
                   } catch (IOException e) {
                       // do nothing
                   }
  @@ -254,8 +256,9 @@
               while (enum.hasMoreElements()) {
                   ZipEntry ze = (ZipEntry) enum.nextElement();
                   if (ze.getName().equalsIgnoreCase(MANIFEST_NAME)) {
  -                    return getManifest(new InputStreamReader(zf
  -                                                             .getInputStream(ze)));
  +                    InputStreamReader isr =
  +                        new InputStreamReader(zf.getInputStream(ze), "UTF-8");
  +                    return getManifest(isr);
                   }
               }
               return null;
  @@ -467,13 +470,13 @@
           }
       }
   
  -    private void filesetManifest(File file, InputStream is) {
  +    private void filesetManifest(File file, InputStream is) throws IOException {
           if (manifestFile != null && manifestFile.equals(file)) {
               // If this is the same name specified in 'manifest', this
               // is the manifest to use
               log("Found manifest " + file, Project.MSG_VERBOSE);
               if (is != null) {
  -                manifest = getManifest(new InputStreamReader(is));
  +                manifest = getManifest(new InputStreamReader(is, "UTF-8"));
               } else {
                   manifest = getManifest(file);
               }
  @@ -486,7 +489,8 @@
               try {
                   Manifest newManifest = null;
                   if (is != null) {
  -                    newManifest = getManifest(new InputStreamReader(is));
  +                    newManifest 
  +                        = getManifest(new InputStreamReader(is, "UTF-8"));
                   } else {
                       newManifest = getManifest(file);
                   }
  
  
  
  1.6       +15 -9     ant/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
  
  Index: ManifestTask.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -u -r1.5 -r1.6
  --- ManifestTask.java	10 Feb 2003 14:13:35 -0000	1.5
  +++ ManifestTask.java	16 Feb 2003 02:03:06 -0000	1.6
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -55,8 +55,10 @@
   package org.apache.tools.ant.taskdefs;
   
   import java.io.File;
  -import java.io.FileReader;
  -import java.io.FileWriter;
  +import java.io.FileInputStream;
  +import java.io.InputStreamReader;
  +import java.io.FileOutputStream;
  +import java.io.OutputStreamWriter;
   import java.io.IOException;
   import java.io.PrintWriter;
   import org.apache.tools.ant.BuildException;
  @@ -169,10 +171,12 @@
           BuildException error = null;
   
           if (manifestFile.exists()) {
  -            FileReader f = null;
  +            FileInputStream fis = null;
  +            InputStreamReader isr = null;
               try {
  -                f = new FileReader(manifestFile);
  -                current = new Manifest(f);
  +                fis = new FileInputStream(manifestFile);
  +                isr = new InputStreamReader(fis, "UTF-8");
  +                current = new Manifest(isr);
               } catch (ManifestException m) {
                   error = new BuildException("Existing manifest " + manifestFile
                                              + " is invalid", m, getLocation());
  @@ -180,9 +184,9 @@
                   error = new BuildException("Failed to read " + manifestFile,
                                              e, getLocation());
               } finally {
  -                if (f != null) {
  +                if (isr != null) {
                       try {
  -                        f.close();
  +                        isr.close();
                       } catch (IOException e) {}
                   }
               }
  @@ -210,7 +214,9 @@
   
           PrintWriter w = null;
           try {
  -            w = new PrintWriter(new FileWriter(manifestFile));
  +            FileOutputStream fos = new FileOutputStream(manifestFile);
  +            OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
  +            w = new PrintWriter(osw);
               toWrite.write(w);
           } catch (IOException e) {
               throw new BuildException("Failed to write " + manifestFile,
  
  
  

Mime
View raw message