[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [m2e-dev] How to convert an instance of Project to MavenProject?
|
On 2014-09-17, 6:20, Danylo Esterman wrote:
2014-09-16 16:52 GMT+02:00 Igor Fedorenko <igor@xxxxxxxxxxxxxx
<mailto:igor@xxxxxxxxxxxxxx>>:
>
> Hard to tell why this does not work for you. Did you check if the
> expected project structure was created on filesystem? Do you see any
> exceptions in the log?
The project and its structure is created just fine without any exceptions.
This works in m2e code, see MavenProjectWizard for example, so I don't
know what's going on. Please provide a unit test that demonstrates the
problem and I will have a look. Better yet, please provide a unit test
and a patch that fixes the problem.
>
> Also, MavenProject cannot be used to mutate pom.xml on filesystem and
> there is no good API to do this. Depending on your requirements you will
> either need to create your own archetype (or just generate project
> structure in your plugin) or use something like decentxml to
> post-process pom.xml file generated by existing archetype.
I excepted that I could programmatically manipulate the POM this way like I
can do it with the aid of MavenPOMEditor. But if you say I can't then I have
to look for a workaround. What I've already tried is to change the
parameters before creating a project, i.e. to set
String version = null;
archetype.setVersion("2.3.0-SNAPSHOT");
But the operation fails because the version may not be null and the
archetype of this version can't be found in the archetype catalog. I need to
change these parameters in the resulting POM though.
What would you suggest to be the best workaround?
You have several options, in no particular order
* fix the archetype you use to do what you need
* create new archetype that does what you need
* fully create project structure in your code, i.e. without an archetype
* use existing archetype but "fix" the generated pom in your code
--
Regards,
Igor
Regards,
Danylo
>
>
> --
> Regards,
> Igor
>
> On 2014-09-16, 10:25, Danylo Esterman wrote:
>>
>> I am programming an Eclipse Plug-In. A /NewWizard/ should became a part
>> of it. Its purpose is to simplify the creation of a maven project with
>> predefined parameters. I managed to handle this job so far using the
>> parts of |m2e.core.ui| to not reinvent the wheel, this snippet shows how
>> the project is created:
>>
>> |final Job job= new AbstactCreateMavenProjectJob("Creating
project" + projectName, workingSets)
>> {
>> @Override
>> protected List<IProject>
doCreateMavenProjects(IProgressMonitor monitor) throws CoreException
>> {
>> List<IProject> projects=
MavenPlugin.getProjectConfigurationManager()
>>
.createArchetypeProjects(location, archetype, groupId,
>>
artifactId, version, javaPackage,
>>
properties, importConfiguration, monitor);
>>
>> return projects;
>> }
>> };|
>>
>> However I've got some additional requirements. I need to modify two
>> parameters of the created project. It should look kinda like that:
>>
>> |IMavenProjectFacade mPFacade=
MavenPlugin.getMavenProjectRegistry().getProject(projects.get(0));
>> mPFacade.getMavenProject().setVersion(null);
>>
mPFacade.getMavenProject().getParentArtifact().setVersion("2.3.0-SNAPSHOT");|
>>
>> But |MavenPlugin.getMavenProjectRegistry().getProjects();| returns an
>> empty array, so |getProject()| returns |null|. How to do the conversion
>> and set the parameters properly?
>>
>>
>>
>> _______________________________________________
>> m2e-dev mailing list
>> m2e-dev@xxxxxxxxxxx <mailto:m2e-dev@xxxxxxxxxxx>
>> To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
>> https://dev.eclipse.org/mailman/listinfo/m2e-dev
>>
> _______________________________________________
> m2e-dev mailing list
> m2e-dev@xxxxxxxxxxx <mailto:m2e-dev@xxxxxxxxxxx>
> To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
> https://dev.eclipse.org/mailman/listinfo/m2e-dev
Hard to tell why this does not work for you. Did you check if the
expected project structure was created on filesystem? Do you see any
exceptions in the log?
Also, MavenProject cannot be used to mutate pom.xml on filesystem and
there is no good API to do this. Depending on your requirements you will
either need to create your own archetype (or just generate project
structure in your plugin) or use something like decentxml to
post-process pom.xml file generated by existing archetype.
--
Regards,
Igor
On 2014-09-16, 10:25, Danylo Esterman wrote:
I am programming an Eclipse Plug-In. A /NewWizard/ should became a part
of it. Its purpose is to simplify the creation of a maven project with
predefined parameters. I managed to handle this job so far using the
parts of |m2e.core.ui| to not reinvent the wheel, this snippet shows how
the project is created:
|final Job job= new AbstactCreateMavenProjectJob("__Creating
project" + projectName, workingSets)
{
@Override
protected List<IProject>
doCreateMavenProjects(__IProgressMonitor monitor) throws
CoreException
{
List<IProject> projects=
MavenPlugin.__getProjectConfigurationManager__()
.createArchetypeProjects(__location, archetype, groupId,
artifactId, version, javaPackage,
properties, importConfiguration, monitor);
return projects;
}
};|
However I've got some additional requirements. I need to modify two
parameters of the created project. It should look kinda like that:
|IMavenProjectFacade mPFacade=
MavenPlugin.__getMavenProjectRegistry().__getProject(projects.get(0));
mPFacade.getMavenProject().__setVersion(null);
mPFacade.getMavenProject().__getParentArtifact().__setVersion("2.3.0-SNAPSHOT");|
But |MavenPlugin.__getMavenProjectRegistry().__getProjects();|
returns an
empty array, so |getProject()| returns |null|. How to do the conversion
and set the parameters properly?
_________________________________________________
m2e-dev mailing list
m2e-dev@xxxxxxxxxxx <mailto:m2e-dev@xxxxxxxxxxx>
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/__mailman/listinfo/m2e-dev
<https://dev.eclipse.org/mailman/listinfo/m2e-dev>
_________________________________________________
m2e-dev mailing list
m2e-dev@xxxxxxxxxxx <mailto:m2e-dev@xxxxxxxxxxx>
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/__mailman/listinfo/m2e-dev
<https://dev.eclipse.org/mailman/listinfo/m2e-dev>
_______________________________________________
m2e-dev mailing list
m2e-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/m2e-dev