Search in sources :

Example 6 with Clazzes

use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.

the class AppCompilerTest method testMultipleMetainfServiceImplsAdded.

@Test
public void testMultipleMetainfServiceImplsAdded() throws Exception {
    final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
    final Path impl2 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Long");
    Clazzes clazzes = createClazzes(impl1, impl2);
    Clazz interfaceClazz = clazzes.load("java/lang/Number");
    Set<Clazz> compiled = new HashSet<>();
    Set<Clazz> queue = new LinkedHashSet<>();
    AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
    assertEquals("Two items added to queue: " + queue, 2, queue.size());
    assertTrue("Integer in queue" + queue, queue.contains(clazzes.load("java/lang/Integer")));
    assertTrue("Long in queue" + queue, queue.contains(clazzes.load("java/lang/Long")));
}
Also used : Path(org.robovm.compiler.clazz.Path) LinkedHashSet(java.util.LinkedHashSet) Clazz(org.robovm.compiler.clazz.Clazz) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 7 with Clazzes

use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.

the class AppCompilerTest method testMissingImplIsIgnore.

@Test
public void testMissingImplIsIgnore() throws Exception {
    final Path impl1 = new MockPath("META-INF/services/java.lang.Number", "java.lang.Integer");
    final Path impl2 = new MockPath("META-INF/services/java.lang.Number", "nobody.knows.such.Class");
    Clazzes clazzes = createClazzes(impl1, impl2);
    Clazz interfaceClazz = clazzes.load("java/lang/Number");
    Set<Clazz> compiled = new HashSet<>();
    Set<Clazz> queue = new LinkedHashSet<>();
    AppCompiler.addMetaInfImplementations(clazzes, interfaceClazz, compiled, queue);
    assertEquals("Just one item added to queue: " + queue, 1, queue.size());
    assertTrue("Integer in queue" + queue, queue.contains(clazzes.load("java/lang/Integer")));
}
Also used : Path(org.robovm.compiler.clazz.Path) LinkedHashSet(java.util.LinkedHashSet) Clazz(org.robovm.compiler.clazz.Clazz) Clazzes(org.robovm.compiler.clazz.Clazzes) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test)

Example 8 with Clazzes

use of org.robovm.compiler.clazz.Clazzes in project robovm by robovm.

the class Config method build.

private Config build() throws IOException {
    // Create a clone of this Config before we have done anything with it so
    // that builder() has a fresh Config it can use.
    this.configBeforeBuild = clone(this);
    if (home == null) {
        home = Home.find();
    }
    if (bootclasspath == null) {
        bootclasspath = new ArrayList<File>();
    }
    if (classpath == null) {
        classpath = new ArrayList<File>();
    }
    if (mainJar != null) {
        mainClass = getMainClass(mainJar);
        classpath.add(mainJar);
    }
    if (executableName == null && imageName != null) {
        executableName = imageName;
    }
    if (!skipLinking && executableName == null && mainClass == null) {
        throw new IllegalArgumentException("No target and no main class specified");
    }
    if (!skipLinking && classpath.isEmpty()) {
        throw new IllegalArgumentException("No classpath specified");
    }
    if (skipLinking) {
        skipInstall = true;
    }
    if (executableName == null) {
        executableName = mainClass;
    }
    if (imageName == null || !imageName.equals(executableName)) {
        imageName = executableName;
    }
    List<File> realBootclasspath = bootclasspath == null ? new ArrayList<File>() : bootclasspath;
    if (!isSkipRuntimeLib()) {
        realBootclasspath = new ArrayList<File>(bootclasspath);
        realBootclasspath.add(0, home.rtPath);
    }
    this.vtableCache = new VTable.Cache();
    this.itableCache = new ITable.Cache();
    this.marshalerLookup = new MarshalerLookup(this);
    if (!skipInstall) {
        if (installDir == null) {
            installDir = new File(".", executableName);
        }
        installDir.mkdirs();
    }
    if (targetType != null) {
        if (ConsoleTarget.TYPE.equals(targetType)) {
            target = new ConsoleTarget();
        } else if (IOSTarget.TYPE.equals(targetType)) {
            target = new IOSTarget();
        } else {
            for (TargetPlugin plugin : getTargetPlugins()) {
                if (plugin.getTarget().getType().equals(targetType)) {
                    target = plugin.getTarget();
                    break;
                }
            }
            if (target == null) {
                throw new IllegalArgumentException("Unsupported target '" + targetType + "'");
            }
        }
    } else {
        // Auto
        if (os == OS.ios) {
            target = new IOSTarget();
        } else {
            target = new ConsoleTarget();
        }
    }
    if (!getArchs().isEmpty()) {
        sliceArch = getArchs().get(0);
    }
    target.init(this);
    os = target.getOs();
    sliceArch = target.getArch();
    dataLayout = new DataLayout(getTriple());
    osArchDepLibDir = new File(new File(home.libVmDir, os.toString()), sliceArch.toString());
    if (treeShakerMode != null && treeShakerMode != TreeShakerMode.none && os.getFamily() == Family.darwin && sliceArch == Arch.x86) {
        logger.warn("Tree shaking is not supported when building " + "for OS X/iOS x86 32-bit due to a bug in Xcode's linker. No tree " + "shaking will be performed. Run in 64-bit mode instead to " + "use tree shaking.");
        treeShakerMode = TreeShakerMode.none;
    }
    dependencyGraph = new DependencyGraph(getTreeShakerMode());
    RamDiskTools ramDiskTools = new RamDiskTools();
    ramDiskTools.setupRamDisk(this, this.cacheDir, this.tmpDir);
    this.cacheDir = ramDiskTools.getCacheDir();
    this.tmpDir = ramDiskTools.getTmpDir();
    File osDir = new File(cacheDir, os.toString());
    File archDir = new File(osDir, sliceArch.toString());
    osArchCacheDir = new File(archDir, debug ? "debug" : "release");
    osArchCacheDir.mkdirs();
    this.clazzes = new Clazzes(this, realBootclasspath, classpath);
    mergeConfigsFromClasspath();
    return this;
}
Also used : TargetPlugin(org.robovm.compiler.plugin.TargetPlugin) DataLayout(org.robovm.compiler.llvm.DataLayout) MarshalerLookup(org.robovm.compiler.MarshalerLookup) DependencyGraph(org.robovm.compiler.DependencyGraph) RamDiskTools(org.robovm.compiler.util.io.RamDiskTools) VTable(org.robovm.compiler.VTable) IOSTarget(org.robovm.compiler.target.ios.IOSTarget) ITable(org.robovm.compiler.ITable) Clazzes(org.robovm.compiler.clazz.Clazzes) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) ConsoleTarget(org.robovm.compiler.target.ConsoleTarget)

Aggregations

Clazzes (org.robovm.compiler.clazz.Clazzes)8 HashSet (java.util.HashSet)6 Clazz (org.robovm.compiler.clazz.Clazz)6 LinkedHashSet (java.util.LinkedHashSet)5 Test (org.junit.Test)5 Path (org.robovm.compiler.clazz.Path)5 File (java.io.File)2 IOException (java.io.IOException)1 JarFile (java.util.jar.JarFile)1 ZipFile (java.util.zip.ZipFile)1 AnnotationVisitor (org.objectweb.asm.AnnotationVisitor)1 Attribute (org.objectweb.asm.Attribute)1 ClassReader (org.objectweb.asm.ClassReader)1 ClassVisitor (org.objectweb.asm.ClassVisitor)1 FieldVisitor (org.objectweb.asm.FieldVisitor)1 MethodVisitor (org.objectweb.asm.MethodVisitor)1 DependencyGraph (org.robovm.compiler.DependencyGraph)1 ITable (org.robovm.compiler.ITable)1 MarshalerLookup (org.robovm.compiler.MarshalerLookup)1 VTable (org.robovm.compiler.VTable)1