Search in sources :

Example 6 with Path

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

the class Config method mergeConfigsFromClasspath.

private void mergeConfigsFromClasspath() throws IOException {
    List<String> dirs = Arrays.asList("META-INF/robovm/" + os + "/" + sliceArch, "META-INF/robovm/" + os);
    // The algorithm below preserves the order of config data from the
    // classpath. Last the config from this object is added.
    // First merge all configs on the classpath to an empty Config
    Config config = new Config();
    for (Path path : clazzes.getPaths()) {
        for (String dir : dirs) {
            if (path.contains(dir + "/robovm.xml")) {
                File configXml = new File(new File(extractIfNeeded(path), dir), "robovm.xml");
                Builder builder = new Builder();
                builder.read(configXml);
                mergeConfig(builder.config, config);
                break;
            }
        }
    }
    // Then merge with this Config
    mergeConfig(this, config);
    // Copy back to this Config
    this.exportedSymbols = config.exportedSymbols;
    this.unhideSymbols = config.unhideSymbols;
    this.forceLinkClasses = config.forceLinkClasses;
    this.frameworkPaths = config.frameworkPaths;
    this.frameworks = config.frameworks;
    this.libs = config.libs;
    this.resources = config.resources;
    this.weakFrameworks = config.weakFrameworks;
}
Also used : Path(org.robovm.compiler.clazz.Path) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 7 with Path

use of org.robovm.compiler.clazz.Path 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 8 with Path

use of org.robovm.compiler.clazz.Path 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 9 with Path

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

the class AppCompiler method getMatchingClasses.

/**
     * Returns all {@link Clazz}es in all {@link Path}s matching the specified
     * ANT-style pattern.
     */
private Collection<Clazz> getMatchingClasses(String pattern) {
    AntPathMatcher matcher = new AntPathMatcher(pattern, ".");
    Map<String, Clazz> matches = new HashMap<String, Clazz>();
    for (Path path : config.getClazzes().getPaths()) {
        for (Clazz clazz : path.listClasses()) {
            if (!matches.containsKey(clazz.getClassName()) && matcher.matches(clazz.getClassName())) {
                matches.put(clazz.getClassName(), clazz);
            }
        }
    }
    return matches.values();
}
Also used : Path(org.robovm.compiler.clazz.Path) HashMap(java.util.HashMap) Clazz(org.robovm.compiler.clazz.Clazz) AntPathMatcher(org.robovm.compiler.util.AntPathMatcher)

Example 10 with Path

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

the class AppCompiler method build.

/**
     * Builds the binary (possibly a fat binary with multiple archs).
     */
public void build() throws IOException {
    List<Arch> archs = this.config.getArchs();
    if (archs.isEmpty()) {
        archs = config.getTarget().getDefaultArchs();
    }
    if (archs.isEmpty()) {
        throw new IllegalArgumentException("No archs specified in config");
    }
    if (archs.size() == 1 && this.config.getArch().equals(archs.get(0))) {
        // No need to clone configs for each slice.
        compile();
    } else {
        Map<Arch, File> slices = new TreeMap<>();
        for (Arch arch : archs) {
            this.config.getLogger().info("Building %s slice", arch);
            Config sliceConfig = this.config.builder().arch(arch).tmpDir(new File(this.config.getTmpDir(), arch.toString())).build();
            new AppCompiler(sliceConfig).compile();
            slices.put(arch, new File(sliceConfig.getTmpDir(), sliceConfig.getExecutableName()));
            for (Path path : sliceConfig.getResourcesPaths()) {
                if (!this.config.getResourcesPaths().contains(path)) {
                    this.config.addResourcesPath(path);
                }
            }
        }
        this.config.getTarget().buildFat(slices);
    }
}
Also used : Path(org.robovm.compiler.clazz.Path) Config(org.robovm.compiler.config.Config) Arch(org.robovm.compiler.config.Arch) TreeMap(java.util.TreeMap) File(java.io.File)

Aggregations

Path (org.robovm.compiler.clazz.Path)10 Clazz (org.robovm.compiler.clazz.Clazz)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Clazzes (org.robovm.compiler.clazz.Clazzes)5 LinkedHashSet (java.util.LinkedHashSet)4 Test (org.junit.Test)4 Config (org.robovm.compiler.config.Config)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 Arch (org.robovm.compiler.config.Arch)2 Random (java.util.Random)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 JarFile (java.util.jar.JarFile)1 ClazzInfo (org.robovm.compiler.clazz.ClazzInfo)1 MethodInfo (org.robovm.compiler.clazz.MethodInfo)1 OS (org.robovm.compiler.config.OS)1 HashTableGenerator (org.robovm.compiler.hash.HashTableGenerator)1