Benjamin Bentmann wrote:
> 
> mraible wrote:
> 
>> Now I need
>> to add the resources and testResources paths (src/main/resources and
>> src/test/resources). Is it possible to do that with a similar
>> annotation-like syntax?
> 
> I still wonder why you want to access the test stuff but use
> 
>   @phase process-sources
>   @requiresDependencyResolution compile
>   @execute phase="compile"
> 
> This does not fit very well together: The suggested phase
> "process-sources"
> is run before "generate-test-resources" so your plugin will miss generated
> resources. Likewise, executing only the phase "compile" as specified by
> your
> @execute annotation will not generate test stuff.
> 
> Final note: The annotation "@execute" will fork the build. If your plugin
> is
> not primarily intended to be invoked from the CLI, you could consider to
> drop the annotation and save yourself some build time.
> 
> Anyway, as for the resources: Once the phases "process-resouces" and
> "process-test-resources" have run (more precisely the
> maven-resources-plugin), the resource files have been copied and filtered
> over to "target/classes" and "target/test-classes" respectively. So, the
> usual way to load the resources from the class path is just to run
> in/after
> these phases, e.g. use
> 
>   @phase process-test-resources
> 
> If you really need to break with the semantics of the build lifecycle, you
> need to push the raw (e.g. unfiltered) resources manually into your class
> loader. To access the resources specified in the POM, you could use:
> 
>   /**
>    * @parameter default-value="${project.resources}"
>    * @readonly
>    */
>   List resources;
> 
>   /**
>    * @parameter default-value="${project.testResources}"
>    * @readonly
>    */
>   List testResources;
> 
> Adding their base directories to the class path should do.
> 
> 
> Benjamin
> 

Thanks for all your help so far, I've been able to solve all my dependency
resolution issues.

Now I'm having issues resolving resources in the project that's running my
plugin. Specifically, I'm unable to resolve Spring context files from the
local project. Here's my code:

    applicationContext.setConfigLocations(contextPaths.split(","));

    //System.out.println(contextPaths);
    applicationContext.setServletContext(new MockServletContext());
    applicationContext.setBundleContext(new MockBundleContext());
    applicationContext.setNamespace(namespace);
    applicationContext.setClassLoader(getClassLoader());
    applicationContext.refresh();

If I run this code in a test locally (where contextPaths = 
"mock-services.xml,WEB-INF/jobs-servlet.xml"), it works. However, with my
plugin, I have to set the contextPaths to the following in order to resolve
the files:

<contextPaths>file://${basedir}/src/test/resources/mock-services.xml,file://${basedir}/src/main/webapp/WEB-INF/jobs-servlet.xml</contextPaths>

Additionally, I have the following FreeMarker code that I want to read files
from the plugin:

      Configuration cfg = new Configuration();
      cfg.setDirectoryForTemplateLoading(new File("src/test/resources"));

      cfg.setObjectWrapper(new DefaultObjectWrapper());
      Map<String, Object> root = new HashMap<String, Object>();
      root.put("package", packageName);
      root.put("urlMap", urls);

      Template template = cfg.getTemplate("APIClass.ftl");
      String output =
FreeMarkerTemplateUtils.processTemplateIntoString(template, root);

The directoryForTemplateLoading and template works if I put these files in
my project that's executing the plugin. However, I'd rather load the
defaults from the plugin and allow overriding in the project. I realize this
is likely a FreeMarker question, but I figured it didn't hurt to ask.

Thanks,

Matt



-- 
View this message in context: 
http://www.nabble.com/Adding-project-dependencies-to-a-plugin-tp17199492p17220105.html
Sent from the mojo - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to