You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2009/10/06 04:12:38 UTC

svn commit: r822107 - /labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java

Author: simoneg
Date: Tue Oct  6 02:12:38 2009
New Revision: 822107

URL: http://svn.apache.org/viewvc?rev=822107&view=rev
Log:
LABS-410 : maven dependency container both on inpath and aspectpath with restrictions.

Modified:
    labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java

Modified: labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java?rev=822107&r1=822106&r2=822107&view=diff
==============================================================================
--- labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java (original)
+++ labs/magma/trunk/magma-eclipse/src/org/apache/magma/tools/magmaeclipse/basics/MagmaPDEUtils.java Tue Oct  6 02:12:38 2009
@@ -15,6 +15,7 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.embedder.MavenEmbedder;
 import org.apache.maven.project.MavenProject;
+import org.eclipse.ajdt.core.AspectJCorePreferences;
 import org.eclipse.ajdt.internal.ui.lazystart.Utils;
 import org.eclipse.ajdt.internal.ui.preferences.AJCompilerPreferencePage;
 import org.eclipse.ajdt.internal.ui.preferences.AspectJPreferences;
@@ -37,6 +38,7 @@
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jdt.core.IClasspathAttribute;
 import org.eclipse.jdt.core.IClasspathEntry;
 import org.eclipse.jdt.core.IJavaProject;
 import org.eclipse.jdt.core.JavaCore;
@@ -528,7 +530,9 @@
 					existing.add(entpath);
 				}
 			}
-	
+
+			String restrictions = "";
+			
 			// Create a folder for unzipped sources
 			File localrepo = MavenPlugin.getDefault().getMavenEmbedderManager()
 					.getLocalRepositoryDir();
@@ -552,7 +556,12 @@
 			List<IClasspathEntry> linkstoadd = new ArrayList<IClasspathEntry>();
 
 			for (Artifact art : artifactMap.values()) {
-				if (art.getGroupId().startsWith("org.apache.magma")) {
+				IMavenProjectFacade artmvnprj = MavenPlugin.getDefault().getMavenProjectManager().getMavenProject(art.getGroupId(), art.getArtifactId(), art.getVersion());
+				if (artmvnprj != null) {
+					// Dependency is in the workspace
+					IProject artprj = artmvnprj.getProject();
+					restrictions += artprj.getName() + ",";
+				} else if (art.getGroupId().startsWith("org.apache.magma")) {
 					String depname = art.getArtifactId() + "-" + art.getVersion();
 					
 					if (prog != null)
@@ -630,7 +639,7 @@
 						downloadSources(project, project.getFullPath(), art.getGroupId(), art.getArtifactId(), art.getBaseVersion(), art.getClassifier(), true, true);
 						*/
 					}
-				}				
+				}
 			}
 			
 			// Adjust the project classpath
@@ -650,8 +659,22 @@
 							continue;
 						}
 					} else {
-						// bypass all the rest
-						nrawClasspath[j++] = rawClasspath[i];
+						boolean bypass = true;
+						// We have dependency projects to weave
+						if (restrictions.length() > 0) {
+							while (restrictions.endsWith(",")) restrictions = restrictions.substring(0, restrictions.length() - 1);
+							// Check if this is the Maven container
+							if (rawClasspath[i].getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
+								if (entpath.equals("org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER")) {
+									nrawClasspath[j++] = aspectJEnabledMavenContainer(rawClasspath[i], restrictions);
+									bypass = false;
+								}
+							}
+						}
+						if (bypass) {
+							// bypass all the rest
+							nrawClasspath[j++] = rawClasspath[i];
+						}
 					}
 				}
 				// Add newly created magmalnk- folders or those not on the classpath
@@ -706,6 +729,32 @@
 	}
 
 
+	private static IClasspathEntry aspectJEnabledMavenContainer(IClasspathEntry maventry, String restrictions) {
+		String prevrest = AspectJCorePreferences.getRestriction(maventry, AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME);
+		if (prevrest == null || !prevrest.equals(restrictions)) {
+			List<IClasspathAttribute> attrs = new ArrayList<IClasspathAttribute>(Arrays.asList(maventry.getExtraAttributes()));
+			for (Iterator<IClasspathAttribute> iterator = attrs.iterator(); iterator.hasNext();) {
+				IClasspathAttribute attr = iterator.next();
+				if (
+						attr.getName().equals(AspectJCorePreferences.ASPECTPATH_ATTRIBUTE_NAME) ||
+						attr.getName().equals(AspectJCorePreferences.INPATH_ATTRIBUTE_NAME) ||
+						attr.getName().equals(AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME) ||
+						attr.getName().equals(AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME)) 
+					iterator.remove();
+			}
+			attrs.add(AspectJCorePreferences.ASPECTPATH_ATTRIBUTE);
+			attrs.add(AspectJCorePreferences.INPATH_ATTRIBUTE);
+			attrs.add(JavaCore.newClasspathAttribute(AspectJCorePreferences.ASPECTPATH_RESTRICTION_ATTRIBUTE_NAME, restrictions));
+			attrs.add(JavaCore.newClasspathAttribute(AspectJCorePreferences.INPATH_RESTRICTION_ATTRIBUTE_NAME, restrictions));
+			
+			return JavaCore.newContainerEntry(maventry.getPath(),
+                    maventry.getAccessRules(), attrs.toArray(new IClasspathAttribute[attrs.size()]), 
+                    maventry.isExported());			
+		} else {
+			return maventry;
+		}
+	}
+
 	/**
 	 * Adds a single entry, as the first one, to a classpath array.
 	 * @param prj The project



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org