Search in sources :

Example 6 with UMAException

use of com.ibm.uma.UMAException in project openj9 by eclipse.

the class ConfigurationImpl method processProperties.

void processProperties(String path) throws UMAException {
    try {
        Properties properties = new Properties();
        // Path is assumed to be in the shape {root}/buildspecs
        properties.load(new FileInputStream(path + "/../makelib/uma.properties"));
        for (Object key : properties.keySet()) {
            String property = properties.getProperty((String) key);
            macroMap.put((String) key, property);
        }
    } catch (FileNotFoundException e) {
        // No uma.properties file, no problem.
        Logger.getLogger().println(Logger.WarningLog, "Warning: uma.properties file not found.");
    } catch (IOException e) {
        throw new UMAException(e);
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) UMAException(com.ibm.uma.UMAException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 7 with UMAException

use of com.ibm.uma.UMAException in project openj9 by eclipse.

the class Main method main.

public static void main(String[] args) {
    if (!parseOptions(args)) {
        System.out.print(applicationNameShort + " ");
        for (String arg : args) {
            System.out.print(" " + arg);
        }
        System.out.println();
        dumpHelp();
        System.exit(-1);
    }
    logger = Logger.initLogger(verbose ? Logger.InformationL2Log : Logger.InformationL1Log);
    dumpSplash();
    if (jitVersionFile.equals("")) {
        File tempJitVersionFile = new File(rootDir + "/compiler/trj9/build/version.h");
        if (tempJitVersionFile.exists() && !tempJitVersionFile.isDirectory()) {
            jitVersionFile = rootDir + "/compiler/trj9/build/version.h";
            System.out.print("Using version.h as the jitVersionFile\n");
        } else {
            tempJitVersionFile = new File(rootDir + "/jit.version");
            if (tempJitVersionFile.exists() && !tempJitVersionFile.isDirectory()) {
                jitVersionFile = rootDir + "/jit.version";
                System.out.print("Using jit.version as the jitVersionFile\n");
            }
        }
    }
    try {
        ConfigurationImpl configuration = new ConfigurationImpl(configDirectory, buildSpecId, buildId, buildDate, buildTag, jitVersionFile, excludeArtifacts);
        for (String flagString : overrideFlags.keySet()) {
            if (!configuration.isFlagValid(flagString)) {
                throw new UMAException("Invalid flag override: " + flagString);
            }
            Flag flag = configuration.getBuildSpec().getFlag(flagString);
            flag.setState(overrideFlags.get(flagString));
        }
        // Since we may have changed some flags, we need to re-verify them
        configuration.verify();
        new UMA(configuration, configuration, rootDir).generate();
    } catch (NullPointerException e) {
        logger.println(Logger.ErrorLog, "Internal error: null pointer exception");
        e.printStackTrace();
        System.exit(-1);
    } catch (UMAException e) {
        logger.println(Logger.ErrorLog, e.getMessage());
        System.exit(-1);
    }
}
Also used : UMA(com.ibm.uma.UMA) UMAException(com.ibm.uma.UMAException) File(java.io.File) ConfigurationImpl(com.ibm.j9.uma.configuration.ConfigurationImpl) Flag(com.ibm.j9tools.om.Flag)

Example 8 with UMAException

use of com.ibm.uma.UMAException in project openj9 by eclipse.

the class TemplateLoader method addAllTemplatesFoundInDirectory.

void addAllTemplatesFoundInDirectory(File dir) throws UMAException {
    String rootDir = UMA.getUma().getRootDirectory();
    File[] dirListing = dir.listFiles();
    Vector<File> directories = new Vector<File>();
    for (File file : dirListing) {
        if (file.isDirectory()) {
            directories.add(file);
        } else if (file.getName().endsWith(".ftl") || file.getName().endsWith(".iftl")) {
            String templatePath = file.getParent();
            if (templatePath.equalsIgnoreCase(rootDir) || rootDir.equalsIgnoreCase(templatePath + File.separator)) {
                templatePath = "";
            } else {
                templatePath = file.getParent().substring(rootDir.length());
            }
            templatePath = templatePath.replace(File.separator, "/");
            String templateName = (templatePath.length() == 0 ? "" : templatePath + "/") + file.getName();
            URL url;
            try {
                url = new URL("file:///" + file.getCanonicalPath());
            } catch (MalformedURLException e) {
                throw new UMAException(e);
            } catch (IOException e) {
                throw new UMAException(e);
            }
            HashMap<String, URL> templates = allTemplates;
            if (file.getName().endsWith(".inc.ftl") || file.getName().endsWith(".iftl")) {
                templates = allIncludeTemplates;
            }
            templates.put(templateName, url);
            Logger.getLogger().println(Logger.InformationL2Log, "Found template " + templateName + " URL: " + url.toExternalForm());
        }
    }
    for (File file : directories) {
        addAllTemplatesFoundInDirectory(file);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HashMap(java.util.HashMap) UMAException(com.ibm.uma.UMAException) IOException(java.io.IOException) File(java.io.File) Vector(java.util.Vector) URL(java.net.URL)

Example 9 with UMAException

use of com.ibm.uma.UMAException in project openj9 by eclipse.

the class ArtifactParser method parse.

public static Artifact parse(Node artifactNode, Module module) throws UMAException {
    Artifact artifact = new Artifact(module);
    NodeList nodeList = artifactNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        String nodeName = node.getLocalName();
        if (nodeName == null)
            continue;
        if (nodeName.equalsIgnoreCase("description")) {
            NodeList descChildren = node.getChildNodes();
            Node descChild = descChildren.item(0);
            artifact.setDescription(descChild.getNodeValue());
        } else if (nodeName.equalsIgnoreCase("options")) {
            NodeList optionsNodeList = node.getChildNodes();
            for (int j = 0; j < optionsNodeList.getLength(); j++) {
                Node optionItem = optionsNodeList.item(j);
                NamedNodeMap attributes = optionItem.getAttributes();
                if (attributes == null)
                    continue;
                Option option = OptionParser.parse(optionItem, artifact.getContainingFile());
                artifact.addOption(option);
            }
        } else if (nodeName.equalsIgnoreCase("phase")) {
            NodeList phaseChildren = node.getChildNodes();
            for (int j = 0; j < phaseChildren.getLength(); j++) {
                Node phasesNode = phaseChildren.item(j);
                String phaselist = phasesNode.getNodeValue();
                String[] phases = phaselist.split("\\s");
                for (int k = 0; k < phases.length; k++) {
                    try {
                        artifact.setPhase(UMA.getUma().getConfiguration().phaseFromString(phases[k]), true);
                    } catch (UMABadPhaseNameException e) {
                        throw new UMAException("in file: " + artifact.getContainingFile(), e);
                    }
                }
            }
        } else if (nodeName.equalsIgnoreCase("includes")) {
            NodeList includesNodeList = node.getChildNodes();
            for (int j = 0; j < includesNodeList.getLength(); j++) {
                Node includeItem = includesNodeList.item(j);
                NamedNodeMap attributes = includeItem.getAttributes();
                if (attributes == null)
                    continue;
                Include include = new Include(artifact.getContainingFile());
                include.setPath(attributes.getNamedItem("path").getNodeValue());
                include.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addInclude(include);
                Parser.populatePredicateList(includeItem.getChildNodes(), include);
            }
        } else if (nodeName.equalsIgnoreCase("commands")) {
            NodeList commandsNodeList = node.getChildNodes();
            for (int j = 0; j < commandsNodeList.getLength(); j++) {
                Node commandItem = commandsNodeList.item(j);
                NamedNodeMap attributes = commandItem.getAttributes();
                if (attributes == null)
                    continue;
                Command command = new Command(artifact.getContainingFile());
                command.setCommand(attributes.getNamedItem("line").getNodeValue());
                command.setType(attributes.getNamedItem("type").getNodeValue());
                artifact.addCommand(command);
                Parser.populatePredicateList(commandItem.getChildNodes(), command);
            }
        } else if (nodeName.equalsIgnoreCase("dependencies")) {
            NodeList dependenciesNodeList = node.getChildNodes();
            for (int j = 0; j < dependenciesNodeList.getLength(); j++) {
                Node dependencyItem = dependenciesNodeList.item(j);
                NamedNodeMap attributes = dependencyItem.getAttributes();
                if (attributes == null)
                    continue;
                Dependency dependency = new Dependency(artifact.getContainingFile());
                dependency.setDependency(attributes.getNamedItem("name").getNodeValue());
                artifact.addDependency(dependency);
                Parser.populatePredicateList(dependencyItem.getChildNodes(), dependency);
            }
        } else if (nodeName.equalsIgnoreCase("libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("static-link-libraries")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("library")) {
                    Library library = LibraryParser.parse(linkItem, artifact.getContainingFile());
                    artifact.addStaticLinkLibrary(library);
                }
            }
        } else if (nodeName.equalsIgnoreCase("objects")) {
            NodeList linkNodeList = node.getChildNodes();
            for (int j = 0; j < linkNodeList.getLength(); j++) {
                Node linkItem = linkNodeList.item(j);
                if (linkItem.getNodeName().equalsIgnoreCase("group") || linkItem.getNodeName().equalsIgnoreCase("object")) {
                    Object object = ObjectParser.parse(linkNodeList.item(j), artifact.getContainingFile());
                    artifact.addObject(object);
                }
            }
        } else if (nodeName.equalsIgnoreCase("vpaths")) {
            NodeList vpathsNodeList = node.getChildNodes();
            for (int j = 0; j < vpathsNodeList.getLength(); j++) {
                Node vpathItem = vpathsNodeList.item(j);
                if (vpathItem.getNodeName().equalsIgnoreCase("vpath")) {
                    VPath vpath = VPathParser.parse(vpathItem, artifact.getContainingFile());
                    artifact.addVPath(vpath);
                }
            }
        } else if (nodeName.equalsIgnoreCase("makefilestubs")) {
            NodeList mfsNodeList = node.getChildNodes();
            for (int j = 0; j < mfsNodeList.getLength(); j++) {
                Node mfsItem = mfsNodeList.item(j);
                if (mfsItem.getNodeName().equalsIgnoreCase("makefilestub")) {
                    NamedNodeMap attributes = mfsItem.getAttributes();
                    Node dataNode = attributes.getNamedItem("data");
                    MakefileStub makefileStub = new MakefileStub(dataNode.getNodeValue(), artifact.getContainingFile());
                    artifact.addMakefileStub(makefileStub);
                    Parser.populatePredicateList(mfsItem.getChildNodes(), makefileStub);
                }
            }
        } else if (nodeName.equalsIgnoreCase("exports")) {
            NodeList exportsNodeList = node.getChildNodes();
            for (int j = 0; j < exportsNodeList.getLength(); j++) {
                Node exportNode = exportsNodeList.item(j);
                if (exportNode.getNodeName().equalsIgnoreCase("group")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_GROUP);
                } else if (exportNode.getNodeName().equalsIgnoreCase("export")) {
                    Export group = ExportParser.parse(exportNode, artifact.getContainingFile());
                    artifact.addExport(group);
                    group.setType(Export.TYPE_FUNCTION);
                }
            }
        } else if (nodeName.equalsIgnoreCase("flags")) {
            NodeList flagsNodeList = node.getChildNodes();
            for (int j = 0; j < flagsNodeList.getLength(); j++) {
                Node item = flagsNodeList.item(j);
                Flag f = FlagParser.parse(item, artifact.getContainingFile());
                if (f != null) {
                    artifact.addFlag(f);
                }
            }
        }
    }
    NamedNodeMap attributes = artifactNode.getAttributes();
    Node nameNode = attributes.getNamedItem("name");
    artifact.setName(nameNode.getNodeValue());
    Node typeNode = attributes.getNamedItem("type");
    artifact.setType(typeNode.getNodeValue());
    Node bundleNode = attributes.getNamedItem("bundle");
    if (bundleNode != null) {
        artifact.setBundle(bundleNode.getNodeValue());
    }
    Node scopeNode = attributes.getNamedItem("scope");
    if (scopeNode != null) {
        artifact.setScope(scopeNode.getNodeValue());
    }
    Node includeInAllTargetNode = attributes.getNamedItem("all");
    if (includeInAllTargetNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setIncludeInAllTarget(true);
    } else {
        artifact.setIncludeInAllTarget(false);
    }
    Node loadgroupNode = attributes.getNamedItem("loadgroup");
    if (loadgroupNode != null) {
        artifact.setLoadgroup(loadgroupNode.getNodeValue());
    }
    Node buildLocal = attributes.getNamedItem("buildlocal");
    if (buildLocal.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setBuildLocal(true);
    }
    Node appendReleaseNode = attributes.getNamedItem("appendrelease");
    if (appendReleaseNode.getNodeValue().equalsIgnoreCase("true")) {
        artifact.setAppendRelease(true);
    }
    Node consoleNode = attributes.getNamedItem("console");
    if (consoleNode.getNodeValue().equalsIgnoreCase("false")) {
        artifact.setConsoleApplication(false);
    } else {
        artifact.setConsoleApplication(true);
    }
    Parser.populatePredicateList(nodeList, artifact);
    return artifact;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) MakefileStub(com.ibm.uma.om.MakefileStub) Include(com.ibm.uma.om.Include) UMAException(com.ibm.uma.UMAException) Dependency(com.ibm.uma.om.Dependency) Flag(com.ibm.uma.om.Flag) Artifact(com.ibm.uma.om.Artifact) Command(com.ibm.uma.om.Command) Export(com.ibm.uma.om.Export) Option(com.ibm.uma.om.Option) Object(com.ibm.uma.om.Object) VPath(com.ibm.uma.om.VPath) Library(com.ibm.uma.om.Library) UMABadPhaseNameException(com.ibm.uma.UMABadPhaseNameException)

Example 10 with UMAException

use of com.ibm.uma.UMAException in project openj9 by eclipse.

the class Parser method parse.

public boolean parse() throws UMAException {
    Vector<String> moduleFilenames = new Vector<String>();
    File rootDirectory = new File(generator.getRootDirectory());
    addAllModulesFoundInDiretory(rootDirectory, moduleFilenames);
    // parse it to determine directories to search for module.xml files.
    moduleFilenames = getModuleFilenames(moduleFilenames);
    // parse all found module.xml files.
    for (String moduleXmlFilename : moduleFilenames) {
        try {
            Logger.getLogger().println(Logger.InformationL2Log, "Parsing " + moduleXmlFilename);
            Document doc = parseFile(moduleXmlFilename);
            Module module = ModuleParser.parse(doc, moduleXmlFilename);
            modules.add(module);
        } catch (SAXException e) {
            throw new UMAException("Error: Module " + moduleXmlFilename + " failed to parse.", e);
        } catch (IOException e) {
            throw new UMAException("Error: " + e.getMessage(), e);
        }
    }
    resolveModuleHierarchy();
    return true;
}
Also used : UMAException(com.ibm.uma.UMAException) IOException(java.io.IOException) Document(org.w3c.dom.Document) Module(com.ibm.uma.om.Module) Vector(java.util.Vector) File(java.io.File) SAXException(org.xml.sax.SAXException)

Aggregations

UMAException (com.ibm.uma.UMAException)13 IOException (java.io.IOException)6 File (java.io.File)5 TemplateModel (freemarker.template.TemplateModel)4 TemplateModelException (freemarker.template.TemplateModelException)4 SimpleScalar (freemarker.template.SimpleScalar)3 FileNotFoundException (java.io.FileNotFoundException)2 Vector (java.util.Vector)2 ConfigurationImpl (com.ibm.j9.uma.configuration.ConfigurationImpl)1 Flag (com.ibm.j9tools.om.Flag)1 UMA (com.ibm.uma.UMA)1 UMABadPhaseNameException (com.ibm.uma.UMABadPhaseNameException)1 Artifact (com.ibm.uma.om.Artifact)1 Command (com.ibm.uma.om.Command)1 Dependency (com.ibm.uma.om.Dependency)1 Export (com.ibm.uma.om.Export)1 Flag (com.ibm.uma.om.Flag)1 Include (com.ibm.uma.om.Include)1 Library (com.ibm.uma.om.Library)1 MakefileStub (com.ibm.uma.om.MakefileStub)1