Java Code Examples for org.eclipse.jdt.core.JavaCore#setClasspathContainer()

The following examples show how to use org.eclipse.jdt.core.JavaCore#setClasspathContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SourceAttacherJob.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@Override
protected IStatus run(IProgressMonitor monitor) {
  Preconditions.checkState(getRule() != null);
  try {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, javaProject);
    LibraryClasspathContainer newContainer = attachSource(container);

    if (newContainer != null) {
      JavaCore.setClasspathContainer(containerPath, new IJavaProject[]{ javaProject },
          new IClasspathContainer[]{ newContainer }, monitor);
      serializer.saveContainer(javaProject, newContainer);
    }
  } catch (Exception ex) {
    // it's not needed to be logged normally
    logger.log(Level.FINE, Messages.getString("SourceAttachmentFailed"), ex);
  }
  return Status.OK_STATUS;  // even if it fails, we should not display an error to the user
}
 
Example 2
Source File: SdkClasspathContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void initialize(IPath containerPath, final IJavaProject javaProject)
    throws CoreException {
  SdkClasspathContainer<T> sdkClasspathContainer = null;
  final T sdk = resolveSdkFromContainerPath(containerPath, javaProject);
  if (sdk != null) {
    String description = getDescription(containerPath, javaProject);
    sdkClasspathContainer = createClasspathContainer(containerPath, sdk,
        description, javaProject);
  }

  // Container will be set to null if it could not be resolved which will
  // result in a classpath error for the project.
  JavaCore.setClasspathContainer(containerPath,
      new IJavaProject[] {javaProject},
      new IClasspathContainer[] {sdkClasspathContainer}, null);
}
 
Example 3
Source File: SdkClasspathContainerInitializer.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(IPath containerPath,
    IJavaProject project, IClasspathContainer containerSuggestion)
    throws CoreException {

  SdkClasspathContainer<T> sdkClasspathContainer = null;
  T sdk = resolveSdkFromContainerPath(containerPath, project);
  if (sdk != null) {
    String description = getDescription(containerPath, project);
    sdkClasspathContainer = updateClasspathContainer(containerPath, sdk,
        description, project, containerSuggestion);
  }

  // Container will be set to null if it could not be resolved which will
  // result in a classpath error for the project.
  JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project},
      new IClasspathContainer[] {sdkClasspathContainer}, null);
}
 
Example 4
Source File: SARLClasspathContainerInitializer.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(
		final IPath containerPath,
		final IJavaProject javaProject,
		final IClasspathContainer containerSuggestion) throws CoreException {
	if (containerSuggestion instanceof SARLClasspathContainer) {
		((SARLClasspathContainer) containerSuggestion).reset();
	}
	super.requestClasspathContainerUpdate(containerPath, javaProject, containerSuggestion);
	final Job job = new Job(Messages.SARLClasspathContainerInitializer_0) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				JavaCore.setClasspathContainer(
						containerPath,
						new IJavaProject[] {javaProject},
						new IClasspathContainer[] {containerSuggestion},
						monitor);
			} catch (CoreException ex) {
				return SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, ex);
			}
			return SARLEclipsePlugin.getDefault().createOkStatus();
		}
	};
	job.schedule();
}
 
Example 5
Source File: JanusClasspathContainerInitializer.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void requestClasspathContainerUpdate(
		final IPath containerPath,
		final IJavaProject javaProject,
		final IClasspathContainer containerSuggestion) throws CoreException {
	if (containerSuggestion instanceof JanusClasspathContainer) {
		((JanusClasspathContainer) containerSuggestion).reset();
	}
	super.requestClasspathContainerUpdate(containerPath, javaProject, containerSuggestion);
	final Job job = new Job(Messages.JanusClasspathContainerInitializer_0) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				JavaCore.setClasspathContainer(
						containerPath,
						new IJavaProject[] {javaProject},
						new IClasspathContainer[] {containerSuggestion},
						monitor);
			} catch (CoreException ex) {
				return JanusEclipsePlugin.getDefault().createStatus(IStatus.ERROR, ex);
			}
			return JanusEclipsePlugin.getDefault().createOkStatus();
		}
	};
	job.schedule();
}
 
Example 6
Source File: XtendContainerInitializer.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialize(final IPath containerPath, final IJavaProject project) throws CoreException {
	if (isXtendPath(containerPath)) {
		IClasspathContainer container = new XtendClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
				new IClasspathContainer[] { container }, null);
	}
}
 
Example 7
Source File: RuntimeLibraryContainerInitializer.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (!LIBRARY_PATH.equals(containerPath)) {
		return;
	}

	IClasspathContainer container = new RuntimeLibraryContainer(
			containerPath);
	JavaCore.setClasspathContainer(containerPath,
			new IJavaProject[] { project },
			new IClasspathContainer[] { container }, null);
}
 
Example 8
Source File: UserLibraryClasspathContainerInitializer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
	if (isUserLibraryContainer(containerPath)) {
		String userLibName = containerPath.segment(1);
		UserLibrary userLibrary = JavaModelManager.getUserLibraryManager().getUserLibrary(userLibName);
		if (userLibrary != null) {
			UserLibraryClasspathContainer container = new UserLibraryClasspathContainer(userLibName);
			JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null);
		} else if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
			verbose_no_user_library_found(project, userLibName);
		}
	} else if (JavaModelManager.CP_RESOLVE_VERBOSE || JavaModelManager.CP_RESOLVE_VERBOSE_FAILURE) {
		verbose_not_a_user_library(project, containerPath);
	}
}
 
Example 9
Source File: SARLClasspathContainerInitializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (CONTAINER_ID.equals(containerPath)) {
		final IClasspathContainer container = new SARLClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath,
				new IJavaProject[] {project},
				new IClasspathContainer[] {container},
				null);
	}
}
 
Example 10
Source File: JanusClasspathContainerInitializer.java    From sarl with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
		throws CoreException {
	if (CONTAINER_ID.equals(containerPath)) {
		final IClasspathContainer container = new JanusClasspathContainer(containerPath);
		JavaCore.setClasspathContainer(containerPath,
				new IJavaProject[] {project},
				new IClasspathContainer[] {container},
				null);
	}
}
 
Example 11
Source File: DerbyClasspathContainerInitializer.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
    throws CoreException {
    IClasspathContainer container = new DerbyClasspathContainer();
    JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}, null);
}
 
Example 12
Source File: LibraryClasspathContainerResolverService.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Override
public IStatus resolveContainer(
    IJavaProject javaProject, IPath containerPath, IProgressMonitor monitor) {

  Preconditions.checkArgument(
      containerPath.segment(0).equals(LibraryClasspathContainer.CONTAINER_PATH_PREFIX));
  ISchedulingRule currentRule = Job.getJobManager().currentRule();
  Preconditions.checkState(
      currentRule == null || currentRule.contains(getSchedulingRule()),
      "current scheduling rule is insufficient");

  SubMonitor subMonitor = SubMonitor.convert(monitor, 19);

  try {
    String libraryId = containerPath.segment(1);
    Library library = null;
    if (CloudLibraries.MASTER_CONTAINER_ID.equals(libraryId)) {
      List<String> referencedIds = serializer.loadLibraryIds(javaProject);
      List<Library> referencedLibraries = new ArrayList<>();
      for (String referencedId : referencedIds) {
        Library referencedLibrary = CloudLibraries.getLibrary(referencedId);
        if (referencedLibrary != null) {
          referencedLibraries.add(referencedLibrary);
        } else {
          // todo this might deserve a non-OK status
          logger.severe("Referenced library not found: " + referencedId);
        }
      }
      library =
          BuildPath.collectLibraryFiles(javaProject, referencedLibraries, subMonitor.newChild(9));
    } else {
      library = CloudLibraries.getLibrary(libraryId);
    }
    if (library != null) {
      List<Job> sourceAttacherJobs = new ArrayList<>();
      LibraryClasspathContainer container =
          resolveLibraryFiles(
              javaProject, containerPath, library, sourceAttacherJobs, subMonitor.newChild(9));
      JavaCore.setClasspathContainer(
          containerPath,
          new IJavaProject[] {javaProject},
          new IClasspathContainer[] {container},
          subMonitor.newChild(1));
      serializer.saveContainer(javaProject, container);
      for (Job job : sourceAttacherJobs) {
        job.schedule();
      }
    }
    return Status.OK_STATUS;
  } catch (CoreException | IOException ex) {
    return StatusUtil.error(
        this, Messages.getString("TaskResolveContainerError", containerPath), ex);
  }
}
 
Example 13
Source File: LibraryClasspathContainerInitializer.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
  if (containerPath.segmentCount() != 2) {
    throw new CoreException(
        StatusUtil.error(
            this, "containerPath does not have exactly 2 segments: " + containerPath.toString()));
  }
  if (!containerPath.segment(0).equals(containerPathPrefix)) {
    throw new CoreException(
        StatusUtil.error(
            this,
            MessageFormat.format(
                "Unexpected first segment of container path, " + "expected: {0} was: {1}",
                containerPathPrefix, containerPath.segment(0))));
  }
  try {
    LibraryClasspathContainer container = serializer.loadContainer(project, containerPath);
    if (container != null && jarPathsAreValid(container)) {
      JavaCore.setClasspathContainer(
          containerPath,
          new IJavaProject[] {project},
          new IClasspathContainer[] {container},
          new NullProgressMonitor());
      return;
    }
    /* Container definition is not resolved, so set an empty container (an
     * IClasspathContainerInitializer *must* set a corresponding container) and initiate
     * a container resolving job. */
    JavaCore.setClasspathContainer(
        containerPath,
        new IJavaProject[] {project},
        new IClasspathContainer[] {
          new LibraryClasspathContainer(
              containerPath, "in progress", Collections.emptyList(), Collections.emptyList())
        },
        new NullProgressMonitor());
    requestClasspathContainerUpdate(containerPath, project, container);
  } catch (IOException ex) {
    throw new CoreException(
        StatusUtil.error(this, "Failed to load persisted container descriptor", ex));
  }
}
 
Example 14
Source File: DerbyClasspathContainerInitializer.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project)
    throws CoreException {
    IClasspathContainer container = new DerbyClasspathContainer();
    JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}, null);
}
 
Example 15
Source File: UserDependenciesClasspathContainerInitializer.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
	if(containerPath.equals(CONTAINER_ID)){
		JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {new UserDependenciesContainer(containerPath, project)}, null);
	}
}