[forge-issues] [JBoss JIRA] (FORGE-2292) ResourcesFacet - A Resource should have API to get the project FQN name

Claus Ibsen (JIRA) issues at jboss.org
Tue Mar 24 04:19:18 EDT 2015


    [ https://issues.jboss.org/browse/FORGE-2292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13052849#comment-13052849 ] 

Claus Ibsen commented on FORGE-2292:
------------------------------------

I was able to strip the absolute prefix and compute the path relative from the resource directory with this code
{code}
                        // we only want the relative dir name from the resource directory, eg META-INF/spring/foo.xml
                        String baseDir = facet.getResourceDirectory().getFullyQualifiedName();
                        String fqn = resource.getFullyQualifiedName();
                        if (fqn.startsWith(baseDir)) {
                            fqn = fqn.substring(baseDir.length() + 1);
                        }

{code}

And I have the xml file in META-INF/spring dir. And the completer now works
{code}
[foo]$ camel-setup^C
[foo]$ ls src/main/resources/META-INF/spring
foo.xml

[foo]$ camel-add-endpoint-xml --xml META-INF/spring/foo.xml
{code}

> ResourcesFacet - A Resource should have API to get the project FQN name
> -----------------------------------------------------------------------
>
>                 Key: FORGE-2292
>                 URL: https://issues.jboss.org/browse/FORGE-2292
>             Project: Forge
>          Issue Type: Feature Request
>    Affects Versions: 2.15.2.Final
>            Reporter: Claus Ibsen
>            Priority: Minor
>
> Using the following code to find all Camel xml files in my project
> {code}
>     public XmlFileCompleter(ResourcesFacet facet) {
>         // find package names in the source code
>         facet.visitResources(new ResourceVisitor() {
>             @Override
>             public void visit(VisitContext context, Resource<?> resource) {
>                 String name = resource.getName();
>                 if (name.endsWith(".xml")) {
>                     // must contain <camelContext...
>                     boolean camel = resource.getContents().contains("<camelContext");
>                     if (camel) {
>                         files.add(resource.getName());
>                     }
>                 }
>             }
>         });
>     }
> {code}
> The problem is that I cannot get the FQN package name of the resource. 
> getName returns the name without any parents - that is okay and would be expected.
> getFullyQualifiedName() returns the absolute path on my computer, so its
> /opt/jboss-forge/foo/src/main/resources/spring/foo.xml
> eg the project is stored in /opt/jboss-forge/foo. So I need an api to give me the java package name of the resource - which in this case would be spring/foo.xml.



--
This message was sent by Atlassian JIRA
(v6.3.11#6341)


More information about the forge-issues mailing list