* @param monitor
* @throws CoreException
*/
private void setModuleDependencies(IProject project, MavenProject mavenProject, IProgressMonitor monitor) throws CoreException {
IVirtualComponent warComponent = ComponentCore.createComponent(project);
if (warComponent == null) {
return;
}
Set<IVirtualReference> newOverlayRefs = new LinkedHashSet<IVirtualReference>();
MavenSessionHelper helper = new MavenSessionHelper(mavenProject);
try {
helper.ensureDependenciesAreResolved("maven-war-plugin", "war:war"); //$NON-NLS-1$ //$NON-NLS-2$
MavenPlugin.getMaven();
WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
List<Overlay> overlays = config.getOverlays();
//1 overlay = current project => no overlay component needed
if (overlays.size() > 1) {
//Component order must be inverted to follow maven's overlay order behaviour
//as in WTP, last components supersede the previous ones
Collections.reverse(overlays);
for(Overlay overlay : overlays) {
if (overlay.shouldSkip()) {
continue;
}
Artifact artifact = overlay.getArtifact();
IOverlayVirtualComponent overlayComponent = null;
IMavenProjectFacade workspaceDependency = projectManager.getMavenProject(
artifact.getGroupId(),
artifact.getArtifactId(),
artifact.getVersion());
if(workspaceDependency != null) {
//artifact dependency is a workspace project && dependency resolution is on
IProject overlayProject = workspaceDependency.getProject();
if (overlayProject.equals(project)) {
overlayComponent = OverlayComponentCore.createSelfOverlayComponent(project);
} else if (workspaceDependency.getFullPath(artifact.getFile()) != null){
overlayComponent = OverlayComponentCore.createOverlayComponent(overlayProject);
} else {
//Dependency resolution is off
overlayComponent = createOverlayArchiveComponent(project, mavenProject, overlay);
}
} else {
overlayComponent = createOverlayArchiveComponent(project, mavenProject, overlay);
}
if (overlayComponent != null) {
overlayComponent.setInclusions(new LinkedHashSet<String>(Arrays.asList(overlay.getIncludes())));
overlayComponent.setExclusions(new LinkedHashSet<String>(Arrays.asList(overlay.getExcludes())));
IVirtualReference depRef = ComponentCore.createReference(warComponent, overlayComponent);
String targetPath = StringUtils.nullOrEmpty(overlay.getTargetPath())?"/":overlay.getTargetPath(); //$NON-NLS-1$
depRef.setRuntimePath(new Path(targetPath));
newOverlayRefs.add(depRef);
}
}
}
IVirtualReference[] oldOverlayRefs = WTPProjectsUtil.extractHardReferences(warComponent, true);
IVirtualReference[] updatedOverlayRefs = newOverlayRefs.toArray(new IVirtualReference[newOverlayRefs.size()]);
if (WTPProjectsUtil.hasChanged2(oldOverlayRefs, updatedOverlayRefs)){
//Only write in the .component file if necessary
IVirtualReference[] nonOverlayRefs = WTPProjectsUtil.extractHardReferences(warComponent, false);
IVirtualReference[] allRefs = new IVirtualReference[nonOverlayRefs.length + updatedOverlayRefs.length];
System.arraycopy(nonOverlayRefs, 0, allRefs, 0, nonOverlayRefs.length);
System.arraycopy(updatedOverlayRefs, 0, allRefs, nonOverlayRefs.length, updatedOverlayRefs.length);
warComponent.setReferences(allRefs);
}
} finally {
helper.dispose();
}