Search in sources :

Example 41 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class JavaProject method areClasspathsEqual.

/**
     * Compare current classpath with given one to see if any different.
     * Note that the argument classpath contains its binary output.
     * @param newClasspath IClasspathEntry[]
     * @param newOutputLocation IPath
     * @param otherClasspathWithOutput IClasspathEntry[]
     * @return boolean
     */
private static boolean areClasspathsEqual(IClasspathEntry[] newClasspath, IPath newOutputLocation, IClasspathEntry[] otherClasspathWithOutput) {
    if (otherClasspathWithOutput == null || otherClasspathWithOutput.length == 0)
        return false;
    int length = otherClasspathWithOutput.length;
    if (length != newClasspath.length + 1)
        // output is amongst file entries (last one)
        return false;
    // compare classpath entries
    for (int i = 0; i < length - 1; i++) {
        if (!otherClasspathWithOutput[i].equals(newClasspath[i]))
            return false;
    }
    // compare binary outputs
    IClasspathEntry output = otherClasspathWithOutput[length - 1];
    if (output.getContentKind() != ClasspathEntry.K_OUTPUT || !output.getPath().equals(newOutputLocation))
        return false;
    return true;
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 42 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class SetContainerOperation method verbose_set_container.

private void verbose_set_container() {
    Util.verbose(//$NON-NLS-1$
    "CPContainer SET  - setting container\n" + "	container path: " + this.containerPath + //$NON-NLS-1$
    '\n' + //$NON-NLS-1$
    "	projects: {" + org.eclipse.jdt.internal.compiler.util.Util.toString(this.affectedProjects, new org.eclipse.jdt.internal.compiler.util.Util.Displayable() {

        public String displayString(Object o) {
            return ((IJavaProject) o).getElementName();
        }
    }) + //$NON-NLS-1$
    "}\n	values: {\n" + org.eclipse.jdt.internal.compiler.util.Util.toString(this.respectiveContainers, new org.eclipse.jdt.internal.compiler.util.Util.Displayable() {

        public String displayString(Object o) {
            //$NON-NLS-1$
            StringBuffer buffer = new StringBuffer("		");
            if (o == null) {
                //$NON-NLS-1$
                buffer.append("<null>");
                return buffer.toString();
            }
            IClasspathContainer container = (IClasspathContainer) o;
            buffer.append(container.getDescription());
            //$NON-NLS-1$
            buffer.append(" {\n");
            IClasspathEntry[] entries = container.getClasspathEntries();
            if (entries != null) {
                for (int i = 0; i < entries.length; i++) {
                    //$NON-NLS-1$
                    buffer.append(" 			");
                    buffer.append(entries[i]);
                    buffer.append('\n');
                }
            }
            //$NON-NLS-1$
            buffer.append(" 		}");
            return buffer.toString();
        }
    }) + //$NON-NLS-1$
    "\n	}");
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IClasspathContainer(org.eclipse.jdt.core.IClasspathContainer)

Example 43 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project tdi-studio-se by Talend.

the class ComponentProjectManager method initializeClasspath.

/**
     * DOC ycbai Initialize classpath of project.
     * 
     * @param project
     * @param monitor
     * @throws OperationCanceledException
     * @throws CoreException
     */
private void initializeClasspath(IJavaProject project, IProgressMonitor monitor) throws OperationCanceledException, CoreException {
    if (monitor != null && monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    if (project == null)
        return;
    IClasspathEntry[] entries = null;
    List<IClasspathEntry> cpEntries = new ArrayList<IClasspathEntry>();
    cpEntries.addAll(Arrays.asList(getDefaultJREClasspathEntries()));
    cpEntries.addAll(getDefaultUtilClasspathEntries());
    entries = (IClasspathEntry[]) cpEntries.toArray(new IClasspathEntry[cpEntries.size()]);
    if (monitor != null)
        monitor.worked(1);
    IPath output = getOutputLocation();
    IProgressMonitor subProgressMonitor = monitor == null ? new NullProgressMonitor() : new SubProgressMonitor(monitor, 2);
    project.setRawClasspath(entries, output, subProgressMonitor);
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 44 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project tdi-studio-se by Talend.

the class TalendJetEmitter method getClasspathStr.

/**
     * DOC ycbai Comment method "getClasspathStr".
     * <p>
     * Get character string of classpath with separator.
     * 
     * @return
     */
private String getClasspathStr() {
    StringBuffer cps = new StringBuffer();
    String classPathSeparator = JavaUtils.JAVA_CLASSPATH_SEPARATOR;
    List<IClasspathEntry> cpes = getClasspathEntries();
    for (IClasspathEntry cpe : cpes) {
        String classpath = getClasspathFromEntry(cpe);
        cps.append(classpath).append(classPathSeparator);
    }
    if (cps.length() > 0) {
        cps.deleteCharAt(cps.length() - 1);
    }
    return cps.toString();
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 45 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project AutoRefactor by JnRouvignac.

the class JavaCoreHelper method addSourceContainer.

private static IPackageFragmentRoot addSourceContainer(IJavaProject javaProject, String containerName) throws Exception {
    final IProject project = javaProject.getProject();
    final IFolder folder = project.getFolder(containerName);
    createFolder(folder);
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
    IClasspathEntry cpe = JavaCore.newSourceEntry(root.getPath(), EMPTY_PATHS, EMPTY_PATHS, null);
    addToClasspath(javaProject, Arrays.asList(cpe));
    return root;
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)55 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ArrayList (java.util.ArrayList)35 Path (org.eclipse.core.runtime.Path)27 JavaModelException (org.eclipse.jdt.core.JavaModelException)23 IProject (org.eclipse.core.resources.IProject)20 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 CoreException (org.eclipse.core.runtime.CoreException)12 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)7