code
stringlengths
73
34.1k
label
stringclasses
1 value
public void pushDryRun() throws Exception { if (releaseAction.isCreateVcsTag()) { if (scmManager.isTagExists(scmManager.getRemoteConfig(releaseAction.getTargetRemoteName()), releaseAction.getTagUrl())) { throw new Exception(String.format("Tag with name '%s' already exists", releaseAc...
java
public synchronized static void registerImagOnAgents(Launcher launcher, final String imageTag, final String host, final String targetRepo, final ArrayListMultimap<String, String> artifactsProps, final int buildInfoId) throws IOException, InterruptedException { // Master final...
java
private static void registerImage(String imageId, String imageTag, String targetRepo, ArrayListMultimap<String, String> artifactsProps, int buildInfoId) throws IOException { DockerImage image = new DockerImage(imageId, imageTag, targetRepo, buildInfoId, artifactsProps); images.add(image); ...
java
public static List<DockerImage> getImagesByBuildId(int buildInfoId) { List<DockerImage> list = new ArrayList<DockerImage>(); Iterator<DockerImage> it = images.iterator(); while (it.hasNext()) { DockerImage image = it.next(); if (image.getBuildInfoId() == buildInfoId && im...
java
public static List<DockerImage> getAndDiscardImagesByBuildId(int buildInfoId) { List<DockerImage> list = new ArrayList<DockerImage>(); synchronized(images) { Iterator<DockerImage> it = images.iterator(); while (it.hasNext()) { DockerImage image = it.next(); ...
java
public static List<DockerImage> getDockerImagesFromAgents(final int buildInfoId, TaskListener listener) throws IOException, InterruptedException { List<DockerImage> dockerImages = new ArrayList<DockerImage>(); // Collect images from the master: dockerImages.addAll(getAndDiscardImagesByBuildId(b...
java
public static boolean pushImage(Launcher launcher, final JenkinsBuildInfoLog log, final String imageTag, final String username, final String password, final String host) throws IOException, InterruptedException { return launcher.getChannel().call(new MasterToSlaveCallable<Boolean, IOException>() {...
java
public static boolean pullImage(Launcher launcher, final String imageTag, final String username, final String password, final String host) throws IOException, InterruptedException { return launcher.getChannel().call(new MasterToSlaveCallable<Boolean, IOException>() { public Boolean call...
java
public static boolean updateImageParentOnAgents(final JenkinsBuildInfoLog log, final String imageTag, final String host, final int buildInfoId) throws IOException, InterruptedException { boolean parentUpdated = updateImageParent(log, imageTag, host, buildInfoId); List<Node> nodes = Jenkins.getInstance()...
java
public static String getImageIdFromAgent(Launcher launcher, final String imageTag, final String host) throws IOException, InterruptedException { return launcher.getChannel().call(new MasterToSlaveCallable<String, IOException>() { public String call() throws IOException { return Docke...
java
public static String getParentIdFromAgent(Launcher launcher, final String imageID, final String host) throws IOException, InterruptedException { return launcher.getChannel().call(new MasterToSlaveCallable<String, IOException>() { public String call() throws IOException { return Docke...
java
@Override protected void initBuilderSpecific() throws Exception { reset(); FilePath workspace = getModuleRoot(EnvVars.masterEnvVars); FilePath gradlePropertiesPath = new FilePath(workspace, "gradle.properties"); if (releaseProps == null) { releaseProps = PropertyUtils.get...
java
public FilePath getModuleRoot(Map<String, String> globalEnv) throws IOException, InterruptedException { FilePath someWorkspace = project.getSomeWorkspace(); if (someWorkspace == null) { throw new IllegalStateException("Couldn't find workspace"); } Map<String, String> workspa...
java
private String extractNumericVersion(Collection<String> versionStrings) { if (versionStrings == null) { return ""; } for (String value : versionStrings) { String releaseValue = calculateReleaseVersion(value); if (!releaseValue.equals(value)) { ...
java
@SuppressWarnings("UnusedDeclaration") public void init() throws Exception { initBuilderSpecific(); resetFields(); if (!UserPluginInfo.NO_PLUGIN_KEY.equals(getSelectedStagingPluginName())) { PluginSettings selectedStagingPluginSettings = getSelectedStagingPlugin(); tr...
java
@SuppressWarnings({"UnusedDeclaration"}) protected void doApi(StaplerRequest req, StaplerResponse resp) throws IOException, ServletException { try { log.log(Level.INFO, "Initiating Artifactory Release Staging using API"); // Enforce release permissions project.checkPermis...
java
protected String calculateNextVersion(String fromVersion) { // first turn it to release version fromVersion = calculateReleaseVersion(fromVersion); String nextVersion; int lastDotIndex = fromVersion.lastIndexOf('.'); try { if (lastDotIndex != -1) { // ...
java
public void addVars(Map<String, String> env) { if (tagUrl != null) { env.put("RELEASE_SCM_TAG", tagUrl); env.put(RT_RELEASE_STAGING + "SCM_TAG", tagUrl); } if (releaseBranch != null) { env.put("RELEASE_SCM_BRANCH", releaseBranch); env.put(RT_RELEAS...
java
public String generateInitScript(EnvVars env) throws IOException, InterruptedException { StringBuilder initScript = new StringBuilder(); InputStream templateStream = getClass().getResourceAsStream("/initscripttemplate.gradle"); String templateAsString = IOUtils.toString(templateStream, Charsets....
java
public static int convertBytesToInt(byte[] bytes, int offset) { return (BITWISE_BYTE_TO_INT & bytes[offset + 3]) | ((BITWISE_BYTE_TO_INT & bytes[offset + 2]) << 8) | ((BITWISE_BYTE_TO_INT & bytes[offset + 1]) << 16) | ((BITWISE_BYTE_TO_INT & bytes[offset]) << ...
java
public static int[] convertBytesToInts(byte[] bytes) { if (bytes.length % 4 != 0) { throw new IllegalArgumentException("Number of input bytes must be a multiple of 4."); } int[] ints = new int[bytes.length / 4]; for (int i = 0; i < ints.length; i++) { ...
java
public static long convertBytesToLong(byte[] bytes, int offset) { long value = 0; for (int i = offset; i < offset + 8; i++) { byte b = bytes[i]; value <<= 8; value |= b; } return value; }
java
private double getExpectedProbability(double x) { double y = 1 / (standardDeviation * Math.sqrt(Math.PI * 2)); double z = -(Math.pow(x - mean, 2) / (2 * Math.pow(standardDeviation, 2))); return y * Math.exp(z); }
java
public final void reset() { for (int i = 0; i < permutationIndices.length; i++) { permutationIndices[i] = i; } remainingPermutations = totalPermutations; }
java
@SuppressWarnings("unchecked") public T[] nextPermutationAsArray() { T[] permutation = (T[]) Array.newInstance(elements.getClass().getComponentType(), permutationIndices.length); return nextPermutationAsArray(permutation); }
java
public List<T> nextPermutationAsList() { List<T> permutation = new ArrayList<T>(elements.length); return nextPermutationAsList(permutation); }
java
private static long createLongSeed(byte[] seed) { if (seed == null || seed.length != SEED_SIZE_BYTES) { throw new IllegalArgumentException("Java RNG requires a 64-bit (8-byte) seed."); } return BinaryUtils.convertBytesToLong(seed, 0); }
java
public void execute() { Runnable task = new Runnable() { public void run() { final V result = performTask(); SwingUtilities.invokeLater(new Runnable() { public void run() { ...
java
public void addValue(double value) { if (dataSetSize == dataSet.length) { // Increase the capacity of the array. int newLength = (int) (GROWTH_RATE * dataSetSize); double[] newDataSet = new double[newLength]; System.arraycopy(dataSet, 0, newDataSet, 0,...
java
public final double getMedian() { assertNotEmpty(); // Sort the data (take a copy to do this). double[] dataCopy = new double[getSize()]; System.arraycopy(dataSet, 0, dataCopy, 0, dataCopy.length); Arrays.sort(dataCopy); int midPoint = dataCopy.length / 2; if ...
java
private double sumSquaredDiffs() { double mean = getArithmeticMean(); double squaredDiffs = 0; for (int i = 0; i < getSize(); i++) { double diff = mean - dataSet[i]; squaredDiffs += (diff * diff); } return squaredDiffs; }
java
public boolean getBit(int index) { assertValidIndex(index); int word = index / WORD_LENGTH; int offset = index % WORD_LENGTH; return (data[word] & (1 << offset)) != 0; }
java
public void setBit(int index, boolean set) { assertValidIndex(index); int word = index / WORD_LENGTH; int offset = index % WORD_LENGTH; if (set) { data[word] |= (1 << offset); } else // Unset the bit. { data[word] &= ~(1 << offs...
java
public void flipBit(int index) { assertValidIndex(index); int word = index / WORD_LENGTH; int offset = index % WORD_LENGTH; data[word] ^= (1 << offset); }
java
public void swapSubstring(BitString other, int start, int length) { assertValidIndex(start); other.assertValidIndex(start); int word = start / WORD_LENGTH; int partialWordSize = (WORD_LENGTH - start) % WORD_LENGTH; if (partialWordSize > 0) { swap...
java
public int compareTo(Rational other) { if (denominator == other.getDenominator()) { return ((Long) numerator).compareTo(other.getNumerator()); } else { Long adjustedNumerator = numerator * other.getDenominator(); Long otherAdjustedNumerator...
java
public static void generateOutputFile(Random rng, File outputFile) throws IOException { DataOutputStream dataOutput = null; try { dataOutput = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile))); f...
java
public static long raiseToPower(int value, int power) { if (power < 0) { throw new IllegalArgumentException("This method does not support negative powers."); } long result = 1; for (int i = 0; i < power; i++) { result *= value; } ...
java
public static int restrictRange(int value, int min, int max) { return Math.min((Math.max(value, min)), max); }
java
protected static Map<Double, Double> doQuantization(double max, double min, double[] values) { double range = max - min; int noIntervals = 20; double intervalSize = range / noInter...
java
public final void reset() { for (int i = 0; i < combinationIndices.length; i++) { combinationIndices[i] = i; } remainingCombinations = totalCombinations; }
java
@SuppressWarnings("unchecked") public T[] nextCombinationAsArray() { T[] combination = (T[]) Array.newInstance(elements.getClass().getComponentType(), combinationIndices.length); return nextCombinationAsArray(combination); }
java
public void setValue(T value) { try { lock.writeLock().lock(); this.value = value; } finally { lock.writeLock().unlock(); } }
java
public static String urlEncode(String path) throws URISyntaxException { if (isNullOrEmpty(path)) return path; return UrlEscapers.urlFragmentEscaper().escape(path); }
java
public static String encode(String value) throws UnsupportedEncodingException { if (isNullOrEmpty(value)) return value; return URLEncoder.encode(value, URL_ENCODING); }
java
public static HttpResponse getResponse(String urls, HttpRequest request, HttpMethod method, int connectTimeoutMillis, int readTimeoutMillis) throws IOException { OutputStream out = null; InputStream content = null; HttpResponse response = null; ...
java
public void refreshCredentials() { if (this.credsProvider == null) return; try { AlibabaCloudCredentials creds = this.credsProvider.getCredentials(); this.accessKeyID = creds.getAccessKeyId(); this.accessKeySecret = creds.getAccessKeySecret(); ...
java
public void addExtraInfo(String key, Object value) { // Turn extraInfo into map Map<String, Object> infoMap = (HashMap<String, Object>)getMapFromJSON(extraInfo); // Add value infoMap.put(key, value); // Turn back into string extraInfo = getJSONFromMap(infoMap); }
java
private Map<String, Object> getMapFromJSON(String json) { Map<String, Object> propMap = new HashMap<String, Object>(); ObjectMapper mapper = new ObjectMapper(); // Initialize string if empty if (json == null || json.length() == 0) { json = "{}"; } try { ...
java
private String getJSONFromMap(Map<String, Object> propMap) { try { return new JSONObject(propMap).toString(); } catch (Exception e) { return "{}"; } }
java
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String queryString = request.getQueryString() == null ? "" : request.getQueryString(); if (ConfigurationService.getInstance().isValid() || ...
java
@RequestMapping(value = "api/edit/server", method = RequestMethod.POST) public @ResponseBody ServerRedirect addRedirectToProfile(Model model, @RequestParam(value = "profileId", required = false) Integer profileId, @RequestParam(...
java
@RequestMapping(value = "api/edit/server", method = RequestMethod.GET) public @ResponseBody HashMap<String, Object> getjqRedirects(Model model, @RequestParam(value = "profileId", required = false) Integer profileId, @Reque...
java
@RequestMapping(value = "api/servergroup", method = RequestMethod.GET) public @ResponseBody HashMap<String, Object> getServerGroups(Model model, @RequestParam(value = "profileId", required = false) Integer profileId, @Re...
java
@RequestMapping(value = "api/servergroup", method = RequestMethod.POST) public @ResponseBody ServerGroup createServerGroup(Model model, @RequestParam(value = "name") String name, @RequestParam(value = "profileId", required = false) Integer ...
java
@RequestMapping(value = "/cert", method = {RequestMethod.GET, RequestMethod.HEAD}) public String certPage() throws Exception { return "cert"; }
java
public static Map<String, String[]> mapUrlEncodedParameters(byte[] dataArray) throws Exception { Map<String, String[]> mapPostParameters = new HashMap<String, String[]>(); try { ByteArrayOutputStream byteout = new ByteArrayOutputStream(); for (int x = 0; x < dataArray.length; x+...
java
public static String getURL(String sourceURI) { String retval = sourceURI; int qPos = sourceURI.indexOf("?"); if (qPos != -1) { retval = retval.substring(0, qPos); } return retval; }
java
public static String getHeaders(HttpMethod method) { String headerString = ""; Header[] headers = method.getRequestHeaders(); for (Header header : headers) { String name = header.getName(); if (name.equals(Constants.ODO_PROXY_HEADER)) { // skip.. don't wan...
java
public static String getHeaders(HttpServletRequest request) { String headerString = ""; Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); if (name.equals(Constants.ODO_PROXY_HEADER...
java
public static String getHeaders(HttpServletResponse response) { String headerString = ""; Collection<String> headerNames = response.getHeaderNames(); for (String headerName : headerNames) { // there may be multiple headers per header name for (String headerValue : respons...
java
public static HashMap<String, String> getParameters(String query) { HashMap<String, String> params = new HashMap<String, String>(); if (query == null || query.length() == 0) { return params; } String[] splitQuery = query.split("&"); for (String splitItem : splitQuery...
java
public List<Method> getMethodsFromGroupIds(int[] groupIds, String[] filters) throws Exception { ArrayList<Method> methods = new ArrayList<Method>(); for (int groupId : groupIds) { methods.addAll(getMethodsFromGroupId(groupId, filters)); } return methods; }
java
public void updateRepeatNumber(int newNum, int path_id, String client_uuid) throws Exception { updateRequestResponseTables("repeat_number", newNum, getProfileIdFromPathID(path_id), client_uuid, path_id); }
java
public void disableAll(int profileId, String client_uuid) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE + ...
java
public void removePathnameFromProfile(int path_id, int profileId) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_ENABLED_OVERRIDE + ...
java
public List<Method> getMethodsFromGroupId(int groupId, String[] filters) throws Exception { ArrayList<Method> methods = new ArrayList<Method>(); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { statem...
java
public void enableCustomResponse(String custom, int path_id, String client_uuid) throws Exception { updateRequestResponseTables("custom_response", custom, getProfileIdFromPathID(path_id), client_uuid, path_id); }
java
public static void updatePathTable(String columnName, Object newData, int path_id) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + ...
java
public void removeCustomOverride(int path_id, String client_uuid) throws Exception { updateRequestResponseTables("custom_response", "", getProfileIdFromPathID(path_id), client_uuid, path_id); }
java
public static int getProfileIdFromPathID(int path_id) throws Exception { return (Integer) SQLService.getInstance().getFromTable(Constants.GENERIC_PROFILE_ID, Constants.GENERIC_ID, path_id, Constants.DB_TABLE_PATH); }
java
public List<Group> findAllGroups() { ArrayList<Group> allGroups = new ArrayList<Group>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatement("SELECT *...
java
public int addPathnameToProfile(int id, String pathname, String actualPath) throws Exception { int pathOrder = getPathOrder(id).size() + 1; int pathId = -1; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) ...
java
public void addPathToRequestResponseTable(int profileId, String clientUUID, int pathId) throws Exception { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection .prepareStatement("INSERT INTO " + Constants....
java
public List<Integer> getPathOrder(int profileId) { ArrayList<Integer> pathOrder = new ArrayList<Integer>(); PreparedStatement queryStatement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepare...
java
public void setGroupsForPath(Integer[] groups, int pathId) { String newGroups = Arrays.toString(groups); newGroups = newGroups.substring(1, newGroups.length() - 1).replaceAll("\\s", ""); logger.info("adding groups={}, to pathId={}", newGroups, pathId); EditService.updatePathTable(Consta...
java
public static boolean intArrayContains(int[] array, int numToCheck) { for (int i = 0; i < array.length; i++) { if (array[i] == numToCheck) { return true; } } return false; }
java
public Integer getGroupIdFromName(String groupName) { return (Integer) sqlService.getFromTable(Constants.GENERIC_ID, Constants.GROUPS_GROUP_NAME, groupName, Constants.DB_TABLE_GROUPS); }
java
public void createOverride(int groupId, String methodName, String className) throws Exception { // first make sure this doesn't already exist for (Method method : EditService.getInstance().getMethodsFromGroupId(groupId, null)) { if (method.getMethodName().equals(methodName) && method.getClas...
java
public String getGroupNameFromId(int groupId) { return (String) sqlService.getFromTable(Constants.GROUPS_GROUP_NAME, Constants.GENERIC_ID, groupId, Constants.DB_TABLE_GROUPS); }
java
public void updateGroupName(String newGroupName, int id) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_GROUPS + " SET " + Cons...
java
public void removeGroup(int groupId) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_GROUPS + " WHERE " + Constants.GENERIC...
java
private void removeGroupIdFromTablePaths(int groupIdToRemove) { PreparedStatement queryStatement = null; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement = sqlConnection.prepareStatemen...
java
public void removePath(int pathId) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { // remove any enabled overrides with this path statement = sqlConnection.prepareStatement( "DELETE FROM " + Constants.DB_TABLE_E...
java
public com.groupon.odo.proxylib.models.Method getMethodForOverrideId(int overrideId) { com.groupon.odo.proxylib.models.Method method = null; // special case for IDs < 0 if (overrideId < 0) { method = new com.groupon.odo.proxylib.models.Method(); method.setId(overrideId);...
java
public void updatePathOrder(int profileId, int[] pathOrder) { for (int i = 0; i < pathOrder.length; i++) { EditService.updatePathTable(Constants.PATH_PROFILE_PATH_ORDER, (i + 1), pathOrder[i]); } }
java
public int getPathId(String pathName, int profileId) { PreparedStatement queryStatement = null; ResultSet results = null; // first get the pathId for the pathName/profileId int pathId = -1; try (Connection sqlConnection = sqlService.getConnection()) { queryStatement =...
java
private String getPathSelectString() { String queryString = "SELECT " + Constants.DB_TABLE_REQUEST_RESPONSE + "." + Constants.GENERIC_CLIENT_UUID + "," + Constants.DB_TABLE_PATH + "." + Constants.GENERIC_ID + "," + Constants.PATH_PROFILE_PATHNAME + "," + Constants.PATH_PROFIL...
java
private EndpointOverride getEndpointOverrideFromResultSet(ResultSet results) throws Exception { EndpointOverride endpoint = new EndpointOverride(); endpoint.setPathId(results.getInt(Constants.GENERIC_ID)); endpoint.setPath(results.getString(Constants.PATH_PROFILE_ACTUAL_PATH)); endpoint....
java
public EndpointOverride getPath(int pathId, String clientUUID, String[] filters) throws Exception { EndpointOverride endpoint = null; PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlService.getConnection()) { String queryStrin...
java
public void setName(int pathId, String pathName) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + " SET " + Constants.PATH_...
java
public void setPath(int pathId, String path) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + " SET " + Constants.PATH_PROF...
java
public void setBodyFilter(int pathId, String bodyFilter) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + " SET " + Constan...
java
public void setContentType(int pathId, String contentType) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + " SET " + Const...
java
public void setRequestType(int pathId, Integer requestType) { if (requestType == null) { requestType = Constants.REQUEST_TYPE_GET; } PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepar...
java
public void setGlobal(int pathId, Boolean global) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { statement = sqlConnection.prepareStatement( "UPDATE " + Constants.DB_TABLE_PATH + " SET " + Constants.PAT...
java
public List<EndpointOverride> getPaths(int profileId, String clientUUID, String[] filters) throws Exception { ArrayList<EndpointOverride> properties = new ArrayList<EndpointOverride>(); PreparedStatement statement = null; ResultSet results = null; try (Connection sqlConnection = sqlServ...
java
public void setCustomRequest(int pathId, String customRequest, String clientUUID) { PreparedStatement statement = null; try (Connection sqlConnection = sqlService.getConnection()) { int profileId = EditService.getProfileIdFromPathID(pathId); statement = sqlConnection.prepareStat...
java
public void clearResponseSettings(int pathId, String clientUUID) throws Exception { logger.info("clearing response settings"); this.setResponseEnabled(pathId, false, clientUUID); OverrideService.getInstance().disableAllOverrides(pathId, clientUUID, Constants.OVERRIDE_TYPE_RESPONSE); Edit...
java
public void clearRequestSettings(int pathId, String clientUUID) throws Exception { this.setRequestEnabled(pathId, false, clientUUID); OverrideService.getInstance().disableAllOverrides(pathId, clientUUID, Constants.OVERRIDE_TYPE_REQUEST); EditService.getInstance().updateRepeatNumber(Constants.OVE...
java