@@ -66,6 +66,8 @@ abstract class SlimeLauncherEclipseConfiguration extends DefaultTask implements
6666
6767 protected abstract @ Nested Property <JavaLauncher > getJavaLauncher ();
6868
69+ protected abstract @ Input ListProperty <String > getProjectDependencies ();
70+
6971 protected abstract @ InputFiles @ Classpath ConfigurableFileCollection getClasspath ();
7072
7173 protected abstract @ Input Property <String > getMainClass ();
@@ -89,10 +91,7 @@ abstract class SlimeLauncherEclipseConfiguration extends DefaultTask implements
8991 @ Inject
9092 public SlimeLauncherEclipseConfiguration () {
9193 this .getProjectName ().convention (this .getProject ().getName ());
92- this .getEclipseProjectName ().convention (getProviders ().provider (() -> {
93- var eclipse = getProject ().getExtensions ().findByType (EclipseModel .class );
94- return eclipse == null ? null : eclipse .getProject ().getName ();
95- }));
94+ this .getEclipseProjectName ().convention (getProject ().provider (() -> Util .getProjectEclipseName (this .getProject ())));
9695
9796 var tool = this .getTool (Tools .SLIMELAUNCHER );
9897 this .getClasspath ().from (tool .getClasspath ());
@@ -141,13 +140,15 @@ protected void exec() {
141140 queue .submit (Action .class , parameters -> {
142141 parameters .getOutputFile ().set (this .getOutputFile ());
143142 parameters .getEclipseProjectName ().set (this .getEclipseProjectName ().orElse (this .getProjectName ()));
143+ parameters .getProjectDependencies ().set (this .getProjectDependencies ());
144144 parameters .getClasspath ().setFrom (this .getClasspath ());
145145 parameters .getMainClass ().set (this .getMainClass ().get ());
146146 parameters .getArgs ().set (args );
147147 parameters .getJvmArgs ().set (jvmArgs );
148148 parameters .getWorkingDir ().set (workingDir );
149149 parameters .getEnvironment ().set (environment );
150150 parameters .getJavaHome ().set (this .getJavaLauncher ().map (j -> j .getMetadata ().getInstallationPath ()));
151+ parameters .getJavaVersion ().set (this .getJavaLauncher ().map (j -> j .getMetadata ().getLanguageVersion ().toString ()));
151152 });
152153 }
153154
@@ -157,6 +158,8 @@ interface Parameters extends WorkParameters {
157158
158159 Property <String > getEclipseProjectName ();
159160
161+ ListProperty <String > getProjectDependencies ();
162+
160163 ConfigurableFileCollection getClasspath ();
161164
162165 Property <String > getMainClass ();
@@ -169,6 +172,8 @@ interface Parameters extends WorkParameters {
169172
170173 DirectoryProperty getJavaHome ();
171174
175+ Property <String > getJavaVersion ();
176+
172177 MapProperty <String , String > getEnvironment ();
173178 }
174179
@@ -202,7 +207,12 @@ public void execute() {
202207 stringAttribute (launch , rootElement , "org.eclipse.jdt.launching.WORKING_DIRECTORY" , parameters .getWorkingDir ().getAsFile ().get ().getAbsolutePath ());
203208 //stringAttribute(launch, rootElement, "org.eclipse.jdt.launching.JRE_CONTAINER", parameters.getJavaHome().getAsFile().get().getAbsolutePath());
204209 mapAttribute (launch , rootElement , "org.eclipse.debug.core.environmentVariables" , parameters .getEnvironment ().get ());
205- classpathAttribute (launch , rootElement , parameters .getClasspath ());
210+
211+ var classpathList = classpathList (rootElement );
212+ addClasspathProjects (classpathList , parameters .getProjectDependencies ());
213+ addClasspathLibraries (classpathList , parameters .getClasspath ());
214+ addClasspathJava (classpathList , parameters .getJavaVersion ().get ());
215+
206216 booleanAttribute (launch , rootElement , "org.eclipse.jdt.launching.DEFAULT_CLASSPATH" , false );
207217
208218 launch .appendChild (rootElement );
@@ -245,19 +255,40 @@ private static void listAttribute(Document document, Element parent, String key,
245255 parent .appendChild (attribute );
246256 }
247257
248- private static final String CLASSPATH_ENTRY_PREFIX = "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?> <runtimeClasspathEntry externalArchive=\" " ;
249- private static final String CLASSPATH_ENTRY_SUFFIX = "\" path=\" 5\" type=\" 2\" />" ;
250258
251- private static void classpathAttribute (Document document , Element parent , FileCollection files ) {
252- var attribute = document .createElement ("listAttribute" );
259+ private static final String CLASSPATH_ENTRY_PREFIX = "<?xml version=\" 1.0\" encoding=\" UTF-8\" standalone=\" no\" ?><runtimeClasspathEntry " ;
260+ private static final String CLASSPATH_ENTRY_SUFFIX = " path=\" 5\" />" ;
261+
262+ private static Element addChild (Element parent , String name ) {
263+ var ret = parent .getOwnerDocument ().createElement (name );
264+ parent .appendChild (ret );
265+ return ret ;
266+ }
267+
268+ private static Element classpathList (Element parent ) {
269+ var attribute = addChild (parent , "listAttribute" );
253270 attribute .setAttribute ("key" , "org.eclipse.jdt.launching.CLASSPATH" );
271+ return attribute ;
272+ }
254273
255- for (var v : files .getFiles ()) {
256- var listEntry = document .createElement ("listEntry" );
257- listEntry .setAttribute ("value" , CLASSPATH_ENTRY_PREFIX + v + CLASSPATH_ENTRY_SUFFIX );
258- attribute .appendChild (listEntry );
274+ private static void classpathEntry (Element parent , int type , String value ) {
275+ addChild (parent , "listEntry" ).setAttribute ("value" , CLASSPATH_ENTRY_PREFIX + value + " type=\" " + type + "\" " + CLASSPATH_ENTRY_SUFFIX );
276+ }
277+
278+ private static void addClasspathLibraries (Element parent , FileCollection files ) {
279+ for (var v : files .getFiles ())
280+ classpathEntry (parent , 2 , "externalArchive=\" " + v + "\" " );
281+ }
282+
283+ private static void addClasspathProjects (Element parent , ListProperty <String > projects ) {
284+ for (var v : projects .get ()) {
285+ classpathEntry (parent , 1 , "projectName=\" " + v + "\" " );
286+ classpathEntry (parent , 4 , "containerPath=\" org.eclipse.buildship.core.gradleclasspathcontainer\" javaProject=\" " + v + "\" " );
259287 }
260- parent .appendChild (attribute );
288+ }
289+
290+ private static void addClasspathJava (Element parent , String version ) {
291+ classpathEntry (parent , 4 , "containerPath=\" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-" + version + "\" " );
261292 }
262293
263294 private static void mapAttribute (Document document , Element parent , String key , Map <String , ?> map ) {
0 commit comments