List of usage examples for java.util ArrayList toString
public String toString()
From source file:com.evolveum.midpoint.common.policy.PasswordPolicyUtils.java
/** * Check provided password against provided policy * /*from w w w. j av a 2s .co m*/ * @param password * - password to check * @param pp * - Password policy used * @return - Operation result of this validation */ public static OperationResult validatePassword(String password, ValuePolicyType pp) { Validate.notNull(pp, "Password policy must not be null."); OperationResult ret = new OperationResult(OPERATION_PASSWORD_VALIDATION); ret.addParam("policyName", pp.getName()); normalize(pp); if (password == null && pp.getMinOccurs() != null && XsdTypeMapper.multiplicityToInteger(pp.getMinOccurs()) == 0) { // No password is allowed ret.recordSuccess(); return ret; } if (password == null) { password = ""; } LimitationsType lims = pp.getStringPolicy().getLimitations(); StringBuilder message = new StringBuilder(); // Test minimal length if (lims.getMinLength() == null) { lims.setMinLength(0); } if (lims.getMinLength() > password.length()) { String msg = "Required minimal size (" + lims.getMinLength() + ") of password is not met (password length: " + password.length() + ")"; ret.addSubresult( new OperationResult("Check global minimal length", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check global minimal length. Minimal length of password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } // Test maximal length if (lims.getMaxLength() != null) { if (lims.getMaxLength() < password.length()) { String msg = "Required maximal size (" + lims.getMaxLength() + ") of password was exceeded (password length: " + password.length() + ")."; ret.addSubresult( new OperationResult("Check global maximal length", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check global maximal length. Maximal length of password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } } // Test uniqueness criteria HashSet<String> tmp = new HashSet<String>(StringPolicyUtils.stringTokenizer(password)); if (lims.getMinUniqueChars() != null) { if (lims.getMinUniqueChars() > tmp.size()) { String msg = "Required minimal count of unique characters (" + lims.getMinUniqueChars() + ") in password are not met (unique characters in password " + tmp.size() + ")"; ret.addSubresult(new OperationResult("Check minimal count of unique chars", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult( // "Check minimal count of unique chars. Password satisfies minimal required unique characters.", // OperationResultStatus.SUCCESS, "PASSED")); // } } // check limitation HashSet<String> allValidChars = new HashSet<String>(128); ArrayList<String> validChars = null; ArrayList<String> passwd = StringPolicyUtils.stringTokenizer(password); if (lims.getLimit() == null || lims.getLimit().isEmpty()) { if (message.toString() == null || message.toString().isEmpty()) { ret.computeStatus(); } else { ret.computeStatus(message.toString()); } return ret; } for (StringLimitType l : lims.getLimit()) { OperationResult limitResult = new OperationResult("Tested limitation: " + l.getDescription()); if (null != l.getCharacterClass().getValue()) { validChars = StringPolicyUtils.stringTokenizer(l.getCharacterClass().getValue()); } else { validChars = StringPolicyUtils.stringTokenizer(StringPolicyUtils.collectCharacterClass( pp.getStringPolicy().getCharacterClass(), l.getCharacterClass().getRef())); } // memorize validChars allValidChars.addAll(validChars); // Count how many character for this limitation are there int count = 0; for (String s : passwd) { if (validChars.contains(s)) { count++; } } // Test minimal occurrence if (l.getMinOccurs() == null) { l.setMinOccurs(0); } if (l.getMinOccurs() > count) { String msg = "Required minimal occurrence (" + l.getMinOccurs() + ") of characters (" + l.getDescription() + ") in password is not met (occurrence of characters in password " + count + ")."; limitResult.addSubresult(new OperationResult("Check minimal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult("Check minimal occurrence of characters in password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } // Test maximal occurrence if (l.getMaxOccurs() != null) { if (l.getMaxOccurs() < count) { String msg = "Required maximal occurrence (" + l.getMaxOccurs() + ") of characters (" + l.getDescription() + ") in password was exceeded (occurrence of characters in password " + count + ")."; limitResult.addSubresult(new OperationResult("Check maximal occurrence of characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult( // "Check maximal occurrence of characters in password OK.", OperationResultStatus.SUCCESS, // "PASSED")); // } } // test if first character is valid if (l.isMustBeFirst() == null) { l.setMustBeFirst(false); } // we check mustBeFirst only for non-empty passwords if (StringUtils.isNotEmpty(password) && l.isMustBeFirst() && !validChars.contains(password.substring(0, 1))) { String msg = "First character is not from allowed set. Allowed set: " + validChars.toString(); limitResult.addSubresult( new OperationResult("Check valid first char", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // limitResult.addSubresult(new OperationResult("Check valid first char in password OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } limitResult.computeStatus(); ret.addSubresult(limitResult); } // Check if there is no invalid character StringBuilder sb = new StringBuilder(); for (String s : passwd) { if (!allValidChars.contains(s)) { // memorize all invalid characters sb.append(s); } } if (sb.length() > 0) { String msg = "Characters [ " + sb + " ] are not allowed in password"; ret.addSubresult(new OperationResult("Check if password does not contain invalid characters", OperationResultStatus.FATAL_ERROR, msg)); message.append(msg); message.append("\n"); } // else { // ret.addSubresult(new OperationResult("Check if password does not contain invalid characters OK.", // OperationResultStatus.SUCCESS, "PASSED")); // } if (message.toString() == null || message.toString().isEmpty()) { ret.computeStatus(); } else { ret.computeStatus(message.toString()); } return ret; }
From source file:org.apache.hadoop.hbase.master.procedure.TestMasterProcedureSchedulerConcurrency.java
/** * Verify that "write" operations for a single table are serialized, * but different tables can be executed in parallel. *//* w ww . ja v a2 s . c o m*/ @Test(timeout = 60000) public void testConcurrentWriteOps() throws Exception { final TestTableProcSet procSet = new TestTableProcSet(queue); final int NUM_ITEMS = 10; final int NUM_TABLES = 4; final AtomicInteger opsCount = new AtomicInteger(0); for (int i = 0; i < NUM_TABLES; ++i) { TableName tableName = TableName.valueOf(String.format("testtb-%04d", i)); for (int j = 1; j < NUM_ITEMS; ++j) { procSet.addBack(new TestTableProcedure(i * 100 + j, tableName, TableProcedureInterface.TableOperationType.EDIT)); opsCount.incrementAndGet(); } } assertEquals(opsCount.get(), queue.size()); final Thread[] threads = new Thread[NUM_TABLES * 2]; final HashSet<TableName> concurrentTables = new HashSet<TableName>(); final ArrayList<String> failures = new ArrayList<String>(); final AtomicInteger concurrentCount = new AtomicInteger(0); for (int i = 0; i < threads.length; ++i) { threads[i] = new Thread() { @Override public void run() { while (opsCount.get() > 0) { try { Procedure proc = procSet.acquire(); if (proc == null) { queue.signalAll(); if (opsCount.get() > 0) { continue; } break; } TableName tableId = procSet.getTableName(proc); synchronized (concurrentTables) { assertTrue("unexpected concurrency on " + tableId, concurrentTables.add(tableId)); } assertTrue(opsCount.decrementAndGet() >= 0); try { long procId = proc.getProcId(); int concurrent = concurrentCount.incrementAndGet(); assertTrue("inc-concurrent=" + concurrent + " 1 <= concurrent <= " + NUM_TABLES, concurrent >= 1 && concurrent <= NUM_TABLES); LOG.debug("[S] tableId=" + tableId + " procId=" + procId + " concurrent=" + concurrent); Thread.sleep(2000); concurrent = concurrentCount.decrementAndGet(); LOG.debug("[E] tableId=" + tableId + " procId=" + procId + " concurrent=" + concurrent); assertTrue("dec-concurrent=" + concurrent, concurrent < NUM_TABLES); } finally { synchronized (concurrentTables) { assertTrue(concurrentTables.remove(tableId)); } procSet.release(proc); } } catch (Throwable e) { LOG.error("Failed " + e.getMessage(), e); synchronized (failures) { failures.add(e.getMessage()); } } finally { queue.signalAll(); } } } }; threads[i].start(); } for (int i = 0; i < threads.length; ++i) { threads[i].join(); } assertTrue(failures.toString(), failures.isEmpty()); assertEquals(0, opsCount.get()); assertEquals(0, queue.size()); for (int i = 1; i <= NUM_TABLES; ++i) { final TableName table = TableName.valueOf(String.format("testtb-%04d", i)); final TestTableProcedure dummyProc = new TestTableProcedure(100, table, TableProcedureInterface.TableOperationType.DELETE); assertTrue("queue should be deleted, table=" + table, queue.markTableAsDeleted(table, dummyProc)); } }
From source file:net.i2cat.csade.life2.backoffice.bl.StatisticsManager.java
public String getDatosProfiles() { ObjStats[] st = null;/*from w w w .ja v a 2s . co m*/ ArrayList<Pair> datos = new ArrayList<Pair>(); HashMap<Integer, Pair> hm = new HashMap<Integer, Pair>(); Pair p; try { String sql = "SELECT t2.role as idStat,count(*) as Event,\"\" as User_login,null as dTime,0 as duration,\"\" as lat,\"\" as lon,\"\" as device,\"\" as query,0 as lng FROM (SELECT s.*,u.role FROM Stat AS s INNER JOIN user_profile AS u ON s.User_login=u.Login AND s.event=" + StatsDAO.LOGIN_EVENT + " ) AS t2 GROUP BY (role)"; st = sd.listStatsSQL(sql); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int i = 0; i < st.length; i++) { if (!hm.containsKey(new Integer(st[i].getIdStat()))) { datos.add(new Pair(PlatformUser.roleNames[st[i].getIdStat()], st[i].getIEvent())); hm.put(new Integer(st[i].getIdStat()), new Pair(PlatformUser.roleNames[st[i].getIdStat()], st[i].getIEvent())); } else { Pair anterior = hm.get(new Integer(st[i].getIdStat())); datos.remove(anterior); anterior = new Pair(PlatformUser.roleNames[st[i].getIdStat()], anterior.getValue() + st[i].getIEvent()); datos.add(anterior); hm.put(new Integer(st[i].getIdStat()), anterior); } } return datos.toString(); }
From source file:org.apache.hadoop.hive.ql.exec.vector.VectorizationContext.java
private String getNewInstanceArgumentString(Object[] args) { if (args == null) { return "arguments: NULL"; }/* w w w . j a va2s. c o m*/ ArrayList<String> argClasses = new ArrayList<String>(); for (Object obj : args) { argClasses.add(obj.getClass().getSimpleName()); } return "arguments: " + Arrays.toString(args) + ", argument classes: " + argClasses.toString(); }
From source file:it.bradipao.berengar.DbTool.java
public static int gson2db(SQLiteDatabase mDB, File jsonFile) { // vars// www . j a va 2 s . c o m int iTableNum = 0; FileReader fr = null; BufferedReader br = null; JsonReader jr = null; String name = null; String val = null; String mTable = null; String mTableSql = null; ArrayList<String> aFields = null; ArrayList<String> aValues = null; ContentValues cv = null; // file readers try { fr = new FileReader(jsonFile); br = new BufferedReader(fr); jr = new JsonReader(br); } catch (FileNotFoundException e) { Log.e(LOGTAG, "error in gson2db file readers", e); } // parsing try { // start database transaction mDB.beginTransaction(); // open root { jr.beginObject(); // iterate through root objects while (jr.hasNext()) { name = jr.nextName(); if (jr.peek() == JsonToken.NULL) jr.skipValue(); // number of tables else if (name.equals("tables_num")) { val = jr.nextString(); iTableNum = Integer.parseInt(val); if (GOLOG) Log.d(LOGTAG, "TABLE NUM : " + iTableNum); } // iterate through tables array else if (name.equals("tables")) { jr.beginArray(); while (jr.hasNext()) { // start table mTable = null; aFields = null; jr.beginObject(); while (jr.hasNext()) { name = jr.nextName(); if (jr.peek() == JsonToken.NULL) jr.skipValue(); // table name else if (name.equals("table_name")) { mTable = jr.nextString(); } // table sql else if (name.equals("table_sql")) { mTableSql = jr.nextString(); if ((mTable != null) && (mTableSql != null)) { mDB.execSQL("DROP TABLE IF EXISTS " + mTable); mDB.execSQL(mTableSql); if (GOLOG) Log.d(LOGTAG, "DROPPED AND CREATED TABLE : " + mTable); } } // iterate through columns name else if (name.equals("cols_name")) { jr.beginArray(); while (jr.hasNext()) { val = jr.nextString(); if (aFields == null) aFields = new ArrayList<String>(); aFields.add(val); } jr.endArray(); if (GOLOG) Log.d(LOGTAG, "COLUMN NAME : " + aFields.toString()); } // iterate through rows else if (name.equals("rows")) { jr.beginArray(); while (jr.hasNext()) { jr.beginArray(); // iterate through values in row aValues = null; cv = null; while (jr.hasNext()) { val = jr.nextString(); if (aValues == null) aValues = new ArrayList<String>(); aValues.add(val); } jr.endArray(); // add to database cv = new ContentValues(); for (int j = 0; j < aFields.size(); j++) cv.put(aFields.get(j), aValues.get(j)); mDB.insert(mTable, null, cv); if (GOLOG) Log.d(LOGTAG, "INSERT IN " + mTable + " : " + aValues.toString()); } jr.endArray(); } else jr.skipValue(); } // end table jr.endObject(); } jr.endArray(); } else jr.skipValue(); } // close root } jr.endObject(); jr.close(); // successfull transaction mDB.setTransactionSuccessful(); } catch (IOException e) { Log.e(LOGTAG, "error in gson2db gson parsing", e); } finally { mDB.endTransaction(); } return iTableNum; }
From source file:com.Candy.sizer.CandySizer.java
private void selectDialog(final ArrayList<String> sysAppProfile, final ArrayAdapter<String> adapter) { AlertDialog.Builder select = new AlertDialog.Builder(getActivity()); select.setItems(R.array.slimsizer_profile_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // The 'which' argument contains the index position // of the selected item short state = sdAvailable(); File path = new File(Environment.getExternalStorageDirectory() + "/Slim"); File savefile = new File(path + "/slimsizer.stf"); if (which == 0) { // load profile action if (state >= 1) { String profile; try { // read savefile and create arraylist profile = new Scanner(savefile, "UTF-8").useDelimiter("\\A").next(); ArrayList<String> profileState = new ArrayList<String>( Arrays.asList(profile.split(", "))); // create arraylist of unique entries in // sysAppProfile (currently installed apps) ArrayList<String> deleteList = new ArrayList<String>(); for (String item : sysAppProfile) { if (!profileState.contains(item)) { deleteList.add(item); }//from w w w . j a v a2s . com } // delete all entries in deleteList ArrayList<String> itemsList = new ArrayList<String>(); for (int i = deleteList.size() - 1; i > 0; i--) { String item = deleteList.get(i); itemsList.add(item); // remove list entry adapter.remove(item); } adapter.notifyDataSetChanged(); new CandySizer.SlimDeleter().execute(itemsList.toArray(new String[itemsList.size()])); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnoread)); } } else if (which == 1) { // save profile action if (state == 2) { try { // create directory if it doesnt exist if (!path.exists()) { path.mkdirs(); } // create string from arraylists String lists = sysAppProfile.toString(); lists = lists.replace("][", ","); lists = lists.replace("[", ""); lists = lists.replace("]", ""); // delete savefile if it exists (overwrite) if (savefile.exists()) { savefile.delete(); } // create savefile and output lists to it FileWriter outstream = new FileWriter(savefile); BufferedWriter save = new BufferedWriter(outstream); save.write(lists); save.close(); // check for success if (savefile.exists()) { toast(getResources().getString(R.string.sizer_message_filesuccess)); } else { toast(getResources().getString(R.string.sizer_message_filefail)); } } catch (IOException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnowrite)); } } } }); select.show(); }
From source file:org.apache.hadoop.hbase.master.procedure.TestMasterProcedureQueue.java
/** * Verify that "write" operations for a single table are serialized, * but different tables can be executed in parallel. *///from w w w. j av a 2 s . c om @Test(timeout = 90000) public void testConcurrentWriteOps() throws Exception { final TestTableProcSet procSet = new TestTableProcSet(queue); final int NUM_ITEMS = 10; final int NUM_TABLES = 4; final AtomicInteger opsCount = new AtomicInteger(0); for (int i = 0; i < NUM_TABLES; ++i) { TableName tableName = TableName.valueOf(String.format("testtb-%04d", i)); for (int j = 1; j < NUM_ITEMS; ++j) { procSet.addBack(new TestTableProcedure(i * 100 + j, tableName, TableProcedureInterface.TableOperationType.EDIT)); opsCount.incrementAndGet(); } } assertEquals(opsCount.get(), queue.size()); final Thread[] threads = new Thread[NUM_TABLES * 2]; final HashSet<TableName> concurrentTables = new HashSet<TableName>(); final ArrayList<String> failures = new ArrayList<String>(); final AtomicInteger concurrentCount = new AtomicInteger(0); for (int i = 0; i < threads.length; ++i) { threads[i] = new Thread() { @Override public void run() { while (opsCount.get() > 0) { try { TableProcedureInterface proc = procSet.acquire(); if (proc == null) { queue.signalAll(); if (opsCount.get() > 0) { continue; } break; } synchronized (concurrentTables) { assertTrue("unexpected concurrency on " + proc.getTableName(), concurrentTables.add(proc.getTableName())); } assertTrue(opsCount.decrementAndGet() >= 0); try { long procId = ((Procedure) proc).getProcId(); TableName tableId = proc.getTableName(); int concurrent = concurrentCount.incrementAndGet(); assertTrue("inc-concurrent=" + concurrent + " 1 <= concurrent <= " + NUM_TABLES, concurrent >= 1 && concurrent <= NUM_TABLES); LOG.debug("[S] tableId=" + tableId + " procId=" + procId + " concurrent=" + concurrent); Thread.sleep(2000); concurrent = concurrentCount.decrementAndGet(); LOG.debug("[E] tableId=" + tableId + " procId=" + procId + " concurrent=" + concurrent); assertTrue("dec-concurrent=" + concurrent, concurrent < NUM_TABLES); } finally { synchronized (concurrentTables) { assertTrue(concurrentTables.remove(proc.getTableName())); } procSet.release(proc); } } catch (Throwable e) { LOG.error("Failed " + e.getMessage(), e); synchronized (failures) { failures.add(e.getMessage()); } } finally { queue.signalAll(); } } } }; threads[i].start(); } for (int i = 0; i < threads.length; ++i) { threads[i].join(); } assertTrue(failures.toString(), failures.isEmpty()); assertEquals(0, opsCount.get()); assertEquals(0, queue.size()); for (int i = 1; i <= NUM_TABLES; ++i) { TableName table = TableName.valueOf(String.format("testtb-%04d", i)); assertTrue("queue should be deleted, table=" + table, queue.markTableAsDeleted(table)); } }
From source file:org.jenkinsci.plugins.zap.ZAPBuilder.java
/** Method launched before the build. */ @Override//from ww w . jav a 2 s.c o m public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) { Utils.lineBreak(listener); Utils.loggerMessage(listener, 0, "[{0}] START PRE-BUILD ENVIRONMENT VARIABLE REPLACEMENT", Utils.ZAP); /* Replaces the environment variables with the corresponding values */ String zapHost = zaproxy.getZapHost(); if (zapHost == null || zapHost.isEmpty()) throw new IllegalArgumentException("ZAP HOST IS MISSING"); String zapPort = zaproxy.getZapPort(); if (zapPort == null || zapPort.isEmpty()) throw new IllegalArgumentException("ZAP PORT IS MISSING"); String sessionFilename = zaproxy.getSessionFilename(); String internalSites = zaproxy.getInternalSites(); String contextName = zaproxy.getContextName(); String includedURL = zaproxy.getIncludedURL(); String excludedURL = zaproxy.getExcludedURL(); String targetURL = zaproxy.getTargetURL(); String reportName = zaproxy.getReportFilename(); String reportTitle = zaproxy.getExportreportTitle(); ArrayList<ZAPCmdLine> cmdLinesZap = new ArrayList<ZAPCmdLine>(zaproxy.getCmdLinesZAP().size()); try { zapHost = applyMacro(build, listener, zapHost); zapPort = applyMacro(build, listener, zapPort); sessionFilename = applyMacro(build, listener, sessionFilename); internalSites = applyMacro(build, listener, internalSites); contextName = applyMacro(build, listener, contextName); includedURL = applyMacro(build, listener, includedURL); excludedURL = applyMacro(build, listener, excludedURL); targetURL = applyMacro(build, listener, targetURL); reportName = applyMacro(build, listener, reportName); reportTitle = applyMacro(build, listener, reportTitle); for (ZAPCmdLine cmdLineZap : zaproxy.getCmdLinesZAP()) cmdLinesZap.add(new ZAPCmdLine(applyMacro(build, listener, cmdLineZap.getCmdLineOption()), applyMacro(build, listener, cmdLineZap.getCmdLineValue()))); } catch (InterruptedException e1) { listener.error(ExceptionUtils.getStackTrace(e1)); } zaproxy.setEvaluatedZapHost(zapHost); zaproxy.setEvaluatedZapPort(Integer.valueOf(zapPort)); zaproxy.setEvaluatedSessionFilename(sessionFilename); zaproxy.setEvaluatedInternalSites(internalSites); zaproxy.setEvaluatedContextName(contextName); zaproxy.setEvaluatedIncludedURL(includedURL); zaproxy.setEvaluatedExcludedURL(excludedURL); zaproxy.setEvaluatedTargetURL(targetURL); zaproxy.setEvaluatedReportFilename(reportName); zaproxy.setEvaluatedExportreportTitle(reportTitle); zaproxy.setEvaluatedCmdLinesZap(cmdLinesZap); Utils.loggerMessage(listener, 1, "HOST = [ {0} ]", zapHost); Utils.loggerMessage(listener, 1, "PORT = [ {0} ]", zapPort); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "SESSION FILENAME = [ {0} ]", sessionFilename); Utils.loggerMessage(listener, 1, "INTERNAL SITES = [ {0} ]", internalSites.trim().replace("\n", ", ")); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "CONTEXT NAME = [ {0} ]", contextName); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "INCLUDE IN CONTEXT = [ {0} ]", includedURL.trim().replace("\n", ", ")); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "EXCLUDE FROM CONTEXT = [ {0} ]", excludedURL.trim().replace("\n", ", ")); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "STARTING POINT (URL) = [ {0} ]", targetURL); Utils.loggerMessage(listener, 1, "REPORT FILENAME = [ {0} ]", reportName); Utils.loggerMessage(listener, 1, "REPORT TITLE = [ {0} ]", reportTitle); Utils.lineBreak(listener); Utils.loggerMessage(listener, 1, "COMMAND LINE = {0}", cmdLinesZap.toString().trim() .substring(1, cmdLinesZap.toString().trim().length() - 1).replace(",", "")); if (cmdLinesZap.isEmpty()) Utils.lineBreak(listener); Utils.loggerMessage(listener, 0, "[{0}] END PRE-BUILD ENVIRONMENT VARIABLE REPLACEMENT", Utils.ZAP); Utils.lineBreak(listener); /* Clear the ZAP home directory of all previous zap logs. */ Utils.loggerMessage(listener, 0, "[{0}] CLEAR LOGS IN SETTINGS...", Utils.ZAP); Utils.loggerMessage(listener, 1, "ZAP HOME DIRECTORY [ {0} ]", this.zaproxy.getZapSettingsDir()); Utils.loggerMessage(listener, 1, "JENKINS WORKSPACE [ {0} ]", build.getWorkspace().getRemote()); /* No workspace before the first build, so workspace is null. */ FilePath ws = build.getWorkspace(); if (ws != null) { File[] listFiles = {}; try { listFiles = ws.act(new LogCallable(this.zaproxy.getZapSettingsDir())); } catch (IOException e) { e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */ } catch (InterruptedException e) { e.printStackTrace(); /* No listener because it's not during a build but it's on the job config page. */ } Utils.loggerMessage(listener, 1, "CLEARING ZAP HOME DIRECTORY/{0}", ZAPDriver.NAME_LOG_DIR.toUpperCase()); Utils.lineBreak(listener); for (File listFile : listFiles) { Utils.loggerMessage(listener, 1, "[ {0} ] LOG HAS BEEN FOUND", listFile.getAbsolutePath()); String stringForLogger = "DELETE [" + listFile.getName() + "] FROM "; try { stringForLogger = ws.act(new DeleteFileCallable(listFile.getAbsolutePath(), stringForLogger)); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } Utils.loggerMessage(listener, 1, "{0}", stringForLogger); Utils.lineBreak(listener); } } /* Start ZAP as a Pre-Build step. */ if (startZAPFirst) { Utils.lineBreak(listener); Utils.loggerMessage(listener, 0, "[{0}] START PRE-BUILD STEP", Utils.ZAP); Utils.lineBreak(listener); try { Launcher launcher = null; Node node = build.getBuiltOn(); /* Create launcher according to the build's location (Master or Slave) and the build's OS */ if ("".equals(node.getNodeName())) launcher = new LocalLauncher(listener, build.getWorkspace().getChannel()); else { /* Build on slave */ boolean isUnix; if ("Unix".equals(((SlaveComputer) node.toComputer()).getOSDescription())) isUnix = true; else isUnix = false; launcher = new RemoteLauncher(listener, build.getWorkspace().getChannel(), isUnix); } proc = zaproxy.startZAP(build, listener, launcher); } catch (Exception e) { e.printStackTrace(); listener.error(ExceptionUtils.getStackTrace(e)); return false; } Utils.loggerMessage(listener, 0, "[{0}] END PRE-BUILD STEP", Utils.ZAP); Utils.lineBreak(listener); Utils.loggerMessage(listener, 0, "[{0}] COMMENCEMENT OF SELENIUM SCRIPTS, ZAP WILL NOW LISTEN ON THE DESIGNATED PORT", Utils.ZAP); Utils.lineBreak(listener); } return true; }
From source file:com.virtusa.isq.rft.runtime.RFTCommandBase.java
private void compareTableData(ObjectLocator locator, TestObject object, Object objExpectedValue, boolean stopOnFaliure) { ArrayList<String> htmlTable; ArrayList<String> inputTable; try {/* www . ja va2s . c om*/ htmlTable = getAppTable(object); inputTable = new ArrayList<String>(Arrays.asList(objExpectedValue.toString().split("(?<!\\\\),"))); ArrayList<String> tempInputTable = new ArrayList<String>(); for (String inputVal : inputTable) { String formattedValue = inputVal.replaceAll("\\\\,", ","); tempInputTable.add(formattedValue); } inputTable = tempInputTable; String inputTableStr = StringUtils.join(inputTable, "|"); String actualTableStr = StringUtils.join(htmlTable, "|"); if (actualTableStr.contains(inputTableStr)) { reportResults(ReportLogger.ReportLevel.SUCCESS, "Check Table", "Success", "Check table data : " + objExpectedValue); } else { String inputTableString = inputTable.toString(); String htmlTableString = htmlTable.toString(); reportResults(stopOnFaliure, ReportLogger.ReportLevel.FAILURE, "Check Table", "Error", "Check Table TABLEDATA command failed. ::: " + "Object : " + Arrays.asList(locator.getPropertyArray()) + " ::: " + "Actual Error : Expected data " + inputTableString + " does not match the actual : " + htmlTableString); } } catch (UserAbortedActionException ex) { throw ex; } catch (Exception ex) { reportResults(stopOnFaliure, ReportLogger.ReportLevel.FAILURE, "Check Table", "Error", "Cannot access the element. ::: " + "Object : " + Arrays.asList(locator.getPropertyArray()) + " ::: " + "Actual Error : " + ex.getMessage()); } }
From source file:com.amazonaws.services.iot.demo.danbo.rpi.PiezoBuzzer.java
public String[] play(String songData) throws Exception { ArrayList<Integer> pitches = new ArrayList<Integer>(); ArrayList<Float> durations = new ArrayList<Float>(); int default_dur = 4; int default_oct = 6; int bpm = 63; int num;//from w w w . ja v a 2s . c o m long wholenote; long duration; int note; int scale; int p = 0; while (songData.charAt(p) != ':') { p++; } p++; if (songData.charAt(p) == 'd') { p++; p++; num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } if (num > 0) { default_dur = num; } p++; } if (songData.charAt(p) == 'o') { p++; p++; num = Integer.valueOf(songData.charAt(p++) - '0'); if (num >= 3 && num <= 7) { default_oct = num; } p++; } if (songData.charAt(p) == 'b') { p++; p++; num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } bpm = num; p++; } wholenote = (60 * 1000L / bpm) * 4; while (p < songData.length()) { num = 0; while (Character.isDigit(songData.charAt(p))) { num = (num * 10) + Integer.valueOf(songData.charAt(p++) - '0'); } if (num != 0) { duration = wholenote / num; } else { duration = wholenote / default_dur; } note = 0; switch (songData.charAt(p)) { case 'c': note = 1; break; case 'd': note = 3; break; case 'e': note = 5; break; case 'f': note = 6; break; case 'g': note = 8; break; case 'a': note = 10; break; case 'b': note = 12; break; case 'p': note = 0; default: note = 0; } p++; if (songData.charAt(p) == '#') { note++; p++; } if (songData.charAt(p) == '.') { duration += duration / 2; p++; } if (Character.isDigit(songData.charAt(p))) { scale = Integer.valueOf(songData.charAt(p) - '0'); p++; } else { scale = default_oct; } scale += OCTAVE_OFFSET; if (songData.charAt(p) == ',') { p++; } if (note != 0) { int n = note_pitch[(scale - 4) * 12 + note]; pitches.add(new Integer(n)); durations.add(new Float(duration) / new Float(1000)); } else { pitches.add(new Integer(0)); durations.add(new Float(duration) / new Float(1000)); } } String[] returnVal = new String[2]; returnVal[0] = pitches.toString().substring(1, pitches.toString().length() - 1).replaceAll(" ", ""); returnVal[1] = durations.toString().substring(1, durations.toString().length() - 1).replaceAll(" ", ""); return returnVal; }