Search in sources :

Example 1 with AILibraryHandler

use of com.microsoft.intellij.ui.libraries.AILibraryHandler in project azure-tools-for-java by Microsoft.

the class AzurePlugin method initializeAIRegistry.

private void initializeAIRegistry() {
    try {
        AzureSettings.getSafeInstance(myProject).loadAppInsights();
        Module[] modules = ModuleManager.getInstance(myProject).getModules();
        for (Module module : modules) {
            if (module != null && module.isLoaded() && ModuleTypeId.JAVA_MODULE.equals(module.getOptionValue(Module.ELEMENT_TYPE))) {
                String aiXMLPath = String.format("%s%s%s", PluginUtil.getModulePath(module), File.separator, message("aiXMLPath"));
                if (new File(aiXMLPath).exists()) {
                    AILibraryHandler handler = new AILibraryHandler();
                    handler.parseAIConfXmlPath(aiXMLPath);
                    String key = handler.getAIInstrumentationKey();
                    if (key != null && !key.isEmpty()) {
                        String unknown = message("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);
                        }
                    }
                }
            }
        }
        AzureSettings.getSafeInstance(myProject).saveAppInsights();
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage(), ex);
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) Module(com.intellij.openapi.module.Module) AILibraryHandler(com.microsoft.intellij.ui.libraries.AILibraryHandler)

Example 2 with AILibraryHandler

use of com.microsoft.intellij.ui.libraries.AILibraryHandler in project azure-tools-for-java by Microsoft.

the class MethodUtils method getModuleNameAsPerKey.

/**
 * Method scans all open Maven or Dynamic web projects form workspace
 * and returns name of project who is using specific key.
 * @return
 */
public static String getModuleNameAsPerKey(Project project, String keyToRemove) {
    String name = "";
    try {
        Module[] modules = ModuleManager.getInstance(project).getModules();
        for (Module module : modules) {
            if (module != null && module.isLoaded() && ModuleTypeId.JAVA_MODULE.equals(module.getOptionValue(Module.ELEMENT_TYPE))) {
                String aiXMLPath = String.format("%s%s%s", PluginUtil.getModulePath(module), File.separator, message("aiXMLPath"));
                String webXMLPath = String.format("%s%s%s", PluginUtil.getModulePath(module), File.separator, message("xmlPath"));
                AILibraryHandler handler = new AILibraryHandler();
                if (new File(aiXMLPath).exists() && new File(webXMLPath).exists()) {
                    handler.parseWebXmlPath(webXMLPath);
                    handler.parseAIConfXmlPath(aiXMLPath);
                    // if application insights configuration is enabled.
                    if (handler.isAIWebFilterConfigured()) {
                        String key = handler.getAIInstrumentationKey();
                        if (key != null && !key.isEmpty() && key.equals(keyToRemove)) {
                            return module.getName();
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        AzurePlugin.log(ex.getMessage(), ex);
    }
    return name;
}
Also used : Module(com.intellij.openapi.module.Module) File(java.io.File) AILibraryHandler(com.microsoft.intellij.ui.libraries.AILibraryHandler)

Example 3 with AILibraryHandler

use of com.microsoft.intellij.ui.libraries.AILibraryHandler in project azure-tools-for-java by Microsoft.

the class AzurePlugin method initializeAIRegistry.

private void initializeAIRegistry(Project myProject) {
    try {
        AzureSettings.getSafeInstance(myProject).loadAppInsights();
        Module[] modules = ModuleManager.getInstance(myProject).getModules();
        for (Module module : modules) {
            if (module != null && module.isLoaded() && ModuleTypeId.JAVA_MODULE.equals(module.getOptionValue(Module.ELEMENT_TYPE))) {
                String aiXMLPath = String.format("%s%s%s", PluginUtil.getModulePath(module), File.separator, message("aiXMLPath"));
                if (new File(aiXMLPath).exists()) {
                    AILibraryHandler handler = new AILibraryHandler();
                    handler.parseAIConfXmlPath(aiXMLPath);
                    String key = handler.getAIInstrumentationKey();
                    if (key != null && !key.isEmpty()) {
                        String unknown = message("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);
                        }
                    }
                }
            }
        }
        AzureSettings.getSafeInstance(myProject).saveAppInsights();
    } catch (Exception ex) {
        // should ignore ProcessCanceledException
        if (Objects.isNull(ExceptionUtil.findCause(ex, ProcessCanceledException.class))) {
            AzurePlugin.log(ex.getMessage(), ex);
        }
    }
}
Also used : ApplicationInsightsResource(com.microsoft.applicationinsights.preference.ApplicationInsightsResource) Module(com.intellij.openapi.module.Module) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) IOException(java.io.IOException) AILibraryHandler(com.microsoft.intellij.ui.libraries.AILibraryHandler)

Aggregations

Module (com.intellij.openapi.module.Module)3 AILibraryHandler (com.microsoft.intellij.ui.libraries.AILibraryHandler)3 ApplicationInsightsResource (com.microsoft.applicationinsights.preference.ApplicationInsightsResource)2 File (java.io.File)2 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1