001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.infra.build.ant.utils;
038:
039: import java.io.File;
040: import java.io.IOException;
041:
042: /**
043: * This class represents the collection of meta data for a file.
044: *
045: * @author Kirill Sorokin
046: */
047: public class FileEntry {
048: /**
049: * The file's size.
050: */
051: private long size;
052:
053: /**
054: * The file's MD5 checksum.
055: */
056: private String md5;
057:
058: /**
059: * Whether the entry is a file or a directory.
060: */
061: private boolean directory;
062:
063: /**
064: * Whether the directory is empty.
065: */
066: private boolean empty;
067:
068: /**
069: * Whether the file is a jar file.
070: */
071: private boolean jarFile;
072:
073: /**
074: * Whether the file is a packed jar file.
075: */
076: private boolean packedJarFile;
077:
078: /**
079: * Whether the file is a signed jar file.
080: */
081: private boolean signedJarFile;
082:
083: /**
084: * The file's modification date.
085: */
086: private long lastModified;
087:
088: /**
089: * The file's permissions (e.g. 775).
090: */
091: private int permissions;
092:
093: /**
094: * The entry's name.
095: */
096: private String name;
097:
098: /**
099: * Constructs a new <code>FileEntry</code> instance from the given file.
100: *
101: * @param file The file for which to calculate the metadata.
102: * @param name The name of the entry.
103: * @throws java.io.IOException if an I/O error occurs.
104: */
105: public FileEntry(final File file, final String name)
106: throws IOException {
107: this .directory = file.isDirectory();
108:
109: if (!directory) {
110: this .size = file.length();
111: this .md5 = Utils.getMd5(file);
112:
113: this .jarFile = Utils.isJarFile(file);
114: if (jarFile) {
115: this .packedJarFile = false; // we cannot determine this
116: this .signedJarFile = Utils.isSigned(file);
117: }
118: } else {
119: this .empty = Utils.isEmpty(file);
120: }
121:
122: this .permissions = Utils.getPermissions(file);
123: this .lastModified = file.lastModified();
124: this .name = name;
125: }
126:
127: /**
128: * Getter of the 'size' property.
129: *
130: * @return Value of the 'size' property.
131: */
132: public long getSize() {
133: return size;
134: }
135:
136: /**
137: * Setter for the 'size' property.
138: *
139: * @param size New value for the 'size' property.
140: */
141: public void setSize(final long size) {
142: this .size = size;
143: }
144:
145: /**
146: * Getter of the 'md5' property.
147: *
148: * @return Value of the 'md5' property.
149: */
150: public String getMd5() {
151: return md5;
152: }
153:
154: /**
155: * Setter for the 'md5' property.
156: *
157: * @param md5 New value for the 'md5' property.
158: */
159: public void setMd5(final String md5) {
160: this .md5 = md5;
161: }
162:
163: /**
164: * Getter of the 'directory' property.
165: *
166: * @return Value of the 'directory' property.
167: */
168: public boolean isDirectory() {
169: return directory;
170: }
171:
172: /**
173: * Setter for the 'directory' property.
174: *
175: * @param directory New value for the 'directory' property.
176: */
177: public void setDirectory(final boolean directory) {
178: this .directory = directory;
179: }
180:
181: /**
182: * Getter of the 'empty' property.
183: *
184: * @return Value of the 'empty' property.
185: */
186: public boolean isEmpty() {
187: return empty;
188: }
189:
190: /**
191: * Setter for the 'empty' property.
192: *
193: * @param empty New value for the 'empty' property.
194: */
195: public void setEmpty(final boolean empty) {
196: this .empty = empty;
197: }
198:
199: /**
200: * Getter of the 'jarFile' property.
201: *
202: * @return Value of the 'jarFile' property.
203: */
204: public boolean isJarFile() {
205: return jarFile;
206: }
207:
208: /**
209: * Setter for the 'jarFile' property.
210: *
211: * @param jarFile New value for the 'jarFile' property.
212: */
213: public void setJarFile(final boolean jarFile) {
214: this .jarFile = jarFile;
215: }
216:
217: /**
218: * Getter of the 'packedJarFile' property.
219: *
220: * @return Value of the 'packedJarFile' property.
221: */
222: public boolean isPackedJarFile() {
223: return packedJarFile;
224: }
225:
226: /**
227: * Setter for the 'packedJarFile' property.
228: *
229: * @param packedJarFile New value for the 'packedJarFile' property.
230: */
231: public void setPackedJarFile(final boolean packedJarFile) {
232: this .packedJarFile = packedJarFile;
233: }
234:
235: /**
236: * Getter of the 'signedJarFile' property.
237: *
238: * @return Value of the 'signedJarFile' property.
239: */
240: public boolean isSignedJarFile() {
241: return signedJarFile;
242: }
243:
244: /**
245: * Setter for the 'signedJarFile' property.
246: *
247: * @param signedJarFile New value for the 'signedJarFile' property.
248: */
249: public void setSignedJarFile(final boolean signedJarFile) {
250: this .signedJarFile = signedJarFile;
251: }
252:
253: /**
254: * Getter of the 'lastModified' property.
255: *
256: * @return Value of the 'lastModified' property.
257: */
258: public long getLastModified() {
259: return lastModified;
260: }
261:
262: /**
263: * Setter for the 'lastModified' property.
264: *
265: * @param lastModified New value for the 'lastModified' property.
266: */
267: public void setLastModified(final long lastModified) {
268: this .lastModified = lastModified;
269: }
270:
271: /**
272: * Getter of the 'permissions' property.
273: *
274: * @return Value of the 'permissions' property.
275: */
276: public int getPermissions() {
277: return permissions;
278: }
279:
280: /**
281: * Setter for the 'permissions' property.
282: *
283: * @param permissions New value for the 'permissions' property.
284: */
285: public void setPermissions(final int permissions) {
286: this .permissions = permissions;
287: }
288:
289: /**
290: * Getter of the 'name' property.
291: *
292: * @return Value of the 'name' property.
293: */
294: public String getName() {
295: return name;
296: }
297:
298: /**
299: * Setter for the 'name' property.
300: *
301: * @param name New value for the 'name' property.
302: */
303: public void setName(final String name) {
304: this.name = name;
305: }
306: }
|