1. /*
  2. * Copyright 2000-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs.optional.dotnet;
  18. import org.apache.tools.ant.BuildException;
  19. /**
  20. * Compile J# source down to a managed .NET application.
  21. * <p>
  22. * J# is not Java. But it is the language closest to Java in the .NET framework.
  23. * This task compiles jsharp source (.java files), and
  24. * generates a .NET managed exe or dll.
  25. * <p>
  26. *
  27. * @see <A=ref="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vjsharp/html/vjoriMicrosoftVisualJ.asp">
  28. * Visual J++ online documentation</a>
  29. *
  30. * @since ant1.6
  31. * @ant.task category="dotnet" name="jsharpc"
  32. */
  33. public class JSharp extends DotnetCompile {
  34. /**
  35. * hex base address
  36. */
  37. String baseAddress;
  38. /** /x option to disable J++ and J# lang extensions
  39. *
  40. */
  41. boolean pureJava = true;
  42. /**
  43. * whether to make package scoped stuff public or assembly scoped
  44. */
  45. boolean secureScoping = false;
  46. public JSharp() {
  47. setExecutable("vjc");
  48. }
  49. public void setBaseAddress(String baseAddress) {
  50. this.baseAddress = baseAddress;
  51. }
  52. /**
  53. * do we want pure java (default, true) or corrupted J#?
  54. * @param pureJava
  55. */
  56. public void setPureJava(boolean pureJava) {
  57. this.pureJava = pureJava;
  58. }
  59. /**
  60. * Make package scoped code visible to the current assembly only (default: false)
  61. * .NET does not have package scoping. Instead it has assembly, private and public.
  62. * By default, package content is public to all.
  63. * @param secureScoping
  64. */
  65. public void setSecureScoping(boolean secureScoping) {
  66. this.secureScoping = secureScoping;
  67. }
  68. /**
  69. * Get the delimiter that the compiler uses between references.
  70. * For example, c# will return ";"; VB.NET will return ","
  71. * @return The string delimiter for the reference string.
  72. */
  73. public String getReferenceDelimiter() {
  74. return ";";
  75. }
  76. /**
  77. * Get the extension of filenames to compile.
  78. * @return The string extension of files to compile.
  79. */
  80. public String getFileExtension() {
  81. return ".java";
  82. }
  83. /**
  84. * add jvc specific commands
  85. * @param command
  86. */
  87. protected void addCompilerSpecificOptions(NetCommand command) {
  88. if (pureJava) {
  89. command.addArgument("/x:all");
  90. }
  91. if (secureScoping) {
  92. command.addArgument("/securescoping");
  93. }
  94. }
  95. /**
  96. * from a resource, get the resource param
  97. * @param resource
  98. * @return a string containing the resource param, or a null string
  99. * to conditionally exclude a resource.
  100. */
  101. protected String createResourceParameter(DotnetResource resource) {
  102. return resource.getCSharpStyleParameter();
  103. }
  104. /**
  105. * validation code
  106. * @throws org.apache.tools.ant.BuildException if validation failed
  107. */
  108. protected void validate()
  109. throws BuildException {
  110. super.validate();
  111. if (getDestFile() == null) {
  112. throw new BuildException("DestFile was not specified");
  113. }
  114. }
  115. }