Add #getName() and #getNameKey() to ProjectState
This commit adds #getName() and #getNameKey() to ProjectState and migrates callers to spare calling #getProject() in many places. Change-Id: I124d370b47723ff3fc7d5bc51a697890a16ab01c
This commit is contained in:
parent
d46fb98646
commit
55326bd493
@ -184,7 +184,7 @@ public class ApprovalCopier {
|
|||||||
|
|
||||||
ChangeKind kind =
|
ChangeKind kind =
|
||||||
changeKindCache.getChangeKind(
|
changeKindCache.getChangeKind(
|
||||||
project.getProject().getNameKey(),
|
project.getNameKey(),
|
||||||
rw,
|
rw,
|
||||||
repoConfig,
|
repoConfig,
|
||||||
ObjectId.fromString(priorPs.getRevision().get()),
|
ObjectId.fromString(priorPs.getRevision().get()),
|
||||||
|
@ -135,7 +135,7 @@ public class ReviewerRecommender {
|
|||||||
.getProvider()
|
.getProvider()
|
||||||
.get()
|
.get()
|
||||||
.suggestReviewers(
|
.suggestReviewers(
|
||||||
projectState.getProject().getNameKey(),
|
projectState.getNameKey(),
|
||||||
changeNotes.getChangeId(),
|
changeNotes.getChangeId(),
|
||||||
query,
|
query,
|
||||||
reviewerScores.keySet()));
|
reviewerScores.keySet()));
|
||||||
@ -239,8 +239,7 @@ public class ReviewerRecommender {
|
|||||||
List<Predicate<ChangeData>> predicates = new ArrayList<>();
|
List<Predicate<ChangeData>> predicates = new ArrayList<>();
|
||||||
for (Account.Id id : candidates) {
|
for (Account.Id id : candidates) {
|
||||||
try {
|
try {
|
||||||
Predicate<ChangeData> projectQuery =
|
Predicate<ChangeData> projectQuery = changeQueryBuilder.project(projectState.getName());
|
||||||
changeQueryBuilder.project(projectState.getProject().getName());
|
|
||||||
|
|
||||||
// Get all labels for this project and create a compound OR query to
|
// Get all labels for this project and create a compound OR query to
|
||||||
// fetch all changes where users have applied one of these labels
|
// fetch all changes where users have applied one of these labels
|
||||||
|
@ -76,7 +76,7 @@ public class CherryPickCommit
|
|||||||
input.message = message.isEmpty() ? commit.getFullMessage() : message;
|
input.message = message.isEmpty() ? commit.getFullMessage() : message;
|
||||||
String destination = Strings.nullToEmpty(input.destination).trim();
|
String destination = Strings.nullToEmpty(input.destination).trim();
|
||||||
input.parent = input.parent == null ? 1 : input.parent;
|
input.parent = input.parent == null ? 1 : input.parent;
|
||||||
Project.NameKey projectName = rsrc.getProjectState().getProject().getNameKey();
|
Project.NameKey projectName = rsrc.getProjectState().getNameKey();
|
||||||
|
|
||||||
if (destination.isEmpty()) {
|
if (destination.isEmpty()) {
|
||||||
throw new BadRequestException("destination must be non-empty");
|
throw new BadRequestException("destination must be non-empty");
|
||||||
@ -99,7 +99,7 @@ public class CherryPickCommit
|
|||||||
projectName,
|
projectName,
|
||||||
commit,
|
commit,
|
||||||
input,
|
input,
|
||||||
new Branch.NameKey(rsrc.getProjectState().getProject().getNameKey(), refName));
|
new Branch.NameKey(rsrc.getProjectState().getNameKey(), refName));
|
||||||
return json.noOptions().format(projectName, cherryPickedChangeId);
|
return json.noOptions().format(projectName, cherryPickedChangeId);
|
||||||
} catch (InvalidChangeOperationException e) {
|
} catch (InvalidChangeOperationException e) {
|
||||||
throw new BadRequestException(e.getMessage());
|
throw new BadRequestException(e.getMessage());
|
||||||
|
@ -315,6 +315,6 @@ public class FileContentUtil {
|
|||||||
|
|
||||||
private Repository openRepository(ProjectState project)
|
private Repository openRepository(ProjectState project)
|
||||||
throws RepositoryNotFoundException, IOException {
|
throws RepositoryNotFoundException, IOException {
|
||||||
return repoManager.openRepository(project.getProject().getNameKey());
|
return repoManager.openRepository(project.getNameKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ public class GetDiff implements RestReadView<FileResource> {
|
|||||||
|
|
||||||
List<DiffWebLinkInfo> links =
|
List<DiffWebLinkInfo> links =
|
||||||
webLinks.getDiffLinks(
|
webLinks.getDiffLinks(
|
||||||
state.getProject().getName(),
|
state.getName(),
|
||||||
resource.getPatchKey().getParentKey().getParentKey().get(),
|
resource.getPatchKey().getParentKey().getParentKey().get(),
|
||||||
basePatchSet != null ? basePatchSet.getId().get() : null,
|
basePatchSet != null ? basePatchSet.getId().get() : null,
|
||||||
revA,
|
revA,
|
||||||
|
@ -95,7 +95,7 @@ public class MergeOpRepoManager implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Project.NameKey getProjectName() {
|
Project.NameKey getProjectName() {
|
||||||
return project.getProject().getNameKey();
|
return project.getNameKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeReviewRevWalk getCodeReviewRevWalk() {
|
public CodeReviewRevWalk getCodeReviewRevWalk() {
|
||||||
|
@ -188,7 +188,7 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
|||||||
if (!deferredTags.isEmpty() && (!result.isEmpty() || filterTagsSeparately)) {
|
if (!deferredTags.isEmpty() && (!result.isEmpty() || filterTagsSeparately)) {
|
||||||
TagMatcher tags =
|
TagMatcher tags =
|
||||||
tagCache
|
tagCache
|
||||||
.get(projectState.getProject().getNameKey())
|
.get(projectState.getNameKey())
|
||||||
.matcher(
|
.matcher(
|
||||||
tagCache,
|
tagCache,
|
||||||
git,
|
git,
|
||||||
@ -268,7 +268,7 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Change.Id, Branch.NameKey> visibleChangesBySearch() {
|
private Map<Change.Id, Branch.NameKey> visibleChangesBySearch() {
|
||||||
Project.NameKey project = projectState.getProject().getNameKey();
|
Project.NameKey project = projectState.getNameKey();
|
||||||
try {
|
try {
|
||||||
Map<Change.Id, Branch.NameKey> visibleChanges = new HashMap<>();
|
Map<Change.Id, Branch.NameKey> visibleChanges = new HashMap<>();
|
||||||
for (ChangeData cd : changeCache.getChangeData(db.get(), project)) {
|
for (ChangeData cd : changeCache.getChangeData(db.get(), project)) {
|
||||||
@ -286,7 +286,7 @@ public class VisibleRefFilter extends AbstractAdvertiseRefsHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Map<Change.Id, Branch.NameKey> visibleChangesByScan() {
|
private Map<Change.Id, Branch.NameKey> visibleChangesByScan() {
|
||||||
Project.NameKey p = projectState.getProject().getNameKey();
|
Project.NameKey p = projectState.getNameKey();
|
||||||
Stream<ChangeNotesResult> s;
|
Stream<ChangeNotesResult> s;
|
||||||
try {
|
try {
|
||||||
s = changeNotesFactory.scan(git, db.get(), p);
|
s = changeNotesFactory.scan(git, db.get(), p);
|
||||||
|
@ -526,7 +526,7 @@ abstract class SubmitStrategyOp implements BatchUpdateOp {
|
|||||||
try (Repository git = args.repoManager.openRepository(getProject())) {
|
try (Repository git = args.repoManager.openRepository(getProject())) {
|
||||||
git.setGitwebDescription(p.getProject().getDescription());
|
git.setGitwebDescription(p.getProject().getDescription());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("cannot update description of " + p.getProject().getName(), e);
|
log.error("cannot update description of " + p.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ public class MergeValidators {
|
|||||||
if (RefNames.REFS_CONFIG.equals(destBranch.get())) {
|
if (RefNames.REFS_CONFIG.equals(destBranch.get())) {
|
||||||
final Project.NameKey newParent;
|
final Project.NameKey newParent;
|
||||||
try {
|
try {
|
||||||
ProjectConfig cfg = new ProjectConfig(destProject.getProject().getNameKey());
|
ProjectConfig cfg = new ProjectConfig(destProject.getNameKey());
|
||||||
cfg.load(repo, commit);
|
cfg.load(repo, commit);
|
||||||
newParent = cfg.getProject().getParent(allProjectsName);
|
newParent = cfg.getProject().getParent(allProjectsName);
|
||||||
final Project.NameKey oldParent = destProject.getProject().getParent(allProjectsName);
|
final Project.NameKey oldParent = destProject.getProject().getParent(allProjectsName);
|
||||||
@ -256,7 +256,7 @@ public class MergeValidators {
|
|||||||
IdentifiedUser caller)
|
IdentifiedUser caller)
|
||||||
throws MergeValidationException {
|
throws MergeValidationException {
|
||||||
Account.Id accountId = Account.Id.fromRef(destBranch.get());
|
Account.Id accountId = Account.Id.fromRef(destBranch.get());
|
||||||
if (!allUsersName.equals(destProject.getProject().getNameKey()) || accountId == null) {
|
if (!allUsersName.equals(destProject.getNameKey()) || accountId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,9 +258,7 @@ public class CommentSender extends ReplyToChangeSender {
|
|||||||
log.warn(
|
log.warn(
|
||||||
String.format(
|
String.format(
|
||||||
"Cannot load %s from %s in %s",
|
"Cannot load %s from %s in %s",
|
||||||
c.key.filename,
|
c.key.filename, patchList.getNewId().name(), projectState.getName()),
|
||||||
patchList.getNewId().name(),
|
|
||||||
projectState.getProject().getName()),
|
|
||||||
e);
|
e);
|
||||||
currentGroup.fileData = null;
|
currentGroup.fileData = null;
|
||||||
}
|
}
|
||||||
@ -586,7 +584,7 @@ public class CommentSender extends ReplyToChangeSender {
|
|||||||
|
|
||||||
private Repository getRepository() {
|
private Repository getRepository() {
|
||||||
try {
|
try {
|
||||||
return args.server.openRepository(projectState.getProject().getNameKey());
|
return args.server.openRepository(projectState.getNameKey());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ public class ProjectWatch {
|
|||||||
} catch (QueryParseException e) {
|
} catch (QueryParseException e) {
|
||||||
log.warn(
|
log.warn(
|
||||||
"Project {} has invalid notify {} filter \"{}\": {}",
|
"Project {} has invalid notify {} filter \"{}\": {}",
|
||||||
state.getProject().getName(),
|
state.getName(),
|
||||||
nc.getName(),
|
nc.getName(),
|
||||||
nc.getFilter(),
|
nc.getFilter(),
|
||||||
e.getMessage());
|
e.getMessage());
|
||||||
|
@ -41,6 +41,6 @@ public class ChildProjectResource implements RestResource {
|
|||||||
|
|
||||||
public boolean isDirectChild() {
|
public boolean isDirectChild() {
|
||||||
ProjectState firstParent = Iterables.getFirst(child.parents(), null);
|
ProjectState firstParent = Iterables.getFirst(child.parents(), null);
|
||||||
return firstParent != null && parent.getNameKey().equals(firstParent.getProject().getNameKey());
|
return firstParent != null && parent.getNameKey().equals(firstParent.getNameKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ class CommitIncludedIn implements RestReadView<CommitResource> {
|
|||||||
public IncludedInInfo apply(CommitResource rsrc)
|
public IncludedInInfo apply(CommitResource rsrc)
|
||||||
throws RestApiException, OrmException, IOException {
|
throws RestApiException, OrmException, IOException {
|
||||||
RevCommit commit = rsrc.getCommit();
|
RevCommit commit = rsrc.getCommit();
|
||||||
Project.NameKey project = rsrc.getProjectState().getProject().getNameKey();
|
Project.NameKey project = rsrc.getProjectState().getNameKey();
|
||||||
return includedIn.apply(project, commit.getId().getName());
|
return includedIn.apply(project, commit.getId().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public class CommitsCollection implements ChildCollection<ProjectResource, Commi
|
|||||||
|
|
||||||
/** @return true if {@code commit} is visible to the caller. */
|
/** @return true if {@code commit} is visible to the caller. */
|
||||||
public boolean canRead(ProjectState state, Repository repo, RevCommit commit) {
|
public boolean canRead(ProjectState state, Repository repo, RevCommit commit) {
|
||||||
Project.NameKey project = state.getProject().getNameKey();
|
Project.NameKey project = state.getNameKey();
|
||||||
|
|
||||||
// Look for changes associated with the commit.
|
// Look for changes associated with the commit.
|
||||||
try {
|
try {
|
||||||
@ -126,7 +126,7 @@ public class CommitsCollection implements ChildCollection<ProjectResource, Commi
|
|||||||
log.error(
|
log.error(
|
||||||
String.format(
|
String.format(
|
||||||
"Cannot verify permissions to commit object %s in repository %s",
|
"Cannot verify permissions to commit object %s in repository %s",
|
||||||
commit.name(), state.getProject().getNameKey()),
|
commit.name(), state.getNameKey()),
|
||||||
e);
|
e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ public class ConfigInfoImpl extends ConfigInfo {
|
|||||||
p.type = configEntry.getType();
|
p.type = configEntry.getType();
|
||||||
p.permittedValues = configEntry.getPermittedValues();
|
p.permittedValues = configEntry.getPermittedValues();
|
||||||
p.editable = configEntry.isEditable(project) ? true : null;
|
p.editable = configEntry.isEditable(project) ? true : null;
|
||||||
if (configEntry.isInheritable() && !allProjects.equals(project.getProject().getNameKey())) {
|
if (configEntry.isInheritable() && !allProjects.equals(project.getNameKey())) {
|
||||||
PluginConfig cfgWithInheritance =
|
PluginConfig cfgWithInheritance =
|
||||||
cfgFactory.getFromProjectConfigWithInheritance(project, e.getPluginName());
|
cfgFactory.getFromProjectConfigWithInheritance(project, e.getPluginName());
|
||||||
p.inheritable = true;
|
p.inheritable = true;
|
||||||
|
@ -34,7 +34,7 @@ public class FileResource implements RestResource {
|
|||||||
public static FileResource create(
|
public static FileResource create(
|
||||||
GitRepositoryManager repoManager, ProjectState projectState, ObjectId rev, String path)
|
GitRepositoryManager repoManager, ProjectState projectState, ObjectId rev, String path)
|
||||||
throws ResourceNotFoundException, IOException {
|
throws ResourceNotFoundException, IOException {
|
||||||
try (Repository repo = repoManager.openRepository(projectState.getProject().getNameKey());
|
try (Repository repo = repoManager.openRepository(projectState.getNameKey());
|
||||||
RevWalk rw = new RevWalk(repo)) {
|
RevWalk rw = new RevWalk(repo)) {
|
||||||
RevTree tree = rw.parseTree(rev);
|
RevTree tree = rw.parseTree(rev);
|
||||||
if (TreeWalk.forPath(repo, path, tree) != null) {
|
if (TreeWalk.forPath(repo, path, tree) != null) {
|
||||||
|
@ -39,6 +39,6 @@ public class GetChildProject implements RestReadView<ChildProjectResource> {
|
|||||||
if (recursive || rsrc.isDirectChild()) {
|
if (recursive || rsrc.isDirectChild()) {
|
||||||
return json.format(rsrc.getChild().getProject());
|
return json.format(rsrc.getChild().getProject());
|
||||||
}
|
}
|
||||||
throw new ResourceNotFoundException(rsrc.getChild().getProject().getName());
|
throw new ResourceNotFoundException(rsrc.getChild().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public class ListChildProjects implements RestReadView<ProjectResource> {
|
|||||||
for (Project.NameKey name : projectCache.all()) {
|
for (Project.NameKey name : projectCache.all()) {
|
||||||
ProjectState c = projectCache.get(name);
|
ProjectState c = projectCache.get(name);
|
||||||
if (c != null && parent.equals(c.getProject().getParent(allProjects))) {
|
if (c != null && parent.equals(c.getProject().getParent(allProjects))) {
|
||||||
children.put(c.getProject().getNameKey(), c.getProject());
|
children.put(c.getNameKey(), c.getProject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return permissionBackend
|
return permissionBackend
|
||||||
@ -105,7 +105,7 @@ public class ListChildProjects implements RestReadView<ProjectResource> {
|
|||||||
for (Project.NameKey name : projectCache.all()) {
|
for (Project.NameKey name : projectCache.all()) {
|
||||||
ProjectState c = projectCache.get(name);
|
ProjectState c = projectCache.get(name);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
projects.put(c.getProject().getNameKey(), c.getProject());
|
projects.put(c.getNameKey(), c.getProject());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return projects;
|
return projects;
|
||||||
|
@ -93,7 +93,7 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
private Collection<ProjectState> tree(ProjectResource rsrc) throws PermissionBackendException {
|
private Collection<ProjectState> tree(ProjectResource rsrc) throws PermissionBackendException {
|
||||||
Map<Project.NameKey, ProjectState> tree = new LinkedHashMap<>();
|
Map<Project.NameKey, ProjectState> tree = new LinkedHashMap<>();
|
||||||
for (ProjectState ps : rsrc.getProjectState().tree()) {
|
for (ProjectState ps : rsrc.getProjectState().tree()) {
|
||||||
tree.put(ps.getProject().getNameKey(), ps);
|
tree.put(ps.getNameKey(), ps);
|
||||||
}
|
}
|
||||||
tree.keySet()
|
tree.keySet()
|
||||||
.retainAll(permissionBackend.user(user).filter(ProjectPermission.ACCESS, tree.keySet()));
|
.retainAll(permissionBackend.user(user).filter(ProjectPermission.ACCESS, tree.keySet()));
|
||||||
@ -102,10 +102,8 @@ class ListDashboards implements RestReadView<ProjectResource> {
|
|||||||
|
|
||||||
private List<DashboardInfo> scan(ProjectState state, String project, boolean setDefault)
|
private List<DashboardInfo> scan(ProjectState state, String project, boolean setDefault)
|
||||||
throws ResourceNotFoundException, IOException, PermissionBackendException {
|
throws ResourceNotFoundException, IOException, PermissionBackendException {
|
||||||
Project.NameKey projectName = state.getProject().getNameKey();
|
PermissionBackend.ForProject perm = permissionBackend.user(user).project(state.getNameKey());
|
||||||
PermissionBackend.ForProject perm =
|
try (Repository git = gitManager.openRepository(state.getNameKey());
|
||||||
permissionBackend.user(user).project(state.getProject().getNameKey());
|
|
||||||
try (Repository git = gitManager.openRepository(projectName);
|
|
||||||
RevWalk rw = new RevWalk(git)) {
|
RevWalk rw = new RevWalk(git)) {
|
||||||
List<DashboardInfo> all = new ArrayList<>();
|
List<DashboardInfo> all = new ArrayList<>();
|
||||||
for (Ref ref : git.getRefDatabase().getRefs(REFS_DASHBOARDS).values()) {
|
for (Ref ref : git.getRefDatabase().getRefs(REFS_DASHBOARDS).values()) {
|
||||||
|
@ -373,12 +373,12 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
|||||||
ProjectState parent = Iterables.getFirst(e.parents(), null);
|
ProjectState parent = Iterables.getFirst(e.parents(), null);
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
if (isParentAccessible(accessibleParents, perm, parent)) {
|
if (isParentAccessible(accessibleParents, perm, parent)) {
|
||||||
info.parent = parent.getProject().getName();
|
info.parent = parent.getName();
|
||||||
} else {
|
} else {
|
||||||
info.parent = hiddenNames.get(parent.getProject().getName());
|
info.parent = hiddenNames.get(parent.getName());
|
||||||
if (info.parent == null) {
|
if (info.parent == null) {
|
||||||
info.parent = "?-" + (hiddenNames.size() + 1);
|
info.parent = "?-" + (hiddenNames.size() + 1);
|
||||||
hiddenNames.put(parent.getProject().getName(), info.parent);
|
hiddenNames.put(parent.getName(), info.parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -506,8 +506,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
|||||||
} else {
|
} else {
|
||||||
log.warn(
|
log.warn(
|
||||||
String.format(
|
String.format(
|
||||||
"parent project %s of project %s not found",
|
"parent project %s of project %s not found", parent.get(), ps.getName()));
|
||||||
parent.get(), ps.getProject().getName()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -518,7 +517,7 @@ public class ListProjects implements RestReadView<TopLevelResource> {
|
|||||||
private boolean isParentAccessible(
|
private boolean isParentAccessible(
|
||||||
Map<Project.NameKey, Boolean> checked, PermissionBackend.WithUser perm, ProjectState p)
|
Map<Project.NameKey, Boolean> checked, PermissionBackend.WithUser perm, ProjectState p)
|
||||||
throws PermissionBackendException {
|
throws PermissionBackendException {
|
||||||
Project.NameKey name = p.getProject().getNameKey();
|
Project.NameKey name = p.getNameKey();
|
||||||
Boolean b = checked.get(name);
|
Boolean b = checked.get(name);
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
try {
|
try {
|
||||||
|
@ -274,8 +274,7 @@ public class ProjectControl {
|
|||||||
if (!canPerformOnAnyRef(Permission.PUSH)
|
if (!canPerformOnAnyRef(Permission.PUSH)
|
||||||
&& !canPerformOnAnyRef(Permission.CREATE_TAG)
|
&& !canPerformOnAnyRef(Permission.CREATE_TAG)
|
||||||
&& !isOwner()) {
|
&& !isOwner()) {
|
||||||
String pName = state.getProject().getName();
|
return new Capable("Upload denied for project '" + state.getName() + "'");
|
||||||
return new Capable("Upload denied for project '" + pName + "'");
|
|
||||||
}
|
}
|
||||||
if (state.isUseContributorAgreements()) {
|
if (state.isUseContributorAgreements()) {
|
||||||
return verifyActiveContributorAgreement();
|
return verifyActiveContributorAgreement();
|
||||||
|
@ -44,7 +44,7 @@ class ProjectHierarchyIterator implements Iterator<ProjectState> {
|
|||||||
allProjectsName = all;
|
allProjectsName = all;
|
||||||
|
|
||||||
seen = Sets.newLinkedHashSet();
|
seen = Sets.newLinkedHashSet();
|
||||||
seen.add(firstResult.getProject().getNameKey());
|
seen.add(firstResult.getNameKey());
|
||||||
next = firstResult;
|
next = firstResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ public class ProjectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRevisionOutOfDate() {
|
private boolean isRevisionOutOfDate() {
|
||||||
try (Repository git = gitMgr.openRepository(getProject().getNameKey())) {
|
try (Repository git = gitMgr.openRepository(getNameKey())) {
|
||||||
Ref ref = git.getRefDatabase().exactRef(RefNames.REFS_CONFIG);
|
Ref ref = git.getRefDatabase().exactRef(RefNames.REFS_CONFIG);
|
||||||
if (ref == null || ref.getObjectId() == null) {
|
if (ref == null || ref.getObjectId() == null) {
|
||||||
return true;
|
return true;
|
||||||
@ -203,7 +203,7 @@ public class ProjectState {
|
|||||||
public PrologEnvironment newPrologEnvironment() throws CompileException {
|
public PrologEnvironment newPrologEnvironment() throws CompileException {
|
||||||
PrologMachineCopy pmc = rulesMachine;
|
PrologMachineCopy pmc = rulesMachine;
|
||||||
if (pmc == null) {
|
if (pmc == null) {
|
||||||
pmc = rulesCache.loadMachine(getProject().getNameKey(), config.getRulesId());
|
pmc = rulesCache.loadMachine(getNameKey(), config.getRulesId());
|
||||||
rulesMachine = pmc;
|
rulesMachine = pmc;
|
||||||
}
|
}
|
||||||
return envFactory.create(pmc);
|
return envFactory.create(pmc);
|
||||||
@ -226,6 +226,14 @@ public class ProjectState {
|
|||||||
return config.getProject();
|
return config.getProject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Project.NameKey getNameKey() {
|
||||||
|
return getProject().getNameKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return getNameKey().get();
|
||||||
|
}
|
||||||
|
|
||||||
public ProjectConfig getConfig() {
|
public ProjectConfig getConfig() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@ -236,10 +244,10 @@ public class ProjectState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProjectLevelConfig cfg = new ProjectLevelConfig(fileName, this);
|
ProjectLevelConfig cfg = new ProjectLevelConfig(fileName, this);
|
||||||
try (Repository git = gitMgr.openRepository(getProject().getNameKey())) {
|
try (Repository git = gitMgr.openRepository(getNameKey())) {
|
||||||
cfg.load(git);
|
cfg.load(git);
|
||||||
} catch (IOException | ConfigInvalidException e) {
|
} catch (IOException | ConfigInvalidException e) {
|
||||||
log.warn("Failed to load " + fileName + " for " + getProject().getName(), e);
|
log.warn("Failed to load " + fileName + " for " + getName(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
configs.put(fileName, cfg);
|
configs.put(fileName, cfg);
|
||||||
@ -268,7 +276,7 @@ public class ProjectState {
|
|||||||
section.setPermissions(copy);
|
section.setPermissions(copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
SectionMatcher matcher = SectionMatcher.wrap(getProject().getNameKey(), section);
|
SectionMatcher matcher = SectionMatcher.wrap(getNameKey(), section);
|
||||||
if (matcher != null) {
|
if (matcher != null) {
|
||||||
sm.add(matcher);
|
sm.add(matcher);
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
|
|||||||
|
|
||||||
public ConfigInfo apply(ProjectState projectState, ConfigInput input)
|
public ConfigInfo apply(ProjectState projectState, ConfigInput input)
|
||||||
throws ResourceNotFoundException, BadRequestException, ResourceConflictException {
|
throws ResourceNotFoundException, BadRequestException, ResourceConflictException {
|
||||||
Project.NameKey projectName = projectState.getProject().getNameKey();
|
Project.NameKey projectName = projectState.getNameKey();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
throw new BadRequestException("config is required");
|
throw new BadRequestException("config is required");
|
||||||
}
|
}
|
||||||
@ -309,7 +309,7 @@ public class PutConfig implements RestModifyView<ProjectResource, ConfigInput> {
|
|||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
String.format(
|
String.format(
|
||||||
"Not allowed to set parameter '%s' of plugin '%s' on project '%s'.",
|
"Not allowed to set parameter '%s' of plugin '%s' on project '%s'.",
|
||||||
parameterName, pluginName, projectState.getProject().getName()));
|
parameterName, pluginName, projectState.getName()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,7 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
|||||||
IdentifiedUser user = rsrc.getUser().asIdentifiedUser();
|
IdentifiedUser user = rsrc.getUser().asIdentifiedUser();
|
||||||
String parentName =
|
String parentName =
|
||||||
MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
|
MoreObjects.firstNonNull(Strings.emptyToNull(input.parent), allProjects.get());
|
||||||
validateParentUpdate(
|
validateParentUpdate(rsrc.getProjectState().getNameKey(), user, parentName, checkIfAdmin);
|
||||||
rsrc.getProjectState().getProject().getNameKey(), user, parentName, checkIfAdmin);
|
|
||||||
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
|
try (MetaDataUpdate md = updateFactory.create(rsrc.getNameKey())) {
|
||||||
ProjectConfig config = ProjectConfig.read(md);
|
ProjectConfig config = ProjectConfig.read(md);
|
||||||
Project project = config.getProject();
|
Project project = config.getProject();
|
||||||
@ -128,11 +127,11 @@ public class SetParent implements RestModifyView<ProjectResource, Input> {
|
|||||||
if (Iterables.tryFind(
|
if (Iterables.tryFind(
|
||||||
parent.tree(),
|
parent.tree(),
|
||||||
p -> {
|
p -> {
|
||||||
return p.getProject().getNameKey().equals(project);
|
return p.getNameKey().equals(project);
|
||||||
})
|
})
|
||||||
.isPresent()) {
|
.isPresent()) {
|
||||||
throw new ResourceConflictException(
|
throw new ResourceConflictException(
|
||||||
"cycle exists between " + project.get() + " and " + parent.getProject().getName());
|
"cycle exists between " + project.get() + " and " + parent.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,8 +600,7 @@ public class SubmitRuleEvaluator {
|
|||||||
try {
|
try {
|
||||||
parentEnv = parentState.newPrologEnvironment();
|
parentEnv = parentState.newPrologEnvironment();
|
||||||
} catch (CompileException err) {
|
} catch (CompileException err) {
|
||||||
throw new RuleEvalException(
|
throw new RuleEvalException("Cannot consult rules.pl for " + parentState.getName(), err);
|
||||||
"Cannot consult rules.pl for " + parentState.getProject().getName(), err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parentEnv.copyStoredValues(childEnv);
|
parentEnv.copyStoredValues(childEnv);
|
||||||
@ -619,12 +618,12 @@ public class SubmitRuleEvaluator {
|
|||||||
throw new RuleEvalException(
|
throw new RuleEvalException(
|
||||||
String.format(
|
String.format(
|
||||||
"%s on change %d of %s",
|
"%s on change %d of %s",
|
||||||
err.getMessage(), cd.getId().get(), parentState.getProject().getName()));
|
err.getMessage(), cd.getId().get(), parentState.getName()));
|
||||||
} catch (RuntimeException err) {
|
} catch (RuntimeException err) {
|
||||||
throw new RuleEvalException(
|
throw new RuleEvalException(
|
||||||
String.format(
|
String.format(
|
||||||
"Exception calling %s on change %d of %s",
|
"Exception calling %s on change %d of %s",
|
||||||
filterRule, cd.getId().get(), parentState.getProject().getName()),
|
filterRule, cd.getId().get(), parentState.getName()),
|
||||||
err);
|
err);
|
||||||
} finally {
|
} finally {
|
||||||
reductionsConsumed += env.getReductions();
|
reductionsConsumed += env.getReductions();
|
||||||
@ -690,6 +689,6 @@ public class SubmitRuleEvaluator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getProjectName() {
|
private String getProjectName() {
|
||||||
return control.getProjectControl().getProjectState().getProject().getName();
|
return control.getProjectControl().getProjectState().getName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class ParentProjectPredicate extends OrPredicate<ChangeData> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Predicate<ChangeData>> r = new ArrayList<>();
|
List<Predicate<ChangeData>> r = new ArrayList<>();
|
||||||
r.add(new ProjectPredicate(projectState.getProject().getName()));
|
r.add(new ProjectPredicate(projectState.getName()));
|
||||||
try {
|
try {
|
||||||
ProjectResource proj = new ProjectResource(projectState.controlFor(self.get()));
|
ProjectResource proj = new ProjectResource(projectState.controlFor(self.get()));
|
||||||
ListChildProjects children = listChildProjects.get();
|
ListChildProjects children = listChildProjects.get();
|
||||||
|
@ -69,8 +69,7 @@ public abstract class AbstractGitCommand extends BaseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Project.NameKey getProjectName() {
|
public Project.NameKey getProjectName() {
|
||||||
Project project = projectControl.getProjectState().getProject();
|
return projectControl.getProjectState().getNameKey();
|
||||||
return project.getNameKey();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -226,6 +226,6 @@ final class AdminSetParent extends SshCommand {
|
|||||||
if (ps == null) {
|
if (ps == null) {
|
||||||
return Collections.emptySet();
|
return Collections.emptySet();
|
||||||
}
|
}
|
||||||
return ps.parents().transform(s -> s.getProject().getNameKey()).toSet();
|
return ps.parents().transform(s -> s.getNameKey()).toSet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user