001 /* 002 Copyright (C) 2002-2003 Renaud Pawlak <renaud@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.ide; 020 021 import java.util.Collection; 022 import java.util.Hashtable; 023 import java.util.Iterator; 024 import java.util.List; 025 import java.util.Map; 026 import java.util.Vector; 027 import org.objectweb.jac.util.File; 028 import org.objectweb.jac.util.Strings; 029 030 public class Project extends ModelElement { 031 032 public void checkGenerationPath() throws CannotGenerateException { 033 if (generationPath==null) { 034 throw new CannotGenerateException( 035 "Project \""+name+"\" does not have a generation path"); 036 } 037 } 038 039 boolean useToolsJavac = false; 040 public void setUseToolsJavac(boolean value) { 041 useToolsJavac = value; 042 } 043 public boolean getUseToolsJavac() { 044 return useToolsJavac; 045 } 046 047 File compilerCommand = new File("javac"); 048 049 /** 050 * Get the value of compilerCommand. 051 * @return value of compilerCommand. 052 */ 053 public File getCompilerCommand() { 054 return compilerCommand; 055 } 056 057 /** 058 * Set the value of compilerCommand. 059 * @param v Value to assign to compilerCommand. 060 */ 061 public void setCompilerCommand(File v) { 062 this.compilerCommand = v; 063 } 064 065 String compilerOptions; 066 public String getCompilerOptions() { 067 return compilerOptions; 068 } 069 public void setCompilerOptions(String options) { 070 this.compilerOptions = options; 071 } 072 073 File generationPath; 074 075 /** 076 * Get the value of generationPath. 077 * @return value of generationPath. 078 */ 079 public File getGenerationPath() { 080 return generationPath; 081 } 082 083 /** 084 * Set the value of generationPath. 085 * @param v Value to assign to generationPath. 086 */ 087 public void setGenerationPath(File v) { 088 this.generationPath = v; 089 } 090 091 /** 092 * Returns the directory where the .class files should be stored 093 */ 094 public File getClassesDir() { 095 return new File(generationPath,"classes"); 096 } 097 098 public File getManifestDir() { 099 return new File(generationPath,"META-INF"); 100 } 101 102 Vector packages = new Vector(); 103 104 /** 105 * Get the value of packages. 106 * @return value of packages. 107 */ 108 public List getPackages() { 109 return packages; 110 } 111 112 public void addPackage(Package p) { 113 packages.add(p); 114 } 115 116 public void removePackage(Package p) { 117 packages.remove(p); 118 } 119 120 /** 121 * Gets a package with a given name 122 * @param packageName the requested package name 123 */ 124 public Package getPackageByName(String packageName) { 125 Iterator it = packages.iterator(); 126 while (it.hasNext()) { 127 Package pkg = (Package)it.next(); 128 if (pkg.getName().equals(packageName)) 129 return pkg; 130 } 131 return null; 132 } 133 134 135 /** 136 * Find a package by its full name (my.package.ClassName) 137 * @param pkgName the package name to find 138 */ 139 public Package findPackage(String pkgName) { 140 int dot = pkgName.indexOf('.'); 141 if (dot!=-1) { 142 Package pkg = getPackageByName(pkgName.substring(0,dot)); 143 if (pkg!=null) 144 return pkg.findPackage(pkgName.substring(dot+1)); 145 else 146 return null; 147 } else { 148 return getPackageByName(pkgName); 149 } 150 } 151 152 Vector applications = new Vector(); 153 154 /** 155 * Get the value of applications. 156 * @return value of applications. 157 */ 158 public List getApplications() { 159 return applications; 160 } 161 162 public void addApplication(Application a) { 163 applications.add(a); 164 a.addAspectConfiguration(new AspectConfiguration("rtti")); 165 } 166 167 public void removeApplication(Application a) { 168 applications.remove(a); 169 } 170 171 /** List of File */ 172 List classpath = new Vector(); 173 public List getClasspath() { 174 return classpath; 175 } 176 public String getClasspathString() { 177 return Strings.join(classpath,System.getProperty("path.separator")); 178 } 179 public void addClasspath(File path) { 180 classpath.add(path); 181 } 182 public void removeClasspath(File path) { 183 classpath.remove(path); 184 } 185 186 /** 187 * Find a class by its full name (my.package.ClassName) 188 * @param className the class name to find 189 */ 190 public Class findClass(String className) { 191 int dot = className.indexOf('.'); 192 if (dot!=-1) { 193 String packageName = className.substring(0,dot); 194 Package pkg = getPackageByName(packageName); 195 if (pkg!=null) 196 return pkg.findClass(className.substring(dot+1)); 197 else 198 return null; 199 } else { 200 return null; 201 } 202 } 203 204 /** 205 * Returns all classes of all packages of the project. 206 */ 207 public Collection getClasses() { 208 Vector classes = new Vector(); 209 Iterator it = packages.iterator(); 210 while (it.hasNext()) { 211 Package pkg = (Package)it.next(); 212 classes.addAll(pkg.getAllClasses()); 213 } 214 return classes; 215 } 216 217 /** 218 * Returns all resources of all packages of the project. 219 */ 220 public Map getAllResources() { 221 Hashtable resources = new Hashtable(); 222 Iterator it = packages.iterator(); 223 while (it.hasNext()) { 224 Package pkg = (Package)it.next(); 225 resources.putAll(pkg.getAllResources()); 226 } 227 return resources; 228 } 229 230 Map externalFiles = new Hashtable(); 231 /** 232 * Add an external file to include in the JAR 233 * @param name name of the file in the JAR 234 * @param file the file to include 235 */ 236 public void addExternalFile(String name, File file) { 237 externalFiles.put(name,file); 238 } 239 public void removeExternalFile(String name) { 240 externalFiles.remove(name); 241 } 242 public Map getExternalFiles() { 243 return externalFiles; 244 } 245 }