org.eclipse.jdt.internal.core.SetContainerOperation Maven / Gradle / Ivy
/*******************************************************************************
* Copyright (c) 2000, 2010 IBM Corporation and others.
* 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.internal.core;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.util.Util;
public class SetContainerOperation extends ChangeClasspathOperation {
IPath containerPath;
IJavaProject[] affectedProjects;
IClasspathContainer[] respectiveContainers;
/*
* Creates a new SetContainerOperation.
*/
public SetContainerOperation(IPath containerPath, IJavaProject[] affectedProjects, IClasspathContainer[] respectiveContainers) {
super(new IJavaElement[] {JavaModelManager.getJavaModelManager().getJavaModel()}, !ResourcesPlugin.getWorkspace().isTreeLocked());
this.containerPath = containerPath;
this.affectedProjects = affectedProjects;
this.respectiveContainers = respectiveContainers;
}
protected void executeOperation() throws JavaModelException {
checkCanceled();
try {
beginTask("", 1); //$NON-NLS-1$
if (JavaModelManager.CP_RESOLVE_VERBOSE)
verbose_set_container();
if (JavaModelManager.CP_RESOLVE_VERBOSE_ADVANCED)
verbose_set_container_invocation_trace();
JavaModelManager manager = JavaModelManager.getJavaModelManager();
if (manager.containerPutIfInitializingWithSameEntries(this.containerPath, this.affectedProjects, this.respectiveContainers))
return;
final int projectLength = this.affectedProjects.length;
final IJavaProject[] modifiedProjects;
System.arraycopy(this.affectedProjects, 0, modifiedProjects = new IJavaProject[projectLength], 0, projectLength);
// filter out unmodified project containers
int remaining = 0;
for (int i = 0; i < projectLength; i++){
if (isCanceled())
return;
JavaProject affectedProject = (JavaProject) this.affectedProjects[i];
IClasspathContainer newContainer = this.respectiveContainers[i];
if (newContainer == null) newContainer = JavaModelManager.CONTAINER_INITIALIZATION_IN_PROGRESS; // 30920 - prevent infinite loop
boolean found = false;
if (JavaProject.hasJavaNature(affectedProject.getProject())){
IClasspathEntry[] rawClasspath = affectedProject.getRawClasspath();
for (int j = 0, cpLength = rawClasspath.length; j "); //$NON-NLS-1$
return buffer.toString();
}
IClasspathContainer container = (IClasspathContainer) o;
buffer.append(container.getDescription());
buffer.append(" {\n"); //$NON-NLS-1$
IClasspathEntry[] entries = container.getClasspathEntries();
if (entries != null){
for (int i = 0; i < entries.length; i++){
buffer.append(" "); //$NON-NLS-1$
buffer.append(entries[i]);
buffer.append('\n');
}
}
buffer.append(" }"); //$NON-NLS-1$
return buffer.toString();
}
}) +
"\n }");//$NON-NLS-1$
}
private void verbose_set_container_invocation_trace() {
Util.verbose(
"CPContainer SET - setting container\n" + //$NON-NLS-1$
" invocation stack trace:"); //$NON-NLS-1$
new Exception("").printStackTrace(System.out); //$NON-NLS-1$
}
}