id
int32 0
165k
| repo
stringlengths 7
58
| path
stringlengths 12
218
| func_name
stringlengths 3
140
| original_string
stringlengths 73
34.1k
| language
stringclasses 1
value | code
stringlengths 73
34.1k
| code_tokens
sequence | docstring
stringlengths 3
16k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 105
339
|
---|---|---|---|---|---|---|---|---|---|---|---|
164,900 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java | ServerRedirectService.setSourceUrl | public void setSourceUrl(String newUrl, int id) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_SERVERS +
" SET " + Constants.SERVER_REDIRECT_SRC_URL + " = ?" +
" WHERE " + Constants.GENERIC_ID + " = ?"
);
statement.setString(1, newUrl);
statement.setInt(2, id);
statement.executeUpdate();
statement.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | java | public void setSourceUrl(String newUrl, int id) {
PreparedStatement statement = null;
try (Connection sqlConnection = sqlService.getConnection()) {
statement = sqlConnection.prepareStatement(
"UPDATE " + Constants.DB_TABLE_SERVERS +
" SET " + Constants.SERVER_REDIRECT_SRC_URL + " = ?" +
" WHERE " + Constants.GENERIC_ID + " = ?"
);
statement.setString(1, newUrl);
statement.setInt(2, id);
statement.executeUpdate();
statement.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (statement != null) {
statement.close();
}
} catch (Exception e) {
}
}
} | [
"public",
"void",
"setSourceUrl",
"(",
"String",
"newUrl",
",",
"int",
"id",
")",
"{",
"PreparedStatement",
"statement",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
")",
"{",
"statement",
"=",
"sqlConnection",
".",
"prepareStatement",
"(",
"\"UPDATE \"",
"+",
"Constants",
".",
"DB_TABLE_SERVERS",
"+",
"\" SET \"",
"+",
"Constants",
".",
"SERVER_REDIRECT_SRC_URL",
"+",
"\" = ?\"",
"+",
"\" WHERE \"",
"+",
"Constants",
".",
"GENERIC_ID",
"+",
"\" = ?\"",
")",
";",
"statement",
".",
"setString",
"(",
"1",
",",
"newUrl",
")",
";",
"statement",
".",
"setInt",
"(",
"2",
",",
"id",
")",
";",
"statement",
".",
"executeUpdate",
"(",
")",
";",
"statement",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"statement",
"!=",
"null",
")",
"{",
"statement",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"}"
] | Set source url for a server
@param newUrl new URL
@param id Server ID | [
"Set",
"source",
"url",
"for",
"a",
"server"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L476-L499 |
164,901 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java | ServerRedirectService.deleteRedirect | public void deleteRedirect(int id) {
try {
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.GENERIC_ID + " = " + id + ";");
} catch (Exception e) {
e.printStackTrace();
}
} | java | public void deleteRedirect(int id) {
try {
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.GENERIC_ID + " = " + id + ";");
} catch (Exception e) {
e.printStackTrace();
}
} | [
"public",
"void",
"deleteRedirect",
"(",
"int",
"id",
")",
"{",
"try",
"{",
"sqlService",
".",
"executeUpdate",
"(",
"\"DELETE FROM \"",
"+",
"Constants",
".",
"DB_TABLE_SERVERS",
"+",
"\" WHERE \"",
"+",
"Constants",
".",
"GENERIC_ID",
"+",
"\" = \"",
"+",
"id",
"+",
"\";\"",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Deletes a redirect by id
@param id redirect ID | [
"Deletes",
"a",
"redirect",
"by",
"id"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L568-L575 |
164,902 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java | ServerRedirectService.deleteServerGroup | public void deleteServerGroup(int id) {
try {
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVER_GROUPS +
" WHERE " + Constants.GENERIC_ID + " = " + id + ";");
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.SERVER_REDIRECT_GROUP_ID + " = " + id);
} catch (Exception e) {
e.printStackTrace();
}
} | java | public void deleteServerGroup(int id) {
try {
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVER_GROUPS +
" WHERE " + Constants.GENERIC_ID + " = " + id + ";");
sqlService.executeUpdate("DELETE FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.SERVER_REDIRECT_GROUP_ID + " = " + id);
} catch (Exception e) {
e.printStackTrace();
}
} | [
"public",
"void",
"deleteServerGroup",
"(",
"int",
"id",
")",
"{",
"try",
"{",
"sqlService",
".",
"executeUpdate",
"(",
"\"DELETE FROM \"",
"+",
"Constants",
".",
"DB_TABLE_SERVER_GROUPS",
"+",
"\" WHERE \"",
"+",
"Constants",
".",
"GENERIC_ID",
"+",
"\" = \"",
"+",
"id",
"+",
"\";\"",
")",
";",
"sqlService",
".",
"executeUpdate",
"(",
"\"DELETE FROM \"",
"+",
"Constants",
".",
"DB_TABLE_SERVERS",
"+",
"\" WHERE \"",
"+",
"Constants",
".",
"SERVER_REDIRECT_GROUP_ID",
"+",
"\" = \"",
"+",
"id",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Delete a server group by id
@param id server group ID | [
"Delete",
"a",
"server",
"group",
"by",
"id"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L582-L592 |
164,903 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java | ServerRedirectService.getProfilesForServerName | public Profile[] getProfilesForServerName(String serverName) throws Exception {
int profileId = -1;
ArrayList<Profile> returnProfiles = new ArrayList<Profile>();
PreparedStatement queryStatement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
queryStatement = sqlConnection.prepareStatement(
"SELECT " + Constants.GENERIC_PROFILE_ID + " FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.SERVER_REDIRECT_SRC_URL + " = ? GROUP BY " +
Constants.GENERIC_PROFILE_ID
);
queryStatement.setString(1, serverName);
results = queryStatement.executeQuery();
while (results.next()) {
profileId = results.getInt(Constants.GENERIC_PROFILE_ID);
Profile profile = ProfileService.getInstance().findProfile(profileId);
returnProfiles.add(profile);
}
} catch (SQLException e) {
throw e;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (queryStatement != null) {
queryStatement.close();
}
} catch (Exception e) {
}
}
if (returnProfiles.size() == 0) {
return null;
}
return returnProfiles.toArray(new Profile[0]);
} | java | public Profile[] getProfilesForServerName(String serverName) throws Exception {
int profileId = -1;
ArrayList<Profile> returnProfiles = new ArrayList<Profile>();
PreparedStatement queryStatement = null;
ResultSet results = null;
try (Connection sqlConnection = sqlService.getConnection()) {
queryStatement = sqlConnection.prepareStatement(
"SELECT " + Constants.GENERIC_PROFILE_ID + " FROM " + Constants.DB_TABLE_SERVERS +
" WHERE " + Constants.SERVER_REDIRECT_SRC_URL + " = ? GROUP BY " +
Constants.GENERIC_PROFILE_ID
);
queryStatement.setString(1, serverName);
results = queryStatement.executeQuery();
while (results.next()) {
profileId = results.getInt(Constants.GENERIC_PROFILE_ID);
Profile profile = ProfileService.getInstance().findProfile(profileId);
returnProfiles.add(profile);
}
} catch (SQLException e) {
throw e;
} finally {
try {
if (results != null) {
results.close();
}
} catch (Exception e) {
}
try {
if (queryStatement != null) {
queryStatement.close();
}
} catch (Exception e) {
}
}
if (returnProfiles.size() == 0) {
return null;
}
return returnProfiles.toArray(new Profile[0]);
} | [
"public",
"Profile",
"[",
"]",
"getProfilesForServerName",
"(",
"String",
"serverName",
")",
"throws",
"Exception",
"{",
"int",
"profileId",
"=",
"-",
"1",
";",
"ArrayList",
"<",
"Profile",
">",
"returnProfiles",
"=",
"new",
"ArrayList",
"<",
"Profile",
">",
"(",
")",
";",
"PreparedStatement",
"queryStatement",
"=",
"null",
";",
"ResultSet",
"results",
"=",
"null",
";",
"try",
"(",
"Connection",
"sqlConnection",
"=",
"sqlService",
".",
"getConnection",
"(",
")",
")",
"{",
"queryStatement",
"=",
"sqlConnection",
".",
"prepareStatement",
"(",
"\"SELECT \"",
"+",
"Constants",
".",
"GENERIC_PROFILE_ID",
"+",
"\" FROM \"",
"+",
"Constants",
".",
"DB_TABLE_SERVERS",
"+",
"\" WHERE \"",
"+",
"Constants",
".",
"SERVER_REDIRECT_SRC_URL",
"+",
"\" = ? GROUP BY \"",
"+",
"Constants",
".",
"GENERIC_PROFILE_ID",
")",
";",
"queryStatement",
".",
"setString",
"(",
"1",
",",
"serverName",
")",
";",
"results",
"=",
"queryStatement",
".",
"executeQuery",
"(",
")",
";",
"while",
"(",
"results",
".",
"next",
"(",
")",
")",
"{",
"profileId",
"=",
"results",
".",
"getInt",
"(",
"Constants",
".",
"GENERIC_PROFILE_ID",
")",
";",
"Profile",
"profile",
"=",
"ProfileService",
".",
"getInstance",
"(",
")",
".",
"findProfile",
"(",
"profileId",
")",
";",
"returnProfiles",
".",
"add",
"(",
"profile",
")",
";",
"}",
"}",
"catch",
"(",
"SQLException",
"e",
")",
"{",
"throw",
"e",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"results",
"!=",
"null",
")",
"{",
"results",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"try",
"{",
"if",
"(",
"queryStatement",
"!=",
"null",
")",
"{",
"queryStatement",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"returnProfiles",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"returnProfiles",
".",
"toArray",
"(",
"new",
"Profile",
"[",
"0",
"]",
")",
";",
"}"
] | This returns all profiles associated with a server name
@param serverName server Name
@return profile UUID
@throws Exception exception | [
"This",
"returns",
"all",
"profiles",
"associated",
"with",
"a",
"server",
"name"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/ServerRedirectService.java#L601-L644 |
164,904 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getInstance | public static PluginManager getInstance() {
if (_instance == null) {
_instance = new PluginManager();
_instance.classInformation = new HashMap<String, ClassInformation>();
_instance.methodInformation = new HashMap<String, com.groupon.odo.proxylib.models.Method>();
_instance.jarInformation = new ArrayList<String>();
if (_instance.proxyLibPath == null) {
//Get the System Classloader
ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
//Get the URLs
URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();
for (int i = 0; i < urls.length; i++) {
if (urls[i].getFile().contains("proxylib")) {
// store the path to the proxylib
_instance.proxyLibPath = urls[i].getFile();
break;
}
}
}
_instance.initializePlugins();
}
return _instance;
} | java | public static PluginManager getInstance() {
if (_instance == null) {
_instance = new PluginManager();
_instance.classInformation = new HashMap<String, ClassInformation>();
_instance.methodInformation = new HashMap<String, com.groupon.odo.proxylib.models.Method>();
_instance.jarInformation = new ArrayList<String>();
if (_instance.proxyLibPath == null) {
//Get the System Classloader
ClassLoader sysClassLoader = Thread.currentThread().getContextClassLoader();
//Get the URLs
URL[] urls = ((URLClassLoader) sysClassLoader).getURLs();
for (int i = 0; i < urls.length; i++) {
if (urls[i].getFile().contains("proxylib")) {
// store the path to the proxylib
_instance.proxyLibPath = urls[i].getFile();
break;
}
}
}
_instance.initializePlugins();
}
return _instance;
} | [
"public",
"static",
"PluginManager",
"getInstance",
"(",
")",
"{",
"if",
"(",
"_instance",
"==",
"null",
")",
"{",
"_instance",
"=",
"new",
"PluginManager",
"(",
")",
";",
"_instance",
".",
"classInformation",
"=",
"new",
"HashMap",
"<",
"String",
",",
"ClassInformation",
">",
"(",
")",
";",
"_instance",
".",
"methodInformation",
"=",
"new",
"HashMap",
"<",
"String",
",",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"(",
")",
";",
"_instance",
".",
"jarInformation",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"if",
"(",
"_instance",
".",
"proxyLibPath",
"==",
"null",
")",
"{",
"//Get the System Classloader",
"ClassLoader",
"sysClassLoader",
"=",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getContextClassLoader",
"(",
")",
";",
"//Get the URLs",
"URL",
"[",
"]",
"urls",
"=",
"(",
"(",
"URLClassLoader",
")",
"sysClassLoader",
")",
".",
"getURLs",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"urls",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"urls",
"[",
"i",
"]",
".",
"getFile",
"(",
")",
".",
"contains",
"(",
"\"proxylib\"",
")",
")",
"{",
"// store the path to the proxylib",
"_instance",
".",
"proxyLibPath",
"=",
"urls",
"[",
"i",
"]",
".",
"getFile",
"(",
")",
";",
"break",
";",
"}",
"}",
"}",
"_instance",
".",
"initializePlugins",
"(",
")",
";",
"}",
"return",
"_instance",
";",
"}"
] | Gets the current instance of plugin manager
@return PluginManager | [
"Gets",
"the",
"current",
"instance",
"of",
"plugin",
"manager"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L72-L97 |
164,905 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.identifyClasses | public void identifyClasses(final String pluginDirectory) throws Exception {
methodInformation.clear();
jarInformation.clear();
try {
new FileTraversal() {
public void onDirectory(final File d) {
}
public void onFile(final File f) {
try {
// loads class files
if (f.getName().endsWith(".class")) {
// get the class name for this path
String className = f.getAbsolutePath();
className = className.replace(pluginDirectory, "");
className = getClassNameFromPath(className);
logger.info("Storing plugin information: {}, {}", className,
f.getName());
ClassInformation classInfo = new ClassInformation();
classInfo.pluginPath = pluginDirectory;
classInformation.put(className, classInfo);
} else if (f.getName().endsWith(".jar")) {
// loads JAR packages
// open up jar and discover files
// look for anything with /proxy/ in it
// this may discover things we don't need but that is OK
try {
jarInformation.add(f.getAbsolutePath());
JarFile jarFile = new JarFile(f);
Enumeration<?> enumer = jarFile.entries();
// Use the Plugin-Name manifest entry to match with the provided pluginName
String pluginPackageName = jarFile.getManifest().getMainAttributes().getValue("plugin-package");
if (pluginPackageName == null) {
return;
}
while (enumer.hasMoreElements()) {
Object element = enumer.nextElement();
String elementName = element.toString();
if (!elementName.endsWith(".class")) {
continue;
}
String className = getClassNameFromPath(elementName);
if (className.contains(pluginPackageName)) {
logger.info("Storing plugin information: {}, {}", className,
f.getAbsolutePath());
ClassInformation classInfo = new ClassInformation();
classInfo.pluginPath = f.getAbsolutePath();
classInformation.put(className, classInfo);
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
logger.warn("Exception caught: {}, {}", e.getMessage(), e.getCause());
}
}
}.traverse(new File(pluginDirectory));
} catch (IOException e) {
throw new Exception("Could not identify all plugins: " + e.getMessage());
}
} | java | public void identifyClasses(final String pluginDirectory) throws Exception {
methodInformation.clear();
jarInformation.clear();
try {
new FileTraversal() {
public void onDirectory(final File d) {
}
public void onFile(final File f) {
try {
// loads class files
if (f.getName().endsWith(".class")) {
// get the class name for this path
String className = f.getAbsolutePath();
className = className.replace(pluginDirectory, "");
className = getClassNameFromPath(className);
logger.info("Storing plugin information: {}, {}", className,
f.getName());
ClassInformation classInfo = new ClassInformation();
classInfo.pluginPath = pluginDirectory;
classInformation.put(className, classInfo);
} else if (f.getName().endsWith(".jar")) {
// loads JAR packages
// open up jar and discover files
// look for anything with /proxy/ in it
// this may discover things we don't need but that is OK
try {
jarInformation.add(f.getAbsolutePath());
JarFile jarFile = new JarFile(f);
Enumeration<?> enumer = jarFile.entries();
// Use the Plugin-Name manifest entry to match with the provided pluginName
String pluginPackageName = jarFile.getManifest().getMainAttributes().getValue("plugin-package");
if (pluginPackageName == null) {
return;
}
while (enumer.hasMoreElements()) {
Object element = enumer.nextElement();
String elementName = element.toString();
if (!elementName.endsWith(".class")) {
continue;
}
String className = getClassNameFromPath(elementName);
if (className.contains(pluginPackageName)) {
logger.info("Storing plugin information: {}, {}", className,
f.getAbsolutePath());
ClassInformation classInfo = new ClassInformation();
classInfo.pluginPath = f.getAbsolutePath();
classInformation.put(className, classInfo);
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
logger.warn("Exception caught: {}, {}", e.getMessage(), e.getCause());
}
}
}.traverse(new File(pluginDirectory));
} catch (IOException e) {
throw new Exception("Could not identify all plugins: " + e.getMessage());
}
} | [
"public",
"void",
"identifyClasses",
"(",
"final",
"String",
"pluginDirectory",
")",
"throws",
"Exception",
"{",
"methodInformation",
".",
"clear",
"(",
")",
";",
"jarInformation",
".",
"clear",
"(",
")",
";",
"try",
"{",
"new",
"FileTraversal",
"(",
")",
"{",
"public",
"void",
"onDirectory",
"(",
"final",
"File",
"d",
")",
"{",
"}",
"public",
"void",
"onFile",
"(",
"final",
"File",
"f",
")",
"{",
"try",
"{",
"// loads class files",
"if",
"(",
"f",
".",
"getName",
"(",
")",
".",
"endsWith",
"(",
"\".class\"",
")",
")",
"{",
"// get the class name for this path",
"String",
"className",
"=",
"f",
".",
"getAbsolutePath",
"(",
")",
";",
"className",
"=",
"className",
".",
"replace",
"(",
"pluginDirectory",
",",
"\"\"",
")",
";",
"className",
"=",
"getClassNameFromPath",
"(",
"className",
")",
";",
"logger",
".",
"info",
"(",
"\"Storing plugin information: {}, {}\"",
",",
"className",
",",
"f",
".",
"getName",
"(",
")",
")",
";",
"ClassInformation",
"classInfo",
"=",
"new",
"ClassInformation",
"(",
")",
";",
"classInfo",
".",
"pluginPath",
"=",
"pluginDirectory",
";",
"classInformation",
".",
"put",
"(",
"className",
",",
"classInfo",
")",
";",
"}",
"else",
"if",
"(",
"f",
".",
"getName",
"(",
")",
".",
"endsWith",
"(",
"\".jar\"",
")",
")",
"{",
"// loads JAR packages",
"// open up jar and discover files",
"// look for anything with /proxy/ in it",
"// this may discover things we don't need but that is OK",
"try",
"{",
"jarInformation",
".",
"add",
"(",
"f",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"JarFile",
"jarFile",
"=",
"new",
"JarFile",
"(",
"f",
")",
";",
"Enumeration",
"<",
"?",
">",
"enumer",
"=",
"jarFile",
".",
"entries",
"(",
")",
";",
"// Use the Plugin-Name manifest entry to match with the provided pluginName",
"String",
"pluginPackageName",
"=",
"jarFile",
".",
"getManifest",
"(",
")",
".",
"getMainAttributes",
"(",
")",
".",
"getValue",
"(",
"\"plugin-package\"",
")",
";",
"if",
"(",
"pluginPackageName",
"==",
"null",
")",
"{",
"return",
";",
"}",
"while",
"(",
"enumer",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"Object",
"element",
"=",
"enumer",
".",
"nextElement",
"(",
")",
";",
"String",
"elementName",
"=",
"element",
".",
"toString",
"(",
")",
";",
"if",
"(",
"!",
"elementName",
".",
"endsWith",
"(",
"\".class\"",
")",
")",
"{",
"continue",
";",
"}",
"String",
"className",
"=",
"getClassNameFromPath",
"(",
"elementName",
")",
";",
"if",
"(",
"className",
".",
"contains",
"(",
"pluginPackageName",
")",
")",
"{",
"logger",
".",
"info",
"(",
"\"Storing plugin information: {}, {}\"",
",",
"className",
",",
"f",
".",
"getAbsolutePath",
"(",
")",
")",
";",
"ClassInformation",
"classInfo",
"=",
"new",
"ClassInformation",
"(",
")",
";",
"classInfo",
".",
"pluginPath",
"=",
"f",
".",
"getAbsolutePath",
"(",
")",
";",
"classInformation",
".",
"put",
"(",
"className",
",",
"classInfo",
")",
";",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"logger",
".",
"warn",
"(",
"\"Exception caught: {}, {}\"",
",",
"e",
".",
"getMessage",
"(",
")",
",",
"e",
".",
"getCause",
"(",
")",
")",
";",
"}",
"}",
"}",
".",
"traverse",
"(",
"new",
"File",
"(",
"pluginDirectory",
")",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Could not identify all plugins: \"",
"+",
"e",
".",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | This loads plugin file information into a hash for lazy loading later on
@param pluginDirectory path of plugin
@throws Exception exception | [
"This",
"loads",
"plugin",
"file",
"information",
"into",
"a",
"hash",
"for",
"lazy",
"loading",
"later",
"on"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L117-L186 |
164,906 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getClassNameFromPath | private String getClassNameFromPath(String path) {
String className = path.replace(".class", "");
// for *nix
if (className.startsWith("/")) {
className = className.substring(1, className.length());
}
className = className.replace("/", ".");
// for windows
if (className.startsWith("\\")) {
className = className.substring(1, className.length());
}
className = className.replace("\\", ".");
return className;
} | java | private String getClassNameFromPath(String path) {
String className = path.replace(".class", "");
// for *nix
if (className.startsWith("/")) {
className = className.substring(1, className.length());
}
className = className.replace("/", ".");
// for windows
if (className.startsWith("\\")) {
className = className.substring(1, className.length());
}
className = className.replace("\\", ".");
return className;
} | [
"private",
"String",
"getClassNameFromPath",
"(",
"String",
"path",
")",
"{",
"String",
"className",
"=",
"path",
".",
"replace",
"(",
"\".class\"",
",",
"\"\"",
")",
";",
"// for *nix",
"if",
"(",
"className",
".",
"startsWith",
"(",
"\"/\"",
")",
")",
"{",
"className",
"=",
"className",
".",
"substring",
"(",
"1",
",",
"className",
".",
"length",
"(",
")",
")",
";",
"}",
"className",
"=",
"className",
".",
"replace",
"(",
"\"/\"",
",",
"\".\"",
")",
";",
"// for windows",
"if",
"(",
"className",
".",
"startsWith",
"(",
"\"\\\\\"",
")",
")",
"{",
"className",
"=",
"className",
".",
"substring",
"(",
"1",
",",
"className",
".",
"length",
"(",
")",
")",
";",
"}",
"className",
"=",
"className",
".",
"replace",
"(",
"\"\\\\\"",
",",
"\".\"",
")",
";",
"return",
"className",
";",
"}"
] | Create a classname from a given path
@param path
@return | [
"Create",
"a",
"classname",
"from",
"a",
"given",
"path"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L194-L210 |
164,907 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.loadClass | public void loadClass(String className) throws Exception {
ClassInformation classInfo = classInformation.get(className);
logger.info("Loading plugin.: {}, {}", className, classInfo.pluginPath);
// get URL for proxylib
// need to load this also otherwise the annotations cannot be found later on
File libFile = new File(proxyLibPath);
URL libUrl = libFile.toURI().toURL();
// store the last modified time of the plugin
File pluginDirectoryFile = new File(classInfo.pluginPath);
classInfo.lastModified = pluginDirectoryFile.lastModified();
// load the plugin directory
URL classURL = new File(classInfo.pluginPath).toURI().toURL();
URL[] urls = new URL[] {classURL};
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
// load the class
Class<?> cls = child.loadClass(className);
// put loaded class into classInfo
classInfo.loadedClass = cls;
classInfo.loaded = true;
classInformation.put(className, classInfo);
logger.info("Loaded plugin: {}, {} method(s)", cls.toString(), cls.getDeclaredMethods().length);
} | java | public void loadClass(String className) throws Exception {
ClassInformation classInfo = classInformation.get(className);
logger.info("Loading plugin.: {}, {}", className, classInfo.pluginPath);
// get URL for proxylib
// need to load this also otherwise the annotations cannot be found later on
File libFile = new File(proxyLibPath);
URL libUrl = libFile.toURI().toURL();
// store the last modified time of the plugin
File pluginDirectoryFile = new File(classInfo.pluginPath);
classInfo.lastModified = pluginDirectoryFile.lastModified();
// load the plugin directory
URL classURL = new File(classInfo.pluginPath).toURI().toURL();
URL[] urls = new URL[] {classURL};
URLClassLoader child = new URLClassLoader(urls, this.getClass().getClassLoader());
// load the class
Class<?> cls = child.loadClass(className);
// put loaded class into classInfo
classInfo.loadedClass = cls;
classInfo.loaded = true;
classInformation.put(className, classInfo);
logger.info("Loaded plugin: {}, {} method(s)", cls.toString(), cls.getDeclaredMethods().length);
} | [
"public",
"void",
"loadClass",
"(",
"String",
"className",
")",
"throws",
"Exception",
"{",
"ClassInformation",
"classInfo",
"=",
"classInformation",
".",
"get",
"(",
"className",
")",
";",
"logger",
".",
"info",
"(",
"\"Loading plugin.: {}, {}\"",
",",
"className",
",",
"classInfo",
".",
"pluginPath",
")",
";",
"// get URL for proxylib",
"// need to load this also otherwise the annotations cannot be found later on",
"File",
"libFile",
"=",
"new",
"File",
"(",
"proxyLibPath",
")",
";",
"URL",
"libUrl",
"=",
"libFile",
".",
"toURI",
"(",
")",
".",
"toURL",
"(",
")",
";",
"// store the last modified time of the plugin",
"File",
"pluginDirectoryFile",
"=",
"new",
"File",
"(",
"classInfo",
".",
"pluginPath",
")",
";",
"classInfo",
".",
"lastModified",
"=",
"pluginDirectoryFile",
".",
"lastModified",
"(",
")",
";",
"// load the plugin directory",
"URL",
"classURL",
"=",
"new",
"File",
"(",
"classInfo",
".",
"pluginPath",
")",
".",
"toURI",
"(",
")",
".",
"toURL",
"(",
")",
";",
"URL",
"[",
"]",
"urls",
"=",
"new",
"URL",
"[",
"]",
"{",
"classURL",
"}",
";",
"URLClassLoader",
"child",
"=",
"new",
"URLClassLoader",
"(",
"urls",
",",
"this",
".",
"getClass",
"(",
")",
".",
"getClassLoader",
"(",
")",
")",
";",
"// load the class",
"Class",
"<",
"?",
">",
"cls",
"=",
"child",
".",
"loadClass",
"(",
"className",
")",
";",
"// put loaded class into classInfo",
"classInfo",
".",
"loadedClass",
"=",
"cls",
";",
"classInfo",
".",
"loaded",
"=",
"true",
";",
"classInformation",
".",
"put",
"(",
"className",
",",
"classInfo",
")",
";",
"logger",
".",
"info",
"(",
"\"Loaded plugin: {}, {} method(s)\"",
",",
"cls",
".",
"toString",
"(",
")",
",",
"cls",
".",
"getDeclaredMethods",
"(",
")",
".",
"length",
")",
";",
"}"
] | Loads the specified class name and stores it in the hash
@param className class name
@throws Exception exception | [
"Loads",
"the",
"specified",
"class",
"name",
"and",
"stores",
"it",
"in",
"the",
"hash"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L218-L248 |
164,908 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.callFunction | public void callFunction(String className, String methodName, PluginArguments pluginArgs, Object... args) throws Exception {
Class<?> cls = getClass(className);
ArrayList<Object> newArgs = new ArrayList<>();
newArgs.add(pluginArgs);
com.groupon.odo.proxylib.models.Method m = preparePluginMethod(newArgs, className, methodName, args);
m.getMethod().invoke(cls, newArgs.toArray(new Object[0]));
} | java | public void callFunction(String className, String methodName, PluginArguments pluginArgs, Object... args) throws Exception {
Class<?> cls = getClass(className);
ArrayList<Object> newArgs = new ArrayList<>();
newArgs.add(pluginArgs);
com.groupon.odo.proxylib.models.Method m = preparePluginMethod(newArgs, className, methodName, args);
m.getMethod().invoke(cls, newArgs.toArray(new Object[0]));
} | [
"public",
"void",
"callFunction",
"(",
"String",
"className",
",",
"String",
"methodName",
",",
"PluginArguments",
"pluginArgs",
",",
"Object",
"...",
"args",
")",
"throws",
"Exception",
"{",
"Class",
"<",
"?",
">",
"cls",
"=",
"getClass",
"(",
"className",
")",
";",
"ArrayList",
"<",
"Object",
">",
"newArgs",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"newArgs",
".",
"add",
"(",
"pluginArgs",
")",
";",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
"m",
"=",
"preparePluginMethod",
"(",
"newArgs",
",",
"className",
",",
"methodName",
",",
"args",
")",
";",
"m",
".",
"getMethod",
"(",
")",
".",
"invoke",
"(",
"cls",
",",
"newArgs",
".",
"toArray",
"(",
"new",
"Object",
"[",
"0",
"]",
")",
")",
";",
"}"
] | Calls the specified function with the specified arguments. This is used for v2 response overrides
@param className name of class
@param methodName name of method
@param pluginArgs plugin arguments
@param args arguments to supply to function
@throws Exception exception | [
"Calls",
"the",
"specified",
"function",
"with",
"the",
"specified",
"arguments",
".",
"This",
"is",
"used",
"for",
"v2",
"response",
"overrides"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L259-L267 |
164,909 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getClass | private synchronized Class<?> getClass(String className) throws Exception {
// see if we need to invalidate the class
ClassInformation classInfo = classInformation.get(className);
File classFile = new File(classInfo.pluginPath);
if (classFile.lastModified() > classInfo.lastModified) {
logger.info("Class {} has been modified, reloading", className);
logger.info("Thread ID: {}", Thread.currentThread().getId());
classInfo.loaded = false;
classInformation.put(className, classInfo);
// also cleanup anything in methodInformation with this className so it gets reloaded
Iterator<Map.Entry<String, com.groupon.odo.proxylib.models.Method>> iter = methodInformation.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, com.groupon.odo.proxylib.models.Method> entry = iter.next();
if (entry.getKey().startsWith(className)) {
iter.remove();
}
}
}
if (!classInfo.loaded) {
loadClass(className);
}
return classInfo.loadedClass;
} | java | private synchronized Class<?> getClass(String className) throws Exception {
// see if we need to invalidate the class
ClassInformation classInfo = classInformation.get(className);
File classFile = new File(classInfo.pluginPath);
if (classFile.lastModified() > classInfo.lastModified) {
logger.info("Class {} has been modified, reloading", className);
logger.info("Thread ID: {}", Thread.currentThread().getId());
classInfo.loaded = false;
classInformation.put(className, classInfo);
// also cleanup anything in methodInformation with this className so it gets reloaded
Iterator<Map.Entry<String, com.groupon.odo.proxylib.models.Method>> iter = methodInformation.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, com.groupon.odo.proxylib.models.Method> entry = iter.next();
if (entry.getKey().startsWith(className)) {
iter.remove();
}
}
}
if (!classInfo.loaded) {
loadClass(className);
}
return classInfo.loadedClass;
} | [
"private",
"synchronized",
"Class",
"<",
"?",
">",
"getClass",
"(",
"String",
"className",
")",
"throws",
"Exception",
"{",
"// see if we need to invalidate the class",
"ClassInformation",
"classInfo",
"=",
"classInformation",
".",
"get",
"(",
"className",
")",
";",
"File",
"classFile",
"=",
"new",
"File",
"(",
"classInfo",
".",
"pluginPath",
")",
";",
"if",
"(",
"classFile",
".",
"lastModified",
"(",
")",
">",
"classInfo",
".",
"lastModified",
")",
"{",
"logger",
".",
"info",
"(",
"\"Class {} has been modified, reloading\"",
",",
"className",
")",
";",
"logger",
".",
"info",
"(",
"\"Thread ID: {}\"",
",",
"Thread",
".",
"currentThread",
"(",
")",
".",
"getId",
"(",
")",
")",
";",
"classInfo",
".",
"loaded",
"=",
"false",
";",
"classInformation",
".",
"put",
"(",
"className",
",",
"classInfo",
")",
";",
"// also cleanup anything in methodInformation with this className so it gets reloaded",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"String",
",",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
">",
"iter",
"=",
"methodInformation",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"iter",
".",
"hasNext",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"String",
",",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"entry",
"=",
"iter",
".",
"next",
"(",
")",
";",
"if",
"(",
"entry",
".",
"getKey",
"(",
")",
".",
"startsWith",
"(",
"className",
")",
")",
"{",
"iter",
".",
"remove",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"classInfo",
".",
"loaded",
")",
"{",
"loadClass",
"(",
"className",
")",
";",
"}",
"return",
"classInfo",
".",
"loadedClass",
";",
"}"
] | Obtain the class of a given className
@param className
@return
@throws Exception | [
"Obtain",
"the",
"class",
"of",
"a",
"given",
"className"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L435-L460 |
164,910 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getMethods | public String[] getMethods(String pluginClass) throws Exception {
ArrayList<String> methodNames = new ArrayList<String>();
Method[] methods = getClass(pluginClass).getDeclaredMethods();
for (Method method : methods) {
logger.info("Checking {}", method.getName());
com.groupon.odo.proxylib.models.Method methodInfo = this.getMethod(pluginClass, method.getName());
if (methodInfo == null) {
continue;
}
// check annotations
Boolean matchesAnnotation = false;
if (methodInfo.getMethodType().endsWith(Constants.PLUGIN_RESPONSE_OVERRIDE_CLASS) ||
methodInfo.getMethodType().endsWith(Constants.PLUGIN_RESPONSE_OVERRIDE_V2_CLASS)) {
matchesAnnotation = true;
}
if (!methodNames.contains(method.getName()) && matchesAnnotation) {
methodNames.add(method.getName());
}
}
return methodNames.toArray(new String[0]);
} | java | public String[] getMethods(String pluginClass) throws Exception {
ArrayList<String> methodNames = new ArrayList<String>();
Method[] methods = getClass(pluginClass).getDeclaredMethods();
for (Method method : methods) {
logger.info("Checking {}", method.getName());
com.groupon.odo.proxylib.models.Method methodInfo = this.getMethod(pluginClass, method.getName());
if (methodInfo == null) {
continue;
}
// check annotations
Boolean matchesAnnotation = false;
if (methodInfo.getMethodType().endsWith(Constants.PLUGIN_RESPONSE_OVERRIDE_CLASS) ||
methodInfo.getMethodType().endsWith(Constants.PLUGIN_RESPONSE_OVERRIDE_V2_CLASS)) {
matchesAnnotation = true;
}
if (!methodNames.contains(method.getName()) && matchesAnnotation) {
methodNames.add(method.getName());
}
}
return methodNames.toArray(new String[0]);
} | [
"public",
"String",
"[",
"]",
"getMethods",
"(",
"String",
"pluginClass",
")",
"throws",
"Exception",
"{",
"ArrayList",
"<",
"String",
">",
"methodNames",
"=",
"new",
"ArrayList",
"<",
"String",
">",
"(",
")",
";",
"Method",
"[",
"]",
"methods",
"=",
"getClass",
"(",
"pluginClass",
")",
".",
"getDeclaredMethods",
"(",
")",
";",
"for",
"(",
"Method",
"method",
":",
"methods",
")",
"{",
"logger",
".",
"info",
"(",
"\"Checking {}\"",
",",
"method",
".",
"getName",
"(",
")",
")",
";",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
"methodInfo",
"=",
"this",
".",
"getMethod",
"(",
"pluginClass",
",",
"method",
".",
"getName",
"(",
")",
")",
";",
"if",
"(",
"methodInfo",
"==",
"null",
")",
"{",
"continue",
";",
"}",
"// check annotations",
"Boolean",
"matchesAnnotation",
"=",
"false",
";",
"if",
"(",
"methodInfo",
".",
"getMethodType",
"(",
")",
".",
"endsWith",
"(",
"Constants",
".",
"PLUGIN_RESPONSE_OVERRIDE_CLASS",
")",
"||",
"methodInfo",
".",
"getMethodType",
"(",
")",
".",
"endsWith",
"(",
"Constants",
".",
"PLUGIN_RESPONSE_OVERRIDE_V2_CLASS",
")",
")",
"{",
"matchesAnnotation",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"methodNames",
".",
"contains",
"(",
"method",
".",
"getName",
"(",
")",
")",
"&&",
"matchesAnnotation",
")",
"{",
"methodNames",
".",
"add",
"(",
"method",
".",
"getName",
"(",
")",
")",
";",
"}",
"}",
"return",
"methodNames",
".",
"toArray",
"(",
"new",
"String",
"[",
"0",
"]",
")",
";",
"}"
] | Returns a string array of the methods loaded for a class
@param pluginClass name of class
@return string array of the methods loaded for the class
@throws Exception exception | [
"Returns",
"a",
"string",
"array",
"of",
"the",
"methods",
"loaded",
"for",
"a",
"class"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L478-L503 |
164,911 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getMethodsNotInGroup | public List<com.groupon.odo.proxylib.models.Method> getMethodsNotInGroup(int groupId) throws Exception {
List<com.groupon.odo.proxylib.models.Method> allMethods = getAllMethods();
List<com.groupon.odo.proxylib.models.Method> methodsNotInGroup = new ArrayList<com.groupon.odo.proxylib.models.Method>();
List<com.groupon.odo.proxylib.models.Method> methodsInGroup = editService.getMethodsFromGroupId(groupId, null);
for (int i = 0; i < allMethods.size(); i++) {
boolean add = true;
String methodName = allMethods.get(i).getMethodName();
String className = allMethods.get(i).getClassName();
for (int j = 0; j < methodsInGroup.size(); j++) {
if ((methodName.equals(methodsInGroup.get(j).getMethodName())) &&
(className.equals(methodsInGroup.get(j).getClassName()))) {
add = false;
}
}
if (add) {
methodsNotInGroup.add(allMethods.get(i));
}
}
return methodsNotInGroup;
} | java | public List<com.groupon.odo.proxylib.models.Method> getMethodsNotInGroup(int groupId) throws Exception {
List<com.groupon.odo.proxylib.models.Method> allMethods = getAllMethods();
List<com.groupon.odo.proxylib.models.Method> methodsNotInGroup = new ArrayList<com.groupon.odo.proxylib.models.Method>();
List<com.groupon.odo.proxylib.models.Method> methodsInGroup = editService.getMethodsFromGroupId(groupId, null);
for (int i = 0; i < allMethods.size(); i++) {
boolean add = true;
String methodName = allMethods.get(i).getMethodName();
String className = allMethods.get(i).getClassName();
for (int j = 0; j < methodsInGroup.size(); j++) {
if ((methodName.equals(methodsInGroup.get(j).getMethodName())) &&
(className.equals(methodsInGroup.get(j).getClassName()))) {
add = false;
}
}
if (add) {
methodsNotInGroup.add(allMethods.get(i));
}
}
return methodsNotInGroup;
} | [
"public",
"List",
"<",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"getMethodsNotInGroup",
"(",
"int",
"groupId",
")",
"throws",
"Exception",
"{",
"List",
"<",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"allMethods",
"=",
"getAllMethods",
"(",
")",
";",
"List",
"<",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"methodsNotInGroup",
"=",
"new",
"ArrayList",
"<",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"(",
")",
";",
"List",
"<",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"models",
".",
"Method",
">",
"methodsInGroup",
"=",
"editService",
".",
"getMethodsFromGroupId",
"(",
"groupId",
",",
"null",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"allMethods",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"boolean",
"add",
"=",
"true",
";",
"String",
"methodName",
"=",
"allMethods",
".",
"get",
"(",
"i",
")",
".",
"getMethodName",
"(",
")",
";",
"String",
"className",
"=",
"allMethods",
".",
"get",
"(",
"i",
")",
".",
"getClassName",
"(",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"methodsInGroup",
".",
"size",
"(",
")",
";",
"j",
"++",
")",
"{",
"if",
"(",
"(",
"methodName",
".",
"equals",
"(",
"methodsInGroup",
".",
"get",
"(",
"j",
")",
".",
"getMethodName",
"(",
")",
")",
")",
"&&",
"(",
"className",
".",
"equals",
"(",
"methodsInGroup",
".",
"get",
"(",
"j",
")",
".",
"getClassName",
"(",
")",
")",
")",
")",
"{",
"add",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"add",
")",
"{",
"methodsNotInGroup",
".",
"add",
"(",
"allMethods",
".",
"get",
"(",
"i",
")",
")",
";",
"}",
"}",
"return",
"methodsNotInGroup",
";",
"}"
] | returns all methods not in the group
@param groupId Id of group
@return List of Methods for a group
@throws Exception exception | [
"returns",
"all",
"methods",
"not",
"in",
"the",
"group"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L562-L583 |
164,912 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getPlugins | public Plugin[] getPlugins(Boolean onlyValid) {
Configuration[] configurations = ConfigurationService.getInstance().getConfigurations(Constants.DB_TABLE_CONFIGURATION_PLUGIN_PATH);
ArrayList<Plugin> plugins = new ArrayList<Plugin>();
if (configurations == null) {
return new Plugin[0];
}
for (Configuration config : configurations) {
Plugin plugin = new Plugin();
plugin.setId(config.getId());
plugin.setPath(config.getValue());
File path = new File(plugin.getPath());
if (path.isDirectory()) {
plugin.setStatus(Constants.PLUGIN_STATUS_VALID);
plugin.setStatusMessage("Valid");
} else {
plugin.setStatus(Constants.PLUGIN_STATUS_NOT_DIRECTORY);
plugin.setStatusMessage("Path is not a directory");
}
if (!onlyValid || plugin.getStatus() == Constants.PLUGIN_STATUS_VALID) {
plugins.add(plugin);
}
}
return plugins.toArray(new Plugin[0]);
} | java | public Plugin[] getPlugins(Boolean onlyValid) {
Configuration[] configurations = ConfigurationService.getInstance().getConfigurations(Constants.DB_TABLE_CONFIGURATION_PLUGIN_PATH);
ArrayList<Plugin> plugins = new ArrayList<Plugin>();
if (configurations == null) {
return new Plugin[0];
}
for (Configuration config : configurations) {
Plugin plugin = new Plugin();
plugin.setId(config.getId());
plugin.setPath(config.getValue());
File path = new File(plugin.getPath());
if (path.isDirectory()) {
plugin.setStatus(Constants.PLUGIN_STATUS_VALID);
plugin.setStatusMessage("Valid");
} else {
plugin.setStatus(Constants.PLUGIN_STATUS_NOT_DIRECTORY);
plugin.setStatusMessage("Path is not a directory");
}
if (!onlyValid || plugin.getStatus() == Constants.PLUGIN_STATUS_VALID) {
plugins.add(plugin);
}
}
return plugins.toArray(new Plugin[0]);
} | [
"public",
"Plugin",
"[",
"]",
"getPlugins",
"(",
"Boolean",
"onlyValid",
")",
"{",
"Configuration",
"[",
"]",
"configurations",
"=",
"ConfigurationService",
".",
"getInstance",
"(",
")",
".",
"getConfigurations",
"(",
"Constants",
".",
"DB_TABLE_CONFIGURATION_PLUGIN_PATH",
")",
";",
"ArrayList",
"<",
"Plugin",
">",
"plugins",
"=",
"new",
"ArrayList",
"<",
"Plugin",
">",
"(",
")",
";",
"if",
"(",
"configurations",
"==",
"null",
")",
"{",
"return",
"new",
"Plugin",
"[",
"0",
"]",
";",
"}",
"for",
"(",
"Configuration",
"config",
":",
"configurations",
")",
"{",
"Plugin",
"plugin",
"=",
"new",
"Plugin",
"(",
")",
";",
"plugin",
".",
"setId",
"(",
"config",
".",
"getId",
"(",
")",
")",
";",
"plugin",
".",
"setPath",
"(",
"config",
".",
"getValue",
"(",
")",
")",
";",
"File",
"path",
"=",
"new",
"File",
"(",
"plugin",
".",
"getPath",
"(",
")",
")",
";",
"if",
"(",
"path",
".",
"isDirectory",
"(",
")",
")",
"{",
"plugin",
".",
"setStatus",
"(",
"Constants",
".",
"PLUGIN_STATUS_VALID",
")",
";",
"plugin",
".",
"setStatusMessage",
"(",
"\"Valid\"",
")",
";",
"}",
"else",
"{",
"plugin",
".",
"setStatus",
"(",
"Constants",
".",
"PLUGIN_STATUS_NOT_DIRECTORY",
")",
";",
"plugin",
".",
"setStatusMessage",
"(",
"\"Path is not a directory\"",
")",
";",
"}",
"if",
"(",
"!",
"onlyValid",
"||",
"plugin",
".",
"getStatus",
"(",
")",
"==",
"Constants",
".",
"PLUGIN_STATUS_VALID",
")",
"{",
"plugins",
".",
"add",
"(",
"plugin",
")",
";",
"}",
"}",
"return",
"plugins",
".",
"toArray",
"(",
"new",
"Plugin",
"[",
"0",
"]",
")",
";",
"}"
] | Returns the data about all of the plugins that are set
@param onlyValid True to get only valid plugins, False for all
@return array of Plugins set | [
"Returns",
"the",
"data",
"about",
"all",
"of",
"the",
"plugins",
"that",
"are",
"set"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L591-L620 |
164,913 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java | PluginManager.getResource | public byte[] getResource(String pluginName, String fileName) throws Exception {
// TODO: This is going to be slow.. future improvement is to cache the data instead of searching all jars
for (String jarFilename : jarInformation) {
JarFile jarFile = new JarFile(new File(jarFilename));
Enumeration<?> enumer = jarFile.entries();
// Use the Plugin-Name manifest entry to match with the provided pluginName
String jarPluginName = jarFile.getManifest().getMainAttributes().getValue("Plugin-Name");
if (!jarPluginName.equals(pluginName)) {
continue;
}
while (enumer.hasMoreElements()) {
Object element = enumer.nextElement();
String elementName = element.toString();
// Skip items in the jar that don't start with "resources/"
if (!elementName.startsWith("resources/")) {
continue;
}
elementName = elementName.replace("resources/", "");
if (elementName.equals(fileName)) {
// get the file from the jar
ZipEntry ze = jarFile.getEntry(element.toString());
InputStream fileStream = jarFile.getInputStream(ze);
byte[] data = new byte[(int) ze.getSize()];
DataInputStream dataIs = new DataInputStream(fileStream);
dataIs.readFully(data);
dataIs.close();
return data;
}
}
}
throw new FileNotFoundException("Could not find resource");
} | java | public byte[] getResource(String pluginName, String fileName) throws Exception {
// TODO: This is going to be slow.. future improvement is to cache the data instead of searching all jars
for (String jarFilename : jarInformation) {
JarFile jarFile = new JarFile(new File(jarFilename));
Enumeration<?> enumer = jarFile.entries();
// Use the Plugin-Name manifest entry to match with the provided pluginName
String jarPluginName = jarFile.getManifest().getMainAttributes().getValue("Plugin-Name");
if (!jarPluginName.equals(pluginName)) {
continue;
}
while (enumer.hasMoreElements()) {
Object element = enumer.nextElement();
String elementName = element.toString();
// Skip items in the jar that don't start with "resources/"
if (!elementName.startsWith("resources/")) {
continue;
}
elementName = elementName.replace("resources/", "");
if (elementName.equals(fileName)) {
// get the file from the jar
ZipEntry ze = jarFile.getEntry(element.toString());
InputStream fileStream = jarFile.getInputStream(ze);
byte[] data = new byte[(int) ze.getSize()];
DataInputStream dataIs = new DataInputStream(fileStream);
dataIs.readFully(data);
dataIs.close();
return data;
}
}
}
throw new FileNotFoundException("Could not find resource");
} | [
"public",
"byte",
"[",
"]",
"getResource",
"(",
"String",
"pluginName",
",",
"String",
"fileName",
")",
"throws",
"Exception",
"{",
"// TODO: This is going to be slow.. future improvement is to cache the data instead of searching all jars",
"for",
"(",
"String",
"jarFilename",
":",
"jarInformation",
")",
"{",
"JarFile",
"jarFile",
"=",
"new",
"JarFile",
"(",
"new",
"File",
"(",
"jarFilename",
")",
")",
";",
"Enumeration",
"<",
"?",
">",
"enumer",
"=",
"jarFile",
".",
"entries",
"(",
")",
";",
"// Use the Plugin-Name manifest entry to match with the provided pluginName",
"String",
"jarPluginName",
"=",
"jarFile",
".",
"getManifest",
"(",
")",
".",
"getMainAttributes",
"(",
")",
".",
"getValue",
"(",
"\"Plugin-Name\"",
")",
";",
"if",
"(",
"!",
"jarPluginName",
".",
"equals",
"(",
"pluginName",
")",
")",
"{",
"continue",
";",
"}",
"while",
"(",
"enumer",
".",
"hasMoreElements",
"(",
")",
")",
"{",
"Object",
"element",
"=",
"enumer",
".",
"nextElement",
"(",
")",
";",
"String",
"elementName",
"=",
"element",
".",
"toString",
"(",
")",
";",
"// Skip items in the jar that don't start with \"resources/\"",
"if",
"(",
"!",
"elementName",
".",
"startsWith",
"(",
"\"resources/\"",
")",
")",
"{",
"continue",
";",
"}",
"elementName",
"=",
"elementName",
".",
"replace",
"(",
"\"resources/\"",
",",
"\"\"",
")",
";",
"if",
"(",
"elementName",
".",
"equals",
"(",
"fileName",
")",
")",
"{",
"// get the file from the jar",
"ZipEntry",
"ze",
"=",
"jarFile",
".",
"getEntry",
"(",
"element",
".",
"toString",
"(",
")",
")",
";",
"InputStream",
"fileStream",
"=",
"jarFile",
".",
"getInputStream",
"(",
"ze",
")",
";",
"byte",
"[",
"]",
"data",
"=",
"new",
"byte",
"[",
"(",
"int",
")",
"ze",
".",
"getSize",
"(",
")",
"]",
";",
"DataInputStream",
"dataIs",
"=",
"new",
"DataInputStream",
"(",
"fileStream",
")",
";",
"dataIs",
".",
"readFully",
"(",
"data",
")",
";",
"dataIs",
".",
"close",
"(",
")",
";",
"return",
"data",
";",
"}",
"}",
"}",
"throw",
"new",
"FileNotFoundException",
"(",
"\"Could not find resource\"",
")",
";",
"}"
] | Gets a static resource from a plugin
@param pluginName - Name of the plugin(defined in the plugin manifest)
@param fileName - Filename to fetch
@return byte array of the resource
@throws Exception exception | [
"Gets",
"a",
"static",
"resource",
"from",
"a",
"plugin"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/PluginManager.java#L640-L677 |
164,914 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/HostsFileUtils.java | HostsFileUtils.changeHost | public static boolean changeHost(String hostName,
boolean enable,
boolean disable,
boolean remove,
boolean isEnabled,
boolean exists) throws Exception {
// Open the file that is the first
// command line parameter
File hostsFile = new File("/etc/hosts");
FileInputStream fstream = new FileInputStream("/etc/hosts");
File outFile = null;
BufferedWriter bw = null;
// only do file output for destructive operations
if (!exists && !isEnabled) {
outFile = File.createTempFile("HostsEdit", ".tmp");
bw = new BufferedWriter(new FileWriter(outFile));
System.out.println("File name: " + outFile.getPath());
}
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
boolean foundHost = false;
boolean hostEnabled = false;
/*
* Group 1 - possible commented out host entry
* Group 2 - destination address
* Group 3 - host name
* Group 4 - everything else
*/
Pattern pattern = Pattern.compile("\\s*(#?)\\s*([^\\s]+)\\s*([^\\s]+)(.*)");
while ((strLine = br.readLine()) != null) {
Matcher matcher = pattern.matcher(strLine);
// if there is a match to the pattern and the host name is the same as the one we want to set
if (matcher.find() &&
matcher.group(3).toLowerCase().compareTo(hostName.toLowerCase()) == 0) {
foundHost = true;
if (remove) {
// skip this line altogether
continue;
} else if (enable) {
// we will disregard group 2 and just set it to 127.0.0.1
if (!exists && !isEnabled)
bw.write("127.0.0.1 " + matcher.group(3) + matcher.group(4));
} else if (disable) {
if (!exists && !isEnabled)
bw.write("# " + matcher.group(2) + " " + matcher.group(3) + matcher.group(4));
} else if (isEnabled && matcher.group(1).compareTo("") == 0) {
// host exists and there is no # before it
hostEnabled = true;
}
} else {
// just write the line back out
if (!exists && !isEnabled)
bw.write(strLine);
}
if (!exists && !isEnabled)
bw.write('\n');
}
// if we didn't find the host in the file but need to enable it
if (!foundHost && enable) {
// write a new host entry
if (!exists && !isEnabled)
bw.write("127.0.0.1 " + hostName + '\n');
}
// Close the input stream
in.close();
if (!exists && !isEnabled) {
bw.close();
outFile.renameTo(hostsFile);
}
// return false if the host wasn't found
if (exists && !foundHost)
return false;
// return false if the host wasn't enabled
if (isEnabled && !hostEnabled)
return false;
return true;
} | java | public static boolean changeHost(String hostName,
boolean enable,
boolean disable,
boolean remove,
boolean isEnabled,
boolean exists) throws Exception {
// Open the file that is the first
// command line parameter
File hostsFile = new File("/etc/hosts");
FileInputStream fstream = new FileInputStream("/etc/hosts");
File outFile = null;
BufferedWriter bw = null;
// only do file output for destructive operations
if (!exists && !isEnabled) {
outFile = File.createTempFile("HostsEdit", ".tmp");
bw = new BufferedWriter(new FileWriter(outFile));
System.out.println("File name: " + outFile.getPath());
}
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
boolean foundHost = false;
boolean hostEnabled = false;
/*
* Group 1 - possible commented out host entry
* Group 2 - destination address
* Group 3 - host name
* Group 4 - everything else
*/
Pattern pattern = Pattern.compile("\\s*(#?)\\s*([^\\s]+)\\s*([^\\s]+)(.*)");
while ((strLine = br.readLine()) != null) {
Matcher matcher = pattern.matcher(strLine);
// if there is a match to the pattern and the host name is the same as the one we want to set
if (matcher.find() &&
matcher.group(3).toLowerCase().compareTo(hostName.toLowerCase()) == 0) {
foundHost = true;
if (remove) {
// skip this line altogether
continue;
} else if (enable) {
// we will disregard group 2 and just set it to 127.0.0.1
if (!exists && !isEnabled)
bw.write("127.0.0.1 " + matcher.group(3) + matcher.group(4));
} else if (disable) {
if (!exists && !isEnabled)
bw.write("# " + matcher.group(2) + " " + matcher.group(3) + matcher.group(4));
} else if (isEnabled && matcher.group(1).compareTo("") == 0) {
// host exists and there is no # before it
hostEnabled = true;
}
} else {
// just write the line back out
if (!exists && !isEnabled)
bw.write(strLine);
}
if (!exists && !isEnabled)
bw.write('\n');
}
// if we didn't find the host in the file but need to enable it
if (!foundHost && enable) {
// write a new host entry
if (!exists && !isEnabled)
bw.write("127.0.0.1 " + hostName + '\n');
}
// Close the input stream
in.close();
if (!exists && !isEnabled) {
bw.close();
outFile.renameTo(hostsFile);
}
// return false if the host wasn't found
if (exists && !foundHost)
return false;
// return false if the host wasn't enabled
if (isEnabled && !hostEnabled)
return false;
return true;
} | [
"public",
"static",
"boolean",
"changeHost",
"(",
"String",
"hostName",
",",
"boolean",
"enable",
",",
"boolean",
"disable",
",",
"boolean",
"remove",
",",
"boolean",
"isEnabled",
",",
"boolean",
"exists",
")",
"throws",
"Exception",
"{",
"// Open the file that is the first",
"// command line parameter",
"File",
"hostsFile",
"=",
"new",
"File",
"(",
"\"/etc/hosts\"",
")",
";",
"FileInputStream",
"fstream",
"=",
"new",
"FileInputStream",
"(",
"\"/etc/hosts\"",
")",
";",
"File",
"outFile",
"=",
"null",
";",
"BufferedWriter",
"bw",
"=",
"null",
";",
"// only do file output for destructive operations",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"{",
"outFile",
"=",
"File",
".",
"createTempFile",
"(",
"\"HostsEdit\"",
",",
"\".tmp\"",
")",
";",
"bw",
"=",
"new",
"BufferedWriter",
"(",
"new",
"FileWriter",
"(",
"outFile",
")",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"\"File name: \"",
"+",
"outFile",
".",
"getPath",
"(",
")",
")",
";",
"}",
"// Get the object of DataInputStream",
"DataInputStream",
"in",
"=",
"new",
"DataInputStream",
"(",
"fstream",
")",
";",
"BufferedReader",
"br",
"=",
"new",
"BufferedReader",
"(",
"new",
"InputStreamReader",
"(",
"in",
")",
")",
";",
"String",
"strLine",
";",
"boolean",
"foundHost",
"=",
"false",
";",
"boolean",
"hostEnabled",
"=",
"false",
";",
"/*\n * Group 1 - possible commented out host entry\n\t\t * Group 2 - destination address\n\t\t * Group 3 - host name\n\t\t * Group 4 - everything else\n\t\t */",
"Pattern",
"pattern",
"=",
"Pattern",
".",
"compile",
"(",
"\"\\\\s*(#?)\\\\s*([^\\\\s]+)\\\\s*([^\\\\s]+)(.*)\"",
")",
";",
"while",
"(",
"(",
"strLine",
"=",
"br",
".",
"readLine",
"(",
")",
")",
"!=",
"null",
")",
"{",
"Matcher",
"matcher",
"=",
"pattern",
".",
"matcher",
"(",
"strLine",
")",
";",
"// if there is a match to the pattern and the host name is the same as the one we want to set",
"if",
"(",
"matcher",
".",
"find",
"(",
")",
"&&",
"matcher",
".",
"group",
"(",
"3",
")",
".",
"toLowerCase",
"(",
")",
".",
"compareTo",
"(",
"hostName",
".",
"toLowerCase",
"(",
")",
")",
"==",
"0",
")",
"{",
"foundHost",
"=",
"true",
";",
"if",
"(",
"remove",
")",
"{",
"// skip this line altogether",
"continue",
";",
"}",
"else",
"if",
"(",
"enable",
")",
"{",
"// we will disregard group 2 and just set it to 127.0.0.1",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"bw",
".",
"write",
"(",
"\"127.0.0.1 \"",
"+",
"matcher",
".",
"group",
"(",
"3",
")",
"+",
"matcher",
".",
"group",
"(",
"4",
")",
")",
";",
"}",
"else",
"if",
"(",
"disable",
")",
"{",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"bw",
".",
"write",
"(",
"\"# \"",
"+",
"matcher",
".",
"group",
"(",
"2",
")",
"+",
"\" \"",
"+",
"matcher",
".",
"group",
"(",
"3",
")",
"+",
"matcher",
".",
"group",
"(",
"4",
")",
")",
";",
"}",
"else",
"if",
"(",
"isEnabled",
"&&",
"matcher",
".",
"group",
"(",
"1",
")",
".",
"compareTo",
"(",
"\"\"",
")",
"==",
"0",
")",
"{",
"// host exists and there is no # before it",
"hostEnabled",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"// just write the line back out",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"bw",
".",
"write",
"(",
"strLine",
")",
";",
"}",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"bw",
".",
"write",
"(",
"'",
"'",
")",
";",
"}",
"// if we didn't find the host in the file but need to enable it",
"if",
"(",
"!",
"foundHost",
"&&",
"enable",
")",
"{",
"// write a new host entry",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"bw",
".",
"write",
"(",
"\"127.0.0.1 \"",
"+",
"hostName",
"+",
"'",
"'",
")",
";",
"}",
"// Close the input stream",
"in",
".",
"close",
"(",
")",
";",
"if",
"(",
"!",
"exists",
"&&",
"!",
"isEnabled",
")",
"{",
"bw",
".",
"close",
"(",
")",
";",
"outFile",
".",
"renameTo",
"(",
"hostsFile",
")",
";",
"}",
"// return false if the host wasn't found",
"if",
"(",
"exists",
"&&",
"!",
"foundHost",
")",
"return",
"false",
";",
"// return false if the host wasn't enabled",
"if",
"(",
"isEnabled",
"&&",
"!",
"hostEnabled",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Only one boolean param should be true at a time for this function to return the proper results
@param hostName
@param enable
@param disable
@param remove
@param isEnabled
@param exists
@return
@throws Exception | [
"Only",
"one",
"boolean",
"param",
"should",
"be",
"true",
"at",
"a",
"time",
"for",
"this",
"function",
"to",
"return",
"the",
"proper",
"results"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/HostsFileUtils.java#L74-L164 |
164,915 | groupon/odo | proxyplugin/src/main/java/com/groupon/odo/plugin/PluginHelper.java | PluginHelper.getByteArrayDataAsString | public static String getByteArrayDataAsString(String contentEncoding, byte[] bytes) {
ByteArrayOutputStream byteout = null;
if (contentEncoding != null &&
contentEncoding.equals("gzip")) {
// GZIP
ByteArrayInputStream bytein = null;
GZIPInputStream zis = null;
try {
bytein = new ByteArrayInputStream(bytes);
zis = new GZIPInputStream(bytein);
byteout = new ByteArrayOutputStream();
int res = 0;
byte buf[] = new byte[1024];
while (res >= 0) {
res = zis.read(buf, 0, buf.length);
if (res > 0) {
byteout.write(buf, 0, res);
}
}
zis.close();
bytein.close();
byteout.close();
return byteout.toString();
} catch (Exception e) {
// No action to take
}
} else if (contentEncoding != null &&
contentEncoding.equals("deflate")) {
try {
// DEFLATE
byte[] buffer = new byte[1024];
Inflater decompresser = new Inflater();
byteout = new ByteArrayOutputStream();
decompresser.setInput(bytes);
while (!decompresser.finished()) {
int count = decompresser.inflate(buffer);
byteout.write(buffer, 0, count);
}
byteout.close();
decompresser.end();
return byteout.toString();
} catch (Exception e) {
// No action to take
}
}
return new String(bytes);
} | java | public static String getByteArrayDataAsString(String contentEncoding, byte[] bytes) {
ByteArrayOutputStream byteout = null;
if (contentEncoding != null &&
contentEncoding.equals("gzip")) {
// GZIP
ByteArrayInputStream bytein = null;
GZIPInputStream zis = null;
try {
bytein = new ByteArrayInputStream(bytes);
zis = new GZIPInputStream(bytein);
byteout = new ByteArrayOutputStream();
int res = 0;
byte buf[] = new byte[1024];
while (res >= 0) {
res = zis.read(buf, 0, buf.length);
if (res > 0) {
byteout.write(buf, 0, res);
}
}
zis.close();
bytein.close();
byteout.close();
return byteout.toString();
} catch (Exception e) {
// No action to take
}
} else if (contentEncoding != null &&
contentEncoding.equals("deflate")) {
try {
// DEFLATE
byte[] buffer = new byte[1024];
Inflater decompresser = new Inflater();
byteout = new ByteArrayOutputStream();
decompresser.setInput(bytes);
while (!decompresser.finished()) {
int count = decompresser.inflate(buffer);
byteout.write(buffer, 0, count);
}
byteout.close();
decompresser.end();
return byteout.toString();
} catch (Exception e) {
// No action to take
}
}
return new String(bytes);
} | [
"public",
"static",
"String",
"getByteArrayDataAsString",
"(",
"String",
"contentEncoding",
",",
"byte",
"[",
"]",
"bytes",
")",
"{",
"ByteArrayOutputStream",
"byteout",
"=",
"null",
";",
"if",
"(",
"contentEncoding",
"!=",
"null",
"&&",
"contentEncoding",
".",
"equals",
"(",
"\"gzip\"",
")",
")",
"{",
"// GZIP",
"ByteArrayInputStream",
"bytein",
"=",
"null",
";",
"GZIPInputStream",
"zis",
"=",
"null",
";",
"try",
"{",
"bytein",
"=",
"new",
"ByteArrayInputStream",
"(",
"bytes",
")",
";",
"zis",
"=",
"new",
"GZIPInputStream",
"(",
"bytein",
")",
";",
"byteout",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"int",
"res",
"=",
"0",
";",
"byte",
"buf",
"[",
"]",
"=",
"new",
"byte",
"[",
"1024",
"]",
";",
"while",
"(",
"res",
">=",
"0",
")",
"{",
"res",
"=",
"zis",
".",
"read",
"(",
"buf",
",",
"0",
",",
"buf",
".",
"length",
")",
";",
"if",
"(",
"res",
">",
"0",
")",
"{",
"byteout",
".",
"write",
"(",
"buf",
",",
"0",
",",
"res",
")",
";",
"}",
"}",
"zis",
".",
"close",
"(",
")",
";",
"bytein",
".",
"close",
"(",
")",
";",
"byteout",
".",
"close",
"(",
")",
";",
"return",
"byteout",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// No action to take",
"}",
"}",
"else",
"if",
"(",
"contentEncoding",
"!=",
"null",
"&&",
"contentEncoding",
".",
"equals",
"(",
"\"deflate\"",
")",
")",
"{",
"try",
"{",
"// DEFLATE",
"byte",
"[",
"]",
"buffer",
"=",
"new",
"byte",
"[",
"1024",
"]",
";",
"Inflater",
"decompresser",
"=",
"new",
"Inflater",
"(",
")",
";",
"byteout",
"=",
"new",
"ByteArrayOutputStream",
"(",
")",
";",
"decompresser",
".",
"setInput",
"(",
"bytes",
")",
";",
"while",
"(",
"!",
"decompresser",
".",
"finished",
"(",
")",
")",
"{",
"int",
"count",
"=",
"decompresser",
".",
"inflate",
"(",
"buffer",
")",
";",
"byteout",
".",
"write",
"(",
"buffer",
",",
"0",
",",
"count",
")",
";",
"}",
"byteout",
".",
"close",
"(",
")",
";",
"decompresser",
".",
"end",
"(",
")",
";",
"return",
"byteout",
".",
"toString",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"// No action to take",
"}",
"}",
"return",
"new",
"String",
"(",
"bytes",
")",
";",
"}"
] | Decodes stream data based on content encoding
@param contentEncoding
@param bytes
@return String representing the stream data | [
"Decodes",
"stream",
"data",
"based",
"on",
"content",
"encoding"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyplugin/src/main/java/com/groupon/odo/plugin/PluginHelper.java#L137-L187 |
164,916 | groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/BackupController.java | BackupController.getBackup | @SuppressWarnings("deprecation")
@RequestMapping(value = "/api/backup", method = RequestMethod.GET)
public
@ResponseBody
String getBackup(Model model, HttpServletResponse response) throws Exception {
response.addHeader("Content-Disposition", "attachment; filename=backup.json");
response.setContentType("application/json");
Backup backup = BackupService.getInstance().getBackupData();
ObjectMapper objectMapper = new ObjectMapper();
ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
return writer.withView(ViewFilters.Default.class).writeValueAsString(backup);
} | java | @SuppressWarnings("deprecation")
@RequestMapping(value = "/api/backup", method = RequestMethod.GET)
public
@ResponseBody
String getBackup(Model model, HttpServletResponse response) throws Exception {
response.addHeader("Content-Disposition", "attachment; filename=backup.json");
response.setContentType("application/json");
Backup backup = BackupService.getInstance().getBackupData();
ObjectMapper objectMapper = new ObjectMapper();
ObjectWriter writer = objectMapper.writerWithDefaultPrettyPrinter();
return writer.withView(ViewFilters.Default.class).writeValueAsString(backup);
} | [
"@",
"SuppressWarnings",
"(",
"\"deprecation\"",
")",
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/backup\"",
",",
"method",
"=",
"RequestMethod",
".",
"GET",
")",
"public",
"@",
"ResponseBody",
"String",
"getBackup",
"(",
"Model",
"model",
",",
"HttpServletResponse",
"response",
")",
"throws",
"Exception",
"{",
"response",
".",
"addHeader",
"(",
"\"Content-Disposition\"",
",",
"\"attachment; filename=backup.json\"",
")",
";",
"response",
".",
"setContentType",
"(",
"\"application/json\"",
")",
";",
"Backup",
"backup",
"=",
"BackupService",
".",
"getInstance",
"(",
")",
".",
"getBackupData",
"(",
")",
";",
"ObjectMapper",
"objectMapper",
"=",
"new",
"ObjectMapper",
"(",
")",
";",
"ObjectWriter",
"writer",
"=",
"objectMapper",
".",
"writerWithDefaultPrettyPrinter",
"(",
")",
";",
"return",
"writer",
".",
"withView",
"(",
"ViewFilters",
".",
"Default",
".",
"class",
")",
".",
"writeValueAsString",
"(",
"backup",
")",
";",
"}"
] | Get all backup data
@param model
@return
@throws Exception | [
"Get",
"all",
"backup",
"data"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/BackupController.java#L64-L77 |
164,917 | groupon/odo | proxyui/src/main/java/com/groupon/odo/controllers/BackupController.java | BackupController.processBackup | @RequestMapping(value = "/api/backup", method = RequestMethod.POST)
public
@ResponseBody
Backup processBackup(@RequestParam("fileData") MultipartFile fileData) throws Exception {
// Method taken from: http://spring.io/guides/gs/uploading-files/
if (!fileData.isEmpty()) {
try {
byte[] bytes = fileData.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File("backup-uploaded.json")));
stream.write(bytes);
stream.close();
} catch (Exception e) {
}
}
File f = new File("backup-uploaded.json");
BackupService.getInstance().restoreBackupData(new FileInputStream(f));
return BackupService.getInstance().getBackupData();
} | java | @RequestMapping(value = "/api/backup", method = RequestMethod.POST)
public
@ResponseBody
Backup processBackup(@RequestParam("fileData") MultipartFile fileData) throws Exception {
// Method taken from: http://spring.io/guides/gs/uploading-files/
if (!fileData.isEmpty()) {
try {
byte[] bytes = fileData.getBytes();
BufferedOutputStream stream =
new BufferedOutputStream(new FileOutputStream(new File("backup-uploaded.json")));
stream.write(bytes);
stream.close();
} catch (Exception e) {
}
}
File f = new File("backup-uploaded.json");
BackupService.getInstance().restoreBackupData(new FileInputStream(f));
return BackupService.getInstance().getBackupData();
} | [
"@",
"RequestMapping",
"(",
"value",
"=",
"\"/api/backup\"",
",",
"method",
"=",
"RequestMethod",
".",
"POST",
")",
"public",
"@",
"ResponseBody",
"Backup",
"processBackup",
"(",
"@",
"RequestParam",
"(",
"\"fileData\"",
")",
"MultipartFile",
"fileData",
")",
"throws",
"Exception",
"{",
"// Method taken from: http://spring.io/guides/gs/uploading-files/",
"if",
"(",
"!",
"fileData",
".",
"isEmpty",
"(",
")",
")",
"{",
"try",
"{",
"byte",
"[",
"]",
"bytes",
"=",
"fileData",
".",
"getBytes",
"(",
")",
";",
"BufferedOutputStream",
"stream",
"=",
"new",
"BufferedOutputStream",
"(",
"new",
"FileOutputStream",
"(",
"new",
"File",
"(",
"\"backup-uploaded.json\"",
")",
")",
")",
";",
"stream",
".",
"write",
"(",
"bytes",
")",
";",
"stream",
".",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"}",
"}",
"File",
"f",
"=",
"new",
"File",
"(",
"\"backup-uploaded.json\"",
")",
";",
"BackupService",
".",
"getInstance",
"(",
")",
".",
"restoreBackupData",
"(",
"new",
"FileInputStream",
"(",
"f",
")",
")",
";",
"return",
"BackupService",
".",
"getInstance",
"(",
")",
".",
"getBackupData",
"(",
")",
";",
"}"
] | Restore backup data
@param fileData - json file with restore data
@return
@throws Exception | [
"Restore",
"backup",
"data"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxyui/src/main/java/com/groupon/odo/controllers/BackupController.java#L86-L105 |
164,918 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/rmi/Client.java | Client.enableHost | public static void enableHost(String hostName) throws Exception {
Registry myRegistry = LocateRegistry.getRegistry("127.0.0.1", port);
com.groupon.odo.proxylib.hostsedit.rmi.Message impl = (com.groupon.odo.proxylib.hostsedit.rmi.Message) myRegistry.lookup(SERVICE_NAME);
impl.enableHost(hostName);
} | java | public static void enableHost(String hostName) throws Exception {
Registry myRegistry = LocateRegistry.getRegistry("127.0.0.1", port);
com.groupon.odo.proxylib.hostsedit.rmi.Message impl = (com.groupon.odo.proxylib.hostsedit.rmi.Message) myRegistry.lookup(SERVICE_NAME);
impl.enableHost(hostName);
} | [
"public",
"static",
"void",
"enableHost",
"(",
"String",
"hostName",
")",
"throws",
"Exception",
"{",
"Registry",
"myRegistry",
"=",
"LocateRegistry",
".",
"getRegistry",
"(",
"\"127.0.0.1\"",
",",
"port",
")",
";",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"hostsedit",
".",
"rmi",
".",
"Message",
"impl",
"=",
"(",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"hostsedit",
".",
"rmi",
".",
"Message",
")",
"myRegistry",
".",
"lookup",
"(",
"SERVICE_NAME",
")",
";",
"impl",
".",
"enableHost",
"(",
"hostName",
")",
";",
"}"
] | Enable a host
@param hostName
@throws Exception | [
"Enable",
"a",
"host"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/rmi/Client.java#L33-L38 |
164,919 | groupon/odo | proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/rmi/Client.java | Client.isAvailable | public static boolean isAvailable() throws Exception {
try {
Registry myRegistry = LocateRegistry.getRegistry("127.0.0.1", port);
com.groupon.odo.proxylib.hostsedit.rmi.Message impl = (com.groupon.odo.proxylib.hostsedit.rmi.Message) myRegistry.lookup(SERVICE_NAME);
return true;
} catch (Exception e) {
return false;
}
} | java | public static boolean isAvailable() throws Exception {
try {
Registry myRegistry = LocateRegistry.getRegistry("127.0.0.1", port);
com.groupon.odo.proxylib.hostsedit.rmi.Message impl = (com.groupon.odo.proxylib.hostsedit.rmi.Message) myRegistry.lookup(SERVICE_NAME);
return true;
} catch (Exception e) {
return false;
}
} | [
"public",
"static",
"boolean",
"isAvailable",
"(",
")",
"throws",
"Exception",
"{",
"try",
"{",
"Registry",
"myRegistry",
"=",
"LocateRegistry",
".",
"getRegistry",
"(",
"\"127.0.0.1\"",
",",
"port",
")",
";",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"hostsedit",
".",
"rmi",
".",
"Message",
"impl",
"=",
"(",
"com",
".",
"groupon",
".",
"odo",
".",
"proxylib",
".",
"hostsedit",
".",
"rmi",
".",
"Message",
")",
"myRegistry",
".",
"lookup",
"(",
"SERVICE_NAME",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns whether or not the host editor service is available
@return
@throws Exception | [
"Returns",
"whether",
"or",
"not",
"the",
"host",
"editor",
"service",
"is",
"available"
] | 3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1 | https://github.com/groupon/odo/blob/3bae43d5eca8ace036775e5b2d3ed9af1a9ff9b1/proxylib/src/main/java/com/groupon/odo/proxylib/hostsedit/rmi/Client.java#L100-L108 |
164,920 | javalite/activeweb | activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java | FreeMarkerTag.getContextPath | protected String getContextPath(){
if(context != null) return context;
if(get("context_path") == null){
throw new ViewException("context_path missing - red alarm!");
}
return get("context_path").toString();
} | java | protected String getContextPath(){
if(context != null) return context;
if(get("context_path") == null){
throw new ViewException("context_path missing - red alarm!");
}
return get("context_path").toString();
} | [
"protected",
"String",
"getContextPath",
"(",
")",
"{",
"if",
"(",
"context",
"!=",
"null",
")",
"return",
"context",
";",
"if",
"(",
"get",
"(",
"\"context_path\"",
")",
"==",
"null",
")",
"{",
"throw",
"new",
"ViewException",
"(",
"\"context_path missing - red alarm!\"",
")",
";",
"}",
"return",
"get",
"(",
"\"context_path\"",
")",
".",
"toString",
"(",
")",
";",
"}"
] | Returns this applications' context path.
@return context path. | [
"Returns",
"this",
"applications",
"context",
"path",
"."
] | f25f589da94852b6f5625182360732e0861794a6 | https://github.com/javalite/activeweb/blob/f25f589da94852b6f5625182360732e0861794a6/activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java#L122-L130 |
164,921 | javalite/activeweb | activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java | FreeMarkerTag.process | protected void process(String text, Map params, Writer writer){
try{
Template t = new Template("temp", new StringReader(text), FreeMarkerTL.getEnvironment().getConfiguration());
t.process(params, writer);
}catch(Exception e){
throw new ViewException(e);
}
} | java | protected void process(String text, Map params, Writer writer){
try{
Template t = new Template("temp", new StringReader(text), FreeMarkerTL.getEnvironment().getConfiguration());
t.process(params, writer);
}catch(Exception e){
throw new ViewException(e);
}
} | [
"protected",
"void",
"process",
"(",
"String",
"text",
",",
"Map",
"params",
",",
"Writer",
"writer",
")",
"{",
"try",
"{",
"Template",
"t",
"=",
"new",
"Template",
"(",
"\"temp\"",
",",
"new",
"StringReader",
"(",
"text",
")",
",",
"FreeMarkerTL",
".",
"getEnvironment",
"(",
")",
".",
"getConfiguration",
"(",
")",
")",
";",
"t",
".",
"process",
"(",
"params",
",",
"writer",
")",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"ViewException",
"(",
"e",
")",
";",
"}",
"}"
] | Processes text as a FreeMarker template. Usually used to process an inner body of a tag.
@param text text of a template.
@param params map with parameters for processing.
@param writer writer to write output to. | [
"Processes",
"text",
"as",
"a",
"FreeMarker",
"template",
".",
"Usually",
"used",
"to",
"process",
"an",
"inner",
"body",
"of",
"a",
"tag",
"."
] | f25f589da94852b6f5625182360732e0861794a6 | https://github.com/javalite/activeweb/blob/f25f589da94852b6f5625182360732e0861794a6/activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java#L140-L148 |
164,922 | javalite/activeweb | activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java | FreeMarkerTag.getAllVariables | protected Map getAllVariables(){
try{
Iterator names = FreeMarkerTL.getEnvironment().getKnownVariableNames().iterator();
Map vars = new HashMap();
while (names.hasNext()) {
Object name =names.next();
vars.put(name, get(name.toString()));
}
return vars;
}catch(Exception e){
throw new ViewException(e);
}
} | java | protected Map getAllVariables(){
try{
Iterator names = FreeMarkerTL.getEnvironment().getKnownVariableNames().iterator();
Map vars = new HashMap();
while (names.hasNext()) {
Object name =names.next();
vars.put(name, get(name.toString()));
}
return vars;
}catch(Exception e){
throw new ViewException(e);
}
} | [
"protected",
"Map",
"getAllVariables",
"(",
")",
"{",
"try",
"{",
"Iterator",
"names",
"=",
"FreeMarkerTL",
".",
"getEnvironment",
"(",
")",
".",
"getKnownVariableNames",
"(",
")",
".",
"iterator",
"(",
")",
";",
"Map",
"vars",
"=",
"new",
"HashMap",
"(",
")",
";",
"while",
"(",
"names",
".",
"hasNext",
"(",
")",
")",
"{",
"Object",
"name",
"=",
"names",
".",
"next",
"(",
")",
";",
"vars",
".",
"put",
"(",
"name",
",",
"get",
"(",
"name",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"return",
"vars",
";",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"throw",
"new",
"ViewException",
"(",
"e",
")",
";",
"}",
"}"
] | Returns a map of all variables in scope.
@return map of all variables in scope. | [
"Returns",
"a",
"map",
"of",
"all",
"variables",
"in",
"scope",
"."
] | f25f589da94852b6f5625182360732e0861794a6 | https://github.com/javalite/activeweb/blob/f25f589da94852b6f5625182360732e0861794a6/activeweb/src/main/java/org/javalite/activeweb/freemarker/FreeMarkerTag.java#L154-L166 |