View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.shared.scriptinterpreter;
20  
21  import java.io.Closeable;
22  import java.io.PrintStream;
23  import java.util.List;
24  import java.util.Map;
25  
26  /**
27   * Defines a simple abstraction used to plug-in several script interpreters for the pre-/post-build-hooks. Each
28   * interpreter implementation should be stateless and support reuse.
29   *
30   * @author Benjamin Bentmann
31   */
32  public interface ScriptInterpreter extends Closeable {
33  
34      /**
35       * Set class path used by interpreted.
36       *
37       * @param classPath The additional class path for the script interpreter, may be <code>null</code> or empty if only
38       *                  the plugin realm should be used for the script evaluation. If specified, this class path will
39       *                  precede
40       *                  the artifacts from the plugin class path.
41       */
42      void setClassPath(List<String> classPath);
43  
44      /**
45       * Evaluates the specified script.
46       *
47       * @param script          The script contents to evaluate, must not be <code>null</code>.
48       * @param globalVariables The global variables (as a mapping from variable name to value) to define for the script,
49       *                        may be <code>null</code> if not used.
50       * @param scriptOutput    A print stream to redirect any output from the script to, may be <code>null</code> to use
51       *                        stdout/stderr.
52       * @return The return value from the script, can be <code>null</code>
53       * @throws ScriptEvaluationException If the script evaluation produced an error.
54       */
55      Object evaluateScript(String script, Map<String, ?> globalVariables, PrintStream scriptOutput)
56              throws ScriptEvaluationException;
57  }