Search in sources :

Example 1 with AppEngineProjectService

use of com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineUtil method createArtifactDeploymentSources.

/**
 * Creates a list of artifact deployment sources available for deployment to App Engine.
 *
 * <p>Artifacts either target the standard or the flexible environment. All standard artifacts are
 * added. Flexible artifacts are only added if there are no other standard artifacts associated
 * with the same module.
 *
 * @return a list of {@link AppEngineArtifactDeploymentSource}
 */
public static List<AppEngineArtifactDeploymentSource> createArtifactDeploymentSources(@NotNull final Project project) {
    List<AppEngineArtifactDeploymentSource> sources = Lists.newArrayList();
    AppEngineProjectService projectService = AppEngineProjectService.getInstance();
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        FacetManager facetManager = FacetManager.getInstance(module);
        if (facetManager.getFacetByType(AppEngineStandardFacetType.ID) != null || facetManager.getFacetByType(AppEngineFlexibleFacetType.ID) != null) {
            final AppEngineEnvironment environment = projectService.getModuleAppEngineEnvironment(module).orElseThrow(() -> new RuntimeException("No environment."));
            Collection<Artifact> artifacts = ArtifactUtil.getArtifactsContainingModuleOutput(module);
            sources.addAll(artifacts.stream().filter(artifact -> doesArtifactMatchEnvironment(artifact, environment)).map(artifact -> AppEngineUtil.createArtifactDeploymentSource(project, artifact, environment)).collect(toList()));
        }
    }
    return sources;
}
Also used : ModulePointer(com.intellij.openapi.module.ModulePointer) AppEngineStandardFacetType(com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacetType) ModuleManager(com.intellij.openapi.module.ModuleManager) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) Artifact(com.intellij.packaging.artifacts.Artifact) Lists(com.google.common.collect.Lists) ModuleDeploymentSource(com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource) Project(com.intellij.openapi.project.Project) ModuleType(com.intellij.openapi.module.ModuleType) Module(com.intellij.openapi.module.Module) AppEngineFlexibleFacetType(com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) AppEngineArtifactDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.AppEngineArtifactDeploymentSource) Collection(java.util.Collection) FacetManager(com.intellij.facet.FacetManager) ArtifactPointerManager(com.intellij.packaging.artifacts.ArtifactPointerManager) ModulePointerManager(com.intellij.openapi.module.ModulePointerManager) Nullable(org.jetbrains.annotations.Nullable) Collectors.toList(java.util.stream.Collectors.toList) UserSpecifiedPathDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource) List(java.util.List) ArtifactUtil(com.intellij.packaging.impl.artifacts.ArtifactUtil) MavenBuildDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.MavenBuildDeploymentSource) NotNull(org.jetbrains.annotations.NotNull) AppEngineEnvironment(com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) AppEngineArtifactDeploymentSource(com.google.cloud.tools.intellij.appengine.cloud.AppEngineArtifactDeploymentSource) AppEngineEnvironment(com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment) Module(com.intellij.openapi.module.Module) FacetManager(com.intellij.facet.FacetManager) Artifact(com.intellij.packaging.artifacts.Artifact)

Example 2 with AppEngineProjectService

use of com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineFlexibleSupportProvider method addSupport.

/**
 * Initializes the Flexible facet by settings the default paths for app.yaml and Dockerfile and
 * generating the necessary run configurations.
 */
public static void addSupport(@NotNull AppEngineFlexibleFacet facet, @NotNull ModifiableRootModel rootModel, boolean generateConfigFiles) {
    UsageTrackerProvider.getInstance().trackEvent(GctTracking.APP_ENGINE_ADD_SUPPORT).addMetadata("env", "flex");
    // Allows suggesting app.yaml and Dockerfile locations in facet and deployment UIs.
    VirtualFile[] contentRoots = rootModel.getContentRoots();
    AppEngineProjectService appEngineProjectService = AppEngineProjectService.getInstance();
    if (contentRoots.length > 0) {
        Path appYamlPath = Paths.get(appEngineProjectService.getDefaultAppYamlPath(contentRoots[0].getPath()));
        Path dockerDirectory = Paths.get(appEngineProjectService.getDefaultDockerDirectory(contentRoots[0].getPath()));
        facet.getConfiguration().setAppYamlPath(appYamlPath.toString());
        facet.getConfiguration().setDockerDirectory(dockerDirectory.toString());
        if (generateConfigFiles) {
            appEngineProjectService.generateAppYaml(FlexibleRuntime.JAVA, facet.getModule(), appYamlPath.getParent());
            UsageTrackerProvider.getInstance().trackEvent(GctTracking.APP_ENGINE_GENERATE_FILE_APPYAML).addMetadata("source", "addedByFramework").addMetadata("env", "flex").ping();
        }
    }
    // TODO(joaomartins): Add other run configurations here too.
    // https://github.com/GoogleCloudPlatform/google-cloud-intellij/issues/1260
    setupDeploymentRunConfiguration(facet.getModule());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Path(java.nio.file.Path) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService)

Example 3 with AppEngineProjectService

use of com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService in project google-cloud-intellij by GoogleCloudPlatform.

the class MavenBuildDeploymentSource method getFile.

@Nullable
@Override
public File getFile() {
    if (getModule() == null) {
        return null;
    }
    MavenProject mavenProject = MavenProjectsManager.getInstance(project).findProject(getModule());
    if (mavenProject == null) {
        return null;
    }
    final StringBuilder targetBuild = new StringBuilder(new File(mavenProject.getBuildDirectory()).getPath() + File.separator + mavenProject.getFinalName());
    AppEngineProjectService projectService = AppEngineProjectService.getInstance();
    // In this case, we need to try and reload the environment.
    if (environment == null) {
        projectService.getModuleAppEngineEnvironment(getModule()).ifPresent(env -> environment = env);
    }
    if (environment != null && environment.isFlexible()) {
        targetBuild.append(".");
        targetBuild.append(mavenProject.getPackaging());
    }
    return new File(targetBuild.toString());
}
Also used : MavenProject(org.jetbrains.idea.maven.project.MavenProject) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AppEngineProjectService

use of com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService in project google-cloud-intellij by GoogleCloudPlatform.

the class AppEngineUtil method createModuleDeploymentSources.

/**
 * Creates a list of module deployment sources available for deployment to App Engine:
 *
 * <p>Maven based deployment sources are included for both flexible and standard projects if
 * applicable.
 *
 * <p>User browsable jar/war deployment sources are included only if there are no App Engine
 * standard modules.
 *
 * @return a list of {@link ModuleDeploymentSource}'s
 */
public static List<ModuleDeploymentSource> createModuleDeploymentSources(@NotNull Project project) {
    AppEngineProjectService projectService = AppEngineProjectService.getInstance();
    List<ModuleDeploymentSource> moduleDeploymentSources = Lists.newArrayList();
    boolean hasStandardModules = false;
    for (Module module : ModuleManager.getInstance(project).getModules()) {
        FacetManager facetManager = FacetManager.getInstance(module);
        if (facetManager.getFacetByType(AppEngineStandardFacetType.ID) != null || facetManager.getFacetByType(AppEngineFlexibleFacetType.ID) != null) {
            AppEngineEnvironment environment = projectService.getModuleAppEngineEnvironment(module).orElseThrow(() -> new RuntimeException("No environment."));
            if (ModuleType.is(module, JavaModuleType.getModuleType()) && projectService.isJarOrWarMavenBuild(module)) {
                moduleDeploymentSources.add(createMavenBuildDeploymentSource(project, module, environment));
            }
            if (environment.isStandard() || environment.isFlexCompat()) {
                hasStandardModules = true;
            }
        }
    }
    if (!hasStandardModules) {
        moduleDeploymentSources.add(createUserSpecifiedPathDeploymentSource(project));
    }
    return moduleDeploymentSources;
}
Also used : ModuleDeploymentSource(com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource) AppEngineProjectService(com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService) AppEngineEnvironment(com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment) Module(com.intellij.openapi.module.Module) FacetManager(com.intellij.facet.FacetManager)

Aggregations

AppEngineProjectService (com.google.cloud.tools.intellij.appengine.project.AppEngineProjectService)4 AppEngineEnvironment (com.google.cloud.tools.intellij.appengine.cloud.AppEngineEnvironment)2 FacetManager (com.intellij.facet.FacetManager)2 Module (com.intellij.openapi.module.Module)2 ModuleDeploymentSource (com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource)2 Nullable (org.jetbrains.annotations.Nullable)2 AppEngineArtifactDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.AppEngineArtifactDeploymentSource)1 MavenBuildDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.MavenBuildDeploymentSource)1 UserSpecifiedPathDeploymentSource (com.google.cloud.tools.intellij.appengine.cloud.flexible.UserSpecifiedPathDeploymentSource)1 AppEngineFlexibleFacetType (com.google.cloud.tools.intellij.appengine.facet.flexible.AppEngineFlexibleFacetType)1 AppEngineStandardFacetType (com.google.cloud.tools.intellij.appengine.facet.standard.AppEngineStandardFacetType)1 Lists (com.google.common.collect.Lists)1 JavaModuleType (com.intellij.openapi.module.JavaModuleType)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 ModulePointer (com.intellij.openapi.module.ModulePointer)1 ModulePointerManager (com.intellij.openapi.module.ModulePointerManager)1 ModuleType (com.intellij.openapi.module.ModuleType)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Artifact (com.intellij.packaging.artifacts.Artifact)1