mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cloud integrations - refactor artifacts deploy
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.impl.util;
|
||||
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
import com.intellij.remoteServer.util.*;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class ArtifactDeploymentRuntimeProviderBase implements CloudDeploymentRuntimeProvider {
|
||||
|
||||
@Override
|
||||
public CloudDeploymentRuntime createDeploymentRuntime(DeploymentSource source,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager)
|
||||
throws ServerRuntimeException {
|
||||
if (!(source instanceof ArtifactDeploymentSource)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArtifactDeploymentSource artifactSource = (ArtifactDeploymentSource)source;
|
||||
Artifact artifact = artifactSource.getArtifact();
|
||||
if (artifact == null) {
|
||||
throw new ServerRuntimeException("Artifact not found " + artifactSource.getArtifactPointer().getArtifactName());
|
||||
}
|
||||
|
||||
String artifactPath = artifact.getOutputFilePath();
|
||||
if (artifactPath == null) {
|
||||
throw new ServerRuntimeException("Artifact output not found");
|
||||
}
|
||||
|
||||
return doCreateDeploymentRuntime(artifactSource, new File(artifactPath), serverRuntime, deploymentTask, logManager);
|
||||
}
|
||||
|
||||
protected abstract CloudDeploymentRuntime doCreateDeploymentRuntime(ArtifactDeploymentSource artifactSource,
|
||||
File artifactFile,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager) throws ServerRuntimeException;
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.impl.util;
|
||||
|
||||
import com.intellij.packaging.artifacts.Artifact;
|
||||
import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource;
|
||||
import com.intellij.remoteServer.util.DeploymentSourceHandler;
|
||||
import com.intellij.remoteServer.util.ServerRuntimeException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class ArtifactDeploymentSourceHandlerBase implements DeploymentSourceHandler {
|
||||
|
||||
private final File myArtifactFile;
|
||||
|
||||
public ArtifactDeploymentSourceHandlerBase(ArtifactDeploymentSource deploymentSource) throws ServerRuntimeException {
|
||||
Artifact artifact = deploymentSource.getArtifact();
|
||||
if (artifact == null) {
|
||||
throw new ServerRuntimeException("Artifact not found " + deploymentSource.getArtifactPointer().getArtifactName());
|
||||
}
|
||||
|
||||
String artifactPath = artifact.getOutputFilePath();
|
||||
if (artifactPath == null) {
|
||||
throw new ServerRuntimeException("Artifact output not found");
|
||||
}
|
||||
myArtifactFile = new File(artifactPath);
|
||||
}
|
||||
|
||||
protected File getArtifactFile() {
|
||||
return myArtifactFile;
|
||||
}
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.impl.util;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
import com.intellij.remoteServer.util.CloudMultiSourceServerRuntimeInstance;
|
||||
import com.intellij.remoteServer.util.CloudDeploymentNameConfiguration;
|
||||
import com.intellij.remoteServer.util.CloudDeploymentRuntime;
|
||||
import com.intellij.remoteServer.util.ServerRuntimeException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class RepositoryArtifactDeploymentRuntimeProviderBase extends ArtifactDeploymentRuntimeProviderBase {
|
||||
|
||||
@Override
|
||||
protected CloudDeploymentRuntime doCreateDeploymentRuntime(ArtifactDeploymentSource artifactSource,
|
||||
File artifactFile,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager) throws ServerRuntimeException {
|
||||
RepositoryDeploymentConfiguration config = (RepositoryDeploymentConfiguration)deploymentTask.getConfiguration();
|
||||
|
||||
String repositoryPath = config.getRepositoryPath();
|
||||
File repositoryRootFile;
|
||||
if (StringUtil.isEmpty(repositoryPath)) {
|
||||
File repositoryParentFolder = new File(PathManager.getSystemPath(), "cloud-git-artifact-deploy");
|
||||
repositoryRootFile = FileUtil.findSequentNonexistentFile(repositoryParentFolder, artifactFile.getName(), "");
|
||||
}
|
||||
else {
|
||||
repositoryRootFile = new File(repositoryPath);
|
||||
}
|
||||
|
||||
if (!FileUtil.createDirectory(repositoryRootFile)) {
|
||||
throw new ServerRuntimeException("Unable to create deploy folder: " + repositoryRootFile);
|
||||
}
|
||||
config.setRepositoryPath(repositoryRootFile.getAbsolutePath());
|
||||
return doCreateDeploymentRuntime(artifactSource, artifactFile, serverRuntime, deploymentTask, logManager, repositoryRootFile);
|
||||
}
|
||||
|
||||
protected abstract CloudDeploymentRuntime doCreateDeploymentRuntime(ArtifactDeploymentSource artifactSource,
|
||||
File artifactFile,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager,
|
||||
File repositoryRootFile) throws ServerRuntimeException;
|
||||
}
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.impl.util;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource;
|
||||
import com.intellij.remoteServer.util.ServerRuntimeException;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class RepositoryArtifactDeploymentSourceHandlerBase extends ArtifactDeploymentSourceHandlerBase {
|
||||
|
||||
private final File myRepositoryRootFile;
|
||||
|
||||
public RepositoryArtifactDeploymentSourceHandlerBase(ArtifactDeploymentSource deploymentSource, RepositoryDeploymentConfiguration config)
|
||||
throws ServerRuntimeException {
|
||||
super(deploymentSource);
|
||||
String repositoryPath = config.getRepositoryPath();
|
||||
if (StringUtil.isEmpty(repositoryPath)) {
|
||||
File repositoryParentFolder = new File(PathManager.getSystemPath(), "cloud-git-artifact-deploy");
|
||||
myRepositoryRootFile = FileUtil.findSequentNonexistentFile(repositoryParentFolder, getArtifactFile().getName(), "");
|
||||
}
|
||||
else {
|
||||
myRepositoryRootFile = new File(repositoryPath);
|
||||
}
|
||||
|
||||
if (!FileUtil.createDirectory(myRepositoryRootFile)) {
|
||||
throw new ServerRuntimeException("Unable to create deploy folder: " + myRepositoryRootFile);
|
||||
}
|
||||
config.setRepositoryPath(myRepositoryRootFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRepositoryRootFile() {
|
||||
return myRepositoryRootFile;
|
||||
}
|
||||
}
|
||||
+4
-8
@@ -13,18 +13,14 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.remoteServer.agent.util.CloudGitApplication;
|
||||
|
||||
import java.io.File;
|
||||
package com.intellij.remoteServer.agent.util;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public interface DeploymentSourceHandler {
|
||||
public interface CloudApplication {
|
||||
|
||||
File getRepositoryRootFile();
|
||||
String getName();
|
||||
|
||||
CloudGitApplication deploy() throws ServerRuntimeException;
|
||||
String getWebUrl();
|
||||
}
|
||||
+1
-5
@@ -18,11 +18,7 @@ package com.intellij.remoteServer.agent.util;
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public interface CloudGitApplication {
|
||||
|
||||
String getName();
|
||||
public interface CloudGitApplication extends CloudApplication {
|
||||
|
||||
String getGitUrl();
|
||||
|
||||
String getWebUrl();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
<extensionPoint name="remoteServer.type" interface="com.intellij.remoteServer.ServerType"/>
|
||||
<extensionPoint name="remoteServer.deploymentSource.type" interface="com.intellij.remoteServer.configuration.deployment.DeploymentSourceType"/>
|
||||
<extensionPoint name="remoteServer.viewContributor" interface="com.intellij.remoteServer.impl.runtime.ui.RemoteServersViewContributor"/>
|
||||
|
||||
<extensionPoint name="remoteServer.util.CloudDeploymentRuntimeProvider"
|
||||
interface="com.intellij.remoteServer.util.CloudDeploymentRuntimeProvider"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
|
||||
+6
-6
@@ -15,20 +15,20 @@ import java.util.List;
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class CloudGitDeploymentConfiguratorBase<D extends DeploymentConfiguration, S extends ServerConfiguration>
|
||||
public abstract class CloudDeploymentConfiguratorBase<D extends DeploymentConfiguration, S extends ServerConfiguration>
|
||||
extends DeploymentConfigurator<D, S> {
|
||||
|
||||
private final Project myProject;
|
||||
private ServerType<S> myServerType;
|
||||
|
||||
public CloudGitDeploymentConfiguratorBase(Project project, ServerType<S> serverType) {
|
||||
public CloudDeploymentConfiguratorBase(Project project, ServerType<S> serverType) {
|
||||
myProject = project;
|
||||
myServerType = serverType;
|
||||
}
|
||||
|
||||
public static List<CloudGitDeploymentSourceHandlerProvider> getDeploymentSourceHandlerProviders(ServerType<?> serverType) {
|
||||
List<CloudGitDeploymentSourceHandlerProvider> result = new ArrayList<CloudGitDeploymentSourceHandlerProvider>();
|
||||
for (CloudGitDeploymentSourceHandlerProvider provider : CloudGitDeploymentSourceHandlerProvider.EP_NAME.getExtensions()) {
|
||||
public static List<CloudDeploymentRuntimeProvider> getDeploymentRuntimeProviders(ServerType<?> serverType) {
|
||||
List<CloudDeploymentRuntimeProvider> result = new ArrayList<CloudDeploymentRuntimeProvider>();
|
||||
for (CloudDeploymentRuntimeProvider provider : CloudDeploymentRuntimeProvider.EP_NAME.getExtensions()) {
|
||||
ServerType<?> providerServerType = provider.getServerType();
|
||||
if (providerServerType == null || providerServerType == serverType) {
|
||||
result.add(provider);
|
||||
@@ -42,7 +42,7 @@ public abstract class CloudGitDeploymentConfiguratorBase<D extends DeploymentCon
|
||||
public List<DeploymentSource> getAvailableDeploymentSources() {
|
||||
if (myProject.isDefault()) return Collections.emptyList();
|
||||
List<DeploymentSource> result = new ArrayList<DeploymentSource>();
|
||||
for (CloudGitDeploymentSourceHandlerProvider provider : getDeploymentSourceHandlerProviders(myServerType)) {
|
||||
for (CloudDeploymentRuntimeProvider provider : getDeploymentRuntimeProviders(myServerType)) {
|
||||
result.addAll(provider.getDeploymentSources(myProject));
|
||||
}
|
||||
return result;
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.remoteServer.agent.util.CloudApplication;
|
||||
import com.intellij.remoteServer.agent.util.CloudGitAgentDeployment;
|
||||
import com.intellij.remoteServer.agent.util.CloudLoggingHandler;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.runtime.ServerTaskExecutor;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentRuntime;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance;
|
||||
import com.intellij.remoteServer.runtime.log.LoggingHandler;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class CloudDeploymentRuntime extends DeploymentRuntime {
|
||||
|
||||
private final CloudGitAgentDeployment myDeployment;
|
||||
private final String myApplicationName;
|
||||
private final CloudConfigurationBase myConfiguration;
|
||||
private final AgentTaskExecutor myAgentTaskExecutor;
|
||||
private final String myPresentableName;
|
||||
private final ServerTaskExecutor myTaskExecutor;
|
||||
private final CloudLoggingHandler myLoggingHandler;
|
||||
@Nullable private final DeploymentLogManager myLogManager;
|
||||
private final Project myProject;
|
||||
|
||||
public CloudDeploymentRuntime(CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentSource source,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> task,
|
||||
@Nullable DeploymentLogManager logManager) throws ServerRuntimeException {
|
||||
myConfiguration = serverRuntime.getConfiguration();
|
||||
|
||||
myTaskExecutor = serverRuntime.getTaskExecutor();
|
||||
myAgentTaskExecutor = serverRuntime.getAgentTaskExecutor();
|
||||
|
||||
myLogManager = logManager;
|
||||
myLoggingHandler = logManager == null ? new CloudSilentLoggingHandlerImpl() : new CloudLoggingHandlerImpl(logManager);
|
||||
|
||||
CloudDeploymentNameConfiguration deploymentConfiguration = task.getConfiguration();
|
||||
myApplicationName = deploymentConfiguration.isDefaultDeploymentName()
|
||||
? serverRuntime.getDeploymentName(source)
|
||||
: deploymentConfiguration.getDeploymentName();
|
||||
|
||||
myPresentableName = source.getPresentableName();
|
||||
|
||||
myDeployment = serverRuntime.getAgent().createDeployment(myApplicationName, myLoggingHandler);
|
||||
|
||||
myProject = task.getProject();
|
||||
}
|
||||
|
||||
public void deploy(ServerRuntimeInstance.DeploymentOperationCallback callback) {
|
||||
try {
|
||||
CloudApplication application = deploy();
|
||||
|
||||
if (myLogManager != null) {
|
||||
LoggingHandler loggingHandler = myLogManager.getMainLoggingHandler();
|
||||
loggingHandler.print("Application is available at ");
|
||||
loggingHandler.printHyperlink(application.getWebUrl());
|
||||
loggingHandler.print("\n");
|
||||
}
|
||||
|
||||
callback.succeeded(this);
|
||||
}
|
||||
catch (ServerRuntimeException e) {
|
||||
callback.errorOccurred(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy(final @NotNull UndeploymentTaskCallback callback) {
|
||||
myTaskExecutor.submit(new ThrowableRunnable<Exception>() {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
try {
|
||||
if (!confirmUndeploy()) {
|
||||
throw new ServerRuntimeException("Undeploy cancelled");
|
||||
}
|
||||
|
||||
undeploy();
|
||||
|
||||
callback.succeeded();
|
||||
}
|
||||
catch (ServerRuntimeException e) {
|
||||
callback.errorOccurred(e.getMessage());
|
||||
}
|
||||
}
|
||||
}, callback);
|
||||
}
|
||||
|
||||
public CloudGitAgentDeployment getDeployment() {
|
||||
return myDeployment;
|
||||
}
|
||||
|
||||
public Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
public String getApplicationName() {
|
||||
return myApplicationName;
|
||||
}
|
||||
|
||||
public AgentTaskExecutor getAgentTaskExecutor() {
|
||||
return myAgentTaskExecutor;
|
||||
}
|
||||
|
||||
public CloudLoggingHandler getLoggingHandler() {
|
||||
return myLoggingHandler;
|
||||
}
|
||||
|
||||
public boolean confirmUndeploy() {
|
||||
final Ref<Boolean> confirmed = new Ref<Boolean>(false);
|
||||
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String title = CloudBundle.getText("cloud.undeploy.confirm.title");
|
||||
while (true) {
|
||||
String password = Messages.showPasswordDialog(CloudBundle.getText("cloud.undeploy.confirm.message", myPresentableName), title);
|
||||
if (password == null) {
|
||||
return;
|
||||
}
|
||||
if (password.equals(myConfiguration.getPassword())) {
|
||||
confirmed.set(true);
|
||||
return;
|
||||
}
|
||||
Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
|
||||
}
|
||||
}
|
||||
}, ModalityState.defaultModalityState());
|
||||
return confirmed.get();
|
||||
}
|
||||
|
||||
public abstract CloudApplication deploy() throws ServerRuntimeException;
|
||||
|
||||
public abstract void undeploy() throws ServerRuntimeException;
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public interface CloudDeploymentRuntimeProvider {
|
||||
|
||||
ExtensionPointName<CloudDeploymentRuntimeProvider> EP_NAME
|
||||
= ExtensionPointName.create("com.intellij.remoteServer.util.CloudDeploymentRuntimeProvider");
|
||||
|
||||
ServerType<?> getServerType();
|
||||
|
||||
Collection<DeploymentSource> getDeploymentSources(Project project);
|
||||
|
||||
CloudDeploymentRuntime createDeploymentRuntime(DeploymentSource source,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager)
|
||||
throws ServerRuntimeException;
|
||||
}
|
||||
+55
-47
@@ -3,6 +3,7 @@ package com.intellij.remoteServer.util;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.agent.RemoteAgentManager;
|
||||
import com.intellij.remoteServer.agent.util.CloudAgentConfigBase;
|
||||
import com.intellij.remoteServer.agent.util.CloudAgentLogger;
|
||||
@@ -25,32 +26,32 @@ import java.util.List;
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
|
||||
public abstract class CloudGitServerRuntimeInstanceBase<
|
||||
public abstract class CloudMultiSourceServerRuntimeInstance<
|
||||
DC extends CloudDeploymentNameConfiguration,
|
||||
AC extends CloudAgentConfigBase,
|
||||
A extends CloudGitAgent<AC, ?>,
|
||||
SC extends AC,
|
||||
DR extends CloudGitDeploymentRuntime>
|
||||
extends CloudServerRuntimeInstance<DC>
|
||||
implements CloudDeploymentNameProvider {
|
||||
SC extends AC>
|
||||
extends CloudServerRuntimeInstance<DC> {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + CloudGitServerRuntimeInstanceBase.class.getName());
|
||||
private static final Logger LOG = Logger.getInstance("#" + CloudMultiSourceServerRuntimeInstance.class.getName());
|
||||
|
||||
private final A myAgent;
|
||||
private final AgentTaskExecutor myAgentTaskExecutor;
|
||||
|
||||
private final ServerType<?> myServerType;
|
||||
private final SC myConfiguration;
|
||||
private final ServerTaskExecutor myTasksExecutor;
|
||||
|
||||
public CloudGitServerRuntimeInstanceBase(SC configuration,
|
||||
ServerTaskExecutor tasksExecutor,
|
||||
List<File> libraries,
|
||||
List<Class<?>> commonJarClasses,
|
||||
String specificsModuleName,
|
||||
String specificJarPath,
|
||||
Class<A> agentInterface,
|
||||
String agentClassName) throws Exception {
|
||||
public CloudMultiSourceServerRuntimeInstance(ServerType<?> serverType,
|
||||
SC configuration,
|
||||
ServerTaskExecutor tasksExecutor,
|
||||
List<File> libraries,
|
||||
List<Class<?>> commonJarClasses,
|
||||
String specificsModuleName,
|
||||
String specificJarPath,
|
||||
Class<A> agentInterface,
|
||||
String agentClassName) throws Exception {
|
||||
myServerType = serverType;
|
||||
myConfiguration = configuration;
|
||||
myTasksExecutor = tasksExecutor;
|
||||
|
||||
@@ -96,7 +97,7 @@ public abstract class CloudGitServerRuntimeInstanceBase<
|
||||
|
||||
@Override
|
||||
public void onSuccess(Object result) {
|
||||
callback.connected(CloudGitServerRuntimeInstanceBase.this);
|
||||
callback.connected(CloudMultiSourceServerRuntimeInstance.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,7 +116,7 @@ public abstract class CloudGitServerRuntimeInstanceBase<
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
createDeploymentRuntime(myConfiguration, myTasksExecutor, task, logManager).deploy(callback);
|
||||
createDeploymentRuntime(task, logManager).deploy(callback);
|
||||
}
|
||||
}, callback);
|
||||
}
|
||||
@@ -176,43 +177,50 @@ public abstract class CloudGitServerRuntimeInstanceBase<
|
||||
return myAgentTaskExecutor;
|
||||
}
|
||||
|
||||
public DR createDeploymentRuntime(final DeployToServerRunConfiguration<?, DC> runConfiguration)
|
||||
public CloudDeploymentRuntime createDeploymentRuntime(final DeployToServerRunConfiguration<?, DC> runConfiguration)
|
||||
throws ServerRuntimeException {
|
||||
return createDeploymentRuntime(myConfiguration,
|
||||
myTasksExecutor,
|
||||
new DeploymentTask<DC>() {
|
||||
return createDeploymentRuntime(new DeploymentTask<DC>() {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeploymentSource getSource() {
|
||||
return runConfiguration.getDeploymentSource();
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public DeploymentSource getSource() {
|
||||
return runConfiguration.getDeploymentSource();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DC getConfiguration() {
|
||||
return runConfiguration.getDeploymentConfiguration();
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public DC getConfiguration() {
|
||||
return runConfiguration.getDeploymentConfiguration();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return runConfiguration.getProject();
|
||||
}
|
||||
@NotNull
|
||||
@Override
|
||||
public Project getProject() {
|
||||
return runConfiguration.getProject();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugMode() {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
null
|
||||
);
|
||||
@Override
|
||||
public boolean isDebugMode() {
|
||||
return false;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
protected abstract DR createDeploymentRuntime(SC configuration,
|
||||
ServerTaskExecutor serverTaskExecutor,
|
||||
DeploymentTask<DC> deploymentTask,
|
||||
@Nullable DeploymentLogManager logManager) throws ServerRuntimeException;
|
||||
private CloudDeploymentRuntime createDeploymentRuntime(DeploymentTask<DC> deploymentTask,
|
||||
@Nullable DeploymentLogManager logManager) throws ServerRuntimeException {
|
||||
DeploymentSource source = deploymentTask.getSource();
|
||||
for (CloudDeploymentRuntimeProvider provider : CloudDeploymentConfiguratorBase.getDeploymentRuntimeProviders(myServerType)) {
|
||||
CloudDeploymentRuntime result = provider.createDeploymentRuntime(source, this, deploymentTask, logManager);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw new ServerRuntimeException("Unknown deployment source");
|
||||
}
|
||||
|
||||
public CloudConfigurationBase getConfiguration() {
|
||||
return (CloudConfigurationBase)myConfiguration;
|
||||
}
|
||||
|
||||
protected abstract void doConnect(SC configuration, CloudAgentLogger logger);
|
||||
}
|
||||
+1
-1
@@ -46,7 +46,7 @@ public abstract class CloudSupportConfigurableBase<
|
||||
SC extends CloudConfigurationBase,
|
||||
DC extends CloudDeploymentNameConfiguration,
|
||||
ST extends ServerType<SC>,
|
||||
SR extends CloudGitServerRuntimeInstanceBase<DC, ?, ?, ?, ?>>
|
||||
SR extends CloudMultiSourceServerRuntimeInstance<DC, ?, ?, ?>>
|
||||
extends FrameworkSupportConfigurable {
|
||||
|
||||
private final String myNotificationDisplayId;
|
||||
@@ -4,7 +4,6 @@
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
+41
-202
@@ -1,12 +1,8 @@
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
@@ -14,20 +10,10 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.agent.util.CloudGitAgent;
|
||||
import com.intellij.remoteServer.agent.util.CloudGitAgentDeployment;
|
||||
import com.intellij.remoteServer.agent.util.CloudGitApplication;
|
||||
import com.intellij.remoteServer.agent.util.CloudLoggingHandler;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource;
|
||||
import com.intellij.remoteServer.runtime.ServerTaskExecutor;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentRuntime;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
import com.intellij.remoteServer.runtime.deployment.ServerRuntimeInstance;
|
||||
import com.intellij.remoteServer.runtime.log.LoggingHandler;
|
||||
import com.intellij.util.ThrowableRunnable;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import git4idea.GitUtil;
|
||||
import git4idea.actions.GitInit;
|
||||
@@ -41,151 +27,68 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameConfiguration,
|
||||
AD extends CloudGitAgentDeployment,
|
||||
A extends CloudGitAgent<?, AD>> extends DeploymentRuntime {
|
||||
public class CloudGitDeploymentRuntime extends CloudDeploymentRuntime {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + CloudGitDeploymentRuntime.class.getName());
|
||||
private final String myApplicationName;
|
||||
private final CloudConfigurationBase myConfiguration;
|
||||
|
||||
private final Project myProject;
|
||||
private final GitRepositoryManager myGitRepositoryManager;
|
||||
private final Git myGit;
|
||||
private DeploymentSourceHandler mySourceHandler;
|
||||
|
||||
private final VirtualFile myContentRoot;
|
||||
private final File myContentRootFile;
|
||||
private final AgentTaskExecutor myAgentTaskExecutor;
|
||||
private final String myPresentableName;
|
||||
private final CloudLoggingHandler myLoggingHandler;
|
||||
private final ServerTaskExecutor myTasksExecutor;
|
||||
private final AD myDeployment;
|
||||
private final File myRepositoryRootFile;
|
||||
|
||||
private final DeploymentLogManager myLogManager;
|
||||
private final String myRemoteName;
|
||||
private final String myCloudName;
|
||||
|
||||
private GitRepository myRepository;
|
||||
|
||||
public CloudGitDeploymentRuntime(CloudConfigurationBase serverConfiguration,
|
||||
A agent,
|
||||
ServerTaskExecutor taskExecutor,
|
||||
DeploymentTask<DC> task,
|
||||
AgentTaskExecutor agentTaskExecutor,
|
||||
@Nullable DeploymentLogManager logManager,
|
||||
CloudDeploymentNameProvider deploymentNameProvider,
|
||||
public CloudGitDeploymentRuntime(CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentSource source,
|
||||
File repositoryRoot,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> task,
|
||||
DeploymentLogManager logManager,
|
||||
String remoteName,
|
||||
String cloudName,
|
||||
ServerType<?> serverType) throws ServerRuntimeException {
|
||||
myConfiguration = serverConfiguration;
|
||||
myTasksExecutor = taskExecutor;
|
||||
myLogManager = logManager;
|
||||
String cloudName) throws ServerRuntimeException {
|
||||
super(serverRuntime, source, task, logManager);
|
||||
|
||||
myRemoteName = remoteName;
|
||||
myCloudName = cloudName;
|
||||
|
||||
DC deploymentConfiguration = task.getConfiguration();
|
||||
myRepositoryRootFile = repositoryRoot;
|
||||
|
||||
List<CloudGitDeploymentSourceHandlerProvider> handlerProviders
|
||||
= CloudGitDeploymentConfiguratorBase.getDeploymentSourceHandlerProviders(serverType);
|
||||
DeploymentSource deploymentSource = task.getSource();
|
||||
for (CloudGitDeploymentSourceHandlerProvider handlerProvider : handlerProviders) {
|
||||
DeploymentSourceHandler sourceHandler = handlerProvider.createHandler(this, deploymentSource, deploymentConfiguration);
|
||||
if (sourceHandler != null) {
|
||||
mySourceHandler = sourceHandler;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (mySourceHandler == null) {
|
||||
throw new ServerRuntimeException("Unknown deployment source");
|
||||
}
|
||||
|
||||
myContentRootFile = mySourceHandler.getRepositoryRootFile();
|
||||
|
||||
VirtualFile contentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myContentRootFile);
|
||||
VirtualFile contentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myRepositoryRootFile);
|
||||
LOG.assertTrue(contentRoot != null, "Repository root is not found");
|
||||
myContentRoot = contentRoot;
|
||||
|
||||
myProject = task.getProject();
|
||||
myGitRepositoryManager = GitUtil.getRepositoryManager(myProject);
|
||||
myGitRepositoryManager = GitUtil.getRepositoryManager(getProject());
|
||||
myGit = ServiceManager.getService(Git.class);
|
||||
if (myGit == null) {
|
||||
throw new ServerRuntimeException("Can't initialize GIT");
|
||||
}
|
||||
|
||||
myAgentTaskExecutor = agentTaskExecutor;
|
||||
myLoggingHandler = logManager == null ? new CloudSilentLoggingHandlerImpl() : new CloudLoggingHandlerImpl(logManager);
|
||||
|
||||
myPresentableName = deploymentSource.getPresentableName();
|
||||
|
||||
myApplicationName = deploymentConfiguration.isDefaultDeploymentName()
|
||||
? deploymentNameProvider.getDeploymentName(deploymentSource)
|
||||
: deploymentConfiguration.getDeploymentName();
|
||||
|
||||
myDeployment = agent.createDeployment(getApplicationName(), myLoggingHandler);
|
||||
}
|
||||
|
||||
public AgentTaskExecutor getAgentTaskExecutor() {
|
||||
return myAgentTaskExecutor;
|
||||
}
|
||||
|
||||
public AD getDeployment() {
|
||||
return myDeployment;
|
||||
}
|
||||
|
||||
public void deploy(ServerRuntimeInstance.DeploymentOperationCallback callback) {
|
||||
try {
|
||||
deploy();
|
||||
callback.succeeded(this);
|
||||
}
|
||||
catch (ServerRuntimeException e) {
|
||||
callback.errorOccurred(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void deploy() throws ServerRuntimeException {
|
||||
CloudGitApplication application = mySourceHandler.deploy();
|
||||
|
||||
if (myLogManager != null) {
|
||||
LoggingHandler loggingHandler = myLogManager.getMainLoggingHandler();
|
||||
loggingHandler.print("Application is available at ");
|
||||
loggingHandler.printHyperlink(application.getWebUrl());
|
||||
loggingHandler.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void undeploy(final @NotNull UndeploymentTaskCallback callback) {
|
||||
myTasksExecutor.submit(new ThrowableRunnable<Exception>() {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
try {
|
||||
undeploy();
|
||||
callback.succeeded();
|
||||
}
|
||||
catch (ServerRuntimeException e) {
|
||||
callback.errorOccurred(e.getMessage());
|
||||
}
|
||||
}
|
||||
}, callback);
|
||||
public CloudGitApplication deploy() throws ServerRuntimeException {
|
||||
CloudGitApplication application = findOrCreateApplication();
|
||||
GitRepository repository = findOrCreateRepository();
|
||||
addOrResetGitRemote(application, repository);
|
||||
add();
|
||||
commit();
|
||||
repository.update();
|
||||
pushApplication(application);
|
||||
return application;
|
||||
}
|
||||
|
||||
public void undeploy() throws ServerRuntimeException {
|
||||
if (!confirmUndeploy()) {
|
||||
throw new ServerRuntimeException("Undeploy cancelled");
|
||||
}
|
||||
myAgentTaskExecutor.execute(new Computable<Object>() {
|
||||
getAgentTaskExecutor().execute(new Computable<Object>() {
|
||||
|
||||
@Override
|
||||
public Object compute() {
|
||||
myDeployment.deleteApplication();
|
||||
getDeployment().deleteApplication();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -216,8 +119,8 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
public GitRepository findOrCreateRepository() throws ServerRuntimeException {
|
||||
GitRepository repository = findRepository();
|
||||
if (repository == null) {
|
||||
myLoggingHandler.println("Initializing git repository...");
|
||||
GitCommandResult gitInitResult = getGit().init(getProject(), getContentRoot(), createGitLineHandlerListener());
|
||||
getLoggingHandler().println("Initializing git repository...");
|
||||
GitCommandResult gitInitResult = getGit().init(getProject(), getRepositoryRoot(), createGitLineHandlerListener());
|
||||
checkGitResult(gitInitResult);
|
||||
|
||||
refreshApplicationRepository();
|
||||
@@ -239,24 +142,16 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
refreshContentRoot();
|
||||
}
|
||||
|
||||
protected Project getProject() {
|
||||
return myProject;
|
||||
}
|
||||
|
||||
private String getApplicationName() {
|
||||
return myApplicationName;
|
||||
}
|
||||
|
||||
protected Git getGit() {
|
||||
return myGit;
|
||||
}
|
||||
|
||||
protected VirtualFile getContentRoot() {
|
||||
protected VirtualFile getRepositoryRoot() {
|
||||
return myContentRoot;
|
||||
}
|
||||
|
||||
protected File getContentRootFile() {
|
||||
return myContentRootFile;
|
||||
protected File getRepositoryRootFile() {
|
||||
return myRepositoryRootFile;
|
||||
}
|
||||
|
||||
protected static void checkGitResult(GitCommandResult commandResult) throws ServerRuntimeException {
|
||||
@@ -277,7 +172,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
|
||||
@Override
|
||||
public void onLineAvailable(String line, Key outputType) {
|
||||
myLoggingHandler.println(line);
|
||||
getLoggingHandler().println(line);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -296,7 +191,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
String failMessage)
|
||||
throws ServerRuntimeException {
|
||||
try {
|
||||
final GitSimpleHandler handler = new GitSimpleHandler(myProject, myContentRoot, GitCommand.REMOTE);
|
||||
final GitSimpleHandler handler = new GitSimpleHandler(getProject(), myContentRoot, GitCommand.REMOTE);
|
||||
handler.setSilent(false);
|
||||
handler.addParameters(subCommand, remoteName, application.getGitUrl());
|
||||
handler.run();
|
||||
@@ -320,7 +215,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
}
|
||||
|
||||
protected void refreshApplicationRepository() {
|
||||
GitInit.refreshAndConfigureVcsMappings(myProject, getContentRoot(), getContentRootFile().getAbsolutePath());
|
||||
GitInit.refreshAndConfigureVcsMappings(getProject(), getRepositoryRoot(), getRepositoryRootFile().getAbsolutePath());
|
||||
}
|
||||
|
||||
protected void pushApplication(@NotNull CloudGitApplication application) throws ServerRuntimeException {
|
||||
@@ -339,7 +234,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
}
|
||||
|
||||
protected void fetch() throws ServerRuntimeException {
|
||||
final VirtualFile contentRoot = getContentRoot();
|
||||
final VirtualFile contentRoot = getRepositoryRoot();
|
||||
GitRepository repository = getRepository();
|
||||
final GitLineHandler fetchHandler = new GitLineHandler(getProject(), contentRoot, GitCommand.FETCH);
|
||||
fetchHandler.setSilent(false);
|
||||
@@ -375,7 +270,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
}
|
||||
|
||||
protected void performRemoteGitTask(final GitLineHandler handler, String title) throws ServerRuntimeException {
|
||||
final GitTask task = new GitTask(myProject, handler, title);
|
||||
final GitTask task = new GitTask(getProject(), handler, title);
|
||||
task.setProgressAnalyzer(new GitStandardProgressAnalyzer());
|
||||
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
@@ -398,7 +293,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
@Override
|
||||
protected void onFailure() {
|
||||
for (VcsException error : handler.errors()) {
|
||||
myLoggingHandler.println(error.toString());
|
||||
getLoggingHandler().println(error.toString());
|
||||
if (errorRef.isNull()) {
|
||||
errorRef.set(new ServerRuntimeException(error));
|
||||
}
|
||||
@@ -419,35 +314,12 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
getContentRoot().refresh(false, true);
|
||||
getRepositoryRoot().refresh(false, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected boolean confirmUndeploy() {
|
||||
final Ref<Boolean> confirmed = new Ref<Boolean>(false);
|
||||
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
String title = CloudBundle.getText("cloud.undeploy.confirm.title");
|
||||
while (true) {
|
||||
String password = Messages.showPasswordDialog(CloudBundle.getText("cloud.undeploy.confirm.message", myPresentableName), title);
|
||||
if (password == null) {
|
||||
return;
|
||||
}
|
||||
if (password.equals(myConfiguration.getPassword())) {
|
||||
confirmed.set(true);
|
||||
return;
|
||||
}
|
||||
Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
|
||||
}
|
||||
}
|
||||
}, ModalityState.defaultModalityState());
|
||||
return confirmed.get();
|
||||
}
|
||||
|
||||
protected String getRemoteName() {
|
||||
private String getRemoteName() {
|
||||
return myRemoteName;
|
||||
}
|
||||
|
||||
@@ -456,21 +328,21 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
}
|
||||
|
||||
protected CloudGitApplication findApplication() throws ServerRuntimeException {
|
||||
return myAgentTaskExecutor.execute(new Computable<CloudGitApplication>() {
|
||||
return getAgentTaskExecutor().execute(new Computable<CloudGitApplication>() {
|
||||
|
||||
@Override
|
||||
public CloudGitApplication compute() {
|
||||
return myDeployment.findApplication();
|
||||
return getDeployment().findApplication();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected CloudGitApplication createApplication() throws ServerRuntimeException {
|
||||
return myAgentTaskExecutor.execute(new Computable<CloudGitApplication>() {
|
||||
return getAgentTaskExecutor().execute(new Computable<CloudGitApplication>() {
|
||||
|
||||
@Override
|
||||
public CloudGitApplication compute() {
|
||||
return myDeployment.createApplication();
|
||||
return getDeployment().createApplication();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -497,7 +369,7 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
File cloneDir = cloneToTemp(gitUrl);
|
||||
|
||||
try {
|
||||
FileUtil.copyDir(cloneDir, getContentRootFile());
|
||||
FileUtil.copyDir(cloneDir, getRepositoryRootFile());
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ServerRuntimeException(e);
|
||||
@@ -528,37 +400,4 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
|
||||
performRemoteGitTask(handler, CloudBundle.getText("cloning.existing.application", getCloudName()));
|
||||
}
|
||||
}
|
||||
|
||||
public class ModuleDeploymentSourceHandler implements DeploymentSourceHandler {
|
||||
|
||||
private final File myRepositoryRootFile;
|
||||
|
||||
public ModuleDeploymentSourceHandler(ModuleDeploymentSource deploymentSource) throws ServerRuntimeException {
|
||||
Module module = deploymentSource.getModule();
|
||||
if (module == null) {
|
||||
throw new ServerRuntimeException("Module not found: " + deploymentSource.getModulePointer().getModuleName());
|
||||
}
|
||||
|
||||
File contentRootFile = deploymentSource.getFile();
|
||||
LOG.assertTrue(contentRootFile != null, "Content root file is not found");
|
||||
myRepositoryRootFile = contentRootFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getRepositoryRootFile() {
|
||||
return myRepositoryRootFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudGitApplication deploy() throws ServerRuntimeException {
|
||||
CloudGitApplication application = findOrCreateApplication();
|
||||
GitRepository repository = findOrCreateRepository();
|
||||
addOrResetGitRemote(application, repository);
|
||||
add();
|
||||
commit();
|
||||
repository.update();
|
||||
pushApplication(application);
|
||||
return application;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public interface CloudGitDeploymentSourceHandlerProvider {
|
||||
|
||||
ExtensionPointName<CloudGitDeploymentSourceHandlerProvider> EP_NAME
|
||||
= ExtensionPointName.create("Git4Idea.remoteServer.CloudGitDeploymentSourceHandlerProvider");
|
||||
|
||||
@Nullable
|
||||
ServerType<?> getServerType();
|
||||
|
||||
Collection<DeploymentSource> getDeploymentSources(Project project);
|
||||
|
||||
DeploymentSourceHandler createHandler(CloudGitDeploymentRuntime<?, ?, ?> deploymentRuntime,
|
||||
DeploymentSource deploymentSource,
|
||||
DeploymentConfiguration deploymentConfiguration)
|
||||
throws ServerRuntimeException;
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModulePointerManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource;
|
||||
import com.intellij.remoteServer.impl.configuration.deployment.ModuleDeploymentSourceImpl;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentLogManager;
|
||||
import com.intellij.remoteServer.runtime.deployment.DeploymentTask;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public abstract class CloudModuleDeploymentRuntimeProviderBase implements CloudDeploymentRuntimeProvider {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance("#" + CloudModuleDeploymentRuntimeProviderBase.class.getName());
|
||||
|
||||
@Override
|
||||
public Collection<DeploymentSource> getDeploymentSources(Project project) {
|
||||
List<DeploymentSource> result = new ArrayList<DeploymentSource>();
|
||||
ModulePointerManager pointerManager = ModulePointerManager.getInstance(project);
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
result.add(new ModuleDeploymentSourceImpl(pointerManager.create(module)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudDeploymentRuntime createDeploymentRuntime(DeploymentSource source,
|
||||
CloudMultiSourceServerRuntimeInstance serverRuntime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager)
|
||||
throws ServerRuntimeException {
|
||||
if (!(source instanceof ModuleDeploymentSource)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ModuleDeploymentSource moduleSource = (ModuleDeploymentSource)source;
|
||||
Module module = moduleSource.getModule();
|
||||
if (module == null) {
|
||||
throw new ServerRuntimeException("Module not found: " + moduleSource.getModulePointer().getModuleName());
|
||||
}
|
||||
|
||||
File contentRootFile = source.getFile();
|
||||
LOG.assertTrue(contentRootFile != null, "Content root file is not found");
|
||||
|
||||
return doCreateDeploymentRuntime(moduleSource, contentRootFile, serverRuntime, deploymentTask, logManager);
|
||||
}
|
||||
|
||||
protected abstract CloudDeploymentRuntime doCreateDeploymentRuntime(ModuleDeploymentSource moduleSource,
|
||||
File contentRootFile,
|
||||
CloudMultiSourceServerRuntimeInstance runtime,
|
||||
DeploymentTask<? extends CloudDeploymentNameConfiguration> deploymentTask,
|
||||
DeploymentLogManager logManager) throws ServerRuntimeException;
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
package com.intellij.remoteServer.util;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModulePointerManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.remoteServer.ServerType;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration;
|
||||
import com.intellij.remoteServer.configuration.deployment.DeploymentSource;
|
||||
import com.intellij.remoteServer.configuration.deployment.ModuleDeploymentSource;
|
||||
import com.intellij.remoteServer.impl.configuration.deployment.ModuleDeploymentSourceImpl;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author michael.golubev
|
||||
*/
|
||||
public class ModuleDeploymentSourceHandlerProvider implements CloudGitDeploymentSourceHandlerProvider {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ServerType<?> getServerType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DeploymentSource> getDeploymentSources(Project project) {
|
||||
List<DeploymentSource> result = new ArrayList<DeploymentSource>();
|
||||
ModulePointerManager pointerManager = ModulePointerManager.getInstance(project);
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
result.add(new ModuleDeploymentSourceImpl(pointerManager.create(module)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeploymentSourceHandler createHandler(CloudGitDeploymentRuntime<?, ?, ?> deploymentRuntime,
|
||||
DeploymentSource deploymentSource,
|
||||
DeploymentConfiguration deploymentConfiguration)
|
||||
throws ServerRuntimeException {
|
||||
if (!(deploymentSource instanceof ModuleDeploymentSource)) {
|
||||
return null;
|
||||
}
|
||||
return deploymentRuntime.new ModuleDeploymentSourceHandler((ModuleDeploymentSource)deploymentSource);
|
||||
}
|
||||
}
|
||||
@@ -193,13 +193,5 @@
|
||||
|
||||
<extensionPoints>
|
||||
<extensionPoint qualifiedName="Git4Idea.GitHttpAuthDataProvider" interface="git4idea.jgit.GitHttpAuthDataProvider"/>
|
||||
|
||||
<extensionPoint qualifiedName="Git4Idea.remoteServer.CloudGitDeploymentSourceHandlerProvider"
|
||||
interface="com.intellij.remoteServer.util.CloudGitDeploymentSourceHandlerProvider"/>
|
||||
</extensionPoints>
|
||||
|
||||
<extensions defaultExtensionNs="Git4Idea">
|
||||
<remoteServer.CloudGitDeploymentSourceHandlerProvider
|
||||
implementation="com.intellij.remoteServer.util.ModuleDeploymentSourceHandlerProvider"/>
|
||||
</extensions>
|
||||
</idea-plugin>
|
||||
|
||||
Reference in New Issue
Block a user