Class PythonCompileMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
de.iip_ecosphere.platform.tools.maven.python.AbstractLoggingMojo
de.iip_ecosphere.platform.tools.maven.python.PythonCompileMojo
All Implemented Interfaces:
Logger, org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="compile-python", defaultPhase=COMPILE) public class PythonCompileMojo extends AbstractLoggingMojo
Python compiler Mojo plugin.
Author:
Alexander Weber, SSE, Holger Eichelberger, SSE
  • Field Details

    • MD5_FILE

      public static final String MD5_FILE
      See Also:
    • project

      @Parameter(defaultValue="${project}", required=true, readonly=true) private org.apache.maven.project.MavenProject project
    • failOnError

      @Parameter(property="python-compile.failOnError", defaultValue="true") private boolean failOnError
    • skip

      @Parameter(property="python-compile.skip", required=false, defaultValue="false") private boolean skip
    • useHash

      @Parameter(property="python-compile.useHash", required=false, defaultValue="true") private boolean useHash
    • hashDir

      @Parameter(property="python-compile.hashDir", required=false, defaultValue="") private String hashDir
    • ignoreText

      @Parameter(property="python-compile.ignoreText", required=false, defaultValue="imported but unused;is assigned to but never used;redefinition of unused;is unused:;SyntaxWarning: invalid escape sequence") private String ignoreText
    • python

      @Parameter(property="python.binary", required=false, defaultValue="") private String python
    • pythonArgs

      @Parameter(property="python.pythonArgs", required=false, defaultValue="") private String pythonArgs
  • Constructor Details

    • PythonCompileMojo

      public PythonCompileMojo()
  • Method Details

    • maxCmdLength

      private int maxCmdLength(String pythonExecutable, String separator)
      Estimates the maximum command line length.
      Parameters:
      pythonExecutable - the python executable to use
      separator - the separator between arguments
      Returns:
      the maximum command line length
    • info

      private void info(List<String> flist)
      Outputs flist.
      Parameters:
      flist - the files list to be emitted
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoExecutionException
      org.apache.maven.plugin.MojoFailureException
    • join

      private static String[] join(String[] array, List<String> list)
      Joins an array and a list to an array.
      Parameters:
      array - the array, may be null
      list - the list (may be null
      Returns:
      the joined array
    • isError

      private boolean isError(String line)
      Returns whether the given line seems to indicate an error, not a warning.
      Parameters:
      line - the output line
      Returns:
      true for error, false for not error/potential warning
    • isContained

      private static boolean isContained(String text, String[] substrings)
      Returns whether at least one of the substrings are contained in text.
      Parameters:
      text - the text to search for
      substrings - the substrings
      Returns:
      true if at least one of substrings is contained in text
    • runPythonTest

      public static String runPythonTest(String[] cmd)
      Running the syntax check for the python Files.
      Parameters:
      cmd - the command to run, either utilising pyflaks or py_compile
      Returns:
      The output to add to the other outputs
    • readProcessOutput

      static String readProcessOutput(InputStream stream) throws IOException
      Shall take in input stream of processes to collect console output.
      Parameters:
      stream - Process to be observed.
      Returns:
      The read Lines from the process.
      Throws:
      IOException - If the reading of the lines does fail.
    • getAllPythonFiles

      static List<File> getAllPythonFiles(String directory, boolean recurse)
      Give a list of files in a directory.
      Parameters:
      directory - the path to the directory as String.
      recurse - if all nested directories shall be considered or if only the files in the top-level directory shall be returned
      Returns:
      list of files in directory
    • getHashFile

      public File getHashFile()
      Returns the file containing the MD5 hashes of known Python files.
      Returns:
      the hash