1. /*
  2. * Copyright 2001-2002,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.ide;
  18. import com.ibm.ivj.util.base.Project;
  19. import com.ibm.ivj.util.base.ToolData;
  20. import org.apache.tools.ant.BuildException;
  21. /**
  22. * This class is the equivalent to org.apache.tools.ant.Main for the
  23. * VAJ tool environment. It's main is called when the user selects
  24. * Tools->Ant Build from the VAJ project menu.
  25. * Additionally this class provides methods to save build info for
  26. * a project in the repository and load it from the repository
  27. *
  28. */
  29. public class VAJAntTool {
  30. private static final String TOOL_DATA_KEY = "AntTool";
  31. /**
  32. * Loads the BuildInfo for the specified VAJ project from the
  33. * tool data for this project.
  34. * If there is no build info stored for that project, a new
  35. * default BuildInfo is returned
  36. *
  37. * @return BuildInfo buildInfo build info for the specified project
  38. * @param projectName String project name
  39. */
  40. public static VAJBuildInfo loadBuildData(String projectName) {
  41. VAJBuildInfo result = null;
  42. try {
  43. Project project =
  44. VAJLocalUtil.getWorkspace().loadedProjectNamed(projectName);
  45. if (project.testToolRepositoryData(TOOL_DATA_KEY)) {
  46. ToolData td = project.getToolRepositoryData(TOOL_DATA_KEY);
  47. String data = (String) td.getData();
  48. result = VAJBuildInfo.parse(data);
  49. } else {
  50. result = new VAJBuildInfo();
  51. }
  52. result.setVAJProjectName(projectName);
  53. } catch (Throwable t) {
  54. throw new BuildException("BuildInfo for Project "
  55. + projectName + " could not be loaded" + t);
  56. }
  57. return result;
  58. }
  59. /**
  60. * Starts the application.
  61. *
  62. * @param args an array of command-line arguments. VAJ puts the
  63. * VAJ project name into args[1] when starting the
  64. * tool from the project context menu
  65. */
  66. public static void main(java.lang.String[] args) {
  67. try {
  68. VAJBuildInfo info;
  69. if (args.length >= 2 && args[1] instanceof String) {
  70. String projectName = (String) args[1];
  71. info = loadBuildData(projectName);
  72. } else {
  73. info = new VAJBuildInfo();
  74. }
  75. VAJAntToolGUI mainFrame = new VAJAntToolGUI(info);
  76. mainFrame.show();
  77. } catch (Throwable t) {
  78. // if all error handling fails, output at least
  79. // something on the console
  80. t.printStackTrace();
  81. }
  82. }
  83. /**
  84. * Saves the BuildInfo for a project in the VAJ repository.
  85. *
  86. * @param info BuildInfo build info to save
  87. */
  88. public static void saveBuildData(VAJBuildInfo info) {
  89. String data = info.asDataString();
  90. try {
  91. ToolData td = new ToolData(TOOL_DATA_KEY, data);
  92. VAJLocalUtil.getWorkspace().loadedProjectNamed(info.getVAJProjectName()).setToolRepositoryData(td);
  93. } catch (Throwable t) {
  94. throw new BuildException("BuildInfo for Project "
  95. + info.getVAJProjectName() + " could not be saved", t);
  96. }
  97. }
  98. }