Source code: org/aspectj/tools/ajde/netbeans/NbProjectProperties.java
1
2 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 *
4 * This file is part of the IDE support for the AspectJ(tm)
5 * programming language; see http://aspectj.org
6 *
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in
9 * compliance with the License. You may obtain a copy of the License at
10 * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
11 *
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
16 *
17 * The Original Code is AspectJ.
18 *
19 * The Initial Developer of the Original Code is Xerox Corporation. Portions
20 * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
21 * All Rights Reserved.
22 *
23 * Contributor(s):
24 */
25
26 package org.aspectj.tools.ajde.netbeans;
27
28 import java.util.*;
29 import java.io.*;
30 import javax.swing.*;
31 import org.openide.*;
32
33 import org.aspectj.tools.ide.*;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.actions.CallableSystemAction;
36 import org.openide.windows.*;
37 import org.openide.loaders.DataFolder;
38 import org.openide.modules.ModuleInstall;
39 import org.openide.util.actions.SystemAction;
40 //import org.openidex.util.Utilities2;
41 import org.openide.explorer.*;
42 import org.openide.execution.*;
43 import org.openide.explorer.view.*;
44 import org.openide.nodes.*;
45 import org.openide.text.*;
46 import org.openide.filesystems.*;
47 import org.openide.loaders.*;
48 import org.openide.cookies.*;
49 import org.netbeans.core.*;
50 import org.openide.src.*;
51
52 import org.openide.compiler.*;
53 import org.openide.util.HelpCtx;
54 import org.openide.util.actions.CallableSystemAction;
55 import org.openide.windows.*;
56 import org.openide.loaders.DataFolder;
57 import org.openide.modules.ModuleInstall;
58 import org.openide.util.actions.SystemAction;
59 import org.openide.explorer.*;
60 import org.openide.execution.*;
61 import org.openide.explorer.view.*;
62 import org.openide.options.*;
63 import org.openide.nodes.*;
64 import org.openide.text.*;
65 import org.openide.filesystems.*;
66 import org.openide.loaders.*;
67 import org.openide.cookies.*;
68 import org.netbeans.core.*;
69 import org.openide.filesystems.*;
70 import org.aspectj.ajde.*;
71 import org.aspectj.ajde.ui.*;
72 import org.aspectj.asm.*;
73
74 public class NbProjectProperties implements ProjectPropertiesAdapter {
75
76 private UserPreferencesAdapter preferencesAdapter = null;
77
78 public NbProjectProperties(UserPreferencesAdapter preferencesAdapter) {
79 this.preferencesAdapter = preferencesAdapter;
80 }
81
82 public String getDefaultBuildConfigFile() {
83 List configFiles = Ajde.getDefault().getProjectProperties().getProjectSourceFiles();
84
85 String projectName = Ajde.getDefault().getProjectProperties().getProjectName();
86 String filePath = Ajde.getDefault().getProjectProperties().getOutputPath() + '/' +
87 "default-config.lst";
88
89 //LstBuildConfigFileUpdater.writeConfigFile(filePath, configFiles);
90
91 return filePath;
92 // List configs = getConfigFiles();
93 // if (configs != null && configs.size() > 0) {
94 // return (String)configs.get(0);
95 // } else {
96 // return null;
97 // }
98 //
99 }
100
101 public List getBuildConfigFiles() {
102 List configs = new ArrayList();
103 configs.add(BuildConfigManager.DEFAULT_CONFIG_LABEL);
104 Repository repository = org.openide.TopManager.getDefault().getRepository();
105 Enumeration filesystems = repository.getFileSystems();
106 while (filesystems.hasMoreElements()) {
107 FileSystem fs = (FileSystem)filesystems.nextElement();
108 if (fs instanceof ExLocalFileSystem) {
109 ExLocalFileSystem exfs = (ExLocalFileSystem)fs;
110 if (new File(exfs.getSystemName()).exists()) {
111 configs.addAll(getLstFilesInDir(exfs.getSystemName()));
112 }
113 }
114 }
115 if (configs.size() == 0) {
116 Ajde.getDefault().getErrorHandler().handleWarning("Could not find any \".lst\" in the project filesystems.");
117 }
118 return configs;
119 }
120
121 public String getLastActiveBuildConfigFile() {
122 return null;
123 }
124
125 /**
126 * Retrieves all of the .lst files in a directory, replacing any '\' characters with '/'.
127 *
128 * @returns an empty List if no files were found
129 */
130 private List getLstFilesInDir(String dirPath) { // todo: why not use a FileFilter?
131 List configs = new ArrayList();
132 File f = new File(dirPath);
133 File[] dirContents = f.listFiles();
134 for (int j = 0; j < dirContents.length; j++) {
135 if (dirContents[j].isDirectory()) {
136 configs.addAll(getLstFilesInDir(dirContents[j].getAbsolutePath()));
137 } else if (dirContents[j].getName().endsWith(".lst")) {
138 configs.add(dirContents[j].getAbsolutePath().replace('\\', '/'));
139 }
140 }
141 return configs;
142 }
143
144 public boolean isGlobalMode() {
145 return true;
146 }
147
148 public String getAjcWorkingDir() {
149 return getRootProjectDir();
150 }
151
152 public String getOutputPath() {
153 Vector filesystemPaths = new Vector();
154 Enumeration filesystems = TopManager.getDefault().getRepository().getFileSystems();
155
156 String path = "";
157 while (filesystems.hasMoreElements()) {
158 FileSystem fs = (FileSystem)filesystems.nextElement();
159 if (fs instanceof org.netbeans.core.ExLocalFileSystem) {
160 org.openide.filesystems.LocalFileSystem exfs = (org.openide.filesystems.LocalFileSystem)fs;
161 path = exfs.getRootDirectory().getAbsolutePath();
162 return path;
163 }
164 }
165 Ajde.getDefault().getErrorHandler().handleWarning("Build output path could not be determined, using \".\"");
166 return ".";
167 }
168
169 public String getClassToExecute() {
170 return null;
171 }
172
173 public String getExecutionArgs() {
174 return null;
175 }
176
177 public String getVmArgs() {
178 return null;
179 }
180
181 public String getProjectName() {
182 return null;
183 }
184
185 public String getRootProjectDir() {
186 Repository repository = org.openide.TopManager.getDefault().getRepository();
187 Enumeration filesystems = repository.getFileSystems();
188 File f = null;
189 while (filesystems.hasMoreElements()) {
190 FileSystem fs = (FileSystem)filesystems.nextElement();
191 if (fs instanceof org.netbeans.core.ExLocalFileSystem) {
192 f = new File(fs.getSystemName());
193 if (f.getPath().endsWith("ajworkingdir")) {
194 return f.getAbsolutePath();
195 }
196 }
197 }
198 return null;
199 }
200
201 public String getProjectSourcePath() {
202 Vector filesystemPaths = new Vector();
203 Enumeration filesystems = org.openide.TopManager.getDefault().getRepository().getFileSystems();
204 File f = null;
205 String paths = "";
206 while (filesystems.hasMoreElements()) {
207 FileSystem fs = (FileSystem)filesystems.nextElement();
208 if (fs instanceof org.openide.filesystems.LocalFileSystem &&
209 !fs.getSystemName().endsWith("ajworkingdir")) {
210 f = new File(fs.getSystemName());
211 paths += f.getAbsolutePath() + ";";
212 }
213 }
214 return paths;
215 }
216
217 /**
218 * @todo fix the ugly loop
219 */
220 public List getProjectSourceFiles() {
221 List projectFiles = new ArrayList();
222
223 Enumeration enum = org.openide.TopManager.getDefault().getRepository().getFileSystems();
224 while (enum.hasMoreElements()) {
225 FileSystem fileSystem = (FileSystem)enum.nextElement();
226 if (!(fileSystem instanceof ExLocalFileSystem)) continue;
227 ExLocalFileSystem exLocalFileSystem = (ExLocalFileSystem)fileSystem;
228 File rootFile = exLocalFileSystem.getRootDirectory();
229 List dirs = new Vector();
230 List files = new Vector();
231 dirs.add(rootFile);
232 Vector classElements = new Vector();
233 while (dirs.size() > 0) {
234 File dir = (File)dirs.remove(0);
235 File[] fileArray = dir.listFiles(new FileFilter() {
236 public boolean accept(File f) {
237 return f.isDirectory() || f.getName().endsWith(".java");
238 }
239 });
240 if (fileArray != null) {
241 for (int i = 0; i < fileArray.length; i++) {
242 File file = fileArray[i];
243 if (file.isDirectory()) {
244 dirs.add(file);
245 } else {
246 projectFiles.add(file.getAbsolutePath());
247 }
248 }
249 }
250 }
251 }
252 return projectFiles;
253
254 }
255
256 public String getClasspath() {
257 Vector filesystemPaths = new Vector();
258 Enumeration filesystems = org.openide.TopManager.getDefault().getRepository().getFileSystems();
259 File f = null;
260 String jars = "";
261 while (filesystems.hasMoreElements()) {
262 FileSystem fs = (FileSystem)filesystems.nextElement();
263 if (fs instanceof org.openide.filesystems.JarFileSystem) {
264 f = new File(fs.getSystemName());
265 jars += f.getAbsolutePath() + ";";
266 }
267 }
268 return jars + System.getProperty("netbeans.home") + "/lib/ext/aspectjrt.jar";
269 }
270
271 public String getBootClasspath() {
272 return null;
273 }
274
275
276 }