4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Copyright (c) 2009 Sun Microsystems, Inc. All Rights Reserved.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * The contents of this file are subject to the terms
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * of the Common Development and Distribution License
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * (the License). You may not use this file except in
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * compliance with the License.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * You can obtain a copy of the License at
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * See the License for the specific language governing
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * permission and limitations under the License.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * When distributing Covered Code, include this CDDL
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Header Notice in each file and include the License file
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * If applicable, add the following below the CDDL Header,
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * with the fields enclosed by brackets [] replaced by
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * your own identifying information:
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * "Portions Copyrighted [year] [name of copyright owner]"
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * $Id: WarCreator.java,v 1.2 2009/08/18 16:08:55 kevinserwin Exp $
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * Portions Copyrighted [2011] [ForgeRock AS]
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * This class creates the specialized WAR such as distributed authentication and
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster * console WAR files.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster private static final Set<String> supportedTypes = new HashSet<String>();
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // if locale is null, default locale will be used.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String locale = getOption(args, "-l", "--locale");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster rb = ResourceBundle.getBundle("deployablewar", getLocale(locale));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // print usage and quit.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (args.length == 0 || hasOption(args, "-?", "--help")) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // validation.
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String staging = getOption(args, "-s", "--staging");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster String warfile = getOption(args, "-w", "--warfile");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if ((staging == null) || (type == null) || (warfile == null)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster File webinfDir = new File(staging + File.separator + "WEB-INF");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (!stagingDir.exists() || !stagingDir.canRead() || !webinfDir.exists()) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster System.err.println(rb.getString("invalid.staging.dir"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster System.err.println(rb.getString("missing.typedir"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster System.err.println(rb.getString("unsupported.type"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // options are all valid, create the WAR now
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (arg.equals(shortName) || arg.equals(longName)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster return true;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster return false;
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster if (args[i].equals(shortName) || args[i].equals(longName)) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster return (args[i + 1].startsWith("-")) ? null : args[i + 1];
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster private static void create(String staging, String type, String warfile) {
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster JarOutputStream out = new JarOutputStream(new FileOutputStream(
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // get the contents from mother opensso.war
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster List<String> fileList = getFileList("fam-" + type + ".list");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster FileInputStream in = new FileInputStream(staging + "/" + f);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster System.err.println(MessageFormat.format(rb.getString("missing.file"), test));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster // get the contents for individual specialized WAR
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster f = f.replaceAll("\\" + System.getProperty("file.separator"), "/");
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster FileInputStream in = new FileInputStream(type + "/" + f);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster System.out.println(rb.getString("warfile.created"));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster private static List<String> getTargetedList(String type, String base)
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster list.addAll(getTargetedList(type + "/" + f.getName(), base));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster list.add(f.getPath().substring(base.length() + 1));
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster private static List<String> getFileList(String listName)
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster BufferedReader brdr = new BufferedReader(frdr);
4a2f0f0be43dfd4c1b490cbf3cc48b6ba6084b1cAllan Foster private static Locale getLocale(String stringformat) {