use of com.microsoft.azuretools.core.applicationinsights.AILibraryHandler in project azure-tools-for-java by Microsoft.
the class AIResourceChangeListener method initializeAIRegistry.
/**
* initializeAIRegistry.
*/
public static void initializeAIRegistry(IProject iproject) {
try {
if (iproject.isOpen() && WebPropertyTester.isWebProj(iproject)) {
String aiXMLPath;
if (iproject.hasNature(Messages.natMaven)) {
aiXMLPath = Messages.aiXMLPathMaven;
} else {
aiXMLPath = Messages.aiXMLPath;
}
AILibraryHandler handler = new AILibraryHandler();
/*
* If ApplicationInsights.xml does not exits, then application insights might not have been configured.
* It will thrown FNF exception in that case, just catch it and log. Note : file.exists() check is not
* useful in this case as during project import generally file.exists() return false.
*/
handler.parseAIConfXmlPath(iproject.getFile(aiXMLPath).getLocation().toOSString());
String key = handler.getAIInstrumentationKey();
if (key != null && !key.isEmpty()) {
String unknown = com.microsoft.applicationinsights.preference.Messages.unknown;
List<ApplicationInsightsResource> list = ApplicationInsightsResourceRegistry.getAppInsightsResrcList();
ApplicationInsightsResource resourceToAdd = new ApplicationInsightsResource(key, key, unknown, unknown, unknown, unknown, false);
if (!list.contains(resourceToAdd)) {
ApplicationInsightsResourceRegistry.getAppInsightsResrcList().add(resourceToAdd);
}
}
}
} catch (Exception ex) {
Activator.getDefault().log(Messages.resChangeErr);
}
}
use of com.microsoft.azuretools.core.applicationinsights.AILibraryHandler in project azure-tools-for-java by Microsoft.
the class AIResourceChangeListener method getProjectNameAsPerKey.
/**
* Method scans all open Maven or Dynamic web projects form workspace and returns name of project who is using
* specific key.
*/
public static String getProjectNameAsPerKey(String keyToRemove) {
String name = "";
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = workspace.getRoot();
for (IProject iproject : root.getProjects()) {
if (iproject.isOpen() && WebPropertyTester.isWebProj(iproject)) {
String aiXMLPath;
String webXMLPath;
if (iproject.hasNature(Messages.natMaven)) {
aiXMLPath = Messages.aiXMLPathMaven;
webXMLPath = Messages.webxmlPathMaven;
} else {
aiXMLPath = Messages.aiXMLPath;
webXMLPath = Messages.webxmlPath;
}
AILibraryHandler handler = new AILibraryHandler();
IFile aiFile = iproject.getFile(aiXMLPath);
IFile webFile = iproject.getFile(webXMLPath);
if (aiFile.exists() && webFile.exists()) {
handler.parseWebXmlPath(webFile.getLocation().toOSString());
handler.parseAIConfXmlPath(aiFile.getLocation().toOSString());
// if application insights configuration is enabled.
if (handler.isAIWebFilterConfigured()) {
String key = handler.getAIInstrumentationKey();
if (key != null && !key.isEmpty() && key.equals(keyToRemove)) {
return iproject.getName();
}
}
}
}
}
} catch (Exception ex) {
Activator.getDefault().log(Messages.genKeyListErr, ex);
}
return name;
}
Aggregations