1 /*
   2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.oracle.tools.packager;
  27 
  28 import java.io.File;
  29 import java.util.Collection;
  30 import java.util.Map;
  31 
  32 public interface Bundler {
  33 
  34 
  35     /**
  36      * @return User Friendly name of this bundler.
  37      */
  38     String getName();
  39 
  40     /**
  41      * @return A more verbose description of the bundler.
  42      */
  43     String getDescription();
  44 
  45     /**
  46      * @return Command line identifier of the bundler.  Should be unique.
  47      */
  48     String getID();
  49 
  50     /**
  51      * @return The bundle type of the bundle that is created by this bundler.
  52      */
  53     String getBundleType();
  54 
  55     /**
  56      * The parameters that this bundler uses to generate it's bundle.
  57      * @return immutable collection
  58      */
  59     Collection<BundlerParamInfo<?>> getBundleParameters();
  60 
  61     /**
  62      * Determines if this bundler will execute with the given parameters.
  63      *
  64      * @param params The parameters to be validate.  Validation may modify
  65      *               the map, so if you are going to be using the same map
  66      *               across multiple bundlers you should pass in a deep copy.
  67      * @return true if valid
  68      * @throws UnsupportedPlatformException If the bundler cannot run on this
  69      *         platform (i.e. creating mac apps on windows)
  70      * @throws ConfigException If the configuration params are incorrect.  The
  71      *         exception may contain advice on how to modify the params map
  72      *         to make it valid.
  73      */
  74     boolean validate(Map<String, ? super Object> params) throws UnsupportedPlatformException, ConfigException;
  75 
  76     /**
  77      * Creates a bundle from existing content.
  78      *
  79      * If a call to {@link #validate(java.util.Map)} date} returns true with the
  80      * parameters map, then you can expect a valid output.  However if an exception
  81      * was thrown out of validate or it returned false then you should not
  82      * expect sensible results from this call.  It may or may not return a value,
  83      * and it may or may not throw an exception.  But any output should not
  84      * be considered valid or sane.
  85      *
  86      * @param params The parameters as specified by getBundleParameters.
  87      *               Keyed by the id from the ParamInfo.  Execution may
  88      *               modify the map, so if you are going to be using the
  89      *               same map across multiple bundlers you should pass
  90      *               in a deep copy.
  91      * @param outputParentDir
  92      *   The parent dir that the returned bundle will be placed in.
  93      * @return The resulting bundled file
  94      *
  95      * For a bundler that produces a single artifact file this will be the
  96      * location of that artifact (.exe file, .deb file, etc)
  97      *
  98      * For a bundler that produces a specific directory format output this will
  99      * be the location of that specific directory (.app file, etc).
 100      *
 101      * For a bundler that produce multiple files, this will be a parent
 102      * directory of those files (linux and windows images), whose name is not
 103      * relevant to the result.
 104      *
 105      * @throws java.lang.IllegalArgumentException for any of the following
 106      * reasons:
 107      *  <ul>
 108      *      <li>A required parameter is not found in the params list, for
 109      *      example missing the main class.</li>
 110      *      <li>A parameter has the wrong type of an object, for example a
 111      *      String where a File is required</li>
 112      *      <li>Bundler specific incompatibilities with the parameters, for
 113      *      example a bad version number format or an application id with
 114      *      forward slashes.</li>
 115      *  </ul>
 116      */
 117     public File execute(Map<String, ? super Object> params, File outputParentDir);
 118 
 119      /**
 120      * Removes temporary files that are used for bundling.
 121      */
 122     public void cleanup(Map<String, ? super Object> params);
 123 
 124 }