felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dsav...@apache.org
Subject svn commit: r918213 - in /felix/trunk/sigil/eclipse: core/src/org/apache/felix/sigil/eclipse/internal/model/project/ core/src/org/apache/felix/sigil/eclipse/job/ core/src/org/apache/felix/sigil/eclipse/model/project/ ui/src/org/apache/felix/sigil/ui/ec...
Date Tue, 02 Mar 2010 21:54:53 GMT
Author: dsavage
Date: Tue Mar  2 21:54:53 2010
New Revision: 918213

URL: http://svn.apache.org/viewvc?rev=918213&view=rev
Log:
Patches for FELIX-2160 and FELIX-2161 - now manages project warnings internally vs in external
job also added support for refreshing project and ensure that views are updated when editting
in rich client or text editor

Modified:
    felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
    felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
    felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/project/ISigilProjectModel.java
    felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java

Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java?rev=918213&r1=918212&r2=918213&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
(original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/internal/model/project/SigilProject.java
Tue Mar  2 21:54:53 2010
@@ -51,6 +51,7 @@
 import org.apache.felix.sigil.repository.ResolutionMonitorAdapter;
 import org.apache.felix.sigil.utils.GlobCompiler;
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.ProjectScope;
@@ -110,11 +111,18 @@
 
     public void save( IProgressMonitor monitor ) throws CoreException
     {
+        save(monitor, true);
+    }
+    
+    public void save( IProgressMonitor monitor, boolean rebuildDependencies ) throws CoreException
+    {
         SubMonitor progress = SubMonitor.convert( monitor, 100 );
 
         bldProjectFile.setContents( buildContents(), IFile.KEEP_HISTORY, progress.newChild(
10 ) );
-        
-        rebuildDependencies(progress.newChild(90));
+     
+        if ( rebuildDependencies ) {
+            rebuildDependencies(progress.newChild(90));
+        }
     }
 
     public void rebuildDependencies(IProgressMonitor monitor) throws CoreException {
@@ -123,26 +131,79 @@
         calculateUses();
 
         IRepositoryManager manager = SigilCore.getRepositoryManager( this );
-        ResolutionConfig config = new ResolutionConfig( ResolutionConfig.INCLUDE_OPTIONAL
);
+        ResolutionConfig config = new ResolutionConfig( ResolutionConfig.INCLUDE_OPTIONAL
| ResolutionConfig.IGNORE_ERRORS );
 
         try
         {
-            IResolution res = manager.getBundleResolver().resolve( this, config,
+            IResolution resolution = manager.getBundleResolver().resolve( this, config,
                 new ResolutionMonitorAdapter( progress.newChild( 10 ) ) );
-            if ( !res.isSynchronized() )
+            
+            getProject().deleteMarkers( SigilCore.MARKER_UNRESOLVED_DEPENDENCY, true,
+                IResource.DEPTH_ONE );
+
+            // Find missing imports
+            Collection<IPackageImport> imports = getBundle().getBundleInfo().getImports();
+            for ( IPackageImport pkgImport : imports )
+            {
+                if ( resolution.getProvider( pkgImport ) == null )
+                {
+                    markMissingImport( pkgImport, getProject() );
+                }
+            }
+
+            // Find missing required bundles
+            Collection<IRequiredBundle> requiredBundles = getBundle().getBundleInfo()
+            .getRequiredBundles();
+            for ( IRequiredBundle requiredBundle : requiredBundles )
+            {
+                if ( resolution.getProvider( requiredBundle ) == null )
+                {
+                    markMissingRequiredBundle( requiredBundle, getProject() );
+                }
+            }
+            
+            if ( !resolution.isSynchronized() )
             {
-                res.synchronize( progress.newChild( 60 ) );
+                resolution.synchronize( progress.newChild( 60 ) );
             }
+            
+
         }
         catch ( ResolutionException e )
         {
-            throw SigilCore.newCoreException( "Failed to synchronize dependencies", e );
+            throw SigilCore.newCoreException( "Failed to resolve dependencies", e );
         }
 
         progress.setWorkRemaining( 30 );
 
         SigilCore.rebuildBundleDependencies( this, progress.newChild( 30 ) );
     }
+    
+
+
+    private static void markMissingImport( IPackageImport pkgImport, IProject project ) throws
CoreException
+    {
+        IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_IMPORT_PACKAGE
);
+        marker.setAttribute( "element", pkgImport.getPackageName() );
+        marker.setAttribute( "versionRange", pkgImport.getVersions().toString() );
+        marker.setAttribute( IMarker.MESSAGE, "Cannot resolve imported package \"" + pkgImport.getPackageName()
+            + "\" with version range " + pkgImport.getVersions() );
+        marker.setAttribute( IMarker.SEVERITY, pkgImport.isOptional() ? IMarker.SEVERITY_WARNING
+            : IMarker.SEVERITY_ERROR );
+        marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
+    }
+
+
+    private static void markMissingRequiredBundle( IRequiredBundle req, IProject project
) throws CoreException
+    {
+        IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_REQUIRE_BUNDLE
);
+        marker.setAttribute( "element", req.getSymbolicName() );
+        marker.setAttribute( "versionRange", req.getVersions().toString() );
+        marker.setAttribute( IMarker.MESSAGE, "Cannot resolve required bundle \"" + req.getSymbolicName()
+            + "\" with version range " + req.getVersions() );
+        marker.setAttribute( IMarker.SEVERITY, req.isOptional() ? IMarker.SEVERITY_WARNING
: IMarker.SEVERITY_ERROR );
+        marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
+    }    
 
     /**
      * Returns the project custom preference pool.

Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java?rev=918213&r1=918212&r2=918213&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
(original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/job/ResolveProjectsJob.java
Tue Mar  2 21:54:53 2010
@@ -22,53 +22,34 @@
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Set;
 
 import org.apache.felix.sigil.eclipse.SigilCore;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
-import org.apache.felix.sigil.model.osgi.IPackageImport;
-import org.apache.felix.sigil.model.osgi.IRequiredBundle;
-import org.apache.felix.sigil.repository.IBundleResolver;
-import org.apache.felix.sigil.repository.IRepositoryManager;
-import org.apache.felix.sigil.repository.IResolution;
-import org.apache.felix.sigil.repository.ResolutionConfig;
-import org.apache.felix.sigil.repository.ResolutionException;
-import org.apache.felix.sigil.repository.ResolutionMonitorAdapter;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
 import org.eclipse.core.resources.IWorkspace;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.MultiStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 
 
 public class ResolveProjectsJob extends Job
 {
-
-    private final IWorkspace workspace;
-    private final IProject project;
-
-
+    final Collection<ISigilProjectModel> sigilProjects;
+    
     public ResolveProjectsJob( IWorkspace workspace )
     {
         super( "Resolving Sigil projects" );
-        this.workspace = workspace;
-        this.project = null;
-        setRule( ResourcesPlugin.getWorkspace().getRoot() );
+        setRule( workspace.getRoot() );
+        sigilProjects = SigilCore.getRoot().getProjects();
     }
 
 
-    public ResolveProjectsJob( IProject project )
+    public ResolveProjectsJob(ISigilProjectModel project)
     {
         super( "Resolving Sigil project" );
-        this.workspace = null;
-        this.project = project;
-        setRule( project.getFile( SigilCore.SIGIL_PROJECT_FILE ) );
+        setRule( project.getProject() );
+        sigilProjects = Collections.singleton(project);
     }
 
 
@@ -77,18 +58,11 @@
     {
         MultiStatus status = new MultiStatus( SigilCore.PLUGIN_ID, 0, "Error resolving Sigil
projects", null );
 
-        Collection<ISigilProjectModel> sigilProjects = null;
-
-        if ( workspace != null )
-        {
-            sigilProjects = SigilCore.getRoot().getProjects();
-        }
-        else if ( project != null )
+        for ( ISigilProjectModel sigilProject : sigilProjects )
         {
             try
             {
-                ISigilProjectModel sigilProject = SigilCore.create( project );
-                sigilProjects = Collections.singleton( sigilProject );
+                sigilProject.rebuildDependencies(monitor);
             }
             catch ( CoreException e )
             {
@@ -96,84 +70,6 @@
             }
         }
 
-        if ( sigilProjects != null )
-        {
-            for ( ISigilProjectModel sigilProject : sigilProjects )
-            {
-                try
-                {
-                    // Delete existing dependency markers on project
-                    sigilProject.getProject().deleteMarkers( SigilCore.MARKER_UNRESOLVED_DEPENDENCY,
true,
-                        IResource.DEPTH_ONE );
-
-                    IRepositoryManager repository = SigilCore.getRepositoryManager( sigilProject
);
-                    ResolutionMonitorAdapter resolutionMonitor = new ResolutionMonitorAdapter(
monitor );
-
-                    IBundleResolver resolver = repository.getBundleResolver();
-                    ResolutionConfig config = new ResolutionConfig( ResolutionConfig.IGNORE_ERRORS
);
-
-                    // Execute resolver
-                    IResolution resolution = resolver.resolve( sigilProject, config, resolutionMonitor
);
-
-                    // Find missing imports
-                    Collection<IPackageImport> imports = sigilProject.getBundle().getBundleInfo().getImports();
-                    for ( IPackageImport pkgImport : imports )
-                    {
-                        if ( resolution.getProvider( pkgImport ) == null )
-                        {
-                            markMissingImport( pkgImport, sigilProject.getProject() );
-                        }
-                    }
-
-                    // Find missing required bundles
-                    Collection<IRequiredBundle> requiredBundles = sigilProject.getBundle().getBundleInfo()
-                        .getRequiredBundles();
-                    for ( IRequiredBundle requiredBundle : requiredBundles )
-                    {
-                        if ( resolution.getProvider( requiredBundle ) == null )
-                        {
-                            markMissingRequiredBundle( requiredBundle, sigilProject.getProject()
);
-                        }
-                    }
-                }
-                catch ( ResolutionException e )
-                {
-                    status.add( new Status( IStatus.ERROR, SigilCore.PLUGIN_ID, 0, "Error
resolving project "
-                        + sigilProject.getProject().getName(), e ) );
-                }
-                catch ( CoreException e )
-                {
-                    status.add( e.getStatus() );
-                }
-            }
-        }
-
         return status;
     }
-
-
-    private static void markMissingImport( IPackageImport pkgImport, IProject project ) throws
CoreException
-    {
-        IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_IMPORT_PACKAGE
);
-        marker.setAttribute( "element", pkgImport.getPackageName() );
-        marker.setAttribute( "versionRange", pkgImport.getVersions().toString() );
-        marker.setAttribute( IMarker.MESSAGE, "Cannot resolve imported package \"" + pkgImport.getPackageName()
-            + "\" with version range " + pkgImport.getVersions() );
-        marker.setAttribute( IMarker.SEVERITY, pkgImport.isOptional() ? IMarker.SEVERITY_WARNING
-            : IMarker.SEVERITY_ERROR );
-        marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
-    }
-
-
-    private static void markMissingRequiredBundle( IRequiredBundle req, IProject project
) throws CoreException
-    {
-        IMarker marker = project.getProject().createMarker( SigilCore.MARKER_UNRESOLVED_REQUIRE_BUNDLE
);
-        marker.setAttribute( "element", req.getSymbolicName() );
-        marker.setAttribute( "versionRange", req.getVersions().toString() );
-        marker.setAttribute( IMarker.MESSAGE, "Cannot resolve required bundle \"" + req.getSymbolicName()
-            + "\" with version range " + req.getVersions() );
-        marker.setAttribute( IMarker.SEVERITY, req.isOptional() ? IMarker.SEVERITY_WARNING
: IMarker.SEVERITY_ERROR );
-        marker.setAttribute( IMarker.PRIORITY, IMarker.PRIORITY_HIGH );
-    }
-
 }

Modified: felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/project/ISigilProjectModel.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/project/ISigilProjectModel.java?rev=918213&r1=918212&r2=918213&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/project/ISigilProjectModel.java
(original)
+++ felix/trunk/sigil/eclipse/core/src/org/apache/felix/sigil/eclipse/model/project/ISigilProjectModel.java
Tue Mar  2 21:54:53 2010
@@ -72,7 +72,15 @@
      *            should be reported and that the operation cannot be cancelled
      * @throws CoreException
      */
-    void save( IProgressMonitor monitor ) throws CoreException;
+    void save(IProgressMonitor monitor) throws CoreException;
+    
+    /**
+     * Save the project and optionally rebuildDependencies
+     * @param monitor
+     * @param rebuildDependencies
+     * @throws CoreException
+     */
+    void save( IProgressMonitor monitor, boolean rebuildDependencies ) throws CoreException;
     
     void rebuildDependencies(IProgressMonitor monitor) throws CoreException;
 

Modified: felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java?rev=918213&r1=918212&r2=918213&view=diff
==============================================================================
--- felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
(original)
+++ felix/trunk/sigil/eclipse/ui/src/org/apache/felix/sigil/ui/eclipse/ui/editors/project/SigilProjectEditorPart.java
Tue Mar  2 21:54:53 2010
@@ -28,6 +28,7 @@
 
 import org.apache.felix.sigil.common.osgi.VersionRange;
 import org.apache.felix.sigil.eclipse.SigilCore;
+import org.apache.felix.sigil.eclipse.job.ResolveProjectsJob;
 import org.apache.felix.sigil.eclipse.model.project.ISigilProjectModel;
 import org.apache.felix.sigil.model.IModelElement;
 import org.apache.felix.sigil.model.ModelElementFactory;
@@ -66,7 +67,7 @@
 {
 
     private final Set<IModelElement> unresolvedElements = Collections.synchronizedSet(
new HashSet<IModelElement>() );
-    private ISigilProjectModel projectx;
+    private ISigilProjectModel project;
     private ISigilProjectModel tempProject;
     private volatile boolean saving = false;
     private int dependenciesPageIndex;
@@ -101,8 +102,10 @@
                     try
                     {
                         if ( doInternalSave(monitor) ) {
-                            projectx.setBundle( null );
-                            projectx.rebuildDependencies(monitor);                      
     
+                            project.setBundle( null );
+                            tempProject.setBundle(null);
+                            project.rebuildDependencies(monitor);
+                            refreshAllPages();
                         }
 
                         monitor.done();
@@ -116,7 +119,7 @@
         }
         catch ( InvocationTargetException e )
         {
-            SigilCore.error( "Failed to save " + projectx, e.getTargetException() );
+            SigilCore.error( "Failed to save " + project, e.getTargetException() );
         }
         catch ( InterruptedException e )
         {
@@ -147,11 +150,12 @@
         else if ( isDirty() )
         {
             commitPages( true );
-            tempProject.save( monitor );
+            tempProject.save( monitor, false );
             SigilUI.runInUISync( new Runnable()
             {
                 public void run()
                 {
+                    textPage.setInput(getEditorInput());
                     editorDirtyStateChanged();
                 }
             } );
@@ -177,7 +181,7 @@
             addPage( new ExportsForm( this, tempProject ) );
             textPage = new PropertiesForm( this, tempProject );
             addPage( textPage, getEditorInput() );
-            setPartName( projectx.getSymbolicName() );
+            setPartName( project.getSymbolicName() );
 
             refreshTabImages();
         }
@@ -231,6 +235,27 @@
 
     public void resourceChanged( IResourceChangeEvent event )
     {
+        switch (event.getType()) {
+            case IResourceChangeEvent.PRE_REFRESH:
+                handleRefresh(event);
+                break;
+            case IResourceChangeEvent.POST_CHANGE:
+                handleChange(event);
+                break;
+        }
+
+    }
+
+
+    private void handleRefresh(IResourceChangeEvent event)
+    {
+        ResolveProjectsJob job = new ResolveProjectsJob(project);
+        job.schedule();        
+    }
+
+
+    private void handleChange(IResourceChangeEvent event)
+    {
         IResourceDelta delta = event.getDelta();
         final IFile editorFile = ( ( IFileEditorInput ) getEditorInput() ).getFile();
         try
@@ -243,43 +268,13 @@
                     IResource resource = delta.getResource();
                     if ( resource instanceof IProject )
                     {
-                        if ( !editorFile.getProject().equals( resource ) )
-                        {
-                            return false;
-                        }
-                        if ( kind == IResourceDelta.CHANGED && ( delta.getFlags()
& IResourceDelta.MARKERS ) > 0 )
-                        {
-                            loadUnresolvedDependencies();
-                            refreshAllPages();
-                        }
-                        return true;
+                        int flags = delta.getFlags();
+                        return handleProjectChange(editorFile, (IProject) resource, kind,
flags);
                     }
 
                     if ( resource instanceof IFile )
                     {
-                        IFile affectedFile = ( IFile ) resource;
-                        if ( affectedFile.equals( editorFile ) )
-                        {
-                            switch ( kind )
-                            {
-                                case IResourceDelta.REMOVED:
-                                    close( false );
-                                    break;
-                                case IResourceDelta.CHANGED:
-                                    if ( !saving )
-                                    {
-                                        reload();
-                                    }
-                                    SigilUI.runInUISync( new Runnable()
-                                    {
-                                        public void run()
-                                        {
-                                            setPartName( projectx.getSymbolicName() );
-                                        }
-                                    } );
-                                    break;
-                            }
-                        }
+                        handleFileChange(editorFile, (IFile) resource, kind);
                         // Recurse no more
                         return false;
                     }
@@ -295,6 +290,48 @@
     }
 
 
+    protected void handleFileChange(IFile editorFile, IFile affectedFile, int kind)
+    {
+        if ( affectedFile.equals( editorFile ) )
+        {
+            switch ( kind )
+            {
+                case IResourceDelta.REMOVED:
+                    close( false );
+                    break;
+                case IResourceDelta.CHANGED:
+                    if ( !saving )
+                    {
+                        reload();
+                    }
+                    SigilUI.runInUISync( new Runnable()
+                    {
+                        public void run()
+                        {
+                            setPartName( project.getSymbolicName() );
+                        }
+                    } );
+                    break;
+            }
+        }
+    }
+
+
+    private boolean handleProjectChange(IResource editorFile, IProject project, int kind,
int flags) throws CoreException
+    {
+        if ( !editorFile.getProject().equals( project ) )
+        {
+            return false;
+        }
+        if ( kind == IResourceDelta.CHANGED && ( flags & IResourceDelta.MARKERS
) > 0 )
+        {
+            loadUnresolvedDependencies();
+            refreshAllPages();
+        }
+        return true;
+    }
+
+
     protected void refreshAllPages()
     {
         Runnable op = new Runnable()
@@ -319,7 +356,7 @@
                     }
                 }
                 firePropertyChange( IEditorPart.PROP_DIRTY );
-                setPartName( projectx.getSymbolicName() );
+                setPartName( project.getSymbolicName() );
                 refreshTabImages();
             }
         };
@@ -327,9 +364,9 @@
     }
 
 
-    protected void reload()
+    private void reload()
     {
-        projectx.setBundle( null );
+        project.setBundle( null );
         refreshAllPages();
     }
 
@@ -341,15 +378,15 @@
 
         try
         {
-            this.projectx = SigilCore.create( getProject() );
-            this.tempProject = (ISigilProjectModel) projectx.clone();
+            this.project = SigilCore.create( getProject() );
+            this.tempProject = (ISigilProjectModel) project.clone();
         }
         catch ( CoreException e )
         {
             throw new PartInitException( "Error creating Sigil project", e );
         }
 
-        ResourcesPlugin.getWorkspace().addResourceChangeListener( this, IResourceChangeEvent.POST_CHANGE
);
+        ResourcesPlugin.getWorkspace().addResourceChangeListener( this, IResourceChangeEvent.POST_CHANGE
| IResourceChangeEvent.PRE_REFRESH );
 
         if ( input instanceof IFileEditorInput )
         {



Mime
View raw message