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

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

Introduction

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

Prototype

IClasspathEntry[] getRawClasspath() throws JavaModelException;

Source Link

Document

Returns the raw classpath for the project, as a list of classpath entries.

Usage

From source file:com.liferay.ide.project.core.facet.ExtPluginFacetInstall.java

License:Open Source License

@Override
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor)
        throws CoreException {
    super.execute(project, fv, config, monitor);

    IDataModel model = (IDataModel) config;
    IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);

    if (masterModel != null && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) {
        /*//from   www .ja  va 2 s  . c  o m
        // get the template zip for portlets and extract into the project
        SDK sdk = getSDK();
                
        String extName = this.masterModel.getStringProperty( EXT_NAME );
                
        // FIX IDE-450
        if( extName.endsWith( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) )
        {
        extName = extName.substring( 0, extName.indexOf( ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX ) );
        }
        // END FIX IDE-450
                
        String displayName = this.masterModel.getStringProperty( DISPLAY_NAME );
                
        Map<String, String> appServerProperties = ServerUtil.configureAppServerProperties( project );
                
        IPath newExtPath = sdk.createNewExtProject( extName, displayName, appServerProperties );
                
        IPath tempInstallPath = newExtPath.append( extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX );
                
        processNewFiles( tempInstallPath );
        // cleanup ext temp files
        FileUtil.deleteDir( installPath.toFile(), true );
        */

        // IDE-1122 SDK creating project has been moved to Class NewPluginProjectWizard
        String extName = this.masterModel.getStringProperty(EXT_NAME);

        IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH);

        processNewFiles(projectTempPath.append(extName + ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX));

        FileUtil.deleteDir(projectTempPath.toFile(), true);
        // End IDE-1122

        try {
            this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        } catch (Exception e) {
            ProjectCore.logError(e);
        }

        IFolder webappRoot = this.project.getFolder(ISDKConstants.DEFAULT_DOCROOT_FOLDER);

        deleteFolder(webappRoot.getFolder("WEB-INF/src")); //$NON-NLS-1$
        deleteFolder(webappRoot.getFolder("WEB-INF/classes")); //$NON-NLS-1$
    }

    if (shouldSetupExtClasspath()) {
        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());

        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        // first lets add all new source folders
        for (int i = 0; i < IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS.length; i++) {
            IPath sourcePath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_SOURCE_FOLDERS[i])
                    .getFullPath();

            IPath outputPath = this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_SDK_OUTPUT_FOLDERS[i])
                    .getFullPath();

            IClasspathAttribute[] attributes = new IClasspathAttribute[] {
                    JavaCore.newClasspathAttribute("owner.project.facets", "liferay.ext") }; //$NON-NLS-1$ //$NON-NLS-2$

            IClasspathEntry sourceEntry = JavaCore.newSourceEntry(sourcePath, new IPath[0], new IPath[0],
                    outputPath, attributes);

            newRawClasspath.add(sourceEntry);
        }

        // next add all previous classpath entries except for source folders
        for (IClasspathEntry entry : existingRawClasspath) {
            if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                newRawClasspath.add(entry);
            }
        }

        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]),
                this.project.getFolder(IPluginFacetConstants.EXT_PLUGIN_DEFAULT_OUTPUT_FOLDER).getFullPath(),
                null);

        ProjectUtil.fixExtProjectSrcFolderLinks(this.project);
        // fixTilesDefExtFile();
    }

    //IDE-1239 need to make sure and delete docroot/WEB-INF/ext-web/docroot/WEB-INF/lib
    removeUnneededFolders(this.project);
}

From source file:com.liferay.ide.project.core.library.PluginLibraryInstallOperation.java

License:Open Source License

@Override
public void execute(LibraryProviderOperationConfig config, IProgressMonitor monitor) throws CoreException {
    IFacetedProjectBase facetedProject = config.getFacetedProject();

    IProject project = facetedProject.getProject();

    IJavaProject javaProject = JavaCore.create(project);

    IPath containerPath = getClasspathContainerPath();

    // IDE-413 check to make sure that the containerPath doesn't already existing.

    IClasspathEntry[] entries = javaProject.getRawClasspath();

    for (IClasspathEntry entry : entries) {
        if (entry.getPath().equals(containerPath)) {
            return;
        }/*from www .  j a  va2  s  . c  o  m*/
    }

    IAccessRule[] accessRules = new IAccessRule[] {};

    IClasspathAttribute[] attributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
            IClasspathDependencyConstants.CLASSPATH_COMPONENT_NON_DEPENDENCY, StringPool.EMPTY) };

    IClasspathEntry newEntry = JavaCore.newContainerEntry(containerPath, accessRules, attributes, false);

    IClasspathEntry[] newEntries = new IClasspathEntry[entries.length + 1];

    System.arraycopy(entries, 0, newEntries, 0, entries.length);

    newEntries[entries.length] = newEntry;

    javaProject.setRawClasspath(newEntries, monitor);
}

From source file:com.liferay.ide.project.core.modules.templates.AbstractLiferayComponentTemplate.java

License:Open Source License

protected void createResorcesFolder(IProject project) throws CoreException {
    IFolder resourceFolder = liferayProject.getSourceFolder("resources");

    if (resourceFolder == null || !resourceFolder.exists()) {
        IJavaProject javaProject = JavaCore.create(project);

        List<IClasspathEntry> existingRawClasspath = Arrays.asList(javaProject.getRawClasspath());
        List<IClasspathEntry> newRawClasspath = new ArrayList<IClasspathEntry>();

        IClasspathAttribute[] attributes = new IClasspathAttribute[] {
                JavaCore.newClasspathAttribute("FROM_GRADLE_MODEL", "true") }; //$NON-NLS-1$ //$NON-NLS-2$

        IClasspathEntry resourcesEntry = JavaCore.newSourceEntry(
                project.getFullPath().append("src/main/resources"), new IPath[0], new IPath[0], null,
                attributes);/*w  w w  . j  a  v a 2  s  . co m*/

        newRawClasspath.add(resourcesEntry);

        for (IClasspathEntry entry : existingRawClasspath) {
            newRawClasspath.add(entry);
        }

        javaProject.setRawClasspath(newRawClasspath.toArray(new IClasspathEntry[0]), new NullProgressMonitor());

        project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    }
}

From source file:com.liferay.ide.project.core.PluginPackageResourceListener.java

License:Open Source License

protected void processPropertiesFile(IFile pluginPackagePropertiesFile) throws CoreException {
    IProject project = pluginPackagePropertiesFile.getProject();

    IJavaProject javaProject = JavaCore.create(project);

    IPath containerPath = null;/* w w  w.ja  v a  2s  . co  m*/

    IClasspathEntry[] entries = javaProject.getRawClasspath();

    for (IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (entry.getPath().segment(0).equals(PluginClasspathContainerInitializer.ID)
                    || entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
                containerPath = entry.getPath();

                break;
            }
        }
    }

    if (containerPath != null) {
        IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath, javaProject);

        final String id = containerPath.segment(0);

        if (id.equals(PluginClasspathContainerInitializer.ID) || id.equals(SDKClasspathContainer.ID)) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id);
            initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer);
        }
    }

    Properties props = new Properties();
    InputStream contents = null;

    try {
        contents = pluginPackagePropertiesFile.getContents();
        props.load(contents);

        // processPortalDependencyTlds(props, pluginPackagePropertiesFile.getProject());

        processRequiredDeploymentContexts(props, pluginPackagePropertiesFile.getProject());
    } catch (Exception e) {
        ProjectCore.logError(e);
    } finally {
        if (contents != null) {
            try {
                contents.close();
            } catch (IOException e) {
                // ignore, this is best effort
            }
        }
    }

}

From source file:com.liferay.ide.project.core.PluginsSDKProjectProvider.java

License:Open Source License

@Override
public ILiferayProject provide(Object type) {
    ILiferayProject retval = null;/*ww  w . ja v  a 2 s. c om*/

    if (type instanceof IProject) {
        final IProject project = (IProject) type;

        try {
            if (SDKUtil.isSDKProject(project)) {
                final IJavaProject javaProject = JavaCore.create(project);

                final boolean hasNewSdk = ClasspathUtil
                        .hasNewLiferaySDKContainer(javaProject.getRawClasspath());

                if (hasNewSdk) {
                    final PortalBundle portalBundle = ServerUtil.getPortalBundle(project);

                    if (portalBundle != null) {
                        retval = new PluginsSDKBundleProject(project, portalBundle);
                    }
                } else {
                    final ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(project);

                    if (liferayRuntime != null) {
                        retval = new PluginsSDKRuntimeProject(project, liferayRuntime);
                    }
                }
            }
        } catch (CoreException e) {
        }
    } else if (type instanceof IRuntime) {
        try {
            final IRuntime runtime = (IRuntime) type;

            final ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(runtime);

            if (liferayRuntime != null) {
                retval = new PluginsSDKRuntimeProject(null, liferayRuntime);
            }
        } catch (Exception e) {
        }
    }

    return retval;
}

From source file:com.liferay.ide.project.core.PluginsSDKProjectRuntimeValidator.java

License:Open Source License

public void validate(IFacetedProject fproj) throws CoreException {

    final IProject proj = fproj.getProject();

    if (ProjectUtil.isLiferayFacetedProject(proj)) {
        clearMarkers(proj);// w w  w.j av a 2  s  .c  o  m

        if (SDKUtil.isSDKProject(fproj.getProject())) {
            IJavaProject javaProject = JavaCore.create(proj);

            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                        && entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
                    return;
                }
            }

            if (fproj.getPrimaryRuntime() == null) {
                setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                        MSG_PRIMARY_RUNTIME_NOT_SET, LOCATION_TARGETED_RUNTIMES, ID_PRIMARY_RUNTIME_NOT_SET);
            } else {
                if (!ServerUtil.isLiferayRuntime((BridgedRuntime) fproj.getPrimaryRuntime())) {
                    setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                            MSG_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME, LOCATION_TARGETED_RUNTIMES,
                            ID_PRIMARY_RUNTIME_NOT_LIFERAY_RUNTIME);
                }
            }
        } else if (!ProjectUtil.isMavenProject(proj)) {

            setMarker(proj, ProjectCore.LIFERAY_PROJECT_MARKER_TYPE, IMarker.SEVERITY_ERROR,
                    Msgs.pluginSDKNotSet, LOCATION_TARGETED_SDK, ID_PLUGINS_SDK_NOT_SET);
        }
    }
}

From source file:com.liferay.ide.project.core.tests.ImportPluginsSDKProjectTests.java

License:Open Source License

@Test
public void testImportBasicHookProject() throws Exception {
    if (shouldSkipBundleTests())
        return;//www  .  ja  v  a 2 s .co m

    final IPath projectPath = importProject("hooks", "Import-IDE3.0-hook");
    IProject hookProjectForIDE3 = ProjectImportUtil.importProject(projectPath, new NullProgressMonitor(), null);

    assertNotNull(hookProjectForIDE3);

    IJavaProject javaProject = JavaCore.create(hookProjectForIDE3);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    List<IClasspathEntry> rawClasspaths = Arrays.asList(rawClasspath);
    final boolean hasPluginClasspathDependencyContainer = isLiferayRuntimePluginClassPath(rawClasspaths,
            SDKClasspathContainer.ID);

    assertEquals(hasPluginClasspathDependencyContainer, true);
}

From source file:com.liferay.ide.project.core.tests.ImportPluginsSDKProjectTests.java

License:Open Source License

@Test
public void testImportConfiguredPortletProject() throws Exception {
    if (shouldSkipBundleTests())
        return;// w w w. j a va 2s .c o m

    final IPath projectPath = importProject("portlets", "Import-Old-Configured-portlet");
    IProject portletProjectForIDE3 = ProjectImportUtil.importProject(projectPath, new NullProgressMonitor(),
            null);

    assertNotNull(portletProjectForIDE3);

    IJavaProject javaProject = JavaCore.create(portletProjectForIDE3);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    List<IClasspathEntry> rawClasspaths = Arrays.asList(rawClasspath);

    final boolean hasOldPluginClasspathContainer = isLiferayRuntimePluginClassPath(rawClasspaths,
            PluginClasspathContainerInitializer.ID);
    final boolean hasPluginClasspathDependencyContainer = isLiferayRuntimePluginClassPath(rawClasspaths,
            SDKClasspathContainer.ID);
    final boolean hasOldRuntimeClasspathContainer = isLiferayRuntimePluginClassPath(rawClasspaths,
            "com.liferay.studio.server.tomcat.runtimeClasspathProvider");

    assertEquals(hasOldPluginClasspathContainer, false);
    assertEquals(hasOldRuntimeClasspathContainer, false);
    assertEquals(hasPluginClasspathDependencyContainer, true);
}

From source file:com.liferay.ide.project.core.util.ClasspathUtil.java

License:Open Source License

public static void updateRequestContainer(IProject project) throws CoreException {
    final IJavaProject javaProject = JavaCore.create(project);
    IPath containerPath = null;//from www  .jav  a2s. c  o m

    final IClasspathEntry[] entries = javaProject.getRawClasspath();

    for (final IClasspathEntry entry : entries) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (entry.getPath().segment(0).equals(SDKClasspathContainer.ID)) {
                containerPath = entry.getPath();
                break;
            }
        }
    }

    if (containerPath != null) {
        final IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(containerPath,
                javaProject);

        final String id = containerPath.segment(0);

        if (id.equals(SDKClasspathContainer.ID)) {
            ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(id);
            initializer.requestClasspathContainerUpdate(containerPath, javaProject, classpathContainer);
        }
    }
}

From source file:com.liferay.ide.project.core.util.ProjectUtil.java

License:Open Source License

public static IProject createExistingProject(final ProjectRecord record, IRuntime runtime, String sdkLocation,
        IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();

    final IWorkspace workspace = ResourcesPlugin.getWorkspace();

    IProject project = workspace.getRoot().getProject(projectName);

    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);

        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());

        // If it is under the root use the default location
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {/*from w w  w . j a va  2  s . co  m*/
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }

    monitor.beginTask(Msgs.importingProject, 100);

    project.create(record.description, new SubProgressMonitor(monitor, 30));

    project.open(IResource.FORCE, new SubProgressMonitor(monitor, 70));

    // need to check to see if we an ext project with source folders with incorrect parent attributes
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        fixExtProjectClasspathEntries(project);
    }

    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);

    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);

    String pluginType = guessPluginType(fpwc);

    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);

    fpwc.commitChanges(monitor);

    final IJavaProject javaProject = JavaCore.create(fProject.getProject());

    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {
        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
                        && entry.getPath().segment(0).equals(PluginClasspathContainerInitializer.ID)) {
                    JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID)
                            .initialize(entry.getPath(), javaProject);
                    break;
                }
            }

            monitor.done();
        }
    }, monitor);

    return project;
}