CR-IU-410 - replace init method with constructor

This commit is contained in:
Michael Golubev
2013-11-27 19:47:04 +01:00
parent 661b9da0f4
commit 6534861611
7 changed files with 97 additions and 78 deletions
@@ -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;
}
}
@@ -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;
@@ -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<D extends DeploymentCon
myServerType = serverType;
}
@Nullable
public static CloudGitDeploymentSourceHandlerProvider getDeploymentSourceHandlerProvider(ServerType<?> serverType) {
public static List<CloudGitDeploymentSourceHandlerProvider> getDeploymentSourceHandlerProviders(ServerType<?> serverType) {
List<CloudGitDeploymentSourceHandlerProvider> result = new ArrayList<CloudGitDeploymentSourceHandlerProvider>();
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<D extends DeploymentCon
public List<DeploymentSource> getAvailableDeploymentSources() {
if (myProject.isDefault()) return Collections.emptyList();
List<DeploymentSource> result = new ArrayList<DeploymentSource>();
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;
@@ -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<DC extends CloudDeploymentNameCo
myRemoteName = remoteName;
myCloudName = cloudName;
List<DeploymentSourceHandler> handlers = new ArrayList<DeploymentSourceHandler>();
handlers.add(new ModuleDeploymentSourceHandler());
CloudGitDeploymentSourceHandlerProvider handlerProvider
= CloudGitDeploymentConfiguratorBase.getDeploymentSourceHandlerProvider(serverType);
if (handlerProvider != null) {
handlers.addAll(handlerProvider.getHandlers(this));
}
List<CloudGitDeploymentSourceHandlerProvider> 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<DC extends CloudDeploymentNameCo
throw new ServerRuntimeException("Unknown deployment source");
}
File contentRootFile = mySourceHandler.getRepositoryRootFile();
myContentRootFile = contentRootFile;
myContentRootFile = mySourceHandler.getRepositoryRootFile();
VirtualFile contentRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(myContentRootFile);
LOG.assertTrue(contentRoot != null, "Repository root is not found");
@@ -539,31 +533,24 @@ public abstract class CloudGitDeploymentRuntime<DC extends CloudDeploymentNameCo
public class ModuleDeploymentSourceHandler implements DeploymentSourceHandler {
private File myRepositoryRootFile;
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 boolean init(DeploymentSource deploymentSource) throws ServerRuntimeException {
if (!(deploymentSource instanceof ModuleDeploymentSource)) {
return false;
}
ModuleDeploymentSource moduleDeploymentSource = (ModuleDeploymentSource)deploymentSource;
Module module = moduleDeploymentSource.getModule();
if (module == null) {
throw new ServerRuntimeException("Module not found: " + moduleDeploymentSource.getModulePointer().getModuleName());
}
File contentRootFile = moduleDeploymentSource.getFile();
LOG.assertTrue(contentRootFile != null, "Content root file is not found");
myRepositoryRootFile = contentRootFile;
return true;
}
@Override
public CloudGitApplication deploy() throws ServerRuntimeException {
CloudGitApplication application = findOrCreateApplication();
@@ -4,9 +4,9 @@ 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 org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.List;
/**
* @author michael.golubev
@@ -16,9 +16,11 @@ public interface CloudGitDeploymentSourceHandlerProvider {
ExtensionPointName<CloudGitDeploymentSourceHandlerProvider> EP_NAME
= ExtensionPointName.create("Git4Idea.remoteServer.CloudGitDeploymentSourceHandlerProvider");
@Nullable
ServerType<?> getServerType();
Collection<DeploymentSource> getDeploymentSources(Project project);
List<DeploymentSourceHandler> getHandlers(CloudGitDeploymentRuntime<?, ?, ?> deploymentRuntime);
DeploymentSourceHandler createHandler(CloudGitDeploymentRuntime<?, ?, ?> deploymentRuntime, DeploymentSource deploymentSource)
throws ServerRuntimeException;
}
@@ -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<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)
throws ServerRuntimeException {
if (!(deploymentSource instanceof ModuleDeploymentSource)) {
return null;
}
return deploymentRuntime.new ModuleDeploymentSourceHandler((ModuleDeploymentSource)deploymentSource);
}
}
+5
View File
@@ -197,4 +197,9 @@
<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>