terp - the ANT Tasks
v1.3.304

com.codemesh.terp.ant.compiler.cpp
Class GenerateVsProject

java.lang.Object
  extended by org.apache.tools.ant.ProjectComponent
      extended by org.apache.tools.ant.Task
          extended by org.apache.tools.ant.taskdefs.Echo
              extended by com.codemesh.terp.ant.TerpEcho
                  extended by com.codemesh.terp.ant.compiler.cpp.GenerateVsProject
All Implemented Interfaces:
CompilerOption<CppCompiler>, CppFileCreating, FileCreating<CppCompiler>, TerpAware, TerpContextHolder, java.lang.Cloneable

public class GenerateVsProject
extends TerpEcho
implements CppFileCreating

An option that causes a VisualStudio project file to be generated. You can add this option to a compiler invocation to generate a VisualStudio project file that mirrors the compiler settings.

This options is really one of the FileCreating tasks (also see ResourceOption) that can be nested in the compiler task. Rather than adding compiler switches to the commandline, they generate one or more files that may play a role during or after the compilation. In this case, the generated file is mostly useful for people who might wish to debug the built project in Microsoft VisualStudio. Having a project that can be double-clicked makes live a lot easier.

This options extends TerpEcho to take advantage of its template expanding capabilities. If no file or template attributes are specified, this task will calculate both the template and the output filenames.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.tools.ant.taskdefs.Echo
org.apache.tools.ant.taskdefs.Echo.EchoLevel
 
Nested classes/interfaces inherited from interface com.codemesh.terp.ant.TerpAware
TerpAware.Delegate
 
Field Summary
 
Fields inherited from class org.apache.tools.ant.taskdefs.Echo
append, file, logLevel, message
 
Fields inherited from class org.apache.tools.ant.Task
target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
description, location, project
 
Constructor Summary
GenerateVsProject()
           
 
Method Summary
 void addCommands(java.util.List<java.lang.String> commandList, CppCompiler compiler, CompilerPhase phase)
          Adds the compiler switches repreesnted by this option to the list of switches.
 boolean appliesTo(CppCompiler compiler, CompilerPhase phase)
          Returns true if this compiler option applies to the given compiler and compiler phase.
protected  java.io.File calculateProjectFile(CppCompiler compiler)
          Calculates the project file based on the settings.
 java.util.List<java.lang.String> creates(CppCompiler compiler, CompilerPhase phase)
          Returns a list of filenames representing the files that are created due to the presence of this compiler option.
 void execute()
           Emits the project file.
 java.lang.String getCharset()
          Returns the configured charset (unicode, mbcs).
static int getConfigurationCharset(java.lang.String charset)
          Returns the integer representing Unicode or MBCS strings.
static int getConfigurationType(TargetType targetType)
          Returns the VisualStudio enumeration values for the given target type.
static java.util.List<java.lang.String> getIncludePath(java.lang.String commandLine)
           
static java.lang.Integer getOptimization(java.lang.String commandLine)
          Returns the optimization level as used by VisualStudio project files.
static java.lang.Boolean getPortabilityWarnings(java.lang.String commandLine)
           
static java.lang.Integer getProcessorOptimization(java.lang.String commandLine)
          Returns the processor optimization as used by VisualStudio project files.
static java.lang.String getProjectFileExtension(Version vers)
          Returns the project file extension that's appropriate for the compiler version.
static java.lang.Integer getRuntimeLibraryNumeric(java.lang.String commandLine)
          Returns the value of the runtime library switch.
static java.lang.String getRuntimeLibraryOption(java.lang.String commandLine)
          Returns the value of the runtime library switch.
 Version getVersion()
          Returns the configured compiler version.
static java.lang.Integer getWarningLevel(java.lang.String commandLine)
          Returns the warning level as used by VisualStudio project files.
 boolean satisfies(TerpContext ctx)
          Returns true if both conditions are met within the given terp context.
 void setCharset(java.lang.String charset)
          Sets the charset used in this project (unicode, mbcs).
 void setVersion(java.lang.String version)
          Sets the MSVC++ version number for which we're generating a VisualStudio project file.
 
Methods inherited from class com.codemesh.terp.ant.TerpEcho
getContext, getFile, getIf, getTemplate, getUnless, satisfiesConditions, setContext, setIf, setProject, setTemplate, setUnless
 
Methods inherited from class org.apache.tools.ant.taskdefs.Echo
addText, setAppend, setEncoding, setFile, setLevel, setMessage, setOutput
 
Methods inherited from class org.apache.tools.ant.Task
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
clone, getDescription, getLocation, getProject, setDescription, setLocation
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.codemesh.terp.ant.compiler.CompilerOption
getIf, getUnless, setIf, setUnless
 

Constructor Detail

GenerateVsProject

public GenerateVsProject()
Method Detail

setCharset

public void setCharset(java.lang.String charset)
Sets the charset used in this project (unicode, mbcs).

Parameters:
charset - the charset used.

getCharset

public java.lang.String getCharset()
Returns the configured charset (unicode, mbcs).

Returns:
the charset.

setVersion

public void setVersion(java.lang.String version)
Sets the MSVC++ version number for which we're generating a VisualStudio project file.

Parameters:
version - the compiler version.

getVersion

public Version getVersion()
Returns the configured compiler version.

Returns:
the compiler version.

addCommands

public void addCommands(java.util.List<java.lang.String> commandList,
                        CppCompiler compiler,
                        CompilerPhase phase)
Adds the compiler switches repreesnted by this option to the list of switches. Some compiler options may result in more than one switch being added to a compiler invocation. Other compiler options may result in different options being added in different phases (compilation vs. linking) of the build.

This method is called by the compiler repeatedly with different values for the compiler phase to account for these possibilities. Does not do anything because the file generation is outside the scope of the invoked compiler.

Specified by:
addCommands in interface CompilerOption<CppCompiler>
Parameters:
commandList - the list to which the compiler switches represented by this option (if any) are added.
compiler - the compiler for which we're doing this.
phase - the compiler phase in wihch we're doing this.

satisfies

public boolean satisfies(TerpContext ctx)
Returns true if both conditions are met within the given terp context.

Specified by:
satisfies in interface CompilerOption<CppCompiler>
Parameters:
ctx - the terp context in which the logical expressions are evaluated.
Returns:
true or false.

appliesTo

public boolean appliesTo(CppCompiler compiler,
                         CompilerPhase phase)
Returns true if this compiler option applies to the given compiler and compiler phase. Not every option has switches to contribute for every compiler and every compilation phase. This method allows a quick, inexpensive check to filter out potentially more expensive calls later on. We limit this option to MSVC and INTEL compilers on Windows. The project file generation takes place in the postlink phase, i.e. after everything else has been done.

Specified by:
appliesTo in interface CompilerOption<CppCompiler>
Parameters:
compiler - the compiler for which we're asking.
phase - the compiler phase we're executing.
Returns:

creates

public java.util.List<java.lang.String> creates(CppCompiler compiler,
                                                CompilerPhase phase)
Returns a list of filenames representing the files that are created due to the presence of this compiler option.

Specified by:
creates in interface FileCreating<CppCompiler>
Parameters:
compiler - the compiler.
phase - the compilation phase.
Returns:
a list of files, possibly empty.

getConfigurationType

public static int getConfigurationType(TargetType targetType)
Returns the VisualStudio enumeration values for the given target type.

Parameters:
targetType - the target type.
Returns:
an integer that can be used in a VisualStudio project file.

getConfigurationCharset

public static int getConfigurationCharset(java.lang.String charset)
Returns the integer representing Unicode or MBCS strings.

Parameters:
charset - a name, either "unicode" or "mbcs" or null.
Returns:
an integer.

getProjectFileExtension

public static java.lang.String getProjectFileExtension(Version vers)
Returns the project file extension that's appropriate for the compiler version.

Parameters:
vers - the compiler version.
Returns:
a project file extension.

getOptimization

public static java.lang.Integer getOptimization(java.lang.String commandLine)
Returns the optimization level as used by VisualStudio project files.

Parameters:
commandLine - the commandline that's used for compilation.
Returns:
an optimization level.

getWarningLevel

public static java.lang.Integer getWarningLevel(java.lang.String commandLine)
Returns the warning level as used by VisualStudio project files.

Parameters:
commandLine - the commandline that's used for compilation.
Returns:
an warning level.

getIncludePath

public static java.util.List<java.lang.String> getIncludePath(java.lang.String commandLine)

getRuntimeLibraryNumeric

public static java.lang.Integer getRuntimeLibraryNumeric(java.lang.String commandLine)
Returns the value of the runtime library switch.


getRuntimeLibraryOption

public static java.lang.String getRuntimeLibraryOption(java.lang.String commandLine)
Returns the value of the runtime library switch.


getPortabilityWarnings

public static java.lang.Boolean getPortabilityWarnings(java.lang.String commandLine)

getProcessorOptimization

public static java.lang.Integer getProcessorOptimization(java.lang.String commandLine)
Returns the processor optimization as used by VisualStudio project files.

Parameters:
commandLine - the commandline that's used for compilation.
Returns:
an warning level.

calculateProjectFile

protected java.io.File calculateProjectFile(CppCompiler compiler)
Calculates the project file based on the settings.

Parameters:
compiler - the compiler task.
Returns:
the project file that's going to be generated.

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Emits the project file.

Overrides:
execute in class TerpEcho
Throws:
org.apache.tools.ant.BuildException

terp - the ANT Tasks
v1.3.304

Copyright © 2008-2012 by Codemesh, Inc. All Rights Reserved.