Index: D:/EWA_02/m2e_trunk/src/org/maven/ide/eclipse/embedder/BuildPathManager.java =================================================================== --- D:/EWA_02/m2e_trunk/src/org/maven/ide/eclipse/embedder/BuildPathManager.java (revision 305) +++ D:/EWA_02/m2e_trunk/src/org/maven/ide/eclipse/embedder/BuildPathManager.java (working copy) @@ -59,6 +59,7 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; @@ -91,6 +92,10 @@ public class BuildPathManager { + + public static final String CLASSPATH_COMPONENT_NON_DEPENDENCY = "org.eclipse.jst.component.nondependency"; + public static final String PACKAGING_WAR = "war"; + private final MavenEmbedderManager embedderManager; private final Maven2Console console; @@ -228,7 +233,6 @@ boolean downloadSources = !offline & preferenceStore.getBoolean(Maven2PreferenceConstants.P_DOWNLOAD_SOURCES); boolean downloadJavadoc = !offline & preferenceStore.getBoolean(Maven2PreferenceConstants.P_DOWNLOAD_JAVADOC); boolean debug = preferenceStore.getBoolean(Maven2PreferenceConstants.P_DEBUG_OUTPUT); - MavenExecutionResult result = mavenModelManager.readMavenProject(pomFile, monitor, offline, debug, resolverConfiguration); MavenProject mavenProject = getMavenProject(pomFile, result); @@ -243,6 +247,15 @@ moduleArtifacts.put(mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(), mavenProject.getArtifact()); + // If the current project is a WAR project AND it has + // a dynamic web project nature, make sure that any workspace + // projects that it depends on are NOT included in any way + // in the container (neither as projects nor as artifacts). + // The idea is that the inclusion is controlled explicitly + // by a developer via WTP UI. + boolean skipWorkspaceProjectsForWeb = PACKAGING_WAR.equals(mavenProject.getPackaging()) + && hasDynamicWebProjectNature(currentProject); + Set artifacts = mavenProject.getArtifacts(); for(Iterator it = artifacts.iterator(); it.hasNext();) { if(monitor.isCanceled()) { @@ -267,9 +280,18 @@ moduleArtifacts.put(artifactKey, a); + List attributes = new ArrayList(); + mavenModelManager.addProjectArtifact(pomFile, a); // this is needed to projects with have modules (either inner or external) mavenModelManager.addProjectArtifact(rootPomFile, a); + // Check the scope & set WTP non-dependency as appropriate + String scope = a.getScope(); + if (Artifact.SCOPE_PROVIDED.equals(scope) + || Artifact.SCOPE_TEST.equals(scope) + || Artifact.SCOPE_SYSTEM.equals(scope)) { + attributes.add(JavaCore.newClasspathAttribute(CLASSPATH_COMPONENT_NON_DEPENDENCY, "")); + } IFile artifactPomFile = mavenModelManager.getArtifactFile(a); if(artifactPomFile != null) { @@ -279,6 +301,11 @@ // add our own project to ourself continue; } + + if (skipWorkspaceProjectsForWeb) { + // Leave it out so that the user can handle it the WTP way + continue; + } } if(resolverConfiguration.shouldResolveWorkspaceProjects()) { @@ -298,7 +325,6 @@ String artifactLocation = a.getFile().getAbsolutePath(); - ArrayList attributes = new ArrayList(); attributes.add(JavaCore.newClasspathAttribute(Maven2Plugin.GROUP_ID_ATTRIBUTE, a.getGroupId())); attributes.add(JavaCore.newClasspathAttribute(Maven2Plugin.ARTIFACT_ID_ATTRIBUTE, a.getArtifactId())); attributes.add(JavaCore.newClasspathAttribute(Maven2Plugin.VERSION_ATTRIBUTE, a.getVersion())); @@ -320,7 +346,7 @@ entries.add(JavaCore.newLibraryEntry(new Path(artifactLocation), // srcPath, null, new IAccessRule[0], // - (IClasspathAttribute[]) attributes.toArray(new IClasspathAttribute[attributes.size()]), // + (IClasspathAttribute[]) attributes.toArray(new IClasspathAttribute[attributes.size()]), // false /*not exported*/)); } @@ -336,7 +362,7 @@ String module = (String) it.next(); IResource memberPom = basedir.findMember(module + "/" + Maven2Plugin.POM_FILE_NAME); //$NON-NLS-1$ if(memberPom != null && memberPom.getType() == IResource.FILE) { - resolveClasspathEntries(entries, moduleArtifacts, // + resolveClasspathEntries(entries, moduleArtifacts, // rootPomFile, (IFile) memberPom, resolverConfiguration, monitor); } } @@ -529,7 +555,7 @@ IClasspathEntry[] currentClasspath = javaProject.getRawClasspath(); for(int i = 0; i < currentClasspath.length; i++ ) { - // Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 + // Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 IClasspathEntry entry = currentClasspath[i]; if(entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if(!JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) { @@ -1041,4 +1067,16 @@ buildpathManager.updateClasspathContainer(project, monitor); } + private boolean hasDynamicWebProjectNature(IProject project) { + try { + IProjectNature nature1 = project.getNature("org.eclipse.wst.common.modulecore.ModuleCoreNature"); + IProjectNature nature2 = project.getNature("org.eclipse.wst.common.project.facet.core.nature"); + if (nature1 != null && nature2 != null) { + return true; + } + } catch (Exception e) { + console.logError("Unable to inspect nature: " + e); + } + return false; + } }