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

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

Introduction

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

Prototype

int K_SOURCE

To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.

Click Source Link

Document

Kind constant for a source path root.

Usage

From source file:org.sculptor.dsl.ui.resource.MavenClasspathUriResolver.java

License:Apache License

/**
 * Returns <code>true</code> if the given {@link IPackageFragment} contains
 * source files, its underlying {@link IResource} is accessible and it is
 * excluded from its root's classpath./*from   ww  w  .  j  ava  2 s.  com*/
 */
protected boolean isMavenResourceDirectory(IPackageFragment packageFragment) throws JavaModelException {
    if (packageFragment.getKind() == IPackageFragmentRoot.K_SOURCE) {
        // check whether this pkg can be opened
        IResource underlyingResource = packageFragment.getUnderlyingResource();
        if (underlyingResource != null && underlyingResource.isAccessible()) {
            return Util.isExcluded(packageFragment);
        }
    }
    return false;
}

From source file:org.seasar.diigu.eclipse.util.ProjectUtils.java

License:Apache License

public static IPackageFragmentRoot[] getSrcPackageFragmentRoot(IJavaProject javap) throws CoreException {
    List result = new ArrayList();
    IPackageFragmentRoot[] roots = javap.getPackageFragmentRoots();
    for (int i = 0; roots != null && i < roots.length; i++) {
        IPackageFragmentRoot root = roots[i];
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            result.add(root);/*from   w w  w.j av  a 2  s.co  m*/
        }
    }
    return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]);
}

From source file:org.seasar.doma.extension.domax.util.JavaProjectUtil.java

License:Apache License

public static List<IResource> getSourceFolders(IJavaProject javaProject) {
    List<IResource> results = new ArrayList<IResource>();
    try {/*from  w  w w .ja va 2 s . c  o m*/
        IPackageFragmentRoot[] roots = javaProject.getAllPackageFragmentRoots();
        for (IPackageFragmentRoot root : roots) {
            if (root.getJavaProject() == javaProject && root.getKind() == IPackageFragmentRoot.K_SOURCE) {
                results.add(root.getCorrespondingResource());
            }
        }
    } catch (JavaModelException e) {
        Logger.error(e);
    }
    return results;
}

From source file:org.seasar.eclipse.common.util.ProjectUtil.java

License:Apache License

public static IPackageFragmentRoot getFirstSrcPackageFragmentRoot(IJavaProject javap) throws CoreException {
    IPackageFragmentRoot[] roots = javap.getPackageFragmentRoots();
    for (int i = 0; roots != null && i < roots.length; i++) {
        IPackageFragmentRoot root = roots[i];
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            return root;
        }/*w  ww .j  a v a  2 s.co  m*/
    }
    return null;
}

From source file:org.seasar.eclipse.common.util.ProjectUtil.java

License:Apache License

public static IPackageFragmentRoot[] getSrcPackageFragmentRoot(IJavaProject javap) throws CoreException {
    List<IPackageFragmentRoot> result = new ArrayList<IPackageFragmentRoot>();
    IPackageFragmentRoot[] roots = javap.getPackageFragmentRoots();
    for (int i = 0; roots != null && i < roots.length; i++) {
        IPackageFragmentRoot root = roots[i];
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            result.add(root);/* w w w.j  ava 2 s  .co m*/
        }
    }
    return result.toArray(new IPackageFragmentRoot[result.size()]);
}

From source file:org.seasar.resource.synchronizer.servlet.SrcLocationServlet.java

License:Apache License

@SuppressWarnings("unchecked")
@Override/* ww  w. j a  va2s. c  o m*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    request.setCharacterEncoding("UTF-8");
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    response.setStatus(HttpServletResponse.SC_OK);
    PrintWriter w = response.getWriter();
    try {
        for (Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
            String s = e.nextElement().toString();
            IProject project = root.getProject(s);
            if (project != null && project.exists()) {
                IJavaProject javap = JavaCore.create(project);
                for (IPackageFragmentRoot pfr : javap.getPackageFragmentRoots()) {
                    if (pfr.getKind() == IPackageFragmentRoot.K_SOURCE) {
                        String p = pfr.getResource().getLocation().toString();
                        w.println(p);
                    }
                }
            }
        }
    } catch (CoreException e) {
        Activator.log(e);
    } finally {
        if (w != null) {
            w.close();
        }
    }
}

From source file:org.seasar.sastrutsplugin.util.SAStrutsUtil.java

License:Apache License

private static String getRootPackageName(IProject project) {
    String conventionDiconPath = PreferencesUtil.getPreferenceStoreOfProject(project)
            .getString(SAStrutsConstants.PREF_CONVENTION_DICON_PATH);
    File conventionDicon = ((Path) project.getFile(conventionDiconPath).getLocation()).toFile();
    try {/*  www.j a v  a2  s . c  o m*/
        DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
        dbfactory.setNamespaceAware(true);
        DocumentBuilder builder = dbfactory.newDocumentBuilder();
        builder.setEntityResolver(new EntityResolver() {
            public InputSource resolveEntity(String publicId, String systemId)
                    throws SAXException, IOException {
                if (publicId.equals(SAStrutsConstants.PUBLIC_ID_DICON_24)
                        && systemId.equals(SAStrutsConstants.SYSTEM_ID_DICON_24)) {
                    try {
                        InputSource source = new InputSource(Activator.getDefault().getBundle()
                                .getEntry(SAStrutsConstants.DTD_DICON_24).openStream());
                        return source;
                    } catch (IOException e) {
                        LogUtil.log(Activator.getDefault(), e);
                    }
                }
                return null;
            }
        });
        Document doc = builder.parse(conventionDicon);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile(SAStrutsConstants.ROOTPACKAGE_XPATH);
        Object result = expr.evaluate(doc, XPathConstants.NODESET);
        NodeList nodes = (NodeList) result;
        if (nodes.getLength() == 0) {
            String title = Messages.ERROR_DIALOG_ROOT_PACKAGE_NAME_TITLE;
            String msg = Messages.ERROR_DIALOG_ROOT_PACKAGE_NAME_NOT_FOUND_MESSAGE;
            MessageDialog.openError(getShell(), title, msg);
        } else if (nodes.getLength() == 1) {
            return StringUtil.decodeString(nodes.item(0).getNodeValue());
        } else {
            for (int i = 0; i < nodes.getLength(); i++) {
                String rootPackageName = StringUtil.decodeString(nodes.item(i).getNodeValue());
                IJavaProject javaProject = JavaCore.create(project);
                IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
                for (int j = 0; j < roots.length; j++) {
                    if (roots[j].getKind() == IPackageFragmentRoot.K_SOURCE) {
                        IPackageFragment packageFragment = roots[j].getPackageFragment(
                                rootPackageName + "." + SAStrutsConstants.LOWER_CASE_ACTION);
                        if (packageFragment.exists()) {
                            return rootPackageName;
                        }
                    }
                }
            }
        }
    } catch (XPathExpressionException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    } catch (DOMException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    } catch (ParserConfigurationException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    } catch (SAXException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    } catch (IOException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    } catch (JavaModelException e) {
        LogUtil.log(Activator.getDefault(), e);
        showConventionDiconAnalyzeErrorDialog(e);
    }
    return null;
}

From source file:org.semanticsoft.vaaclipse.wizards.project.E4NewProjectWizard.java

License:Open Source License

/**
 * create products extension detail//from   ww  w .  ja v a2  s. c  o  m
 * 
 * @param project
 */
@SuppressWarnings("restriction")
public void createApplicationResources(IProject project, IProgressMonitor monitor) {
    Map<String, String> map = fApplicationPage.getData();
    isMinimalist = !map.get(NewApplicationWizardPage.richSample).equalsIgnoreCase("TRUE");
    if (map == null || map.get(NewApplicationWizardPage.PRODUCT_NAME) == null)
        return;

    // If the project has invalid characters, the plug-in name would replace
    // them with underscores, product name does the same
    String pluginName = map.get(NewApplicationWizardPage.PRODUCT_NAME);

    // If there's no Activator created we create default package
    if (!fPluginData.doGenerateClass()) {
        String packageName = fPluginData.getId();
        IPath path = new Path(packageName.replace('.', '/'));
        if (fPluginData.getSourceFolderName().trim().length() > 0)
            path = new Path(fPluginData.getSourceFolderName()).append(path);

        try {
            CoreUtility.createFolder(project.getFolder(path));
        } catch (CoreException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    IJavaProject javaProject = JavaCore.create(project);
    IPackageFragment fragment = null;

    try {
        for (IPackageFragment element : javaProject.getPackageFragments()) {
            if (element.getKind() == IPackageFragmentRoot.K_SOURCE) {
                fragment = element;
            }
        }
    } catch (JavaModelException e1) {
        e1.printStackTrace();
    }

    IFile file = project.getFile("css/main.css");

    try {
        prepareFolder(file.getParent(), monitor);

        URL corePath = ResourceLocator.getProjectTemplateFiles("css/main.css");
        file.create(corePath.openStream(), true, monitor);
    } catch (Exception e) {
        PDEPlugin.logException(e);
    }

    String template_id = "common";
    Set<String> binaryExtentions = new HashSet<String>();
    binaryExtentions.add(".gif");
    binaryExtentions.add(".png");

    Map<String, String> keys = new HashMap<String, String>();
    keys.put("projectName", pluginName);
    String elementName = fragment.getElementName();
    keys.put("handlersPackageName", (elementName.equals("") ? "" : elementName + ".") + "handlers");
    keys.put("loginPackageName", (elementName.equals("") ? "" : elementName + ".") + "login");
    keys.put("viewsPackageName", (elementName.equals("") ? "" : elementName + ".") + "views");
    keys.put("programArgs",
            "true".equalsIgnoreCase(map.get(NewApplicationWizardPage.CLEAR_PERSISTED_STATE))
                    ? "-clearPersistedState"
                    : "");
    keys.put("contextPath",
            !map.get(NewApplicationWizardPage.CONTEXT_PATH).trim().isEmpty()
                    ? map.get(NewApplicationWizardPage.CONTEXT_PATH)
                    : "vaaclipse");

    keys.put("port",
            !map.get(NewApplicationWizardPage.PORT).trim().isEmpty() ? map.get(NewApplicationWizardPage.PORT)
                    : "8080");

    try {
        URL corePath = ResourceLocator.getProjectTemplateFiles(template_id);
        IRunnableWithProgress op = new TemplateOperation(corePath, project, keys, binaryExtentions,
                isMinimalist);
        getContainer().run(false, true, op);
    } catch (Exception e) {
        PDEPlugin.logException(e);
    }
    if (!isMinimalist) {
        try {
            URL corePath = ResourceLocator.getProjectTemplateFiles("src");
            IRunnableWithProgress op = new TemplateOperation(corePath, (IContainer) fragment.getResource(),
                    keys, binaryExtentions, isMinimalist);
            getContainer().run(false, true, op);
        } catch (Exception e) {
            PDEPlugin.logException(e);
        }
    }
}

From source file:org.springframework.ide.eclipse.beans.ui.editor.util.BeansJavaCompletionUtils.java

License:Open Source License

private static IPackageFragment getPackageFragment(IJavaProject project, String prefix)
        throws JavaModelException {
    int dot = prefix.lastIndexOf('.');
    if (dot > -1) {
        String packageName = prefix.substring(0, dot);
        for (IPackageFragmentRoot root : project.getPackageFragmentRoots()) {
            IPackageFragment p = root.getPackageFragment(packageName);
            if (p != null && p.exists()) {
                return p;
            }//from  w ww . j a  v a 2 s  .co m
        }
        IPackageFragment[] packages = project.getPackageFragments();
        for (IPackageFragment p : packages) {
            if (p.getElementName().equals(packageName))
                return p;
        }
    } else {
        for (IPackageFragmentRoot p : project.getAllPackageFragmentRoots()) {
            if (p.getKind() == IPackageFragmentRoot.K_SOURCE) {
                return p.getPackageFragment("");
            }
        }
    }
    return project.getPackageFragments()[0];
}

From source file:org.springframework.ide.eclipse.boot.dash.model.requestmappings.AbstractRequestMapping.java

License:Open Source License

@Override
public boolean isUserDefined() {
    try {/*from  w w  w  .jav  a2  s.  c  o m*/
        IType type = getType();
        if (type != null) {
            IPackageFragmentRoot pfr = (IPackageFragmentRoot) type
                    .getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
            if (pfr != null) {
                return pfr.getKind() == IPackageFragmentRoot.K_SOURCE;
            }
        }
    } catch (Exception e) {
        BootDashActivator.log(e);
    }
    return false;
}