Merge changes I082ab755,I789c9a09
* changes: Create project through web interface Create project refactoring
This commit is contained in:
@@ -41,6 +41,7 @@ public class PageLinks {
|
|||||||
public static final String MINE = "/";
|
public static final String MINE = "/";
|
||||||
public static final String ADMIN_GROUPS = "/admin/groups/";
|
public static final String ADMIN_GROUPS = "/admin/groups/";
|
||||||
public static final String ADMIN_PROJECTS = "/admin/projects/";
|
public static final String ADMIN_PROJECTS = "/admin/projects/";
|
||||||
|
public static final String ADMIN_CREATE_PROJECT = "/admin/create-project/";
|
||||||
|
|
||||||
public static String toChange(final ChangeInfo c) {
|
public static String toChange(final ChangeInfo c) {
|
||||||
return toChange(c.getId());
|
return toChange(c.getId());
|
||||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.reviewdb.Project;
|
|||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
import com.google.gwtjsonrpc.client.RemoteJsonService;
|
||||||
import com.google.gwtjsonrpc.client.RpcImpl;
|
import com.google.gwtjsonrpc.client.RpcImpl;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
import com.google.gwtjsonrpc.client.RpcImpl.Version;
|
import com.google.gwtjsonrpc.client.RpcImpl.Version;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -27,13 +28,18 @@ import java.util.Set;
|
|||||||
|
|
||||||
@RpcImpl(version = Version.V2_0)
|
@RpcImpl(version = Version.V2_0)
|
||||||
public interface ProjectAdminService extends RemoteJsonService {
|
public interface ProjectAdminService extends RemoteJsonService {
|
||||||
void visibleProjects(AsyncCallback<List<Project>> callback);
|
void visibleProjects(AsyncCallback<ProjectList> callback);
|
||||||
|
|
||||||
void visibleProjectDetails(AsyncCallback<List<ProjectDetail>> callback);
|
void visibleProjectDetails(AsyncCallback<List<ProjectDetail>> callback);
|
||||||
|
|
||||||
void projectDetail(Project.NameKey projectName,
|
void projectDetail(Project.NameKey projectName,
|
||||||
AsyncCallback<ProjectDetail> callback);
|
AsyncCallback<ProjectDetail> callback);
|
||||||
|
|
||||||
|
@SignInRequired
|
||||||
|
void createNewProject(String projectName, String parentName,
|
||||||
|
boolean emptyCommit, boolean permissionsOnly,
|
||||||
|
AsyncCallback<VoidResult> callback);
|
||||||
|
|
||||||
void projectAccess(Project.NameKey projectName,
|
void projectAccess(Project.NameKey projectName,
|
||||||
AsyncCallback<ProjectAccess> callback);
|
AsyncCallback<ProjectAccess> callback);
|
||||||
|
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.common.data;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ProjectList {
|
||||||
|
protected List<Project> projects;
|
||||||
|
protected boolean canCreateProject;
|
||||||
|
|
||||||
|
public ProjectList() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Project> getProjects() {
|
||||||
|
return projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjects(List<Project> projects) {
|
||||||
|
this.projects = projects;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canCreateProject() {
|
||||||
|
return canCreateProject;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCanCreateProject(boolean canCreateProject) {
|
||||||
|
this.canCreateProject = canCreateProject;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,29 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.common.errors;
|
||||||
|
|
||||||
|
/** Error indicating failed to create new project. */
|
||||||
|
public class ProjectCreationFailedException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public ProjectCreationFailedException(final String message) {
|
||||||
|
this(message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectCreationFailedException(final String message,
|
||||||
|
final Throwable why) {
|
||||||
|
super(message, why);
|
||||||
|
}
|
||||||
|
}
|
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.client;
|
package com.google.gerrit.client;
|
||||||
|
|
||||||
|
import static com.google.gerrit.common.PageLinks.ADMIN_CREATE_PROJECT;
|
||||||
import static com.google.gerrit.common.PageLinks.ADMIN_GROUPS;
|
import static com.google.gerrit.common.PageLinks.ADMIN_GROUPS;
|
||||||
import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
|
import static com.google.gerrit.common.PageLinks.ADMIN_PROJECTS;
|
||||||
import static com.google.gerrit.common.PageLinks.MINE;
|
import static com.google.gerrit.common.PageLinks.MINE;
|
||||||
@@ -45,6 +46,7 @@ import com.google.gerrit.client.account.ValidateEmailScreen;
|
|||||||
import com.google.gerrit.client.admin.AccountGroupInfoScreen;
|
import com.google.gerrit.client.admin.AccountGroupInfoScreen;
|
||||||
import com.google.gerrit.client.admin.AccountGroupMembersScreen;
|
import com.google.gerrit.client.admin.AccountGroupMembersScreen;
|
||||||
import com.google.gerrit.client.admin.AccountGroupScreen;
|
import com.google.gerrit.client.admin.AccountGroupScreen;
|
||||||
|
import com.google.gerrit.client.admin.CreateProjectScreen;
|
||||||
import com.google.gerrit.client.admin.GroupListScreen;
|
import com.google.gerrit.client.admin.GroupListScreen;
|
||||||
import com.google.gerrit.client.admin.ProjectAccessScreen;
|
import com.google.gerrit.client.admin.ProjectAccessScreen;
|
||||||
import com.google.gerrit.client.admin.ProjectBranchesScreen;
|
import com.google.gerrit.client.admin.ProjectBranchesScreen;
|
||||||
@@ -579,6 +581,10 @@ public class Dispatcher {
|
|||||||
} else if (matchPrefix("/admin/projects/", token)) {
|
} else if (matchPrefix("/admin/projects/", token)) {
|
||||||
Gerrit.display(token, selectProject());
|
Gerrit.display(token, selectProject());
|
||||||
|
|
||||||
|
} else if (matchExact(ADMIN_CREATE_PROJECT, token)
|
||||||
|
|| matchExact("/admin/create-project", token)) {
|
||||||
|
Gerrit.display(token, new CreateProjectScreen());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Gerrit.display(token, new NotFoundScreen());
|
Gerrit.display(token, new NotFoundScreen());
|
||||||
}
|
}
|
||||||
|
@@ -80,6 +80,8 @@ public interface GerritCss extends CssResource {
|
|||||||
String contributorAgreementLegal();
|
String contributorAgreementLegal();
|
||||||
String contributorAgreementShortDescription();
|
String contributorAgreementShortDescription();
|
||||||
String coverMessage();
|
String coverMessage();
|
||||||
|
String createProjectLink();
|
||||||
|
String createProjectPanel();
|
||||||
String dataCell();
|
String dataCell();
|
||||||
String dataHeader();
|
String dataHeader();
|
||||||
String diffLinkCell();
|
String diffLinkCell();
|
||||||
|
@@ -22,7 +22,7 @@ import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
|||||||
import com.google.gerrit.client.ui.ProjectsTable;
|
import com.google.gerrit.client.ui.ProjectsTable;
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
import com.google.gerrit.common.data.AccountProjectWatchInfo;
|
import com.google.gerrit.common.data.AccountProjectWatchInfo;
|
||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.common.data.ProjectList;
|
||||||
import com.google.gwt.event.dom.client.ClickEvent;
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
import com.google.gwt.event.dom.client.ClickHandler;
|
import com.google.gwt.event.dom.client.ClickHandler;
|
||||||
import com.google.gwt.event.dom.client.KeyCodes;
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
@@ -362,10 +362,10 @@ public class MyWatchedProjectsScreen extends SettingsScreen implements
|
|||||||
|
|
||||||
protected void populateProjects() {
|
protected void populateProjects() {
|
||||||
Util.PROJECT_SVC.visibleProjects(
|
Util.PROJECT_SVC.visibleProjects(
|
||||||
new GerritCallback<List<Project>>() {
|
new GerritCallback<ProjectList>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final List<Project> result) {
|
public void onSuccess(final ProjectList result) {
|
||||||
projectsTab.display(result);
|
projectsTab.display(result.getProjects());
|
||||||
if (firstPopupLoad) { // Display was delayed until table was loaded
|
if (firstPopupLoad) { // Display was delayed until table was loaded
|
||||||
firstPopupLoad = false;
|
firstPopupLoad = false;
|
||||||
displayPopup();
|
displayPopup();
|
||||||
|
@@ -31,10 +31,13 @@ public interface AdminConstants extends Constants {
|
|||||||
String buttonSaveDescription();
|
String buttonSaveDescription();
|
||||||
String buttonRenameGroup();
|
String buttonRenameGroup();
|
||||||
String buttonCreateGroup();
|
String buttonCreateGroup();
|
||||||
|
String buttonCreateProject();
|
||||||
String buttonChangeGroupOwner();
|
String buttonChangeGroupOwner();
|
||||||
String buttonChangeGroupType();
|
String buttonChangeGroupType();
|
||||||
String buttonSelectGroup();
|
String buttonSelectGroup();
|
||||||
String buttonSaveChanges();
|
String buttonSaveChanges();
|
||||||
|
String checkBoxEmptyCommit();
|
||||||
|
String checkBoxPermissionsOnly();
|
||||||
String useContentMerge();
|
String useContentMerge();
|
||||||
String useContributorAgreements();
|
String useContributorAgreements();
|
||||||
String useSignedOffBy();
|
String useSignedOffBy();
|
||||||
@@ -56,6 +59,9 @@ public interface AdminConstants extends Constants {
|
|||||||
String noMembersInfo();
|
String noMembersInfo();
|
||||||
String headingExternalGroup();
|
String headingExternalGroup();
|
||||||
String headingCreateGroup();
|
String headingCreateGroup();
|
||||||
|
String headingCreateProject();
|
||||||
|
String headingParentProjectName();
|
||||||
|
String columnProjectName();
|
||||||
String headingAgreements();
|
String headingAgreements();
|
||||||
|
|
||||||
String projectSubmitType_FAST_FORWARD_ONLY();
|
String projectSubmitType_FAST_FORWARD_ONLY();
|
||||||
@@ -93,6 +99,7 @@ public interface AdminConstants extends Constants {
|
|||||||
String groupTabGeneral();
|
String groupTabGeneral();
|
||||||
String groupTabMembers();
|
String groupTabMembers();
|
||||||
String projectListTitle();
|
String projectListTitle();
|
||||||
|
String createProjectTitle();
|
||||||
String projectAdminTabGeneral();
|
String projectAdminTabGeneral();
|
||||||
String projectAdminTabBranches();
|
String projectAdminTabBranches();
|
||||||
String projectAdminTabAccess();
|
String projectAdminTabAccess();
|
||||||
|
@@ -10,10 +10,13 @@ buttonAddGroupMember = Add
|
|||||||
buttonRenameGroup = Rename Group
|
buttonRenameGroup = Rename Group
|
||||||
buttonSaveDescription = Save Description
|
buttonSaveDescription = Save Description
|
||||||
buttonCreateGroup = Create Group
|
buttonCreateGroup = Create Group
|
||||||
|
buttonCreateProject = Create Project
|
||||||
buttonChangeGroupOwner = Change Owner
|
buttonChangeGroupOwner = Change Owner
|
||||||
buttonChangeGroupType = Change Type
|
buttonChangeGroupType = Change Type
|
||||||
buttonSelectGroup = Select
|
buttonSelectGroup = Select
|
||||||
buttonSaveChanges = Save Changes
|
buttonSaveChanges = Save Changes
|
||||||
|
checkBoxEmptyCommit = Create initial empty commit
|
||||||
|
checkBoxPermissionsOnly = Only serve as parent for other projects
|
||||||
useContentMerge = Automatically resolve conflicts
|
useContentMerge = Automatically resolve conflicts
|
||||||
useContributorAgreements = Require a valid contributor agreement to upload
|
useContributorAgreements = Require a valid contributor agreement to upload
|
||||||
useSignedOffBy = Require <a href="http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html#Signed-off-by" target="_blank"><code>Signed-off-by</code></a> in commit message
|
useSignedOffBy = Require <a href="http://gerrit.googlecode.com/svn/documentation/2.0/user-signedoffby.html#Signed-off-by" target="_blank"><code>Signed-off-by</code></a> in commit message
|
||||||
@@ -22,6 +25,8 @@ headingGroupOptions = Group Options
|
|||||||
isVisibleToAll = Make group visible to all registered users.
|
isVisibleToAll = Make group visible to all registered users.
|
||||||
buttonSaveGroupOptions = Save Group Options
|
buttonSaveGroupOptions = Save Group Options
|
||||||
suggestedGroupLabel = group
|
suggestedGroupLabel = group
|
||||||
|
headingParentProjectName = Rights Inherit From
|
||||||
|
columnProjectName = Project Name
|
||||||
|
|
||||||
emailOnlyAuthors = Authors
|
emailOnlyAuthors = Authors
|
||||||
descriptionNotifications = Send email notifications about comments and actions by users in this group only to:
|
descriptionNotifications = Send email notifications about comments and actions by users in this group only to:
|
||||||
@@ -36,6 +41,7 @@ headingIncludedGroups = Included Groups
|
|||||||
noMembersInfo = Group Members can only be viewed for Gerrit internal groups. For external groups and Gerrit system groups the members cannot be displayed.
|
noMembersInfo = Group Members can only be viewed for Gerrit internal groups. For external groups and Gerrit system groups the members cannot be displayed.
|
||||||
headingExternalGroup = Selected External Group
|
headingExternalGroup = Selected External Group
|
||||||
headingCreateGroup = Create New Group
|
headingCreateGroup = Create New Group
|
||||||
|
headingCreateProject = Create New Project
|
||||||
headingAgreements = Contributor Agreements
|
headingAgreements = Contributor Agreements
|
||||||
|
|
||||||
projectSubmitType_FAST_FORWARD_ONLY = Fast Forward Only
|
projectSubmitType_FAST_FORWARD_ONLY = Fast Forward Only
|
||||||
@@ -73,6 +79,7 @@ groupListTitle = Groups
|
|||||||
groupTabGeneral = General
|
groupTabGeneral = General
|
||||||
groupTabMembers = Members
|
groupTabMembers = Members
|
||||||
projectListTitle = Projects
|
projectListTitle = Projects
|
||||||
|
createProjectTitle = Create Project
|
||||||
projectAdminTabGeneral = General
|
projectAdminTabGeneral = General
|
||||||
projectAdminTabBranches = Branches
|
projectAdminTabBranches = Branches
|
||||||
projectAdminTabAccess = Access
|
projectAdminTabAccess = Access
|
||||||
|
@@ -0,0 +1,159 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.client.admin;
|
||||||
|
|
||||||
|
import com.google.gerrit.client.Dispatcher;
|
||||||
|
import com.google.gerrit.client.ErrorDialog;
|
||||||
|
import com.google.gerrit.client.Gerrit;
|
||||||
|
import com.google.gerrit.client.rpc.GerritCallback;
|
||||||
|
import com.google.gerrit.client.ui.HintTextBox;
|
||||||
|
import com.google.gerrit.client.ui.ProjectNameSuggestOracle;
|
||||||
|
import com.google.gerrit.client.ui.Screen;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gwt.event.dom.client.ClickEvent;
|
||||||
|
import com.google.gwt.event.dom.client.ClickHandler;
|
||||||
|
import com.google.gwt.event.dom.client.KeyCodes;
|
||||||
|
import com.google.gwt.event.dom.client.KeyPressEvent;
|
||||||
|
import com.google.gwt.event.dom.client.KeyPressHandler;
|
||||||
|
import com.google.gwt.user.client.History;
|
||||||
|
import com.google.gwt.user.client.ui.Button;
|
||||||
|
import com.google.gwt.user.client.ui.CheckBox;
|
||||||
|
import com.google.gwt.user.client.ui.Grid;
|
||||||
|
import com.google.gwt.user.client.ui.SuggestBox;
|
||||||
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
import com.google.gwtexpui.globalkey.client.NpTextBox;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
|
||||||
|
public class CreateProjectScreen extends Screen {
|
||||||
|
private NpTextBox project;
|
||||||
|
private Button create;
|
||||||
|
private HintTextBox parent;
|
||||||
|
private SuggestBox sugestParent;
|
||||||
|
private CheckBox emptyCommit;
|
||||||
|
private CheckBox permissionsOnly;
|
||||||
|
|
||||||
|
public CreateProjectScreen() {
|
||||||
|
super();
|
||||||
|
setRequiresSignIn(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onLoad() {
|
||||||
|
super.onLoad();
|
||||||
|
display();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onInitUI() {
|
||||||
|
super.onInitUI();
|
||||||
|
setPageTitle(Util.C.createProjectTitle());
|
||||||
|
|
||||||
|
addCreateProjectPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCreateProjectPanel() {
|
||||||
|
final VerticalPanel fp = new VerticalPanel();
|
||||||
|
fp.setStyleName(Gerrit.RESOURCES.css().createProjectPanel());
|
||||||
|
|
||||||
|
initCreateTxt();
|
||||||
|
initCreateButton();
|
||||||
|
initParentBox();
|
||||||
|
|
||||||
|
addGrid(fp);
|
||||||
|
|
||||||
|
emptyCommit = new CheckBox(Util.C.checkBoxEmptyCommit());
|
||||||
|
permissionsOnly = new CheckBox(Util.C.checkBoxPermissionsOnly());
|
||||||
|
fp.add(emptyCommit);
|
||||||
|
fp.add(permissionsOnly);
|
||||||
|
fp.add(create);
|
||||||
|
add(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCreateTxt() {
|
||||||
|
project = new NpTextBox();
|
||||||
|
project.setVisibleLength(50);
|
||||||
|
project.addKeyPressHandler(new KeyPressHandler() {
|
||||||
|
@Override
|
||||||
|
public void onKeyPress(KeyPressEvent event) {
|
||||||
|
if (event.getCharCode() == KeyCodes.KEY_ENTER) {
|
||||||
|
doCreateProject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCreateButton() {
|
||||||
|
create = new Button(Util.C.buttonCreateProject());
|
||||||
|
create.addClickHandler(new ClickHandler() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final ClickEvent event) {
|
||||||
|
doCreateProject();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initParentBox() {
|
||||||
|
parent = new HintTextBox();
|
||||||
|
sugestParent =
|
||||||
|
new SuggestBox(new ProjectNameSuggestOracle(), parent);
|
||||||
|
parent.setVisibleLength(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addGrid(final VerticalPanel fp) {
|
||||||
|
final Grid grid = new Grid(2, 2);
|
||||||
|
grid.setStyleName(Gerrit.RESOURCES.css().infoBlock());
|
||||||
|
grid.setText(0, 0, Util.C.columnProjectName() + ":");
|
||||||
|
grid.setWidget(0, 1, project);
|
||||||
|
grid.setText(1, 0, Util.C.headingParentProjectName() + ":");
|
||||||
|
grid.setWidget(1, 1, sugestParent);
|
||||||
|
|
||||||
|
fp.add(grid);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doCreateProject() {
|
||||||
|
final String projectName = project.getText().trim();
|
||||||
|
final String parentName = sugestParent.getText().trim();
|
||||||
|
|
||||||
|
if ("".equals(projectName)) {
|
||||||
|
project.setFocus(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
enableForm(false);
|
||||||
|
Util.PROJECT_SVC.createNewProject(projectName, parentName,
|
||||||
|
emptyCommit.getValue(), permissionsOnly.getValue(),
|
||||||
|
new GerritCallback<VoidResult>() {
|
||||||
|
@Override
|
||||||
|
public void onSuccess(VoidResult result) {
|
||||||
|
History.newItem(Dispatcher.toProjectAdmin(new Project.NameKey(
|
||||||
|
projectName), ProjectScreen.INFO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
new ErrorDialog(caught.getMessage()).center();
|
||||||
|
enableForm(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableForm(final boolean enabled) {
|
||||||
|
project.setEnabled(enabled);
|
||||||
|
create.setEnabled(enabled);
|
||||||
|
parent.setEnabled(enabled);
|
||||||
|
emptyCommit.setEnabled(enabled);
|
||||||
|
permissionsOnly.setEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
@@ -20,24 +20,24 @@ import com.google.gerrit.client.rpc.ScreenLoadCallback;
|
|||||||
import com.google.gerrit.client.ui.Hyperlink;
|
import com.google.gerrit.client.ui.Hyperlink;
|
||||||
import com.google.gerrit.client.ui.ProjectsTable;
|
import com.google.gerrit.client.ui.ProjectsTable;
|
||||||
import com.google.gerrit.client.ui.Screen;
|
import com.google.gerrit.client.ui.Screen;
|
||||||
import com.google.gerrit.client.ui.SmallHeading;
|
|
||||||
import com.google.gerrit.common.PageLinks;
|
import com.google.gerrit.common.PageLinks;
|
||||||
|
import com.google.gerrit.common.data.ProjectList;
|
||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.reviewdb.Project;
|
||||||
import com.google.gwt.user.client.History;
|
import com.google.gwt.user.client.History;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class ProjectListScreen extends Screen {
|
public class ProjectListScreen extends Screen {
|
||||||
|
private VerticalPanel createProjectLinkPanel;
|
||||||
private ProjectsTable projects;
|
private ProjectsTable projects;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLoad() {
|
protected void onLoad() {
|
||||||
super.onLoad();
|
super.onLoad();
|
||||||
Util.PROJECT_SVC.visibleProjects(new ScreenLoadCallback<List<Project>>(this) {
|
Util.PROJECT_SVC.visibleProjects(new ScreenLoadCallback<ProjectList>(this) {
|
||||||
@Override
|
@Override
|
||||||
protected void preDisplay(final List<Project> result) {
|
protected void preDisplay(final ProjectList result) {
|
||||||
projects.display(result);
|
createProjectLinkPanel.setVisible(result.canCreateProject());
|
||||||
|
projects.display(result.getProjects());
|
||||||
projects.finishDisplay();
|
projects.finishDisplay();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -48,6 +48,13 @@ public class ProjectListScreen extends Screen {
|
|||||||
super.onInitUI();
|
super.onInitUI();
|
||||||
setPageTitle(Util.C.projectListTitle());
|
setPageTitle(Util.C.projectListTitle());
|
||||||
|
|
||||||
|
createProjectLinkPanel = new VerticalPanel();
|
||||||
|
createProjectLinkPanel.setStyleName(Gerrit.RESOURCES.css()
|
||||||
|
.createProjectLink());
|
||||||
|
createProjectLinkPanel.add(new Hyperlink(Util.C.headingCreateProject(),
|
||||||
|
PageLinks.ADMIN_CREATE_PROJECT));
|
||||||
|
add(createProjectLinkPanel);
|
||||||
|
|
||||||
projects = new ProjectsTable() {
|
projects = new ProjectsTable() {
|
||||||
@Override
|
@Override
|
||||||
protected void onOpenRow(final int row) {
|
protected void onOpenRow(final int row) {
|
||||||
@@ -69,10 +76,6 @@ public class ProjectListScreen extends Screen {
|
|||||||
projects.setSavePointerId(PageLinks.ADMIN_PROJECTS);
|
projects.setSavePointerId(PageLinks.ADMIN_PROJECTS);
|
||||||
|
|
||||||
add(projects);
|
add(projects);
|
||||||
|
|
||||||
final VerticalPanel fp = new VerticalPanel();
|
|
||||||
fp.setStyleName(Gerrit.RESOURCES.css().addSshKeyPanel());
|
|
||||||
fp.add(new SmallHeading(Util.C.headingCreateGroup()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -1110,6 +1110,16 @@ a:hover.downloadLink {
|
|||||||
padding: 5px 5px 5px 5px;
|
padding: 5px 5px 5px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.createProjectLink {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.createProjectPanel {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
background-color: trimColor;
|
||||||
|
padding: 5px 5px 5px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
.sshHostKeyPanel {
|
.sshHostKeyPanel {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
border: 1px solid trimColor;
|
border: 1px solid trimColor;
|
||||||
|
@@ -0,0 +1,85 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.httpd.rpc.project;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
||||||
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.reviewdb.Project.SubmitType;
|
||||||
|
import com.google.gerrit.server.project.CreateProject;
|
||||||
|
import com.google.gerrit.server.project.CreateProjectArgs;
|
||||||
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
|
||||||
|
public class CreateProjectHandler extends Handler<VoidResult> {
|
||||||
|
|
||||||
|
interface Factory {
|
||||||
|
CreateProjectHandler create(@Assisted("projectName") String projectName,
|
||||||
|
@Assisted("parentName") String parentName,
|
||||||
|
@Assisted("emptyCommit") boolean emptyCommit,
|
||||||
|
@Assisted("permissionsOnly") boolean permissionsOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final CreateProject.Factory createProjectFactory;
|
||||||
|
private final ProjectControl.Factory projectControlFactory;
|
||||||
|
private final String projectName;
|
||||||
|
private final String parentName;
|
||||||
|
private final boolean emptyCommit;
|
||||||
|
private final boolean permissionsOnly;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public CreateProjectHandler(final CreateProject.Factory createProjectFactory,
|
||||||
|
final ProjectControl.Factory projectControlFactory,
|
||||||
|
@Assisted("projectName") final String projectName,
|
||||||
|
@Assisted("parentName") final String parentName,
|
||||||
|
@Assisted("emptyCommit") final boolean emptyCommit,
|
||||||
|
@Assisted("permissionsOnly") final boolean permissionsOnly) {
|
||||||
|
this.createProjectFactory = createProjectFactory;
|
||||||
|
this.projectControlFactory = projectControlFactory;
|
||||||
|
this.projectName = projectName;
|
||||||
|
this.parentName = parentName;
|
||||||
|
this.emptyCommit = emptyCommit;
|
||||||
|
this.permissionsOnly = permissionsOnly;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VoidResult call() throws ProjectCreationFailedException {
|
||||||
|
final CreateProjectArgs args = new CreateProjectArgs();
|
||||||
|
args.setProjectName(projectName);
|
||||||
|
if (!parentName.equals("")) {
|
||||||
|
final Project.NameKey nameKey = new Project.NameKey(parentName);
|
||||||
|
try {
|
||||||
|
args.newParent = projectControlFactory.validateFor(nameKey);
|
||||||
|
} catch (NoSuchProjectException e) {
|
||||||
|
throw new ProjectCreationFailedException("Parent project \""
|
||||||
|
+ parentName + "\" does not exist.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
args.projectDescription = "";
|
||||||
|
args.submitType = SubmitType.MERGE_IF_NECESSARY;
|
||||||
|
args.branch = Constants.MASTER;
|
||||||
|
args.createEmptyCommit = emptyCommit;
|
||||||
|
args.permissionsOnly = permissionsOnly;
|
||||||
|
|
||||||
|
final CreateProject createProject = createProjectFactory.create(args);
|
||||||
|
createProject.createProject();
|
||||||
|
return VoidResult.INSTANCE;
|
||||||
|
}
|
||||||
|
}
|
@@ -19,9 +19,11 @@ import com.google.gerrit.common.data.ListBranchesResult;
|
|||||||
import com.google.gerrit.common.data.ProjectAccess;
|
import com.google.gerrit.common.data.ProjectAccess;
|
||||||
import com.google.gerrit.common.data.ProjectAdminService;
|
import com.google.gerrit.common.data.ProjectAdminService;
|
||||||
import com.google.gerrit.common.data.ProjectDetail;
|
import com.google.gerrit.common.data.ProjectDetail;
|
||||||
|
import com.google.gerrit.common.data.ProjectList;
|
||||||
import com.google.gerrit.reviewdb.Branch;
|
import com.google.gerrit.reviewdb.Branch;
|
||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.reviewdb.Project;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwtjsonrpc.client.VoidResult;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
@@ -38,6 +40,7 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
private final VisibleProjects.Factory visibleProjectsFactory;
|
private final VisibleProjects.Factory visibleProjectsFactory;
|
||||||
private final VisibleProjectDetails.Factory visibleProjectDetailsFactory;
|
private final VisibleProjectDetails.Factory visibleProjectDetailsFactory;
|
||||||
private final ProjectAccessFactory.Factory projectAccessFactory;
|
private final ProjectAccessFactory.Factory projectAccessFactory;
|
||||||
|
private final CreateProjectHandler.Factory createProjectHandlerFactory;
|
||||||
private final ProjectDetailFactory.Factory projectDetailFactory;
|
private final ProjectDetailFactory.Factory projectDetailFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -49,7 +52,8 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
final VisibleProjects.Factory visibleProjectsFactory,
|
final VisibleProjects.Factory visibleProjectsFactory,
|
||||||
final VisibleProjectDetails.Factory visibleProjectDetailsFactory,
|
final VisibleProjectDetails.Factory visibleProjectDetailsFactory,
|
||||||
final ProjectAccessFactory.Factory projectAccessFactory,
|
final ProjectAccessFactory.Factory projectAccessFactory,
|
||||||
final ProjectDetailFactory.Factory projectDetailFactory) {
|
final ProjectDetailFactory.Factory projectDetailFactory,
|
||||||
|
final CreateProjectHandler.Factory createNewProjectFactory) {
|
||||||
this.addBranchFactory = addBranchFactory;
|
this.addBranchFactory = addBranchFactory;
|
||||||
this.changeProjectAccessFactory = changeProjectAccessFactory;
|
this.changeProjectAccessFactory = changeProjectAccessFactory;
|
||||||
this.changeProjectSettingsFactory = changeProjectSettingsFactory;
|
this.changeProjectSettingsFactory = changeProjectSettingsFactory;
|
||||||
@@ -59,10 +63,11 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
this.visibleProjectDetailsFactory = visibleProjectDetailsFactory;
|
this.visibleProjectDetailsFactory = visibleProjectDetailsFactory;
|
||||||
this.projectAccessFactory = projectAccessFactory;
|
this.projectAccessFactory = projectAccessFactory;
|
||||||
this.projectDetailFactory = projectDetailFactory;
|
this.projectDetailFactory = projectDetailFactory;
|
||||||
|
this.createProjectHandlerFactory = createNewProjectFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visibleProjects(final AsyncCallback<List<Project>> callback) {
|
public void visibleProjects(final AsyncCallback<ProjectList> callback) {
|
||||||
visibleProjectsFactory.create().to(callback);
|
visibleProjectsFactory.create().to(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,4 +127,12 @@ class ProjectAdminServiceImpl implements ProjectAdminService {
|
|||||||
addBranchFactory.create(projectName, branchName, startingRevision).to(
|
addBranchFactory.create(projectName, branchName, startingRevision).to(
|
||||||
callback);
|
callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createNewProject(String projectName, String parentName,
|
||||||
|
boolean emptyCommit, boolean permissionsOnly,
|
||||||
|
AsyncCallback<VoidResult> callback) {
|
||||||
|
createProjectHandlerFactory.create(projectName, parentName, emptyCommit,
|
||||||
|
permissionsOnly).to(callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ public class ProjectModule extends RpcServletModule {
|
|||||||
protected void configure() {
|
protected void configure() {
|
||||||
factory(AddBranch.Factory.class);
|
factory(AddBranch.Factory.class);
|
||||||
factory(ChangeProjectAccess.Factory.class);
|
factory(ChangeProjectAccess.Factory.class);
|
||||||
|
factory(CreateProjectHandler.Factory.class);
|
||||||
factory(ChangeProjectSettings.Factory.class);
|
factory(ChangeProjectSettings.Factory.class);
|
||||||
factory(DeleteBranches.Factory.class);
|
factory(DeleteBranches.Factory.class);
|
||||||
factory(ListBranches.Factory.class);
|
factory(ListBranches.Factory.class);
|
||||||
|
@@ -14,9 +14,10 @@
|
|||||||
|
|
||||||
package com.google.gerrit.httpd.rpc.project;
|
package com.google.gerrit.httpd.rpc.project;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.ProjectList;
|
||||||
import com.google.gerrit.httpd.rpc.Handler;
|
import com.google.gerrit.httpd.rpc.Handler;
|
||||||
import com.google.gerrit.reviewdb.Project;
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.project.NoSuchProjectException;
|
import com.google.gerrit.server.project.NoSuchProjectException;
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
@@ -27,23 +28,32 @@ import java.util.Collections;
|
|||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class VisibleProjects extends Handler<List<Project>> {
|
class VisibleProjects extends Handler<ProjectList> {
|
||||||
interface Factory {
|
interface Factory {
|
||||||
VisibleProjects create();
|
VisibleProjects create();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ProjectControl.Factory projectControlFactory;
|
private final ProjectControl.Factory projectControlFactory;
|
||||||
private final ProjectCache projectCache;
|
private final ProjectCache projectCache;
|
||||||
|
private final CurrentUser user;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
VisibleProjects(final ProjectControl.Factory projectControlFactory,
|
VisibleProjects(final ProjectControl.Factory projectControlFactory,
|
||||||
final ProjectCache projectCache) {
|
final ProjectCache projectCache, final CurrentUser user) {
|
||||||
this.projectControlFactory = projectControlFactory;
|
this.projectControlFactory = projectControlFactory;
|
||||||
this.projectCache = projectCache;
|
this.projectCache = projectCache;
|
||||||
|
this.user = user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Project> call() {
|
public ProjectList call() {
|
||||||
|
ProjectList result = new ProjectList();
|
||||||
|
result.setProjects(getProjects());
|
||||||
|
result.setCanCreateProject(user.getCapabilities().canCreateProject());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Project> getProjects() {
|
||||||
List<Project> result = new ArrayList<Project>();
|
List<Project> result = new ArrayList<Project>();
|
||||||
for (Project.NameKey p : projectCache.all()) {
|
for (Project.NameKey p : projectCache.all()) {
|
||||||
try {
|
try {
|
||||||
|
@@ -45,6 +45,7 @@ import com.google.gerrit.server.patch.AddReviewer;
|
|||||||
import com.google.gerrit.server.patch.PublishComments;
|
import com.google.gerrit.server.patch.PublishComments;
|
||||||
import com.google.gerrit.server.patch.RemoveReviewer;
|
import com.google.gerrit.server.patch.RemoveReviewer;
|
||||||
import com.google.gerrit.server.project.ChangeControl;
|
import com.google.gerrit.server.project.ChangeControl;
|
||||||
|
import com.google.gerrit.server.project.CreateProject;
|
||||||
import com.google.gerrit.server.project.PerRequestProjectControlCache;
|
import com.google.gerrit.server.project.PerRequestProjectControlCache;
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
|
||||||
@@ -95,5 +96,6 @@ public class GerritRequestModule extends FactoryModule {
|
|||||||
factory(VisibleGroups.Factory.class);
|
factory(VisibleGroups.Factory.class);
|
||||||
factory(GroupDetailFactory.Factory.class);
|
factory(GroupDetailFactory.Factory.class);
|
||||||
factory(GroupMembers.Factory.class);
|
factory(GroupMembers.Factory.class);
|
||||||
|
factory(CreateProject.Factory.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,264 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.server.project;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.data.AccessSection;
|
||||||
|
import com.google.gerrit.common.data.GroupReference;
|
||||||
|
import com.google.gerrit.common.data.Permission;
|
||||||
|
import com.google.gerrit.common.data.PermissionRule;
|
||||||
|
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
||||||
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.reviewdb.ReviewDb;
|
||||||
|
import com.google.gerrit.server.GerritPersonIdent;
|
||||||
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.account.GroupCache;
|
||||||
|
import com.google.gerrit.server.config.ProjectOwnerGroups;
|
||||||
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
|
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||||
|
import com.google.gerrit.server.git.ProjectConfig;
|
||||||
|
import com.google.gerrit.server.git.ReplicationQueue;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.assistedinject.Assisted;
|
||||||
|
|
||||||
|
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||||
|
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||||
|
import org.eclipse.jgit.lib.CommitBuilder;
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
import org.eclipse.jgit.lib.ObjectInserter;
|
||||||
|
import org.eclipse.jgit.lib.PersonIdent;
|
||||||
|
import org.eclipse.jgit.lib.RefUpdate;
|
||||||
|
import org.eclipse.jgit.lib.Repository;
|
||||||
|
import org.eclipse.jgit.lib.RefUpdate.Result;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.google.gerrit.server.git.RepositoryCaseMismatchException;
|
||||||
|
import com.google.gerrit.server.project.ProjectCache;
|
||||||
|
|
||||||
|
|
||||||
|
/** Common class that holds the code to create projects */
|
||||||
|
public class CreateProject {
|
||||||
|
private static final Logger log = LoggerFactory
|
||||||
|
.getLogger(CreateProject.class);
|
||||||
|
|
||||||
|
public interface Factory {
|
||||||
|
CreateProject create(CreateProjectArgs createProjectArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Set<AccountGroup.UUID> projectOwnerGroups;
|
||||||
|
private final IdentifiedUser currentUser;
|
||||||
|
private final GitRepositoryManager repoManager;
|
||||||
|
private final ReplicationQueue replication;
|
||||||
|
private final PersonIdent serverIdent;
|
||||||
|
private CreateProjectArgs createProjectArgs;
|
||||||
|
private ProjectCache projectCache;
|
||||||
|
private GroupCache groupCache;
|
||||||
|
private MetaDataUpdate.User metaDataUpdateFactory;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
CreateProject(@ProjectOwnerGroups Set<AccountGroup.UUID> pOwnerGroups,
|
||||||
|
IdentifiedUser identifiedUser, GitRepositoryManager gitRepoManager,
|
||||||
|
ReplicationQueue replicateq, ReviewDb db,
|
||||||
|
@GerritPersonIdent PersonIdent personIdent, final GroupCache groupCache,
|
||||||
|
final MetaDataUpdate.User metaDataUpdateFactory,
|
||||||
|
@Assisted CreateProjectArgs createPArgs, ProjectCache pCache) {
|
||||||
|
this.projectOwnerGroups = pOwnerGroups;
|
||||||
|
this.currentUser = identifiedUser;
|
||||||
|
this.repoManager = gitRepoManager;
|
||||||
|
this.replication = replicateq;
|
||||||
|
this.serverIdent = personIdent;
|
||||||
|
this.createProjectArgs = createPArgs;
|
||||||
|
this.projectCache = pCache;
|
||||||
|
this.groupCache = groupCache;
|
||||||
|
this.metaDataUpdateFactory = metaDataUpdateFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createProject() throws ProjectCreationFailedException {
|
||||||
|
validateParameters();
|
||||||
|
try {
|
||||||
|
final Project.NameKey nameKey = createProjectArgs.getProject();
|
||||||
|
final String head =
|
||||||
|
createProjectArgs.permissionsOnly ? GitRepositoryManager.REF_CONFIG
|
||||||
|
: createProjectArgs.branch;
|
||||||
|
final Repository repo = repoManager.createRepository(nameKey);
|
||||||
|
try {
|
||||||
|
replication.replicateNewProject(nameKey, head);
|
||||||
|
|
||||||
|
final RefUpdate u = repo.updateRef(Constants.HEAD);
|
||||||
|
u.disableRefLog();
|
||||||
|
u.link(head);
|
||||||
|
|
||||||
|
createProjectConfig();
|
||||||
|
|
||||||
|
if (!createProjectArgs.permissionsOnly
|
||||||
|
&& createProjectArgs.createEmptyCommit) {
|
||||||
|
createEmptyCommit(repo, nameKey, createProjectArgs.branch);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
repo.close();
|
||||||
|
}
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
handleRepositoryExistsException(createProjectArgs.getProject(), e);
|
||||||
|
} catch (RepositoryCaseMismatchException ee) {
|
||||||
|
handleRepositoryExistsException(ee.getNameOfExistingProject(), ee);
|
||||||
|
} catch (Exception e) {
|
||||||
|
final String msg = "Cannot create " + createProjectArgs.getProject();
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ProjectCreationFailedException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createProjectConfig() throws IOException, ConfigInvalidException {
|
||||||
|
final MetaDataUpdate md =
|
||||||
|
metaDataUpdateFactory.create(createProjectArgs.getProject());
|
||||||
|
try {
|
||||||
|
final ProjectConfig config = ProjectConfig.read(md);
|
||||||
|
config.load(md);
|
||||||
|
|
||||||
|
Project newProject = config.getProject();
|
||||||
|
newProject.setDescription(createProjectArgs.projectDescription);
|
||||||
|
newProject.setSubmitType(createProjectArgs.submitType);
|
||||||
|
newProject
|
||||||
|
.setUseContributorAgreements(createProjectArgs.contributorAgreements);
|
||||||
|
newProject.setUseSignedOffBy(createProjectArgs.signedOffBy);
|
||||||
|
newProject.setUseContentMerge(createProjectArgs.contentMerge);
|
||||||
|
newProject.setRequireChangeID(createProjectArgs.changeIdRequired);
|
||||||
|
if (createProjectArgs.newParent != null) {
|
||||||
|
newProject.setParentName(createProjectArgs.newParent.getProject()
|
||||||
|
.getNameKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!createProjectArgs.ownerIds.isEmpty()) {
|
||||||
|
final AccessSection all =
|
||||||
|
config.getAccessSection(AccessSection.ALL, true);
|
||||||
|
for (AccountGroup.UUID ownerId : createProjectArgs.ownerIds) {
|
||||||
|
AccountGroup accountGroup = groupCache.get(ownerId);
|
||||||
|
GroupReference group = config.resolve(accountGroup);
|
||||||
|
all.getPermission(Permission.OWNER, true).add(
|
||||||
|
new PermissionRule(group));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
md.setMessage("Created project\n");
|
||||||
|
if (!config.commit(md)) {
|
||||||
|
throw new IOException("Cannot create "
|
||||||
|
+ createProjectArgs.getProjectName());
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
md.close();
|
||||||
|
}
|
||||||
|
projectCache.onCreateProject(createProjectArgs.getProject());
|
||||||
|
repoManager.setProjectDescription(createProjectArgs.getProject(),
|
||||||
|
createProjectArgs.projectDescription);
|
||||||
|
replication.scheduleUpdate(createProjectArgs.getProject(),
|
||||||
|
GitRepositoryManager.REF_CONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateParameters() throws ProjectCreationFailedException {
|
||||||
|
if (createProjectArgs.getProjectName() == null
|
||||||
|
|| createProjectArgs.getProjectName().isEmpty()) {
|
||||||
|
throw new ProjectCreationFailedException("Project name is required");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createProjectArgs.getProjectName().endsWith(Constants.DOT_GIT_EXT)) {
|
||||||
|
createProjectArgs.setProjectName(createProjectArgs.getProjectName()
|
||||||
|
.substring(
|
||||||
|
0,
|
||||||
|
createProjectArgs.getProjectName().length()
|
||||||
|
- Constants.DOT_GIT_EXT.length()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentUser.getCapabilities().canCreateProject()) {
|
||||||
|
throw new ProjectCreationFailedException(String.format(
|
||||||
|
"%s does not have \"Create Project\" capability.",
|
||||||
|
currentUser.getUserName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (createProjectArgs.ownerIds == null
|
||||||
|
|| createProjectArgs.ownerIds.isEmpty()) {
|
||||||
|
createProjectArgs.ownerIds =
|
||||||
|
new ArrayList<AccountGroup.UUID>(projectOwnerGroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (createProjectArgs.branch.startsWith("/")) {
|
||||||
|
createProjectArgs.branch = createProjectArgs.branch.substring(1);
|
||||||
|
}
|
||||||
|
if (!createProjectArgs.branch.startsWith(Constants.R_HEADS)) {
|
||||||
|
createProjectArgs.branch = Constants.R_HEADS + createProjectArgs.branch;
|
||||||
|
}
|
||||||
|
if (!Repository.isValidRefName(createProjectArgs.branch)) {
|
||||||
|
throw new ProjectCreationFailedException(String.format(
|
||||||
|
"Branch \"%s\" is not a valid name.", createProjectArgs.branch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createEmptyCommit(final Repository repo,
|
||||||
|
final Project.NameKey project, final String ref) throws IOException {
|
||||||
|
ObjectInserter oi = repo.newObjectInserter();
|
||||||
|
try {
|
||||||
|
CommitBuilder cb = new CommitBuilder();
|
||||||
|
cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {}));
|
||||||
|
cb.setAuthor(metaDataUpdateFactory.getUserPersonIdent());
|
||||||
|
cb.setCommitter(serverIdent);
|
||||||
|
cb.setMessage("Initial empty repository\n");
|
||||||
|
|
||||||
|
ObjectId id = oi.insert(cb);
|
||||||
|
oi.flush();
|
||||||
|
|
||||||
|
RefUpdate ru = repo.updateRef(Constants.HEAD);
|
||||||
|
ru.setNewObjectId(id);
|
||||||
|
final Result result = ru.update();
|
||||||
|
switch (result) {
|
||||||
|
case NEW:
|
||||||
|
replication.scheduleUpdate(project, ref);
|
||||||
|
break;
|
||||||
|
default: {
|
||||||
|
throw new IOException(result.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(
|
||||||
|
"Cannot create empty commit for "
|
||||||
|
+ createProjectArgs.getProjectName(), e);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
oi.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleRepositoryExistsException(final Project.NameKey nameKey,
|
||||||
|
Exception e) throws ProjectCreationFailedException {
|
||||||
|
try {
|
||||||
|
Repository repo = repoManager.openRepository(nameKey);
|
||||||
|
try {
|
||||||
|
if (repo.getObjectDatabase().exists()) {
|
||||||
|
throw new ProjectCreationFailedException("Project \"" + nameKey
|
||||||
|
+ "\" exists", e);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
repo.close();
|
||||||
|
}
|
||||||
|
} catch (RepositoryNotFoundException er) {
|
||||||
|
throw new ProjectCreationFailedException("Cannot create \"" + nameKey
|
||||||
|
+ "\"", er);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (C) 2011 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.server.project;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
|
import com.google.gerrit.reviewdb.Project;
|
||||||
|
import com.google.gerrit.reviewdb.Project.SubmitType;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CreateProjectArgs {
|
||||||
|
|
||||||
|
private Project.NameKey projectName;
|
||||||
|
public List<AccountGroup.UUID> ownerIds;
|
||||||
|
public ProjectControl newParent;
|
||||||
|
public String projectDescription;
|
||||||
|
public SubmitType submitType;
|
||||||
|
public boolean contributorAgreements;
|
||||||
|
public boolean signedOffBy;
|
||||||
|
public boolean permissionsOnly;
|
||||||
|
public String branch;
|
||||||
|
public boolean contentMerge;
|
||||||
|
public boolean changeIdRequired;
|
||||||
|
public boolean createEmptyCommit;
|
||||||
|
|
||||||
|
public CreateProjectArgs() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Project.NameKey getProject() {
|
||||||
|
return projectName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProjectName() {
|
||||||
|
return projectName != null ? projectName.get() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(String n) {
|
||||||
|
projectName = n != null ? new Project.NameKey(n) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProjectName(Project.NameKey n) {
|
||||||
|
projectName = n;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,309 +0,0 @@
|
|||||||
// Copyright (C) 2009 The Android Open Source Project
|
|
||||||
//
|
|
||||||
// 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.google.gerrit.sshd.commands;
|
|
||||||
|
|
||||||
import com.google.gerrit.common.data.AccessSection;
|
|
||||||
import com.google.gerrit.common.data.GroupReference;
|
|
||||||
import com.google.gerrit.common.data.Permission;
|
|
||||||
import com.google.gerrit.common.data.PermissionRule;
|
|
||||||
import com.google.gerrit.reviewdb.AccountGroup;
|
|
||||||
import com.google.gerrit.reviewdb.Project;
|
|
||||||
import com.google.gerrit.reviewdb.Project.SubmitType;
|
|
||||||
import com.google.gerrit.server.GerritPersonIdent;
|
|
||||||
import com.google.gerrit.server.IdentifiedUser;
|
|
||||||
import com.google.gerrit.server.account.GroupCache;
|
|
||||||
import com.google.gerrit.server.config.ProjectOwnerGroups;
|
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
|
||||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
|
||||||
import com.google.gerrit.server.git.ProjectConfig;
|
|
||||||
import com.google.gerrit.server.git.ReplicationQueue;
|
|
||||||
import com.google.gerrit.server.git.RepositoryCaseMismatchException;
|
|
||||||
import com.google.gerrit.server.project.ProjectCache;
|
|
||||||
import com.google.gerrit.server.project.ProjectControl;
|
|
||||||
import com.google.gerrit.sshd.BaseCommand;
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
|
|
||||||
import org.apache.sshd.server.Environment;
|
|
||||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
|
||||||
import org.eclipse.jgit.lib.CommitBuilder;
|
|
||||||
import org.eclipse.jgit.lib.Constants;
|
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
|
||||||
import org.eclipse.jgit.lib.ObjectInserter;
|
|
||||||
import org.eclipse.jgit.lib.PersonIdent;
|
|
||||||
import org.eclipse.jgit.lib.RefUpdate;
|
|
||||||
import org.eclipse.jgit.lib.Repository;
|
|
||||||
import org.eclipse.jgit.lib.RefUpdate.Result;
|
|
||||||
import org.kohsuke.args4j.Argument;
|
|
||||||
import org.kohsuke.args4j.Option;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/** Create a new project. **/
|
|
||||||
final class CreateProject extends BaseCommand {
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(CreateProject.class);
|
|
||||||
|
|
||||||
@Option(name = "--name", aliases = {"-n"}, metaVar = "NAME", usage = "name of project to be created (deprecated option)")
|
|
||||||
void setProjectNameFromOption(String name) {
|
|
||||||
if (projectName != null) {
|
|
||||||
throw new IllegalArgumentException("NAME already supplied");
|
|
||||||
} else {
|
|
||||||
projectName = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Option(name = "--owner", aliases = {"-o"}, usage = "owner(s) of project")
|
|
||||||
private List<AccountGroup.UUID> ownerIds;
|
|
||||||
|
|
||||||
@Option(name = "--parent", aliases = {"-p"}, metaVar = "NAME", usage = "parent project")
|
|
||||||
private ProjectControl newParent;
|
|
||||||
|
|
||||||
@Option(name = "--permissions-only", usage = "create project for use only as parent")
|
|
||||||
private boolean permissionsOnly;
|
|
||||||
|
|
||||||
@Option(name = "--description", aliases = {"-d"}, metaVar = "DESCRIPTION", usage = "description of project")
|
|
||||||
private String projectDescription = "";
|
|
||||||
|
|
||||||
@Option(name = "--submit-type", aliases = {"-t"}, usage = "project submit type\n"
|
|
||||||
+ "(default: MERGE_IF_NECESSARY)")
|
|
||||||
private SubmitType submitType = SubmitType.MERGE_IF_NECESSARY;
|
|
||||||
|
|
||||||
@Option(name = "--use-contributor-agreements", aliases = {"--ca"}, usage = "if contributor agreement is required")
|
|
||||||
private boolean contributorAgreements;
|
|
||||||
|
|
||||||
@Option(name = "--use-signed-off-by", aliases = {"--so"}, usage = "if signed-off-by is required")
|
|
||||||
private boolean signedOffBy;
|
|
||||||
|
|
||||||
@Option(name = "--use-content-merge", usage = "allow automatic conflict resolving within files")
|
|
||||||
private boolean contentMerge;
|
|
||||||
|
|
||||||
@Option(name = "--require-change-id", aliases = {"--id"}, usage = "if change-id is required")
|
|
||||||
private boolean requireChangeID;
|
|
||||||
|
|
||||||
@Option(name = "--branch", aliases = {"-b"}, metaVar = "BRANCH", usage = "initial branch name\n"
|
|
||||||
+ "(default: master)")
|
|
||||||
private String branch = Constants.MASTER;
|
|
||||||
|
|
||||||
@Option(name = "--empty-commit", usage = "to create initial empty commit")
|
|
||||||
private boolean createEmptyCommit;
|
|
||||||
|
|
||||||
private String projectName;
|
|
||||||
@Argument(index = 0, metaVar="NAME", usage="name of project to be created")
|
|
||||||
void setProjectNameFromArgument(String name) {
|
|
||||||
if (projectName != null) {
|
|
||||||
throw new IllegalArgumentException("--name already supplied");
|
|
||||||
} else {
|
|
||||||
projectName = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GitRepositoryManager repoManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ProjectCache projectCache;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GroupCache groupCache;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@ProjectOwnerGroups
|
|
||||||
private Set<AccountGroup.UUID> projectOwnerGroups;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private IdentifiedUser currentUser;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ReplicationQueue rq;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
@GerritPersonIdent
|
|
||||||
private PersonIdent serverIdent;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
MetaDataUpdate.User metaDataUpdateFactory;
|
|
||||||
|
|
||||||
private Project.NameKey nameKey;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(final Environment env) {
|
|
||||||
startThread(new CommandRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() throws Exception {
|
|
||||||
if (!currentUser.getCapabilities().canCreateProject()) {
|
|
||||||
String msg = String.format(
|
|
||||||
"fatal: %s does not have \"Create Project\" capability.",
|
|
||||||
currentUser.getUserName());
|
|
||||||
throw new UnloggedFailure(BaseCommand.STATUS_NOT_ADMIN, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
parseCommandLine();
|
|
||||||
validateParameters();
|
|
||||||
|
|
||||||
try {
|
|
||||||
nameKey = new Project.NameKey(projectName);
|
|
||||||
|
|
||||||
String head = permissionsOnly ? GitRepositoryManager.REF_CONFIG : branch;
|
|
||||||
final Repository repo = repoManager.createRepository(nameKey);
|
|
||||||
try {
|
|
||||||
rq.replicateNewProject(nameKey, head);
|
|
||||||
|
|
||||||
RefUpdate u = repo.updateRef(Constants.HEAD);
|
|
||||||
u.disableRefLog();
|
|
||||||
u.link(head);
|
|
||||||
|
|
||||||
createProjectConfig();
|
|
||||||
|
|
||||||
if (!permissionsOnly && createEmptyCommit) {
|
|
||||||
createEmptyCommit(repo, nameKey, branch);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
repo.close();
|
|
||||||
}
|
|
||||||
} catch (IllegalStateException err) {
|
|
||||||
handleRepositoryExistsException(nameKey);
|
|
||||||
} catch (RepositoryCaseMismatchException err) {
|
|
||||||
handleRepositoryExistsException(err.getNameOfExistingProject());
|
|
||||||
} catch (RepositoryNotFoundException badName) {
|
|
||||||
throw new UnloggedFailure(1, "fatal: " + badName.getMessage());
|
|
||||||
} catch (Exception err) {
|
|
||||||
throw new Failure(1, "fatal: Cannot create " + projectName, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createEmptyCommit(final Repository repo,
|
|
||||||
final Project.NameKey project, final String ref) throws IOException {
|
|
||||||
ObjectInserter oi = repo.newObjectInserter();
|
|
||||||
try {
|
|
||||||
CommitBuilder cb = new CommitBuilder();
|
|
||||||
cb.setTreeId(oi.insert(Constants.OBJ_TREE, new byte[] {}));
|
|
||||||
cb.setAuthor(metaDataUpdateFactory.getUserPersonIdent());
|
|
||||||
cb.setCommitter(serverIdent);
|
|
||||||
cb.setMessage("Initial empty repository\n");
|
|
||||||
|
|
||||||
ObjectId id = oi.insert(cb);
|
|
||||||
oi.flush();
|
|
||||||
|
|
||||||
RefUpdate ru = repo.updateRef(Constants.HEAD);
|
|
||||||
ru.setNewObjectId(id);
|
|
||||||
final Result result = ru.update();
|
|
||||||
switch (result) {
|
|
||||||
case NEW:
|
|
||||||
rq.scheduleUpdate(project, ref);
|
|
||||||
break;
|
|
||||||
default: {
|
|
||||||
throw new IOException(result.name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Cannot create empty commit for " + projectName, e);
|
|
||||||
throw e;
|
|
||||||
} finally {
|
|
||||||
oi.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createProjectConfig() throws IOException, ConfigInvalidException {
|
|
||||||
MetaDataUpdate md = metaDataUpdateFactory.create(nameKey);
|
|
||||||
try {
|
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
|
||||||
config.load(md);
|
|
||||||
|
|
||||||
Project newProject = config.getProject();
|
|
||||||
newProject.setDescription(projectDescription);
|
|
||||||
newProject.setSubmitType(submitType);
|
|
||||||
newProject.setUseContributorAgreements(contributorAgreements);
|
|
||||||
newProject.setUseSignedOffBy(signedOffBy);
|
|
||||||
newProject.setUseContentMerge(contentMerge);
|
|
||||||
newProject.setRequireChangeID(requireChangeID);
|
|
||||||
if (newParent != null) {
|
|
||||||
newProject.setParentName(newParent.getProject().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ownerIds.isEmpty()) {
|
|
||||||
AccessSection all = config.getAccessSection(AccessSection.ALL, true);
|
|
||||||
for (AccountGroup.UUID ownerId : ownerIds) {
|
|
||||||
AccountGroup accountGroup = groupCache.get(ownerId);
|
|
||||||
GroupReference group = config.resolve(accountGroup);
|
|
||||||
all.getPermission(Permission.OWNER, true).add(
|
|
||||||
new PermissionRule(group));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
md.setMessage("Created project\n");
|
|
||||||
if (!config.commit(md)) {
|
|
||||||
throw new IOException("Cannot create " + projectName);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
md.close();
|
|
||||||
}
|
|
||||||
projectCache.onCreateProject(nameKey);
|
|
||||||
repoManager.setProjectDescription(nameKey, projectDescription);
|
|
||||||
rq.scheduleUpdate(nameKey, GitRepositoryManager.REF_CONFIG);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateParameters() throws Failure {
|
|
||||||
if (projectName == null || projectName.isEmpty()) {
|
|
||||||
throw new Failure(1, "fatal: Argument NAME is required");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (projectName.endsWith(Constants.DOT_GIT_EXT)) {
|
|
||||||
projectName = projectName.substring(0, //
|
|
||||||
projectName.length() - Constants.DOT_GIT_EXT.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ownerIds != null && !ownerIds.isEmpty()) {
|
|
||||||
ownerIds =
|
|
||||||
new ArrayList<AccountGroup.UUID>(new HashSet<AccountGroup.UUID>(ownerIds));
|
|
||||||
} else {
|
|
||||||
ownerIds = new ArrayList<AccountGroup.UUID>(projectOwnerGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (branch.startsWith("/")) {
|
|
||||||
branch = branch.substring(1);
|
|
||||||
}
|
|
||||||
if (!branch.startsWith(Constants.R_HEADS)) {
|
|
||||||
branch = Constants.R_HEADS + branch;
|
|
||||||
}
|
|
||||||
if (!Repository.isValidRefName(branch)) {
|
|
||||||
throw new Failure(1, "--branch \"" + branch + "\" is not a valid name");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleRepositoryExistsException(final Project.NameKey projectName)
|
|
||||||
throws Failure {
|
|
||||||
try {
|
|
||||||
Repository repo = repoManager.openRepository(projectName);
|
|
||||||
try {
|
|
||||||
if (repo.getObjectDatabase().exists()) {
|
|
||||||
throw new UnloggedFailure(1, "fatal: project \"" + projectName
|
|
||||||
+ "\" exists");
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
repo.close();
|
|
||||||
}
|
|
||||||
} catch (RepositoryNotFoundException err) {
|
|
||||||
throw new Failure(1, "fatal: Cannot create " + projectName, err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,138 @@
|
|||||||
|
// Copyright (C) 2009 The Android Open Source Project
|
||||||
|
//
|
||||||
|
// 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.google.gerrit.sshd.commands;
|
||||||
|
|
||||||
|
import com.google.gerrit.common.errors.ProjectCreationFailedException;
|
||||||
|
import com.google.gerrit.reviewdb.AccountGroup;
|
||||||
|
import com.google.gerrit.reviewdb.Project.SubmitType;
|
||||||
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
|
import com.google.gerrit.server.project.CreateProject;
|
||||||
|
import com.google.gerrit.server.project.CreateProjectArgs;
|
||||||
|
import com.google.gerrit.server.project.ProjectControl;
|
||||||
|
import com.google.gerrit.sshd.BaseCommand;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import org.apache.sshd.server.Environment;
|
||||||
|
import org.eclipse.jgit.lib.Constants;
|
||||||
|
import org.kohsuke.args4j.Argument;
|
||||||
|
import org.kohsuke.args4j.Option;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/** Create a new project. **/
|
||||||
|
final class CreateProjectCommand extends BaseCommand {
|
||||||
|
@Option(name = "--name", aliases = {"-n"}, metaVar = "NAME", usage = "name of project to be created (deprecated option)")
|
||||||
|
void setProjectNameFromOption(String name) {
|
||||||
|
if (projectName != null) {
|
||||||
|
throw new IllegalArgumentException("NAME already supplied");
|
||||||
|
} else {
|
||||||
|
projectName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Option(name = "--owner", aliases = {"-o"}, usage = "owner(s) of project")
|
||||||
|
private List<AccountGroup.UUID> ownerIds;
|
||||||
|
|
||||||
|
@Option(name = "--parent", aliases = {"-p"}, metaVar = "NAME", usage = "parent project")
|
||||||
|
private ProjectControl newParent;
|
||||||
|
|
||||||
|
@Option(name = "--permissions-only", usage = "create project for use only as parent")
|
||||||
|
private boolean permissionsOnly;
|
||||||
|
|
||||||
|
@Option(name = "--description", aliases = {"-d"}, metaVar = "DESCRIPTION", usage = "description of project")
|
||||||
|
private String projectDescription = "";
|
||||||
|
|
||||||
|
@Option(name = "--submit-type", aliases = {"-t"}, usage = "project submit type\n"
|
||||||
|
+ "(default: MERGE_IF_NECESSARY)")
|
||||||
|
private SubmitType submitType = SubmitType.MERGE_IF_NECESSARY;
|
||||||
|
|
||||||
|
@Option(name = "--use-contributor-agreements", aliases = {"--ca"}, usage = "if contributor agreement is required")
|
||||||
|
private boolean contributorAgreements;
|
||||||
|
|
||||||
|
@Option(name = "--use-signed-off-by", aliases = {"--so"}, usage = "if signed-off-by is required")
|
||||||
|
private boolean signedOffBy;
|
||||||
|
|
||||||
|
@Option(name = "--use-content-merge", usage = "allow automatic conflict resolving within files")
|
||||||
|
private boolean contentMerge;
|
||||||
|
|
||||||
|
@Option(name = "--require-change-id", aliases = {"--id"}, usage = "if change-id is required")
|
||||||
|
private boolean requireChangeID;
|
||||||
|
|
||||||
|
@Option(name = "--branch", aliases = {"-b"}, metaVar = "BRANCH", usage = "initial branch name\n"
|
||||||
|
+ "(default: master)")
|
||||||
|
private String branch = Constants.MASTER;
|
||||||
|
|
||||||
|
@Option(name = "--empty-commit", usage = "to create initial empty commit")
|
||||||
|
private boolean createEmptyCommit;
|
||||||
|
|
||||||
|
private String projectName;
|
||||||
|
|
||||||
|
@Argument(index = 0, metaVar = "NAME", usage = "name of project to be created")
|
||||||
|
void setProjectNameFromArgument(String name) {
|
||||||
|
if (projectName != null) {
|
||||||
|
throw new IllegalArgumentException("--name already supplied");
|
||||||
|
} else {
|
||||||
|
projectName = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private IdentifiedUser currentUser;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CreateProject.Factory CreateProjectFactory;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(final Environment env) {
|
||||||
|
startThread(new CommandRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() throws Exception {
|
||||||
|
if (!currentUser.getCapabilities().canCreateProject()) {
|
||||||
|
String msg =
|
||||||
|
String.format(
|
||||||
|
"fatal: %s does not have \"Create Project\" capability.",
|
||||||
|
currentUser.getUserName());
|
||||||
|
throw new UnloggedFailure(BaseCommand.STATUS_NOT_ADMIN, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
parseCommandLine();
|
||||||
|
if (projectName == null) {
|
||||||
|
throw new UnloggedFailure(1, "fatal: Project name is required.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
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;
|
||||||
|
|
||||||
|
final CreateProject createProject = CreateProjectFactory.create(args);
|
||||||
|
createProject.createProject();
|
||||||
|
} catch (ProjectCreationFailedException err) {
|
||||||
|
throw new UnloggedFailure(1, "fatal: " + err.getMessage(), err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@@ -29,7 +29,7 @@ public class MasterCommandModule extends CommandModule {
|
|||||||
command(gerrit, "create-account").to(CreateAccountCommand.class);
|
command(gerrit, "create-account").to(CreateAccountCommand.class);
|
||||||
command(gerrit, "create-group").to(CreateGroupCommand.class);
|
command(gerrit, "create-group").to(CreateGroupCommand.class);
|
||||||
command(gerrit, "rename-group").to(RenameGroupCommand.class);
|
command(gerrit, "rename-group").to(RenameGroupCommand.class);
|
||||||
command(gerrit, "create-project").to(CreateProject.class);
|
command(gerrit, "create-project").to(CreateProjectCommand.class);
|
||||||
command(gerrit, "gsql").to(AdminQueryShell.class);
|
command(gerrit, "gsql").to(AdminQueryShell.class);
|
||||||
command(gerrit, "set-reviewers").to(SetReviewersCommand.class);
|
command(gerrit, "set-reviewers").to(SetReviewersCommand.class);
|
||||||
command(gerrit, "receive-pack").to(Receive.class);
|
command(gerrit, "receive-pack").to(Receive.class);
|
||||||
|
Reference in New Issue
Block a user