KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > apt > core > internal > AptProject


1 /*******************************************************************************
2  * Copyright (c) 2005, 2007 BEA Systems, Inc.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * jgarms@bea.com - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.apt.core.internal;
12
13 import org.eclipse.core.resources.IFolder;
14 import org.eclipse.core.resources.IResource;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedFileManager;
17 import org.eclipse.jdt.apt.core.internal.generatedfile.GeneratedSourceFolderManager;
18 import org.eclipse.jdt.apt.core.internal.util.FileSystemUtil;
19 import org.eclipse.jdt.apt.core.util.AptPreferenceConstants;
20 import org.eclipse.jdt.core.IJavaProject;
21
22 /**
23  * Stores project-specific data for APT. Analagous to JavaProject
24  * @author jgarms
25  *
26  */

27 public class AptProject {
28     
29     private final IJavaProject _javaProject;
30     
31     private final GeneratedFileManager _gfm;
32     
33     private final GeneratedSourceFolderManager _gsfm;
34     
35     public AptProject(final IJavaProject javaProject) {
36         _javaProject = javaProject;
37         _gsfm = new GeneratedSourceFolderManager(this);
38         _gfm = new GeneratedFileManager(this, _gsfm);
39     }
40     
41     public IJavaProject getJavaProject() {
42         return _javaProject;
43     }
44     
45     public GeneratedFileManager getGeneratedFileManager() {
46         return _gfm;
47     }
48     
49     public GeneratedSourceFolderManager getGeneratedSourceFolderManager() {
50         return _gsfm;
51     }
52     
53     /**
54      * This method should be called whenever compilation begins, to perform
55      * initialization and verify configuration.
56      */

57     public void compilationStarted() {
58         _gfm.compilationStarted();
59     }
60     
61     /**
62      * This method should be called whenever project preferences are
63      * changed by the user. This may cause the classpath and generated
64      * source folder to change, so this should <em>not</em> be called
65      * from a context where resources may be locked, e.g., within
66      * certain resource change listeners.
67      * @param key a preference key such as @see AptPreferenceConstants#APT_ENABLED
68      */

69     public void preferenceChanged(String JavaDoc key) {
70         if (AptPreferenceConstants.APT_GENSRCDIR.equals(key)) {
71             _gsfm.folderNamePreferenceChanged();
72         }
73         else if(AptPreferenceConstants.APT_ENABLED.equals(key) ){
74             _gsfm.enabledPreferenceChanged();
75         }
76     }
77
78     /**
79      * Invoked whenever a project is cleaned. This will remove any state kept about
80      * generated files for the given project. If the deleteFiles flag is specified,
81      * then the contents of the generated source folder will be deleted.
82      *
83      * @param deleteFiles true if the contents of the generated source folder are to be
84      * deleted, false otherwise.
85      */

86     
87     public void projectClean( boolean deleteFiles )
88     {
89         _gfm.projectCleaned();
90         
91         // delete the contents of the generated source folder, but don't delete
92
// the generated source folder because that will cause a classpath change,
93
// which will force the next build to be a full build.
94
if ( deleteFiles )
95         {
96             IFolder f = _gsfm.getFolder();
97             if ( f != null && f.exists() )
98             {
99                 try
100                 {
101                     IResource[] members = f.members();
102                     for ( int i = 0; i<members.length; i++ ){
103                         FileSystemUtil.deleteDerivedResources(members[i]);
104                     }
105                 }
106                 catch ( CoreException ce )
107                 {
108                     AptPlugin.log(ce, "Could not delete generated files"); //$NON-NLS-1$
109
}
110             }
111         }
112     }
113     
114     /**
115      * Invoked when a project is closed.
116      */

117     public void projectClosed()
118     {
119         _gfm.projectClosed();
120     }
121     
122     /**
123      * Invoked when a project has been deleted, to clean up
124      * state associated with the project.
125      * This will not delete any of the project's generated files
126      * from disk, nor will it delete this object (which in turn
127      * owns the GeneratedFileManager for this project).
128      */

129     public void projectDeleted()
130     {
131         if (AptPlugin.DEBUG)
132             AptPlugin.trace("AptProject.projectDeleted cleaning state for project " + _javaProject.getElementName()); //$NON-NLS-1$
133
_gfm.projectDeleted();
134     }
135
136 }
137
Popular Tags