List of usage examples for java.io ByteArrayOutputStream reset
public synchronized void reset()
From source file:au.com.rayh.XCodeBuilder.java
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { EnvVars envs = build.getEnvironment(listener); FilePath projectRoot = build.getWorkspace(); // check that the configured tools exist if (!new FilePath(projectRoot.getChannel(), getDescriptor().getXcodebuildPath()).exists()) { listener.fatalError(Messages.XCodeBuilder_xcodebuildNotFound(getDescriptor().getXcodebuildPath())); return false; }/*from w w w. j a v a 2 s. co m*/ if (!new FilePath(projectRoot.getChannel(), getDescriptor().getAgvtoolPath()).exists()) { listener.fatalError(Messages.XCodeBuilder_avgtoolNotFound(getDescriptor().getAgvtoolPath())); return false; } // Start expanding all string variables in parameters // NOTE: we currently use variable shadowing to avoid having to rewrite all code (and break pull requests), this will be cleaned up at later stage. String configuration = envs.expand(this.configuration); String target = envs.expand(this.target); String sdk = envs.expand(this.sdk); String symRoot = envs.expand(this.symRoot); String configurationBuildDir = envs.expand(this.configurationBuildDir); String xcodeProjectPath = envs.expand(this.xcodeProjectPath); String xcodeProjectFile = envs.expand(this.xcodeProjectFile); String xcodebuildArguments = envs.expand(this.xcodebuildArguments); String xcodeSchema = envs.expand(this.xcodeSchema); String xcodeWorkspaceFile = envs.expand(this.xcodeWorkspaceFile); String embeddedProfileFile = envs.expand(this.embeddedProfileFile); String cfBundleVersionValue = envs.expand(this.cfBundleVersionValue); String cfBundleShortVersionStringValue = envs.expand(this.cfBundleShortVersionStringValue); String keychainPath = envs.expand(this.keychainPath); String keychainPwd = envs.expand(this.keychainPwd); String codeSigningIdentity = envs.expand(this.codeSigningIdentity); // End expanding all string variables in parameters // Set the working directory if (!StringUtils.isEmpty(xcodeProjectPath)) { projectRoot = projectRoot.child(xcodeProjectPath); } listener.getLogger().println(Messages.XCodeBuilder_workingDir(projectRoot)); // Infer as best we can the build platform String buildPlatform = "iphoneos"; if (!StringUtils.isEmpty(sdk)) { if (StringUtils.contains(sdk.toLowerCase(), "iphonesimulator")) { // Building for the simulator buildPlatform = "iphonesimulator"; } } // Set the build directory and the symRoot // String symRootValue = null; if (!StringUtils.isEmpty(symRoot)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin symRootValue = TokenMacro.expandAll(build, listener, symRoot).trim(); } catch (MacroEvaluationException e) { listener.error(Messages.XCodeBuilder_symRootMacroError(e.getMessage())); return false; } } String configurationBuildDirValue = null; FilePath buildDirectory; if (!StringUtils.isEmpty(configurationBuildDir)) { try { configurationBuildDirValue = TokenMacro.expandAll(build, listener, configurationBuildDir).trim(); } catch (MacroEvaluationException e) { listener.error(Messages.XCodeBuilder_configurationBuildDirMacroError(e.getMessage())); return false; } } if (configurationBuildDirValue != null) { // If there is a CONFIGURATION_BUILD_DIR, that overrides any use of SYMROOT. Does not require the build platform and the configuration. buildDirectory = new FilePath(projectRoot.getChannel(), configurationBuildDirValue); } else if (symRootValue != null) { // If there is a SYMROOT specified, compute the build directory from that. buildDirectory = new FilePath(projectRoot.getChannel(), symRootValue) .child(configuration + "-" + buildPlatform); } else { // Assume its a build for the handset, not the simulator. buildDirectory = projectRoot.child("build").child(configuration + "-" + buildPlatform); } // XCode Version int returnCode = launcher.launch().envs(envs).cmds(getDescriptor().getXcodebuildPath(), "-version") .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_xcodeVersionNotFound()); return false; // We fail the build if XCode isn't deployed } ByteArrayOutputStream output = new ByteArrayOutputStream(); // Try to read CFBundleShortVersionString from project listener.getLogger().println(Messages.XCodeBuilder_fetchingCFBundleShortVersionString()); String cfBundleShortVersionString = ""; returnCode = launcher.launch().envs(envs).cmds(getDescriptor().getAgvtoolPath(), "mvers", "-terse1") .stdout(output).pwd(projectRoot).join(); // only use this version number if we found it if (returnCode == 0) cfBundleShortVersionString = output.toString().trim(); if (StringUtils.isEmpty(cfBundleShortVersionString)) listener.getLogger().println(Messages.XCodeBuilder_CFBundleShortVersionStringNotFound()); else listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringFound(cfBundleShortVersionString)); listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringValue(cfBundleShortVersionString)); output.reset(); // Try to read CFBundleVersion from project listener.getLogger().println(Messages.XCodeBuilder_fetchingCFBundleVersion()); String cfBundleVersion = ""; returnCode = launcher.launch().envs(envs).cmds(getDescriptor().getAgvtoolPath(), "vers", "-terse") .stdout(output).pwd(projectRoot).join(); // only use this version number if we found it if (returnCode == 0) cfBundleVersion = output.toString().trim(); if (StringUtils.isEmpty(cfBundleVersion)) listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionNotFound()); else listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionFound(cfBundleShortVersionString)); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionValue(cfBundleVersion)); String buildDescription = cfBundleShortVersionString + " (" + cfBundleVersion + ")"; XCodeAction a = new XCodeAction(buildDescription); build.addAction(a); // Update the Marketing version (CFBundleShortVersionString) if (!StringUtils.isEmpty(cfBundleShortVersionStringValue)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin cfBundleShortVersionString = TokenMacro.expandAll(build, listener, cfBundleShortVersionStringValue); listener.getLogger().println( Messages.XCodeBuilder_CFBundleShortVersionStringUpdate(cfBundleShortVersionString)); returnCode = launcher.launch().envs(envs) .cmds(getDescriptor().getAgvtoolPath(), "new-marketing-version", cfBundleShortVersionString) .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages .XCodeBuilder_CFBundleShortVersionStringUpdateError(cfBundleShortVersionString)); return false; } } catch (MacroEvaluationException e) { listener.fatalError(Messages.XCodeBuilder_CFBundleShortVersionStringMacroError(e.getMessage())); // Fails the build return false; } } // Update the Technical version (CFBundleVersion) if (!StringUtils.isEmpty(cfBundleVersionValue)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin cfBundleVersion = TokenMacro.expandAll(build, listener, cfBundleVersionValue); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionUpdate(cfBundleVersion)); returnCode = launcher.launch().envs(envs) .cmds(getDescriptor().getAgvtoolPath(), "new-version", "-all", cfBundleVersion) .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_CFBundleVersionUpdateError(cfBundleVersion)); return false; } } catch (MacroEvaluationException e) { listener.fatalError(Messages.XCodeBuilder_CFBundleVersionMacroError(e.getMessage())); // Fails the build return false; } } listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringUsed(cfBundleShortVersionString)); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionUsed(cfBundleVersion)); // Clean build directories if (cleanBeforeBuild) { listener.getLogger() .println(Messages.XCodeBuilder_cleaningBuildDir(buildDirectory.absolutize().getRemote())); buildDirectory.deleteRecursive(); } // remove test-reports and *.ipa if (cleanTestReports != null && cleanTestReports) { listener.getLogger().println(Messages.XCodeBuilder_cleaningTestReportsDir( projectRoot.child("test-reports").absolutize().getRemote())); projectRoot.child("test-reports").deleteRecursive(); } if (unlockKeychain) { // Let's unlock the keychain launcher.launch().envs(envs).cmds("/usr/bin/security", "list-keychains", "-s", keychainPath) .stdout(listener).pwd(projectRoot).join(); launcher.launch().envs(envs) .cmds("/usr/bin/security", "default-keychain", "-d", "user", "-s", keychainPath) .stdout(listener).pwd(projectRoot).join(); if (StringUtils.isEmpty(keychainPwd)) returnCode = launcher.launch().envs(envs).cmds("/usr/bin/security", "unlock-keychain", keychainPath) .stdout(listener).pwd(projectRoot).join(); else returnCode = launcher.launch().envs(envs) .cmds("/usr/bin/security", "unlock-keychain", "-p", keychainPwd, keychainPath) .masks(false, false, false, true, false).stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_unlockKeychainFailed()); return false; } } // display useful setup information listener.getLogger().println(Messages.XCodeBuilder_DebugInfoLineDelimiter()); listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailablePProfiles()); /*returnCode =*/ launcher.launch().envs(envs) .cmds("/usr/bin/security", "find-identity", "-p", "codesigning", "-v").stdout(listener) .pwd(projectRoot).join(); if (!StringUtils.isEmpty(codeSigningIdentity)) { listener.getLogger().println(Messages.XCodeBuilder_DebugInfoCanFindPProfile()); /*returnCode =*/ launcher .launch().envs(envs).cmds("/usr/bin/security", "find-certificate", "-a", "-c", codeSigningIdentity, "-Z", "|", "grep", "^SHA-1") .stdout(listener).pwd(projectRoot).join(); // We could fail here, but this doesn't seem to work as it should right now (output not properly redirected. We might need a parser) } listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailableSDKs()); /*returnCode =*/ launcher.launch().envs(envs).cmds(getDescriptor().getXcodebuildPath(), "-showsdks") .stdout(listener).pwd(projectRoot).join(); { List<String> commandLine = Lists.newArrayList(getDescriptor().getXcodebuildPath()); commandLine.add("-list"); // xcodebuild -list -workspace $workspace listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailableSchemes()); if (!StringUtils.isEmpty(xcodeWorkspaceFile)) { commandLine.add("-workspace"); commandLine.add(xcodeWorkspaceFile + ".xcworkspace"); } else if (!StringUtils.isEmpty(xcodeProjectFile)) { commandLine.add("-project"); commandLine.add(xcodeProjectFile); } returnCode = launcher.launch().envs(envs).cmds(commandLine).stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) return false; } listener.getLogger().println(Messages.XCodeBuilder_DebugInfoLineDelimiter()); // Build StringBuilder xcodeReport = new StringBuilder(Messages.XCodeBuilder_invokeXcodebuild()); XCodeBuildOutputParser reportGenerator = new XCodeBuildOutputParser(projectRoot, listener); List<String> commandLine = Lists.newArrayList(getDescriptor().getXcodebuildPath()); // Prioritizing schema over target setting if (!StringUtils.isEmpty(xcodeSchema)) { commandLine.add("-scheme"); commandLine.add(xcodeSchema); xcodeReport.append(", scheme: ").append(xcodeSchema); } else if (StringUtils.isEmpty(target)) { commandLine.add("-alltargets"); xcodeReport.append("target: ALL"); } else { commandLine.add("-target"); commandLine.add(target); xcodeReport.append("target: ").append(target); } if (!StringUtils.isEmpty(sdk)) { commandLine.add("-sdk"); commandLine.add(sdk); xcodeReport.append(", sdk: ").append(sdk); } else { xcodeReport.append(", sdk: DEFAULT"); } xcodeReport.append(". xcodebuildAction: ").append(this.xcodebuildAction); // Prioritizing workspace over project setting if (!StringUtils.isEmpty(xcodeWorkspaceFile)) { commandLine.add("-workspace"); commandLine.add(xcodeWorkspaceFile + ".xcworkspace"); xcodeReport.append(", workspace: ").append(xcodeWorkspaceFile); } else if (!StringUtils.isEmpty(xcodeProjectFile)) { commandLine.add("-project"); commandLine.add(xcodeProjectFile); xcodeReport.append(", project: ").append(xcodeProjectFile); } else { xcodeReport.append(", project: DEFAULT"); } commandLine.add("-configuration"); commandLine.add(configuration); xcodeReport.append(", configuration: ").append(configuration); if (cleanBeforeBuild) { commandLine.add("clean"); xcodeReport.append(", clean: YES"); } else { xcodeReport.append(", clean: NO"); } commandLine.add(this.xcodebuildAction); if (!StringUtils.isEmpty(symRootValue)) { commandLine.add("SYMROOT=" + symRootValue); xcodeReport.append(", symRoot: ").append(symRootValue); } else { xcodeReport.append(", symRoot: DEFAULT"); } // CONFIGURATION_BUILD_DIR if (!StringUtils.isEmpty(configurationBuildDirValue)) { commandLine.add("CONFIGURATION_BUILD_DIR=" + configurationBuildDirValue); xcodeReport.append(", configurationBuildDir: ").append(configurationBuildDirValue); } else { xcodeReport.append(", configurationBuildDir: DEFAULT"); } // handle code signing identities if (!StringUtils.isEmpty(codeSigningIdentity)) { commandLine.add("CODE_SIGN_IDENTITY=" + codeSigningIdentity); xcodeReport.append(", codeSignIdentity: ").append(codeSigningIdentity); } else { xcodeReport.append(", codeSignIdentity: DEFAULT"); } // Additional (custom) xcodebuild arguments if (!StringUtils.isEmpty(xcodebuildArguments)) { commandLine.addAll(splitXcodeBuildArguments(xcodebuildArguments)); } listener.getLogger().println(xcodeReport.toString()); returnCode = launcher.launch().envs(envs).cmds(commandLine).stdout(reportGenerator.getOutputStream()) .pwd(projectRoot).join(); if (reportGenerator.getExitCode() != 0) return false; if (returnCode > 0) return false; // Package IPA if (buildIpa) { if (!buildDirectory.exists() || !buildDirectory.isDirectory()) { listener.fatalError( Messages.XCodeBuilder_NotExistingBuildDirectory(buildDirectory.absolutize().getRemote())); return false; } // clean IPA listener.getLogger().println(Messages.XCodeBuilder_cleaningIPA()); for (FilePath path : buildDirectory.list("*.ipa")) { path.delete(); } listener.getLogger().println(Messages.XCodeBuilder_cleaningDSYM()); for (FilePath path : buildDirectory.list("*-dSYM.zip")) { path.delete(); } // packaging IPA listener.getLogger().println(Messages.XCodeBuilder_packagingIPA()); List<FilePath> apps = buildDirectory.list(new AppFileFilter()); // FilePath is based on File.listFiles() which can randomly fail | http://stackoverflow.com/questions/3228147/retrieving-the-underlying-error-when-file-listfiles-return-null if (apps == null) { listener.fatalError( Messages.XCodeBuilder_NoAppsInBuildDirectory(buildDirectory.absolutize().getRemote())); return false; } for (FilePath app : apps) { String version; if (StringUtils.isEmpty(cfBundleShortVersionString) && StringUtils.isEmpty(cfBundleVersion)) version = Integer.toString(build.getNumber()); else if (StringUtils.isEmpty(cfBundleVersion)) version = cfBundleShortVersionString; else version = cfBundleVersion; String baseName = app.getBaseName().replaceAll(" ", "_") + "-" + configuration.replaceAll(" ", "_") + (StringUtils.isEmpty(version) ? "" : "-" + version); FilePath ipaLocation = buildDirectory.child(baseName + ".ipa"); FilePath payload = buildDirectory.child("Payload"); payload.deleteRecursive(); payload.mkdirs(); listener.getLogger().println( "Packaging " + app.getBaseName() + ".app => " + ipaLocation.absolutize().getRemote()); List<String> packageCommandLine = new ArrayList<String>(); packageCommandLine.add(getDescriptor().getXcrunPath()); packageCommandLine.add("-sdk"); if (!StringUtils.isEmpty(sdk)) { packageCommandLine.add(sdk); } else { packageCommandLine.add(buildPlatform); } packageCommandLine.addAll(Lists.newArrayList("PackageApplication", "-v", app.absolutize().getRemote(), "-o", ipaLocation.absolutize().getRemote())); if (!StringUtils.isEmpty(embeddedProfileFile)) { packageCommandLine.add("--embed"); packageCommandLine.add(embeddedProfileFile); } if (!StringUtils.isEmpty(codeSigningIdentity)) { packageCommandLine.add("--sign"); packageCommandLine.add(codeSigningIdentity); } returnCode = launcher.launch().envs(envs).stdout(listener).pwd(projectRoot).cmds(packageCommandLine) .join(); if (returnCode > 0) { listener.getLogger().println("Failed to build " + ipaLocation.absolutize().getRemote()); continue; } // also zip up the symbols, if present returnCode = launcher.launch().envs(envs).stdout(listener).pwd(buildDirectory) .cmds("ditto", "-c", "-k", "--keepParent", "-rsrc", app.absolutize().getRemote() + ".dSYM", baseName + "-dSYM.zip") .join(); if (returnCode > 0) { listener.getLogger().println(Messages.XCodeBuilder_zipFailed(baseName)); continue; } payload.deleteRecursive(); } } return true; }
From source file:org.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java
public ActionForward printPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PurchaseOrderDocument poa = (PurchaseOrderDocument) ((PurchaseOrderForm) form).getDocument(); String poDocId = ((PurchaseOrderForm) form).getDocId(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); try {// w w w . java 2 s . c om SpringContext.getBean(OlePurchaseOrderService.class).purchaseOrderFirstTransmitViaPrinting(poDocId, baosPDF); } finally { if (baosPDF != null) { baosPDF.reset(); } } String basePath = getApplicationBaseUrl(); String docId = ((PurchaseOrderForm) form).getDocId(); String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly"; String methodToCallDocHandler = "docHandler"; String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF); String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler); request.setAttribute("printPOPDFUrl", printPOPDFUrl); request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl); String label = ""; if (OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT .equalsIgnoreCase(poa.getDocumentHeader().getWorkflowDocument().getDocumentTypeName())) { label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class) .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT); } else { label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class) .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER); } request.setAttribute("purchaseOrderLabel", label); return mapping.findForward("printPurchaseOrderPDF"); }
From source file:org.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java
/** * Is executed when the user clicks on the "print" button on a Purchase Order Print Document page. On a non * javascript enabled browser, it will display a page with 2 buttons. One is to display the PDF, the other is to view the PO * tabbed page where the PO document statuses, buttons, etc have already been updated (the updates of those occurred while the * <code>performPurchaseOrderFirstTransmitViaPrinting</code> method is invoked. On a javascript enabled browser, it will * display both the PO tabbed page containing the updated PO document info and the pdf on the next window/tab of the browser. * * @param mapping An ActionMapping//w w w.ja va 2 s .c o m * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ @Override public ActionForward firstTransmitPrintPo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PurchaseOrderDocument poa = (PurchaseOrderDocument) ((PurchaseOrderForm) form).getDocument(); String poDocId = ((PurchaseOrderForm) form).getDocId(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); try { SpringContext.getBean(OlePurchaseOrderService.class) .performPurchaseOrderFirstTransmitViaPrinting(poDocId, baosPDF); } finally { if (baosPDF != null) { baosPDF.reset(); } } String basePath = getApplicationBaseUrl(); String docId = ((PurchaseOrderForm) form).getDocId(); String methodToCallPrintPurchaseOrderPDF = "printPurchaseOrderPDFOnly"; String methodToCallDocHandler = "docHandler"; String printPOPDFUrl = getUrlForPrintPO(basePath, docId, methodToCallPrintPurchaseOrderPDF); String displayPOTabbedPageUrl = getUrlForPrintPO(basePath, docId, methodToCallDocHandler); request.setAttribute("printPOPDFUrl", printPOPDFUrl); request.setAttribute("displayPOTabbedPageUrl", displayPOTabbedPageUrl); String label = ""; if (OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT .equalsIgnoreCase(poa.getDocumentHeader().getWorkflowDocument().getDocumentTypeName())) { label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class) .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER_AMENDMENT); } else { label = SpringContext.getBean(org.kuali.rice.krad.service.DataDictionaryService.class) .getDocumentLabelByTypeName(OLEConstants.FinancialDocumentTypeCodes.PURCHASE_ORDER); } request.setAttribute("purchaseOrderLabel", label); return mapping.findForward("printPurchaseOrderPDF"); }
From source file:org.dbgl.gui.EditProfileDialog.java
public static Profile duplicateProfile(final Profile prof, final java.util.List<DosboxVersion> dbversionsList, final Database dbase, final Shell shell) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bos); try {//from w w w . j a va2 s .c o m dbase.startTransaction(); DosboxVersion dbversion = DosboxVersion.findById(dbversionsList, prof.getDbversionId()); Conf newCompositeConf = new Conf(prof, dbversion, ps); Profile newProfile = dbase.duplicateProfile(prof); dbase.saveNativeCommands(dbase.readNativeCommandsList(prof.getId(), -1), newProfile.getId(), -1); String newCapturesString = FileUtils.constructCapturesDir(newProfile.getId()); File newCaptures = FileUtils.canonicalToData(newCapturesString); FileUtils.createDir(newCaptures); String newConfFile = FileUtils.constructUniqueConfigFileString(newProfile.getId(), prof.getTitle(), newCompositeConf.getAutoexec().isIncomplete() ? null : newCompositeConf.getAutoexec().getCanonicalMainDir()); newProfile = new Profile(newProfile.getId(), newConfFile, newCapturesString, newProfile); newCompositeConf.injectOrUpdateProfile(newProfile); newCompositeConf.save(); newProfile = dbase.updateProfileConf(newConfFile, newCapturesString, newProfile.getId()); dbase.commitTransaction(); if (GeneralPurposeDialogs.confirmMessage(shell, Settings.getInstance().msg("dialog.profile.confirm.capturesduplication"))) { FileUtils.copyFiles(prof.getCanonicalCaptures(), newCaptures); } if (bos.size() > 0) { GeneralPurposeDialogs.warningMessage(shell, bos.toString()); bos.reset(); } return newProfile; } catch (Exception e) { GeneralPurposeDialogs.warningMessage(shell, e); try { dbase.rollbackTransaction(); } catch (SQLException se) { GeneralPurposeDialogs.warningMessage(shell, se); } return null; } finally { dbase.finishTransaction(); } }
From source file:org.jopac2.jbal.iso2709.Unimarc.java
@Override public void setImage(BufferedImage image, int maxx, int maxy) { if (image == null) { try {/*w w w . j av a 2 s. c o m*/ removeTags("911"); } catch (JOpac2Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return; } ByteArrayOutputStream a = new ByteArrayOutputStream(); try { Image im = image.getScaledInstance(maxx, maxy, Image.SCALE_SMOOTH); BufferedImage dest = new BufferedImage(maxx, maxy, BufferedImage.TYPE_INT_RGB); dest.createGraphics().drawImage(im, 0, 0, null); ImageIO.write(dest, "jpeg", a); String coded = Base64.encode(a.toByteArray()); Tag t = new Tag("911", ' ', ' '); t.addField(new Field("a", coded)); try { removeTags("911"); } catch (JOpac2Exception e) { } addTag(t); a.reset(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ipc.Server.java
private void wrapWithSasl(ByteArrayOutputStream response, Call call) throws IOException { if (call.connection.useSasl) { byte[] token = response.toByteArray(); // synchronization may be needed since there can be multiple Handler // threads using saslServer to wrap responses. synchronized (call.connection.saslServer) { token = call.connection.saslServer.wrap(token, 0, token.length); }/*w ww .j a v a2 s.c o m*/ if (LOG.isDebugEnabled()) LOG.debug("Adding saslServer wrapped token of size " + token.length + " as call response."); response.reset(); DataOutputStream saslOut = new DataOutputStream(response); saslOut.writeInt(token.length); saslOut.write(token, 0, token.length); } }
From source file:org.apache.hadoop.hdfs.TestDFSShell.java
private void doSetXattr(ByteArrayOutputStream out, FsShell fshell, String[] setOp, String[] getOp, String[] expectArr, String[] dontExpectArr) throws Exception { int ret = ToolRunner.run(fshell, setOp); out.reset(); ret = ToolRunner.run(fshell, getOp); final String str = out.toString(); for (int i = 0; i < expectArr.length; i++) { final String expect = expectArr[i]; final StringBuilder sb = new StringBuilder("Incorrect results from getfattr. Expected: "); sb.append(expect).append(" Full Result: "); sb.append(str);//from w ww . ja v a 2 s . c o m assertTrue(sb.toString(), str.indexOf(expect) != -1); } for (int i = 0; i < dontExpectArr.length; i++) { String dontExpect = dontExpectArr[i]; final StringBuilder sb = new StringBuilder("Incorrect results from getfattr. Didn't Expect: "); sb.append(dontExpect).append(" Full Result: "); sb.append(str); assertTrue(sb.toString(), str.indexOf(dontExpect) == -1); } out.reset(); }
From source file:test.jamocha.languages.clips.SystemTest.java
@SuppressWarnings("unchecked") @Test/*from w ww. j av a 2 s .c o m*/ public void testNodeSharingAllButTerminal() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(deftemplate t1 (slot s1 (type INTEGER)))\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r1 (t1 (s1 5)) => (assert (t1 (s1 999))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 5)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-2>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-2\t(t1 (s1 5))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r2 (t1 (s1 5)) => (assert (t1 (s1 888))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, either(arrayContaining(equalTo("==> f-3\t(t1 (s1 888))"), equalTo("==> f-4\t(t1 (s1 999))"))) .or(arrayContaining(equalTo("==> f-3\t(t1 (s1 999))"), equalTo("==> f-4\t(t1 (s1 888))")))); assertThat(lines, arrayWithSize(2)); out.reset(); } }
From source file:test.jamocha.languages.clips.SystemTest.java
@Test public void testSimpleRuleExecution() throws ParseException { final Network network = new Network(); final ByteArrayOutputStream out = initializeAppender(network); {//from w w w.jav a 2s . co m final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(unwatch all)\n(watch facts)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(deftemplate t1 (slot s1 (type INTEGER)))\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(defrule r1 (t1 (s1 5)) => (assert (t1 (s1 999))) )\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); assertThat(out.toString(), isEmptyString()); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 2)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-2>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-2\t(t1 (s1 2))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(assert (t1 (s1 5)))\n"); final Queue<Object> values = returnValues.getLeft(); assertThat(values, hasSize(1)); final Object value = values.iterator().next(); assertThat(value, instanceOf(String.class)); assertEquals("<Fact-3>", value); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-3\t(t1 (s1 5))", lines[0]); out.reset(); } { final Pair<Queue<Object>, Queue<Warning>> returnValues = run(network, "(run)\n"); assertThat(returnValues.getLeft(), empty()); assertThat(returnValues.getRight(), empty()); final String[] lines = out.toString().split(linesep); assertThat(lines, arrayWithSize(1)); assertEquals("==> f-4\t(t1 (s1 999))", lines[0]); out.reset(); } }
From source file:au.com.rayh.AbstractXCodeBuilder.java
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { EnvVars envs = build.getEnvironment(listener); FilePath projectRoot = build.getWorkspace(); // check that the configured tools exist if (!new FilePath(projectRoot.getChannel(), getGlobalConfiguration().getXcodebuildPath()).exists()) { listener.fatalError(/* w w w .j av a 2 s . c om*/ Messages.XCodeBuilder_xcodebuildNotFound(getGlobalConfiguration().getXcodebuildPath())); return false; } if (!new FilePath(projectRoot.getChannel(), getGlobalConfiguration().getAgvtoolPath()).exists()) { listener.fatalError(Messages.XCodeBuilder_avgtoolNotFound(getGlobalConfiguration().getAgvtoolPath())); return false; } // Start expanding all string variables in parameters // NOTE: we currently use variable shadowing to avoid having to rewrite all code (and break pull requests), this will be cleaned up at later stage. String configuration = envs.expand(this.configuration); String target = envs.expand(this.target); String sdk = envs.expand(this.sdk); String symRoot = envs.expand(this.symRoot); String configurationBuildDir = envs.expand(this.configurationBuildDir); String xcodeProjectPath = envs.expand(this.xcodeProjectPath); String xcodeProjectFile = envs.expand(this.xcodeProjectFile); String xcodebuildArguments = envs.expand(this.xcodebuildArguments); String xcodeSchema = envs.expand(this.xcodeSchema); String xcodeWorkspaceFile = envs.expand(this.xcodeWorkspaceFile); String embeddedProfileFile = envs.expand(this.embeddedProfileFile); String cfBundleVersionValue = envs.expand(this.cfBundleVersionValue); String cfBundleShortVersionStringValue = envs.expand(this.cfBundleShortVersionStringValue); String codeSigningIdentity = envs.expand(this.codeSigningIdentity); String ipaName = envs.expand(this.ipaName); String ipaOutputDirectory = envs.expand(this.ipaOutputDirectory); // End expanding all string variables in parameters // Set the working directory if (!StringUtils.isEmpty(xcodeProjectPath)) { projectRoot = projectRoot.child(xcodeProjectPath); } listener.getLogger().println(Messages.XCodeBuilder_workingDir(projectRoot)); // Infer as best we can the build platform String buildPlatform = "iphoneos"; if (!StringUtils.isEmpty(sdk)) { if (StringUtils.contains(sdk.toLowerCase(), "iphonesimulator")) { // Building for the simulator buildPlatform = "iphonesimulator"; } } // Set the build directory and the symRoot // String symRootValue = null; if (!StringUtils.isEmpty(symRoot)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin symRootValue = TokenMacro.expandAll(build, listener, symRoot).trim(); } catch (MacroEvaluationException e) { listener.error(Messages.XCodeBuilder_symRootMacroError(e.getMessage())); return false; } } String configurationBuildDirValue = null; FilePath buildDirectory; if (!StringUtils.isEmpty(configurationBuildDir)) { try { configurationBuildDirValue = TokenMacro.expandAll(build, listener, configurationBuildDir).trim(); } catch (MacroEvaluationException e) { listener.error(Messages.XCodeBuilder_configurationBuildDirMacroError(e.getMessage())); return false; } } if (configurationBuildDirValue != null) { // If there is a CONFIGURATION_BUILD_DIR, that overrides any use of SYMROOT. Does not require the build platform and the configuration. buildDirectory = new FilePath(projectRoot.getChannel(), configurationBuildDirValue); } else if (symRootValue != null) { // If there is a SYMROOT specified, compute the build directory from that. buildDirectory = new FilePath(projectRoot.getChannel(), symRootValue) .child(configuration + "-" + buildPlatform); } else { // Assume its a build for the handset, not the simulator. buildDirectory = projectRoot.child("build").child(configuration + "-" + buildPlatform); } // XCode Version int returnCode = launcher.launch().envs(envs).cmds(getGlobalConfiguration().getXcodebuildPath(), "-version") .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_xcodeVersionNotFound()); return false; // We fail the build if XCode isn't deployed } ByteArrayOutputStream output = new ByteArrayOutputStream(); // Try to read CFBundleShortVersionString from project listener.getLogger().println(Messages.XCodeBuilder_fetchingCFBundleShortVersionString()); String cfBundleShortVersionString = ""; returnCode = launcher.launch().envs(envs) .cmds(getGlobalConfiguration().getAgvtoolPath(), "mvers", "-terse1").stdout(output).pwd(projectRoot) .join(); // only use this version number if we found it if (returnCode == 0) cfBundleShortVersionString = output.toString().trim(); if (StringUtils.isEmpty(cfBundleShortVersionString)) listener.getLogger().println(Messages.XCodeBuilder_CFBundleShortVersionStringNotFound()); else listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringFound(cfBundleShortVersionString)); listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringValue(cfBundleShortVersionString)); output.reset(); // Try to read CFBundleVersion from project listener.getLogger().println(Messages.XCodeBuilder_fetchingCFBundleVersion()); String cfBundleVersion = ""; returnCode = launcher.launch().envs(envs).cmds(getGlobalConfiguration().getAgvtoolPath(), "vers", "-terse") .stdout(output).pwd(projectRoot).join(); // only use this version number if we found it if (returnCode == 0) cfBundleVersion = output.toString().trim(); if (StringUtils.isEmpty(cfBundleVersion)) listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionNotFound()); else listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionFound(cfBundleVersion)); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionValue(cfBundleVersion)); String buildDescription = cfBundleShortVersionString + " (" + cfBundleVersion + ")"; XCodeAction a = new XCodeAction(buildDescription); build.addAction(a); // Update the Marketing version (CFBundleShortVersionString) if (!StringUtils.isEmpty(cfBundleShortVersionStringValue)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin cfBundleShortVersionString = TokenMacro.expandAll(build, listener, cfBundleShortVersionStringValue); listener.getLogger().println( Messages.XCodeBuilder_CFBundleShortVersionStringUpdate(cfBundleShortVersionString)); returnCode = launcher .launch().envs(envs).cmds(getGlobalConfiguration().getAgvtoolPath(), "new-marketing-version", cfBundleShortVersionString) .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages .XCodeBuilder_CFBundleShortVersionStringUpdateError(cfBundleShortVersionString)); return false; } } catch (MacroEvaluationException e) { listener.fatalError(Messages.XCodeBuilder_CFBundleShortVersionStringMacroError(e.getMessage())); // Fails the build return false; } } // Update the Technical version (CFBundleVersion) if (!StringUtils.isEmpty(cfBundleVersionValue)) { try { // If not empty we use the Token Expansion to replace it // https://wiki.jenkins-ci.org/display/JENKINS/Token+Macro+Plugin cfBundleVersion = TokenMacro.expandAll(build, listener, cfBundleVersionValue); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionUpdate(cfBundleVersion)); returnCode = launcher.launch().envs(envs) .cmds(getGlobalConfiguration().getAgvtoolPath(), "new-version", "-all", cfBundleVersion) .stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_CFBundleVersionUpdateError(cfBundleVersion)); return false; } } catch (MacroEvaluationException e) { listener.fatalError(Messages.XCodeBuilder_CFBundleVersionMacroError(e.getMessage())); // Fails the build return false; } } listener.getLogger() .println(Messages.XCodeBuilder_CFBundleShortVersionStringUsed(cfBundleShortVersionString)); listener.getLogger().println(Messages.XCodeBuilder_CFBundleVersionUsed(cfBundleVersion)); // Clean build directories if (cleanBeforeBuild) { listener.getLogger() .println(Messages.XCodeBuilder_cleaningBuildDir(buildDirectory.absolutize().getRemote())); buildDirectory.deleteRecursive(); } // remove test-reports and *.ipa if (cleanTestReports != null && cleanTestReports) { listener.getLogger().println(Messages.XCodeBuilder_cleaningTestReportsDir( projectRoot.child("test-reports").absolutize().getRemote())); projectRoot.child("test-reports").deleteRecursive(); } if (unlockKeychain != null && unlockKeychain) { // Let's unlock the keychain Keychain keychain = getKeychain(); if (keychain == null) { listener.fatalError(Messages.XCodeBuilder_keychainNotConfigured()); return false; } String keychainPath = envs.expand(keychain.getKeychainPath()); String keychainPwd = envs.expand(keychain.getKeychainPassword()); launcher.launch().envs(envs).cmds("/usr/bin/security", "list-keychains", "-s", keychainPath) .stdout(listener).pwd(projectRoot).join(); launcher.launch().envs(envs) .cmds("/usr/bin/security", "default-keychain", "-d", "user", "-s", keychainPath) .stdout(listener).pwd(projectRoot).join(); if (StringUtils.isEmpty(keychainPwd)) returnCode = launcher.launch().envs(envs).cmds("/usr/bin/security", "unlock-keychain", keychainPath) .stdout(listener).pwd(projectRoot).join(); else returnCode = launcher.launch().envs(envs) .cmds("/usr/bin/security", "unlock-keychain", "-p", keychainPwd, keychainPath) .masks(false, false, false, true, false).stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) { listener.fatalError(Messages.XCodeBuilder_unlockKeychainFailed()); return false; } // Show the keychain info after unlocking, if not, OS X will prompt for the keychain password launcher.launch().envs(envs).cmds("/usr/bin/security", "show-keychain-info", keychainPath) .stdout(listener).pwd(projectRoot).join(); } // display useful setup information listener.getLogger().println(Messages.XCodeBuilder_DebugInfoLineDelimiter()); listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailablePProfiles()); /*returnCode =*/ launcher.launch().envs(envs) .cmds("/usr/bin/security", "find-identity", "-p", "codesigning", "-v").stdout(listener) .pwd(projectRoot).join(); if (!StringUtils.isEmpty(codeSigningIdentity)) { listener.getLogger().println(Messages.XCodeBuilder_DebugInfoCanFindPProfile()); /*returnCode =*/ launcher .launch().envs(envs).cmds("/usr/bin/security", "find-certificate", "-a", "-c", codeSigningIdentity, "-Z", "|", "grep", "^SHA-1") .stdout(listener).pwd(projectRoot).join(); // We could fail here, but this doesn't seem to work as it should right now (output not properly redirected. We might need a parser) } listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailableSDKs()); /*returnCode =*/ launcher.launch().envs(envs) .cmds(getGlobalConfiguration().getXcodebuildPath(), "-showsdks").stdout(listener).pwd(projectRoot) .join(); { List<String> commandLine = Lists.newArrayList(getGlobalConfiguration().getXcodebuildPath()); commandLine.add("-list"); // xcodebuild -list -workspace $workspace listener.getLogger().println(Messages.XCodeBuilder_DebugInfoAvailableSchemes()); if (!StringUtils.isEmpty(xcodeWorkspaceFile)) { commandLine.add("-workspace"); commandLine.add(xcodeWorkspaceFile + ".xcworkspace"); } else if (!StringUtils.isEmpty(xcodeProjectFile)) { commandLine.add("-project"); commandLine.add(xcodeProjectFile); } returnCode = launcher.launch().envs(envs).cmds(commandLine).stdout(listener).pwd(projectRoot).join(); if (returnCode > 0) return false; } listener.getLogger().println(Messages.XCodeBuilder_DebugInfoLineDelimiter()); // Build StringBuilder xcodeReport = new StringBuilder(Messages.XCodeBuilder_invokeXcodebuild()); XCodeBuildOutputParser reportGenerator = new JenkinsXCodeBuildOutputParser(projectRoot, listener); List<String> commandLine = Lists.newArrayList(getGlobalConfiguration().getXcodebuildPath()); // Prioritizing schema over target setting if (!StringUtils.isEmpty(xcodeSchema)) { commandLine.add("-scheme"); commandLine.add(xcodeSchema); xcodeReport.append(", scheme: ").append(xcodeSchema); } else if (StringUtils.isEmpty(target)) { commandLine.add("-alltargets"); xcodeReport.append("target: ALL"); } else { commandLine.add("-target"); commandLine.add(target); xcodeReport.append("target: ").append(target); } if (!StringUtils.isEmpty(sdk)) { commandLine.add("-sdk"); commandLine.add(sdk); xcodeReport.append(", sdk: ").append(sdk); } else { xcodeReport.append(", sdk: DEFAULT"); } // Prioritizing workspace over project setting if (!StringUtils.isEmpty(xcodeWorkspaceFile)) { commandLine.add("-workspace"); commandLine.add(xcodeWorkspaceFile + ".xcworkspace"); xcodeReport.append(", workspace: ").append(xcodeWorkspaceFile); } else if (!StringUtils.isEmpty(xcodeProjectFile)) { commandLine.add("-project"); commandLine.add(xcodeProjectFile); xcodeReport.append(", project: ").append(xcodeProjectFile); } else { xcodeReport.append(", project: DEFAULT"); } if (!StringUtils.isEmpty(configuration)) { commandLine.add("-configuration"); commandLine.add(configuration); xcodeReport.append(", configuration: ").append(configuration); } if (runTests) { commandLine.add("-destination"); String destination = "devicetype=iOS Simulator,name="; destination += testDevice; destination += ",OS=" + testOsVersion; commandLine.add(destination); xcodeReport.append("testing for: " + testDevice + ", on " + testOsVersion); } if (cleanBeforeBuild) { commandLine.add("clean"); xcodeReport.append(", clean: YES"); } else { xcodeReport.append(", clean: NO"); } String action = runTests ? "test" : "build"; commandLine.add(action); if (generateArchive != null && generateArchive) { commandLine.add("archive"); xcodeReport.append(", archive:YES"); } else { xcodeReport.append(", archive:NO"); } if (!StringUtils.isEmpty(symRootValue)) { commandLine.add("SYMROOT=" + symRootValue); xcodeReport.append(", symRoot: ").append(symRootValue); } else { xcodeReport.append(", symRoot: DEFAULT"); } // CONFIGURATION_BUILD_DIR if (!StringUtils.isEmpty(configurationBuildDirValue)) { commandLine.add("CONFIGURATION_BUILD_DIR=" + configurationBuildDirValue); xcodeReport.append(", configurationBuildDir: ").append(configurationBuildDirValue); } else { xcodeReport.append(", configurationBuildDir: DEFAULT"); } // handle code signing identities if (!StringUtils.isEmpty(codeSigningIdentity)) { commandLine.add("CODE_SIGN_IDENTITY=" + codeSigningIdentity); xcodeReport.append(", codeSignIdentity: ").append(codeSigningIdentity); } else { xcodeReport.append(", codeSignIdentity: DEFAULT"); } // Additional (custom) xcodebuild arguments if (!StringUtils.isEmpty(xcodebuildArguments)) { commandLine.addAll(splitXcodeBuildArguments(xcodebuildArguments)); } // Reset simulator if requested, by blowing away ~/Library/Application Support/iPhone Simulator/VERSION if (resetSimulator) { String path = System.getProperty("user.home") + "/Library/Application Support/iPhone Simulator/" + testOsVersion; xcodeReport.append("resetting simulator at location: ").append(path); FilePath filePath = new FilePath(new File(path)); if (filePath.exists() && filePath.isDirectory()) { filePath.deleteRecursive(); } } listener.getLogger().println(xcodeReport.toString()); returnCode = launcher.launch().envs(envs).cmds(commandLine).stdout(reportGenerator.getOutputStream()) .pwd(projectRoot).join(); if (allowFailingBuildResults != null && allowFailingBuildResults.booleanValue() == false) { if (reportGenerator.getExitCode() != 0) return false; if (returnCode > 0) return false; } // Package IPA if (buildIpa) { if (!buildDirectory.exists() || !buildDirectory.isDirectory()) { listener.fatalError( Messages.XCodeBuilder_NotExistingBuildDirectory(buildDirectory.absolutize().getRemote())); return false; } // clean IPA FilePath ipaOutputPath = null; if (ipaOutputDirectory != null && !StringUtils.isEmpty(ipaOutputDirectory)) { ipaOutputPath = buildDirectory.child(ipaOutputDirectory); // Create if non-existent if (!ipaOutputPath.exists()) { ipaOutputPath.mkdirs(); } } if (ipaOutputPath == null) { ipaOutputPath = buildDirectory; } listener.getLogger().println(Messages.XCodeBuilder_cleaningIPA()); for (FilePath path : ipaOutputPath.list("*.ipa")) { path.delete(); } listener.getLogger().println(Messages.XCodeBuilder_cleaningDSYM()); for (FilePath path : ipaOutputPath.list("*-dSYM.zip")) { path.delete(); } // packaging IPA listener.getLogger().println(Messages.XCodeBuilder_packagingIPA()); List<FilePath> apps = buildDirectory.list(new AppFileFilter()); // FilePath is based on File.listFiles() which can randomly fail | http://stackoverflow.com/questions/3228147/retrieving-the-underlying-error-when-file-listfiles-return-null if (apps == null) { listener.fatalError( Messages.XCodeBuilder_NoAppsInBuildDirectory(buildDirectory.absolutize().getRemote())); return false; } for (FilePath app : apps) { String version = ""; String shortVersion = ""; if (!provideApplicationVersion) { try { output.reset(); returnCode = launcher.launch().envs(envs) .cmds("/usr/libexec/PlistBuddy", "-c", "Print :CFBundleVersion", app.absolutize().child("Info.plist").getRemote()) .stdout(output).pwd(projectRoot).join(); if (returnCode == 0) { version = output.toString().trim(); } output.reset(); returnCode = launcher.launch().envs(envs) .cmds("/usr/libexec/PlistBuddy", "-c", "Print :CFBundleShortVersionString", app.absolutize().child("Info.plist").getRemote()) .stdout(output).pwd(projectRoot).join(); if (returnCode == 0) { shortVersion = output.toString().trim(); } } catch (Exception ex) { listener.getLogger().println("Failed to get version from Info.plist: " + ex.toString()); return false; } } else { if (!StringUtils.isEmpty(cfBundleVersionValue)) { version = cfBundleVersionValue; } else if (!StringUtils.isEmpty(cfBundleShortVersionStringValue)) { shortVersion = cfBundleShortVersionStringValue; } else { listener.getLogger().println( "You have to provide a value for either the marketing or technical version. Found neither."); return false; } } File file = new File(app.absolutize().getRemote()); String lastModified = new SimpleDateFormat("yyyy.MM.dd").format(new Date(file.lastModified())); String baseName = app.getBaseName().replaceAll(" ", "_") + (shortVersion.isEmpty() ? "" : "-" + shortVersion) + (version.isEmpty() ? "" : "-" + version); // If custom .ipa name pattern has been provided, use it and expand version and build date variables if (!StringUtils.isEmpty(ipaName)) { EnvVars customVars = new EnvVars("BASE_NAME", app.getBaseName().replaceAll(" ", "_"), "VERSION", version, "SHORT_VERSION", shortVersion, "BUILD_DATE", lastModified); baseName = customVars.expand(ipaName); } FilePath ipaLocation = ipaOutputPath.child(baseName + ".ipa"); FilePath payload = ipaOutputPath.child("Payload"); payload.deleteRecursive(); payload.mkdirs(); listener.getLogger().println( "Packaging " + app.getBaseName() + ".app => " + ipaLocation.absolutize().getRemote()); List<String> packageCommandLine = new ArrayList<String>(); packageCommandLine.add(getGlobalConfiguration().getXcrunPath()); packageCommandLine.add("-sdk"); if (!StringUtils.isEmpty(sdk)) { packageCommandLine.add(sdk); } else { packageCommandLine.add(buildPlatform); } packageCommandLine.addAll(Lists.newArrayList("PackageApplication", "-v", app.absolutize().getRemote(), "-o", ipaLocation.absolutize().getRemote())); if (!StringUtils.isEmpty(embeddedProfileFile)) { packageCommandLine.add("--embed"); packageCommandLine.add(embeddedProfileFile); } if (!StringUtils.isEmpty(codeSigningIdentity)) { packageCommandLine.add("--sign"); packageCommandLine.add(codeSigningIdentity); } returnCode = launcher.launch().envs(envs).stdout(listener).pwd(projectRoot).cmds(packageCommandLine) .join(); if (returnCode > 0) { listener.getLogger().println("Failed to build " + ipaLocation.absolutize().getRemote()); continue; } // also zip up the symbols, if present returnCode = launcher.launch().envs(envs).stdout(listener).pwd(buildDirectory) .cmds("ditto", "-c", "-k", "--keepParent", "-rsrc", app.absolutize().getRemote() + ".dSYM", ipaOutputPath.child(baseName + "-dSYM.zip").absolutize().getRemote()) .join(); if (returnCode > 0) { listener.getLogger().println(Messages.XCodeBuilder_zipFailed(baseName)); continue; } payload.deleteRecursive(); } } return true; }