/** Generates .h/.cpp files from the Java files found in "src/", with their .class files being in "bin/". The generated files * will be stored in "jni/". All paths are relative to the applications working directory. * @throws Exception */ public void generate () throws Exception { generate("src", "bin", "jni", null, null); }
private void generateCppFile (ArrayList<JavaSegment> javaSegments, FileDescriptor hFile, FileDescriptor cppFile) throws Exception { String headerFileContent = hFile.readString(); ArrayList<CMethod> cMethods = cMethodParser.parse(headerFileContent).getMethods(); StringBuffer buffer = new StringBuffer(); emitHeaderInclude(buffer, hFile.name()); for (JavaSegment segment : javaSegments) { if (segment instanceof JniSection) { emitJniSection(buffer, (JniSection)segment); } if (segment instanceof JavaMethod) { JavaMethod javaMethod = (JavaMethod)segment; if (javaMethod.getNativeCode() == null) { throw new RuntimeException("Method '" + javaMethod.getName() + "' has no body"); } CMethod cMethod = findCMethod(javaMethod, cMethods); if (cMethod == null) throw new RuntimeException("Couldn't find C method for Java method '" + javaMethod.getClassName() + "#" + javaMethod.getName() + "'"); emitJavaMethod(buffer, javaMethod, cMethod); } } cppFile.writeString(buffer.toString(), false, "UTF-8"); }
StringBuffer additionalArgs = new StringBuffer(); StringBuffer wrapperArgs = new StringBuffer(); emitJniSetupCode(jniSetupCode, javaMethod, additionalArgs, wrapperArgs); emitJniCleanupCode(jniCleanupCode, javaMethod, cMethod); emitMethodSignature(buffer, javaMethod, cMethod, null, false); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); } else { String wrappedMethodName = emitMethodSignature(buffer, javaMethod, cMethod, additionalArgs.toString()); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodBody(buffer, javaMethod); if (!isManual) { buffer.append(jniCleanupCode);
public static void main(String[] args) throws Exception { // generate C/C++ code new NativeCodeGenerator().generate("src", "bin", "jni", new String[] { "**/MyJniClass.java" }, null); // generate build scripts, for win32 and linux64 only BuildConfig buildConfig = new BuildConfig("test"); BuildTarget win32 = BuildTarget.newDefaultTarget(TargetOs.Windows, false); win32.compilerPrefix = ""; win32.cppFlags += " -g"; BuildTarget lin64 = BuildTarget.newDefaultTarget(TargetOs.Linux, true); new AntScriptGenerator().generate(buildConfig, win32, lin64); // build natives BuildExecutor.executeAnt("jni/build-linux64.xml", "-v -Dhas-compiler=true clean postcompile"); BuildExecutor.executeAnt("jni/build.xml", "-v pack-natives"); // load the test-natives.jar and from it the shared library, then execute the test. new JniGenSharedLibraryLoader("libs/test-natives.jar").load("test"); ByteBuffer buffer = ByteBuffer.allocateDirect(1); buffer.put(0, (byte)8); MyJniClass.test( true, (byte)1, (char)2, (short)3, 4, 5, 6, 7, buffer, new boolean[] { false }, new char[] { 9 }, new short[] { 10 }, new int[] { 11 }, new long[] { 12 }, new float[] { 13 }, new double[] { 14 }, null, "Hurray", MyJniClass.class, new RuntimeException(), new MyJniClass()); } }
public static void main(String[] args) throws Exception { // generate C/C++ code new NativeCodeGenerator().generate("src", "bin", "jni", new String[] { "**/MyJniClass.java" }, null); // generate build scripts, for win32 and linux64 only BuildConfig buildConfig = new BuildConfig("test"); BuildTarget win32 = BuildTarget.newDefaultTarget(TargetOs.Windows, false); win32.compilerPrefix = ""; win32.cppFlags += " -g"; BuildTarget lin64 = BuildTarget.newDefaultTarget(TargetOs.Linux, true); new AntScriptGenerator().generate(buildConfig, win32, lin64); // build natives BuildExecutor.executeAnt("jni/build-linux64.xml", "-v -Dhas-compiler=true clean postcompile"); BuildExecutor.executeAnt("jni/build.xml", "-v pack-natives"); // load the test-natives.jar and from it the shared library, then execute the test. new JniGenSharedLibraryLoader("libs/test-natives.jar").load("test"); ByteBuffer buffer = ByteBuffer.allocateDirect(1); buffer.put(0, (byte)8); MyJniClass.test( true, (byte)1, (char)2, (short)3, 4, 5, 6, 7, buffer, new boolean[] { false }, new char[] { 9 }, new short[] { 10 }, new int[] { 11 }, new long[] { 12 }, new float[] { 13 }, new double[] { 14 }, null, "Hurray", MyJniClass.class, new RuntimeException(), new MyJniClass()); } }
public static void main(String[] args) throws Exception { BuildTarget win32 = BuildTarget.newDefaultTarget(TargetOs.Windows, false); BuildTarget win64 = BuildTarget.newDefaultTarget(TargetOs.Windows, true); BuildTarget lin32 = BuildTarget.newDefaultTarget(TargetOs.Linux, false); BuildTarget lin64 = BuildTarget.newDefaultTarget(TargetOs.Linux, true); BuildTarget android = BuildTarget.newDefaultTarget(TargetOs.Android, false); BuildTarget mac32 = BuildTarget.newDefaultTarget(TargetOs.MacOsX, false); BuildTarget mac64 = BuildTarget.newDefaultTarget(TargetOs.MacOsX, true); BuildTarget ios = BuildTarget.newDefaultTarget(TargetOs.IOS, false); new NativeCodeGenerator().generate("src", "bin" + File.pathSeparator + "../../../gdx/bin", "jni"); new AntScriptGenerator().generate(new BuildConfig("gdx-box2d"), win32, win64, lin32, lin64, mac32, mac64, android, ios); } }
/** Generates .h/.cpp fiels from the Java files found in <code>sourceDir</code>, with their .class files being in * <code>classpath</code>. The generated files will be stored in <code>jniDir</code>. All paths are relative to the * applications working directory. * @param sourceDir the directory containing the Java files * @param classpath the directory containing the .class files * @param jniDir the output directory * @throws Exception */ public void generate (String sourceDir, String classpath, String jniDir) throws Exception { generate(sourceDir, classpath, jniDir, null, null); }
private void generateCppFile (ArrayList<JavaSegment> javaSegments, FileDescriptor hFile, FileDescriptor cppFile) throws Exception { String headerFileContent = hFile.readString(); ArrayList<CMethod> cMethods = cMethodParser.parse(headerFileContent).getMethods(); StringBuffer buffer = new StringBuffer(); emitHeaderInclude(buffer, hFile.name()); for (JavaSegment segment : javaSegments) { if (segment instanceof JniSection) { emitJniSection(buffer, (JniSection)segment); } if (segment instanceof JavaMethod) { JavaMethod javaMethod = (JavaMethod)segment; if (javaMethod.getNativeCode() == null) { throw new RuntimeException("Method '" + javaMethod.getName() + "' has no body"); } CMethod cMethod = findCMethod(javaMethod, cMethods); if (cMethod == null) throw new RuntimeException("Couldn't find C method for Java method '" + javaMethod.getClassName() + "#" + javaMethod.getName() + "'"); emitJavaMethod(buffer, javaMethod, cMethod); } } cppFile.writeString(buffer.toString(), false, "UTF-8"); }
StringBuffer additionalArgs = new StringBuffer(); StringBuffer wrapperArgs = new StringBuffer(); emitJniSetupCode(jniSetupCode, javaMethod, additionalArgs, wrapperArgs); emitJniCleanupCode(jniCleanupCode, javaMethod, cMethod); emitMethodSignature(buffer, javaMethod, cMethod, null, false); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); } else { String wrappedMethodName = emitMethodSignature(buffer, javaMethod, cMethod, additionalArgs.toString()); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodBody(buffer, javaMethod); if (!isManual) { buffer.append(jniCleanupCode);
public static void main (String[] args) throws Exception { new NativeCodeGenerator().generate("src/", "bin/", "jni/"); BuildConfig buildConfig = new BuildConfig("gdx-controllers-desktop");
/** Generates .h/.cpp fiels from the Java files found in <code>sourceDir</code>, with their .class files being in * <code>classpath</code>. The generated files will be stored in <code>jniDir</code>. All paths are relative to the * applications working directory. * @param sourceDir the directory containing the Java files * @param classpath the directory containing the .class files * @param jniDir the output directory * @throws Exception */ public void generate (String sourceDir, String classpath, String jniDir) throws Exception { generate(sourceDir, classpath, jniDir, null, null); }
private void generateCppFile (ArrayList<JavaSegment> javaSegments, FileDescriptor hFile, FileDescriptor cppFile) throws Exception { String headerFileContent = hFile.readString(); ArrayList<CMethod> cMethods = cMethodParser.parse(headerFileContent).getMethods(); StringBuffer buffer = new StringBuffer(); emitHeaderInclude(buffer, hFile.name()); for (JavaSegment segment : javaSegments) { if (segment instanceof JniSection) { emitJniSection(buffer, (JniSection)segment); } if (segment instanceof JavaMethod) { JavaMethod javaMethod = (JavaMethod)segment; if (javaMethod.getNativeCode() == null) { throw new RuntimeException("Method '" + javaMethod.getName() + "' has no body"); } CMethod cMethod = findCMethod(javaMethod, cMethods); if (cMethod == null) throw new RuntimeException("Couldn't find C method for Java method '" + javaMethod.getClassName() + "#" + javaMethod.getName() + "'"); emitJavaMethod(buffer, javaMethod, cMethod); } } cppFile.writeString(buffer.toString(), false, "UTF-8"); }
StringBuffer additionalArgs = new StringBuffer(); StringBuffer wrapperArgs = new StringBuffer(); emitJniSetupCode(jniSetupCode, javaMethod, additionalArgs, wrapperArgs); emitJniCleanupCode(jniCleanupCode, javaMethod, cMethod); emitMethodSignature(buffer, javaMethod, cMethod, null, false); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); } else { String wrappedMethodName = emitMethodSignature(buffer, javaMethod, cMethod, additionalArgs.toString()); emitMethodBody(buffer, javaMethod); buffer.append("}\n\n"); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodSignature(buffer, javaMethod, cMethod, null); if (!isManual) { buffer.append(jniSetupCode); emitMethodBody(buffer, javaMethod); if (!isManual) { buffer.append(jniCleanupCode);
new NativeCodeGenerator().generate("src", "bin", JNI_DIR, new String[] {"**/*"}, null);
/** Generates .h/.cpp files from the Java files found in "src/", with their .class files being in "bin/". The generated files * will be stored in "jni/". All paths are relative to the applications working directory. * @throws Exception */ public void generate () throws Exception { generate("src", "bin", "jni", null, null); }
new NativeCodeGenerator().generate("src", "bin", JNI_DIR, new String[] {"**/*"}, null);
/** Generates .h/.cpp files from the Java files found in "src/", with their .class files being in "bin/". The generated files * will be stored in "jni/". All paths are relative to the applications working directory. * @throws Exception */ public void generate () throws Exception { generate("src", "bin", "jni", null, null); }
public static void main (String[] args) throws Exception { new NativeCodeGenerator().generate("src", "bin", "jni");
/** Generates .h/.cpp fiels from the Java files found in <code>sourceDir</code>, with their .class files being in * <code>classpath</code>. The generated files will be stored in <code>jniDir</code>. All paths are relative to the * applications working directory. * @param sourceDir the directory containing the Java files * @param classpath the directory containing the .class files * @param jniDir the output directory * @throws Exception */ public void generate (String sourceDir, String classpath, String jniDir) throws Exception { generate(sourceDir, classpath, jniDir, null, null); }
public static void main (String[] args) throws Exception { new NativeCodeGenerator().generate("src", "bin", "jni");