compile

Compile from memory/filesystem to memory/filesystem, easily

io.earcam.instrumental.compile.Compiler

  • Convenience functionality on top of javax.tools.JavaCompiler
  • Compile to/from the file-system, or entirely in-memory (e.g. from source as String to class as byte array)
  • Fluid builder with specific support for annotation processors
  • Create native headers in arbitrary locations (in-mem/on-disk)
  • Find sourcecode for classes within maven module or it’s dependencies (on proviso that source jar has been downloaded)

Provides a complete in-memory experience:

Note: currently the Eclipse compiler only supports input from the filesystem.


Dependency Graph

Module Dependency

Examples

Take the source as a String, then compile it to a map of byte arrays:

		final String fqn = "com.acme.Thing";

		final String text = "" +
				"package com.acme;   \n" +
				"                    \n" +
				"class Thing {       \n" +

				" int fortyTwo()     \n" +
				" {                  \n" +
				"   return 42;       \n" +
				" }                  \n" +
				"}                   \n";

		@Test
		void map()
		{
			Map<String, byte[]> map;

			map = compiling()
					.versionAt(latestSupported())
					.source(from(text))
					.compile(toByteArrays());

			byte[] bytes = map.get(Names.typeToResourceName(fqn));

			assertValidClass(bytes, fqn);
		}

Find the source for the specified class, then compile it the filesystem:

			compiling()
					.versionAt(SourceVersion.latestSupported())
					.source(foundFor(Pojo.class))
					.compile(toFileSystem(path));

			Path compiled = path.resolve(Names.typeToResourceName(Pojo.class));
			byte[] bytes = Files.readAllBytes(compiled);

			assertValidClass(bytes, Pojo.class.getCanonicalName());

(source).



Back to top

Version: 0.1.0. Last Published: 2018-10-08.

Earcam Maven Skin.