All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robovm.compiler.config.ConfigXmlEntries Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2012 RoboVM AB
 * Copyright (C) 2018 Daniel Thommes, NeverNull GmbH, 
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */
package org.robovm.compiler.config;

import org.robovm.compiler.config.Config.QualifiedEntry;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Value objects for serialization with SimpleXML
 * Mostly list wrappers to fix SimpleXML issue: it allows unexpected tags to be present while parsing list
 * this caused side effect like empty text tags or null objects inserted: for example
 * 
 *      aaaa
 * 
 * would result in (null, "aaaa") in list
 * (beside the fact that structure is wrong)
 *
 * General approach for a workaround:
 * instead of
 *     @ElementList(required = false, entry = "framework")
 *     private ArrayList frameworks;
 * list wrapper class to be used:
 *     @Element(required = false)
 *     private FrameworksList frameworks;
 * list wrapper class expected to be @Root with strict = true, so unexpected tags will cause exception
 */
final class ConfigXmlEntries {

    /**
     * common class with generic setter. there is a bug/issue in SimpleXML -- when holder is a list and
     * property is a list -- it will add items to holder and then pass it as parameter to property.
     * have to check for this != items
     * @param 
     */
    static class BaseArrayList extends ArrayList {
        void setItems(List items) {
            if (this != items) {
                clear();
                addAll(items);
            }
        }
    }

    /**
     * Replacement for
     * @ElementList(required = false, entry = "framework")
     * private ArrayList frameworks;
     * @ElementList(required = false, entry = "framework")
     * private ArrayList weakFrameworks;
     */
    @Root
    static class FrameworksList extends BaseArrayList {
        @ElementList(required = false, entry = "framework", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "framework", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * private ArrayList weakFrameworks;
     * @ElementList(required = false, entry = "path")
     * private ArrayList frameworkPaths;
     * @ElementList(required = false, entry = "path")
     * @ElementList(required = false, entry = "path")
     * private ArrayList appExtensionPaths;
     */
    @Root
    static class PathsList extends BaseArrayList {
        @ElementList(required = false, entry = "path", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "path", inline = true)
        private List getItems() { return this; }
    }

    /**
     * Replacement for
     * @ElementList(required = false, entry = "symbol")
     * private ArrayList exportedSymbols;
     * @ElementList(required = false, entry = "symbol")
     * private ArrayList unhideSymbols;
     */
    @Root
    static class SymbolsList extends BaseArrayList {
        @ElementList(required = false, entry = "symbol", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "symbol", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "root")
     * private ArrayList roots;
     */
    @Root
    static class RootsList extends BaseArrayList {
        @ElementList(required = false, entry = "root", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "root", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for:
     * @ElementList(required = false, entry = "entry")
     * private ArrayList forceLinkMethods;
     */
    @Root
    static class ForceLinkMethodsList extends BaseArrayList {
        @ElementList(required = false, entry = "entry", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "entry", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "pattern")
     * private ArrayList forceLinkClasses;
     */
    @Root
    static class ForceLinkClassesList extends BaseArrayList {
        @ElementList(required = false, entry = "pattern", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "pattern", inline = true)
        private List getItems() { return this; }
    }


    /**
     * replacement for
     * @ElementList(required = false, entry = "lib")
     * private ArrayList libs;
     */
    @Root
    static class LibsList extends BaseArrayList {
        @ElementList(required = false, entry = "lib", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "lib", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "extension")
     * private ArrayList appExtensions;
     */
    @Root
    static class AppExtensionsList extends BaseArrayList {
        @ElementList(required = false, entry = "extension", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "extension", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "resource")
     * private ArrayList resources;
     */
    @Root
    static class ResourcesList extends BaseArrayList {
        @ElementList(required = false, entry = "resource", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "resource", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "classpathentry")
     * private ArrayList bootclasspath;
     * @ElementList(required = false, entry = "classpathentry")
     * private ArrayList classpath;
     */
    @Root
    static class ClasspathentryList extends BaseArrayList {
        @ElementList(required = false, entry = "classpathentry", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "classpathentry", inline = true)
        private List getItems() { return this; }
    }

    /**
     * replacement for
     * @ElementList(required = false, entry = "argument")
     * private ArrayList pluginArguments;
     */
    @Root
    static class PluginArgumentsList extends BaseArrayList {
        @ElementList(required = false, entry = "argument", inline = true)
        void setItems(List items) { super.setItems(items); }

        @ElementList(required = false, entry = "argument", inline = true)
        private List getItems() { return this; }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy