From 6534861611b7f3a3941ef56905fd07b48bef6a42 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Wed, 27 Nov 2013 19:47:04 +0100 Subject: [PATCH] CR-IU-410 - replace init method with constructor --- .../ArtifactDeploymentSourceHandlerBase.java | 43 +++++++--------- .../util/DeploymentSourceHandler.java | 3 -- .../CloudGitDeploymentConfiguratorBase.java | 23 +++------ .../util/CloudGitDeploymentRuntime.java | 49 +++++++------------ ...oudGitDeploymentSourceHandlerProvider.java | 6 ++- ...ModuleDeploymentSourceHandlerProvider.java | 46 +++++++++++++++++ plugins/git4idea/src/META-INF/plugin.xml | 5 ++ 7 files changed, 97 insertions(+), 78 deletions(-) create mode 100644 plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/ModuleDeploymentSourceHandlerProvider.java diff --git a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/util/ArtifactDeploymentSourceHandlerBase.java b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/util/ArtifactDeploymentSourceHandlerBase.java index f30bdd7f3bcd..314900bdb8f3 100644 --- a/java/remote-servers/impl/src/com/intellij/remoteServer/impl/util/ArtifactDeploymentSourceHandlerBase.java +++ b/java/remote-servers/impl/src/com/intellij/remoteServer/impl/util/ArtifactDeploymentSourceHandlerBase.java @@ -18,7 +18,6 @@ package com.intellij.remoteServer.impl.util; import com.intellij.openapi.diagnostic.Logger; import com.intellij.packaging.artifacts.Artifact; import com.intellij.remoteServer.configuration.deployment.ArtifactDeploymentSource; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; import com.intellij.remoteServer.util.DeploymentSourceHandler; import com.intellij.remoteServer.util.ServerRuntimeException; @@ -31,8 +30,23 @@ public abstract class ArtifactDeploymentSourceHandlerBase implements DeploymentS private static final Logger LOG = Logger.getInstance("#" + ArtifactDeploymentSourceHandlerBase.class.getName()); - private Artifact myArtifact; - private File myRepositoryRootFile; + private final Artifact myArtifact; + private final File myRepositoryRootFile; + + public ArtifactDeploymentSourceHandlerBase(ArtifactDeploymentSource deploymentSource) throws ServerRuntimeException { + Artifact artifact = deploymentSource.getArtifact(); + if (artifact == null) { + throw new ServerRuntimeException("Artifact not found " + deploymentSource.getArtifactPointer().getArtifactName()); + } + + String outputPath = artifact.getOutputPath(); + LOG.assertTrue(outputPath != null, "Artifact output path not found"); + myRepositoryRootFile = new File(outputPath, "/deploy"); + if (!myRepositoryRootFile.exists() && !myRepositoryRootFile.mkdir()) { + throw new ServerRuntimeException("Unable to create deploy folder"); + } + myArtifact = artifact; + } protected File getArtifactFile() { return new File(myArtifact.getOutputFilePath()); @@ -42,27 +56,4 @@ public abstract class ArtifactDeploymentSourceHandlerBase implements DeploymentS public File getRepositoryRootFile() { return myRepositoryRootFile; } - - @Override - public boolean init(DeploymentSource deploymentSource) throws ServerRuntimeException { - if (!(deploymentSource instanceof ArtifactDeploymentSource)) { - return false; - } - ArtifactDeploymentSource artifactDeploymentSource = (ArtifactDeploymentSource)deploymentSource; - Artifact artifact = artifactDeploymentSource.getArtifact(); - if (artifact == null) { - throw new ServerRuntimeException("Artifact not found " + artifactDeploymentSource.getArtifactPointer().getArtifactName()); - } - - String outputPath = artifact.getOutputPath(); - LOG.assertTrue(outputPath != null, "Artifact output path not found"); - myRepositoryRootFile = new File(outputPath, "/deploy"); - if (!myRepositoryRootFile.exists()) { - if (!myRepositoryRootFile.mkdir()) { - throw new ServerRuntimeException("Unable to create deploy folder"); - } - } - myArtifact = artifact; - return true; - } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DeploymentSourceHandler.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DeploymentSourceHandler.java index 0dba5d2932b5..64a8599eacd6 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DeploymentSourceHandler.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/util/DeploymentSourceHandler.java @@ -16,7 +16,6 @@ package com.intellij.remoteServer.util; import com.intellij.remoteServer.agent.util.CloudGitApplication; -import com.intellij.remoteServer.configuration.deployment.DeploymentSource; import java.io.File; @@ -25,8 +24,6 @@ import java.io.File; */ public interface DeploymentSourceHandler { - boolean init(DeploymentSource deploymentSource) throws ServerRuntimeException; - File getRepositoryRootFile(); CloudGitApplication deploy() throws ServerRuntimeException; diff --git a/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentConfiguratorBase.java b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentConfiguratorBase.java index c1fb091012cc..40b7a23c2d67 100644 --- a/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentConfiguratorBase.java +++ b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentConfiguratorBase.java @@ -1,17 +1,12 @@ 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.ServerConfiguration; import com.intellij.remoteServer.configuration.deployment.DeploymentConfiguration; import com.intellij.remoteServer.configuration.deployment.DeploymentConfigurator; import com.intellij.remoteServer.configuration.deployment.DeploymentSource; -import com.intellij.remoteServer.impl.configuration.deployment.ModuleDeploymentSourceImpl; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collections; @@ -31,14 +26,15 @@ public abstract class CloudGitDeploymentConfiguratorBase serverType) { + public static List getDeploymentSourceHandlerProviders(ServerType serverType) { + List result = new ArrayList(); for (CloudGitDeploymentSourceHandlerProvider provider : CloudGitDeploymentSourceHandlerProvider.EP_NAME.getExtensions()) { - if (provider.getServerType() == serverType) { - return provider; + ServerType providerServerType = provider.getServerType(); + if (providerServerType == null || providerServerType == serverType) { + result.add(provider); } } - return null; + return result; } @NotNull @@ -46,12 +42,7 @@ public abstract class CloudGitDeploymentConfiguratorBase getAvailableDeploymentSources() { if (myProject.isDefault()) return Collections.emptyList(); List result = new ArrayList(); - ModulePointerManager pointerManager = ModulePointerManager.getInstance(myProject); - for (Module module : ModuleManager.getInstance(myProject).getModules()) { - result.add(new ModuleDeploymentSourceImpl(pointerManager.create(module))); - } - CloudGitDeploymentSourceHandlerProvider provider = getDeploymentSourceHandlerProvider(myServerType); - if (provider != null) { + for (CloudGitDeploymentSourceHandlerProvider provider : getDeploymentSourceHandlerProviders(myServerType)) { result.addAll(provider.getDeploymentSources(myProject)); } return result; diff --git a/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentRuntime.java b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentRuntime.java index 74bf0ea3b8e5..9e97de507a75 100644 --- a/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentRuntime.java +++ b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/CloudGitDeploymentRuntime.java @@ -40,7 +40,6 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; -import java.util.ArrayList; import java.util.List; /** @@ -90,16 +89,12 @@ public abstract class CloudGitDeploymentRuntime handlers = new ArrayList(); - handlers.add(new ModuleDeploymentSourceHandler()); - CloudGitDeploymentSourceHandlerProvider handlerProvider - = CloudGitDeploymentConfiguratorBase.getDeploymentSourceHandlerProvider(serverType); - if (handlerProvider != null) { - handlers.addAll(handlerProvider.getHandlers(this)); - } + List handlerProviders + = CloudGitDeploymentConfiguratorBase.getDeploymentSourceHandlerProviders(serverType); DeploymentSource deploymentSource = task.getSource(); - for (DeploymentSourceHandler sourceHandler : handlers) { - if (sourceHandler.init(deploymentSource)) { + for (CloudGitDeploymentSourceHandlerProvider handlerProvider : handlerProviders) { + DeploymentSourceHandler sourceHandler = handlerProvider.createHandler(this, deploymentSource); + if (sourceHandler != null) { mySourceHandler = sourceHandler; break; } @@ -108,8 +103,7 @@ public abstract class CloudGitDeploymentRuntime EP_NAME = ExtensionPointName.create("Git4Idea.remoteServer.CloudGitDeploymentSourceHandlerProvider"); + @Nullable ServerType getServerType(); Collection getDeploymentSources(Project project); - List getHandlers(CloudGitDeploymentRuntime deploymentRuntime); + DeploymentSourceHandler createHandler(CloudGitDeploymentRuntime deploymentRuntime, DeploymentSource deploymentSource) + throws ServerRuntimeException; } diff --git a/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/ModuleDeploymentSourceHandlerProvider.java b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/ModuleDeploymentSourceHandlerProvider.java new file mode 100644 index 000000000000..657c426990fc --- /dev/null +++ b/plugins/git4idea/remote-servers-git/src/com/intellij/remoteServer/util/ModuleDeploymentSourceHandlerProvider.java @@ -0,0 +1,46 @@ +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.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 getDeploymentSources(Project project) { + List result = new ArrayList(); + 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) + throws ServerRuntimeException { + if (!(deploymentSource instanceof ModuleDeploymentSource)) { + return null; + } + return deploymentRuntime.new ModuleDeploymentSourceHandler((ModuleDeploymentSource)deploymentSource); + } +} diff --git a/plugins/git4idea/src/META-INF/plugin.xml b/plugins/git4idea/src/META-INF/plugin.xml index 1d2beb25ad28..4c2c787074f0 100644 --- a/plugins/git4idea/src/META-INF/plugin.xml +++ b/plugins/git4idea/src/META-INF/plugin.xml @@ -197,4 +197,9 @@ + + + +