[149858] Problems exporting Web App Libraries
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/ClasspathUtil.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/ClasspathUtil.java
new file mode 100644
index 0000000..2a83554
--- /dev/null
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/ClasspathUtil.java
@@ -0,0 +1,110 @@
+/******************************************************************************
+ * Copyright (c) 2006 BEA Systems, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *    Konstantin Komissarchik - initial API and implementation
+ ******************************************************************************/
+
+package org.eclipse.jst.common.jdt.internal.classpath;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IClasspathContainer;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jem.util.logger.proxy.Logger;
+
+/**
+ * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a>
+ */
+
+public final class ClasspathUtil
+{
+    private ClasspathUtil() {}
+    
+    public static Set getResolvedClasspath( final IJavaProject jproj,
+                                            final IPath entryToIgnore )
+    {
+        return getResolvedClasspath( jproj, Collections.singleton( entryToIgnore ) );
+    }
+    
+    public static Set getResolvedClasspath( final IJavaProject jproj,
+                                            final Set entriesToIgnore )
+    {
+        final Set resolved = new HashSet();
+        
+        try 
+        {
+            final IClasspathEntry[] entries = jproj.getRawClasspath();
+            
+            for( int i = 0; i < entries.length; i++ )
+            {
+                IClasspathEntry entry = entries[ i ];
+                
+                if( entriesToIgnore.contains( entry.getPath() ) )
+                {
+                    continue;
+                }
+                
+                switch( entry.getEntryKind() )
+                {
+                    case IClasspathEntry.CPE_LIBRARY:
+                    case IClasspathEntry.CPE_PROJECT:
+                    {
+                        resolved.add( entry.getPath() );
+                        break;
+                    }
+                    case IClasspathEntry.CPE_VARIABLE:
+                    {
+                        entry = JavaCore.getResolvedClasspathEntry( entry );
+                        
+                        if( entry != null )
+                        {
+                            resolved.add( entry.getPath() );
+                        }
+                        
+                        break;
+                    }
+                    case IClasspathEntry.CPE_CONTAINER:
+                    {
+                        final IClasspathContainer container;
+                        
+                        try
+                        {
+                            container = JavaCore.getClasspathContainer( entry.getPath(), jproj );
+                        }
+                        catch( JavaModelException e )
+                        {
+                            Logger.getLogger().logError( e );
+                            continue;
+                        }
+                        
+                        final IClasspathEntry[] containerEntries
+                            = container.getClasspathEntries();
+
+                        for( int j = 0; j < containerEntries.length; j++ )
+                        {
+                            resolved.add( containerEntries[ j ].getPath() );
+                        }
+                    }
+                }
+            }
+        } 
+        catch( JavaModelException e ) 
+        {
+            Logger.getLogger().logError( e );
+        }
+        
+        return resolved;
+    }
+
+}
diff --git a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/FlexibleProjectContainer.java b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/FlexibleProjectContainer.java
index ad9a82d..6ad8658 100644
--- a/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/FlexibleProjectContainer.java
+++ b/plugins/org.eclipse.jst.common.frameworks/src/org/eclipse/jst/common/jdt/internal/classpath/FlexibleProjectContainer.java
@@ -13,10 +13,8 @@
 
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -39,10 +37,6 @@
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
 import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.internal.core.ClasspathEntry;
-import org.eclipse.jdt.internal.core.JavaProject;
-import org.eclipse.jdt.internal.core.util.Util;
-import org.eclipse.jem.util.logger.proxy.Logger;
 import org.eclipse.jst.common.frameworks.CommonFrameworksPlugin;
 import org.eclipse.wst.common.componentcore.ComponentCore;
 import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent;
@@ -183,7 +177,10 @@
             return entries;
         }
         
-        final Set existingEntries = computeExistingClasspathEntries();
+        final IJavaProject jproject = JavaCore.create( this.project );
+        
+        final Set existingEntries 
+            = ClasspathUtil.getResolvedClasspath( jproject, getPath() );
         
         IVirtualReference[] refs = vc.getReferences();
         IVirtualComponent comp = null;
@@ -214,10 +211,10 @@
                 newPath = project.getFullPath();    
             }
             
-        	if(null != newPath && !isAlreadyOnClasspath(existingEntries, newPath)){
-                entries.add(newPath);
+        	if( newPath != null && ! existingEntries.contains( newPath ) )
+            {
+                entries.add( newPath );
         	}
-
         }
         
         for( int i = 0; i < this.paths.length; i++ )
@@ -247,7 +244,9 @@
                     if(!jarsHandled.contains(p.lastSegment()) &&  isJarFile( r.getLocation().toFile() ) )
                     {
                         jarsHandled.add(p.lastSegment());
-                        if(!isAlreadyOnClasspath(existingEntries, p)){
+                        
+                        if( ! existingEntries.contains( p ) )
+                        {
                         	entries.add( p );
                         }
                     }
@@ -265,7 +264,9 @@
                         ! isSourceOrOutputDirectory( p ) )
                     {
                         jarsHandled.add(p.lastSegment());
-                        if(!isAlreadyOnClasspath(existingEntries, p)){
+                        
+                        if( ! existingEntries.contains( p ) )
+                        {
                         	entries.add( p );
                         }
                     }
@@ -276,49 +277,6 @@
         return entries;
     }
     
-    private Set computeExistingClasspathEntries()
-    {
-        final IJavaProject jproj = JavaCore.create( this.project );
-        final Set existing = new HashSet();
-        
-        try 
-        {
-            // Get all resolved entries first.
-            
-            final IClasspathEntry[] entries = jproj.getResolvedClasspath( true );
-            existing.addAll( Arrays.asList( entries ) );
-            
-            // Then remove any entries provided by this container's prior self.
-            
-            final IClasspathEntry[] cp = jproj.getRawClasspath();
-            
-            for( int i = 0; i < cp.length; i++ )
-            {
-                final IPath path = cp[ i ].getPath();
-                
-                if( path.equals( this.path ) )
-                {
-                    final IClasspathContainer container
-                        = JavaCore.getClasspathContainer( path, jproj );
-                    if(null != container){
-	                    final IClasspathEntry[] containerEntries
-	                        = container.getClasspathEntries();
-	                    
-	                    existing.removeAll( Arrays.asList( containerEntries ) );
-                    
-	                    break;
-                    }
-                }
-            }
-        } 
-        catch( JavaModelException e ) 
-        {
-            Logger.getLogger().logError( e );
-        }
-        
-        return existing;
-    }
-    
     private IClasspathEntry newLibraryEntry( final IPath p )
     {
         IPath srcpath = null;
@@ -420,30 +378,6 @@
         return false;
     }
     
-    /**
-	 * Taken from {@link JavaProject#isOnClasspath(org.eclipse.core.resources.IResource)}
-	 * 
-	 * @param classpath
-	 * @param newPath
-	 * @return
-	 */
-	private static boolean isAlreadyOnClasspath(Set classpath, IPath newPath) 
-    {
-		for( Iterator itr = classpath.iterator(); itr.hasNext(); ) 
-        {
-			IClasspathEntry entry = (IClasspathEntry) itr.next();
-			IPath entryPath = entry.getPath();
-			if (entryPath.equals(newPath)) { // package fragment roots must match exactly entry
-				// pathes (no exclusion there)
-				return true;
-			}
-			if (entryPath.isPrefixOf(newPath) && !Util.isExcluded(newPath, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars(), false)) {
-				return true;
-			}
-		}
-		return false;
-	}
-    
     private static class Listener
     
         implements IResourceChangeListener