8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster* $Id: Manifest.java,v 1.3 2009/02/17 18:41:41 kevinserwin Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster*/
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.tools.manifest;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.BufferedReader;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.BufferedOutputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.File;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.FileOutputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.IOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.PrintStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.FileReader;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Enumeration;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.LinkedList;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Properties;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Date;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.text.SimpleDateFormat;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class Manifest implements ManifestConstants{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String manifestName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public File srcFile;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public File destFile;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean verbose;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FilesDigester digester;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Properties digestResult;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static char wildCard;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static LinkedList includePattern = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static LinkedList excludePattern = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String headerFilePath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String srcFilePath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String destFilePath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean recursive;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String includePatternString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String excludePatternString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String wildCardString;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String digestAlg;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean intoJar;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean intoWar;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static boolean overwrite;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setDefaultProperties() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster verbose = Boolean.valueOf(DEFAULT_VERBOSE).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster recursive = Boolean.valueOf(DEFAULT_RECURSIVE).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestAlg = SHA1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster intoJar = Boolean.valueOf(DEFAULT_DIGEST_HANDLEJAR).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster intoWar = Boolean.valueOf(DEFAULT_DIGEST_HANDLEWAR).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manifestName = DEFAULT_MANIFEST_FILE_NAME;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster overwrite = Boolean.valueOf(DEFAULT_OVERWRITE).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster wildCard = DEFAULT_WILD_CARD;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void getProperties() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster headerFilePath = System.getProperty(HEADER_FILE_PATH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster srcFilePath = System.getProperty(SRC_FILE_PATH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster destFilePath = System.getProperty(DEST_FILE_PATH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster verbose = Boolean.valueOf(System.getProperty(VERBOSE_OPTION,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_VERBOSE)).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster recursive=Boolean.valueOf(System.getProperty(RECURSIVE,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_RECURSIVE)).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster includePatternString = System.getProperty(INCLUDE_PATTERN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster excludePatternString = System.getProperty(EXCLUDE_PATTERN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster manifestName = System.getProperty(MANIFEST_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_MANIFEST_FILE_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster wildCardString = System.getProperty(WILDCARD_CHAR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestAlg=System.getProperty(DIGEST_ALG, SHA1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster intoJar = Boolean.valueOf(System.getProperty(DIGEST_HANDLEJAR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_DIGEST_HANDLEJAR)).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster intoWar = Boolean.valueOf(System.getProperty(DIGEST_HANDLEWAR,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_DIGEST_HANDLEWAR)).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster overwrite = Boolean.valueOf(System.getProperty(OVERWRITE,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_OVERWRITE)).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((includePatternString != null) &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (includePatternString.length() > 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster includePattern = new LinkedList();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int offset = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = includePatternString.indexOf(PATTERN_SEPARATOR, offset);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster do{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (index > offset) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster includePattern.add(includePatternString.substring(offset,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index).trim());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (offset < includePatternString.length()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tempPattern = includePatternString.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster offset, includePatternString.length()).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tempPattern.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster includePattern.add(tempPattern);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster offset = index + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index = includePatternString.indexOf(PATTERN_SEPARATOR, offset);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } while (true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((excludePatternString!=null) &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (excludePatternString.length() > 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster excludePattern = new LinkedList();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int offset = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = excludePatternString.indexOf(PATTERN_SEPARATOR, offset);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster do{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (index > offset) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster excludePattern.add(excludePatternString.substring(offset,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index).trim());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (offset < excludePatternString.length()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tempPattern = excludePatternString.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster offset, excludePatternString.length()).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tempPattern.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster excludePattern.add(tempPattern);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster offset = index + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster index = excludePatternString.indexOf(PATTERN_SEPARATOR, offset);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } while (true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster wildCard = DEFAULT_WILD_CARD;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (wildCardString != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster wildCard = wildCardString.trim().charAt(0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private boolean setSourceFile(String srcFilePath) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (srcFilePath == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Source file not specified!");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.srcFilePath = srcFilePath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster srcFile = new File(srcFilePath);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (! srcFile.isFile()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Source file not found!");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setProperties(Properties prop) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestResult = new Properties(prop);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getProperty(String propertyName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return digestResult.getProperty(propertyName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Enumeration getPropertyNames() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return digestResult.propertyNames();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void removeProperty(String propertyName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestResult.remove(propertyName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void writeDestFile() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster destFile = new File(destFilePath);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BufferedOutputStream fout = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (destFile.isDirectory()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout = new BufferedOutputStream(new FileOutputStream(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new File(destFile, manifestName)));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (destFile.isFile() && (!overwrite)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout = new BufferedOutputStream(new FileOutputStream(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster destFile, true));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File parentFile = destFile.getParentFile();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((parentFile != null) && (!parentFile.exists())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster parentFile.mkdirs();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout = new BufferedOutputStream(new FileOutputStream(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster destFile));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (headerFilePath != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster File headerFile = new File(headerFilePath);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((headerFile.exists()) && (headerFile.isFile())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BufferedReader fr = new BufferedReader(new
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster FileReader(headerFile));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String line;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while ((line = fr.readLine()) != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.write(line.getBytes());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.write("\n".getBytes());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fr.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long currentTimeInMillis = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create Date object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Date date = new Date(currentTimeInMillis);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //Specify the desired date format
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String DATE_FORMAT = "yyyyMMddhhmm";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //Create object of SimpleDateFormat and pass the desired date format.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.write("identifier=(".getBytes());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.write(sdf.format(date).getBytes());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.write(")\n".getBytes());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestResult.store(fout, "");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (IOException ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ex.printStackTrace();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } finally {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (fout != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout.close();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (IOException ignored) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster fout = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void createManifest() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digester = new FilesDigester(includePattern,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster excludePattern, wildCard, recursive);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestResult = new Properties();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digester.digest(digestAlg, srcFile, digestResult, srcFilePath, intoJar,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster intoWar);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean createManifest(String srcFilePath, String destFilePath,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String headerFilePath, boolean intoJar, boolean intoWar) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.intoJar = intoJar;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.intoWar = intoWar;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (setSourceFile(srcFilePath) == false) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (verbose) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (destFilePath != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.print("Creating Manifest file "+ destFilePath);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.print("Displaying Manifest file ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println(" for "+srcFilePath+"\n");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster createManifest();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (destFilePath != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.destFilePath = destFilePath;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster writeDestFile();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long currentTimeInMillis = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create Date object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Date date = new Date(currentTimeInMillis);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //Specify the desired date format
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String DATE_FORMAT = "yyyyMMddhhmm";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //Create object of SimpleDateFormat and pass the desired date format.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster digestResult.setProperty("identifier","generated-"+sdf.format(date));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return true;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void main(String[] args) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Manifest m = new Manifest();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.getProperties();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.createManifest(srcFilePath, destFilePath, headerFilePath,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster true, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Prints the usage for using the patch generation utility
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void printUsage(PrintStream out){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Usage: java ARGUMENTS -jar Manifest.jar");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\nARGUMENTS");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\t-D\"" + MANIFEST_CREATE_FILE + "=<RTM zip file>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tPath of RTM zip file [Required].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + LATEST_WAR_FILE +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<latest zip file>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tPath of the resulting patch file [Optional].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + IDENTIFIER_ENTRY +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<name of the entry which indicate version>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tName of the entry in manifest indicate identity " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "[Default: " + DEFAULT_IDENTIFIER_ENTRY + "].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + MANIFEST_PATTERN +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<pattern of manifest file>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tPattern of the manifest file in the war file " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "[Default: " + DEFAULT_MANIFEST_PATTERN + "].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + MANIFEST_FILE_NAME +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<name of the manifest file in the resulting file>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tName of the manifest file " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "[Required if " + VERSION_FILE + " is not defined].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + WILDCARD_CHAR +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<char to be used as wildcard>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tWild card character [Default: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DEFAULT_WILDCARD_CHAR + "].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + VERSION_FILE +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<properties file indicate version>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tProperties file indicate the version of patch " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "[Optional].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\n\t-D\"" + PROPERTIES_FILE +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "=<propeties file has the above directive defined>\"");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("\tProperties file have above directives defined " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "[Optional].");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}