I need Maven to include every dependency that has a specific groupId, version and type (for example only wars). Is it possible? Is there any plugin for this? Any pattern expression?
Something like this that I can do in my pom.xml:
<dependency>
<groupId>an.exact.group.id</groupId>
<!-- No artifactId specified-->
<version>*-SNAPSHOT</version> <!-- a pattern here for version -->
<type>war</type>
</dependency>
I don't want exactly like the above code. But, the result I wish is to have in the classpath all the artifactIds that respect the mentionned tags.
Thank you a lot!
Not sure how to do it from POM directly but you can always create a java main class, read your pom , append the necessary dependencies , and the print out a new POM file with all the details.
Use rest api to get the details on the versions.
http://search.maven.org/#api
e.g.
http://search.maven.org/#search|gav|1|g:"com.google. inject"%20AND%20a:"guice"
Mimics clicking the link for all versions of groupId "com.google. inject" and artifactId "guice." Returns sorted list of all versions of an artifact.
Related
Can I somehow use the same Eclipse plug-in project for both a generated EMF model and the corresponding generated EMF Edit code?
Normally these two components reside in two different projects, the EMF Edit one with the suffix .edit to its name. I find this superfluous, since there is so little code in the Edit project, and it is so closely related to the model code.
I have tried setting both the modelDirectory and the editDirectory Gen Model attributes to (different) directories in the same project, but that seems to lead to endless confusion and build problems. I think maybe the two generation steps overwrite each others project setting files.
After some more experimentation it seems like it works fine to have EMF and EMF Edit generated code in the same project.
The things I had to do to make it work are the following:
Setting the genmodel property modelDirectory and editDirectory to the same directory. Otherwise I got a build error saying "The type ... is already defined in ...".
Setting the genmodel property bundleManifest="false". Otherwise the plug-in ID is overwritten by the generation process.
Apart from this I also set updateClasspath="false" to avoid that the generation process messes around with that.
The automatic updates to the manifest and plugin.xml files seem to be the following:
Set plug-in ID
Add exported packages
Add EMF extensions to plugin.xml
2 and 3 needs to be performed manually if they are desired. That would involve adding entries to plugin.xml similar to these:
<extension point="org.eclipse.emf.ecore.generated_package">
<!-- #generated model -->
<package
uri="somePackage"
class="somePackage.SomePackage"
genModel="model/model.xcore"/>
</extension>
<extension point="org.eclipse.emf.edit.itemProviderAdapterFactories">
<!-- #generated model -->
<factory
uri="somePackage"
class="somePackage.someClass"
supportedTypes=
"org.eclipse.emf.edit.provider.IEditingDomainItemProvider
org.eclipse.emf.edit.provider.IStructuredItemContentProvider
org.eclipse.emf.edit.provider.ITreeItemContentProvider
org.eclipse.emf.edit.provider.IItemLabelProvider
org.eclipse.emf.edit.provider.IItemPropertySource"/>
</extension>
when we implement SitecoreApiController, for each action method we make using Sitecore.Services.Core.ServicesController("namespace") attribute, we get a url like this:
/sitecore/api/ssc/{namespace}/{controller}/{id}/{action}
I wonder if we could change this default pattern, somehow in config files. I particularly interested in /sitecore/api/ part, because sometimes in the sense of security concerns, certain clients don't like to reveal that much about CMS platform behind the scene. Sometimes they even ask us to hide anything in HTTP header that tells about Microsoft ASP.NET explicitly.
Is this possible here?
Edit
this link shows a way to customize it using pipelines but I wonder if we could change the base url just through config files without needing a custom pipeline
I had a look at it, and I think I found out how - although I haven't tested it.
It looks for a setting named Sitecore.Services.RouteBase and if it can't find it, it uses sitecore/api/ssc/ as the default value.
You should be able to change it with a config patch like this in the App_Config/Include folder:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<settings>
<setting name="Sitecore.Services.RouteBase" value="custom/api/" />
</settings>
</sitecore>
</configuration>
I'm working on a project consisting of two Eclipse plugin projects. One is an EMF project and contains the metamodel for the application. The other one is the acctual plugin working on that metamodel.
I'm now looking for a way to list all types of models available in the metamodel project. Since I basically need all generated classes I could use reflections to iterate through the metamodel package but I'd prefer an easier way if there is one.
The models are already listed as extensions in the plugin.xml like this:
<plugin>
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="MyModel"
class="org.myproject.metamodel.MyModel.MyModelPackage"
genModel="model/MetaModel.genmodel"/>
</extension>
</plugin>
where the class MyModelPackage extends EPackage and org.myproject.metamodel.MyModel also contains all the other generated classes I need to list. I'm guessing that I can use that information but I still don't know how.
Update
The project I'm working on is based on EMFStore. Running it offers the EMFStore perspective. If I have the Navigator view with a project I can right click on that project and select New Model Element. This opens a dialog where all the model elements from my metamodel are listed so it is possible. It must be done somewhere in EMFStore or one of it's dependencies. I looked through the source code but can't seem to find where it's done.
The plugin.xml of the project org.eclipse.emf.emfstore.perspective refers to the class org.eclipse.emf.emfstore.emfperspective.EMFStorePerspective which I can't find in the sources. I imported the project via the Eclipse Import Plug-Ins and Fragments functionality and it has no source folder. In the EMFStore git repositories I can't even find that project.
Update
I now got the registry that contains the generated packages using EPackage.Registry.INSTANCE. Unfortunately it contains more than the EPackages from the one project containing the metadata (org.myproject.metamodel). Now I'm just looking for a proper way to filter it, but still can't get the hang of it.
Update
As the filtering is not part of my original question I accepted the answer by #SpaceTrucker. For those who are curious, this is how I've done it now:
Registry registry = EPackage.Registry.INSTANCE;
for (String key : new HashSet<String>(registry.keySet())) {
EPackage ePackage = registry.getEPackage(key);
if (ePackage.getClass().getName().startsWith("org.myproject.metamodel")) {
//do stuf
}
}
I found no way to filter for the project but luckily all the packages start with the same prefix.
EPackages may be registered via an EPackage.Registry. There seems to be a globally used instance available via ECorePlugin.getDefaultRegistryImplementation(). However I'm not 100% sure on that.
MoDisco comes with a EMF Model Browser, where you are also able to select any registered EMF model. So you also could have a look at those sources.
I would like to retrieve jar to a specific folder(like lib) by ivy, below is my retrieve definition in the build.xml:
<ivy:retrieve pattern="lib/[artifact].[ext]" conf="webInfLib" />
And the definition of my ivy.xml like below:
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:m="http://ant.apache.org/ivy/maven">
<info organisation="xxxx" module="xxxx" status="integration"/>
<configurations>
<conf name="webInfLib" description="add jar to web-inf/lib folder"/>
</configurations>
<dependencies>
<dependency org="org.springframework" name="spring-beans" rev="2.5.5" transitive="false" conf="webInfLib -> default"/>
<dependency org="net.sf.json-lib" name="json-lib" rev="2.3">
<artifact name="json-lib" type="jar" m:classifier="jdk15"/>
</dependency>
</dependencies>
</ivy-module>
But it always throws:
impossible to ivy retrieve: java.lang.RuntimeException: Multiple artifacts of the module xxxxxx are retrieved to the same file! Update the retrieve pattern to fix this error.
I have read some similar question and their suggest to change the retrieve pattern to a more complex one. I try something like "[artifact]-revision.[ext]", but not help. And when I execute "ivy.resolve", it work fines. Is there any suggestion about this issue?
The retrieve pattern is the problem that's true.
You are trying
[artifact]-[revision].ext
so I would imagine the binary jar and the source jar would be both written on the same location for any arbitrary dependency. But if you add something unique to the case that you are having
[artifact]-[revision](-[classifier]).[ext]
In the case of a source or doc, the classifier would have a value and therefore would have a different name. In case of no classifier (like the case of the binary compiled jar) there won't be any classifier and this is dealt with by the parentheses ( )
I have a problem using the Maven Plugin Testing Harness (2.0-alpha1): When I want to test my Mojo, the default values and expressions for parameters are not applicable.
I have the following parameter:
/**
* <p>The output file to write the settings to.</p>
*
* #parameter default-value="${project.build.directory}/myProperties.properties" expression="${properties.file}"
*/
private String file;
When I run my unit tests this property is always null. I tried to inject a MavenProjectStub which returns ${project.build.directory} successfully but this is not applied to my Mojo parameter.
Is there any way to enable default values and expressions like ${project.build.directory} inside my Mojos during the tests?
So it looks like they added lookupConfiguredMojo for just this use case. It took me a while to figure out how to call that because you need a properly configured MavenProject to use it. Here's what worked for me:
File pomFile = ...
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
ProjectBuildingRequest buildingRequest = executionRequest.getProjectBuildingRequest();
ProjectBuilder projectBuilder = this.lookup(ProjectBuilder.class);
MavenProject project = projectBuilder.build(pomFile, buildingRequest).getProject();
MyMojo mojo = (MyMojo) this.lookupConfiguredMojo(project, "my-goal");
...
I hit a bunch of issues including this when testing my plugin. Each problem only took a few lines to fix but finding them wasn't easy. The pointers here helped!
I've combined them in a
BetterAbstractMojoTestCase.java class. It contains the magic lines which solved the half-dozed issues I hit; and it gives a lookupConfiguredMojo(File pom, String goal) method for your issue here.
I've had this very same problem and couldn't find any solution, so I decided to fix it myself. I've checked out the source code for the latest version of the maven-plugin-testing-harness (which is 2.0-alpha-1 at the moment) and placed it in my own github repository.
You will have to checkout the code from there and build it locally.
The only change you need to make in your project is replace the dependency in your POM. I used my own domain/groupId name instead of the Apache one just to avoid any conflicts (and confusion) with future Apache releases.
This is what you need to put in your POM:
<dependency>
<groupId>com.menttis.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
And this is the repository where you can grab the code from: https://github.com/grighetto/maven-plugin-testing-harness
For version 3+:
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.5</version>
<scope>provided</scope>
</dependency>
spent a while confused about this myself before realising I was mixing the annotation syntax with the javadoc syntax.
#Parameter(property = "project.build.directory")
private String projectBuildDir;
Then concatenate your file name with that value to complete the path in your code.