Search in sources :

Example 6 with InvariantViolationException

use of net.sf.launch4j.binding.InvariantViolationException in project SIMRacingApps by SIMRacingApps.

the class Cmd method build.

/**
	 * @return Output file path.
	 */
public File build() throws BuilderException {
    final Config c = ConfigPersister.getInstance().getConfig();
    try {
        c.validate();
    } catch (InvariantViolationException e) {
        throw new BuilderException(e.getMessage());
    }
    File rc = null;
    File ro = null;
    File outfile = null;
    FileInputStream is = null;
    FileOutputStream os = null;
    final RcBuilder rcb = new RcBuilder();
    try {
        if (c.isJniApplication()) {
            _log.append("WARNING: Some features are not implemented in JNI headers, see documentation.");
        }
        rc = rcb.build(c);
        ro = Util.createTempFile("o");
        outfile = ConfigPersister.getInstance().getOutputFile();
        Cmd resCmd = new Cmd(_basedir);
        resCmd.addExe("windres").add(Util.WINDOWS_OS ? "--preprocessor=type" : "--preprocessor=cat").add("-J rc -O coff -F pe-i386").addAbsFile(rc).addAbsFile(ro);
        _log.append(Messages.getString("Builder.compiling.resources"));
        resCmd.exec(_log);
        Cmd ldCmd = new Cmd(_basedir);
        ldCmd.addExe("ld").add("-mi386pe").add("--oformat pei-i386").add("--dynamicbase").add("--nxcompat").add("--no-seh").add(c.isGuiApplication() ? "--subsystem windows" : "--subsystem console").add(// strip symbols
        "-s").addFiles(c.getHeaderObjects()).addAbsFile(ro).addFiles(c.getLibs()).add("-o").addAbsFile(outfile);
        _log.append(Messages.getString("Builder.linking"));
        ldCmd.exec(_log);
        if (!c.isDontWrapJar()) {
            _log.append(Messages.getString("Builder.wrapping"));
            int len;
            byte[] buffer = new byte[1024];
            is = new FileInputStream(Util.getAbsoluteFile(ConfigPersister.getInstance().getConfigPath(), c.getJar()));
            os = new FileOutputStream(outfile, true);
            while ((len = is.read(buffer)) > 0) {
                os.write(buffer, 0, len);
            }
        }
        _log.append(Messages.getString("Builder.success") + outfile.getPath());
        return outfile;
    } catch (IOException e) {
        Util.delete(outfile);
        _log.append(e.getMessage());
        throw new BuilderException(e);
    } catch (ExecException e) {
        Util.delete(outfile);
        String msg = e.getMessage();
        if (msg != null && msg.indexOf("windres") != -1) {
            if (e.getErrLine() != -1) {
                _log.append(Messages.getString("Builder.line.has.errors", String.valueOf(e.getErrLine())));
                _log.append(rcb.getLine(e.getErrLine()));
            } else {
                _log.append(Messages.getString("Builder.generated.resource.file"));
                _log.append(rcb.getContent());
            }
        }
        throw new BuilderException(e);
    } finally {
        Util.close(is);
        Util.close(os);
        Util.delete(rc);
        Util.delete(ro);
    }
}
Also used : Config(net.sf.launch4j.config.Config) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InvariantViolationException(net.sf.launch4j.binding.InvariantViolationException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 7 with InvariantViolationException

use of net.sf.launch4j.binding.InvariantViolationException in project chipKIT32-MAX by chipKIT32.

the class Cmd method build.

/**
	 * @return Output file path.
	 */
public File build() throws BuilderException {
    final Config c = ConfigPersister.getInstance().getConfig();
    try {
        c.validate();
    } catch (InvariantViolationException e) {
        throw new BuilderException(e.getMessage());
    }
    File rc = null;
    File ro = null;
    File outfile = null;
    FileInputStream is = null;
    FileOutputStream os = null;
    final RcBuilder rcb = new RcBuilder();
    try {
        rc = rcb.build(c);
        ro = Util.createTempFile("o");
        outfile = ConfigPersister.getInstance().getOutputFile();
        Cmd resCmd = new Cmd(_basedir);
        resCmd.addExe("windres").add(Util.WINDOWS_OS ? "--preprocessor=type" : "--preprocessor=cat").add("-J rc -O coff -F pe-i386").addAbsFile(rc).addAbsFile(ro);
        _log.append(Messages.getString("Builder.compiling.resources"));
        resCmd.exec(_log);
        Cmd ldCmd = new Cmd(_basedir);
        ldCmd.addExe("ld").add("-mi386pe").add("--oformat pei-i386").add((c.getHeaderType().equals(Config.GUI_HEADER)) ? "--subsystem windows" : "--subsystem console").add(// strip symbols
        "-s").addFiles(c.getHeaderObjects()).addAbsFile(ro).addFiles(c.getLibs()).add("-o").addAbsFile(outfile);
        _log.append(Messages.getString("Builder.linking"));
        ldCmd.exec(_log);
        if (!c.isDontWrapJar()) {
            _log.append(Messages.getString("Builder.wrapping"));
            int len;
            byte[] buffer = new byte[1024];
            is = new FileInputStream(Util.getAbsoluteFile(ConfigPersister.getInstance().getConfigPath(), c.getJar()));
            os = new FileOutputStream(outfile, true);
            while ((len = is.read(buffer)) > 0) {
                os.write(buffer, 0, len);
            }
        }
        _log.append(Messages.getString("Builder.success") + outfile.getPath());
        return outfile;
    } catch (IOException e) {
        Util.delete(outfile);
        _log.append(e.getMessage());
        throw new BuilderException(e);
    } catch (ExecException e) {
        Util.delete(outfile);
        String msg = e.getMessage();
        if (msg != null && msg.indexOf("windres") != -1) {
            if (e.getErrLine() != -1) {
                _log.append(Messages.getString("Builder.line.has.errors", String.valueOf(e.getErrLine())));
                _log.append(rcb.getLine(e.getErrLine()));
            } else {
                _log.append(Messages.getString("Builder.generated.resource.file"));
                _log.append(rcb.getContent());
            }
        }
        throw new BuilderException(e);
    } finally {
        Util.close(is);
        Util.close(os);
        Util.delete(rc);
        Util.delete(ro);
    }
}
Also used : Config(net.sf.launch4j.config.Config) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InvariantViolationException(net.sf.launch4j.binding.InvariantViolationException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 8 with InvariantViolationException

use of net.sf.launch4j.binding.InvariantViolationException in project beast-mcmc by beast-dev.

the class Cmd method build.

/**
	 * @return Output file path.
	 */
public File build() throws BuilderException {
    final Config c = ConfigPersister.getInstance().getConfig();
    try {
        c.validate();
    } catch (InvariantViolationException e) {
        throw new BuilderException(e.getMessage());
    }
    File rc = null;
    File ro = null;
    File outfile = null;
    FileInputStream is = null;
    FileOutputStream os = null;
    final RcBuilder rcb = new RcBuilder();
    try {
        rc = rcb.build(c);
        ro = Util.createTempFile("o");
        outfile = ConfigPersister.getInstance().getOutputFile();
        Cmd resCmd = new Cmd(_basedir);
        resCmd.addExe("windres").add(Util.WINDOWS_OS ? "--preprocessor=type" : "--preprocessor=cat").add("-J rc -O coff -F pe-i386").addAbsFile(rc).addAbsFile(ro);
        _log.append(Messages.getString("Builder.compiling.resources"));
        resCmd.exec(_log);
        Cmd ldCmd = new Cmd(_basedir);
        ldCmd.addExe("ld").add("-mi386pe").add("--oformat pei-i386").add("--dynamicbase").add("--nxcompat").add("--no-seh").add((c.getHeaderType().equals(Config.GUI_HEADER)) ? "--subsystem windows" : "--subsystem console").add(// strip symbols
        "-s").addFiles(c.getHeaderObjects()).addAbsFile(ro).addFiles(c.getLibs()).add("-o").addAbsFile(outfile);
        _log.append(Messages.getString("Builder.linking"));
        ldCmd.exec(_log);
        if (!c.isDontWrapJar()) {
            _log.append(Messages.getString("Builder.wrapping"));
            int len;
            byte[] buffer = new byte[1024];
            is = new FileInputStream(Util.getAbsoluteFile(ConfigPersister.getInstance().getConfigPath(), c.getJar()));
            os = new FileOutputStream(outfile, true);
            while ((len = is.read(buffer)) > 0) {
                os.write(buffer, 0, len);
            }
        }
        _log.append(Messages.getString("Builder.success") + outfile.getPath());
        return outfile;
    } catch (IOException e) {
        Util.delete(outfile);
        _log.append(e.getMessage());
        throw new BuilderException(e);
    } catch (ExecException e) {
        Util.delete(outfile);
        String msg = e.getMessage();
        if (msg != null && msg.indexOf("windres") != -1) {
            if (e.getErrLine() != -1) {
                _log.append(Messages.getString("Builder.line.has.errors", String.valueOf(e.getErrLine())));
                _log.append(rcb.getLine(e.getErrLine()));
            } else {
                _log.append(Messages.getString("Builder.generated.resource.file"));
                _log.append(rcb.getContent());
            }
        }
        throw new BuilderException(e);
    } finally {
        Util.close(is);
        Util.close(os);
        Util.delete(rc);
        Util.delete(ro);
    }
}
Also used : Config(net.sf.launch4j.config.Config) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) InvariantViolationException(net.sf.launch4j.binding.InvariantViolationException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

File (java.io.File)8 InvariantViolationException (net.sf.launch4j.binding.InvariantViolationException)8 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)4 BindingException (net.sf.launch4j.binding.BindingException)4 Config (net.sf.launch4j.config.Config)4 ConfigPersisterException (net.sf.launch4j.config.ConfigPersisterException)4