Skip to main content

[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?


2014-09-16 16:52 GMT+02:00 Igor Fedorenko <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.

>
> 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?

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
>> 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
> 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
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
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/m2e-dev

Back to the top