git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274766 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -1,13 +1,13 @@ | |||||
| <?xml version="1.0"?> | <?xml version="1.0"?> | ||||
| <project default="checkstyle" name="CheckAnt"> | <project default="checkstyle" name="CheckAnt"> | ||||
| <!-- <import file="build.xml"/> --> | |||||
| <!-- <import file="build.xml"/> --> | |||||
| <property name="src.dir" value="src"/> | <property name="src.dir" value="src"/> | ||||
| <property name="java.dir" value="${src.dir}/main"/> | <property name="java.dir" value="${src.dir}/main"/> | ||||
| <property name="etc.dir" value="${src.dir}/etc"/> | <property name="etc.dir" value="${src.dir}/etc"/> | ||||
| <property name="config.dir" value="${etc.dir}/checkstyle"/> | <property name="config.dir" value="${etc.dir}/checkstyle"/> | ||||
| <property name="build.dir" value="build"/> | <property name="build.dir" value="build"/> | ||||
| <property name="checkstyle.reportdir" value="${build.dir}/reports/checkstyle"/> | <property name="checkstyle.reportdir" value="${build.dir}/reports/checkstyle"/> | ||||
| <property name="checkstyle.raw" value="${checkstyle.reportdir}/raw.xml"/> | <property name="checkstyle.raw" value="${checkstyle.reportdir}/raw.xml"/> | ||||
| <property name="stylesheet.html" value="${config.dir}/checkstyle-frames.xsl"/> | <property name="stylesheet.html" value="${config.dir}/checkstyle-frames.xsl"/> | ||||
| @@ -17,9 +17,11 @@ | |||||
| <property name="checkstyle.basedir" location="${java.dir}"/> | <property name="checkstyle.basedir" location="${java.dir}"/> | ||||
| <!-- Ant Checkstyle report --> | <!-- Ant Checkstyle report --> | ||||
| <property name="tocheck" value="**/*.java"/> | |||||
| <property name="tocheck" value="**/*.java"/> | |||||
| <property name="javadoc.scope" value="public"/> | <property name="javadoc.scope" value="public"/> | ||||
| <taskdef resource="simiantask.properties"/> | |||||
| <target name="checkstyle"> | <target name="checkstyle"> | ||||
| <mkdir dir="${checkstyle.reportdir}"/> | <mkdir dir="${checkstyle.reportdir}"/> | ||||
| <taskdef resource="checkstyletask.properties"/> | <taskdef resource="checkstyletask.properties"/> | ||||
| @@ -28,6 +30,7 @@ | |||||
| <fileset dir="${java.dir}"> | <fileset dir="${java.dir}"> | ||||
| <include name="${tocheck}"/> | <include name="${tocheck}"/> | ||||
| <exclude name="**/BZip2Constants.java"/> | <exclude name="**/BZip2Constants.java"/> | ||||
| <exclude name="**/CVSPass.java"/> | |||||
| </fileset> | </fileset> | ||||
| </checkstyle> | </checkstyle> | ||||
| </target> | </target> | ||||
| @@ -39,7 +42,7 @@ | |||||
| <param name="basedir" expression="${checkstyle.basedir}"/> | <param name="basedir" expression="${checkstyle.basedir}"/> | ||||
| </style> | </style> | ||||
| </target> | </target> | ||||
| <target name="textreport"> | <target name="textreport"> | ||||
| <style in="${checkstyle.raw}" style="${stylesheet.text}" | <style in="${checkstyle.raw}" style="${stylesheet.text}" | ||||
| out="${checkstyle.reportdir}/report.txt"> | out="${checkstyle.reportdir}/report.txt"> | ||||
| @@ -58,6 +61,12 @@ | |||||
| <filelist dir="${checkstyle.reportdir}" files="report.txt"/> | <filelist dir="${checkstyle.reportdir}" files="report.txt"/> | ||||
| </concat> | </concat> | ||||
| </target> | </target> | ||||
| <target name="simiancheck"> | |||||
| <simian> | |||||
| <fileset dir="${java.dir}" /> | |||||
| </simian> | |||||
| </target> | |||||
| </project> | </project> | ||||
| @@ -14,8 +14,8 @@ | |||||
| </module> | </module> | ||||
| <module name="JavadocVariable"> | <module name="JavadocVariable"> | ||||
| <property name="scope" value="public"/> | <property name="scope" value="public"/> | ||||
| </module> | |||||
| </module> | |||||
| <!-- element naming --> | <!-- element naming --> | ||||
| <module name="PackageName"/> | <module name="PackageName"/> | ||||
| <module name="TypeName"/> | <module name="TypeName"/> | ||||
| @@ -26,22 +26,25 @@ | |||||
| <module name="MethodName"/> | <module name="MethodName"/> | ||||
| <module name="ParameterName"/> | <module name="ParameterName"/> | ||||
| <module name="StaticVariableName"/> | <module name="StaticVariableName"/> | ||||
| <!-- required licence file --> | <!-- required licence file --> | ||||
| <module name="Header"> | <module name="Header"> | ||||
| <property name="headerFile" value="${config.dir}/RequiredHeader.txt"/> | <property name="headerFile" value="${config.dir}/RequiredHeader.txt"/> | ||||
| <property name="ignoreLines" value="4"/> | <property name="ignoreLines" value="4"/> | ||||
| </module> | </module> | ||||
| <!-- Import conventions --> | <!-- Import conventions --> | ||||
| <module name="AvoidStarImport"/> | <module name="AvoidStarImport"/> | ||||
| <module name="IllegalImport"/> | <module name="IllegalImport"/> | ||||
| <module name="RedundantImport"/> | <module name="RedundantImport"/> | ||||
| <module name="UnusedImports"/> | <module name="UnusedImports"/> | ||||
| <!-- size limits --> | <!-- size limits --> | ||||
| <module name="FileLength"/> | <module name="FileLength"/> | ||||
| <module name="LineLength"/> | |||||
| <module name="LineLength"> | |||||
| <property name="max" value="100"/> | |||||
| <property name="ignorePattern" value="^ *\* *[^ ]+$"/> | |||||
| </module> | |||||
| <module name="MethodLength"/> | <module name="MethodLength"/> | ||||
| <module name="ParameterNumber"/> | <module name="ParameterNumber"/> | ||||
| @@ -58,19 +61,21 @@ | |||||
| <!-- Modifier Checks --> | <!-- Modifier Checks --> | ||||
| <module name="ModifierOrder"/> | <module name="ModifierOrder"/> | ||||
| <module name="RedundantModifier"/> | <module name="RedundantModifier"/> | ||||
| <!-- Checks for blocks --> | <!-- Checks for blocks --> | ||||
| <module name="AvoidNestedBlocks"/> | <module name="AvoidNestedBlocks"/> | ||||
| <module name="EmptyBlock"/> | |||||
| <module name="EmptyBlock"> | |||||
| <property name="option" value="text"/> | |||||
| </module> | |||||
| <module name="LeftCurly"/> | <module name="LeftCurly"/> | ||||
| <module name="NeedBraces"/> | <module name="NeedBraces"/> | ||||
| <module name="RightCurly"/> | <module name="RightCurly"/> | ||||
| <!-- Checks for common coding problems --> | <!-- Checks for common coding problems --> | ||||
| <module name="AvoidInlineConditionals"/> | |||||
| <module name="DoubleCheckedLocking"/> | |||||
| <!--<module name="AvoidInlineConditionals"/> --> | |||||
| <module name="DoubleCheckedLocking"/> | |||||
| <module name="EmptyStatement"/> | <module name="EmptyStatement"/> | ||||
| <module name="EqualsHashCode"/> | <module name="EqualsHashCode"/> | ||||
| <module name="IllegalInstantiation"> | <module name="IllegalInstantiation"> | ||||
| @@ -79,18 +84,20 @@ | |||||
| <module name="InnerAssignment"/> | <module name="InnerAssignment"/> | ||||
| <module name="MagicNumber"/> | <module name="MagicNumber"/> | ||||
| <module name="MissingSwitchDefault"/> | <module name="MissingSwitchDefault"/> | ||||
| <module name="RedundantThrows"/> | |||||
| <module name="RedundantThrows"> | |||||
| <property name="allowUnchecked" value="true"/> | |||||
| </module> | |||||
| <module name="SimplifyBooleanExpression"/> | <module name="SimplifyBooleanExpression"/> | ||||
| <module name="SimplifyBooleanReturn"/> | <module name="SimplifyBooleanReturn"/> | ||||
| <!-- Checks for class design --> | <!-- Checks for class design --> | ||||
| <module name="DesignForExtension"/> | |||||
| <!-- <module name="DesignForExtension"/> --> | |||||
| <module name="FinalClass"/> | <module name="FinalClass"/> | ||||
| <module name="HideUtilityClassConstructor"/> | <module name="HideUtilityClassConstructor"/> | ||||
| <module name="InterfaceIsType"/> | <module name="InterfaceIsType"/> | ||||
| <module name="VisibilityModifier"/> | <module name="VisibilityModifier"/> | ||||
| <!-- Miscellaneous other checks. --> | |||||
| <!-- Miscellaneous other checks. --> | |||||
| <module name="ArrayTypeStyle"/> | <module name="ArrayTypeStyle"/> | ||||
| <module name="GenericIllegalRegexp"> | <module name="GenericIllegalRegexp"> | ||||
| <property name="format" value="\s+$"/> | <property name="format" value="\s+$"/> | ||||
| @@ -99,5 +106,5 @@ | |||||
| <module name="TodoComment"/> | <module name="TodoComment"/> | ||||
| <module name="UpperEll"/> | <module name="UpperEll"/> | ||||
| </module> | </module> | ||||
| <module name="au.com.redhillconsulting.simian.SimianCheck"/> | |||||
| <!-- <module name="au.com.redhillconsulting.simian.SimianCheck"/> --> | |||||
| </module> | </module> | ||||
| @@ -106,7 +106,7 @@ public class CVSPass extends Task { | |||||
| /** | /** | ||||
| * Create a CVS task using the default cvspass file location. | * Create a CVS task using the default cvspass file location. | ||||
| */ | */ | ||||
| public CVSPass(){ | |||||
| public CVSPass() { | |||||
| passFile = new File( | passFile = new File( | ||||
| System.getProperty("cygwin.user.home", | System.getProperty("cygwin.user.home", | ||||
| System.getProperty("user.home")) | System.getProperty("user.home")) | ||||
| @@ -161,7 +161,9 @@ public class CVSPass extends Task { | |||||
| if (reader != null) { | if (reader != null) { | ||||
| try { | try { | ||||
| reader.close(); | reader.close(); | ||||
| } catch (IOException e) {} | |||||
| } catch (IOException e) { | |||||
| // ignore | |||||
| } | |||||
| } | } | ||||
| if (writer != null) { | if (writer != null) { | ||||
| writer.close(); | writer.close(); | ||||
| @@ -169,7 +171,7 @@ public class CVSPass extends Task { | |||||
| } | } | ||||
| } | } | ||||
| private final String mangle(String password){ | |||||
| private final String mangle(String password) { | |||||
| StringBuffer buf = new StringBuffer(); | StringBuffer buf = new StringBuffer(); | ||||
| for (int i = 0; i < password.length(); i++) { | for (int i = 0; i < password.length(); i++) { | ||||
| buf.append(shifts[password.charAt(i)]); | buf.append(shifts[password.charAt(i)]); | ||||
| @@ -179,6 +181,8 @@ public class CVSPass extends Task { | |||||
| /** | /** | ||||
| * The CVS repository to add an entry for. | * The CVS repository to add an entry for. | ||||
| * | |||||
| * @param cvsRoot the CVS repository | |||||
| */ | */ | ||||
| public void setCvsroot(String cvsRoot) { | public void setCvsroot(String cvsRoot) { | ||||
| this.cvsRoot = cvsRoot; | this.cvsRoot = cvsRoot; | ||||
| @@ -186,6 +190,8 @@ public class CVSPass extends Task { | |||||
| /** | /** | ||||
| * Password file to add the entry to. | * Password file to add the entry to. | ||||
| * | |||||
| * @param passFile the password file. | |||||
| */ | */ | ||||
| public void setPassfile(File passFile) { | public void setPassfile(File passFile) { | ||||
| this.passFile = passFile; | this.passFile = passFile; | ||||
| @@ -193,6 +199,8 @@ public class CVSPass extends Task { | |||||
| /** | /** | ||||
| * Password to be added to the password file. | * Password to be added to the password file. | ||||
| * | |||||
| * @param password the password. | |||||
| */ | */ | ||||
| public void setPassword(String password) { | public void setPassword(String password) { | ||||
| this.password = password; | this.password = password; | ||||
| @@ -71,81 +71,79 @@ import java.util.jar.Manifest; | |||||
| * Java2 Standard Edition package, in file | * Java2 Standard Edition package, in file | ||||
| * <code>guide/extensions/versioning.html</code>.</p> | * <code>guide/extensions/versioning.html</code>.</p> | ||||
| * | * | ||||
| * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | |||||
| * This file is from excalibur.extension package. Dont edit this file | |||||
| * directly as there is no unit tests to make sure it is operational | |||||
| * in ant. Edit file in excalibur and run tests there before changing | |||||
| * ants file. | |||||
| * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | |||||
| * | |||||
| * @author <a href="mailto:peter@apache.org">Peter Donald</a> | * @author <a href="mailto:peter@apache.org">Peter Donald</a> | ||||
| * @version $Revision$ $Date$ | * @version $Revision$ $Date$ | ||||
| */ | */ | ||||
| public final class Specification | |||||
| { | |||||
| public final class Specification { | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for SPECIFICATION_TITLE. | * Manifest Attribute Name object for SPECIFICATION_TITLE. | ||||
| * @see Attributes.Name#SPECIFICATION_TITLE | * @see Attributes.Name#SPECIFICATION_TITLE | ||||
| */ | */ | ||||
| public static final Attributes.Name SPECIFICATION_TITLE = Attributes.Name.SPECIFICATION_TITLE; | |||||
| public static final Attributes.Name SPECIFICATION_TITLE | |||||
| = Attributes.Name.SPECIFICATION_TITLE; | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for SPECIFICATION_VERSION. | * Manifest Attribute Name object for SPECIFICATION_VERSION. | ||||
| * @see Attributes.Name#SPECIFICATION_VERSION | * @see Attributes.Name#SPECIFICATION_VERSION | ||||
| */ | */ | ||||
| public static final Attributes.Name SPECIFICATION_VERSION = Attributes.Name.SPECIFICATION_VERSION; | |||||
| public static final Attributes.Name SPECIFICATION_VERSION | |||||
| = Attributes.Name.SPECIFICATION_VERSION; | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for SPECIFICATION_VENDOR. | * Manifest Attribute Name object for SPECIFICATION_VENDOR. | ||||
| * @see Attributes.Name#SPECIFICATION_VENDOR | * @see Attributes.Name#SPECIFICATION_VENDOR | ||||
| */ | */ | ||||
| public static final Attributes.Name SPECIFICATION_VENDOR = Attributes.Name.SPECIFICATION_VENDOR; | |||||
| public static final Attributes.Name SPECIFICATION_VENDOR | |||||
| = Attributes.Name.SPECIFICATION_VENDOR; | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for IMPLEMENTATION_TITLE. | * Manifest Attribute Name object for IMPLEMENTATION_TITLE. | ||||
| * @see Attributes.Name#IMPLEMENTATION_TITLE | * @see Attributes.Name#IMPLEMENTATION_TITLE | ||||
| */ | */ | ||||
| public static final Attributes.Name IMPLEMENTATION_TITLE = Attributes.Name.IMPLEMENTATION_TITLE; | |||||
| public static final Attributes.Name IMPLEMENTATION_TITLE | |||||
| = Attributes.Name.IMPLEMENTATION_TITLE; | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for IMPLEMENTATION_VERSION. | * Manifest Attribute Name object for IMPLEMENTATION_VERSION. | ||||
| * @see Attributes.Name#IMPLEMENTATION_VERSION | * @see Attributes.Name#IMPLEMENTATION_VERSION | ||||
| */ | */ | ||||
| public static final Attributes.Name IMPLEMENTATION_VERSION = Attributes.Name.IMPLEMENTATION_VERSION; | |||||
| public static final Attributes.Name IMPLEMENTATION_VERSION | |||||
| = Attributes.Name.IMPLEMENTATION_VERSION; | |||||
| /** | /** | ||||
| * Manifest Attribute Name object for IMPLEMENTATION_VENDOR. | * Manifest Attribute Name object for IMPLEMENTATION_VENDOR. | ||||
| * @see Attributes.Name#IMPLEMENTATION_VENDOR | * @see Attributes.Name#IMPLEMENTATION_VENDOR | ||||
| */ | */ | ||||
| public static final Attributes.Name IMPLEMENTATION_VENDOR = Attributes.Name.IMPLEMENTATION_VENDOR; | |||||
| public static final Attributes.Name IMPLEMENTATION_VENDOR | |||||
| = Attributes.Name.IMPLEMENTATION_VENDOR; | |||||
| /** | /** | ||||
| * Enum indicating that extension is compatible with other Package | * Enum indicating that extension is compatible with other Package | ||||
| * Specification. | * Specification. | ||||
| */ | */ | ||||
| public static final Compatibility COMPATIBLE = | public static final Compatibility COMPATIBLE = | ||||
| new Compatibility( "COMPATIBLE" ); | |||||
| new Compatibility("COMPATIBLE"); | |||||
| /** | /** | ||||
| * Enum indicating that extension requires an upgrade | * Enum indicating that extension requires an upgrade | ||||
| * of specification to be compatible with other Package Specification. | * of specification to be compatible with other Package Specification. | ||||
| */ | */ | ||||
| public static final Compatibility REQUIRE_SPECIFICATION_UPGRADE = | public static final Compatibility REQUIRE_SPECIFICATION_UPGRADE = | ||||
| new Compatibility( "REQUIRE_SPECIFICATION_UPGRADE" ); | |||||
| new Compatibility("REQUIRE_SPECIFICATION_UPGRADE"); | |||||
| /** | /** | ||||
| * Enum indicating that extension requires a vendor | * Enum indicating that extension requires a vendor | ||||
| * switch to be compatible with other Package Specification. | * switch to be compatible with other Package Specification. | ||||
| */ | */ | ||||
| public static final Compatibility REQUIRE_VENDOR_SWITCH = | public static final Compatibility REQUIRE_VENDOR_SWITCH = | ||||
| new Compatibility( "REQUIRE_VENDOR_SWITCH" ); | |||||
| new Compatibility("REQUIRE_VENDOR_SWITCH"); | |||||
| /** | /** | ||||
| * Enum indicating that extension requires an upgrade | * Enum indicating that extension requires an upgrade | ||||
| * of implementation to be compatible with other Package Specification. | * of implementation to be compatible with other Package Specification. | ||||
| */ | */ | ||||
| public static final Compatibility REQUIRE_IMPLEMENTATION_CHANGE = | public static final Compatibility REQUIRE_IMPLEMENTATION_CHANGE = | ||||
| new Compatibility( "REQUIRE_IMPLEMENTATION_CHANGE" ); | |||||
| new Compatibility("REQUIRE_IMPLEMENTATION_CHANGE"); | |||||
| /** | /** | ||||
| * Enum indicating that extension is incompatible with | * Enum indicating that extension is incompatible with | ||||
| @@ -154,46 +152,46 @@ public final class Specification | |||||
| * may have a different ID. | * may have a different ID. | ||||
| */ | */ | ||||
| public static final Compatibility INCOMPATIBLE = | public static final Compatibility INCOMPATIBLE = | ||||
| new Compatibility( "INCOMPATIBLE" ); | |||||
| new Compatibility("INCOMPATIBLE"); | |||||
| /** | /** | ||||
| * The name of the Package Specification. | * The name of the Package Specification. | ||||
| */ | */ | ||||
| private String m_specificationTitle; | |||||
| private String specificationTitle; | |||||
| /** | /** | ||||
| * The version number (dotted decimal notation) of the specification | * The version number (dotted decimal notation) of the specification | ||||
| * to which this optional package conforms. | * to which this optional package conforms. | ||||
| */ | */ | ||||
| private DeweyDecimal m_specificationVersion; | |||||
| private DeweyDecimal specificationVersion; | |||||
| /** | /** | ||||
| * The name of the company or organization that originated the | * The name of the company or organization that originated the | ||||
| * specification to which this specification conforms. | * specification to which this specification conforms. | ||||
| */ | */ | ||||
| private String m_specificationVendor; | |||||
| private String specificationVendor; | |||||
| /** | /** | ||||
| * The title of implementation. | * The title of implementation. | ||||
| */ | */ | ||||
| private String m_implementationTitle; | |||||
| private String implementationTitle; | |||||
| /** | /** | ||||
| * The name of the company or organization that produced this | * The name of the company or organization that produced this | ||||
| * implementation of this specification. | * implementation of this specification. | ||||
| */ | */ | ||||
| private String m_implementationVendor; | |||||
| private String implementationVendor; | |||||
| /** | /** | ||||
| * The version string for implementation. The version string is | * The version string for implementation. The version string is | ||||
| * opaque. | * opaque. | ||||
| */ | */ | ||||
| private String m_implementationVersion; | |||||
| private String implementationVersion; | |||||
| /** | /** | ||||
| * The sections of jar that the specification applies to. | * The sections of jar that the specification applies to. | ||||
| */ | */ | ||||
| private String[] m_sections; | |||||
| private String[] sections; | |||||
| /** | /** | ||||
| * Return an array of <code>Package Specification</code> objects. | * Return an array of <code>Package Specification</code> objects. | ||||
| @@ -201,12 +199,12 @@ public final class Specification | |||||
| * | * | ||||
| * @param manifest Manifest to be parsed | * @param manifest Manifest to be parsed | ||||
| * @return the Package Specifications extensions in specified manifest | * @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 ) | |||||
| { | |||||
| public static Specification[] getSpecifications(final Manifest manifest) | |||||
| throws ParseException { | |||||
| if (null == manifest) { | |||||
| return new Specification[ 0 ]; | return new Specification[ 0 ]; | ||||
| } | } | ||||
| @@ -214,19 +212,18 @@ public final class Specification | |||||
| final Map entries = manifest.getEntries(); | final Map entries = manifest.getEntries(); | ||||
| final Iterator keys = entries.keySet().iterator(); | final Iterator keys = entries.keySet().iterator(); | ||||
| 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 ) | |||||
| { | |||||
| results.add( specification ); | |||||
| 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) { | |||||
| results.add(specification); | |||||
| } | } | ||||
| } | } | ||||
| final ArrayList trimmedResults = removeDuplicates( results ); | |||||
| return (Specification[])trimmedResults.toArray( new Specification[ 0 ] ); | |||||
| final ArrayList trimmedResults = removeDuplicates(results); | |||||
| return (Specification[]) trimmedResults.toArray(new Specification[0]); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -241,16 +238,15 @@ public final class Specification | |||||
| * @param implementationVersion the implementation Version. | * @param implementationVersion the implementation Version. | ||||
| * @param implementationVendor the implementation Vendor. | * @param implementationVendor the implementation Vendor. | ||||
| */ | */ | ||||
| public Specification( final String specificationTitle, | |||||
| public Specification(final String specificationTitle, | |||||
| final String specificationVersion, | final String specificationVersion, | ||||
| final String specificationVendor, | final String specificationVendor, | ||||
| final String implementationTitle, | final String implementationTitle, | ||||
| final String implementationVersion, | final String implementationVersion, | ||||
| final String implementationVendor ) | |||||
| { | |||||
| this( specificationTitle, specificationVersion, specificationVendor, | |||||
| final String implementationVendor) { | |||||
| this(specificationTitle, specificationVersion, specificationVendor, | |||||
| implementationTitle, implementationVersion, implementationVendor, | implementationTitle, implementationVersion, implementationVendor, | ||||
| null ); | |||||
| null); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -266,47 +262,42 @@ public final class Specification | |||||
| * @param implementationVendor the implementation Vendor. | * @param implementationVendor the implementation Vendor. | ||||
| * @param sections the sections/packages that Specification applies to. | * @param sections the sections/packages that Specification applies to. | ||||
| */ | */ | ||||
| public Specification( final String specificationTitle, | |||||
| public Specification(final String specificationTitle, | |||||
| final String specificationVersion, | final String specificationVersion, | ||||
| final String specificationVendor, | final String specificationVendor, | ||||
| final String implementationTitle, | final String implementationTitle, | ||||
| final String implementationVersion, | final String implementationVersion, | ||||
| final String implementationVendor, | 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 + ")"; | |||||
| throw new IllegalArgumentException( error ); | |||||
| 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 ) | |||||
| { | |||||
| throw new NullPointerException( "specificationTitle" ); | |||||
| if (null == this.specificationTitle) { | |||||
| throw new NullPointerException("specificationTitle"); | |||||
| } | } | ||||
| String[] copy = null; | String[] copy = null; | ||||
| if( null != sections ) | |||||
| { | |||||
| if (null != sections) { | |||||
| copy = new String[ sections.length ]; | copy = new String[ sections.length ]; | ||||
| System.arraycopy( sections, 0, copy, 0, sections.length ); | |||||
| System.arraycopy(sections, 0, copy, 0, sections.length); | |||||
| } | } | ||||
| m_sections = copy; | |||||
| this.sections = copy; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -314,9 +305,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the title of speciication | * @return the title of speciication | ||||
| */ | */ | ||||
| public String getSpecificationTitle() | |||||
| { | |||||
| return m_specificationTitle; | |||||
| public String getSpecificationTitle() { | |||||
| return specificationTitle; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -324,9 +314,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the vendor of the specification. | * @return the vendor of the specification. | ||||
| */ | */ | ||||
| public String getSpecificationVendor() | |||||
| { | |||||
| return m_specificationVendor; | |||||
| public String getSpecificationVendor() { | |||||
| return specificationVendor; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -334,9 +323,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the title of the specification. | * @return the title of the specification. | ||||
| */ | */ | ||||
| public String getImplementationTitle() | |||||
| { | |||||
| return m_implementationTitle; | |||||
| public String getImplementationTitle() { | |||||
| return implementationTitle; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -344,9 +332,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the version of the specification. | * @return the version of the specification. | ||||
| */ | */ | ||||
| public DeweyDecimal getSpecificationVersion() | |||||
| { | |||||
| return m_specificationVersion; | |||||
| public DeweyDecimal getSpecificationVersion() { | |||||
| return specificationVersion; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -354,9 +341,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the vendor of the extensions implementation. | * @return the vendor of the extensions implementation. | ||||
| */ | */ | ||||
| public String getImplementationVendor() | |||||
| { | |||||
| return m_implementationVendor; | |||||
| public String getImplementationVendor() { | |||||
| return implementationVendor; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -364,9 +350,8 @@ public final class Specification | |||||
| * | * | ||||
| * @return the version of the implementation. | * @return the version of the implementation. | ||||
| */ | */ | ||||
| public String getImplementationVersion() | |||||
| { | |||||
| return m_implementationVersion; | |||||
| public String getImplementationVersion() { | |||||
| return implementationVersion; | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -376,65 +361,55 @@ public final class Specification | |||||
| * @return an array containing sections to which specification applies | * @return an array containing sections to which specification applies | ||||
| * or null if relevent to no sections. | * or null if relevent to no sections. | ||||
| */ | */ | ||||
| public String[] getSections() | |||||
| { | |||||
| if( null == m_sections ) | |||||
| { | |||||
| public String[] getSections() { | |||||
| if (null == sections) { | |||||
| return null; | 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 | * Return a Compatibility enum indicating the relationship of this | ||||
| * <code>Package Specification</code> with the specified <code>Extension</code>. | |||||
| * <code>Package Specification</code> with the specified | |||||
| * <code>Extension</code>. | |||||
| * | * | ||||
| * @param other the other specification | * @param other the other specification | ||||
| * @return the enum indicating the compatibility (or lack thereof) | * @return the enum indicating the compatibility (or lack thereof) | ||||
| * of specifed Package Specification | * of specifed Package Specification | ||||
| */ | */ | ||||
| public Compatibility getCompatibilityWith( final Specification other ) | |||||
| { | |||||
| public Compatibility getCompatibilityWith(final Specification other) { | |||||
| // Specification Name must match | // Specification Name must match | ||||
| if( !m_specificationTitle.equals( other.getSpecificationTitle() ) ) | |||||
| { | |||||
| if (!specificationTitle.equals(other.getSpecificationTitle())) { | |||||
| return INCOMPATIBLE; | return INCOMPATIBLE; | ||||
| } | } | ||||
| // Available specification version must be >= required | // 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; | return REQUIRE_SPECIFICATION_UPGRADE; | ||||
| } | } | ||||
| } | } | ||||
| // Implementation Vendor ID must match | // Implementation Vendor ID must match | ||||
| final String implementationVendor = other.getImplementationVendor(); | 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; | return REQUIRE_VENDOR_SWITCH; | ||||
| } | } | ||||
| } | } | ||||
| // Implementation version must be >= required | // Implementation version must be >= required | ||||
| final String implementationVersion = other.getImplementationVersion(); | 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; | return REQUIRE_IMPLEMENTATION_CHANGE; | ||||
| } | } | ||||
| } | } | ||||
| @@ -451,9 +426,8 @@ public final class Specification | |||||
| * @param other the specification | * @param other the specification | ||||
| * @return true if the specification is compatible with this specification | * @return true if the specification is compatible with this specification | ||||
| */ | */ | ||||
| public boolean isCompatibleWith( final Specification other ) | |||||
| { | |||||
| return ( COMPATIBLE == getCompatibilityWith( other ) ); | |||||
| public boolean isCompatibleWith(final Specification other) { | |||||
| return (COMPATIBLE == getCompatibilityWith(other)); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -461,54 +435,49 @@ public final class Specification | |||||
| * | * | ||||
| * @return string representation of object. | * @return string representation of object. | ||||
| */ | */ | ||||
| public String toString() | |||||
| { | |||||
| final String lineSeparator = System.getProperty( "line.separator" ); | |||||
| public String toString() { | |||||
| final String lineSeparator = System.getProperty("line.separator"); | |||||
| final String brace = ": "; | final String brace = ": "; | ||||
| final StringBuffer sb = new StringBuffer( SPECIFICATION_TITLE.toString() ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_specificationTitle ); | |||||
| sb.append( lineSeparator ); | |||||
| if( null != m_specificationVersion ) | |||||
| { | |||||
| sb.append( SPECIFICATION_VERSION ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_specificationVersion ); | |||||
| sb.append( lineSeparator ); | |||||
| final StringBuffer sb | |||||
| = new StringBuffer(SPECIFICATION_TITLE.toString()); | |||||
| sb.append(brace); | |||||
| sb.append(specificationTitle); | |||||
| sb.append(lineSeparator); | |||||
| if (null != specificationVersion) { | |||||
| sb.append(SPECIFICATION_VERSION); | |||||
| sb.append(brace); | |||||
| sb.append(specificationVersion); | |||||
| sb.append(lineSeparator); | |||||
| } | } | ||||
| if( null != m_specificationVendor ) | |||||
| { | |||||
| sb.append( SPECIFICATION_VENDOR ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_specificationVendor ); | |||||
| sb.append( lineSeparator ); | |||||
| if (null != specificationVendor) { | |||||
| sb.append(SPECIFICATION_VENDOR); | |||||
| sb.append(brace); | |||||
| sb.append(specificationVendor); | |||||
| sb.append(lineSeparator); | |||||
| } | } | ||||
| if( null != m_implementationTitle ) | |||||
| { | |||||
| sb.append( IMPLEMENTATION_TITLE ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_implementationTitle ); | |||||
| sb.append( lineSeparator ); | |||||
| if (null != implementationTitle) { | |||||
| sb.append(IMPLEMENTATION_TITLE); | |||||
| sb.append(brace); | |||||
| sb.append(implementationTitle); | |||||
| sb.append(lineSeparator); | |||||
| } | } | ||||
| if( null != m_implementationVersion ) | |||||
| { | |||||
| sb.append( IMPLEMENTATION_VERSION ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_implementationVersion ); | |||||
| sb.append( lineSeparator ); | |||||
| if (null != implementationVersion) { | |||||
| sb.append(IMPLEMENTATION_VERSION); | |||||
| sb.append(brace); | |||||
| sb.append(implementationVersion); | |||||
| sb.append(lineSeparator); | |||||
| } | } | ||||
| if( null != m_implementationVendor ) | |||||
| { | |||||
| sb.append( IMPLEMENTATION_VENDOR ); | |||||
| sb.append( brace ); | |||||
| sb.append( m_implementationVendor ); | |||||
| sb.append( lineSeparator ); | |||||
| if (null != implementationVendor) { | |||||
| sb.append(IMPLEMENTATION_VENDOR); | |||||
| sb.append(brace); | |||||
| sb.append(implementationVendor); | |||||
| sb.append(lineSeparator); | |||||
| } | } | ||||
| return sb.toString(); | return sb.toString(); | ||||
| @@ -521,9 +490,9 @@ public final class Specification | |||||
| * @param first First version number (dotted decimal) | * @param first First version number (dotted decimal) | ||||
| * @param second Second version number (dotted decimal) | * @param second Second version number (dotted decimal) | ||||
| */ | */ | ||||
| private boolean isCompatible( final DeweyDecimal first, final DeweyDecimal second ) | |||||
| { | |||||
| return first.isGreaterThanOrEqual( second ); | |||||
| private boolean isCompatible(final DeweyDecimal first, | |||||
| final DeweyDecimal second) { | |||||
| return first.isGreaterThanOrEqual(second); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -536,31 +505,26 @@ public final class Specification | |||||
| * @param list the array of results to trim | * @param list the array of results to trim | ||||
| * @return an array list with all duplicates removed | * @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 results = new ArrayList(); | ||||
| final ArrayList sections = new ArrayList(); | final ArrayList sections = new ArrayList(); | ||||
| while( list.size() > 0 ) | |||||
| { | |||||
| final Specification specification = (Specification)list.remove( 0 ); | |||||
| while (list.size() > 0) { | |||||
| final Specification specification = (Specification) list.remove(0); | |||||
| final Iterator iterator = list.iterator(); | final Iterator iterator = list.iterator(); | ||||
| while( iterator.hasNext() ) | |||||
| { | |||||
| final Specification other = (Specification)iterator.next(); | |||||
| if( isEqual( specification, other ) ) | |||||
| { | |||||
| while (iterator.hasNext()) { | |||||
| final Specification other = (Specification) iterator.next(); | |||||
| if (isEqual(specification, other)) { | |||||
| final String[] otherSections = other.getSections(); | final String[] otherSections = other.getSections(); | ||||
| if( null != sections ) | |||||
| { | |||||
| sections.addAll( Arrays.asList( otherSections ) ); | |||||
| if (null != sections) { | |||||
| sections.addAll(Arrays.asList(otherSections)); | |||||
| } | } | ||||
| iterator.remove(); | iterator.remove(); | ||||
| } | } | ||||
| } | } | ||||
| final Specification merged = | final Specification merged = | ||||
| mergeInSections( specification, sections ); | |||||
| results.add( merged ); | |||||
| mergeInSections(specification, sections); | |||||
| results.add(merged); | |||||
| //Reset list of sections | //Reset list of sections | ||||
| sections.clear(); | sections.clear(); | ||||
| } | } | ||||
| @@ -576,16 +540,15 @@ public final class Specification | |||||
| * @return true if two specifications are equal except for their | * @return true if two specifications are equal except for their | ||||
| * sections, else false | * sections, else false | ||||
| */ | */ | ||||
| private static boolean isEqual( final Specification specification, | |||||
| final Specification other ) | |||||
| { | |||||
| private static boolean isEqual(final Specification specification, | |||||
| final Specification other) { | |||||
| return | 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()); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -596,27 +559,23 @@ public final class Specification | |||||
| * @param sectionsToAdd the list of sections to merge | * @param sectionsToAdd the list of sections to merge | ||||
| * @return the merged specification | * @return the merged specification | ||||
| */ | */ | ||||
| private static Specification mergeInSections( final Specification specification, | |||||
| final ArrayList sectionsToAdd ) | |||||
| { | |||||
| if( 0 == sectionsToAdd.size() ) | |||||
| { | |||||
| private static Specification mergeInSections(final Specification specification, | |||||
| final ArrayList sectionsToAdd) { | |||||
| if (0 == sectionsToAdd.size()) { | |||||
| return specification; | return specification; | ||||
| } | |||||
| else | |||||
| { | |||||
| sectionsToAdd.addAll( Arrays.asList( specification.getSections() ) ); | |||||
| } else { | |||||
| sectionsToAdd.addAll(Arrays.asList(specification.getSections())); | |||||
| final String[] sections = | final String[] sections = | ||||
| (String[])sectionsToAdd.toArray( new String[ sectionsToAdd.size() ] ); | |||||
| (String[]) sectionsToAdd.toArray(new String[sectionsToAdd.size()]); | |||||
| return new Specification( specification.getSpecificationTitle(), | |||||
| return new Specification(specification.getSpecificationTitle(), | |||||
| specification.getSpecificationVersion().toString(), | specification.getSpecificationVersion().toString(), | ||||
| specification.getSpecificationVendor(), | specification.getSpecificationVendor(), | ||||
| specification.getImplementationTitle(), | specification.getImplementationTitle(), | ||||
| specification.getImplementationVersion(), | specification.getImplementationVersion(), | ||||
| specification.getImplementationVendor(), | specification.getImplementationVendor(), | ||||
| sections ); | |||||
| sections); | |||||
| } | } | ||||
| } | } | ||||
| @@ -626,14 +585,10 @@ public final class Specification | |||||
| * @param value the string to trim or null | * @param value the string to trim or null | ||||
| * @return the trimmed string 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; | return null; | ||||
| } | |||||
| else | |||||
| { | |||||
| } else { | |||||
| return value.trim(); | return value.trim(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -644,51 +599,50 @@ public final class Specification | |||||
| * @param attributes Attributes to searched | * @param attributes Attributes to searched | ||||
| * @return the new Specification object, or null | * @return the new Specification object, or null | ||||
| */ | */ | ||||
| private static Specification getSpecification( final String section, | |||||
| final Attributes attributes ) | |||||
| throws ParseException | |||||
| { | |||||
| private static Specification getSpecification(final String section, | |||||
| final Attributes attributes) | |||||
| throws ParseException { | |||||
| //WARNING: We trim the values of all the attributes because | //WARNING: We trim the values of all the attributes because | ||||
| //Some extension declarations are badly defined (ie have spaces | //Some extension declarations are badly defined (ie have spaces | ||||
| //after version or vendor) | //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; | return null; | ||||
| } | } | ||||
| final String specVendor = getTrimmedString( attributes.getValue( SPECIFICATION_VENDOR ) ); | |||||
| if( null == specVendor ) | |||||
| { | |||||
| throw new ParseException( "Missing " + SPECIFICATION_VENDOR, 0 ); | |||||
| 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 ) | |||||
| { | |||||
| throw new ParseException( "Missing " + SPECIFICATION_VERSION, 0 ); | |||||
| 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 ) | |||||
| { | |||||
| throw new ParseException( "Missing " + IMPLEMENTATION_TITLE, 0 ); | |||||
| 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 ) | |||||
| { | |||||
| throw new ParseException( "Missing " + IMPLEMENTATION_VERSION, 0 ); | |||||
| 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 ) | |||||
| { | |||||
| throw new ParseException( "Missing " + IMPLEMENTATION_VENDOR, 0 ); | |||||
| final String impVendor | |||||
| = getTrimmedString(attributes.getValue(IMPLEMENTATION_VENDOR)); | |||||
| if (null == impVendor) { | |||||
| throw new ParseException("Missing " + IMPLEMENTATION_VENDOR, 0); | |||||
| } | } | ||||
| return new Specification( name, specVersion, specVendor, | |||||
| return new Specification(name, specVersion, specVendor, | |||||
| impTitle, impVersion, impVendor, | impTitle, impVersion, impVendor, | ||||
| new String[]{section} ); | |||||
| new String[]{section}); | |||||
| } | } | ||||
| } | } | ||||
| @@ -53,7 +53,7 @@ | |||||
| */ | */ | ||||
| /* | /* | ||||
| * This package is based on the work done by Timothy Gerard Endres | |||||
| * This package is based on the work done by Timothy Gerard Endres | |||||
| * (time@ice.com) to whom the Ant project is very grateful for his great code. | * (time@ice.com) to whom the Ant project is very grateful for his great code. | ||||
| */ | */ | ||||
| @@ -88,7 +88,7 @@ import java.util.Locale; | |||||
| * the archive, and the header information is constructed from | * the archive, and the header information is constructed from | ||||
| * other information. In this case the header fields are set to | * other information. In this case the header fields are set to | ||||
| * defaults and the File is set to null. | * defaults and the File is set to null. | ||||
| * | |||||
| * | |||||
| * <p> | * <p> | ||||
| * The C structure for a Tar Entry's header is: | * The C structure for a Tar Entry's header is: | ||||
| * <pre> | * <pre> | ||||
| @@ -109,209 +109,265 @@ import java.util.Locale; | |||||
| * char devminor[8]; | * char devminor[8]; | ||||
| * } header; | * } header; | ||||
| * </pre> | * </pre> | ||||
| * | |||||
| * | |||||
| * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a> | * @author Timothy Gerard Endres <a href="mailto:time@ice.com">time@ice.com</a> | ||||
| * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> | * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a> | ||||
| */ | */ | ||||
| public class TarEntry implements TarConstants { | public class TarEntry implements TarConstants { | ||||
| /** The entry's name. */ | |||||
| private StringBuffer name; | |||||
| /** 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; | |||||
| 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 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. | * Construct an empty entry and prepares the header values. | ||||
| */ | |||||
| */ | |||||
| private TarEntry () { | private TarEntry () { | ||||
| this.magic = new StringBuffer(TMAGIC); | this.magic = new StringBuffer(TMAGIC); | ||||
| this.name = new StringBuffer(); | this.name = new StringBuffer(); | ||||
| this.linkName = new StringBuffer(); | this.linkName = new StringBuffer(); | ||||
| String user = System.getProperty("user.name", ""); | 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; | this.userId = 0; | ||||
| this.groupId = 0; | this.groupId = 0; | ||||
| this.userName = new StringBuffer(user); | this.userName = new StringBuffer(user); | ||||
| this.groupName = new StringBuffer(""); | this.groupName = new StringBuffer(""); | ||||
| this.file = null; | this.file = null; | ||||
| } | } | ||||
| /** | |||||
| /** | |||||
| * Construct an entry with only a name. This allows the programmer | * Construct an entry with only a name. This allows the programmer | ||||
| * to construct the entry's header "by hand". File is set to null. | * to construct the entry's header "by hand". File is set to null. | ||||
| */ | |||||
| * | |||||
| * @param name the entry name | |||||
| */ | |||||
| public TarEntry(String name) { | public TarEntry(String name) { | ||||
| this(); | this(); | ||||
| boolean isDir = name.endsWith("/"); | boolean isDir = name.endsWith("/"); | ||||
| this.checkSum = 0; | this.checkSum = 0; | ||||
| this.devMajor = 0; | this.devMajor = 0; | ||||
| this.devMinor = 0; | this.devMinor = 0; | ||||
| this.name = new StringBuffer(name); | 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.linkFlag = isDir ? LF_DIR : LF_NORMAL; | ||||
| this.userId = 0; | this.userId = 0; | ||||
| this.groupId = 0; | this.groupId = 0; | ||||
| this.size = 0; | this.size = 0; | ||||
| this.checkSum = 0; | this.checkSum = 0; | ||||
| this.modTime = (new Date()).getTime() / 1000; | |||||
| this.modTime = (new Date()).getTime() / MILLIS_PER_SECOND; | |||||
| this.linkName = new StringBuffer(""); | this.linkName = new StringBuffer(""); | ||||
| this.userName = new StringBuffer(""); | this.userName = new StringBuffer(""); | ||||
| this.groupName = new StringBuffer(""); | this.groupName = new StringBuffer(""); | ||||
| this.devMajor = 0; | this.devMajor = 0; | ||||
| this.devMinor = 0; | this.devMinor = 0; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Construct an entry with a name an a link flag. | * 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) { | public TarEntry(String name, byte linkFlag) { | ||||
| this(name); | this(name); | ||||
| this.linkFlag = linkFlag; | this.linkFlag = linkFlag; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Construct an entry for a file. File is set to file, and the | * Construct an entry for a file. File is set to file, and the | ||||
| * header is constructed from information from the file. | * header is constructed from information from the file. | ||||
| * | |||||
| * | |||||
| * @param file The file that the entry represents. | * @param file The file that the entry represents. | ||||
| */ | |||||
| */ | |||||
| public TarEntry(File file) { | public TarEntry(File file) { | ||||
| this(); | this(); | ||||
| this.file = file; | this.file = file; | ||||
| String name = file.getPath(); | String name = file.getPath(); | ||||
| String osname = System.getProperty("os.name").toLowerCase(Locale.US); | String osname = System.getProperty("os.name").toLowerCase(Locale.US); | ||||
| if (osname != null) { | if (osname != null) { | ||||
| // Strip off drive letters! | // Strip off drive letters! | ||||
| // REVIEW Would a better check be "(File.separator == '\')"? | // REVIEW Would a better check be "(File.separator == '\')"? | ||||
| if (osname.startsWith("windows")) { | if (osname.startsWith("windows")) { | ||||
| if (name.length() > 2) { | if (name.length() > 2) { | ||||
| char ch1 = name.charAt(0); | char ch1 = name.charAt(0); | ||||
| char ch2 = name.charAt(1); | char ch2 = name.charAt(1); | ||||
| if (ch2 == ':' | |||||
| && ((ch1 >= 'a' && ch1 <= 'z') | |||||
| if (ch2 == ':' | |||||
| && ((ch1 >= 'a' && ch1 <= 'z') | |||||
| || (ch1 >= 'A' && ch1 <= 'Z'))) { | || (ch1 >= 'A' && ch1 <= 'Z'))) { | ||||
| name = name.substring(2); | name = name.substring(2); | ||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| } else if (osname.indexOf("netware") > -1) { | } else if (osname.indexOf("netware") > -1) { | ||||
| int colon = name.indexOf(':'); | int colon = name.indexOf(':'); | ||||
| if (colon != -1) { | if (colon != -1) { | ||||
| name = name.substring(colon + 1); | name = name.substring(colon + 1); | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||
| name = name.replace(File.separatorChar, '/'); | name = name.replace(File.separatorChar, '/'); | ||||
| // No absolute pathnames | // No absolute pathnames | ||||
| // Windows (and Posix?) paths can start with "\\NetworkDrive\", | // Windows (and Posix?) paths can start with "\\NetworkDrive\", | ||||
| // so we loop on starting /'s. | // so we loop on starting /'s. | ||||
| while (name.startsWith("/")) { | while (name.startsWith("/")) { | ||||
| name = name.substring(1); | name = name.substring(1); | ||||
| } | } | ||||
| this.linkName = new StringBuffer(""); | this.linkName = new StringBuffer(""); | ||||
| this.name = new StringBuffer(name); | this.name = new StringBuffer(name); | ||||
| if (file.isDirectory()) { | if (file.isDirectory()) { | ||||
| this.mode = 040755; | |||||
| this.mode = DEFAULT_DIR_MODE; | |||||
| this.linkFlag = LF_DIR; | this.linkFlag = LF_DIR; | ||||
| if (this.name.charAt(this.name.length() - 1) != '/') { | if (this.name.charAt(this.name.length() - 1) != '/') { | ||||
| this.name.append("/"); | this.name.append("/"); | ||||
| } | |||||
| } | |||||
| } else { | } else { | ||||
| this.mode = 0100644; | |||||
| this.mode = DEFAULT_FILE_MODE; | |||||
| this.linkFlag = LF_NORMAL; | this.linkFlag = LF_NORMAL; | ||||
| } | |||||
| } | |||||
| this.size = file.length(); | this.size = file.length(); | ||||
| this.modTime = file.lastModified() / 1000; | |||||
| this.modTime = file.lastModified() / MILLIS_PER_SECOND; | |||||
| this.checkSum = 0; | this.checkSum = 0; | ||||
| this.devMajor = 0; | this.devMajor = 0; | ||||
| this.devMinor = 0; | this.devMinor = 0; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Construct an entry from an archive's header bytes. File is set | * Construct an entry from an archive's header bytes. File is set | ||||
| * to null. | * to null. | ||||
| * | |||||
| * | |||||
| * @param headerBuf The header bytes from a tar archive entry. | * @param headerBuf The header bytes from a tar archive entry. | ||||
| */ | |||||
| */ | |||||
| public TarEntry(byte[] headerBuf) { | public TarEntry(byte[] headerBuf) { | ||||
| this(); | this(); | ||||
| this.parseTarHeader(headerBuf); | this.parseTarHeader(headerBuf); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Determine if the two entries are equal. Equality is determined | * Determine if the two entries are equal. Equality is determined | ||||
| * by the header names being equal. | * 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. | * @return True if the entries are equal. | ||||
| */ | |||||
| */ | |||||
| public boolean equals(TarEntry it) { | public boolean equals(TarEntry it) { | ||||
| return this.getName().equals(it.getName()); | return this.getName().equals(it.getName()); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * 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. | * Determine if the given entry is a descendant of this entry. | ||||
| * Descendancy is determined by the name of the descendant | * Descendancy is determined by the name of the descendant | ||||
| * starting with this entry's name. | * starting with this entry's name. | ||||
| * | |||||
| * | |||||
| * @param desc Entry to be checked as a descendent of this. | * @param desc Entry to be checked as a descendent of this. | ||||
| * @return True if entry is a descendant of this. | * @return True if entry is a descendant of this. | ||||
| */ | |||||
| */ | |||||
| public boolean isDescendent(TarEntry desc) { | public boolean isDescendent(TarEntry desc) { | ||||
| return desc.getName().startsWith(this.getName()); | return desc.getName().startsWith(this.getName()); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Get this entry's name. | * Get this entry's name. | ||||
| * | |||||
| * | |||||
| * @return This entry's name. | * @return This entry's name. | ||||
| */ | |||||
| */ | |||||
| public String getName() { | public String getName() { | ||||
| return this.name.toString(); | return this.name.toString(); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's name. | * Set this entry's name. | ||||
| * | |||||
| * | |||||
| * @param name This entry's new name. | * @param name This entry's new name. | ||||
| */ | |||||
| */ | |||||
| public void setName(String name) { | public void setName(String name) { | ||||
| this.name = new StringBuffer(name); | this.name = new StringBuffer(name); | ||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Set the mode for this entry | * Set the mode for this entry | ||||
| * | |||||
| * @param mode the mode for this entry | |||||
| */ | */ | ||||
| public void setMode(int mode) { | public void setMode(int mode) { | ||||
| this.mode = mode; | this.mode = mode; | ||||
| @@ -326,138 +382,138 @@ public class TarEntry implements TarConstants { | |||||
| return this.linkName.toString(); | return this.linkName.toString(); | ||||
| } | } | ||||
| /** | |||||
| /** | |||||
| * Get this entry's user id. | * Get this entry's user id. | ||||
| * | |||||
| * | |||||
| * @return This entry's user id. | * @return This entry's user id. | ||||
| */ | |||||
| */ | |||||
| public int getUserId() { | public int getUserId() { | ||||
| return this.userId; | return this.userId; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's user id. | * Set this entry's user id. | ||||
| * | |||||
| * | |||||
| * @param userId This entry's new user id. | * @param userId This entry's new user id. | ||||
| */ | |||||
| */ | |||||
| public void setUserId(int userId) { | public void setUserId(int userId) { | ||||
| this.userId = userId; | this.userId = userId; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Get this entry's group id. | * Get this entry's group id. | ||||
| * | |||||
| * | |||||
| * @return This entry's group id. | * @return This entry's group id. | ||||
| */ | |||||
| */ | |||||
| public int getGroupId() { | public int getGroupId() { | ||||
| return this.groupId; | return this.groupId; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's group id. | * Set this entry's group id. | ||||
| * | |||||
| * | |||||
| * @param groupId This entry's new group id. | * @param groupId This entry's new group id. | ||||
| */ | |||||
| */ | |||||
| public void setGroupId(int groupId) { | public void setGroupId(int groupId) { | ||||
| this.groupId = groupId; | this.groupId = groupId; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Get this entry's user name. | * Get this entry's user name. | ||||
| * | |||||
| * | |||||
| * @return This entry's user name. | * @return This entry's user name. | ||||
| */ | |||||
| */ | |||||
| public String getUserName() { | public String getUserName() { | ||||
| return this.userName.toString(); | return this.userName.toString(); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's user name. | * Set this entry's user name. | ||||
| * | |||||
| * | |||||
| * @param userName This entry's new user name. | * @param userName This entry's new user name. | ||||
| */ | |||||
| */ | |||||
| public void setUserName(String userName) { | public void setUserName(String userName) { | ||||
| this.userName = new StringBuffer(userName); | this.userName = new StringBuffer(userName); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Get this entry's group name. | * Get this entry's group name. | ||||
| * | |||||
| * | |||||
| * @return This entry's group name. | * @return This entry's group name. | ||||
| */ | |||||
| */ | |||||
| public String getGroupName() { | public String getGroupName() { | ||||
| return this.groupName.toString(); | return this.groupName.toString(); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's group name. | * Set this entry's group name. | ||||
| * | |||||
| * | |||||
| * @param groupName This entry's new group name. | * @param groupName This entry's new group name. | ||||
| */ | |||||
| */ | |||||
| public void setGroupName(String groupName) { | public void setGroupName(String groupName) { | ||||
| this.groupName = new StringBuffer(groupName); | this.groupName = new StringBuffer(groupName); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Convenience method to set this entry's group and user ids. | * Convenience method to set this entry's group and user ids. | ||||
| * | |||||
| * | |||||
| * @param userId This entry's new user id. | * @param userId This entry's new user id. | ||||
| * @param groupId This entry's new group id. | * @param groupId This entry's new group id. | ||||
| */ | |||||
| */ | |||||
| public void setIds(int userId, int groupId) { | public void setIds(int userId, int groupId) { | ||||
| this.setUserId(userId); | this.setUserId(userId); | ||||
| this.setGroupId(groupId); | this.setGroupId(groupId); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Convenience method to set this entry's group and user names. | * Convenience method to set this entry's group and user names. | ||||
| * | |||||
| * | |||||
| * @param userName This entry's new user name. | * @param userName This entry's new user name. | ||||
| * @param groupName This entry's new group name. | * @param groupName This entry's new group name. | ||||
| */ | |||||
| */ | |||||
| public void setNames(String userName, String groupName) { | public void setNames(String userName, String groupName) { | ||||
| this.setUserName(userName); | this.setUserName(userName); | ||||
| this.setGroupName(groupName); | this.setGroupName(groupName); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's modification time. The parameter passed | * Set this entry's modification time. The parameter passed | ||||
| * to this method is in "Java time". | * to this method is in "Java time". | ||||
| * | |||||
| * | |||||
| * @param time This entry's new modification time. | * @param time This entry's new modification time. | ||||
| */ | |||||
| */ | |||||
| public void setModTime(long time) { | public void setModTime(long time) { | ||||
| this.modTime = time / 1000; | |||||
| } | |||||
| /** | |||||
| this.modTime = time / MILLIS_PER_SECOND; | |||||
| } | |||||
| /** | |||||
| * Set this entry's modification time. | * Set this entry's modification time. | ||||
| * | |||||
| * | |||||
| * @param time This entry's new modification time. | * @param time This entry's new modification time. | ||||
| */ | |||||
| */ | |||||
| public void setModTime(Date time) { | public void setModTime(Date time) { | ||||
| this.modTime = time.getTime() / 1000; | |||||
| } | |||||
| /** | |||||
| this.modTime = time.getTime() / MILLIS_PER_SECOND; | |||||
| } | |||||
| /** | |||||
| * Set this entry's modification time. | * 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() { | public Date getModTime() { | ||||
| return new Date(this.modTime * 1000); | |||||
| } | |||||
| /** | |||||
| return new Date(this.modTime * MILLIS_PER_SECOND); | |||||
| } | |||||
| /** | |||||
| * Get this entry's file. | * Get this entry's file. | ||||
| * | |||||
| * | |||||
| * @return This entry's file. | * @return This entry's file. | ||||
| */ | |||||
| */ | |||||
| public File getFile() { | public File getFile() { | ||||
| return this.file; | return this.file; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Get this entry's mode. | * Get this entry's mode. | ||||
| * | * | ||||
| * @return This entry's mode. | * @return This entry's mode. | ||||
| @@ -468,96 +524,96 @@ public class TarEntry implements TarConstants { | |||||
| /** | /** | ||||
| * Get this entry's file size. | * Get this entry's file size. | ||||
| * | |||||
| * | |||||
| * @return This entry's file size. | * @return This entry's file size. | ||||
| */ | |||||
| */ | |||||
| public long getSize() { | public long getSize() { | ||||
| return this.size; | return this.size; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Set this entry's file size. | * Set this entry's file size. | ||||
| * | |||||
| * | |||||
| * @param size This entry's new file size. | * @param size This entry's new file size. | ||||
| */ | |||||
| */ | |||||
| public void setSize(long size) { | public void setSize(long size) { | ||||
| this.size = size; | this.size = size; | ||||
| } | |||||
| } | |||||
| /** | /** | ||||
| * Indicate if this entry is a GNU long name block | * Indicate if this entry is a GNU long name block | ||||
| * | * | ||||
| * @return true if this is a long name extension provided by GNU tar | * @return true if this is a long name extension provided by GNU tar | ||||
| */ | */ | ||||
| public boolean isGNULongNameEntry() { | public boolean isGNULongNameEntry() { | ||||
| return linkFlag == LF_GNUTYPE_LONGNAME && | |||||
| name.toString().equals(GNU_LONGLINK); | |||||
| } | |||||
| return linkFlag == LF_GNUTYPE_LONGNAME | |||||
| && name.toString().equals(GNU_LONGLINK); | |||||
| } | |||||
| /** | |||||
| /** | |||||
| * Return whether or not this entry represents a directory. | * Return whether or not this entry represents a directory. | ||||
| * | |||||
| * | |||||
| * @return True if this entry is a directory. | * @return True if this entry is a directory. | ||||
| */ | |||||
| */ | |||||
| public boolean isDirectory() { | public boolean isDirectory() { | ||||
| if (this.file != null) { | if (this.file != null) { | ||||
| return this.file.isDirectory(); | return this.file.isDirectory(); | ||||
| } | |||||
| } | |||||
| if (this.linkFlag == LF_DIR) { | if (this.linkFlag == LF_DIR) { | ||||
| return true; | return true; | ||||
| } | |||||
| } | |||||
| if (this.getName().endsWith("/")) { | if (this.getName().endsWith("/")) { | ||||
| return true; | return true; | ||||
| } | |||||
| } | |||||
| return false; | return false; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * If this entry represents a file, and the file is a directory, return | * If this entry represents a file, and the file is a directory, return | ||||
| * an array of TarEntries for this entry's children. | * an array of TarEntries for this entry's children. | ||||
| * | |||||
| * | |||||
| * @return An array of TarEntry's for this entry's children. | * @return An array of TarEntry's for this entry's children. | ||||
| */ | |||||
| */ | |||||
| public TarEntry[] getDirectoryEntries() { | public TarEntry[] getDirectoryEntries() { | ||||
| if (this.file == null || !this.file.isDirectory()) { | if (this.file == null || !this.file.isDirectory()) { | ||||
| return new TarEntry[0]; | return new TarEntry[0]; | ||||
| } | |||||
| } | |||||
| String[] list = this.file.list(); | String[] list = this.file.list(); | ||||
| TarEntry[] result = new TarEntry[list.length]; | TarEntry[] result = new TarEntry[list.length]; | ||||
| for (int i = 0; i < list.length; ++i) { | for (int i = 0; i < list.length; ++i) { | ||||
| result[i] = new TarEntry(new File(this.file, list[i])); | result[i] = new TarEntry(new File(this.file, list[i])); | ||||
| } | |||||
| } | |||||
| return result; | return result; | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Write an entry's header information to a header buffer. | * Write an entry's header information to a header buffer. | ||||
| * | |||||
| * | |||||
| * @param outbuf The tar entry header buffer to fill in. | * @param outbuf The tar entry header buffer to fill in. | ||||
| */ | |||||
| */ | |||||
| public void writeEntryHeader(byte[] outbuf) { | public void writeEntryHeader(byte[] outbuf) { | ||||
| int offset = 0; | int offset = 0; | ||||
| offset = TarUtils.getNameBytes(this.name, outbuf, offset, NAMELEN); | offset = TarUtils.getNameBytes(this.name, outbuf, offset, NAMELEN); | ||||
| offset = TarUtils.getOctalBytes(this.mode, outbuf, offset, MODELEN); | offset = TarUtils.getOctalBytes(this.mode, outbuf, offset, MODELEN); | ||||
| offset = TarUtils.getOctalBytes(this.userId, outbuf, offset, UIDLEN); | offset = TarUtils.getOctalBytes(this.userId, outbuf, offset, UIDLEN); | ||||
| offset = TarUtils.getOctalBytes(this.groupId, outbuf, offset, GIDLEN); | offset = TarUtils.getOctalBytes(this.groupId, outbuf, offset, GIDLEN); | ||||
| offset = TarUtils.getLongOctalBytes(this.size, outbuf, offset, SIZELEN); | offset = TarUtils.getLongOctalBytes(this.size, outbuf, offset, SIZELEN); | ||||
| offset = TarUtils.getLongOctalBytes(this.modTime, outbuf, offset, MODTIMELEN); | offset = TarUtils.getLongOctalBytes(this.modTime, outbuf, offset, MODTIMELEN); | ||||
| int csOffset = offset; | int csOffset = offset; | ||||
| for (int c = 0; c < CHKSUMLEN; ++c) { | for (int c = 0; c < CHKSUMLEN; ++c) { | ||||
| outbuf[offset++] = (byte) ' '; | outbuf[offset++] = (byte) ' '; | ||||
| } | } | ||||
| outbuf[offset++] = this.linkFlag; | outbuf[offset++] = this.linkFlag; | ||||
| offset = TarUtils.getNameBytes(this.linkName, outbuf, offset, NAMELEN); | offset = TarUtils.getNameBytes(this.linkName, outbuf, offset, NAMELEN); | ||||
| offset = TarUtils.getNameBytes(this.magic, outbuf, offset, MAGICLEN); | offset = TarUtils.getNameBytes(this.magic, outbuf, offset, MAGICLEN); | ||||
| @@ -565,27 +621,27 @@ public class TarEntry implements TarConstants { | |||||
| offset = TarUtils.getNameBytes(this.groupName, outbuf, offset, GNAMELEN); | offset = TarUtils.getNameBytes(this.groupName, outbuf, offset, GNAMELEN); | ||||
| offset = TarUtils.getOctalBytes(this.devMajor, outbuf, offset, DEVLEN); | offset = TarUtils.getOctalBytes(this.devMajor, outbuf, offset, DEVLEN); | ||||
| offset = TarUtils.getOctalBytes(this.devMinor, outbuf, offset, DEVLEN); | offset = TarUtils.getOctalBytes(this.devMinor, outbuf, offset, DEVLEN); | ||||
| while (offset < outbuf.length) { | while (offset < outbuf.length) { | ||||
| outbuf[offset++] = 0; | outbuf[offset++] = 0; | ||||
| } | } | ||||
| long checkSum = TarUtils.computeCheckSum(outbuf); | long checkSum = TarUtils.computeCheckSum(outbuf); | ||||
| TarUtils.getCheckSumOctalBytes(checkSum, outbuf, csOffset, CHKSUMLEN); | TarUtils.getCheckSumOctalBytes(checkSum, outbuf, csOffset, CHKSUMLEN); | ||||
| } | |||||
| /** | |||||
| } | |||||
| /** | |||||
| * Parse an entry's header information from a header buffer. | * Parse an entry's header information from a header buffer. | ||||
| * | |||||
| * | |||||
| * @param header The tar entry header buffer to get information from. | * @param header The tar entry header buffer to get information from. | ||||
| */ | |||||
| */ | |||||
| public void parseTarHeader(byte[] header) { | public void parseTarHeader(byte[] header) { | ||||
| int offset = 0; | int offset = 0; | ||||
| this.name = TarUtils.parseName(header, offset, NAMELEN); | |||||
| this.name = TarUtils.parseName(header, offset, NAMELEN); | |||||
| offset += NAMELEN; | offset += NAMELEN; | ||||
| this.mode = (int) TarUtils.parseOctal(header, offset, MODELEN); | |||||
| this.mode = (int) TarUtils.parseOctal(header, offset, MODELEN); | |||||
| offset += MODELEN; | offset += MODELEN; | ||||
| this.userId = (int) TarUtils.parseOctal(header, offset, UIDLEN); | this.userId = (int) TarUtils.parseOctal(header, offset, UIDLEN); | ||||
| offset += UIDLEN; | offset += UIDLEN; | ||||
| @@ -610,4 +666,4 @@ public class TarEntry implements TarConstants { | |||||
| offset += DEVLEN; | offset += DEVLEN; | ||||
| this.devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN); | this.devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN); | ||||
| } | } | ||||
| } | |||||
| } | |||||