private static void checkPortValue(@Nullable String port, @NotNull String errorMessage) throws RuntimeConfigurationError { if (StringUtil.isNotEmpty(port)) { int intPort = StringUtil.parseInt(port, -1); if (intPort < 0 || intPort > Short.MAX_VALUE * 2) { throw new RuntimeConfigurationError(errorMessage); } } }
@Test public void checkConfiguration_withOutdatedCloudSdkVersion_throwsException() { setUpValidFlexConfiguration(); when(mockSdkValidator.validateCloudSdk()) .thenReturn(ImmutableSet.of(CLOUD_SDK_NOT_MINIMUM_VERSION)); RuntimeConfigurationError error = expectThrows( RuntimeConfigurationError.class, () -> configuration.checkConfiguration( mockRemoteServer, mockAppEngineDeployable, project)); assertThat(error.getMessage()) .contains("Server is misconfigured: The Cloud SDK is out of date."); }
runtimeConfigurationError.printStackTrace();
@Test public void checkConfiguration_withNoAppEngineComponent_throwsException() { setUpValidFlexConfiguration(); when(mockSdkValidator.validateCloudSdk()).thenReturn(ImmutableSet.of(NO_APP_ENGINE_COMPONENT)); RuntimeConfigurationError error = expectThrows( RuntimeConfigurationError.class, () -> configuration.checkConfiguration( mockRemoteServer, mockAppEngineDeployable, project)); assertThat(error.getMessage()) .contains( "Server is misconfigured: The Cloud SDK does not contain the app-engine-java " + "component."); }
protected void checkFileConfiguration() throws RuntimeConfigurationError { VirtualFile file = findFile(getFilePath()); if (file == null) { throw new RuntimeConfigurationError("Main file is not specified"); } PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file); if (!(psiFile instanceof GoFile)) { throw new RuntimeConfigurationError("Main file is invalid"); } if (!GoRunUtil.isMainGoFile(psiFile)) { throw new RuntimeConfigurationError("Main file has non-main package or doesn't contain main function"); } }
protected void checkFileConfiguration() throws RuntimeConfigurationError { VirtualFile file = findFile(getFilePath()); if (file == null) { throw new RuntimeConfigurationError("Cannot find the specified main file."); } PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file); if (!(psiFile instanceof BallerinaFile)) { throw new RuntimeConfigurationError("Main file is not a valid Ballerina file."); } if (myRunKind == RunConfigurationKind.MAIN && !BallerinaRunUtil.hasMainFunction(psiFile)) { throw new RuntimeConfigurationError("Main run kind is selected, but the file does not contain a main " + "function."); } if (myRunKind == RunConfigurationKind.SERVICE && !BallerinaRunUtil.hasServices(psiFile)) { throw new RuntimeConfigurationError("Service run kind is selected, but the file does not contain any " + "services."); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { super.checkBaseConfiguration(); VirtualFile file = findFile(getFilePath()); if (file == null) { throw new RuntimeConfigurationError("Cannot find the specified main file."); } PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file); if (!(psiFile instanceof BallerinaFile)) { throw new RuntimeConfigurationError("Selected file is not a valid Ballerina file."); } if (!file.getName().endsWith(BallerinaConstants.BALLERINA_TEST_FILE_SUFFIX)) { throw new RuntimeConfigurationError("Selected file is not a Ballerina test file. File should end with " + "'" + BallerinaConstants.BALLERINA_TEST_FILE_SUFFIX + "' suffix."); } if (getPackage().isEmpty()) { throw new RuntimeConfigurationError("Test files must be in a package."); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { BallerinaModuleBasedConfiguration configurationModule = getConfigurationModule(); Module module = configurationModule.getModule(); if (module != null) { if (BallerinaSdkService.getInstance(module.getProject()).getSdkHomePath(module) == null) { throw new RuntimeConfigurationError("Ballerina SDK is not specified for module '" + module.getName() + "'"); } } else { String moduleName = configurationModule.getModuleName(); if (moduleName != null) { throw new RuntimeConfigurationError( ExecutionBundle.message("module.doesn.t.exist.in.project.error.text", moduleName)); } throw new RuntimeConfigurationError(ExecutionBundle.message("module.not.specified.error.text")); } if (myWorkingDirectory.isEmpty()) { throw new RuntimeConfigurationError("Working directory is not specified"); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { GoModuleBasedConfiguration configurationModule = getConfigurationModule(); Module module = configurationModule.getModule(); if (module != null) { if (GoSdkService.getInstance(module.getProject()).getSdkHomePath(module) == null) { throw new RuntimeConfigurationWarning("Go SDK is not specified for module '" + module.getName() + "'"); } } else { String moduleName = configurationModule.getModuleName(); if (moduleName != null) { throw new RuntimeConfigurationError(ExecutionBundle.message("module.doesn.t.exist.in.project.error.text", moduleName)); } throw new RuntimeConfigurationError(ExecutionBundle.message("module.not.specified.error.text")); } if (myWorkingDirectory.isEmpty()) { throw new RuntimeConfigurationError("Working directory is not specified"); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { checkBaseConfiguration(); switch (myKind) { case PACKAGE: Module module = getConfigurationModule().getModule(); assert module != null; if (StringUtil.isEmptyOrSpaces(myPackage)) { throw new RuntimeConfigurationError("Package is not specified"); } VirtualFile packageDirectory = GoPackageUtil.findByImportPath(myPackage, module.getProject(), module); if (packageDirectory == null || !packageDirectory.isDirectory()) { throw new RuntimeConfigurationError("Cannot find package '" + myPackage + "'"); } if (GoRunUtil.findMainFileInDirectory(packageDirectory, getProject()) == null) { throw new RuntimeConfigurationError("Cannot find Go file with main in '" + myPackage + "'"); } break; case FILE: checkFileConfiguration(); break; } }
GoModuleBasedConfiguration configurationModule = getConfigurationModule(); if (!myTestFramework.isAvailable(configurationModule.getModule())) { throw new RuntimeConfigurationError("Framework `" + myTestFramework.getName() + "` is not available in selected module"); throw new RuntimeConfigurationError("Working directory should be ancestor of testing directory"); throw new RuntimeConfigurationError("Testing directory doesn't exist"); throw new RuntimeConfigurationError("Cannot find package '" + myPackage + "'"); throw new RuntimeConfigurationError(message); case FILE: VirtualFile virtualFile = findFile(getFilePath()); if (virtualFile == null) { throw new RuntimeConfigurationError("Test file doesn't exist"); throw new RuntimeConfigurationError(message);
@Override public void checkConfiguration() throws RuntimeConfigurationException { super.checkBaseConfiguration(); super.checkFileConfiguration(); Module module = getConfigurationModule().getModule(); assert module != null; if (StringUtil.isEmptyOrSpaces(myPackage) && StringUtil.isEmptyOrSpaces(getFilePath())) { throw new RuntimeConfigurationError("Both file path and package are not specified. Need to specify at " + "least one."); } }
@Override public void checkConfiguration() throws RuntimeConfigurationException { if (mongoShell == null) { throw new RuntimeConfigurationError("Mongo shell path is not set."); } if (scriptPath == null) { throw new RuntimeConfigurationError("Script path is not set."); } if (serverConfiguration == null) { throw new RuntimeConfigurationError("Server is not set."); } if (database == null) { throw new RuntimeConfigurationError("Database is not set."); } }
/** * Ensures the truth of the given boolean expression, otherwise throws a {@link * RuntimeConfigurationError} with the given message. * * @param expression the expression to test * @param message the key of the message (as described by {@link AppEngineMessageBundle#message}) * to show in the error * @throws RuntimeConfigurationError if the given expression is false */ private static void check(boolean expression, String message) throws RuntimeConfigurationError { if (!expression) { throw new RuntimeConfigurationError(AppEngineMessageBundle.message(message)); } }
@NotNull public VirtualFile getDFile() throws RuntimeConfigurationError { final String filePath = getdFilePath(); if (StringUtil.isEmptyOrSpaces(filePath)) { throw new RuntimeConfigurationError(DlangBundle.INSTANCE.message("path.to.dlanguage.file.not.set")); } final VirtualFile dFile = LocalFileSystem.getInstance().findFileByPath(filePath); if (dFile == null || dFile.isDirectory()) { throw new RuntimeConfigurationError(DlangBundle.INSTANCE.message("dlanguage.file.not.found", FileUtil.toSystemDependentName(filePath))); } if (dFile.getFileType() != DlangFileType.INSTANCE) { throw new RuntimeConfigurationError(DlangBundle.INSTANCE.message("not.a.dlanguage.file", FileUtil.toSystemDependentName(filePath))); } return dFile; }
@Override public void checkConfiguration() throws RuntimeConfigurationException { if (artifactPointer == null || artifactPointer.getArtifact() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.artifact.missing")); } // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { if (!CloudSdkValidator.getInstance().isValidCloudSdk()) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.run.server.sdk.misconfigured.panel.message")); } } if (ProjectRootManager.getInstance(commonModel.getProject()).getProjectSdk() == null) { throw new RuntimeConfigurationError( AppEngineMessageBundle.getString("appengine.run.server.nojdk")); } }
String interpreter = settings.getProjectInterpreter(); if (interpreter.isEmpty()) { throw new RuntimeConfigurationError("No project interpreter configured"); throw new RuntimeConfigurationError("Script name not given.");
private void checkCommonConfig(AppEngineDeployable deployable) throws RuntimeConfigurationError { // do not check SDK if it supports dynamic install - the deployment runner will block itself // until installation is done. CloudSdkService cloudSdkService = CloudSdkService.getInstance(); SdkStatus sdkStatus = cloudSdkService.getStatus(); if (sdkStatus != SdkStatus.READY && !cloudSdkService.isInstallSupported()) { Set<CloudSdkValidationResult> sdkValidationResult = CloudSdkValidator.getInstance().validateCloudSdk(); if (!sdkValidationResult.isEmpty()) { CloudSdkValidationResult result = Iterables.getFirst(sdkValidationResult, null); throw new RuntimeConfigurationError( AppEngineMessageBundle.message( "appengine.flex.config.server.error", result.getMessage())); } } check( deployable instanceof UserSpecifiedPathDeploymentSource || deployable.isValid(), "appengine.config.deployment.source.error"); check( StringUtils.isNotBlank(cloudProjectName), "appengine.flex.config.project.missing.message"); }
@Override public void checkConfiguration( RemoteServer<?> server, DeploymentSource deploymentSource, Project project) throws RuntimeConfigurationException { if (!(deploymentSource instanceof AppEngineDeployable)) { throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.deployment.invalid.source.error")); } AppEngineDeployable deployable = (AppEngineDeployable) deploymentSource; checkCommonConfig(deployable); if (deployable.getEnvironment() != null && deployable.getEnvironment().isFlexible()) { checkFlexConfig(deployable, project); } }
throw new RuntimeConfigurationError( AppEngineMessageBundle.message("appengine.appyaml.malformed"));