Java 类org.eclipse.jdt.core.ClasspathContainerInitializer 实例源码

项目:che    文件:ReorgCorrectionsSubProcessor.java   
private static boolean canModifyAccessRules(IBinding binding) {
  IJavaElement element = binding.getJavaElement();
  if (element == null) return false;

  IPackageFragmentRoot root = JavaModelUtil.getPackageFragmentRoot(element);
  if (root == null) return false;

  try {
    IClasspathEntry classpathEntry = root.getRawClasspathEntry();
    if (classpathEntry == null) return false;
    if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) return true;
    if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
      ClasspathContainerInitializer classpathContainerInitializer =
          JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
      IStatus status =
          classpathContainerInitializer.getAccessRulesStatus(
              classpathEntry.getPath(), root.getJavaProject());
      return status.isOK();
    }
  } catch (JavaModelException e) {
    return false;
  }
  return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:ReorgCorrectionsSubProcessor.java   
private static boolean canModifyAccessRules(IBinding binding) {
    IJavaElement element= binding.getJavaElement();
    if (element == null)
        return false;

    IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
    if (root == null)
        return false;

    try {
        IClasspathEntry classpathEntry= root.getRawClasspathEntry();
        if (classpathEntry == null)
            return false;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
            return true;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
            IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
            return status.isOK();
        }
    } catch (JavaModelException e) {
        return false;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocConfigurationPropertyPage.java   
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    if (initializer == null || container == null) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
        return null;
    }
    String containerName= container.getDescription();
    IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName));
        return null;
    }
    IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName));
        fIsReadOnly= true;
        return entry;
    }
    Assert.isNotNull(entry);
    setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description);
    return entry;
}
项目:Eclipse-Postfix-Code-Completion    文件:NativeLibrariesPropertyPage.java   
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    if (initializer == null || container == null) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
        return null;
    }
    String containerName= container.getDescription();
    IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
        return null;
    }
    IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
        fIsReadOnly= true;
        return entry;
    }
    Assert.isNotNull(entry);
    return entry;
}
项目:Eclipse-Postfix-Code-Completion    文件:CPListElement.java   
private IStatus evaluateContainerChildStatus(CPListElementAttribute attrib) {
    if (fProject != null) {
        ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(fPath.segment(0));
        if (initializer != null && initializer.canUpdateClasspathContainer(fPath, fProject)) {
            if (attrib.isBuiltIn()) {
                if (CPListElement.SOURCEATTACHMENT.equals(attrib.getKey())) {
                    return initializer.getSourceAttachmentStatus(fPath, fProject);
                } else if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
                    return initializer.getAccessRulesStatus(fPath, fProject);
                }
            } else {
                return initializer.getAttributeStatus(fPath, fProject, attrib.getKey());
            }
        }
        return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY, "", null); //$NON-NLS-1$
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ReorgCorrectionsSubProcessor.java   
private static boolean canModifyAccessRules(IBinding binding) {
    IJavaElement element= binding.getJavaElement();
    if (element == null)
        return false;

    IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element);
    if (root == null)
        return false;

    try {
        IClasspathEntry classpathEntry= root.getRawClasspathEntry();
        if (classpathEntry == null)
            return false;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY)
            return true;
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0));
            IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject());
            return status.isOK();
        }
    } catch (JavaModelException e) {
        return false;
    }
    return false;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocConfigurationPropertyPage.java   
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    if (initializer == null || container == null) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
        return null;
    }
    String containerName= container.getDescription();
    IStatus status= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_not_supported, containerName));
        return null;
    }
    IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
        setDescription(Messages.format(PreferencesMessages.JavadocConfigurationPropertyPage_read_only, containerName));
        fIsReadOnly= true;
        return entry;
    }
    Assert.isNotNull(entry);
    setDescription(PreferencesMessages.JavadocConfigurationPropertyPage_IsPackageFragmentRoot_description);
    return entry;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NativeLibrariesPropertyPage.java   
private IClasspathEntry handleContainerEntry(IPath containerPath, IJavaProject jproject, IPath jarPath) throws JavaModelException {
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    if (initializer == null || container == null) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)));
        return null;
    }
    String containerName= container.getDescription();
    IStatus status= initializer.getAttributeStatus(containerPath, jproject, JavaRuntime.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_not_supported, containerName));
        return null;
    }
    IClasspathEntry entry= JavaModelUtil.findEntryInContainer(container, jarPath);
    if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
        setDescription(Messages.format(PreferencesMessages.NativeLibrariesPropertyPage_read_only, containerName));
        fIsReadOnly= true;
        return entry;
    }
    Assert.isNotNull(entry);
    return entry;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CPListElement.java   
private IStatus evaluateContainerChildStatus(CPListElementAttribute attrib) {
    if (fProject != null) {
        ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(fPath.segment(0));
        if (initializer != null && initializer.canUpdateClasspathContainer(fPath, fProject)) {
            if (attrib.isBuiltIn()) {
                if (CPListElement.SOURCEATTACHMENT.equals(attrib.getKey())) {
                    return initializer.getSourceAttachmentStatus(fPath, fProject);
                } else if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
                    return initializer.getAccessRulesStatus(fPath, fProject);
                }
            } else {
                return initializer.getAttributeStatus(fPath, fProject, attrib.getKey());
            }
        }
        return new Status(IStatus.ERROR, JavaUI.ID_PLUGIN, ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY, "", null); //$NON-NLS-1$
    }
    return null;
}
项目:eclipse.jdt.ls    文件:JavaElementLabels.java   
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
    if (container != null) {
        return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(container.getDescription());
    }
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        return org.eclipse.jdt.internal.core.manipulation.util.Strings.markLTR(initializer.getDescription(containerPath, project));
    }
    return BasicElementLabels.getPathLabel(containerPath, false);
}
项目:che    文件:JavaElementLabels.java   
/**
 * Returns the label of a classpath container. The returned label is BiDi-processed with {@link
 * TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project)
    throws JavaModelException {
  IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
  if (container != null) {
    return Strings.markLTR(container.getDescription());
  }
  ClasspathContainerInitializer initializer =
      JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
  if (initializer != null) {
    return Strings.markLTR(initializer.getDescription(containerPath, project));
  }
  return BasicElementLabels.getPathLabel(containerPath, false);
}
项目:che    文件:JavaElementLabels.java   
/**
 * Returns the styled label of a classpath container. The returned label is BiDi-processed with
 * {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(
    IPath containerPath, IJavaProject project) {
  try {
    IClasspathContainer container = JavaCore.getClasspathContainer(containerPath, project);
    String description = null;
    if (container != null) {
      description = container.getDescription();
    }
    if (description == null) {
      ClasspathContainerInitializer initializer =
          JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
      if (initializer != null) {
        description = initializer.getDescription(containerPath, project);
      }
    }
    if (description != null) {
      StyledString str = new StyledString(description);
      //                if (containerPath.segmentCount() > 0 &&
      // JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
      //                    int index= description.indexOf('[');
      //                    if (index != -1) {
      //                        str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
      //                    }
      //                }
      return Strings.markLTR(str);
    }
  } catch (JavaModelException e) {
    // ignore
  }
  return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLabels.java   
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
    if (container != null) {
        return Strings.markLTR(container.getDescription());
    }
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        return Strings.markLTR(initializer.getDescription(containerPath, project));
    }
    return BasicElementLabels.getPathLabel(containerPath, false);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLabels.java   
/**
 * Returns the styled label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 *
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
    try {
        IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
        String description= null;
        if (container != null) {
            description= container.getDescription();
        }
        if (description == null) {
            ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
            if (initializer != null) {
                description= initializer.getDescription(containerPath, project);
            }
        }
        if (description != null) {
            StyledString str= new StyledString(description);
            if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
                int index= description.indexOf('[');
                if (index != -1) {
                    str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
                }
            }
            return Strings.markLTR(str);
        }
    } catch (JavaModelException e) {
        // ignore
    }
    return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
项目:Eclipse-Postfix-Code-Completion    文件:ClassPathContainer.java   
@Override
public String getLabel() {
    if (fContainer != null)
        return fContainer.getDescription();

    IPath path= fClassPathEntry.getPath();
    String containerId= path.segment(0);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerId);
    if (initializer != null) {
        String description= initializer.getDescription(path, getJavaProject());
        return Messages.format(PackagesMessages.ClassPathContainer_unbound_label, description);
    }
    return Messages.format(PackagesMessages.ClassPathContainer_unknown_label, BasicElementLabels.getPathLabel(path, false));
}
项目:Eclipse-Postfix-Code-Completion    文件:BuildPathSupport.java   
/**
 * Request a container update.
 * @param jproject The project of the container
 * @param container The container to request a change to
 * @param newEntries The updated entries
 * @throws CoreException if the request failed
 */
public static void requestContainerUpdate(IJavaProject jproject, IClasspathContainer container, IClasspathEntry[] newEntries) throws CoreException {
    IPath containerPath= container.getPath();
    IClasspathContainer updatedContainer= new UpdatedClasspathContainer(container, newEntries);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        initializer.requestClasspathContainerUpdate(containerPath, jproject, updatedContainer);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementLabels.java   
/**
 * Returns the label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 * @throws JavaModelException when resolving of the container failed
 */
public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException {
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
    if (container != null) {
        return Strings.markLTR(container.getDescription());
    }
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        return Strings.markLTR(initializer.getDescription(containerPath, project));
    }
    return BasicElementLabels.getPathLabel(containerPath, false);
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementLabels.java   
/**
 * Returns the styled label of a classpath container.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param containerPath the path of the container
 * @param project the project the container is resolved in
 * @return the label of the classpath container
 *
 * @since 3.4
 */
public static StyledString getStyledContainerEntryLabel(IPath containerPath, IJavaProject project) {
    try {
        IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project);
        String description= null;
        if (container != null) {
            description= container.getDescription();
        }
        if (description == null) {
            ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
            if (initializer != null) {
                description= initializer.getDescription(containerPath, project);
            }
        }
        if (description != null) {
            StyledString str= new StyledString(description);
            if (containerPath.segmentCount() > 0 && JavaRuntime.JRE_CONTAINER.equals(containerPath.segment(0))) {
                int index= description.indexOf('[');
                if (index != -1) {
                    str.setStyle(index, description.length() - index, DECORATIONS_STYLE);
                }
            }
            return Strings.markLTR(str);
        }
    } catch (JavaModelException e) {
        // ignore
    }
    return new StyledString(BasicElementLabels.getPathLabel(containerPath, false));
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ClassPathContainer.java   
@Override
public String getLabel() {
    if (fContainer != null)
        return fContainer.getDescription();

    IPath path= fClassPathEntry.getPath();
    String containerId= path.segment(0);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerId);
    if (initializer != null) {
        String description= initializer.getDescription(path, getJavaProject());
        return Messages.format(PackagesMessages.ClassPathContainer_unbound_label, description);
    }
    return Messages.format(PackagesMessages.ClassPathContainer_unknown_label, BasicElementLabels.getPathLabel(path, false));
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:BuildPathSupport.java   
/**
 * Request a container update.
 * @param jproject The project of the container
 * @param container The container to request a change to
 * @param newEntries The updated entries
 * @throws CoreException if the request failed
 */
public static void requestContainerUpdate(IJavaProject jproject, IClasspathContainer container, IClasspathEntry[] newEntries) throws CoreException {
    IPath containerPath= container.getPath();
    IClasspathContainer updatedContainer= new UpdatedClasspathContainer(container, newEntries);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (initializer != null) {
        initializer.requestClasspathContainerUpdate(containerPath, jproject, updatedContainer);
    }
}
项目:XRobot    文件:PreferencePage.java   
@Override
public boolean performOk() {
    boolean b = super.performOk();

    ClasspathContainerInitializer init = JavaCore.getClasspathContainerInitializer(LeJOSEV3LibContainer.ID);
    Path p1 = new Path(LeJOSEV3LibContainer.ID+"/"+LeJOSEV3Util.LIBSUBDIR_EV3);
    Path p2 = new Path(LeJOSEV3LibContainer.ID+"/"+LeJOSEV3Util.LIBSUBDIR_PC);

    IWorkspace ws = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot wsr = ws.getRoot();
    IProject[] projects = wsr.getProjects();
    for (IProject p : projects)
    {
        try
        {
            if (p.isOpen() && p.isNatureEnabled(JavaCore.NATURE_ID))
            {
                IJavaProject jp = JavaCore.create(p);
                if (JavaCore.getClasspathContainer(p1, jp) != null)
                    init.initialize(p1, jp);
                if (JavaCore.getClasspathContainer(p2, jp) != null)
                    init.initialize(p2, jp);
            }
        }
        catch (Exception e)
        {
            LeJOSEV3Util.log(e);
        }
    }

    return b;
}
项目:che    文件:JavaModelManager.java   
private IClasspathContainer initializeContainer(IJavaProject project, IPath containerPath)
    throws JavaModelException {
  ClasspathContainerInitializer initializer =
      containerInitializersCache.get(containerPath.segment(0));
  IClasspathContainer container = null;
  if (initializer != null) {
    containerPut(
        project,
        containerPath,
        CONTAINER_INITIALIZATION_IN_PROGRESS); // avoid initialization cycles
    try {
      initializer.initialize(containerPath, project);

      //            if (monitor != null)
      //                monitor.subTask(""); //$NON-NLS-1$

      // retrieve value (if initialization was successful)
      container = containerBeingInitializedGet(project, containerPath);
      if (container == null && containerGet(project, containerPath) == null) {
        // initializer failed to do its job: redirect to the failure container
        container = initializer.getFailureContainer(containerPath, project);
        //                if (container == null) {
        //                    if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
        //                        verbose_container_null_failure_container(project, containerPath,
        // initializer);
        //                    return null; // break cycle
        //                }
        //                if (CP_RESOLVE_VERBOSE || CP_RESOLVE_VERBOSE_FAILURE)
        //                    verbose_container_using_failure_container(project, containerPath,
        // initializer);
        containerPut(project, containerPath, container);
      }
    } catch (CoreException e) {
      if (e instanceof JavaModelException) {
        throw (JavaModelException) e;
      } else {
        throw new JavaModelException(e);
      }
    }
  } else {
    // create a dummy initializer and get the default failure container
    container =
        (new ClasspathContainerInitializer() {
              public void initialize(IPath path, IJavaProject javaProject) throws CoreException {
                // not used
              }
            })
            .getFailureContainer(containerPath, project);
  }
  return container;
}
项目:SecureBPMN    文件:CreateActivitiProjectWizard.java   
@Override
public boolean performFinish() {
    if (!super.performFinish())
        return false;

    IProject newProject = getNewProject();

    try {

        IProjectDescription description = newProject.getDescription();
        String[] newNatures = new String[2];
        newNatures[0] = JavaCore.NATURE_ID;
        newNatures[1] = ActivitiProjectNature.NATURE_ID;
        description.setNatureIds(newNatures);
        newProject.setDescription(description, null);

        IJavaProject javaProject = JavaCore.create(newProject);

        createSourceFolders(newProject);
        createOutputLocation(javaProject);

        IFile pomFile = newProject.getFile("pom.xml");
        InputStream pomSource = new ByteArrayInputStream(createPOMFile().getBytes()); 
        pomFile.create(pomSource, true, null);
        pomSource.close();

        String[] userLibraryNames = JavaCore.getUserLibraryNames();
        boolean activitiExtensionLibraryPresent = false;
        if(userLibraryNames != null && userLibraryNames.length > 0) {
          for(String userLibraryName : userLibraryNames) {
            if(ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS.equals(userLibraryName)) {
              activitiExtensionLibraryPresent = true;
            }
          }
        }

        if(activitiExtensionLibraryPresent == false) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
            IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
            initializer.requestClasspathContainerUpdate(containerPath.append(ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS), 
                    null, new IClasspathContainer() {

              public IPath getPath() {
                return new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS) ;
              }
              public int getKind() {
                return K_APPLICATION;
              }
              public String getDescription() {
                return ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS;
              }
              public IClasspathEntry[] getClasspathEntries() {
                return new IClasspathEntry[] {};
              }
            });
        }

        IClasspathEntry[] entries = createClasspathEntries(javaProject);

        javaProject.setRawClasspath(entries, null);
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }

    return true;
}
项目:SecureBPMN    文件:CreateDefaultActivitiProjectWizard.java   
@Override
public boolean performFinish() {
  if (!super.performFinish())
    return false;

  IProject newProject = getNewProject();

  try {

    IProjectDescription description = newProject.getDescription();
    String[] newNatures = new String[2];
    newNatures[0] = JavaCore.NATURE_ID;
    newNatures[1] = ActivitiProjectNature.NATURE_ID;
    description.setNatureIds(newNatures);
    newProject.setDescription(description, null);

    IJavaProject javaProject = JavaCore.create(newProject);

    createSourceFolders(newProject);
    createOutputLocation(javaProject);

    IFile pomFile = newProject.getFile("pom.xml");
    InputStream pomSource = new ByteArrayInputStream(createPOMFile().getBytes());
    pomFile.create(pomSource, true, null);
    pomSource.close();

    String[] userLibraryNames = JavaCore.getUserLibraryNames();
    boolean activitiExtensionLibraryPresent = false;
    if (userLibraryNames != null && userLibraryNames.length > 0) {
      for (String userLibraryName : userLibraryNames) {
        if (ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS.equals(userLibraryName)) {
          activitiExtensionLibraryPresent = true;
        }
      }
    }

    if (activitiExtensionLibraryPresent == false) {
      ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
      IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
      initializer.requestClasspathContainerUpdate(containerPath.append(ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS), null, new IClasspathContainer() {

        public IPath getPath() {
          return new Path(JavaCore.USER_LIBRARY_CONTAINER_ID).append(ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS);
        }

        public int getKind() {
          return K_APPLICATION;
        }

        public String getDescription() {
          return ActivitiPlugin.USER_LIBRARY_NAME_EXTENSIONS;
        }

        public IClasspathEntry[] getClasspathEntries() {
          return new IClasspathEntry[] {};
        }
      });
    }

    IClasspathEntry[] entries = createClasspathEntries(javaProject);

    javaProject.setRawClasspath(entries, null);
  } catch (Exception e) {
    e.printStackTrace();
    return false;
  }

  return true;
}
项目:Eclipse-Postfix-Code-Completion    文件:ClassFileEditor.java   
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry entry;
    try {
        entry= JavaModelUtil.getClasspathEntry(root);
    } catch (JavaModelException ex) {
        if (ex.isDoesNotExist())
            entry= null;
        else
            throw ex;
    }
    IPath containerPath= null;

    if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) {
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile)));
        return;
    }

    IJavaProject jproject= root.getJavaProject();
    boolean canEditEncoding= true;
    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        containerPath= entry.getPath();
        ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
        IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
        if (initializer == null || container == null) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false)));
            return;
        }
        String containerName= container.getDescription();
        IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName));
            return;
        }
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName));
            return;
        }
        IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
        canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);
        entry= JavaModelUtil.findEntryInContainer(container, root.getPath());
        Assert.isNotNull(entry);
    }


    Button button;

    IPath path= entry.getSourceAttachmentPath();
    if (path == null || path.isEmpty()) {
        String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel));
        createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach);
        createLabel(composite, null);

        button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource);

    } else {
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile)));
        createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange);
        createLabel(composite, null);

        button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource);
    }

    button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding));
}
项目:Eclipse-Postfix-Code-Completion    文件:SourceAttachmentPropertyPage.java   
private Control createPageContent(Composite composite) {
    try {
        fContainerPath= null;
        fEntry= null;
        fRoot= getJARPackageFragmentRoot();
        if (fRoot == null || fRoot.getKind() != IPackageFragmentRoot.K_BINARY) {
            return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
        }

        IPath containerPath= null;
        IJavaProject jproject= fRoot.getJavaProject();
        IClasspathEntry entry= JavaModelUtil.getClasspathEntry(fRoot);
        boolean canEditEncoding= true;
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            containerPath= entry.getPath();
            ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
            IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
            if (initializer == null || container == null) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)), fRoot);
            }
            String containerName= container.getDescription();

            IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_not_supported, containerName), null);
            }
            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_read_only, containerName), fRoot);
            }
            IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
            canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);

            entry= JavaModelUtil.findEntryInContainer(container, fRoot.getPath());
        }
        fContainerPath= containerPath;
        fEntry= entry;

        fSourceAttachmentBlock= new SourceAttachmentBlock(this, entry, canEditEncoding);
        return fSourceAttachmentBlock.createControl(composite);
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:CPListElementAttribute.java   
/**
 * @return Returns <code>true</code> if the attribute a on a container child and is not supported
 */
public boolean isNotSupported() {
    return fStatus != null && fStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ClassFileEditor.java   
private void createSourceAttachmentControls(Composite composite, IPackageFragmentRoot root) throws JavaModelException {
    IClasspathEntry entry;
    try {
        entry= JavaModelUtil.getClasspathEntry(root);
    } catch (JavaModelException ex) {
        if (ex.isDoesNotExist())
            entry= null;
        else
            throw ex;
    }
    IPath containerPath= null;

    if (entry == null || root.getKind() != IPackageFragmentRoot.K_BINARY) {
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSource, BasicElementLabels.getFileName( fFile)));
        return;
    }

    IJavaProject jproject= root.getJavaProject();
    boolean canEditEncoding= true;
    if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
        containerPath= entry.getPath();
        ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
        IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
        if (initializer == null || container == null) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_cannotconfigure, BasicElementLabels.getPathLabel(containerPath, false)));
            return;
        }
        String containerName= container.getDescription();
        IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_notsupported, containerName));
            return;
        }
        if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
            createLabel(composite, Messages.format(JavaEditorMessages.ClassFileEditor_SourceAttachmentForm_readonly, containerName));
            return;
        }
        IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
        canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);
        entry= JavaModelUtil.findEntryInContainer(container, root.getPath());
        Assert.isNotNull(entry);
    }


    Button button;

    IPath path= entry.getSourceAttachmentPath();
    if (path == null || path.isEmpty()) {
        String rootLabel= JavaElementLabels.getElementLabel(root, JavaElementLabels.ALL_DEFAULT);
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceAttachment, rootLabel));
        createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToAttach);
        createLabel(composite, null);

        button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_attachSource);

    } else {
        createLabel(composite, Messages.format(JavaEditorMessages.SourceAttachmentForm_message_noSourceInAttachment, BasicElementLabels.getFileName(fFile)));
        createLabel(composite, JavaEditorMessages.SourceAttachmentForm_message_pressButtonToChange);
        createLabel(composite, null);

        button= createButton(composite, JavaEditorMessages.SourceAttachmentForm_button_changeAttachedSource);
    }

    button.addSelectionListener(getButtonListener(entry, containerPath, jproject, canEditEncoding));
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:SourceAttachmentPropertyPage.java   
private Control createPageContent(Composite composite) {
    try {
        fContainerPath= null;
        fEntry= null;
        fRoot= getJARPackageFragmentRoot();
        if (fRoot == null || fRoot.getKind() != IPackageFragmentRoot.K_BINARY) {
            return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
        }

        IPath containerPath= null;
        IJavaProject jproject= fRoot.getJavaProject();
        IClasspathEntry entry= JavaModelUtil.getClasspathEntry(fRoot);
        boolean canEditEncoding= true;
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            containerPath= entry.getPath();
            ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
            IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
            if (initializer == null || container == null) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)), fRoot);
            }
            String containerName= container.getDescription();

            IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_not_supported, containerName), null);
            }
            if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
                return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_read_only, containerName), fRoot);
            }
            IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
            canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);

            entry= JavaModelUtil.findEntryInContainer(container, fRoot.getPath());
        }
        fContainerPath= containerPath;
        fEntry= entry;

        fSourceAttachmentBlock= new SourceAttachmentBlock(this, entry, canEditEncoding);
        return fSourceAttachmentBlock.createControl(composite);
    } catch (CoreException e) {
        JavaPlugin.log(e);
        return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:CPListElementAttribute.java   
/**
 * @return Returns <code>true</code> if the attribute a on a container child and is not supported
 */
public boolean isNotSupported() {
    return fStatus != null && fStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaModelUtil.java   
/**
 * Helper method that tests if an classpath entry can be found in a
 * container. <code>null</code> is returned if the entry can not be found
 * or if the container does not allows the configuration of source
 * attachments
 * @param jproject The container's parent project
 * @param containerPath The path of the container
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 * @throws JavaModelException thrown if accessing the container failed
 */
public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) {
        return findEntryInContainer(container, libPath);
    }
    return null; // attachment not possible
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaModelUtil.java   
/**
 * Helper method that tests if an classpath entry can be found in a
 * container. <code>null</code> is returned if the entry can not be found
 * or if the container does not allows the configuration of source
 * attachments
 * @param jproject The container's parent project
 * @param containerPath The path of the container
 * @param libPath The path of the library to be found
 * @return IClasspathEntry A classpath entry from the container of
 * <code>null</code> if the container can not be modified.
 * @throws JavaModelException thrown if accessing the container failed
 */
public static IClasspathEntry getClasspathEntryToEdit(IJavaProject jproject, IPath containerPath, IPath libPath) throws JavaModelException {
    IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
    ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
    if (container != null && initializer != null && initializer.canUpdateClasspathContainer(containerPath, jproject)) {
        return findEntryInContainer(container, libPath);
    }
    return null; // attachment not possible
}