Example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind

List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind.

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService.java

License:Open Source License

public Status compute() {
    final Element modelElement = context(Element.class);

    if (!modelElement.disposed() && modelElement instanceof SupportedLocales) {
        final IProject project = modelElement.adapt(IProject.class);
        final Portlet portlet = modelElement.nearest(Portlet.class);
        final IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
        final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);

        if (cpEntries != null) {
            final String locale = modelElement.property(context(ValueProperty.class)).text(false);
            final Value<Path> resourceBundle = portlet.getResourceBundle();

            if (locale == null) {
                return Status.createErrorStatus(Resources.localeMustNotEmpty);
            } else {
                final String bundleName = resourceBundle.text();

                if (resourceBundle != null && bundleName != null) {
                    final String localeString = PortletUtil.localeString(locale);
                    final String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION,
                            localeString);

                    for (IClasspathEntry iClasspathEntry : cpEntries) {
                        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
                            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
                            entryPath = entryPath.append(ioFileName);
                            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
                            if (resourceBundleFile != null && resourceBundleFile.exists()) {
                                return Status.createOkStatus();
                            } else {
                                return Status.createWarningStatus(Resources.bind(
                                        StringEscapeUtils.unescapeJava(Resources.noResourceBundle),
                                        new Object[] { locale, bundleName, localeString }));
                            }/*from  w ww . java2s.c o m*/

                        }
                    }
                }
            }
        }
    }

    return Status.createOkStatus();
}

From source file:com.liferay.ide.portlet.core.util.PortletUtil.java

License:Open Source License

/**
 * this will convert the IO file name of the resource bundle to java package name
 * /*from   w w  w.j  a v a 2  s  .  co  m*/
 * @param project
 * @param value
 *            - the io file name
 * @return - the java package name of the resource bundle
 */
public static String convertIOToJavaFileName(IProject project, String value) {
    String rbIOFile = value.substring(value.lastIndexOf("/") + 1); //$NON-NLS-1$
    IFile resourceBundleFile = null;
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot wroot = workspace.getRoot();
    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    for (IClasspathEntry iClasspathEntry : cpEntries) {
        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
            entryPath = entryPath.append(rbIOFile);
            resourceBundleFile = wroot.getFileForLocation(entryPath);
            // System.out.println( "ResourceBundleValidationService.validate():" + resourceBundleFile );
            if (resourceBundleFile != null && resourceBundleFile.exists()) {
                break;
            }
        }
    }

    String javaName = resourceBundleFile.getProjectRelativePath().toPortableString();
    if (javaName.indexOf('.') != -1) {
        // Strip the extension
        javaName = value.substring(0, value.lastIndexOf('.'));
        // Replace all "/" by "."
        javaName = javaName.replace('/', '.');
    }
    return javaName;
}

From source file:com.liferay.ide.portlet.ui.editor.internal.AbstractResourceBundleActionHandler.java

License:Open Source License

/**
 * @param project//w w w  . j  av  a 2s.com
 * @param ioFileName
 * @return
 */
protected final boolean getFileFromClasspath(IProject project, String ioFileName) {

    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    for (IClasspathEntry iClasspathEntry : cpEntries) {
        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
            entryPath = entryPath.append(ioFileName);
            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
            if (resourceBundleFile != null && resourceBundleFile.exists()) {
                return true;
            } else {
                return false;
            }
        }
    }
    return false;
}

From source file:com.liferay.ide.portlet.ui.editor.internal.AbstractResourceBundleActionHandler.java

License:Open Source License

/**
 * @param project//from   www  .j  a  v a2 s.  c  o m
 * @param ioFileName
 * @return
 */
protected final IFolder getResourceBundleFolderLocation(IProject project, String ioFileName) {

    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    for (IClasspathEntry iClasspathEntry : cpEntries) {
        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
            IFolder srcFolder = wroot.getFolder(iClasspathEntry.getPath());
            IPath rbSourcePath = srcFolder.getLocation();
            rbSourcePath = rbSourcePath.append(ioFileName);
            IFile resourceBundleFile = wroot.getFileForLocation(rbSourcePath);
            if (resourceBundleFile != null) {
                return srcFolder;
            }
        }
    }
    return null;
}

From source file:com.liferay.ide.portlet.ui.editor.internal.ResourceBundleJumpActionHandler.java

License:Open Source License

@Override
protected boolean computeEnablementState() {
    final Element element = getModelElement();
    IProject project = element.adapt(IProject.class);

    final ValueProperty property = (ValueProperty) property().definition();

    final String text = element.property(property).text(true);
    boolean isEnabled = super.computeEnablementState();
    if (isEnabled && text != null) {
        final IWorkspace workspace = ResourcesPlugin.getWorkspace();
        final IWorkspaceRoot wroot = workspace.getRoot();
        final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
        String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);
        for (IClasspathEntry iClasspathEntry : cpEntries) {
            if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
                IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
                entryPath = entryPath.append(ioFileName);
                IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
                if (resourceBundleFile != null && resourceBundleFile.exists()) {
                    return true;
                }//from   w ww  .  j  av a  2s .  com
            }
        }
    }
    return false;
}

From source file:com.liferay.ide.portlet.ui.editor.internal.ResourceBundleJumpActionHandler.java

License:Open Source License

@Override
protected Object run(Presentation context) {

    final Element element = getModelElement();

    final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();

    final ValueProperty property = (ValueProperty) property().definition();

    final IProject project = element.adapt(IProject.class);

    final Value<Path> value = element.property(property);

    final String text = value.text(false);

    final IWorkspace workspace = ResourcesPlugin.getWorkspace();
    final IWorkspaceRoot wroot = workspace.getRoot();
    final IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);

    for (IClasspathEntry iClasspathEntry : cpEntries) {
        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
            entryPath = entryPath.append(ioFileName);
            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
            if (resourceBundleFile != null && resourceBundleFile.exists()) {
                if (window != null) {
                    final IWorkbenchPage page = window.getActivePage();
                    IEditorDescriptor editorDescriptor = null;

                    try {
                        editorDescriptor = IDE.getEditorDescriptor(resourceBundleFile.getName());
                    } catch (PartInitException e) {
                        // No editor was found for this file type.
                    }//w  ww.j  av a  2 s  .  c om

                    if (editorDescriptor != null) {
                        try {
                            IDE.openEditor(page, resourceBundleFile, editorDescriptor.getId(), true);
                        } catch (PartInitException e) {
                            PortletUIPlugin.logError(e);
                        }
                    }
                }
            }
        }
    }
    return null;
}

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

License:Open Source License

protected IPath[] getSourceEntries(IJavaProject javaProject) {
    List<IPath> paths = new ArrayList<IPath>();

    try {/*w  w  w  .j a v a 2 s . co m*/
        final IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);

        for (IClasspathEntry entry : classpathEntries) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                paths.add(entry.getPath());
            }
        }
    } catch (JavaModelException e) {
        ProjectCore.logError("Error resolving classpath.", e);
    }

    return paths.toArray(new IPath[0]);
}

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   ww  w. jav a  2 s  .  c  om*/
        // 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.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  . j  av  a  2  s . c  o  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.PluginsSDKProjectRuntimeValidator.java

License:Open Source License

public void validate(IFacetedProject fproj) throws CoreException {

    final IProject proj = fproj.getProject();

    if (ProjectUtil.isLiferayFacetedProject(proj)) {
        clearMarkers(proj);//from  ww  w.j  a  va  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);
        }
    }
}