示例#1
0
 def compile_Unit(self, class_name, file_name, target, version, compile_to):
     """
     Compiles a model (parsing, instantiating, flattening, code generation 
     and binary file generation) and creates an FMU on the file system. Set 
     target to specify which type of FMU should be created. The different 
     targets are "me" and "cs". 
     
     Note: target must currently be set to 'model_fmume'.
     
     Parameters::
     
         class_name --
             Name of model class in the model file to compile.
         
         file_name --
             Path to file or list of paths to files or libraries 
             in which the model is contained.
             
         target --
             The build target. Valid options are 'me' and 'cs'.
             
         version --
             The FMI version. Valid options are '1.0' and '2.0'.
             
         compile_to --
             Specify location of the compiled FMU. Directory will be created 
             if it does not exist.
     
     Returns::
     
         A list of warnings given by the compiler
     """
     self._compiler.retrieveAndClearWarnings()  # Remove old warnings
     unit = None
     try:
         unit = self._compiler.compileUnit(class_name, file_name, target,
                                           version, compile_to)
         self._compiler.closeLogger()
     except jpype.JavaException as ex:
         self._handle_exception(ex)
     from compiler import CompilerResult
     return CompilerResult(unit, self.get_warnings())
    def end(self):
        """ 
        End the current logging session. It is important that the log stream
        has been closed before calling this method. Otherwise this method will
        block indefinitely. The reason for this is that this method will wait
        for the the log parser thread to finish. It only does so when the log
        stream is closed.
        
        This method will proccess the errors and warnings that are given in the
        log stream. An appropriate Python error is raised if an exception was
        given by the compiler process.
        """
        if (self.loggerThread is None):
            print "Invalid call order!"
        self.loggerThread.join()
        problems = self.loggerThread.result.problems
        name = self.loggerThread.result.name
        self.loggerThread = None

        exceptions = []
        errors = []
        warnings = []

        for problem in problems:
            if isinstance(problem, CompilationException):
                exceptions.append(problem)
            elif isinstance(problem, CompilationError):
                errors.append(problem)
            elif isinstance(problem, CompilationWarning):
                warnings.append(problem)
        if not exceptions:
            if not errors:
                from compiler import CompilerResult
                return CompilerResult(name, warnings)
            else:
                raise CompilerError(errors, warnings)

        exception = exceptions[0]

        if exception.kind == 'org.jmodelica.util.exceptions.ModelicaClassNotFoundException':
            raise ModelicaClassNotFoundError(exception.message)

        if exception.kind == 'java.io.FileNotFoundException':
            raise IOError(exception.message)

        if exception.kind == 'org.jmodelica.util.logging.IllegalLogStringException':
            raise IllegalLogStringError(exception.message)

        if exception.kind == 'org.jmodelica.common.options.AbstractOptionRegistry$UnknownOptionException':
            raise UnknownOptionError(exception.message)

        if exception.kind == 'org.jmodelica.common.options.AbstractOptionRegistry$InvalidOptionValueException':
            raise InvalidOptionValueError(exception.message)

        if exception.kind == 'org.jmodelica.util.exceptions.CcodeCompilationException':
            raise CcodeCompilationError(exception.message)

        if exception.kind == 'org.jmodelica.util.exceptions.PackingFailedException':
            raise PackingFailedError(exception.message)

        if exception.kind == 'xml.sax.SAXParseException':
            raise IOError(exception.message)

        if exception.kind == 'org.jmodelica.util.exceptions.IllegalCompilerArgumentException':
            raise IllegalCompilerArgumentError(exception.message)

        raise JError("%s\n%s" % (exception.message, exception.stacktrace))