source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/optional/ide/VAJAntTool.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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