View | Details | Raw Unified | Return to bug 154251 | Differences between
and this patch

Collapse All | Expand All

(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/src/org/maven/ide/eclipse/actions/DisableNatureAction.java (-45 / +2 lines)
Lines 1-24 Link Here
1
1
2
package org.maven.ide.eclipse.actions;
2
package org.maven.ide.eclipse.actions;
3
3
4
import java.util.ArrayList;
5
import java.util.Iterator;
4
import java.util.Iterator;
6
5
7
import org.eclipse.core.resources.IProject;
6
import org.eclipse.core.resources.IProject;
8
import org.eclipse.core.resources.IProjectDescription;
9
import org.eclipse.core.resources.IResource;
10
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.IAdaptable;
7
import org.eclipse.core.runtime.IAdaptable;
12
import org.eclipse.jdt.core.IClasspathEntry;
13
import org.eclipse.jdt.core.IJavaProject;
14
import org.eclipse.jdt.core.JavaCore;
15
import org.eclipse.jface.action.IAction;
8
import org.eclipse.jface.action.IAction;
16
import org.eclipse.jface.viewers.ISelection;
9
import org.eclipse.jface.viewers.ISelection;
17
import org.eclipse.jface.viewers.IStructuredSelection;
10
import org.eclipse.jface.viewers.IStructuredSelection;
18
import org.eclipse.ui.IObjectActionDelegate;
11
import org.eclipse.ui.IObjectActionDelegate;
19
import org.eclipse.ui.IWorkbenchPart;
12
import org.eclipse.ui.IWorkbenchPart;
20
import org.maven.ide.eclipse.Maven2Plugin;
13
import org.maven.ide.eclipse.project.MavenEclipseProject;
21
import org.maven.ide.eclipse.container.Maven2ClasspathContainer;
22
14
23
15
24
public class DisableNatureAction implements IObjectActionDelegate {
16
public class DisableNatureAction implements IObjectActionDelegate {
Lines 42-48 Link Here
42
          project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
34
          project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
43
        }
35
        }
44
        if(project != null) {
36
        if(project != null) {
45
          disableNature(project, structuredSelection.size() == 1);
37
          MavenEclipseProject.enableNature(project);
46
        }
38
        }
47
      }
39
      }
48
    }
40
    }
Lines 66-104 Link Here
66
    this.targetPart = targetPart;
58
    this.targetPart = targetPart;
67
  }
59
  }
68
60
69
  private void disableNature(IProject project, boolean isSingle) {
70
    try {
71
      project.deleteMarkers(Maven2Plugin.MARKER_ID, true, IResource.DEPTH_INFINITE);
72
      
73
      IProjectDescription description = project.getDescription();
74
      String[] natures = description.getNatureIds();
75
      ArrayList newNatures = new ArrayList();
76
      for(int i = 0; i < natures.length; ++i) {
77
        if(!Maven2Plugin.NATURE_ID.equals(natures[i])) {
78
          newNatures.add(natures[i]);
79
        }
80
      }
81
      description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()]));
82
      project.setDescription(description, null);
83
84
      IJavaProject javaProject = JavaCore.create(project);
85
      if(javaProject != null) {
86
        // remove classpatch container from JavaProject
87
        IClasspathEntry[] entries = javaProject.getRawClasspath();
88
        ArrayList newEntries = new ArrayList();
89
        for(int i = 0; i < entries.length; i++ ) {
90
          if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entries[i].getPath())) {
91
            newEntries.add(entries[i]);
92
          }
93
        }
94
        javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
95
      }
96
97
    } catch(CoreException ex) {
98
      Maven2Plugin.getDefault().getConsole().logError("Can't disable nature " + ex.toString());
99
      Maven2Plugin.log(ex);
100
101
    }
102
  }
103
104
}
61
}
(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/src/org/maven/ide/eclipse/actions/EnableNatureAction.java (-85 / +28 lines)
Lines 1-20 Link Here
1
1
2
package org.maven.ide.eclipse.actions;
2
package org.maven.ide.eclipse.actions;
3
3
4
import java.util.ArrayList;
5
import java.util.HashSet;
6
import java.util.Iterator;
4
import java.util.Iterator;
7
5
8
import org.eclipse.core.resources.IFile;
6
import org.eclipse.core.resources.IFile;
9
import org.eclipse.core.resources.IProject;
7
import org.eclipse.core.resources.IProject;
10
import org.eclipse.core.resources.IProjectDescription;
11
import org.eclipse.core.runtime.CoreException;
12
import org.eclipse.core.runtime.IAdaptable;
8
import org.eclipse.core.runtime.IAdaptable;
13
import org.eclipse.core.runtime.Path;
14
import org.eclipse.jdt.core.IClasspathContainer;
15
import org.eclipse.jdt.core.IClasspathEntry;
16
import org.eclipse.jdt.core.IJavaProject;
17
import org.eclipse.jdt.core.JavaCore;
18
import org.eclipse.jface.action.IAction;
9
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.viewers.ISelection;
10
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
11
import org.eclipse.jface.viewers.IStructuredSelection;
Lines 25-32 Link Here
25
import org.eclipse.ui.IWorkbench;
16
import org.eclipse.ui.IWorkbench;
26
import org.eclipse.ui.IWorkbenchPart;
17
import org.eclipse.ui.IWorkbenchPart;
27
import org.maven.ide.eclipse.Maven2Plugin;
18
import org.maven.ide.eclipse.Maven2Plugin;
28
import org.maven.ide.eclipse.container.Maven2ClasspathContainer;
19
import org.maven.ide.eclipse.project.MavenEclipseProject;
29
import org.maven.ide.eclipse.container.Maven2ClasspathContainerInitializer;
30
import org.maven.ide.eclipse.wizards.Maven2PomWizard;
20
import org.maven.ide.eclipse.wizards.Maven2PomWizard;
31
21
32
22
Lines 37-55 Link Here
37
   * (non-Javadoc)
27
   * (non-Javadoc)
38
   * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
28
   * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
39
   */
29
   */
40
  public void run( IAction action) {
30
  public void run(IAction action) {
41
    if( selection instanceof IStructuredSelection) {
31
    if(selection instanceof IStructuredSelection) {
42
      IStructuredSelection structuredSelection = ( IStructuredSelection) selection;
32
      IStructuredSelection structuredSelection = (IStructuredSelection) selection;
43
      for( Iterator it = structuredSelection.iterator(); it.hasNext();) {
33
      for(Iterator it = structuredSelection.iterator(); it.hasNext();) {
44
        Object element = it.next();
34
        Object element = it.next();
45
        IProject project = null;
35
        IProject project = null;
46
        if( element instanceof IProject) {
36
        if(element instanceof IProject) {
47
          project = ( IProject) element;
37
          project = (IProject) element;
48
        } else if( element instanceof IAdaptable) {
38
        } else if(element instanceof IAdaptable) {
49
          project = ( IProject) (( IAdaptable) element).getAdapter( IProject.class);
39
          project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
50
        }
40
        }
51
        if( project != null) {
41
        if(project != null) {
52
          enableNature( project, structuredSelection.size()==1);
42
          enableNature(project, structuredSelection.size() == 1);
53
        }
43
        }
54
      }
44
      }
55
    }
45
    }
Lines 60-66 Link Here
60
   * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
50
   * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction,
61
   *      org.eclipse.jface.viewers.ISelection)
51
   *      org.eclipse.jface.viewers.ISelection)
62
   */
52
   */
63
  public void selectionChanged( IAction action, ISelection selection) {
53
  public void selectionChanged(IAction action, ISelection selection) {
64
    this.selection = selection;
54
    this.selection = selection;
65
  }
55
  }
66
56
Lines 69-143 Link Here
69
   * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
59
   * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction,
70
   *      org.eclipse.ui.IWorkbenchPart)
60
   *      org.eclipse.ui.IWorkbenchPart)
71
   */
61
   */
72
  public void setActivePart( IAction action, IWorkbenchPart targetPart) {
62
  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
73
  }
63
  }
74
64
75
  private void enableNature( IProject project, boolean isSingle) {
65
  private void enableNature(IProject project, boolean isSingle) {
76
    try {
66
    IFile pom = project.getFile(Maven2Plugin.POM_FILE_NAME);
77
      IFile pom = project.getFile( Maven2Plugin.POM_FILE_NAME);
67
    if(isSingle && !pom.exists()) {
78
      if( isSingle && !pom.exists()) {
68
      Maven2PomWizard wizard = new Maven2PomWizard();
79
        Maven2PomWizard wizard = new Maven2PomWizard();
80
        
81
        Maven2Plugin plugin = Maven2Plugin.getDefault();
82
        IWorkbench workbench = plugin.getWorkbench();
83
        wizard.init(workbench, (IStructuredSelection) selection);
84
        
85
        Shell shell = workbench.getActiveWorkbenchWindow().getShell();
86
        WizardDialog wizardDialog = new WizardDialog( shell, wizard);
87
        wizardDialog.create();
88
        wizardDialog.getShell().setText("Create new POM");
89
        if(wizardDialog.open()==Window.CANCEL) {
90
          return;
91
        }
92
      }
93
69
94
      
70
      Maven2Plugin plugin = Maven2Plugin.getDefault();
95
      
71
      IWorkbench workbench = plugin.getWorkbench();
96
      ArrayList newNatures = new ArrayList();
72
      wizard.init(workbench, (IStructuredSelection) selection);
97
      newNatures.add(JavaCore.NATURE_ID);
98
      newNatures.add(Maven2Plugin.NATURE_ID);
99
      
100
      IProjectDescription description = project.getDescription();
101
      String[] natures = description.getNatureIds();
102
      for(int i = 0; i < natures.length; ++i) {
103
        String id = natures[i];
104
        if(!Maven2Plugin.NATURE_ID.equals(id) && !JavaCore.NATURE_ID.equals(natures[i])) {
105
          newNatures.add(natures[i]);
106
        }
107
      }
108
      description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()]));
109
      project.setDescription(description, null);
110
      
111
      IJavaProject javaProject = JavaCore.create(project);
112
      if(javaProject!=null) {
113
        IClasspathContainer maven2ClasspathContainer = Maven2ClasspathContainerInitializer.getMaven2ClasspathContainer(javaProject);
114
        IClasspathEntry[] containerEntries = maven2ClasspathContainer.getClasspathEntries();
115
        HashSet containerEntrySet = new HashSet();
116
        for(int i = 0; i < containerEntries.length; i++ ) {
117
          containerEntrySet.add(containerEntries[i].getPath().toString());
118
        }
119
      
120
        // remove classpath container from JavaProject
121
        IClasspathEntry[] entries = javaProject.getRawClasspath();
122
        ArrayList newEntries = new ArrayList();
123
        for( int i = 0; i < entries.length; i++) {
124
          IClasspathEntry entry = entries[i];
125
          if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entry.getPath()) &&
126
              !containerEntrySet.contains(entry.getPath().toString())) {
127
            newEntries.add(entry);
128
          }
129
        }
130
        newEntries.add(JavaCore.newContainerEntry(new Path(Maven2Plugin.CONTAINER_ID)));
131
73
132
        javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]), null);
74
      Shell shell = workbench.getActiveWorkbenchWindow().getShell();
75
      WizardDialog wizardDialog = new WizardDialog(shell, wizard);
76
      wizardDialog.create();
77
      wizardDialog.getShell().setText("Create new POM");
78
      if(wizardDialog.open() == Window.CANCEL) {
79
        return;
133
      }
80
      }
134
      
135
    } catch( CoreException ex) {
136
      Maven2Plugin.getDefault().getConsole().logError( "Can't enable nature "+ex.toString() );
137
      Maven2Plugin.log(ex);
138
    
139
    }
81
    }
82
83
    MavenEclipseProject.enableNature(project);
140
  }
84
  }
141
85
142
}
86
}
143
(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/src/org/maven/ide/eclipse/actions/UpdateSourcesAction.java (-399 / +12 lines)
Lines 1-434 Link Here
1
1
2
package org.maven.ide.eclipse.actions;
2
package org.maven.ide.eclipse.actions;
3
3
4
import java.io.File;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.Iterator;
4
import java.util.Iterator;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Properties;
13
import java.util.Set;
14
import java.util.jar.Attributes;
15
import java.util.jar.JarFile;
16
import java.util.jar.Manifest;
17
5
18
import org.apache.maven.SettingsConfigurationException;
19
import org.apache.maven.embedder.MavenEmbedder;
20
import org.apache.maven.execution.DefaultMavenExecutionRequest;
21
import org.apache.maven.execution.MavenExecutionRequest;
22
import org.apache.maven.model.Plugin;
23
import org.apache.maven.model.Resource;
24
import org.apache.maven.project.MavenProject;
25
import org.apache.maven.settings.Settings;
26
27
import org.codehaus.plexus.util.xml.Xpp3Dom;
28
import org.eclipse.core.resources.IContainer;
29
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IProject;
6
import org.eclipse.core.resources.IProject;
31
import org.eclipse.core.resources.IResource;
32
import org.eclipse.core.runtime.IAdaptable;
7
import org.eclipse.core.runtime.IAdaptable;
33
import org.eclipse.core.runtime.IPath;
34
import org.eclipse.core.runtime.IProgressMonitor;
35
import org.eclipse.core.runtime.IStatus;
36
import org.eclipse.core.runtime.OperationCanceledException;
37
import org.eclipse.core.runtime.Path;
38
import org.eclipse.core.runtime.Status;
39
import org.eclipse.core.runtime.SubProgressMonitor;
40
import org.eclipse.core.runtime.jobs.Job;
41
import org.eclipse.jdt.core.IClasspathEntry;
42
import org.eclipse.jdt.core.IJavaProject;
43
import org.eclipse.jdt.core.JavaCore;
44
import org.eclipse.jdt.launching.IVMInstall;
45
import org.eclipse.jdt.launching.IVMInstallType;
46
import org.eclipse.jdt.launching.JavaRuntime;
47
import org.eclipse.jdt.launching.LibraryLocation;
48
import org.eclipse.jface.action.IAction;
8
import org.eclipse.jface.action.IAction;
49
import org.eclipse.jface.viewers.ISelection;
9
import org.eclipse.jface.viewers.ISelection;
50
import org.eclipse.jface.viewers.IStructuredSelection;
10
import org.eclipse.jface.viewers.IStructuredSelection;
51
import org.eclipse.ui.IObjectActionDelegate;
11
import org.eclipse.ui.IObjectActionDelegate;
52
import org.eclipse.ui.IWorkbenchPart;
12
import org.eclipse.ui.IWorkbenchPart;
53
import org.maven.ide.eclipse.Maven2Plugin;
13
import org.maven.ide.eclipse.project.MavenEclipseProject;
54
import org.maven.ide.eclipse.MavenEmbedderCallback;
55
import org.maven.ide.eclipse.PluginConsoleEventMonitor;
56
import org.maven.ide.eclipse.TransferListenerAdapter;
57
import org.maven.ide.eclipse.preferences.Maven2PreferenceConstants;
58
14
59
15
60
public class UpdateSourcesAction implements IObjectActionDelegate {
16
public class UpdateSourcesAction implements IObjectActionDelegate {
61
  // private IAction action;
17
  // private IAction action;
62
  // private IWorkbenchPart targetPart;
18
  // private IWorkbenchPart targetPart;
63
  private ISelection selection;
19
  private ISelection selection;
64
  
65
20
66
  public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
21
  public void setActivePart(IAction action, IWorkbenchPart targetPart) {
67
    // this.action = action;
22
    // this.action = action;
68
    // this.targetPart = targetPart;
23
    // this.targetPart = targetPart;
69
  }
24
  }
70
25
71
  public void selectionChanged( IAction action, ISelection selection ) {
26
  public void selectionChanged(IAction action, ISelection selection) {
72
    // this.action = action;
27
    // this.action = action;
73
    this.selection = selection;
28
    this.selection = selection;
74
  }
29
  }
75
30
76
  
31
  public void run(IAction action) {
77
  public void run( IAction action ) {
32
    IStructuredSelection structuredSelection = (IStructuredSelection) selection;
78
    IStructuredSelection structuredSelection = ( IStructuredSelection ) selection;
33
    for(Iterator it = structuredSelection.iterator(); it.hasNext();) {
79
    for( Iterator it = structuredSelection.iterator(); it.hasNext(); ) {
80
      Object element = it.next();
34
      Object element = it.next();
81
      IProject project = null;
35
      IProject project = null;
82
      if( element instanceof IProject ) {
36
      if(element instanceof IProject) {
83
        project = ( IProject ) element;
37
        project = (IProject) element;
84
      } else if( element instanceof IAdaptable ) {
38
      } else if(element instanceof IAdaptable) {
85
        project = ( IProject ) ( ( IAdaptable ) element ).getAdapter( IProject.class );
39
        project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
86
      }
40
      }
87
      if( project != null ) {
41
      if(project != null) {
88
        new UpdateSourcesJob( project).schedule();
42
        MavenEclipseProject.scheduleUpdateSources(project);
89
      }
43
      }
90
    }
44
    }
91
  }
45
  }
92
46
93
  
94
  private static final class UpdateSourcesJob extends Job implements MavenEmbedderCallback {
95
    private final IProject project;
96
97
    private Set sources = new HashSet();
98
    private List sourceEntries = new ArrayList(); 
99
    private Map options = new HashMap();
100
101
    UpdateSourcesJob( IProject project) {
102
      super( "Updating "+project.getName()+" Sources");
103
      this.project = project;
104
    }
105
106
    protected IStatus run( IProgressMonitor monitor ) {
107
      IFile pom = project.getFile(Maven2Plugin.POM_FILE_NAME);
108
      if( !pom.exists()) {
109
        return Status.OK_STATUS;
110
      }
111
      
112
      monitor.beginTask( "Updating sources "+project.getName(), IProgressMonitor.UNKNOWN );
113
      try {
114
        Maven2Plugin.getDefault().executeInEmbedder(this, monitor);
115
        
116
        // TODO optimize project refresh
117
        monitor.subTask( "Refreshing" );
118
        project.refreshLocal( IResource.DEPTH_INFINITE, new SubProgressMonitor( monitor, 1) );
119
        
120
        monitor.subTask( "Configuring Build Path" );
121
        IJavaProject javaProject = JavaCore.create(project);
122
        
123
        setOption( javaProject, options, JavaCore.COMPILER_COMPLIANCE );
124
        setOption( javaProject, options, JavaCore.COMPILER_SOURCE);
125
        setOption( javaProject, options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
126
        
127
        String source = ( String ) options.get( JavaCore.COMPILER_SOURCE );
128
        if(source==null) {
129
          sourceEntries.add( JavaRuntime.getDefaultJREContainerEntry() );
130
        } else {
131
          sourceEntries.add( getJREContainer( source ) );
132
        }
133
        
134
        IClasspathEntry[] currentClasspath = javaProject.getRawClasspath();
135
        for( int i = 0; i < currentClasspath.length; i++ ) {
136
          // Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 
137
          IClasspathEntry entry = currentClasspath[i];
138
          if( entry.getEntryKind()==IClasspathEntry.CPE_CONTAINER ) {
139
            if( !JavaRuntime.JRE_CONTAINER.equals( entry.getPath().segment( 0 ) )) {
140
              sourceEntries.add( entry);
141
            }
142
          }
143
        }
144
        
145
        IClasspathEntry[] entries = ( IClasspathEntry[] ) sourceEntries.toArray( new IClasspathEntry[ sourceEntries.size()]);
146
        javaProject.setRawClasspath(entries, monitor);
147
        
148
        Maven2Plugin.getDefault().getConsole().logMessage("Updated source folders for project "+project.getName());
149
150
      } catch( Exception ex ) {
151
        String msg = "Unable to update source folders "+project.getName()+"; " +ex.toString();
152
        Maven2Plugin.getDefault().getConsole().logMessage( msg );
153
        // Maven2Plugin.log( msg, ex);
154
      } finally {
155
        monitor.done();
156
      }
157
      
158
      return Status.OK_STATUS;
159
    }
160
161
    private void setOption( IJavaProject javaProject, Map options, String name ) {
162
      String newValue = ( String ) options.get( name );
163
      if(newValue==null) {
164
        return;
165
      }
166
      String currentValue = javaProject.getOption( name, false );
167
      if(!newValue.equals( currentValue )) {
168
        javaProject.setOption( name, newValue );
169
      }
170
    }
171
    
172
    private IClasspathEntry getJREContainer( String version ) {
173
      int n = VERSIONS.indexOf( version );
174
      if(n>-1) {
175
        Map jreContainers = getJREContainers();
176
        for( int i = n; i < VERSIONS.size(); i++ ) {
177
          IClasspathEntry entry = ( IClasspathEntry ) jreContainers.get( version );
178
          if(entry!=null) {
179
            Maven2Plugin.getDefault().getConsole().logMessage( "JRE compliant to "+version+". "+entry );
180
            return entry;
181
          }
182
        }
183
      }
184
      IClasspathEntry entry = JavaRuntime.getDefaultJREContainerEntry();
185
      Maven2Plugin.getDefault().getConsole().logMessage( "No JRE compliant to "+version+". Using default JRE container "+entry );
186
      return entry;
187
    }
188
    
189
    private Map getJREContainers() {
190
      Map jreContainers = new HashMap();
191
      
192
      jreContainers.put( getJREVersion( JavaRuntime.getDefaultVMInstall() ), JavaRuntime.getDefaultJREContainerEntry());
193
      
194
      IVMInstallType[] installTypes = JavaRuntime.getVMInstallTypes();
195
      for( int i = 0; i < installTypes.length; i++ ) {
196
        IVMInstall[] installs = installTypes[i].getVMInstalls();
197
        for( int j = 0; j < installs.length; j++ ) {
198
          IVMInstall install = installs[j];
199
          String version = getJREVersion(install);
200
          if(!jreContainers.containsKey( version )) {
201
            // in Eclipse 3.2 one could use JavaRuntime.newJREContainerPath(install)
202
            IPath jreContainerPath = new Path(JavaRuntime.JRE_CONTAINER)            
203
                .append(install.getVMInstallType().getId())
204
                .append(install.getName());            
205
            jreContainers.put(version, JavaCore.newContainerEntry( jreContainerPath ));
206
          }
207
        }
208
      }
209
      
210
      return jreContainers;
211
    }
212
213
    private String getJREVersion( IVMInstall install ) {
214
      LibraryLocation[] libraryLocations = JavaRuntime.getLibraryLocations( install );
215
      if( libraryLocations != null ) {
216
        for( int k = 0; k < libraryLocations.length; k++ ) {
217
          IPath path = libraryLocations[k].getSystemLibraryPath();
218
          String jarName = path.lastSegment();
219
          if( "rt.jar".equals( jarName ) ) {
220
            try {
221
              JarFile jarFile = new JarFile( path.toFile() );
222
              Manifest manifest = jarFile.getManifest();
223
              Attributes attributes = manifest.getMainAttributes();
224
              return attributes.getValue( Attributes.Name.SPECIFICATION_VERSION );
225
            } catch( Exception ex ) {
226
              Maven2Plugin.getDefault().getConsole().logError( "Unable to read "+path+" "+ex.getMessage() );
227
            }
228
          }
229
        }
230
      }
231
      return null;
232
    }
233
    
234
    /**
235
     * @see MavenEmbedderCallback#run(MavenEmbedder, IProgressMonitor)
236
     */
237
    public Object run( MavenEmbedder mavenEmbedder, IProgressMonitor monitor ) {
238
      resolve( project.getFile(Maven2Plugin.POM_FILE_NAME), mavenEmbedder, monitor );
239
      return null;
240
    }
241
242
    private void resolve( IResource pomResource, MavenEmbedder mavenEmbedder, IProgressMonitor monitor ) {
243
      if(monitor.isCanceled()) {
244
        throw new OperationCanceledException();
245
      }
246
247
      Maven2Plugin plugin = Maven2Plugin.getDefault();
248
249
      String msg = "Reading "+pomResource.getFullPath();
250
      plugin.getConsole().logMessage( msg);
251
      
252
      monitor.subTask( "Reading "+pomResource.getFullPath() );
253
      File pomFile = pomResource.getLocation().toFile();
254
255
      MavenProject mavenProject;
256
      try {
257
        mavenProject = mavenEmbedder.readProject(pomFile);
258
      } catch( Exception ex) {
259
        plugin.getConsole().logError("Unable to read project "+pomResource.getFullPath()+"; "+ex.toString());
260
        return;
261
      }
262
263
      String source = getBuildOption( mavenProject, "maven-compiler-plugin", "source" );
264
      if(source!=null) {
265
        plugin.getConsole().logMessage( "Setting source compatibility: "+source );
266
        setVersion( options, JavaCore.COMPILER_SOURCE, source);
267
        setVersion( options, JavaCore.COMPILER_COMPLIANCE, source );
268
      }
269
      
270
      String target = getBuildOption( mavenProject, "maven-compiler-plugin", "target" );
271
      if(target!=null) {
272
        plugin.getConsole().logMessage( "Setting target compatibility: "+source );
273
        setVersion( options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, target );
274
      }
275
      
276
      monitor.subTask( "Generating Sources "+pomResource.getFullPath() );
277
      try {
278
        plugin.getConsole().logMessage("Generating sources "+pomResource.getFullPath());
279
        
280
        mavenEmbedder.execute( getExecutionRequest(pomFile, monitor, mavenEmbedder) );
281
        // TODO hook up console view
282
        // EventMonitor eventMonitor = new PluginConsoleEventMonitor();
283
        // mavenEmbedder.execute(mavenProject, goals, eventMonitor, transferListener, properties, f.getParentFile());
284
285
      } catch( Exception ex ) {
286
        plugin.getConsole().logError("Failed to run generate source goals "+pomResource.getFullPath()+" "+ex.getMessage());
287
      }
288
      
289
      File basedir = pomResource.getLocation().toFile().getParentFile();
290
      File projectBaseDir = project.getLocation().toFile();
291
      
292
      extractSourceDirs(project, mavenProject.getCompileSourceRoots(), basedir, projectBaseDir);
293
      extractSourceDirs(project, mavenProject.getTestCompileSourceRoots(), basedir, projectBaseDir);
294
      
295
      extractResourceDirs(project, mavenProject.getBuild().getResources(), basedir, projectBaseDir);
296
      extractResourceDirs(project, mavenProject.getBuild().getTestResources(), basedir, projectBaseDir);
297
      
298
      IContainer parent = pomResource.getParent();      
299
      List modules = mavenProject.getModules();
300
      for( Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled(); ) {
301
        if(monitor.isCanceled()) {
302
          throw new OperationCanceledException();
303
        }
304
        String module = ( String ) it.next();
305
        IResource memberPom = parent.findMember( module+"/"+Maven2Plugin.POM_FILE_NAME); //$NON-NLS-1$
306
        if(memberPom!=null) {
307
          resolve(memberPom, mavenEmbedder, monitor);
308
        }
309
      }
310
    }
311
    
312
    
313
    private MavenExecutionRequest getExecutionRequest(File pomFile, IProgressMonitor monitor, MavenEmbedder embedder) throws SettingsConfigurationException {
314
      List goals = Arrays.asList( "generate-sources,generate-resources,generate-test-sources,generate-test-resources".split(","));
315
316
      Properties properties = new Properties();                
317
318
      File userSettingsPath = embedder.getUserSettingsPath( null );
319
      File globalSettingsFile = embedder.getGlobalSettingsPath();
320
      
321
      Settings settings = embedder.buildSettings( 
322
          userSettingsPath,
323
          globalSettingsFile,
324
          false,  // interactive
325
          false,  // offline,
326
          false,  // usePluginRegistry,
327
          Boolean.FALSE);  // pluginUpdateOverride );
328
329
      String localRepositoryPath = System.getProperty(Maven2PreferenceConstants.P_LOCAL_REPOSITORY_DIR);
330
      if(localRepositoryPath==null || localRepositoryPath.trim().length()==0) {
331
        localRepositoryPath = embedder.getLocalRepositoryPath( settings );
332
      }
333
      
334
      MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest()
335
          .setPomFile( pomFile.getAbsolutePath() )
336
          .setBasedir( pomFile.getParentFile() )
337
          .setGoals( goals )
338
          .setSettings( settings )  // TODO
339
          .setProperties( properties )
340
          .setLocalRepositoryPath( localRepositoryPath )
341
          .setReactorActive( false )
342
          .setRecursive( true )
343
          .setShowErrors( true )  // TODO
344
          .setInteractive( false )
345
          .setLoggingLevel( MavenExecutionRequest.LOGGING_LEVEL_INFO )
346
          .activateDefaultEventMonitor()
347
          .addEventMonitor( new PluginConsoleEventMonitor() )
348
          .setTransferListener( new TransferListenerAdapter( monitor ) )
349
          .setFailureBehavior( MavenExecutionRequest.REACTOR_FAIL_AT_END )
350
          // .addActiveProfiles( activeProfiles )
351
          // .addInactiveProfiles( inactiveProfiles )
352
          .setOffline(Boolean.getBoolean(Maven2PreferenceConstants.P_OFFLINE))
353
          .setGlobalChecksumPolicy(System.getProperty(Maven2PreferenceConstants.P_GLOBAL_CHECKSUM_POLICY));
354
          // .setUpdateSnapshots( updateSnapshots )  // TODO
355
          ;
356
      
357
      return executionRequest;
358
    }
359
360
361
    public static final List VERSIONS = Arrays.asList( "1.1,1.2,1.3,1.4,1.5,1.6,1.7".split( "," ) ); 
362
    
363
    static void setVersion( Map options, String name, String value ) {
364
      if(value==null) {
365
        return;
366
      }
367
      String current = ( String ) options.get( name );
368
      if(current==null) {
369
        options.put( name, value );
370
      } else {
371
        int oldIndex = VERSIONS.indexOf( current );
372
        int newIndex = VERSIONS.indexOf( value.trim() );
373
        if(newIndex>oldIndex) {
374
          options.put( name, value );
375
        }
376
      }
377
    }
378
379
    void extractSourceDirs( IProject project, List sourceRoots, File basedir, File projectBaseDir ) {
380
      for( Iterator it = sourceRoots.iterator(); it.hasNext(); ) {
381
        String sourceRoot = ( String ) it.next();
382
        if( new File( sourceRoot ).isDirectory() ) {
383
          IResource r = project.findMember(toRelativeAndFixSeparator( projectBaseDir, sourceRoot ));
384
          if(r!=null && sources.add( r.getFullPath().toString())) {
385
            sourceEntries.add( JavaCore.newSourceEntry( r.getFullPath() /*, new IPath[] { new Path( "**"+"/.svn/"+"**")} */) );
386
            Maven2Plugin.getDefault().getConsole().logMessage( "Adding source folder " + r.getFullPath() );
387
          }
388
        }
389
      }
390
    }
391
392
    void extractResourceDirs(IProject project, List resources, File basedir, File projectBaseDir ) {
393
      for( Iterator it = resources.iterator(); it.hasNext(); ) {
394
        Resource resource = ( Resource ) it.next();
395
        File resourceDirectory = new File( resource.getDirectory() );
396
        if( resourceDirectory.exists() && resourceDirectory.isDirectory() ) {
397
          IResource r = project.findMember(toRelativeAndFixSeparator( projectBaseDir, resource.getDirectory() ));
398
          if(r!=null && sources.add( r.getFullPath().toString())) {
399
            sourceEntries.add( JavaCore.newSourceEntry( r.getFullPath(), new IPath[] { new Path("**") }, r.getFullPath()));  //, new IPath[] { new Path( "**"+"/.svn/"+"**")} ) );
400
            Maven2Plugin.getDefault().getConsole().logMessage( "Adding resource folder " + r.getFullPath() );
401
          }
402
        }
403
      }
404
    }
405
406
    private String toRelativeAndFixSeparator( File basedir, String absolutePath ) {
407
      String relative;
408
      if( absolutePath.equals( basedir.getAbsolutePath() ) ) {
409
        relative = ".";
410
      } else if( absolutePath.startsWith( basedir.getAbsolutePath() ) ) {
411
        relative = absolutePath.substring( basedir.getAbsolutePath().length() + 1 );
412
      } else {
413
        relative = absolutePath;
414
      }
415
      return relative.replace( '\\', '/' ); //$NON-NLS-1$ //$NON-NLS-2$
416
    }
417
418
    public static String getBuildOption( MavenProject project, String artifactId, String optionName ) {
419
      for( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); ) {
420
        Plugin plugin = ( Plugin ) it.next();
421
        if( artifactId.equals( plugin.getArtifactId() ) ) {
422
          Xpp3Dom o = ( Xpp3Dom ) plugin.getConfiguration();
423
          if( o != null && o.getChild( optionName ) != null ) {
424
            return o.getChild( optionName ).getValue();
425
          }
426
        }
427
      }
428
      return null;
429
    }
430
    
431
  }
432
433
}
47
}
434
(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/src/org/maven/ide/eclipse/project/MavenEclipseProject.java (+496 lines)
Line 0 Link Here
1
2
package org.maven.ide.eclipse.project;
3
4
import java.io.File;
5
import java.util.ArrayList;
6
import java.util.Arrays;
7
import java.util.HashMap;
8
import java.util.HashSet;
9
import java.util.Iterator;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Properties;
13
import java.util.Set;
14
import java.util.jar.Attributes;
15
import java.util.jar.JarFile;
16
import java.util.jar.Manifest;
17
18
import org.apache.maven.SettingsConfigurationException;
19
import org.apache.maven.embedder.MavenEmbedder;
20
import org.apache.maven.execution.DefaultMavenExecutionRequest;
21
import org.apache.maven.execution.MavenExecutionRequest;
22
import org.apache.maven.model.Plugin;
23
import org.apache.maven.model.Resource;
24
import org.apache.maven.project.MavenProject;
25
import org.apache.maven.settings.Settings;
26
27
import org.codehaus.plexus.util.xml.Xpp3Dom;
28
import org.eclipse.core.resources.IContainer;
29
import org.eclipse.core.resources.IFile;
30
import org.eclipse.core.resources.IProject;
31
import org.eclipse.core.resources.IProjectDescription;
32
import org.eclipse.core.resources.IResource;
33
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
35
import org.eclipse.core.runtime.IProgressMonitor;
36
import org.eclipse.core.runtime.IStatus;
37
import org.eclipse.core.runtime.OperationCanceledException;
38
import org.eclipse.core.runtime.Path;
39
import org.eclipse.core.runtime.Status;
40
import org.eclipse.core.runtime.SubProgressMonitor;
41
import org.eclipse.core.runtime.jobs.Job;
42
import org.eclipse.jdt.core.IClasspathContainer;
43
import org.eclipse.jdt.core.IClasspathEntry;
44
import org.eclipse.jdt.core.IJavaProject;
45
import org.eclipse.jdt.core.JavaCore;
46
import org.eclipse.jdt.launching.IVMInstall;
47
import org.eclipse.jdt.launching.IVMInstallType;
48
import org.eclipse.jdt.launching.JavaRuntime;
49
import org.eclipse.jdt.launching.LibraryLocation;
50
import org.maven.ide.eclipse.Maven2Plugin;
51
import org.maven.ide.eclipse.MavenEmbedderCallback;
52
import org.maven.ide.eclipse.PluginConsoleEventMonitor;
53
import org.maven.ide.eclipse.TransferListenerAdapter;
54
import org.maven.ide.eclipse.container.Maven2ClasspathContainer;
55
import org.maven.ide.eclipse.container.Maven2ClasspathContainerInitializer;
56
import org.maven.ide.eclipse.preferences.Maven2PreferenceConstants;
57
58
59
/**
60
 * Basic helper class that can be used to enable the Maven tooling on a project and also programatically
61
 * update the source folders for the projects
62
 *
63
 * @author Philip Dodds
64
 */
65
public class MavenEclipseProject {
66
67
  private static final class UpdateSourcesJob extends Job implements MavenEmbedderCallback {
68
69
    private final IProject project;
70
71
    private Set sources = new HashSet();
72
73
    private List sourceEntries = new ArrayList();
74
75
    private Map options = new HashMap();
76
77
    UpdateSourcesJob(IProject project) {
78
      super("Updating " + project.getName() + " Sources");
79
      this.project = project;
80
    }
81
82
    protected IStatus run(IProgressMonitor monitor) {
83
      IFile pom = project.getFile(Maven2Plugin.POM_FILE_NAME);
84
      if(!pom.exists()) {
85
        return Status.OK_STATUS;
86
      }
87
88
      monitor.beginTask("Updating sources " + project.getName(), IProgressMonitor.UNKNOWN);
89
      try {
90
        Maven2Plugin.getDefault().executeInEmbedder(this, monitor);
91
92
        // TODO optimize project refresh
93
        monitor.subTask("Refreshing");
94
        project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1));
95
96
        monitor.subTask("Configuring Build Path");
97
        IJavaProject javaProject = JavaCore.create(project);
98
99
        setOption(javaProject, options, JavaCore.COMPILER_COMPLIANCE);
100
        setOption(javaProject, options, JavaCore.COMPILER_SOURCE);
101
        setOption(javaProject, options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
102
103
        String source = (String) options.get(JavaCore.COMPILER_SOURCE);
104
        if(source == null) {
105
          sourceEntries.add(JavaRuntime.getDefaultJREContainerEntry());
106
        } else {
107
          sourceEntries.add(getJREContainer(source));
108
        }
109
110
        IClasspathEntry[] currentClasspath = javaProject.getRawClasspath();
111
        for(int i = 0; i < currentClasspath.length; i++ ) {
112
          // Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 
113
          IClasspathEntry entry = currentClasspath[i];
114
          if(entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
115
            if(!JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) {
116
              sourceEntries.add(entry);
117
            }
118
          }
119
        }
120
121
        IClasspathEntry[] entries = (IClasspathEntry[]) sourceEntries
122
            .toArray(new IClasspathEntry[sourceEntries.size()]);
123
        javaProject.setRawClasspath(entries, monitor);
124
125
        Maven2Plugin.getDefault().getConsole().logMessage("Updated source folders for project " + project.getName());
126
127
      } catch(Exception ex) {
128
        String msg = "Unable to update source folders " + project.getName() + "; " + ex.toString();
129
        Maven2Plugin.getDefault().getConsole().logMessage(msg);
130
        // Maven2Plugin.log( msg, ex);
131
      } finally {
132
        monitor.done();
133
      }
134
135
      return Status.OK_STATUS;
136
    }
137
138
    private void setOption(IJavaProject javaProject, Map options, String name) {
139
      String newValue = (String) options.get(name);
140
      if(newValue == null) {
141
        return;
142
      }
143
      String currentValue = javaProject.getOption(name, false);
144
      if(!newValue.equals(currentValue)) {
145
        javaProject.setOption(name, newValue);
146
      }
147
    }
148
149
    private IClasspathEntry getJREContainer(String version) {
150
      int n = VERSIONS.indexOf(version);
151
      if(n > -1) {
152
        Map jreContainers = getJREContainers();
153
        for(int i = n; i < VERSIONS.size(); i++ ) {
154
          IClasspathEntry entry = (IClasspathEntry) jreContainers.get(version);
155
          if(entry != null) {
156
            Maven2Plugin.getDefault().getConsole().logMessage("JRE compliant to " + version + ". " + entry);
157
            return entry;
158
          }
159
        }
160
      }
161
      IClasspathEntry entry = JavaRuntime.getDefaultJREContainerEntry();
162
      Maven2Plugin.getDefault().getConsole().logMessage(
163
          "No JRE compliant to " + version + ". Using default JRE container " + entry);
164
      return entry;
165
    }
166
167
    private Map getJREContainers() {
168
      Map jreContainers = new HashMap();
169
170
      jreContainers.put(getJREVersion(JavaRuntime.getDefaultVMInstall()), JavaRuntime.getDefaultJREContainerEntry());
171
172
      IVMInstallType[] installTypes = JavaRuntime.getVMInstallTypes();
173
      for(int i = 0; i < installTypes.length; i++ ) {
174
        IVMInstall[] installs = installTypes[i].getVMInstalls();
175
        for(int j = 0; j < installs.length; j++ ) {
176
          IVMInstall install = installs[j];
177
          String version = getJREVersion(install);
178
          if(!jreContainers.containsKey(version)) {
179
            // in Eclipse 3.2 one could use JavaRuntime.newJREContainerPath(install)
180
            IPath jreContainerPath = new Path(JavaRuntime.JRE_CONTAINER).append(install.getVMInstallType().getId())
181
                .append(install.getName());
182
            jreContainers.put(version, JavaCore.newContainerEntry(jreContainerPath));
183
          }
184
        }
185
      }
186
187
      return jreContainers;
188
    }
189
190
    private String getJREVersion(IVMInstall install) {
191
      LibraryLocation[] libraryLocations = JavaRuntime.getLibraryLocations(install);
192
      if(libraryLocations != null) {
193
        for(int k = 0; k < libraryLocations.length; k++ ) {
194
          IPath path = libraryLocations[k].getSystemLibraryPath();
195
          String jarName = path.lastSegment();
196
          if("rt.jar".equals(jarName)) {
197
            try {
198
              JarFile jarFile = new JarFile(path.toFile());
199
              Manifest manifest = jarFile.getManifest();
200
              Attributes attributes = manifest.getMainAttributes();
201
              return attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
202
            } catch(Exception ex) {
203
              Maven2Plugin.getDefault().getConsole().logError("Unable to read " + path + " " + ex.getMessage());
204
            }
205
          }
206
        }
207
      }
208
      return null;
209
    }
210
211
    /**
212
     * @see MavenEmbedderCallback#run(MavenEmbedder, IProgressMonitor)
213
     */
214
    public Object run(MavenEmbedder mavenEmbedder, IProgressMonitor monitor) {
215
      resolve(project.getFile(Maven2Plugin.POM_FILE_NAME), mavenEmbedder, monitor);
216
      return null;
217
    }
218
219
    private void resolve(IResource pomResource, MavenEmbedder mavenEmbedder, IProgressMonitor monitor) {
220
      if(monitor.isCanceled()) {
221
        throw new OperationCanceledException();
222
      }
223
224
      Maven2Plugin plugin = Maven2Plugin.getDefault();
225
226
      String msg = "Reading " + pomResource.getFullPath();
227
      plugin.getConsole().logMessage(msg);
228
229
      monitor.subTask("Reading " + pomResource.getFullPath());
230
      File pomFile = pomResource.getLocation().toFile();
231
232
      MavenProject mavenProject;
233
      try {
234
        mavenProject = mavenEmbedder.readProject(pomFile);
235
      } catch(Exception ex) {
236
        plugin.getConsole().logError("Unable to read project " + pomResource.getFullPath() + "; " + ex.toString());
237
        return;
238
      }
239
240
      String source = getBuildOption(mavenProject, "maven-compiler-plugin", "source");
241
      if(source != null) {
242
        plugin.getConsole().logMessage("Setting source compatibility: " + source);
243
        setVersion(options, JavaCore.COMPILER_SOURCE, source);
244
        setVersion(options, JavaCore.COMPILER_COMPLIANCE, source);
245
      }
246
247
      String target = getBuildOption(mavenProject, "maven-compiler-plugin", "target");
248
      if(target != null) {
249
        plugin.getConsole().logMessage("Setting target compatibility: " + source);
250
        setVersion(options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, target);
251
      }
252
253
      monitor.subTask("Generating Sources " + pomResource.getFullPath());
254
      try {
255
        plugin.getConsole().logMessage("Generating sources " + pomResource.getFullPath());
256
257
        mavenEmbedder.execute(getExecutionRequest(pomFile, monitor, mavenEmbedder));
258
        // TODO hook up console view
259
        // EventMonitor eventMonitor = new PluginConsoleEventMonitor();
260
        // mavenEmbedder.execute(mavenProject, goals, eventMonitor, transferListener, properties, f.getParentFile());
261
262
      } catch(Exception ex) {
263
        plugin.getConsole().logError(
264
            "Failed to run generate source goals " + pomResource.getFullPath() + " " + ex.getMessage());
265
      }
266
267
      File basedir = pomResource.getLocation().toFile().getParentFile();
268
      File projectBaseDir = project.getLocation().toFile();
269
270
      extractSourceDirs(project, mavenProject.getCompileSourceRoots(), basedir, projectBaseDir);
271
      extractSourceDirs(project, mavenProject.getTestCompileSourceRoots(), basedir, projectBaseDir);
272
273
      extractResourceDirs(project, mavenProject.getBuild().getResources(), basedir, projectBaseDir);
274
      extractResourceDirs(project, mavenProject.getBuild().getTestResources(), basedir, projectBaseDir);
275
276
      IContainer parent = pomResource.getParent();
277
      List modules = mavenProject.getModules();
278
      for(Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled();) {
279
        if(monitor.isCanceled()) {
280
          throw new OperationCanceledException();
281
        }
282
        String module = (String) it.next();
283
        IResource memberPom = parent.findMember(module + "/" + Maven2Plugin.POM_FILE_NAME); //$NON-NLS-1$
284
        if(memberPom != null) {
285
          resolve(memberPom, mavenEmbedder, monitor);
286
        }
287
      }
288
    }
289
290
    private MavenExecutionRequest getExecutionRequest(File pomFile, IProgressMonitor monitor, MavenEmbedder embedder)
291
        throws SettingsConfigurationException {
292
      List goals = Arrays.asList("generate-sources,generate-resources,generate-test-sources,generate-test-resources"
293
          .split(","));
294
295
      Properties properties = new Properties();
296
297
      File userSettingsPath = embedder.getUserSettingsPath(null);
298
      File globalSettingsFile = embedder.getGlobalSettingsPath();
299
300
      Settings settings = embedder.buildSettings(userSettingsPath, globalSettingsFile, false, // interactive
301
          false, // offline,
302
          false, // usePluginRegistry,
303
          Boolean.FALSE); // pluginUpdateOverride );
304
305
      String localRepositoryPath = System.getProperty(Maven2PreferenceConstants.P_LOCAL_REPOSITORY_DIR);
306
      if(localRepositoryPath == null || localRepositoryPath.trim().length() == 0) {
307
        localRepositoryPath = embedder.getLocalRepositoryPath(settings);
308
      }
309
310
      MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest().setPomFile(pomFile.getAbsolutePath())
311
          .setBasedir(pomFile.getParentFile()).setGoals(goals).setSettings(settings)
312
          // TODO
313
          .setProperties(properties).setLocalRepositoryPath(localRepositoryPath).setReactorActive(false).setRecursive(
314
              true).setShowErrors(true)
315
          // TODO
316
          .setInteractive(false).setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO)
317
          .activateDefaultEventMonitor().addEventMonitor(new PluginConsoleEventMonitor()).setTransferListener(
318
              new TransferListenerAdapter(monitor)).setFailureBehavior(MavenExecutionRequest.REACTOR_FAIL_AT_END)
319
          // .addActiveProfiles( activeProfiles )
320
          // .addInactiveProfiles( inactiveProfiles )
321
          .setOffline(Boolean.getBoolean(Maven2PreferenceConstants.P_OFFLINE)).setGlobalChecksumPolicy(
322
              System.getProperty(Maven2PreferenceConstants.P_GLOBAL_CHECKSUM_POLICY));
323
      // .setUpdateSnapshots( updateSnapshots )  // TODO
324
      ;
325
326
      return executionRequest;
327
    }
328
329
    public static final List VERSIONS = Arrays.asList("1.1,1.2,1.3,1.4,1.5,1.6,1.7".split(","));
330
331
    static void setVersion(Map options, String name, String value) {
332
      if(value == null) {
333
        return;
334
      }
335
      String current = (String) options.get(name);
336
      if(current == null) {
337
        options.put(name, value);
338
      } else {
339
        int oldIndex = VERSIONS.indexOf(current);
340
        int newIndex = VERSIONS.indexOf(value.trim());
341
        if(newIndex > oldIndex) {
342
          options.put(name, value);
343
        }
344
      }
345
    }
346
347
    void extractSourceDirs(IProject project, List sourceRoots, File basedir, File projectBaseDir) {
348
      for(Iterator it = sourceRoots.iterator(); it.hasNext();) {
349
        String sourceRoot = (String) it.next();
350
        if(new File(sourceRoot).isDirectory()) {
351
          IResource r = project.findMember(toRelativeAndFixSeparator(projectBaseDir, sourceRoot));
352
          if(r != null && sources.add(r.getFullPath().toString())) {
353
            sourceEntries.add(JavaCore
354
                .newSourceEntry(r.getFullPath() /*, new IPath[] { new Path( "**"+"/.svn/"+"**")} */));
355
            Maven2Plugin.getDefault().getConsole().logMessage("Adding source folder " + r.getFullPath());
356
          }
357
        }
358
      }
359
    }
360
361
    void extractResourceDirs(IProject project, List resources, File basedir, File projectBaseDir) {
362
      for(Iterator it = resources.iterator(); it.hasNext();) {
363
        Resource resource = (Resource) it.next();
364
        File resourceDirectory = new File(resource.getDirectory());
365
        if(resourceDirectory.exists() && resourceDirectory.isDirectory()) {
366
          IResource r = project.findMember(toRelativeAndFixSeparator(projectBaseDir, resource.getDirectory()));
367
          if(r != null && sources.add(r.getFullPath().toString())) {
368
            sourceEntries.add(JavaCore.newSourceEntry(r.getFullPath(), new IPath[] {new Path("**")}, r.getFullPath())); //, new IPath[] { new Path( "**"+"/.svn/"+"**")} ) );
369
            Maven2Plugin.getDefault().getConsole().logMessage("Adding resource folder " + r.getFullPath());
370
          }
371
        }
372
      }
373
    }
374
375
    private String toRelativeAndFixSeparator(File basedir, String absolutePath) {
376
      String relative;
377
      if(absolutePath.equals(basedir.getAbsolutePath())) {
378
        relative = ".";
379
      } else if(absolutePath.startsWith(basedir.getAbsolutePath())) {
380
        relative = absolutePath.substring(basedir.getAbsolutePath().length() + 1);
381
      } else {
382
        relative = absolutePath;
383
      }
384
      return relative.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$
385
    }
386
387
    public static String getBuildOption(MavenProject project, String artifactId, String optionName) {
388
      for(Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();) {
389
        Plugin plugin = (Plugin) it.next();
390
        if(artifactId.equals(plugin.getArtifactId())) {
391
          Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration();
392
          if(o != null && o.getChild(optionName) != null) {
393
            return o.getChild(optionName).getValue();
394
          }
395
        }
396
      }
397
      return null;
398
    }
399
400
  }
401
402
  public static void scheduleUpdateSources(IProject project) {
403
    new UpdateSourcesJob(project).schedule();
404
  }
405
406
  public static void updateSources(IProject project) throws InterruptedException {
407
    UpdateSourcesJob job = new UpdateSourcesJob(project);
408
    job.schedule();
409
    job.join();
410
  }
411
412
  public static void enableNature(IProject project) {
413
    try {
414
      ArrayList newNatures = new ArrayList();
415
      newNatures.add(JavaCore.NATURE_ID);
416
      newNatures.add(Maven2Plugin.NATURE_ID);
417
418
      IProjectDescription description = project.getDescription();
419
      String[] natures = description.getNatureIds();
420
      for(int i = 0; i < natures.length; ++i) {
421
        String id = natures[i];
422
        if(!Maven2Plugin.NATURE_ID.equals(id) && !JavaCore.NATURE_ID.equals(natures[i])) {
423
          newNatures.add(natures[i]);
424
        }
425
      }
426
      description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()]));
427
      project.setDescription(description, null);
428
429
      IJavaProject javaProject = JavaCore.create(project);
430
      if(javaProject != null) {
431
        IClasspathContainer maven2ClasspathContainer = Maven2ClasspathContainerInitializer
432
            .getMaven2ClasspathContainer(javaProject);
433
        IClasspathEntry[] containerEntries = maven2ClasspathContainer.getClasspathEntries();
434
        HashSet containerEntrySet = new HashSet();
435
        for(int i = 0; i < containerEntries.length; i++ ) {
436
          containerEntrySet.add(containerEntries[i].getPath().toString());
437
        }
438
439
        // remove classpath container from JavaProject
440
        IClasspathEntry[] entries = javaProject.getRawClasspath();
441
        ArrayList newEntries = new ArrayList();
442
        for(int i = 0; i < entries.length; i++ ) {
443
          IClasspathEntry entry = entries[i];
444
          if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entry.getPath())
445
              && !containerEntrySet.contains(entry.getPath().toString())) {
446
            newEntries.add(entry);
447
          }
448
        }
449
        newEntries.add(JavaCore.newContainerEntry(new Path(Maven2Plugin.CONTAINER_ID)));
450
451
        javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]),
452
            null);
453
      }
454
455
    } catch(CoreException ex) {
456
      Maven2Plugin.getDefault().getConsole().logError("Can't enable nature " + ex.toString());
457
      Maven2Plugin.log(ex);
458
459
    }
460
  }
461
462
  public static void disableNature(IProject project) {
463
    try {
464
      project.deleteMarkers(Maven2Plugin.MARKER_ID, true, IResource.DEPTH_INFINITE);
465
466
      IProjectDescription description = project.getDescription();
467
      String[] natures = description.getNatureIds();
468
      ArrayList newNatures = new ArrayList();
469
      for(int i = 0; i < natures.length; ++i) {
470
        if(!Maven2Plugin.NATURE_ID.equals(natures[i])) {
471
          newNatures.add(natures[i]);
472
        }
473
      }
474
      description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()]));
475
      project.setDescription(description, null);
476
477
      IJavaProject javaProject = JavaCore.create(project);
478
      if(javaProject != null) {
479
        // remove classpatch container from JavaProject
480
        IClasspathEntry[] entries = javaProject.getRawClasspath();
481
        ArrayList newEntries = new ArrayList();
482
        for(int i = 0; i < entries.length; i++ ) {
483
          if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entries[i].getPath())) {
484
            newEntries.add(entries[i]);
485
          }
486
        }
487
        javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]),
488
            null);
489
      }
490
491
    } catch(CoreException ex) {
492
      Maven2Plugin.getDefault().getConsole().logError("Can't disable nature " + ex.toString());
493
      Maven2Plugin.log(ex);
494
    }
495
  }
496
}
(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/build.xml (+218 lines)
Line 0 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project name="org.maven.ide.eclipse" default="build.jars" basedir=".">
3
4
	<property name="basews" value="${ws}"/>
5
	<property name="baseos" value="${os}"/>
6
	<property name="basearch" value="${arch}"/>
7
	<property name="basenl" value="${nl}"/>
8
9
	<!-- Compiler settings. -->
10
	<property name="javacFailOnError" value="false"/>
11
	<property name="javacDebugInfo" value="on"/>
12
	<property name="javacVerbose" value="false"/>
13
	<property name="logExtension" value=".log"/>
14
	<property name="compilerArg" value=""/>
15
	<property name="javacSource" value="1.3"/>
16
	<property name="javacTarget" value="1.2"/>
17
	<path id="path_bootclasspath">
18
		<fileset dir="${java.home}/lib">
19
			<include name="*.jar"/>
20
		</fileset>
21
	</path>
22
	<property name="bootclasspath" refid="path_bootclasspath"/>
23
	<property name="bundleJavacSource" value="${javacSource}"/>
24
	<property name="bundleJavacTarget" value="${javacTarget}"/>
25
	<property name="bundleBootClasspath" value="${bootclasspath}"/>
26
27
	<target name="init" depends="properties">
28
		<condition property="pluginTemp" value="${buildTempFolder}/plugins">
29
			<isset property="buildTempFolder"/>
30
		</condition>
31
		<property name="pluginTemp" value="${basedir}"/>
32
		<condition property="build.result.folder" value="${pluginTemp}/org.maven.ide.eclipse">
33
			<isset property="buildTempFolder"/>
34
		</condition>
35
		<property name="build.result.folder" value="${basedir}"/>
36
		<property name="temp.folder" value="${basedir}/temp.folder"/>
37
		<property name="plugin.destination" value="${basedir}"/>
38
	</target>
39
40
	<target name="properties" if="eclipse.running">
41
		<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
42
43
	</target>
44
45
	<target name="build.update.jar" depends="init" description="Build the plug-in: org.maven.ide.eclipse for an update site.">
46
		<delete dir="${temp.folder}"/>
47
		<mkdir dir="${temp.folder}"/>
48
		<antcall target="build.jars"/>
49
		<antcall target="gather.bin.parts">
50
			<param name="destination.temp.folder" value="${temp.folder}/"/>
51
		</antcall>
52
		<zip destfile="${plugin.destination}/org.maven.ide.eclipse_0.0.10.jar" basedir="${temp.folder}/org.maven.ide.eclipse_0.0.10" filesonly="false" whenempty="skip" update="false"/>
53
		<delete dir="${temp.folder}"/>
54
	</target>
55
56
	<target name="m2plugin.jar" depends="init" unless="m2plugin.jar" description="Create jar: org.maven.ide.eclipse m2plugin.jar.">
57
		<delete dir="${temp.folder}/m2plugin.jar.bin"/>
58
		<mkdir dir="${temp.folder}/m2plugin.jar.bin"/>
59
		<path id="m2plugin.jar.classpath">
60
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.runtime_3.2.0.v20060603.jar"/>
61
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.osgi_3.2.0.v20060601.jar"/>
62
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.equinox.common_3.2.0.v20060603.jar"/>
63
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.jobs_3.2.0.v20060603.jar"/>
64
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.0.v20060603/runtime_registry_compatibility.jar"/>
65
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.runtime.compatibility.registry_3.2.0.v20060603/@dot"/>
66
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.equinox.registry_3.2.0.v20060601.jar"/>
67
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.apache.xerces_2.8.0.v200606131651/resolver.jar"/>
68
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.apache.xerces_2.8.0.v200606131651/xercesImpl.jar"/>
69
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.apache.xerces_2.8.0.v200606131651/xml-apis.jar"/>
70
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.equinox.preferences_3.2.0.v20060601.jar"/>
71
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.contenttype_3.2.0.v20060603.jar"/>
72
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.runtime.compatibility.auth_3.2.0.v20060601.jar"/>
73
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.resources_3.2.0.v20060603.jar"/>
74
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.resources.compatibility_3.2.0.v20060603.jar"/>
75
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.resources.win32_3.2.0.v20060603.jar"/>
76
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.runtime.compatibility_3.1.100.v20060603.jar"/>
77
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.update.configurator_3.2.0.v20060605.jar"/>
78
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ant.core_3.1.100.v20060531.jar"/>
79
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.variables_3.1.100.v20060605.jar"/>
80
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.expressions_3.2.0.v20060605-1400.jar"/>
81
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.filesystem_1.0.0.v20060603.jar"/>
82
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.filesystem.win32.x86_1.0.0.v20060603.jar"/>
83
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jface.text_3.2.0.v20060605-1400.jar"/>
84
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/com.ibm.icu_3.4.4.1.jar"/>
85
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.text_3.2.0.v20060605-1400.jar"/>
86
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.commands_3.2.0.I20060605-1400.jar"/>
87
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.swt_3.2.0.v3232o.jar"/>
88
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.swt.win32.win32.x86_3.2.0.v3232m.jar"/>
89
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jface_3.2.0.I20060605-1400.jar"/>
90
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.core_3.2.0.v_671.jar"/>
91
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.team.core_3.2.0.I200606051140.jar"/>
92
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.ui_3.2.0.v20060605-1400.jar"/>
93
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui_3.2.0.I20060605-1400.jar"/>
94
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.workbench_3.2.0.I20060605-1400.jar"/>
95
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.workbench.compatibility_3.2.0.I20060605-1400/@dot"/>
96
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.workbench.compatibility_3.2.0.I20060605-1400/compatibility.jar"/>
97
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.help_3.2.0.v20060602.jar"/>
98
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.console_3.1.100.v20060605.jar"/>
99
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.workbench.texteditor_3.2.0.v20060605-1400.jar"/>
100
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.search_3.2.0.v20060605-1400.jar"/>
101
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.core.filebuffers_3.2.0.v20060605-1400.jar"/>
102
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.ide_3.2.0.I20060605-1400.jar"/>
103
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.win32_3.2.0.I20060605-1400.jar"/>
104
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.views_3.2.0.I20060605-1400.jar"/>
105
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.update.core_3.2.0.v20060605.jar"/>
106
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.update.core.win32_3.2.0.v20060605.jar"/>
107
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.update.ui_3.2.0.v20060605.jar"/>
108
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.forms_3.2.0.v20060602.jar"/>
109
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.debug.core_3.2.0.v20060605.jar"/>
110
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.debug.ui_3.2.0.v20060605.jar"/>
111
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.editors_3.2.0.v20060605-1400.jar"/>
112
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.launching_3.2.0.v20060605.jar"/>
113
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.debug_3.2.0.v20060605/jdi.jar"/>
114
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.debug_3.2.0.v20060605/jdimodel.jar"/>
115
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.debug_3.2.0.v20060605/tools.jar"/>
116
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.compare_3.2.0.v20060605.jar"/>
117
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.team.ui_3.2.0.I200606051140.jar"/>
118
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.navigator_3.2.0.I20060605-1400.jar"/>
119
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.navigator.resources_3.2.0.I20060605-1400.jar"/>
120
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ui.views.properties.tabbed_3.2.0.I20060605-1400.jar"/>
121
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ltk.core.refactoring_3.2.0.v20060605-1400.jar"/>
122
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.ltk.ui.refactoring_3.2.0.v20060605-1400.jar"/>
123
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.core.manipulation_1.0.0.v20060605-1400.jar"/>
124
			<pathelement path="../../../../devtools/eclipse-3.2/eclipse/plugins/org.eclipse.jdt.debug.ui_3.2.0.v20060605.jar"/>
125
			<pathelement path="lib/lucene-core-2.0.0.jar"/>
126
			<pathelement path="${build.result.folder}/../org.maven.ide.eclipse/lib/lucene-core-2.0.0.jar"/>
127
			<pathelement path="lib/maven-embedder-2.1-20060530210557-dep.jar"/>
128
			<pathelement path="${build.result.folder}/../org.maven.ide.eclipse/lib/maven-embedder-2.1-20060530210557-dep.jar"/>
129
		</path>
130
		<!-- compile the source code -->
131
		<javac destdir="${temp.folder}/m2plugin.jar.bin" failonerror="${javacFailOnError}" verbose="${javacVerbose}" debug="${javacDebugInfo}" includeAntRuntime="no" bootclasspath="${bundleBootClasspath}" source="${bundleJavacSource}" target="${bundleJavacTarget}"		>
132
			<compilerarg line="${compilerArg}" compiler="${build.compiler}"/>
133
			<classpath refid="m2plugin.jar.classpath" />
134
			<src path="src/"			/>
135
			<compilerarg value="@${basedir}/javaCompiler.m2plugin.jar.args" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
136
			<compilerarg line="-log '${temp.folder}/m2plugin.jar.bin${logExtension}'" compiler="org.eclipse.jdt.core.JDTCompilerAdapter"/>
137
		</javac>
138
		<!-- Copy necessary resources -->
139
		<copy todir="${temp.folder}/m2plugin.jar.bin" failonerror="true" overwrite="false">
140
			<fileset dir="src/" excludes="**/*.java, **/package.htm*"			/>
141
		</copy>
142
		<mkdir dir="${build.result.folder}"/>
143
		<jar destfile="${build.result.folder}/m2plugin.jar" basedir="${temp.folder}/m2plugin.jar.bin"/>
144
		<delete dir="${temp.folder}/m2plugin.jar.bin"/>
145
	</target>
146
147
	<target name="m2pluginsrc.zip" depends="init" unless="m2pluginsrc.zip">
148
		<mkdir dir="${build.result.folder}"/>
149
		<zip destfile="${build.result.folder}/m2pluginsrc.zip" filesonly="false" whenempty="skip" update="false">
150
			<fileset dir="src/" includes="**/*.java"			/>
151
		</zip>
152
	</target>
153
154
	<target name="build.jars" depends="init" description="Build all the jars for the plug-in: org.maven.ide.eclipse.">
155
		<available property="m2plugin.jar" file="${build.result.folder}/m2plugin.jar"/>
156
		<antcall target="m2plugin.jar"/>
157
	</target>
158
159
	<target name="build.sources" depends="init">
160
		<available property="m2pluginsrc.zip" file="${build.result.folder}/m2pluginsrc.zip"/>
161
		<antcall target="m2pluginsrc.zip"/>
162
	</target>
163
164
	<target name="gather.bin.parts" depends="init" if="destination.temp.folder">
165
		<mkdir dir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10"/>
166
		<copy todir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10" failonerror="true" overwrite="false">
167
			<fileset dir="${build.result.folder}" includes="m2plugin.jar"			/>
168
		</copy>
169
		<copy todir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10" failonerror="true" overwrite="false">
170
			<fileset dir="${basedir}" includes="plugin.xml,META-INF/,m2plugin.jar,central.zip,icons/,about.ini,about.properties,plugin.properties,.options,lib/lucene-core-2.0.0.jar,lib/maven-embedder-2.1-20060530210557-dep.jar"			/>
171
		</copy>
172
	</target>
173
174
	<target name="build.zips" depends="init">
175
	</target>
176
177
	<target name="gather.sources" depends="init" if="destination.temp.folder">
178
		<mkdir dir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10"/>
179
		<copy file="${build.result.folder}/m2pluginsrc.zip" todir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10" failonerror="false" overwrite="false"/>
180
	</target>
181
182
	<target name="gather.logs" depends="init" if="destination.temp.folder">
183
		<mkdir dir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10"/>
184
		<copy file="${temp.folder}/m2plugin.jar.bin${logExtension}" todir="${destination.temp.folder}/org.maven.ide.eclipse_0.0.10" failonerror="false" overwrite="false"/>
185
	</target>
186
187
	<target name="clean" depends="init" description="Clean the plug-in: org.maven.ide.eclipse of all the zips, jars and logs created.">
188
		<delete file="${build.result.folder}/m2plugin.jar"/>
189
		<delete file="${build.result.folder}/m2pluginsrc.zip"/>
190
		<delete file="${plugin.destination}/org.maven.ide.eclipse_0.0.10.jar"/>
191
		<delete file="${plugin.destination}/org.maven.ide.eclipse_0.0.10.zip"/>
192
		<delete dir="${temp.folder}"/>
193
	</target>
194
195
	<target name="refresh" depends="init" if="eclipse.running" description="Refresh this folder.">
196
		<eclipse.convertPath fileSystemPath="C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse" property="resourcePath"/>
197
		<eclipse.refreshLocal resource="${resourcePath}" depth="infinite"/>
198
	</target>
199
200
	<target name="zip.plugin" depends="init" description="Create a zip containing all the elements for the plug-in: org.maven.ide.eclipse.">
201
		<delete dir="${temp.folder}"/>
202
		<mkdir dir="${temp.folder}"/>
203
		<antcall target="build.jars"/>
204
		<antcall target="build.sources"/>
205
		<antcall target="gather.bin.parts">
206
			<param name="destination.temp.folder" value="${temp.folder}/"/>
207
		</antcall>
208
		<antcall target="gather.sources">
209
			<param name="destination.temp.folder" value="${temp.folder}/"/>
210
		</antcall>
211
		<delete>
212
			<fileset dir="${temp.folder}" includes="**/*.bin${logExtension}"			/>
213
		</delete>
214
		<zip destfile="${plugin.destination}/org.maven.ide.eclipse_0.0.10.zip" basedir="${temp.folder}" filesonly="true" whenempty="skip" update="false"/>
215
		<delete dir="${temp.folder}"/>
216
	</target>
217
218
</project>
(-)C:/dev/workspaces/fuse-tooling/org.maven.ide.eclipse/META-INF/MANIFEST.MF (+3 lines)
Lines 29-31 Link Here
29
Bundle-ClassPath: m2plugin.jar,
29
Bundle-ClassPath: m2plugin.jar,
30
 lib/lucene-core-2.0.0.jar,
30
 lib/lucene-core-2.0.0.jar,
31
 lib/maven-embedder-2.1-20060530210557-dep.jar
31
 lib/maven-embedder-2.1-20060530210557-dep.jar
32
Export-Package: org.maven.ide.eclipse,
33
 org.maven.ide.eclipse.launch,
34
 org.maven.ide.eclipse.project

Return to bug 154251