diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/project/CreateProject.java b/gerrit-server/src/main/java/com/google/gerrit/server/project/CreateProject.java index aa120e12ce..32c4ef850e 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/project/CreateProject.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/project/CreateProject.java @@ -45,19 +45,19 @@ import java.util.List; @RequiresCapability(GlobalCapability.CREATE_PROJECT) public class CreateProject implements RestModifyView { public static class Input { - String name; - String parent; - String description; - boolean permissionsOnly; - boolean createEmptyCommit; - SubmitType submitType; - List branches; - List owners; - InheritableBoolean useContributorAgreements; - InheritableBoolean useSignedOffBy; - InheritableBoolean useContentMerge; - InheritableBoolean requireChangeId; - String maxObjectSizeLimit; + public String name; + public String parent; + public String description; + public boolean permissionsOnly; + public boolean createEmptyCommit; + public SubmitType submitType; + public List branches; + public List owners; + public InheritableBoolean useContributorAgreements; + public InheritableBoolean useSignedOffBy; + public InheritableBoolean useContentMerge; + public InheritableBoolean requireChangeId; + public String maxObjectSizeLimit; } public static interface Factory { diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateProjectCommand.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateProjectCommand.java index 90c5e9460f..90c1f2c03f 100644 --- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateProjectCommand.java +++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/CreateProjectCommand.java @@ -14,24 +14,31 @@ package com.google.gerrit.sshd.commands; +import com.google.common.base.Function; +import com.google.common.collect.Lists; import com.google.gerrit.common.data.GlobalCapability; import com.google.gerrit.common.errors.ProjectCreationFailedException; import com.google.gerrit.extensions.annotations.RequiresCapability; +import com.google.gerrit.extensions.restapi.RestApiException; +import com.google.gerrit.extensions.restapi.TopLevelResource; import com.google.gerrit.reviewdb.client.AccountGroup; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project.InheritableBoolean; import com.google.gerrit.reviewdb.client.Project.SubmitType; -import com.google.gerrit.server.project.PerformCreateProject; -import com.google.gerrit.server.project.CreateProjectArgs; +import com.google.gerrit.server.project.CreateProject; +import com.google.gerrit.server.project.NoSuchProjectException; import com.google.gerrit.server.project.ProjectControl; import com.google.gerrit.server.project.SuggestParentCandidates; import com.google.gerrit.sshd.CommandMetaData; import com.google.gerrit.sshd.SshCommand; +import com.google.gwtorm.server.OrmException; import com.google.inject.Inject; +import com.google.inject.Provider; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; +import java.io.IOException; import java.util.List; /** Create a new project. **/ @@ -120,35 +127,46 @@ final class CreateProjectCommand extends SshCommand { } @Inject - private PerformCreateProject.Factory factory; + private Provider createProjectFactory; @Inject private SuggestParentCandidates.Factory suggestParentCandidatesFactory; @Override - protected void run() throws Exception { + protected void run() throws UnloggedFailure { try { if (!suggestParent) { if (projectName == null) { throw new UnloggedFailure(1, "fatal: Project name is required."); } - final CreateProjectArgs args = new CreateProjectArgs(); - args.setProjectName(projectName); - args.ownerIds = ownerIds; - args.newParent = newParent; - args.permissionsOnly = permissionsOnly; - args.projectDescription = projectDescription; - args.submitType = submitType; - args.contributorAgreements = contributorAgreements; - args.signedOffBy = signedOffBy; - args.contentMerge = contentMerge; - args.changeIdRequired = requireChangeID; - args.branch = branch; - args.createEmptyCommit = createEmptyCommit; - args.maxObjectSizeLimit = maxObjectSizeLimit; - final PerformCreateProject createProject = factory.create(args); - createProject.createProject(); + CreateProject.Input input = new CreateProject.Input(); + input.name = projectName; + if (ownerIds != null) { + input.owners = Lists.transform(ownerIds, + new Function() { + @Override + public String apply(AccountGroup.UUID uuid) { + return uuid.get(); + } + }); + } + if (newParent != null) { + input.parent = newParent.getProject().getName(); + } + input.permissionsOnly = permissionsOnly; + input.description = projectDescription; + input.submitType = submitType; + input.useContributorAgreements = contributorAgreements; + input.useSignedOffBy = signedOffBy; + input.useContentMerge = contentMerge; + input.requireChangeId = requireChangeID; + input.branches = branch; + input.createEmptyCommit = createEmptyCommit; + input.maxObjectSizeLimit = maxObjectSizeLimit; + + createProjectFactory.get().create(projectName) + .apply(TopLevelResource.INSTANCE, input); } else { List parentCandidates = suggestParentCandidatesFactory.create().getNameKeys(); @@ -157,7 +175,8 @@ final class CreateProjectCommand extends SshCommand { stdout.print(parent + "\n"); } } - } catch (ProjectCreationFailedException err) { + } catch (RestApiException | ProjectCreationFailedException | IOException + | NoSuchProjectException | OrmException err) { throw new UnloggedFailure(1, "fatal: " + err.getMessage(), err); } }