Example usage for org.eclipse.jdt.core IJavaProject readOutputLocation

List of usage examples for org.eclipse.jdt.core IJavaProject readOutputLocation

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject readOutputLocation.

Prototype

IPath readOutputLocation();

Source Link

Document

Returns the default output location for the project as defined by its .classpath file from disk, or null if unable to read the file.

Usage

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

private File findBinaryFor(IJavaProject jp, IType typ) {
    IPath op = jp.readOutputLocation();
    // op might not be correct if there is an output directory associated with
    // the source directory

    String tnm = typ.getFullyQualifiedName();
    tnm = tnm.replace('.', File.separatorChar);
    IPath cp = op.append(tnm + ".class");
    File f = BedrockUtil.getFileForPath(cp, jp.getProject());
    return f;// ww w .  j  av  a  2  s  .c  o  m
}

From source file:org.eclipse.birt.report.debug.internal.ui.launcher.util.WorkspaceClassPathFinder.java

License:Open Source License

private String getProjectOutClassPath(IProject project) {
    if (!hasJavaNature(project)) {
        return null;
    }/*from ww  w  .  ja  va 2 s . c o  m*/

    IJavaProject fCurrJProject = JavaCore.create(project);
    IPath path = null;
    boolean projectExists = (project.exists() && project.getFile(".classpath").exists()); //$NON-NLS-1$
    if (projectExists) {
        if (path == null) {
            path = fCurrJProject.readOutputLocation();
            //            String curPath = path.toOSString( );
            //            String directPath = project.getLocation( ).toOSString( );
            //            int index = directPath.lastIndexOf( File.separator );
            String absPath = getFullPath(path, project);

            return absPath;
        }
    }

    return null;
}

From source file:org.eclipse.birt.report.debug.internal.ui.script.util.ScriptDebugUtil.java

License:Open Source License

/**
 * @param project//from w w  w  .ja  v  a2s. co  m
 * @return
 */
public static String getOutputFolder(IJavaProject project) {
    if (project == null) {
        return null;
    }
    IPath path = project.readOutputLocation();
    String curPath = path.toOSString();
    String directPath = project.getProject().getLocation().toOSString();
    int index = directPath.lastIndexOf(File.separator);
    String absPath = directPath.substring(0, index) + curPath;

    return absPath;
}

From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDEReportClasspathResolver.java

License:Open Source License

private String getProjectOutputClassPath(IProject project) {
    if (!hasJavaNature(project)) {
        return null;
    }/*from  w w  w .  ja  v  a  2s .co  m*/

    IJavaProject fCurrJProject = JavaCore.create(project);
    IPath path = null;
    boolean projectExists = (project.exists() && project.getFile(".classpath").exists()); //$NON-NLS-1$
    if (projectExists) {
        if (path == null) {
            path = fCurrJProject.readOutputLocation();
            // String curPath = path.toOSString( );
            // String directPath = project.getLocation( ).toOSString( );
            // int index = directPath.lastIndexOf( File.separator );
            if (path == null) {
                return null;
            }
            String absPath = getFullPath(path, project);

            return absPath;
        }
    }

    return null;
}

From source file:org.eclipse.edt.ide.core.utils.EclipseUtilities.java

License:Open Source License

/**
 * Adds the outputFolder as a Java source folder if the project is a Java project.
 * /*from   ww  w  .j ava  2  s.c  om*/
 * @param project       The project containing the folder (used when outputFolder is a relative path)
 * @param outputFolder  The path of the folder. It may be project-relative, or workspace-relative. If workspace-relative
 *                      it should start with 'F/' for a folder or 'P/' for a project.
 * @param forceClasspathRefresh A classpath needs to be refreshed if an entry already exists for the output folder, but the folder has yet to be
 *                         created.  This can occur when a project is exported without a generation directory.
 * @throws CoreException
 */
public static void addToJavaBuildPathIfNecessary(IProject project, String outputFolder,
        boolean forceClasspathRefresh) throws CoreException {
    if (project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaProject = JavaCore.create(project);
        if (javaProject.exists()) {
            IClasspathEntry[] entries = javaProject.getRawClasspath();
            IPath outputFolderPath = new Path(convertFromInternalPath(outputFolder));
            boolean needToAdd = true;

            IPath fullPath = outputFolderPath.isAbsolute() ? outputFolderPath
                    : outputFolderPath.segmentCount() == 0 ? project.getFullPath()
                            : project.getFolder(outputFolderPath).getFullPath();

            for (int i = 0; i < entries.length; i++) {
                if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath nextPath = entries[i].getPath();
                    // JDT throws an error if you have a source folder within a source folder. We could add exclusions to support this, but
                    // for now we just won't add the folder.
                    if (nextPath.isPrefixOf(fullPath) || fullPath.isPrefixOf(nextPath)) {
                        needToAdd = false;
                        break;
                    }
                }
            }

            if (needToAdd) {
                IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];
                System.arraycopy(entries, 0, newEntries, 0, entries.length);
                newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(fullPath);
                javaProject.setRawClasspath(newEntries, null);
            }

            if (!needToAdd && forceClasspathRefresh) {
                javaProject.setRawClasspath(javaProject.readRawClasspath(), javaProject.readOutputLocation(),
                        null);
            }
        }
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Return the location of the binary output files for the JavaProject.
 * /*from   w w w  .  ja va 2 s .c  o  m*/
 * @param p
 *            project
 * @return path to binary output folder or <code>null</code> if not java project or other problem.
 * 
 * @since 1.0.0
 */
public static IPath getJavaProjectOutputLocation(IProject p) {
    try {
        IJavaProject javaProj = getJavaProject(p);
        if (javaProj == null)
            return null;
        if (!javaProj.isOpen())
            javaProj.open(null);
        return javaProj.readOutputLocation();
    } catch (JavaModelException e) {
        return null;
    }
}

From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java

License:Open Source License

/**
 * Hack to force a reload of the .classpath file
 * //w w w. j av  a2 s  . co m
 * @param project
 *            project to reload
 * @since 1.0.0
 */
public static void forceClasspathReload(IProject project) throws JavaModelException {
    IJavaProject javaProj = getJavaProject(project);
    if (javaProj != null) {
        IClasspathEntry[] entries = javaProj.readRawClasspath();
        if (entries != null) {
            IPath output = javaProj.readOutputLocation();
            if (output != null)
                javaProj.setRawClasspath(entries, output, null);
        }
    }
}

From source file:org.eclipse.jst.j2ee.application.internal.operations.BinaryProjectHelper.java

License:Open Source License

/**
 * //  ww  w  .  java  2s . c o  m
 */
public static void removeImportedClassesFromClasspathIfNecessary(IProject project) {
    IJavaProject javaProj = JavaCore.create(project);
    if (javaProj != null) {
        IClasspathEntry[] entries = javaProj.readRawClasspath();
        if (entries != null) {
            IClasspathEntry entryToRemove = null;
            for (int i = 0; i < entries.length; i++) {
                if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY
                        && entries[i].getPath().toString().endsWith("imported_classes") //$NON-NLS-1$
                        && !project.getFolder("imported_classes").exists()) { //$NON-NLS-1$
                    entryToRemove = entries[i];
                    break;
                }
            }
            if (null != entryToRemove) {
                IClasspathEntry[] newEntries = new IClasspathEntry[entries.length - 1];
                for (int i = 0, j = 0; i < newEntries.length && j < entries.length; j++) {
                    if (entryToRemove != entries[j]) {
                        newEntries[i] = entries[j];
                        i++;
                    }
                }
                entries = newEntries;
                IPath output = javaProj.readOutputLocation();
                if (output != null)
                    try {
                        javaProj.setRawClasspath(entries, output, null);
                    } catch (JavaModelException e) {
                    }
            }

        }
    }
}

From source file:org.hibernate.eclipse.console.utils.ProjectUtils.java

License:Open Source License

private static String[] projectPersistenceUnits(IJavaProject javaProject) {
    if (javaProject == null || javaProject.getResource() == null) {
        return new String[0];
    }//from   www.  jav a2  s.  co m
    IPath projPathFull = javaProject.getResource().getLocation();
    IPath projPath = javaProject.getPath();
    IPath path = javaProject.readOutputLocation().append("META-INF/persistence.xml"); //$NON-NLS-1$
    path = path.makeRelativeTo(projPath);
    path = projPathFull.append(path);
    IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path);
    if (!exists(file)) {
        return new String[0];
    }
    InputStream is = null;
    org.dom4j.Document doc = null;
    try {
        is = file.getContents();
        SAXReader saxReader = new SAXReader();
        doc = saxReader.read(new InputSource(is));
    } catch (CoreException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage("CoreException: ", e); //$NON-NLS-1$
    } catch (DocumentException e) {
        HibernateConsolePlugin.getDefault().logErrorMessage("DocumentException: ", e); //$NON-NLS-1$
    } finally {
        try {
            if (is != null)
                is.close();
        } catch (IOException ioe) {
            //ignore
        }
    }
    if (doc == null || doc.getRootElement() == null) {
        return new String[0];
    }
    Iterator<?> it = doc.getRootElement().elements("persistence-unit").iterator(); //$NON-NLS-1$
    ArrayList<String> res = new ArrayList<String>();
    while (it.hasNext()) {
        Element el = (Element) it.next();
        res.add(el.attributeValue("name")); //$NON-NLS-1$
    }
    return res.toArray(new String[0]);
}

From source file:org.jboss.ide.eclipse.as.ui.mbeans.project.JBossSARFacetInstallationDelegate.java

License:Open Source License

public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
        throws CoreException {
    model = (IDataModel) config;/* w w w. ja  v a  2s  .  com*/
    final IJavaProject jproj = JavaCore.create(project);

    createProjectStructure(project);

    // Add WTP natures.
    WtpUtils.addNatures(project);

    // Setup the flexible project structure

    /* 
     * This is necessary because at time, the project has NO facets
     * So a call to createComponent(etc) returns a default implementation.
     * Today, this WTP default implementation does not handle  
     * new reference types in an acceptable fashion 
     * (Does not use extension point). 
     */
    IComponentImplFactory factory = new SARVirtualComponent();
    IVirtualComponent newComponent = factory.createComponent(project);

    String outputLoc = jproj.readOutputLocation().removeFirstSegments(1).toString();
    newComponent.create(0, null);
    newComponent.setMetaProperty("java-output-path", outputLoc); //$NON-NLS-1$

    final IVirtualFolder jbiRoot = newComponent.getRootFolder();

    // Map the sarcontent to root for deploy
    String resourcesFolder = model.getStringProperty(IJBossSARFacetDataModelProperties.SAR_CONTENT_FOLDER);
    jbiRoot.createLink(new Path("/" + resourcesFolder), 0, null); //$NON-NLS-1$

    final IWorkspace ws = ResourcesPlugin.getWorkspace();
    final IClasspathEntry[] cp = jproj.getRawClasspath();
    for (int i = 0; i < cp.length; i++) {
        final IClasspathEntry cpe = cp[i];
        if (cpe.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            if (cpe.getPath().removeFirstSegments(1).segmentCount() > 0) {
                try {
                    IFolder srcFolder = ws.getRoot().getFolder(cpe.getPath());

                    IVirtualResource[] virtualResource = ComponentCore.createResources(srcFolder);
                    //create link for source folder only when it is not mapped
                    if (virtualResource.length == 0) {
                        jbiRoot.createLink(cpe.getPath().removeFirstSegments(1), 0, null);
                    }
                } catch (Exception e) {
                    Activator.log(e);
                }
            }
        }
    }
}