-
Notifications
You must be signed in to change notification settings - Fork 6
/
EclipsePlugin.scala
280 lines (249 loc) · 9.36 KB
/
EclipsePlugin.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
package com.carrotgarden.maven.scalor
import com.carrotgarden.maven.tools.Description
import org.apache.maven.plugin.MojoExecution
import org.eclipse.core.runtime.SubMonitor
import org.eclipse.core.runtime.IProgressMonitor
import org.eclipse.jface.viewers.IDecoration
import org.eclipse.jface.viewers.ILightweightLabelDecorator
import org.eclipse.jface.viewers.LabelProvider
import org.eclipse.m2e.core.internal.embedder.IMavenComponentContributor
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata
import org.eclipse.m2e.core.project.configurator.AbstractBuildParticipant
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest
import org.eclipse.m2e.core.project.configurator.AbstractCustomizableLifecycleMapping
import org.eclipse.m2e.core.project.IMavenProjectFacade
import org.eclipse.m2e.jdt.IClasspathDescriptor
import org.eclipse.m2e.jdt.IJavaProjectConfigurator
import org.eclipse.m2e.jdt.IClasspathManager
import org.osgi.framework.BundleContext
/**
* Eclipse companion plugin installed by this Maven plugin.
*/
@Description( """
Keep in sync with src/main/resources/plugin.xml.
""" )
object EclipsePlugin {
@volatile private var instance : Activator = _
/**
* Expose plugin instance.
*/
def apply() : Activator = instance
/**
* Eclipse companion plugin installed by this Maven plugin.
*/
class Activator extends eclipse.Plugin.Activator {
/**
* Eclipse plugin lifecycle.
*/
override def start( context : BundleContext ) = {
EclipsePlugin.instance = this
super.start( context )
log.info( s"Plugin start: ${pluginId}" )
ensureContribution
}
/**
* Eclipse plugin lifecycle.
*/
override def stop( context : BundleContext ) = {
log.info( s"Plugin stop: ${pluginId}" )
unensureContribution
super.stop( context )
EclipsePlugin.instance = null
}
}
/**
* M2E project configurator contributed by this Eclipse plugin.
*/
@Description( """
Keep in sync with src/main/resources/plugin.xml.
Use lazy vals to work around multiple instantiation (note/issue-m2e.md).
""" )
class Configurator
extends eclipse.Project.Configurator
with IJavaProjectConfigurator {
lazy val plugin = EclipsePlugin()
override lazy val log = plugin.log
/**
* Cache values during configurator life cycle.
*/
lazy val cached = meta.Cached()
/**
* M2E build participant implements Maven goal executions.
*/
override def getBuildParticipant(
facade : IMavenProjectFacade,
execution : MojoExecution,
metadata : IPluginExecutionMetadata
) : AbstractBuildParticipant = plugin.tryCore( "Scalor build." ) {
val logger = log.branch( "build" )
def hasGoal( goal : String ) = execution.getGoal == goal
val subMon = SubMonitor.convert( null )
val config = cached( paramsConfig( logger, facade, subMon ) )
val format = if ( hasGoal( A.mojo.`eclipse-format` ) )
Some( cached( paramsFormat( logger, facade, subMon ) ) ) else None
val restart = if ( hasGoal( A.mojo.`eclipse-restart` ) )
Some( cached( paramsRestart( logger, facade, subMon ) ) ) else None
val prescomp = if ( hasGoal( A.mojo.`eclipse-prescomp` ) )
Some( cached( paramsPrescomp( logger, facade, subMon ) ) ) else None
val context = eclipse.Config.BuildContext(
logger = logger,
config = config,
format = format,
restart = restart,
prescomp = prescomp,
facade = facade,
execution = execution
)
eclipse.Build.Participant( context )
}
/**
* M2E configuration step #1.
* Provide internal content of the class path container:
* .classpath!<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
*
* Configures Maven project classpath,
* i.e. content of Maven Dependencies classpath container.
*/
override def configureClasspath(
facade : IMavenProjectFacade,
classpath : IClasspathDescriptor,
monitor : IProgressMonitor
) : Unit = plugin.tryCore( "Scalor step#1." ) {
val logger = log.branch( "config-step#1" )
logger.info( s"Configuring container ${IClasspathManager.CONTAINER_ID}." )
val subMon = monitor.toSub
val config = cached( paramsConfig( logger, facade, subMon.split( 10 ) ) )
val assert = cached( assertVersion( logger, config, subMon.split( 10 ) ) )
val context = eclipse.Config.SetupContext(
logger = logger,
config = config,
facade = facade,
classpath = Some( classpath )
)
ensureOrderMaven( context, subMon.split( 80 ) )
reportClassPath( context, false, subMon.split( 10 ) )
}
/**
* M2E configuration step #2.
* Provide top level class path entries, i.e:
* .classpath!<classpathentry kind="src" output="target/classes" path="src/main/java">
* .classpath!<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
*
* Configures JDT project classpath,
* i.e. project-level entries like source folders,
* JRE and Maven Dependencies classpath container.
*/
override def configureRawClasspath(
request : ProjectConfigurationRequest,
classpath : IClasspathDescriptor,
monitor : IProgressMonitor
) : Unit = plugin.tryCore( "Scalor step#2." ) {
val logger = log.branch( "config-step#2" )
logger.info( s"Configuring project classpath." )
val subMon = monitor.toSub
val facade = request.getMavenProjectFacade
val config = cached( paramsConfig( logger, facade, subMon.split( 10 ) ) )
val assert = cached( assertVersion( logger, config, subMon.split( 10 ) ) )
val context = eclipse.Config.SetupContext(
logger = logger,
config = config,
facade = facade,
request = Some( request ),
classpath = Some( classpath )
)
ensureSourceRoots( context, subMon.split( 20 ) )
ensureScalaLibrary( context, subMon.split( 20 ) )
ensureOrderTopLevel( context, subMon.split( 20 ) )
reportClassPath( context, true, subMon.split( 10 ) )
}
/**
* M2E configuration step #3.
* Provide content for:
* .project!<nature>
* .project!<comment>
* .project!<buildSpec>
* .settings/org.scala-ide.sdt.core.prefs
*
* Configures Eclipse project passed in ProjectConfigurationRequest,
* using information from Maven project and other configuration request parameters.
*/
override def configure(
request : ProjectConfigurationRequest,
monitor : IProgressMonitor
) : Unit = plugin.tryCore( "Scalor step#3." ) {
val logger = log.branch( "config-step#3" )
logger.info( s"Configuring project settings." )
val subMon = monitor.toSub
val facade = request.getMavenProjectFacade
val project = request.getProject
val config = cached( paramsConfig( logger, facade, subMon.split( 10 ) ) )
val assert = cached( assertVersion( logger, config, subMon.split( 10 ) ) )
val context = eclipse.Config.SetupContext(
logger = logger,
config = config,
facade = facade,
request = Some( request )
)
plugin.projectRegister( project, config );
hackSymbolicLinks( context, subMon.split( 10 ) )
ensureProjectComment( context, subMon.split( 10 ) )
ensureProjectNature( context, subMon.split( 10 ) )
ensureOrderBuilder( context, subMon.split( 10 ) )
ensureOrderNature( context, subMon.split( 10 ) )
configureScalaIDE( context, subMon.split( 10 ) )
}
}
/**
* Eclipse UI decorator contributed by this Eclipse plugin.
*/
@Description( """
TODO
Keep in sync with src/main/resources/plugin.xml.
""" )
class Decorator extends LabelProvider
with ILightweightLabelDecorator
with eclipse.Decor {
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer
type Process[ T ] = ( T, IDecoration ) => Unit
val processMap = Map[ Class[ _ ], Process[ _ ] ](
classOf[ ClassPathContainer ] -> processContainer _
)
def hasContext = false
override def decorate( element : Object, decoration : IDecoration ) : Unit = {
if ( hasContext ) {
processMap.get( element.getClass ).map { process =>
process.asInstanceOf[ Process[ Object ] ]( element, decoration )
}
}
}
}
/**
* Eclipse M2E lifecycle mapping contributed by this Eclipse plugin.
*/
@Description( """
TODO
Keep in sync with src/main/resources/plugin.xml.
""" )
class LifecycleMapping extends AbstractCustomizableLifecycleMapping {
}
/**
* Contribute this plugin components into M2E runtime environment.
*/
@Description( """
TODO
FIXME not activated on dynamic bundle install
Keep in sync with src/main/resources/plugin.xml.
""" )
class Injector extends IMavenComponentContributor {
import IMavenComponentContributor.IMavenComponentBinder
import extend.Lifecycle
lazy val plugin = EclipsePlugin()
lazy val log = plugin.log
override def contribute( binder : IMavenComponentBinder ) : Unit = {
// log.context( "inject" )
log.info( s"Provide lifecycle extension ${Lifecycle.Hint}" )
binder.bind( Lifecycle.Role, Lifecycle.Impl, Lifecycle.Hint )
}
}
}