Search in sources :

Example 1 with AILibraryHandler

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);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) CoreException(org.eclipse.core.runtime.CoreException) AILibraryHandler(com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)

Example 2 with AILibraryHandler

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) AILibraryHandler(com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)

Aggregations

AILibraryHandler (com.microsoft.azuretools.core.applicationinsights.AILibraryHandler)2 CoreException (org.eclipse.core.runtime.CoreException)2 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1