|
5 | 5 | */ |
6 | 6 | package com.codename1.maven; |
7 | 7 |
|
8 | | -import com.codename1.build.client.GenerateGuiSources; |
9 | | - |
10 | 8 | import java.io.ByteArrayInputStream; |
11 | 9 | import java.io.File; |
12 | 10 | import java.io.IOException; |
13 | 11 | import java.io.StringWriter; |
| 12 | +import java.net.URL; |
| 13 | +import java.net.URLClassLoader; |
14 | 14 | import java.util.LinkedList; |
15 | 15 | import java.util.function.Function; |
16 | 16 |
|
@@ -52,12 +52,20 @@ protected void executeImpl() throws MojoExecutionException, MojoFailureException |
52 | 52 | } |
53 | 53 | System.setProperty("generate-gui-sources-done", "true"); |
54 | 54 | System.setProperty("javax.xml.bind.context.factory", "com.sun.xml.bind.v2.ContextFactory"); |
55 | | - |
56 | | - GenerateGuiSources g = new GenerateGuiSources(); |
57 | | - g.setSrcDir(new File(getCN1ProjectDir(), "src" + File.separator + "main" + File.separator + "java")); |
58 | | - g.setGuiDir(new File(getCN1ProjectDir(), "src" + File.separator + "main" + File.separator + "guibuilder")); |
59 | | - g.execute(); |
60 | | - |
| 55 | + String buildClientJarPath = path(System.getProperty("user.home"), ".codenameone", "CodeNameOneBuildClient.jar"); |
| 56 | + File jarFile = new File(buildClientJarPath); |
| 57 | + if (!jarFile.exists()) { |
| 58 | + throw new MojoExecutionException(buildClientJarPath + " not found at " + jarFile.getAbsolutePath()); |
| 59 | + } |
| 60 | + try (URLClassLoader classLoader = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}, this.getClass().getClassLoader())) { |
| 61 | + Class<?> clazz = classLoader.loadClass("com.codename1.build.client.GenerateGuiSources"); |
| 62 | + Object g = clazz.getDeclaredConstructor().newInstance(); |
| 63 | + clazz.getMethod("setSrcDir", File.class).invoke(g, new File(getCN1ProjectDir(), "src" + File.separator + "main" + File.separator + "java")); |
| 64 | + clazz.getMethod("setGuiDir", File.class).invoke(g, new File(getCN1ProjectDir(), "src" + File.separator + "main" + File.separator + "guibuilder")); |
| 65 | + clazz.getMethod("execute").invoke(g); |
| 66 | + } catch (Exception e) { |
| 67 | + throw new MojoExecutionException("Failed to load and execute GenerateGuiSources", e); |
| 68 | + } |
61 | 69 |
|
62 | 70 | // Generate the RAD templates while we're at it |
63 | 71 |
|
|
0 commit comments