Example #1
0
 public PowershellCompiler()
 {
     this.schema =
         CompilerExtension.LoadXmlSchemaHelper(
             Assembly.GetExecutingAssembly(),
             "PowershellExtension.PowershellSchema.xsd");
 }
 public GACompiler()
 {
     this.schema =
         CompilerExtension.LoadXmlSchemaHelper(
             Assembly.GetExecutingAssembly(),
             "WixGAExtension.ExtensionSchema.xsd");
 }
Example #3
0
        public CompilerManager(ICompiler compiler,
                               IStaticContentTransformer staticContTransf,
                               IDynamicContentTransformer dynContTransf,
                               CompilerExtension ext)
        {
            Instance = compiler;
            StaticContentTransformer  = staticContTransf;
            DynamicContentTransformer = dynContTransf;

            m_Ext = ext;
            m_Ext.RequestPreCompile       += OnRequestPreCompile;
            m_Ext.RequestRenderCodeBlock  += OnRequestRenderCodeBlock;
            m_Ext.RequestRenderImage      += OnRequestRenderImage;
            m_Ext.RequestRenderUrl        += OnRequestRenderUrl;
            m_Ext.RequestWritePageContent += OnRequestWritePageContent;
            m_Ext.RequestPostCompile      += OnRequestPostCompile;
            m_Ext.RequestPostCompileFile  += OnRequestPostCompileFile;
        }
Example #4
0
        /// <summary>
        /// Main running method for the application.
        /// </summary>
        /// <param name="args">Commandline arguments to the application.</param>
        /// <returns>Returns the application error code.</returns>
        private int Run(string[] args)
        {
            try
            {
                FileInfo currentFile = null;

                // parse the command line
                this.ParseCommandLine(args);

                // exit if there was an error parsing the command line (otherwise the logo appears after error messages)
                if (this.messageHandler.FoundError)
                {
                    return(this.messageHandler.PostProcess());
                }

                if (0 == this.sourceFiles.Count)
                {
                    this.showHelp = true;
                }
                else if (1 < this.sourceFiles.Count && null != this.outputFile)
                {
                    throw new ArgumentException("cannot specify more than one source file with single output file.  Either specify an output directory for the -out argument by ending the argument with a '\\' or remove the -out argument to have the source files compiled to the current directory.", "-out");
                }

                if (this.showLogo)
                {
                    Assembly candleAssembly = Assembly.GetExecutingAssembly();

                    Console.WriteLine("Microsoft (R) Windows Installer Xml Compiler version {0}", candleAssembly.GetName().Version.ToString());
                    Console.WriteLine("Copyright (C) Microsoft Corporation 2003. All rights reserved.");
                    Console.WriteLine();
                }
                if (this.showHelp)
                {
                    Console.WriteLine(" usage:  candle.exe [-?] [-nologo] [-out outputFile] sourceFile [sourceFile ...]");
                    Console.WriteLine();
                    Console.WriteLine("   -d<name>=<value>  define a parameter for the preprocessor");
                    Console.WriteLine("   -p<file>  preprocess to a file (or stdout if no file supplied)");
                    Console.WriteLine("   -I<dir>  add to include search path");
                    Console.WriteLine("   -nologo  skip printing candle logo information");
                    Console.WriteLine("   -out     specify output file (default: write to current directory)");
                    Console.WriteLine("   -pedantic:<level>  pedantic checks (levels: easy, heroic, legendary)");
                    Console.WriteLine("   -ss      suppress schema validation of documents (performance boost)");
                    Console.WriteLine("   -ust     use small table definitions (for backwards compatiblity)");
                    Console.WriteLine("   -trace   show source trace for errors, warnings, and verbose messages");
                    Console.WriteLine("   -ext     extension (class, assembly), should extend CompilerExtension");
                    Console.WriteLine("   -zs      only do validation of documents (no output)");
                    Console.WriteLine("   -wx      treat warnings as errors");
                    Console.WriteLine("   -w<N>    set the warning level (0: show all, 3: show none)");
                    Console.WriteLine("   -sw      suppress all warnings (same as -w3)");
                    Console.WriteLine("   -sw<N>   suppress warning with specific message ID");
                    Console.WriteLine("   -v       verbose output (same as -v2)");
                    Console.WriteLine("   -v<N>    sets the level of verbose output (0: most output, 3: none)");
                    Console.WriteLine("   -?       this help information");
                    Console.WriteLine();
                    Console.WriteLine("Common extensions:");
                    Console.WriteLine("   .wxs    - Windows installer Xml Source file");
                    Console.WriteLine("   .wxi    - Windows installer Xml Include file");
                    Console.WriteLine("   .wxl    - Windows installer Xml Localization file");
                    Console.WriteLine("   .wixobj - Windows installer Xml Object file (in XML format)");
                    Console.WriteLine("   .wixlib - Windows installer Xml Library file (in XML format)");
                    Console.WriteLine("   .wixout - Windows installer Xml Output file (in XML format)");
                    Console.WriteLine();
                    Console.WriteLine("   .msm - Windows installer Merge Module");
                    Console.WriteLine("   .msi - Windows installer Product Database");
                    Console.WriteLine("   .mst - Windows installer Transform");
                    Console.WriteLine("   .pcp - Windows installer Patch Creation Package");
                    Console.WriteLine();
                    Console.WriteLine("For more information see: http://wix.sourceforge.net");

                    return(this.messageHandler.PostProcess());
                }

                // create the preprocessor and compiler
                Preprocessor preprocessor = new Preprocessor();
                preprocessor.Message += new MessageEventHandler(this.messageHandler.Display);
                for (int i = 0; i < this.includeSearchPaths.Count; ++i)
                {
                    preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]);
                }

                Compiler compiler = new Compiler(this.useSmallTables);
                compiler.Message         += new MessageEventHandler(this.messageHandler.Display);
                compiler.PedanticLevel    = this.pedanticLevel;
                compiler.SuppressValidate = this.suppressSchema;

                // load any extensions
                foreach (string extension in this.extensionList)
                {
                    Type extensionType = Type.GetType(extension);
                    if (null == extensionType)
                    {
                        throw new WixInvalidExtensionException(extension);
                    }

                    if (extensionType.IsSubclassOf(typeof(PreprocessorExtension)))
                    {
                        preprocessor.AddExtension((PreprocessorExtension)Activator.CreateInstance(extensionType));
                    }

                    if (extensionType.IsSubclassOf(typeof(CompilerExtension)))
                    {
                        CompilerExtension compilerExtensionObject = Activator.CreateInstance(extensionType) as CompilerExtension;
                        compiler.AddExtension(compilerExtensionObject);
                    }

                    if (!extensionType.IsSubclassOf(typeof(PreprocessorExtension)) && !extensionType.IsSubclassOf(typeof(CompilerExtension)))
                    {
                        throw new WixInvalidExtensionException(extension);
                    }
                }

                // preprocess then compile each source file
                foreach (FileInfo sourceFile in this.sourceFiles)
                {
                    currentFile = sourceFile;                     // point at the file we're working on in case a exception is thrown

                    FileInfo targetFile;
                    if (null != this.outputFile)
                    {
                        targetFile = this.outputFile;
                    }
                    else if (null != this.outputDirectory)
                    {
                        targetFile = new FileInfo(String.Concat(this.outputDirectory.FullName, Path.ChangeExtension(currentFile.Name, ".wixobj")));
                    }
                    else
                    {
                        targetFile = new FileInfo(Path.ChangeExtension(currentFile.Name, ".wixobj"));
                    }

                    // print friendly message saying what file is being compiled
                    Console.WriteLine(currentFile.Name);

                    // need to clear and re-add the commandline defines for each file
                    preprocessor.ResetParameters();
                    foreach (string param in this.parameters.Keys)
                    {
                        string name = param;
                        if (!name.StartsWith("var."))
                        {
                            name = String.Concat("var.", name);
                        }
                        preprocessor.Parameters.Add(name, (string)this.parameters[param]);
                    }

                    // preprocess the source
                    XmlDocument sourceDocument;
                    try
                    {
                        if (this.preprocessToStdout)
                        {
                            preprocessor.PreprocessOut = Console.Out;
                        }
                        else if (null != this.preprocessFile)
                        {
                            preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile);
                        }

                        sourceDocument = preprocessor.Process(currentFile.FullName);
                    }
                    finally
                    {
                        if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut)
                        {
                            preprocessor.PreprocessOut.Close();
                        }
                    }

                    // if we're not actually going to compile anything, move on to the next file
                    if (this.schemaOnly || null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile)
                    {
                        continue;
                    }

                    // and now we do what we came here to do...
                    Intermediate intermediate = compiler.Compile(sourceDocument, currentFile.FullName);

                    // save the intermediate to disk if no errors were found for this source file
                    if (null != intermediate)
                    {
                        intermediate.Save(targetFile.FullName);
                    }

                    // this file is was successful so clear the reference in case an exception gets thrown
                    currentFile = null;
                }
            }
            catch (WixException we)
            {
                // TODO: once all WixExceptions are converted to errors, this clause
                // should be a no-op that just catches WixFatalErrorException's
                this.messageHandler.Display("candle.exe", "CNDL", we);
                return(1);
            }
            catch (Exception e)
            {
                this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace));
                if (e is NullReferenceException || e is SEHException)
                {
                    throw;
                }
            }

            return(this.messageHandler.PostProcess());
        }