static private List getCommandCompilerCPP(String avrBasePath, List includePaths, String sourceName, String objectName, Map<String, String> boardPreferences) { List baseCommandCompilerCPP = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-g++", "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-Os", // optimize for size Preferences.getBoolean("build.verbose") ? "-Wall" : "-w", // show warnings if verbose "-fno-exceptions", "-ffunction-sections", // place each function in its own section "-fdata-sections", "-mmcu=" + boardPreferences.get("build.mcu"), "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-MMD", // output dependancy info "-DUSB_VID=" + boardPreferences.get("build.vid"), "-DUSB_PID=" + boardPreferences.get("build.pid"), "-DARDUINO=" + Base.REVISION, })); for (int i = 0; i < includePaths.size(); i++) { baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); } baseCommandCompilerCPP.add(sourceName); baseCommandCompilerCPP.add("-o"); baseCommandCompilerCPP.add(objectName); return baseCommandCompilerCPP; }
@SuppressWarnings("squid:S1244") private static String selectBestEncoding(String acceptEncodingHeader) { // multiple encodings are accepted; determine best one Collection<String> bestEncodings = new HashSet<>(3); double bestQ = 0.0; Collection<String> unacceptableEncodings = new HashSet<>(3); boolean willAcceptAnything = false; for (String token : COMMA.split(acceptEncodingHeader)) { ContentEncodingQ contentEncodingQ = parseContentEncodingQ(token); String contentEncoding = contentEncodingQ.getContentEncoding(); double q = contentEncodingQ.getQ(); if (ANY_ENCODING.equals(contentEncoding)) { willAcceptAnything = q > 0.0; } else if (SUPPORTED_ENCODINGS.contains(contentEncoding)) { if (q > 0.0) { // This is a header quality comparison. // So it is safe to suppress warning squid:S1244 if (q == bestQ) { bestEncodings.add(contentEncoding); } else if (q > bestQ) { bestQ = q; bestEncodings.clear(); bestEncodings.add(contentEncoding); } } else { unacceptableEncodings.add(contentEncoding); } } } if (bestEncodings.isEmpty()) { // nothing was acceptable to us if (willAcceptAnything) { if (unacceptableEncodings.isEmpty()) { return SUPPORTED_ENCODINGS.get(0); } else { for (String encoding : SUPPORTED_ENCODINGS) { if (!unacceptableEncodings.contains(encoding)) { return encoding; } } } } } else { for (String encoding : SUPPORTED_ENCODINGS) { if (bestEncodings.contains(encoding)) { return encoding; } } } return NO_ENCODING; }
private static String parseBestEncoding(String acceptEncodingHeader) { ContentEncodingQ contentEncodingQ = parseContentEncodingQ(acceptEncodingHeader); String contentEncoding = contentEncodingQ.getContentEncoding(); if (contentEncodingQ.getQ() > 0.0) { if (ANY_ENCODING.equals(contentEncoding)) { return SUPPORTED_ENCODINGS.get(0); } else if (SUPPORTED_ENCODINGS.contains(contentEncoding)) { return contentEncoding; } } return NO_ENCODING; }
/** * Writes the index file out to <code>jos</code>. <code>oldEntries</code> gives the names of the * files that were removed, <code>movedMap</code> maps from the new name to the old name. */ private static void createIndex(JarOutputStream jos, List oldEntries, Map movedMap) throws IOException { StringWriter writer = new StringWriter(); writer.write(VERSION_HEADER); writer.write("\r\n"); // Write out entries that have been removed for (int counter = 0; counter < oldEntries.size(); counter++) { String name = (String) oldEntries.get(counter); writer.write(REMOVE_COMMAND); writer.write(" "); writeEscapedString(writer, name); writer.write("\r\n"); } // And those that have moved Iterator names = movedMap.keySet().iterator(); if (names != null) { while (names.hasNext()) { String newName = (String) names.next(); String oldName = (String) movedMap.get(newName); writer.write(MOVE_COMMAND); writer.write(" "); writeEscapedString(writer, oldName); writer.write(" "); writeEscapedString(writer, newName); writer.write("\r\n"); } } JarEntry je = new JarEntry(INDEX_NAME); byte[] bytes = writer.toString().getBytes("UTF-8"); writer.close(); jos.putNextEntry(je); jos.write(bytes, 0, bytes.length); }
static private List getCommandCompilerS(String avrBasePath, List includePaths, String sourceName, String objectName, Map<String, String> boardPreferences) { List baseCommandCompiler = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-c", // compile, don't link "-g", // include debugging info (so errors include line numbers) "-assembler-with-cpp", "-mmcu=" + boardPreferences.get("build.mcu"), "-DF_CPU=" + boardPreferences.get("build.f_cpu"), "-DARDUINO=" + Base.REVISION, "-DUSB_VID=" + boardPreferences.get("build.vid"), "-DUSB_PID=" + boardPreferences.get("build.pid"), })); for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); } baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+ objectName); return baseCommandCompiler; }
/** The run method. */ public void run() { instances.add(this); try { listener.startUnpack(); String currentOs = System.getProperty("os.name").toLowerCase(); // // Initialisations FileOutputStream out = null; ArrayList parsables = new ArrayList(); ArrayList executables = new ArrayList(); List packs = idata.selectedPacks; int npacks = packs.size(); udata = UninstallData.getInstance(); // Specific to the web installers if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) { InputStream kin = getClass().getResourceAsStream("/res/WebInstallers.url"); BufferedReader kreader = new BufferedReader(new InputStreamReader(kin)); jarLocation = kreader.readLine(); } // We unpack the selected packs for (int i = 0; i < npacks; i++) { // We get the pack stream int n = idata.allPacks.indexOf(packs.get(i)); ObjectInputStream objIn = new ObjectInputStream(getPackAsStream(n)); // We unpack the files int nfiles = objIn.readInt(); listener.changeUnpack(0, nfiles, ((Pack) packs.get(i)).name); for (int j = 0; j < nfiles; j++) { // We read the header PackFile pf = (PackFile) objIn.readObject(); if (null == pf.os || matchOS(currentOs, pf.os.toLowerCase())) { // We translate & build the path String path = translatePath(pf.targetPath); File pathFile = new File(path); String fname = pathFile.getName(); int z = fname.length(); File dest = pathFile.getParentFile(); if (!dest.exists()) dest.mkdirs(); // We add the path to the log, udata.addFile(path); listener.progressUnpack(j, path); // if this file exists and shouldnot override skip this file if (((pf.override == false) && (pathFile.exists()))) { objIn.skip(pf.length); continue; } // We copy the file out = new FileOutputStream(path); byte[] buffer = new byte[5120]; long bytesCopied = 0; while (bytesCopied < pf.length) { int maxBytes = (pf.length - bytesCopied < buffer.length ? (int) (pf.length - bytesCopied) : buffer.length); int bytesInBuffer = objIn.read(buffer, 0, maxBytes); if (bytesInBuffer == -1) throw new IOException("Unexpected end of stream"); out.write(buffer, 0, bytesInBuffer); bytesCopied += bytesInBuffer; } // Cleanings out.close(); // Empty dirs restoring String _n = pathFile.getName(); if (_n.startsWith("izpack-keepme") && _n.endsWith(".tmp")) pathFile.delete(); } else objIn.skip(pf.length); } // Load information about parsable files int numParsables = objIn.readInt(); int k; for (k = 0; k < numParsables; k++) { ParsableFile pf = (ParsableFile) objIn.readObject(); pf.path = translatePath(pf.path); parsables.add(pf); } // Load information about executable files int numExecutables = objIn.readInt(); for (k = 0; k < numExecutables; k++) { ExecutableFile ef = (ExecutableFile) objIn.readObject(); ef.path = translatePath(ef.path); if (null != ef.argList && !ef.argList.isEmpty()) { String arg = null; for (int j = 0; j < ef.argList.size(); j++) { arg = (String) ef.argList.get(j); arg = translatePath(arg); ef.argList.set(j, arg); } } executables.add(ef); if (ef.executionStage == ExecutableFile.UNINSTALL) { udata.addExecutable(ef); } } objIn.close(); } // We use the scripts parser ScriptParser parser = new ScriptParser(parsables, vs); parser.parseFiles(); // We use the file executor FileExecutor executor = new FileExecutor(executables); if (executor.executeFiles(ExecutableFile.POSTINSTALL) != 0) javax.swing.JOptionPane.showMessageDialog( null, "The installation was not completed.", "Installation warning", javax.swing.JOptionPane.WARNING_MESSAGE); // We put the uninstaller putUninstaller(); // The end :-) listener.stopUnpack(); } catch (Exception err) { listener.stopUnpack(); listener.errorUnpack(err.toString()); } instances.remove(instances.indexOf(this)); }