Search in sources :

Example 1 with FileAssistant

use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.

the class PlatformWindows method writeExecutableManifestFile.

// TODO: move to template
void writeExecutableManifestFile(Artifact artifact) throws UMAException {
    if (artifact.getType() != Artifact.TYPE_EXECUTABLE)
        return;
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".exe.manifest";
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    buffer.append("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n" + "<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>\n" + "  <trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\">\n" + "    <security>\n" + "      <requestedPrivileges>\n" + "        <requestedExecutionLevel level='asInvoker' uiAccess='false' />\n" + "      </requestedPrivileges>\n" + "    </security>\n" + "  </trustInfo>\n" + "</assembly>\n");
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant)

Example 2 with FileAssistant

use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.

the class PlatformWindows method writeExportFile.

// TODO: convert to template
@Override
protected void writeExportFile(Artifact artifact) throws UMAException {
    if (artifact.getType() != Artifact.TYPE_SHARED && artifact.getType() != Artifact.TYPE_BUNDLE) {
        return;
    }
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".def";
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    buffer.append("LIBRARY " + getTargetNameWithRelease(artifact).toUpperCase() + "\n");
    if (!isProcessor("amd64") && !isType("ce")) {
        buffer.append("\n\nSECTIONS\n\t.data\tREAD WRITE\n\t.text\tEXECUTE READ\n\n");
    }
    Vector<Export> exports = artifact.getArtifactExportedFunctions();
    StringBuffer exportsBuffer = new StringBuffer();
    exportsBuffer.append("EXPORTS\n");
    boolean exportDefined = false;
    for (Export export : exports) {
        if (!export.evaluate())
            continue;
        exportDefined = true;
        String exportString = export.getExport();
        if (isProcessor("amd64")) {
            exportString = stripExportName(exportString);
        }
        exportsBuffer.append("\t" + exportString + "\n");
    }
    if (exportDefined) {
        buffer.append(exportsBuffer.toString() + "\n");
    }
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Export(com.ibm.uma.om.Export)

Example 3 with FileAssistant

use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.

the class PlatformWindows method writeExecutableResourceFile.

// TODO: move to template
void writeExecutableResourceFile(Artifact artifact) throws UMAException {
    if (artifact.getType() != Artifact.TYPE_EXECUTABLE)
        return;
    GregorianCalendar calendar = new GregorianCalendar();
    String filename = UMA.getUma().getRootDirectory() + artifact.getContainingModule().getFullName() + "/" + artifact.getTargetNameWithScope() + ".rc";
    FileAssistant fa = new FileAssistant(filename);
    StringBuffer buffer = fa.getStringBuffer();
    String productName = replaceMacro("rc_productName");
    if (productName == null) {
        productName = DEFAULT_RC_PRODUCT_NAME;
    }
    int buildIdLow = Integer.parseInt(getBuildId()) & 0xffff;
    int buildIdHigh = Integer.parseInt(getBuildId()) >> 16;
    buffer.append("\n" + "#include <windows.h>\n");
    writeResourceFileDefines(buffer);
    buffer.append("#include \"j9cfg.h\"\n" + "#include \"j9version.h\"\n" + "\n" + "VS_VERSION_INFO VERSIONINFO\n" + " FILEVERSION " + getMajorVersion() + "," + getMinorVersion() + "," + buildIdHigh + "," + buildIdLow + "\n" + " PRODUCTVERSION " + getMajorVersion() + "," + getMinorVersion() + "," + buildIdHigh + "," + buildIdLow + "\n" + " FILEFLAGSMASK 0x3fL\n" + " FILEFLAGS 0x0L\n" + " FILEOS VOS_NT_WINDOWS32\n" + " FILETYPE VFT_APP\n" + " FILESUBTYPE 0x0L\n" + "BEGIN\n" + "	BLOCK \"StringFileInfo\"\n" + "	BEGIN\n" + "		BLOCK \"040904b0\"\n" + "		BEGIN\n" + "			VALUE \"CompanyName\", \"International Business Machines Corporation\\0\"\n" + "			VALUE \"FileDescription\", \"WebSphere Studio Device Developer\\0\"\n" + "			VALUE \"FileVersion\", \"R" + getMajorVersion() + "." + getMinorVersion() + " (\" EsBuildVersionString \")\\0\"\n" + "			VALUE \"InternalName\", \"" + getTargetNameWithRelease(artifact) + "\\0\"\n" + "			VALUE \"LegalCopyright\", \" Copyright (c) 1991, " + calendar.get(Calendar.YEAR) + " IBM Corp. and others\\0\"\n" + "			VALUE \"OriginalFilename\", \"" + getTargetNameWithRelease(artifact) + ".dll\\0\"\n" + "			VALUE \"ProductName\", \"" + productName + "\\0\"\n" + "			VALUE \"ProductVersion\", \"R" + getMajorVersion() + "." + getMinorVersion() + "\\0\"\n" + "		END\n" + "	END\n" + "	BLOCK \"VarFileInfo\"\n" + "	BEGIN\n" + "		VALUE \"Translation\", 0x0409, 1200\n" + "	END\n" + "END\n");
    if (replaceMacro("uma.includeIcon").equalsIgnoreCase("true")) {
        buffer.append("\n" + "100	ICON	DISCARDABLE	\"..\\include\\j9.ico\"\n");
    }
    if (isType("ce"))
        writeExecutableResourceFileExtraCommands(buffer);
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) GregorianCalendar(java.util.GregorianCalendar)

Example 4 with FileAssistant

use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.

the class UMA method generate.

public void generate() throws UMAException {
    Parser parser = new Parser(this);
    if (!parser.parse()) {
        return;
    }
    modules = parser.getModules();
    platform.decorateModules(modules);
    try {
        Map<String, TemplateModel> map = new HashMap<String, TemplateModel>();
        map.put(FREEMARKER_UMA, new com.ibm.uma.freemarker.UMA());
        for (String tmp : templateLoader.getTemplates()) {
            Template template = freemarkerConfig.getTemplate(tmp);
            String filename = tmp.substring(0, tmp.lastIndexOf(".ftl"));
            StringWriter writer = new StringWriter();
            template.process(map, writer);
            new FileAssistant(this.rootDirectory + filename, writer.getBuffer()).writeToDisk();
        }
    } catch (IOException e) {
        throw new UMAException(e);
    } catch (TemplateException e) {
        throw new UMAException(e);
    }
    writeTargetInformationMacrosFile();
    // top level module is the first in the list.
    Module rootModule = null;
    for (Module module : modules) {
        if (module.isTopLevel()) {
            if (rootModule != null) {
                throw new UMAException("Error: more than one root module " + rootModule.getFullName() + " and " + module.getFullName());
            }
            rootModule = module;
        }
    }
    if (rootModule == null) {
        throw new UMAException("Error: no " + configuration.getMetadataFilename() + " found in the root directory " + getRootDirectory());
    }
    writeDirectoryMakefile(rootModule);
    Logger.getLogger().println(Logger.InformationL1Log, "Complete");
}
Also used : HashMap(java.util.HashMap) TemplateException(freemarker.template.TemplateException) TemplateModel(freemarker.template.TemplateModel) IOException(java.io.IOException) Parser(com.ibm.uma.om.parser.Parser) Template(freemarker.template.Template) FileAssistant(com.ibm.uma.util.FileAssistant) StringWriter(java.io.StringWriter) Module(com.ibm.uma.om.Module)

Example 5 with FileAssistant

use of com.ibm.uma.util.FileAssistant in project openj9 by eclipse.

the class UMA method writeMakefileForArtifact.

void writeMakefileForArtifact(Artifact artifact) throws UMAException {
    if (!artifact.evaluate() || artifact.getType() == Artifact.TYPE_SUBDIR || artifact.getType() == Artifact.TYPE_REFERENCE || artifact.getType() == Artifact.TYPE_TARGET)
        return;
    Module module = artifact.getContainingModule();
    String modulePath = new File(module.getModulePath()).getParent();
    String makefileName = artifact.getMakefileFileName();
    makefileName = modulePath + File.separator + makefileName;
    platform.writePlatformSpecificFiles(artifact);
    FileAssistant fa = new FileAssistant(makefileName);
    StringBuffer buffer = fa.getStringBuffer();
    buffer.append("# Makefile for '" + artifact.getMakefileName() + "'\n");
    buffer.append(configuration.getMakefileCopyrightNotice());
    String pathToRoot = determinePathToRoot(module);
    buffer.append(UMA_PATH_TO_ROOT + "=" + pathToRoot + "\n");
    buffer.append(OMR_DIR + "?=" + pathToRoot + "omr\n");
    switch(artifact.getType()) {
        // fall-thru
        case Artifact.TYPE_BUNDLE:
        case Artifact.TYPE_SHARED:
            buffer.append("UMA_TARGET_TYPE=DLL\n");
            break;
        case Artifact.TYPE_EXECUTABLE:
            buffer.append("UMA_TARGET_TYPE=EXE\n");
            break;
        case Artifact.TYPE_STATIC:
            buffer.append("UMA_TARGET_TYPE=LIB\n");
            break;
    }
    buffer.append("UMA_TARGET_NAME=" + artifact.getTargetNameWithScope() + "\n");
    if (artifact.getTargetPath() != null) {
        buffer.append("UMA_TARGET_PATH=" + UMA_PATH_TO_ROOT_VAR + artifact.getTargetPath() + "\n");
    }
    if (artifact.flagSet("isCPlusPlus")) {
        buffer.append("UMA_IS_C_PLUS_PLUS=1\n");
    }
    platform.addArtifactSpecificMakefileInformation(artifact, buffer);
    buffer.append("\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_MKCONSTANTS_PATH_FROM_ROOT + "\n\n");
    writeMakefileIncludeLine(buffer, module, artifact);
    writeMakefileLibraryLine(buffer, module, artifact);
    buffer.append(platform.writeMakefileFlagsLine(artifact).toString());
    writeMakefileObjectLine(buffer, module, artifact);
    buffer.append(platform.writeMakefileExtras(artifact).toString());
    writeMakefileStubs(buffer, module, artifact);
    writeMakefileVPathInformation(buffer, module, artifact);
    buffer.append(platform.writeMakefilePostscript(artifact).toString());
    if (artifact.getCommands().isEmpty()) {
        buffer.append("\ninclude " + UMA_PATH_TO_ROOT_VAR + UMA_TARGET_MAKEFILE_WITH_PATH + "\n");
    } else {
        /* Support custom recipes for building a target.
				 * 
				 * If module.xml specifies <commands /> for this artifact, we will use the commands
				 * to build the on-disk artifact, instead of the rules in targets.mk.
				 */
        /* uma_macros.mk defines the names of the ondisk artifact and its dependencies */
        buffer.append("include " + UMA_PATH_TO_ROOT_VAR + UMA_MACROS_PATH_FROM_ROOT + "\n\n");
        /* Defines the default target.
				 * 
				 * $($(target)_ondisk): $($(target)_dependencies)
				 * 		commands with type="all"
				 */
        buffer.append("$(" + artifact.getTargetNameWithScope() + "_ondisk): ");
        buffer.append("$(" + artifact.getTargetNameWithScope() + "_dependencies)\n");
        for (Command command : artifact.getCommands()) {
            if (!command.evaluate() || command.getType() != Command.TYPE_ALL)
                continue;
            buffer.append("\t" + command.getCommand() + "\n");
        }
        buffer.append("\n");
        /* Defines the clean target.
				 * 
				 * clean:
				 * 		commands with type="clean"
				 */
        buffer.append("clean:\n");
        for (Command command : artifact.getCommands()) {
            if (!command.evaluate() || command.getType() != Command.TYPE_CLEAN)
                continue;
            buffer.append("\t" + command.getCommand() + "\n");
        }
        buffer.append("\n");
        /* Defines the ddrgen target.
				 * 
				 * ddrgen:
				 * 		commands with type="ddrgen"
				 */
        buffer.append("ddrgen:\n");
        for (Command command : artifact.getCommands()) {
            if (!command.evaluate() || command.getType() != Command.TYPE_DDRGEN)
                continue;
            buffer.append("\t" + command.getCommand() + "\n");
        }
        buffer.append("\n");
    }
    fa.writeToDisk();
}
Also used : FileAssistant(com.ibm.uma.util.FileAssistant) Command(com.ibm.uma.om.Command) Module(com.ibm.uma.om.Module) File(java.io.File)

Aggregations

FileAssistant (com.ibm.uma.util.FileAssistant)10 Artifact (com.ibm.uma.om.Artifact)3 Export (com.ibm.uma.om.Export)3 Module (com.ibm.uma.om.Module)3 File (java.io.File)3 Command (com.ibm.uma.om.Command)2 SubdirArtifact (com.ibm.uma.om.SubdirArtifact)2 GregorianCalendar (java.util.GregorianCalendar)2 Vector (java.util.Vector)2 Dependency (com.ibm.uma.om.Dependency)1 Library (com.ibm.uma.om.Library)1 Parser (com.ibm.uma.om.parser.Parser)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 TemplateModel (freemarker.template.TemplateModel)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 LinkedHashSet (java.util.LinkedHashSet)1