Search in sources :

Example 16 with Nullable

use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.

the class ContainerRegistryPropertyViewPresenter method parseLinkHeader.

@Nullable
private String parseLinkHeader(@NotNull String header) {
    int start = header.indexOf("<") + 1;
    int end = header.lastIndexOf(">");
    if (start <= 0 || end < 0 || end >= header.length() || start >= end) {
        return null;
    }
    HttpUrl url = HttpUrl.parse(FAKE_URL + header.substring(start, end));
    if (url == null) {
        return null;
    }
    return url.queryParameter(KEY_LAST);
}
Also used : HttpUrl(okhttp3.HttpUrl) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 17 with Nullable

use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.

the class FunctionUtils method createTempleHostJson.

@Nullable
public static Path createTempleHostJson() {
    try {
        final File result = File.createTempFile("host", ".json");
        FileUtils.write(result, DEFAULT_HOST_JSON, Charset.defaultCharset());
        return result.toPath();
    } catch (final IOException e) {
        return null;
    }
}
Also used : IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 18 with Nullable

use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.

the class ManifestFileUtilsEx method selectMainClass.

@Nullable
public PsiClass selectMainClass(@Nullable VirtualFile jarFile) {
    if (jarFile == null) {
        return null;
    }
    final TreeClassChooserFactory chooserFactory = TreeClassChooserFactory.getInstance(myProject);
    final GlobalSearchScope searchScope = GlobalSearchScope.everythingScope(myProject);
    // TODO: the following code is used to find initialClassName in the jar. When user specified initialClassName
    // in the main-class-selection textfield and clicked the main-class-selection button, the filter result in the dialog
    // should be the initialClass. Currently we don't enable this method since exception happens with the following code.
    // final PsiClass aClass = initialClassName != null ? JavaPsiFacade.getInstance(project).findClass(initialClassName, searchScope) : null;
    final TreeClassChooser chooser = chooserFactory.createWithInnerClassesScopeChooser("Select Main Class", searchScope, new MainClassFilter(jarFile.getPath()), null);
    ((TreeJavaClassChooserDialog) chooser).getWindow().addWindowListener(new WindowAdapter() {

        // These fields are recorded to help remove the artifact and the module.
        @Nullable
        private String localArtifactLibraryName;

        @Nullable
        private String localArtifactModuleName;

        @Override
        public void windowOpened(WindowEvent e) {
            // remove old jar and add new jar to project dependency
            WriteAction.run(() -> addJarToModuleDependency(jarFile));
            super.windowOpened(e);
        }

        @Override
        public void windowClosed(WindowEvent e) {
            WriteAction.run(() -> removeModuleAndJar());
            super.windowClosed(e);
        }

        private void addJarToModuleDependency(@NotNull VirtualFile jarFile) {
            try {
                final Module module = createJarPackingModule();
                final List<OrderRoot> myRoots = RootDetectionUtil.detectRoots(Arrays.asList(jarFile), null, myProject, new DefaultLibraryRootsComponentDescriptor());
                final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
                // find a unique library name in the module
                final String libraryName = LibraryEditingUtil.suggestNewLibraryName(modifiableModel.getModuleLibraryTable().getModifiableModel(), jarFile.getName());
                // add library to the model of the new-created module
                LibrariesContainerFactory.createContainer(modifiableModel).createLibrary(libraryName, LibrariesContainer.LibraryLevel.MODULE, myRoots);
                modifiableModel.commit();
                localArtifactModuleName = module.getName();
                localArtifactLibraryName = libraryName;
            } catch (Exception ex) {
                log().warn(String.format("Failed to add the user selected jar(%s) into module dependency: %s", jarFile.getPath(), ex.toString()));
            }
        }

        private void removeModuleAndJar() {
            assert (localArtifactLibraryName != null && localArtifactModuleName != null) : String.format("Can't get module name or library name. module:%s, library:%s", localArtifactModuleName, localArtifactLibraryName);
            try {
                final Module module = ModuleManager.getInstance(myProject).findModuleByName(localArtifactModuleName);
                // remove library from the model of the module
                final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
                modifiableModel.getModuleLibraryTable().removeLibrary(modifiableModel.getModuleLibraryTable().getLibraryByName(localArtifactLibraryName));
                modifiableModel.commit();
                // remove module from project
                ModuleManager.getInstance(myProject).disposeModule(module);
                localArtifactModuleName = null;
                localArtifactLibraryName = null;
            } catch (Exception ex) {
                log().warn(String.format("Failed to remove jar(%s) from module(%s): %s", localArtifactLibraryName, localArtifactModuleName, ex.toString()));
            }
        }
    });
    chooser.showDialog();
    return chooser.getSelected();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) DefaultLibraryRootsComponentDescriptor(com.intellij.openapi.roots.ui.configuration.libraryEditor.DefaultLibraryRootsComponentDescriptor) WindowAdapter(java.awt.event.WindowAdapter) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) TreeClassChooserFactory(com.intellij.ide.util.TreeClassChooserFactory) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) WindowEvent(java.awt.event.WindowEvent) List(java.util.List) Module(com.intellij.openapi.module.Module) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 19 with Nullable

use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.

the class ADLSGen1HDFSDeploy method getArtifactUploadedPath.

@Override
@Nullable
public String getArtifactUploadedPath(String rootPath) throws URISyntaxException {
    // convert https://xx/webhdfs/v1/hdi-root/SparkSubmission/artifact.jar to adl://xx/hdi-root/SparkSubmission/artifact.jar
    URIBuilder builder = new URIBuilder(rootPath.replace("/webhdfs/v1", ""));
    builder.setScheme(cluster.getStorageAccount().getDefaultStorageSchema());
    return builder.build().toString();
}
Also used : URIBuilder(org.apache.http.client.utils.URIBuilder) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Example 20 with Nullable

use of com.microsoft.azuretools.azurecommons.helpers.Nullable in project azure-tools-for-java by Microsoft.

the class AzureSparkServerlessAccount method getJobManagementURI.

@Nullable
public URI getJobManagementURI() {
    if (getId() == null || subscription.getTenantId() == null) {
        log().warn(String.format("Can't get account ID or tenantID. AccountID:%s, tenantID:%s", getId(), subscription.getTenantId()));
        return null;
    }
    final AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager();
    if (azureManager == null) {
        log().warn("Azure manager is null");
        return null;
    }
    final String url = azureManager.getPortalUrl() + REST_SEGMENT_JOB_MANAGEMENT_TENANTID + subscription.getTenantId() + REST_SEGMENT_JOB_MANAGEMENT_RESOURCE + getId() + REST_SEGMENT_JOB_MANAGEMENT_SUFFIX;
    return URI.create(url);
}
Also used : AzureManager(com.microsoft.azuretools.sdkmanage.AzureManager) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable)

Aggregations

Nullable (com.microsoft.azuretools.azurecommons.helpers.Nullable)22 Project (com.intellij.openapi.project.Project)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ILogger (com.microsoft.azure.hdinsight.common.logger.ILogger)3 NotNull (com.microsoft.azuretools.azurecommons.helpers.NotNull)3 ConsoleView (com.intellij.execution.ui.ConsoleView)2 Module (com.intellij.openapi.module.Module)2 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)2 Azure (com.microsoft.azure.management.Azure)2 Action (com.microsoft.azure.toolkit.lib.common.action.Action)2 ActionView (com.microsoft.azure.toolkit.lib.common.action.ActionView)2 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)2 AzureMessager (com.microsoft.azure.toolkit.lib.common.messager.AzureMessager)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 AzureOperationBundle.title (com.microsoft.azure.toolkit.lib.common.operation.AzureOperationBundle.title)2 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)2 AzureTaskManager (com.microsoft.azure.toolkit.lib.common.task.AzureTaskManager)2