Skip to content

Commit d39d15c

Browse files
committed
Removed CodenameOneBuildClient dependency - load instead at runtime using URLClassLoader
1 parent 7258bce commit d39d15c

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

maven/codenameone-maven-plugin/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@
3030
<exists>${cn1.build.client.path}</exists>
3131
</file>
3232
</activation>
33-
<dependencies>
34-
<dependency>
35-
<groupId>com.codenameone</groupId>
36-
<artifactId>codenameone-buildclient</artifactId>
37-
<version>8.0</version>
38-
<scope>system</scope>
39-
<systemPath>${cn1.build.client.path}</systemPath>
40-
<optional>true</optional>
41-
</dependency>
42-
</dependencies>
4333
</profile>
4434
</profiles>
4535

maven/codenameone-maven-plugin/src/main/java/com/codename1/maven/GenerateGuiSourcesMojo.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66
package com.codename1.maven;
77

8-
import com.codename1.build.client.GenerateGuiSources;
9-
108
import java.io.ByteArrayInputStream;
119
import java.io.File;
1210
import java.io.IOException;
1311
import java.io.StringWriter;
12+
import java.net.URL;
13+
import java.net.URLClassLoader;
1414
import java.util.LinkedList;
1515
import java.util.function.Function;
1616

@@ -52,12 +52,20 @@ protected void executeImpl() throws MojoExecutionException, MojoFailureException
5252
}
5353
System.setProperty("generate-gui-sources-done", "true");
5454
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+
}
6169

6270
// Generate the RAD templates while we're at it
6371

0 commit comments

Comments
 (0)