21
21
import java.io.ByteArrayInputStream;
22
22
import java.io.ByteArrayOutputStream;
23
23
import java.io.File;
24
import java.io.FileInputStream;
24
25
import java.io.FileOutputStream;
25
import java.io.FileInputStream;
26
26
import java.io.IOException;
27
27
import java.io.InputStream;
28
import java.io.UnsupportedEncodingException;
29
28
import java.io.InputStreamReader;
30
29
import java.io.OutputStreamWriter;
31
30
import java.io.PrintWriter;
32
31
import java.io.Reader;
32
import java.io.UnsupportedEncodingException;
33
33
import java.util.ArrayList;
34
34
import java.util.Collections;
35
35
import java.util.Comparator;
42
42
import java.util.Vector;
43
43
import java.util.zip.ZipEntry;
44
44
import java.util.zip.ZipFile;
45
46
import org.apache.tools.ant.BuildException;
46
47
import org.apache.tools.ant.Project;
48
import org.apache.tools.ant.taskdefs.Manifest.Section;
47
49
import org.apache.tools.ant.types.EnumeratedAttribute;
48
50
import org.apache.tools.ant.types.Path;
49
51
import org.apache.tools.ant.types.ResourceCollection;
50
52
import org.apache.tools.ant.types.ZipFileSet;
51
53
import org.apache.tools.ant.types.spi.Service;
54
import org.apache.tools.ant.util.FileUtils;
52
55
import org.apache.tools.zip.JarMarker;
53
56
import org.apache.tools.zip.ZipExtraField;
54
57
import org.apache.tools.zip.ZipOutputStream;
140
144
private Path indexJars;
146
// CheckStyle:LineLength OFF - Link is too long.
148
* Strict mode for checking rules of the JAR-Specification.
149
* @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
151
private StrictMode strict = new StrictMode("ignore");
153
// CheckStyle:LineLength ON
143
156
* Extra fields needed to make Solaris recognize the archive as a jar file.
198
* Activate the strict mode. When set to <i>true</i> a BuildException
199
* will be thrown if the Jar-Packaging specification was broken.
200
* @param strict New value of the strict mode.
203
public void setStrict(StrictMode strict) {
204
this.strict = strict;
189
208
* Set the destination file.
190
209
* @param jarFile the destination file
191
210
* @deprecated since 1.5.x.
397
410
service = (Service) serviceIterator.next();
398
411
//stolen from writeManifest
399
412
super.zipFile(service.getAsStream(), zOut,
400
"META-INF/service/" + service.getType(),
413
"META-INF/services/" + service.getType(),
401
414
System.currentTimeMillis(), null,
402
415
ZipFileSet.DEFAULT_FILE_MODE);
471
484
OutputStreamWriter osw = new OutputStreamWriter(baos, Manifest.JAR_ENCODING);
472
485
PrintWriter writer = new PrintWriter(osw);
473
486
manifest.write(writer);
476
489
ByteArrayInputStream bais =
477
490
new ByteArrayInputStream(baos.toByteArray());
557
570
ByteArrayInputStream bais =
558
571
new ByteArrayInputStream(baos.toByteArray());
559
572
super.zipFile(bais, zOut, INDEX_NAME, System.currentTimeMillis(), null,
575
588
long lastModified, File fromArchive, int mode)
576
589
throws IOException {
577
590
if (MANIFEST_NAME.equalsIgnoreCase(vPath)) {
578
if (!doubleFilePass || (doubleFilePass && skipWriting)) {
591
if (!doubleFilePass || skipWriting) {
579
592
filesetManifest(fromArchive, is);
581
594
} else if (INDEX_NAME.equalsIgnoreCase(vPath) && index) {
788
795
protected void cleanUp() {
791
799
// we want to save this info if we are going to make another pass
792
if (!doubleFilePass || (doubleFilePass && !skipWriting)) {
800
if (!doubleFilePass || !skipWriting) {
794
802
configuredManifest = savedConfiguredManifest;
795
803
filesetManifest = null;
798
806
rootEntries.removeAllElements();
809
// CheckStyle:LineLength OFF - Link is too long.
811
* Check against packaging spec
812
* @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
814
// CheckStyle:LineLength ON
815
private void checkJarSpec() {
816
String br = System.getProperty("line.separator");
817
StringBuffer message = new StringBuffer();
818
Section mainSection = (configuredManifest == null)
820
: configuredManifest.getMainSection();
822
if (mainSection == null) {
823
message.append("No Implementation-Title set.");
824
message.append("No Implementation-Version set.");
825
message.append("No Implementation-Vendor set.");
827
if (mainSection.getAttribute("Implementation-Title") == null) {
828
message.append("No Implementation-Title set.");
830
if (mainSection.getAttribute("Implementation-Version") == null) {
831
message.append("No Implementation-Version set.");
833
if (mainSection.getAttribute("Implementation-Vendor") == null) {
834
message.append("No Implementation-Vendor set.");
838
if (message.length() > 0) {
840
message.append("Location: ").append(getLocation());
842
if (strict.getValue().equalsIgnoreCase("fail")) {
843
throw new BuildException(message.toString(), getLocation());
845
log(message.toString(), strict.getLogLevel());
802
851
* reset to default values.
899
948
* @return the matching entry, or null if the file is not found
900
949
* @since Ant 1.6.2
902
protected static final String findJarName(String fileName,
951
protected static String findJarName(String fileName,
903
952
String[] classpath) {
904
953
if (classpath == null) {
905
954
return (new File(fileName)).getName();
947
996
* @throws IOException on error
949
protected static final void grabFilesAndDirs(String file, List dirs,
998
protected static void grabFilesAndDirs(String file, List dirs,
951
1000
throws IOException {
952
1001
org.apache.tools.zip.ZipFile zf = null;
1035
/** The strict enumerated type. */
1036
public static class StrictMode extends EnumeratedAttribute {
1037
/** Public no arg constructor. */
1038
public StrictMode() {
1041
* Constructor with an arg.
1042
* @param value the enumerated value as a string.
1044
public StrictMode(String value) {
1048
* Get List of valid strings.
1049
* @return the list of values.
1051
public String[] getValues() {
1052
return new String[]{"fail", "warn", "ignore"};
1055
* @return The log level according to the strict mode.
1057
public int getLogLevel() {
1058
return (getValue().equals("ignore")) ? Project.MSG_VERBOSE : Project.MSG_WARN;