3m9 compatible;
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / SetClasspathOperation.java
index 513ad3d..29c98d5 100644 (file)
@@ -27,6 +27,7 @@ import net.sourceforge.phpdt.core.IPackageFragment;
 import net.sourceforge.phpdt.core.IPackageFragmentRoot;
 import net.sourceforge.phpdt.core.JavaModelException;
 import net.sourceforge.phpdt.internal.compiler.util.ObjectVector;
+import net.sourceforge.phpdt.internal.core.util.Util;
 
 import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IProject;
@@ -38,6 +39,8 @@ import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
+import net.sourceforge.phpdt.internal.core.JavaModelManager;
+import net.sourceforge.phpdt.internal.core.JavaProject;
 
 /**
  * This operation sets an <code>IJavaProject</code>'s classpath.
@@ -48,11 +51,13 @@ public class SetClasspathOperation extends JavaModelOperation {
 
        IClasspathEntry[] oldResolvedPath, newResolvedPath;
        IClasspathEntry[] newRawPath;
-       boolean canChangeResource;
+       boolean canChangeResources;
        boolean needCycleCheck;
        boolean needValidation;
        boolean needSave;
        IPath newOutputLocation;
+       JavaProject project;
+       boolean identicalRoots;
        
        public static final IClasspathEntry[] ReuseClasspath = new IClasspathEntry[0];
        public static final IClasspathEntry[] UpdateClasspath = new IClasspathEntry[0];
@@ -63,7 +68,7 @@ public class SetClasspathOperation extends JavaModelOperation {
         * When executed, this operation sets the classpath of the given project.
         */
        public SetClasspathOperation(
-               IJavaProject project,
+               JavaProject project,
                IClasspathEntry[] oldResolvedPath,
                IClasspathEntry[] newRawPath,
                IPath newOutputLocation,
@@ -75,9 +80,10 @@ public class SetClasspathOperation extends JavaModelOperation {
                this.oldResolvedPath = oldResolvedPath;
                this.newRawPath = newRawPath;
                this.newOutputLocation = newOutputLocation;
-               this.canChangeResource = canChangeResource;
+               this.canChangeResources = canChangeResource;
                this.needValidation = needValidation;
                this.needSave = needSave;
+               this.project = project;
        }
 
        /**
@@ -219,7 +225,6 @@ public class SetClasspathOperation extends JavaModelOperation {
 //             }
 //             return fragments;
 //     }
-
        /**
         * Sets the classpath of the pre-specified project.
         */
@@ -236,12 +241,11 @@ public class SetClasspathOperation extends JavaModelOperation {
                JavaModelException originalException = null;
 
                try {
-                       JavaProject project = getProject();
                        if (this.newRawPath == UpdateClasspath) this.newRawPath = project.getRawClasspath();
                        if (this.newRawPath != ReuseClasspath){
                                updateClasspath();
-//                             project.updatePackageFragmentRoots();
-                               JavaModelManager.getJavaModelManager().deltaProcessor.addForRefresh(project);
+                               project.updatePackageFragmentRoots();
+                               JavaModelManager.getJavaModelManager().getDeltaProcessor().addForRefresh(project);
                        }
 
                } catch(JavaModelException e){
@@ -256,11 +260,23 @@ public class SetClasspathOperation extends JavaModelOperation {
                        } catch(JavaModelException e){
                                if (originalException != null) throw originalException; 
                                throw e;
+                       } finally {
+                               // ensures the project is getting rebuilt if only variable is modified
+                               if (!this.identicalRoots && this.canChangeResources) {
+                                       try {
+                                               this.project.getProject().touch(this.progressMonitor);
+                                       } catch (CoreException e) {
+                                               if (JavaModelManager.CP_RESOLVE_VERBOSE){
+                                                       Util.verbose("CPContainer INIT - FAILED to touch project: "+ this.project.getElementName(), System.err); //$NON-NLS-1$
+                                                       e.printStackTrace();
+                                               }
+                                       }
+                               }                               
                        }
                }
                done();
        }
-
+       
        /**
         * Generates the delta of removed/added/reordered roots.
         * Use three deltas in case the same root is removed/added/reordered (for
@@ -526,12 +542,12 @@ public class SetClasspathOperation extends JavaModelOperation {
         * otherwise <code>false</code>. Subclasses must override.
         */
        public boolean isReadOnly() {
-               return !this.canChangeResource;
+               return !this.canChangeResources;
        }
 
        protected void saveClasspathIfNecessary() throws JavaModelException {
                
-               if (!this.canChangeResource || !this.needSave) return;
+               if (!this.canChangeResources || !this.needSave) return;
                                
                IClasspathEntry[] classpathForSave;
                JavaProject project = getProject();
@@ -586,7 +602,7 @@ public class SetClasspathOperation extends JavaModelOperation {
 
                // resolve new path (asking for marker creation if problems)
                if (this.newResolvedPath == null) {
-                       this.newResolvedPath = project.getResolvedClasspath(true, this.canChangeResource);
+                       this.newResolvedPath = project.getResolvedClasspath(true, this.canChangeResources);
                }
                
 //             if (this.oldResolvedPath != null) {
@@ -628,8 +644,8 @@ public class SetClasspathOperation extends JavaModelOperation {
                                                        project.setRawClasspath(
                                                                UpdateClasspath, 
                                                                SetClasspathOperation.ReuseOutputLocation, 
-                                                               this.fMonitor, 
-                                                               this.canChangeResource,  
+                                                               this.progressMonitor, 
+                                                               this.canChangeResources,  
                                                                project.getResolvedClasspath(true), 
                                                                false, // updating only - no validation
                                                                false); // updating only - no need to save
@@ -650,7 +666,7 @@ public class SetClasspathOperation extends JavaModelOperation {
        protected void updateCycleMarkersIfNecessary(IClasspathEntry[] newResolvedPath) {
 
                if (!this.needCycleCheck) return;
-               if (!this.canChangeResource) return;
+               if (!this.canChangeResources) return;
                 
                try {
                        JavaProject project = getProject();
@@ -728,7 +744,7 @@ public class SetClasspathOperation extends JavaModelOperation {
         */
        protected void updateProjectReferencesIfNecessary() throws JavaModelException {
                
-               if (!this.canChangeResource) return;
+               if (!this.canChangeResources) return;
                if (this.newRawPath == ReuseClasspath || this.newRawPath == UpdateClasspath) return;
        
                JavaProject jproject = getProject();
@@ -790,7 +806,7 @@ public class SetClasspathOperation extends JavaModelOperation {
                        }
        
                        description.setReferencedProjects(requiredProjectArray);
-                       project.setDescription(description, this.fMonitor);
+                       project.setDescription(description, this.progressMonitor);
        
                } catch(CoreException e){
                        throw new JavaModelException(e);