Example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot getPath.

Prototype

IPath getPath();

Source Link

Document

Returns the path to the innermost resource enclosing this element.

Usage

From source file:org.jboss.tools.pde.sourcelookup.core.internal.jobs.AbstractSourceDownloadJob.java

License:Open Source License

protected IPath findSources(IPackageFragmentRoot fragment, IProgressMonitor monitor) throws CoreException {
    monitor.setTaskName(fragment.getElementName());

    File jar = fragment.getPath().toFile();
    IPath path = sourceLocators.stream().map(sl -> findSource(sl, jar, monitor)).filter(p -> p != null)
            .findFirst().orElse(null);//  w  w w. j a  va  2  s .c  om

    return path;
}

From source file:org.jboss.tools.pde.sourcelookup.core.internal.utils.ClasspathUtils.java

License:Open Source License

public static boolean hasSources(IPackageFragmentRoot fragment) throws CoreException {
    if (fragment == null || fragment.getSourceAttachmentPath() == null) {
        return false;
    }/*  w w  w  . j av a 2  s . c  om*/
    IPath filePath = fragment.getPath();
    IPath sourcePath = fragment.getSourceAttachmentPath();
    if (isBinaryFragment(fragment)) {
        if (!Files.isRegularFile(Paths.get(sourcePath.toOSString()))) {
            return false;
        }
        return !Objects.equals(sourcePath, filePath);
    }
    return true;
}

From source file:org.jboss.tools.portlet.ui.internal.wizard.xpl.NewJavaClassWizardPageEx.java

License:Open Source License

/**
 * Add folder group to composite/*from w w  w . j  av a  2 s . co  m*/
 */
private void addFolderGroup(Composite composite) {
    // folder
    Label folderLabel = new Label(composite, SWT.LEFT);
    folderLabel.setText(J2EEUIMessages.FOLDER_LABEL);
    folderLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    folderText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    folderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    synchHelper.synchText(folderText, INewJavaClassDataModelProperties.SOURCE_FOLDER, null);

    IPackageFragmentRoot root = getSelectedPackageFragmentRoot();
    String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
    if (projectName != null && projectName.length() > 0) {
        IProject targetProject = ProjectUtilities.getProject(projectName);
        if (root == null || !root.getJavaProject().getProject().equals(targetProject)) {
            IFolder folder = getDefaultJavaSourceFolder(targetProject);
            if (folder != null)
                folderText.setText(folder.getFullPath().toOSString());
        } else {
            folderText.setText(root.getPath().toString());
        }
    }

    folderButton = new Button(composite, SWT.PUSH);
    folderButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
    folderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    folderButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            handleFolderButtonPressed();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // Do nothing
        }
    });
}

From source file:org.jboss.tools.portlet.ui.internal.wizard.xpl.NewJavaClassWizardPageEx.java

License:Open Source License

/**
 * Add package group to composite/*from w  w  w  . jav a2 s.c  o m*/
 */
private void addPackageGroup(Composite composite) {
    // package
    packageLabel = new Label(composite, SWT.LEFT);
    packageLabel.setText(J2EEUIMessages.JAVA_PACKAGE_LABEL);
    packageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    packageText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    packageText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    synchHelper.synchText(packageText, INewJavaClassDataModelProperties.JAVA_PACKAGE, null);

    IPackageFragment packageFragment = getSelectedPackageFragment();
    String targetProject = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
    if (packageFragment != null && packageFragment.exists()
            && packageFragment.getJavaProject().getElementName().equals(targetProject)) {
        IPackageFragmentRoot root = getPackageFragmentRoot(packageFragment);
        if (root != null)
            folderText.setText(root.getPath().toString());
        model.setProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE, packageFragment.getElementName());
    }

    packageButton = new Button(composite, SWT.PUSH);
    packageButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
    packageButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    packageButton.addSelectionListener(new SelectionListener() {
        public void widgetSelected(SelectionEvent e) {
            handlePackageButtonPressed();
        }

        public void widgetDefaultSelected(SelectionEvent e) {
            // Do nothing
        }
    });
}

From source file:org.jboss.tools.ws.jaxrs.core.internal.metamodel.builder.ResourceDeltaFilter.java

License:Open Source License

public boolean applyRules(final ResourceDelta event) throws JavaModelException {
    final IResource resource = event.getResource();
    // prevent processing resources in a closed project
    if (!resource.getProject().isOpen()) {
        return false;
    }//from   w w  w.  j a  v a2 s  .c  o  m

    final IJavaProject javaProject = JavaCore.create(resource.getProject());
    // check if the resource if a .java file in an existing Package Fragment
    // Root
    if ("java".equals(resource.getFileExtension())) {
        final IPath resourcePath = resource.getFullPath();
        for (IPackageFragmentRoot fragment : javaProject.getPackageFragmentRoots()) {
            if (fragment.getPath().isPrefixOf(resourcePath)) {
                Logger.debug("**accepted** {}", event);
                return true;
            }
        }
    }
    Logger.debug("**rejected** {}", event);
    return false;
}

From source file:org.jboss.tools.ws.jaxrs.core.WorkbenchUtils.java

License:Open Source License

/**
 * Iterates through the project's package fragment roots and returns the one (source or binary) which project
 * relative path matches the given path.
 * /*from w w w  .  java2  s . com*/
 * @param project
 * @param path
 * @param progressMonitor
 * @return
 * @throws JavaModelException
 */
public static IPackageFragmentRoot getPackageFragmentRoot(IJavaProject project, String path,
        IProgressMonitor progressMonitor) throws JavaModelException {
    for (IPackageFragmentRoot packageFragmentRoot : project.getAllPackageFragmentRoots()) {
        final String fragmentPath = packageFragmentRoot.getPath().makeRelativeTo(project.getPath())
                .toPortableString();
        if (fragmentPath.equals(path)) {
            return packageFragmentRoot;
        }
    }
    fail("Entry with path " + path + " not found in project.");
    return null;
}

From source file:org.jboss.tools.ws.jaxrs.ui.wizards.JaxrsElementCreationUtils.java

License:Open Source License

/**
 * Computes the suggested package fragment from the given package fragment.
 * //from w ww  . ja va 2s  . c om
 * @param selectedPackage
 *            the {@link IPackageFragment} to process
 * @return {@link IPackageFragment} the suggested package fragment
 */
public static IPackageFragment getSuggestedPackage(final IPackageFragment selectedPackage) {
    final IPath selectedPackagePath = selectedPackage.getPath();
    final IPackageFragmentRoot selectedSourceFolder = (IPackageFragmentRoot) selectedPackage
            .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
    if (selectedPackage.isDefaultPackage()) {
        return selectedSourceFolder.getPackageFragment("rest");
    } else {
        final String suggestedPackageName = selectedPackagePath.append("rest")
                .makeRelativeTo(selectedSourceFolder.getPath()).toString().replace("/", ".");
        return selectedSourceFolder.getPackageFragment(suggestedPackageName);
    }
}

From source file:org.jboss.tools.ws.jaxws.ui.utils.JBossWSUIUtils.java

License:Open Source License

public static IStatus validatePackageName(String name, IJavaElement context) {
    IStatus status = null;/*from   w w w  .  j av a  2  s.co  m*/
    if (context == null || !context.exists()) {
        status = JavaConventions.validatePackageName(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
        if (status != null && !status.isOK()) {
            return status;
        }
    }
    String[] sourceComplianceLevels = getSourceComplianceLevels(context);
    status = JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]);
    if (status != null && status.getSeverity() == IStatus.ERROR) {
        return status;
    }

    IPackageFragmentRoot[] roots = null;
    try {
        IResource[] srcFolders = JBossWSCreationUtils.getJavaSourceRoots(context.getJavaProject());
        roots = new IPackageFragmentRoot[srcFolders.length];
        int i = 0;
        for (IResource src : srcFolders) {
            roots[i] = context.getJavaProject().getPackageFragmentRoot(src);
            i++;
        }
    } catch (JavaModelException e) {
        JBossWSUIPlugin.log(e);
    }
    for (IPackageFragmentRoot root : roots) {
        if (root != null) {
            IPackageFragment pack = root.getPackageFragment(name);
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = root.getJavaProject().getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow
                    // to name a package
                    // like the bin folder
                    IPath packagePath = pack.getPath();
                    if (outputPath.isPrefixOf(packagePath)) {
                        status = StatusUtils.warningStatus(
                                JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_IsOutputFolder);
                        return status;
                    }
                }
                if (pack.exists()) {
                    if (pack.containsJavaResources() || !pack.hasSubpackages()) {
                        status = StatusUtils
                                .warningStatus(JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageExists);
                    } else {
                        status = StatusUtils.warningStatus(
                                JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageNotShown);
                    }
                    return status;
                } else {
                    if (pack.getResource() == null) {
                        continue;
                    }
                    URI location = pack.getResource().getLocationURI();
                    if (location != null) {
                        IFileStore store = EFS.getStore(location);
                        if (store.fetchInfo().exists()) {
                            status = StatusUtils.warningStatus(
                                    JBossJAXWSUIMessages.Error_JBossWS_GenerateWizard_PackageExistsDifferentCase);
                            return status;
                        }
                    }
                }
            } catch (CoreException e) {
                JBossWSUIPlugin.log(e);
            }
        }
    }
    return status;
}

From source file:org.jboss.tools.ws.ui.utils.JBossWSUIUtils.java

License:Open Source License

public static IStatus validatePackageName(String name, IJavaElement context) {
    IStatus status = null;/*from w  w w. j a v  a2 s . c  o  m*/
    if (context == null || !context.exists()) {
        status = JavaConventions.validatePackageName(name, JavaCore.VERSION_1_3, JavaCore.VERSION_1_3);
        if (status != null && !status.isOK()) {
            return status;
        }
    }
    String[] sourceComplianceLevels = getSourceComplianceLevels(context);
    status = JavaConventions.validatePackageName(name, sourceComplianceLevels[0], sourceComplianceLevels[1]);
    if (status != null && status.getSeverity() == IStatus.ERROR) {
        return status;
    }

    IPackageFragmentRoot[] roots = null;
    try {
        IResource[] srcFolders = JBossWSCreationUtils.getJavaSourceRoots(context.getJavaProject());
        roots = new IPackageFragmentRoot[srcFolders.length];
        int i = 0;
        for (IResource src : srcFolders) {
            roots[i] = context.getJavaProject().getPackageFragmentRoot(src);
            i++;
        }
    } catch (JavaModelException e) {
        JBossWSUIPlugin.log(e);
    }
    for (IPackageFragmentRoot root : roots) {
        if (root != null) {
            IPackageFragment pack = root.getPackageFragment(name);
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = root.getJavaProject().getOutputLocation();
                if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                    // if the bin folder is inside of our root, don't allow
                    // to name a package
                    // like the bin folder
                    IPath packagePath = pack.getPath();
                    if (outputPath.isPrefixOf(packagePath)) {
                        status = StatusUtils
                                .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_IsOutputFolder);
                        return status;
                    }
                }
                if (pack.exists()) {
                    if (pack.containsJavaResources() || !pack.hasSubpackages()) {
                        status = StatusUtils
                                .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageExists);
                    } else {
                        status = StatusUtils
                                .warningStatus(JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageNotShown);
                    }
                    return status;
                } else {
                    if (pack.getResource() == null) {
                        continue;
                    }
                    URI location = pack.getResource().getLocationURI();
                    if (location != null) {
                        IFileStore store = EFS.getStore(location);
                        if (store.fetchInfo().exists()) {
                            status = StatusUtils.warningStatus(
                                    JBossWSUIMessages.Error_JBossWS_GenerateWizard_PackageExistsDifferentCase);
                            return status;
                        }
                    }
                }
            } catch (CoreException e) {
                JBossWSUIPlugin.log(e);
            }
        }
    }
    return status;
}

From source file:org.jbpm.gd.jpdl.wizard.NewProcessProjectWizard.java

License:Open Source License

private void addSourceFolder(IJavaProject javaProject, ArrayList entries, String path) throws CoreException {
    IFolder folder = javaProject.getProject().getFolder(path);
    createFolder(folder);/*from w  ww . ja  v a 2  s  . c  om*/
    IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(folder);
    entries.add(JavaCore.newSourceEntry(root.getPath()));
}