Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Mylyn Intent » Connecting Java ..
Connecting Java .. [message #896798] Thu, 19 July 2012 20:21 Go to next message
Torsten  is currently offline Torsten
Messages: 4
Registered: September 2010
Junior Member
Hi Alex in your previous post you mentioned the possibility to integrate
java-artifacts in intent-sections.

The hin you gave left me clue-less:

> Did you know that in addition of models, Intent can also synchronize any technical artifact (Java Code, C++ code, samples on the internet...) as long as you have plugged the corresponding synchronization bridge? More details here http://www.eclipse.org/intent/pages/transcripts/2012_AgileALMConnect/img17.html


Is there any other source of information how to get down to pure
java-code with intent?


Thanks,

Torsten.K


--
Dipl.-Ing. Torsten Krämer

Fachgebiet Bauinformatik
Technische Universität Berlin
Sekr. TIB1-B8
Gustav-Meyer-Allee 25, 13355 Berlin
Büro : Gebäude 13b - Zimmer 504
Tel. : +49 (0) 30 314 72303
Fax : +49 (0) 30 314 72301
Email: Torsten.Kraemer@xxxxxxxx
WWW : http://www.bauinformatik.tu-berlin.de
Re: Connecting Java .. [message #896873 is a reply to message #896798] Fri, 20 July 2012 08:41 Go to previous messageGo to next message
Alex Lagarde is currently offline Alex Lagarde
Messages: 185
Registered: May 2010
Senior Member

Hi Torsten,

from now on, we only have a little example (called 'retro') showing how to plug a synchronization bridge inside Intent https://github.com/eclipse/mylyn.docs.intent.main/blob/master/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java .


A synchronization bridge allows to represent technical artifacts (e.g. java code, Manifest files...) as a model.

The 'retro' synchronization bridge considers any java file found in the referenced project as an Acceptance Test. It is used to check the synchronization mechanism extensibility, but is not very useful on concrete use cases.

1. How can I use an already defined synchronization bridge?

It's quite simple: instead of referencing an actual file in a Resource declaration (as you have done for model files) :
Resource modelResource {
    URI = "platform:/resource/myProject/model/myModel.xmi";
}


You use the URI protocol associated to the synchronization bridge you want to use (in the 'retro' synchronization bridge it's "retro"). Then it's the synchronization bridge that decides how to handle the other segments of the URI. The 'retro' synchronization bridge considers that the next segment is the java project name, and the rest is a regular expression specifying which java files should be synchronized.
Resource acceptanceTestsResource {
   URI = "retro:/myTestProject/*";
      or
   URI = "retro:/myTestProject/*mypackage/*Te?t.java";
}


Every java file matching this regular expression is then represented as an Acceptance test by the 'retro' synchronization bridge.

A further example of how to use the 'retro' synchronization bridge is available in this post http://www.eclipse.org/forums/index.php/mv/msg/261790/756023/#msg_756023

2. How can I plug my own synchronization briges inside Intent?

We are working on advanced synchronization bridges, that will allow to represent Java API, workspace configuration... In the meanwhile, if you want to write your own synchronization bridge to test, here is what you need to do:

1) Define your meta-model (optional)

The first step is of course to define the model in which your technical artifacts will be represented. Let's take a very simple example: I create an ECore file with only one concept : the "EclipseProject" Eclass, containing:

- an attribute 'id' of type EString
- an attribute 'natures' which is a list of EString.

Once you have defined your meta-model, use the standard EMF mechanism (e.g. genmodels) to generate your meta-model code.

Of course you can use an already existing meta-model.


2) Define a Resource.Factory that creates the model corresponding to the technical artifacts matching a given URI

Here is an example of a Resource.Factory that represents any Eclipse project as a "EclipseProject" EClass, and sets its associated natures :


public class EclipseProjectFactory implements Resource.Factory {

	public Resource createResource(URI uri) {
                // First segment of the uri is the project name
		String projectName = uri.segment(0);

		if (projectName != null) {
			IWorkspace wksps = ResourcesPlugin.getWorkspace();
			if (wksps != null) {
				IProject prj = wksps.getRoot().getProject(projectName);
                                // If a project with that name exists in the workspace
				if (prj != null) {
					Resource result = new ResourceImpl(uri);
                                        // we create an instance of the EclipseProject Eclass
					Project eclipseProject = EclipseProjectFactory.eINSTANCE.createEclipseProject();
					eclipseProject.setId(projectName);

                                         // And fill the 'natures' EAttribute with th actual natures associated to this project
                                        for (String nature: prj.getDescription().getNatureIds()) {
											eclipseProject.getNatures().add(nature);
										}
					result.getContents().add(eclipseProject);
					return result;
				}
			}

		}
		return null;
	}


Once my Resource.Factory is implemented, I register it through the following extension point:
 <extension
         point="org.eclipse.emf.ecore.protocol_parser">
      <parser
            class="my.project.EclipseProjectFactory"
            protocolName="eclipseProject">
      </parser>
   </extension>


3) Define how to detect modifications on the technical artifacts in real-time (optional)

If you skip this step, then Intent will not be able to detect changes made on the referenced projects in real-time, so potential synchronization issues will only be detected next time the Intent Document is modified/reopened (you may judge this behavior acceptable).

To do so, you will have to define an ISynchronizerExtension . I invite you to check the 'retro' example to see how to implement such an ISynchronizerExtension. We are going to refactor the API and provide abstract classes to provide facilities for detecting modifications.

Once you're done, simply plug this extension inside Intent :
  <extension
         point="org.eclipse.mylyn.docs.intent.client.synchronizer.extension">
      <SynchronizerExtensionDescription
            class="my.project.EclipseProjectChangeListener"
            handled_uri_scheme="eclipseProject">
      </SynchronizerExtensionDescription>
   </extension>


4) How to use my newly created synchronization bridge :


Here is a short example :
Document {
     Chapter The @SampleProject@ project {
         Section SampleProject purpose {
              In this section, we will explain why the @SampleProject@ has been created.

              @M
                    new EclipseProject SampleProject {
                       id = "com.my.company.sampleproject";
                       natures += "org.eclipse.jdt.core.javanature";
                    }
              M@
         }
         Section Sample Project natures {
              For a very good reason, we decided to add the 'acceleo' nature to the SampleProject
             @M
                 SampleProject  {
                   natures += "org.eclipse.acceleo.ide.ui.acceleoNature";
                 }
             M@
         
             // And here is how to declare the Resource
             @M
                 Resource sampleProjectResource {
                     URI = "eclipseProject:/com.my.company.sampleproject";
                 }
             M@

          }
     }
}



I'll soon write a more detailled tutorial on this subject.

Please do not hesitate to ask further questions if you do not understand something, and thanks again for your interest in Intent !

Cheers,
Alex

[Updated on: Fri, 20 July 2012 08:51]

Report message to a moderator

Re: Connecting Java .. [message #1009152 is a reply to message #896873] Thu, 14 February 2013 14:57 Go to previous message
Alex Lagarde is currently offline Alex Lagarde
Messages: 185
Registered: May 2010
Senior Member

Hi Torsten,

just to let you know that a Java Bridge for Intent will be available in
the next milestone. Meanwhile, you can test it using the latest Intent
build
https://hudson.eclipse.org/hudson/job/mylyn-docs-intent-0.7-nightly/lastSuccessfulBuild/artifact/features/org.eclipse.mylyn.docs.intent.update/target/org.eclipse.mylyn.docs.intent.update.zip

Just drop a Java file/class/method/field in your Intent document, and
Intent will;
- add automatically a reference to your java file
- display an image providing an overview of this java element (see
https://dl.dropbox.com/u/25353760/work/java_sync_with_Intent.png )

When you make change on this java file, Intent will as always detect
that a desynchronization occured, and will place synchronization markers
in the documentation the appropriate location.

Notice that by ctrl-clicking (or using F3) on inside your document, a
java editor will be opened on the appropriate file, selecting the
synchronized class/method/field.

I'm interested in any feedback you may have, this is still a work in
progress.

Best regards,
Alex

Le 20/07/2012 10:41, Alex Lagarde a écrit :
> Hi Torsten,
>
> from now on, we only have a little example (called 'retro') showing how
> to plug a synchronization bridge inside Intent
> https://github.com/eclipse/mylyn.docs.intent.main/blob/master/examples/org.eclipse.mylyn.docs.intent.retro/src/org/eclipse/mylyn/docs/intent/retro/ProtocolFactory.java
> .
>
>
> A synchronization bridge allows to represent technical artifacts (e.g.
> java code, Manifest files...) as a model.
>
> The 'retro' synchronization bridge considers any java file found in the
> referenced project as an Acceptance Test. It is used to check the
> synchronization mechanism extensibility, but is not very useful on
> concrete use cases.
>
> 1. Who can I use an already defined synchronization bridge?
>
> It's quite simple: instead of referencing an actual file in a Resource
> declaration (as you have done for model files) :
> Resource modelResource {
> URI = "platform:/resource/myProject/model/myModel.xmi";
> }
>
>
> You use the URI protocol associated to the synchronization bridge you
> want to use (in the 'retro' synchronization bridge it's "retro"). Then
> it's the synchronization bridge that decides how to handle the other
> segments of the URI. The 'retro' synchronization bridge considers that
> the next segment is the java project name, and the rest is a regular
> expression specifying which java files should be synchronized.
>
> Resource acceptanceTestsResource {
> URI = "retro:/myTestProject/*";
> or
> URI = "retro:/myTestProject/*mypackage/*Te?t.java";
> }
>
>
> Every java file matching this regular expression is then represented as
> an Acceptance test by the 'retro' synchronization bridge.
>
> A further example of how to use the 'retro' synchronization bridge is
> available in this post
> http://www.eclipse.org/forums/index.php/mv/msg/261790/756023/#msg_756023
>
> 2. Who can I plug my own synchronization briges inside Intent?
>
> We are working on advanced synchronization bridges, that will allow to
> represent Java API, workspace configuration... In the meanwhile, if you
> want to write your own synchronization bridge to test, here is what you
> need to do:
> 1) Define your meta-model (optional)
>
> The first step is of course to define the model in which your technical
> artifacts will be represented. Let's take a very simple example: I
> create an ECore file with only one concept : the "EclipseProject"
> Eclass, containing:
> - an attribute 'id' of type EString
> - an attribute 'natures' which is a list of EString.
>
> Once you have defined your meta-model, use the standard EMF mechanism
> (e.g. genmodels) to generate your meta-model code.
>
> Of course you can use an already existing meta-model.
>
>
> 2) Define a Resource.Factory that creates the model corresponding to the
> technical artifacts matching a given URI
>
> Here is an example of a Resource.Factory that represents any Eclipse
> project as a "EclipseProject" EClass, and sets its associated natures :
>
>
> public class EclipseProjectFactory implements Resource.Factory {
>
> public Resource createResource(URI uri) {
> // First segment of the uri is the project name
> String projectName = uri.segment(0);
>
> if (projectName != null) {
> IWorkspace wksps = ResourcesPlugin.getWorkspace();
> if (wksps != null) {
> IProject prj = wksps.getRoot().getProject(projectName);
> // If a project with that name exists in
> the workspace
> if (prj != null) {
> Resource result = new ResourceImpl(uri);
> // we create an instance of the
> EclipseProject Eclass
> Project eclipseProject =
> EclipseProjectFactory.eINSTANCE.createEclipseProject();
> eclipseProject.setId(projectName);
>
> // And fill the 'natures'
> EAttribute with th actual natures associated to this project
> for (String nature:
> prj.getDescription().getNatureIds()) {
>
> eclipseProject.getNatures().add(nature);
> }
> result.getContents().add(eclipseProject);
> return result;
> }
> }
>
> }
> return null;
> }
>
>
> Once my Resource.Factory is implemented, I register it through the
> following extension point:
>
> <extension
> point="org.eclipse.emf.ecore.protocol_parser">
> <parser
> class="my.project.EclipseProjectFactory"
> protocolName="eclipseProject">
> </parser>
> </extension>
>
>
> 3) Define how to detect modifications on the technical artifacts in
> real-time (optional)
>
> If you skip this step, then Intent will not be able to detect changes
> made on the referenced projects in real-time, so potential
> synchronization issues will only be detected next time the Intent
> Document is modified/reopened (you may judge this behavior acceptable).
>
> To do so, you will have to define an ISynchronizerExtension . I invite
> you to check the 'retro' example to see how to implement such an
> ISynchronizerExtension. We are going to refactor the API and provide
> abstract classes to provide facilities for detecting modifications.
>
> Once you're done, simply plug this extension inside Intent :
>
> <extension
>
> point="org.eclipse.mylyn.docs.intent.client.synchronizer.extension">
> <SynchronizerExtensionDescription
> class="my.project.EclipseProjectChangeListener"
> handled_uri_scheme="eclipseProject">
> </SynchronizerExtensionDescription>
> </extension>
>
>
> 4) How to use my newly created synchronization bridge :
>
>
> Here is a short example :
> Document {
> Chapter The @SampleProject@ project {
> Section SampleProject purpose {
> In this section, we will explain why the @SampleProject@
> has been created.
>
> @M
> new EclipseProject SampleProject {
> id = "com.my.company.sampleproject";
> natures += "org.eclipse.jdt.core.javanature";
> }
> M@
> }
> Section Sample Project natures {
> For a very good reason, we decided to add the 'acceleo'
> nature to the SampleProject
> @M
> SampleProject {
> natures += "org.eclipse.acceleo.ide.ui.acceleoNature";
> }
> M@
> // And here is how to declare the Resource
> @M
> Resource sampleProjectResource {
> URI = "eclipseProject:/com.my.company.sampleproject";
> }
> M@
>
> }
> }
> }
>
>
>
> I'll soon write a more detailled tutorial on this subject.
>
> Please do not hesitate to ask further questions if you do not understand
> something, and thanks again for your interest in Intent !
>
> Cheers,
> Alex
Previous Topic:Font size of Model in Editor on OS X
Next Topic:How can I synchronize Java code with Intent ?
Goto Forum:
  


Current Time: Fri Sep 19 14:08:57 GMT 2014

Powered by FUDForum. Page generated in 0.02711 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software