use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineFlexibleStage method stage.
/**
* Stages the application in the given staging directory, in preparation for deployment to the App
* Engine flexible environment.
*
* @param stagingDirectory the directory to stage the application to
* @return {@code true} if the application was staged successfully, {@code false} otherwise
* @throws IOException if there was a filesystem error during copying
*/
public boolean stage(@NotNull Path stagingDirectory) throws IOException {
try {
String moduleName = deploymentConfiguration.getModuleName();
if (StringUtils.isEmpty(moduleName)) {
loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
return false;
}
AppEngineFlexibleFacet flexibleFacet = AppEngineFlexibleFacet.getFacetByModuleName(moduleName, project);
if (flexibleFacet == null || StringUtils.isEmpty(flexibleFacet.getConfiguration().getAppYamlPath())) {
loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notspecified"));
return false;
}
AppEngineFlexibleFacetConfiguration facetConfiguration = flexibleFacet.getConfiguration();
String appYaml = facetConfiguration.getAppYamlPath();
// Checks if the app.yaml exists before staging.
if (!Files.exists(Paths.get(appYaml))) {
loggingHandler.print(getMessage("appengine.deployment.error.staging.yaml.notfound"));
return false;
}
boolean isCustomRuntime = AppEngineProjectService.getInstance().getFlexibleRuntimeFromAppYaml(appYaml).filter(FlexibleRuntime::isCustom).isPresent();
// Checks if the Dockerfile exists before staging.
String dockerDirectory = facetConfiguration.getDockerDirectory();
if (isCustomRuntime) {
if (Strings.isNullOrEmpty(dockerDirectory)) {
loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notspecified"));
return false;
}
if (!Files.isRegularFile(Paths.get(dockerDirectory, DOCKERFILE_NAME))) {
loggingHandler.print(getMessage("appengine.deployment.error.staging.dockerfile.notfound"));
return false;
}
}
String stagedArtifactName = deploymentConfiguration.getStagedArtifactName();
if (Strings.isNullOrEmpty(stagedArtifactName)) {
if (deploymentConfiguration.isStagedArtifactNameLegacy()) {
// Uses "target.jar" or "target.war" for legacy configs.
AppEngineFlexibleDeploymentArtifactType artifactType = AppEngineFlexibleDeploymentArtifactType.typeForPath(deploymentArtifactPath);
stagedArtifactName = StagedArtifactNameLegacySupport.getTargetName(artifactType);
} else {
// Defaults to the name of the artifact.
stagedArtifactName = deploymentArtifactPath.getFileName().toString();
}
}
loggingHandler.print(getMessage("appengine.deployment.staging.artifact.as", stagedArtifactName));
Path stagedArtifactPath = stagingDirectory.resolve(stagedArtifactName);
// Creates parent directories first, if necessary.
Files.createDirectories(stagedArtifactPath.getParent());
Files.copy(deploymentArtifactPath, stagedArtifactPath);
Path appYamlPath = Paths.get(appYaml);
Files.copy(appYamlPath, stagingDirectory.resolve(appYamlPath.getFileName()));
if (isCustomRuntime) {
FileUtils.copyDirectory(Paths.get(dockerDirectory).toFile(), stagingDirectory.toFile());
}
} catch (InvalidPathException | MalformedYamlFileException e) {
loggingHandler.print(e.getMessage() + "\n");
}
return true;
}
use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineFlexibleDeploymentEditorTest method setUp.
@Before
public void setUp() {
FacetManager.getInstance(javaModule).getFacetByType(AppEngineFlexibleFacet.getFacetType().getId()).getConfiguration().setAppYamlPath(javaYaml.getPath());
AppEngineFlexibleFacetConfiguration customConfig = FacetManager.getInstance(customModule).getFacetByType(AppEngineFlexibleFacet.getFacetType().getId()).getConfiguration();
customConfig.setAppYamlPath(customYaml.getPath());
customConfig.setDockerDirectory(dockerfile.getParentFile().getPath());
userSpecifiedPathDeploymentSource = new UserSpecifiedPathDeploymentSource(ModulePointerManager.getInstance(testFixture.getProject()).create(UserSpecifiedPathDeploymentSource.moduleName));
configuration = new AppEngineDeploymentConfiguration();
editor = new AppEngineFlexibleDeploymentEditor(testFixture.getProject(), deploymentSource);
editor.setAppInfoPanel(appInfoPanel);
editor.getCommonConfig().setProjectSelector(projectSelector);
}
use of com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetConfiguration in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineDeploymentConfigurationTest method setUpValidCustomFlexConfiguration.
/**
* Sets up the {@code configuration} to be a valid custom deployment to a flex environment.
*/
private void setUpValidCustomFlexConfiguration() {
when(mockSdkValidator.validateCloudSdk()).thenReturn(ImmutableSet.of());
when(mockAppEngineDeployable.isValid()).thenReturn(true);
when(mockAppEngineDeployable.getEnvironment()).thenReturn(AppEngineEnvironment.APP_ENGINE_FLEX);
AppEngineFlexibleFacetConfiguration facetConfig = FacetManager.getInstance(module).getFacetByType(AppEngineFlexibleFacet.getFacetType().getId()).getConfiguration();
facetConfig.setAppYamlPath(customYaml.getPath());
facetConfig.setDockerDirectory(dockerfile.getParent());
configuration.setCloudProjectName("some-project-name");
configuration.setModuleName(module.getName());
configuration.setStagedArtifactName("target.war");
try {
when(mockAppEngineProjectService.getFlexibleRuntimeFromAppYaml(customYaml.getPath())).thenReturn(Optional.of(FlexibleRuntime.CUSTOM));
} catch (MalformedYamlFileException e) {
throw new AssertionError("This should not happen; Mockito must be broken.", e);
}
}
Aggregations