Return-Path:
guide/extensions/versioning.html
.
Package Specification
objects.
@@ -201,12 +199,12 @@
*
* @param manifest Manifest to be parsed
* @return the Package Specifications extensions in specified manifest
+ * @throws ParseException if the attributes of the specifications cannot
+ * be parsed according to their expected formats.
*/
public static Specification[] getSpecifications( final Manifest manifest )
- throws ParseException
- {
- if( null == manifest )
- {
+ throws ParseException {
+ if (null == manifest) {
return new Specification[ 0 ];
}
@@ -214,13 +212,12 @@
final Map entries = manifest.getEntries();
final Iterator keys = entries.keySet().iterator();
- while( keys.hasNext() )
- {
+ while (keys.hasNext()) {
final String key = (String)keys.next();
final Attributes attributes = (Attributes)entries.get( key );
- final Specification specification = getSpecification( key, attributes );
- if( null != specification )
- {
+ final Specification specification
+ = getSpecification(key, attributes);
+ if (null != specification) {
results.add( specification );
}
}
@@ -246,8 +243,7 @@
final String specificationVendor,
final String implementationTitle,
final String implementationVersion,
- final String implementationVendor )
- {
+ final String implementationVendor) {
this( specificationTitle, specificationVersion, specificationVendor,
implementationTitle, implementationVersion, implementationVendor,
null );
@@ -272,41 +268,36 @@
final String implementationTitle,
final String implementationVersion,
final String implementationVendor,
- final String[] sections )
- {
- m_specificationTitle = specificationTitle;
- m_specificationVendor = specificationVendor;
-
- if( null != specificationVersion )
- {
- try
- {
- m_specificationVersion = new DeweyDecimal( specificationVersion );
- }
- catch( final NumberFormatException nfe )
- {
- final String error = "Bad specification version format '" + specificationVersion +
- "' in '" + specificationTitle + "'. (Reason: " + nfe + ")";
+ final String[] sections) {
+ this.specificationTitle = specificationTitle;
+ this.specificationVendor = specificationVendor;
+
+ if (null != specificationVersion) {
+ try {
+ this.specificationVersion
+ = new DeweyDecimal(specificationVersion);
+ } catch (final NumberFormatException nfe) {
+ final String error = "Bad specification version format '"
+ + specificationVersion + "' in '" + specificationTitle
+ + "'. (Reason: " + nfe + ")";
throw new IllegalArgumentException( error );
}
}
- m_implementationTitle = implementationTitle;
- m_implementationVendor = implementationVendor;
- m_implementationVersion = implementationVersion;
+ this.implementationTitle = implementationTitle;
+ this.implementationVendor = implementationVendor;
+ this.implementationVersion = implementationVersion;
- if( null == m_specificationTitle )
- {
+ if (null == this.specificationTitle) {
throw new NullPointerException( "specificationTitle" );
}
String[] copy = null;
- if( null != sections )
- {
+ if (null != sections) {
copy = new String[ sections.length ];
System.arraycopy( sections, 0, copy, 0, sections.length );
}
- m_sections = copy;
+ this.sections = copy;
}
/**
@@ -314,9 +305,8 @@
*
* @return the title of speciication
*/
- public String getSpecificationTitle()
- {
- return m_specificationTitle;
+ public String getSpecificationTitle() {
+ return specificationTitle;
}
/**
@@ -324,9 +314,8 @@
*
* @return the vendor of the specification.
*/
- public String getSpecificationVendor()
- {
- return m_specificationVendor;
+ public String getSpecificationVendor() {
+ return specificationVendor;
}
/**
@@ -334,9 +323,8 @@
*
* @return the title of the specification.
*/
- public String getImplementationTitle()
- {
- return m_implementationTitle;
+ public String getImplementationTitle() {
+ return implementationTitle;
}
/**
@@ -344,9 +332,8 @@
*
* @return the version of the specification.
*/
- public DeweyDecimal getSpecificationVersion()
- {
- return m_specificationVersion;
+ public DeweyDecimal getSpecificationVersion() {
+ return specificationVersion;
}
/**
@@ -354,9 +341,8 @@
*
* @return the vendor of the extensions implementation.
*/
- public String getImplementationVendor()
- {
- return m_implementationVendor;
+ public String getImplementationVendor() {
+ return implementationVendor;
}
/**
@@ -364,9 +350,8 @@
*
* @return the version of the implementation.
*/
- public String getImplementationVersion()
- {
- return m_implementationVersion;
+ public String getImplementationVersion() {
+ return implementationVersion;
}
/**
@@ -376,65 +361,55 @@
* @return an array containing sections to which specification applies
* or null if relevent to no sections.
*/
- public String[] getSections()
- {
- if( null == m_sections )
- {
+ public String[] getSections() {
+ if (null == sections) {
return null;
- }
- else
- {
- final String[] sections = new String[ m_sections.length ];
- System.arraycopy( m_sections, 0, sections, 0, m_sections.length );
- return sections;
+ } else {
+ final String[] newSections = new String[ sections.length ];
+ System.arraycopy(sections, 0, newSections, 0, sections.length);
+ return newSections;
}
}
/**
* Return a Compatibility enum indicating the relationship of this
- * Package Specification
with the specified Extension
.
+ * Package Specification
with the specified
+ * Extension
.
*
* @param other the other specification
* @return the enum indicating the compatibility (or lack thereof)
* of specifed Package Specification
*/
- public Compatibility getCompatibilityWith( final Specification other )
- {
+ public Compatibility getCompatibilityWith(final Specification other) {
// Specification Name must match
- if( !m_specificationTitle.equals( other.getSpecificationTitle() ) )
- {
+ if (!specificationTitle.equals(other.getSpecificationTitle())) {
return INCOMPATIBLE;
}
// Available specification version must be >= required
- final DeweyDecimal specificationVersion = other.getSpecificationVersion();
- if( null != specificationVersion )
- {
- if( null == m_specificationVersion ||
- !isCompatible( m_specificationVersion, specificationVersion ) )
- {
+ final DeweyDecimal specificationVersion
+ = other.getSpecificationVersion();
+ if (null != specificationVersion) {
+ if (null == specificationVersion
+ || !isCompatible(specificationVersion, specificationVersion)) {
return REQUIRE_SPECIFICATION_UPGRADE;
}
}
// Implementation Vendor ID must match
final String implementationVendor = other.getImplementationVendor();
- if( null != implementationVendor )
- {
- if( null == m_implementationVendor ||
- !m_implementationVendor.equals( implementationVendor ) )
- {
+ if (null != implementationVendor) {
+ if (null == implementationVendor
+ || !implementationVendor.equals(implementationVendor)) {
return REQUIRE_VENDOR_SWITCH;
}
}
// Implementation version must be >= required
final String implementationVersion = other.getImplementationVersion();
- if( null != implementationVersion )
- {
- if( null == m_implementationVersion ||
- !m_implementationVersion.equals( implementationVersion ) )
- {
+ if (null != implementationVersion) {
+ if (null == implementationVersion
+ || !implementationVersion.equals(implementationVersion)) {
return REQUIRE_IMPLEMENTATION_CHANGE;
}
}
@@ -451,8 +426,7 @@
* @param other the specification
* @return true if the specification is compatible with this specification
*/
- public boolean isCompatibleWith( final Specification other )
- {
+ public boolean isCompatibleWith(final Specification other) {
return ( COMPATIBLE == getCompatibilityWith( other ) );
}
@@ -461,53 +435,48 @@
*
* @return string representation of object.
*/
- public String toString()
- {
+ public String toString() {
final String lineSeparator = System.getProperty( "line.separator" );
final String brace = ": ";
- final StringBuffer sb = new StringBuffer( SPECIFICATION_TITLE.toString() );
+ final StringBuffer sb
+ = new StringBuffer(SPECIFICATION_TITLE.toString());
sb.append( brace );
- sb.append( m_specificationTitle );
+ sb.append(specificationTitle);
sb.append( lineSeparator );
- if( null != m_specificationVersion )
- {
+ if (null != specificationVersion) {
sb.append( SPECIFICATION_VERSION );
sb.append( brace );
- sb.append( m_specificationVersion );
+ sb.append(specificationVersion);
sb.append( lineSeparator );
}
- if( null != m_specificationVendor )
- {
+ if (null != specificationVendor) {
sb.append( SPECIFICATION_VENDOR );
sb.append( brace );
- sb.append( m_specificationVendor );
+ sb.append(specificationVendor);
sb.append( lineSeparator );
}
- if( null != m_implementationTitle )
- {
+ if (null != implementationTitle) {
sb.append( IMPLEMENTATION_TITLE );
sb.append( brace );
- sb.append( m_implementationTitle );
+ sb.append(implementationTitle);
sb.append( lineSeparator );
}
- if( null != m_implementationVersion )
- {
+ if (null != implementationVersion) {
sb.append( IMPLEMENTATION_VERSION );
sb.append( brace );
- sb.append( m_implementationVersion );
+ sb.append(implementationVersion);
sb.append( lineSeparator );
}
- if( null != m_implementationVendor )
- {
+ if (null != implementationVendor) {
sb.append( IMPLEMENTATION_VENDOR );
sb.append( brace );
- sb.append( m_implementationVendor );
+ sb.append(implementationVendor);
sb.append( lineSeparator );
}
@@ -521,8 +490,8 @@
* @param first First version number (dotted decimal)
* @param second Second version number (dotted decimal)
*/
- private boolean isCompatible( final DeweyDecimal first, final DeweyDecimal second )
- {
+ private boolean isCompatible(final DeweyDecimal first,
+ final DeweyDecimal second) {
return first.isGreaterThanOrEqual( second );
}
@@ -536,22 +505,17 @@
* @param list the array of results to trim
* @return an array list with all duplicates removed
*/
- private static ArrayList removeDuplicates( final ArrayList list )
- {
+ private static ArrayList removeDuplicates(final ArrayList list) {
final ArrayList results = new ArrayList();
final ArrayList sections = new ArrayList();
- while( list.size() > 0 )
- {
+ while (list.size() > 0) {
final Specification specification = (Specification)list.remove( 0 );
final Iterator iterator = list.iterator();
- while( iterator.hasNext() )
- {
+ while (iterator.hasNext()) {
final Specification other = (Specification)iterator.next();
- if( isEqual( specification, other ) )
- {
+ if (isEqual(specification, other)) {
final String[] otherSections = other.getSections();
- if( null != sections )
- {
+ if (null != sections) {
sections.addAll( Arrays.asList( otherSections ) );
}
iterator.remove();
@@ -577,15 +541,14 @@
* sections, else false
*/
private static boolean isEqual( final Specification specification,
- final Specification other )
- {
+ final Specification other) {
return
- specification.getSpecificationTitle().equals( other.getSpecificationTitle() ) &&
- specification.getSpecificationVersion().isEqual( other.getSpecificationVersion() ) &&
- specification.getSpecificationVendor().equals( other.getSpecificationVendor() ) &&
- specification.getImplementationTitle().equals( other.getImplementationTitle() ) &&
- specification.getImplementationVersion().equals( other.getImplementationVersion() ) &&
- specification.getImplementationVendor().equals( other.getImplementationVendor() );
+ specification.getSpecificationTitle().equals(other.getSpecificationTitle())
+ && specification.getSpecificationVersion().isEqual(other.getSpecificationVersion())
+ && specification.getSpecificationVendor().equals(other.getSpecificationVendor())
+ && specification.getImplementationTitle().equals(other.getImplementationTitle())
+ && specification.getImplementationVersion().equals(other.getImplementationVersion())
+ && specification.getImplementationVendor().equals(other.getImplementationVendor());
}
/**
@@ -597,14 +560,10 @@
* @return the merged specification
*/
private static Specification mergeInSections( final Specification specification,
- final ArrayList sectionsToAdd )
- {
- if( 0 == sectionsToAdd.size() )
- {
+ final ArrayList sectionsToAdd) {
+ if (0 == sectionsToAdd.size()) {
return specification;
- }
- else
- {
+ } else {
sectionsToAdd.addAll( Arrays.asList( specification.getSections() ) );
final String[] sections =
@@ -626,14 +585,10 @@
* @param value the string to trim or null
* @return the trimmed string or null
*/
- private static String getTrimmedString( final String value )
- {
- if( null == value )
- {
+ private static String getTrimmedString(final String value) {
+ if (null == value) {
return null;
- }
- else
- {
+ } else {
return value.trim();
}
}
@@ -646,44 +601,43 @@
*/
private static Specification getSpecification( final String section,
final Attributes attributes )
- throws ParseException
- {
+ throws ParseException {
//WARNING: We trim the values of all the attributes because
//Some extension declarations are badly defined (ie have spaces
//after version or vendor)
- final String name = getTrimmedString( attributes.getValue( SPECIFICATION_TITLE ) );
- if( null == name )
- {
+ final String name
+ = getTrimmedString(attributes.getValue(SPECIFICATION_TITLE));
+ if (null == name) {
return null;
}
- final String specVendor = getTrimmedString( attributes.getValue( SPECIFICATION_VENDOR ) );
- if( null == specVendor )
- {
+ final String specVendor
+ = getTrimmedString(attributes.getValue(SPECIFICATION_VENDOR));
+ if (null == specVendor) {
throw new ParseException( "Missing " + SPECIFICATION_VENDOR, 0 );
}
- final String specVersion = getTrimmedString( attributes.getValue( SPECIFICATION_VERSION ) );
- if( null == specVersion )
- {
+ final String specVersion
+ = getTrimmedString(attributes.getValue(SPECIFICATION_VERSION));
+ if (null == specVersion) {
throw new ParseException( "Missing " + SPECIFICATION_VERSION, 0 );
}
- final String impTitle = getTrimmedString( attributes.getValue( IMPLEMENTATION_TITLE ) );
- if( null == impTitle )
- {
+ final String impTitle
+ = getTrimmedString(attributes.getValue(IMPLEMENTATION_TITLE));
+ if (null == impTitle) {
throw new ParseException( "Missing " + IMPLEMENTATION_TITLE, 0 );
}
- final String impVersion = getTrimmedString( attributes.getValue( IMPLEMENTATION_VERSION ) );
- if( null == impVersion )
- {
+ final String impVersion
+ = getTrimmedString(attributes.getValue(IMPLEMENTATION_VERSION));
+ if (null == impVersion) {
throw new ParseException( "Missing " + IMPLEMENTATION_VERSION, 0 );
}
- final String impVendor = getTrimmedString( attributes.getValue( IMPLEMENTATION_VENDOR ) );
- if( null == impVendor )
- {
+ final String impVendor
+ = getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR));
+ if (null == impVendor) {
throw new ParseException( "Missing " + IMPLEMENTATION_VENDOR, 0 );
}
1.16 +275 -219 ant/src/main/org/apache/tools/tar/TarEntry.java
Index: TarEntry.java
===================================================================
RCS file: /home/cvs/ant/src/main/org/apache/tools/tar/TarEntry.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -w -u -r1.15 -r1.16
--- TarEntry.java 19 Mar 2003 10:09:38 -0000 1.15
+++ TarEntry.java 4 Jul 2003 13:03:38 -0000 1.16
@@ -115,22 +115,62 @@
*/
public class TarEntry implements TarConstants {
+ /** The entry's name. */
+ private StringBuffer name;
- private StringBuffer name; /** The entry's name. */
- private int mode; /** The entry's permission mode. */
- private int userId; /** The entry's user id. */
- private int groupId; /** The entry's group id. */
- private long size; /** The entry's size. */
- private long modTime; /** The entry's modification time. */
- private int checkSum; /** The entry's checksum. */
- private byte linkFlag; /** The entry's link flag. */
- private StringBuffer linkName; /** The entry's link name. */
- private StringBuffer magic; /** The entry's magic tag. */
- private StringBuffer userName; /** The entry's user name. */
- private StringBuffer groupName; /** The entry's group name. */
- private int devMajor; /** The entry's major device number. */
- private int devMinor; /** The entry's minor device number. */
- private File file; /** The entry's file reference */
+ /** The entry's permission mode. */
+ private int mode;
+
+ /** The entry's user id. */
+ private int userId;
+
+ /** The entry's group id. */
+ private int groupId;
+
+ /** The entry's size. */
+ private long size;
+
+ /** The entry's modification time. */
+ private long modTime;
+
+ /** The entry's checksum. */
+ private int checkSum;
+
+ /** The entry's link flag. */
+ private byte linkFlag;
+
+ /** The entry's link name. */
+ private StringBuffer linkName;
+
+ /** The entry's magic tag. */
+ private StringBuffer magic;
+
+ /** The entry's user name. */
+ private StringBuffer userName;
+
+ /** The entry's group name. */
+ private StringBuffer groupName;
+
+ /** The entry's major device number. */
+ private int devMajor;
+
+ /** The entry's minor device number. */
+ private int devMinor;
+
+ /** The entry's file reference */
+ private File file;
+
+ /** Maximum length of a user's name in the tar file */
+ public static final int MAX_NAMELEN = 31;
+
+ /** Default permissions bits for directories */
+ public static final int DEFAULT_DIR_MODE = 040755;
+
+ /** Default permissions bits for files */
+ public static final int DEFAULT_FILE_MODE = 0100644;
+
+ /** Convert millis to seconds */
+ public static final int MILLIS_PER_SECOND = 1000;
/**
* Construct an empty entry and prepares the header values.
@@ -142,8 +182,8 @@
String user = System.getProperty("user.name", "");
- if (user.length() > 31) {
- user = user.substring(0, 31);
+ if (user.length() > MAX_NAMELEN) {
+ user = user.substring(0, MAX_NAMELEN);
}
this.userId = 0;
@@ -156,6 +196,8 @@
/**
* Construct an entry with only a name. This allows the programmer
* to construct the entry's header "by hand". File is set to null.
+ *
+ * @param name the entry name
*/
public TarEntry(String name) {
this();
@@ -166,13 +208,13 @@
this.devMajor = 0;
this.devMinor = 0;
this.name = new StringBuffer(name);
- this.mode = isDir ? 040755 : 0100644;
+ this.mode = isDir ? DEFAULT_DIR_MODE : DEFAULT_FILE_MODE;
this.linkFlag = isDir ? LF_DIR : LF_NORMAL;
this.userId = 0;
this.groupId = 0;
this.size = 0;
this.checkSum = 0;
- this.modTime = (new Date()).getTime() / 1000;
+ this.modTime = (new Date()).getTime() / MILLIS_PER_SECOND;
this.linkName = new StringBuffer("");
this.userName = new StringBuffer("");
this.groupName = new StringBuffer("");
@@ -183,6 +225,9 @@
/**
* Construct an entry with a name an a link flag.
+ *
+ * @param name the entry name
+ * @param linkFlag the entry link flag.
*/
public TarEntry(String name, byte linkFlag) {
this(name);
@@ -240,19 +285,19 @@
this.name = new StringBuffer(name);
if (file.isDirectory()) {
- this.mode = 040755;
+ this.mode = DEFAULT_DIR_MODE;
this.linkFlag = LF_DIR;
if (this.name.charAt(this.name.length() - 1) != '/') {
this.name.append("/");
}
} else {
- this.mode = 0100644;
+ this.mode = DEFAULT_FILE_MODE;
this.linkFlag = LF_NORMAL;
}
this.size = file.length();
- this.modTime = file.lastModified() / 1000;
+ this.modTime = file.lastModified() / MILLIS_PER_SECOND;
this.checkSum = 0;
this.devMajor = 0;
this.devMinor = 0;
@@ -273,7 +318,7 @@
* Determine if the two entries are equal. Equality is determined
* by the header names being equal.
*
- * @return it Entry to be checked for equality.
+ * @param it Entry to be checked for equality.
* @return True if the entries are equal.
*/
public boolean equals(TarEntry it) {
@@ -281,6 +326,15 @@
}
/**
+ * Hashcodes are based on entry names.
+ *
+ * @return the entry hashcode
+ */
+ public int hashCode() {
+ return getName().hashCode();
+ }
+
+ /**
* Determine if the given entry is a descendant of this entry.
* Descendancy is determined by the name of the descendant
* starting with this entry's name.
@@ -312,6 +366,8 @@
/**
* Set the mode for this entry
+ *
+ * @param mode the mode for this entry
*/
public void setMode(int mode) {
this.mode = mode;
@@ -427,7 +483,7 @@
* @param time This entry's new modification time.
*/
public void setModTime(long time) {
- this.modTime = time / 1000;
+ this.modTime = time / MILLIS_PER_SECOND;
}
/**
@@ -436,16 +492,16 @@
* @param time This entry's new modification time.
*/
public void setModTime(Date time) {
- this.modTime = time.getTime() / 1000;
+ this.modTime = time.getTime() / MILLIS_PER_SECOND;
}
/**
* Set this entry's modification time.
*
- * @param time This entry's new modification time.
+ * @return time This entry's new modification time.
*/
public Date getModTime() {
- return new Date(this.modTime * 1000);
+ return new Date(this.modTime * MILLIS_PER_SECOND);
}
/**
@@ -491,8 +547,8 @@
* @return true if this is a long name extension provided by GNU tar
*/
public boolean isGNULongNameEntry() {
- return linkFlag == LF_GNUTYPE_LONGNAME &&
- name.toString().equals(GNU_LONGLINK);
+ return linkFlag == LF_GNUTYPE_LONGNAME
+ && name.toString().equals(GNU_LONGLINK);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org