Skip to content

Remove references to ChildNameGenerator.beforeCreateItem #506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/main/java/jenkins/branch/MultiBranchProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

package jenkins.branch;

import com.cloudbees.hudson.plugins.folder.ChildNameGenerator;
import com.cloudbees.hudson.plugins.folder.FolderIcon;
import com.cloudbees.hudson.plugins.folder.computed.ChildObserver;
import com.cloudbees.hudson.plugins.folder.computed.ComputedFolder;
Expand Down Expand Up @@ -2092,21 +2091,16 @@ private void observeExisting(@NonNull SCMHead head, @NonNull SCMRevision revisio
}

private void observeNew(@NonNull SCMHead head, @NonNull SCMRevision revision, @NonNull Branch branch, String rawName, String encodedName, Action[] revisionActions) {
P project;
if (!observer.mayCreate(encodedName)) {
listener.getLogger().println("Ignoring duplicate branch project " + rawName);
return;
}
try (ChildNameGenerator.Trace trace = ChildNameGenerator.beforeCreateItem(
MultiBranchProject.this, encodedName, branch.getName()
)) {
Comment on lines -2100 to -2102
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (getItem(encodedName) != null) {
throw new IllegalStateException(
"JENKINS-42511: attempted to redundantly create " + encodedName + " in "
+ MultiBranchProject.this);
}
project = _factory.newInstance(branch);
if (getItem(encodedName) != null) {
throw new IllegalStateException(
"JENKINS-42511: attempted to redundantly create " + encodedName + " in "
+ MultiBranchProject.this);
}
P project = _factory.newInstance(branch);
if (!project.getName().equals(encodedName)) {
throw new IllegalStateException(
"Name of created project " + project + " did not match expected " + encodedName);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/jenkins/branch/MultiBranchProjectDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@
if (factory.isProject(item)) {
return NameEncoder.encode(factory.getBranch(item).getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameEncoder.encode(idealName);
String name = item.getName();
if (name != null) {
return NameEncoder.encode(name);

Check warning on line 236 in src/main/java/jenkins/branch/MultiBranchProjectDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 234-236 are not covered by tests
}
return null;
}
Expand All @@ -245,9 +245,9 @@
if (factory.isProject(item)) {
return NameMangler.apply(factory.getBranch(item).getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameMangler.apply(idealName);
String name = item.getName();
if (name != null) {

Check warning on line 249 in src/main/java/jenkins/branch/MultiBranchProjectDescriptor.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 249 is only partially covered, one branch is missing
return NameMangler.apply(name);
}
return null;
}
Expand Down
31 changes: 13 additions & 18 deletions src/main/java/jenkins/branch/OrganizationFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -852,23 +852,23 @@
if (property != null) {
return NameEncoder.encode(property.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameEncoder.encode(idealName);
String name = item.getName();
if (name != null) {
return NameEncoder.encode(name);
}
return null;
}

@Override
@CheckForNull
public String dirNameFromItem(@NonNull OrganizationFolder parent, @NonNull MultiBranchProject<?, ?> item) {
ProjectNameProperty property = item.getProperties().get(ProjectNameProperty.class);
if (property != null) {
return NameMangler.apply(property.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameMangler.apply(idealName);
String name = item.getName();
if (name != null) {
return NameMangler.apply(name);

Check warning on line 871 in src/main/java/jenkins/branch/OrganizationFolder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 855-871 are not covered by tests
}
return null;
}
Expand Down Expand Up @@ -1436,19 +1436,14 @@
.println("Ignoring duplicate child " + projectName + " named " + folderName);
return;
}
MultiBranchProject<?, ?> project;
try (ChildNameGenerator.Trace trace = ChildNameGenerator.beforeCreateItem(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AbstractWorkflowMultiBranchProjectFactory#doCreateProject does not attempt to save the project, and both SCMSourceObserver.ProjectObserver#completeNew and SCMSourceObserver.ProjectObserver#completeExisting use BulkChange, so idealNames is never consulted here.

OrganizationFolder.this, folderName, projectName
)) {
if (getItem(folderName) != null) {
throw new IllegalStateException(
"JENKINS-42511: attempted to redundantly create " + folderName + " in "
+ OrganizationFolder.this);
}
project = factory.createNewProject(
OrganizationFolder.this, folderName, sources, attributes, listener
);
if (getItem(folderName) != null) {
throw new IllegalStateException(
"JENKINS-42511: attempted to redundantly create " + folderName + " in "
+ OrganizationFolder.this);
}
MultiBranchProject<?, ?> project = factory.createNewProject(
OrganizationFolder.this, folderName, sources, attributes, listener
);
BulkChange bc = new BulkChange(project);
try {
if (!projectName.equals(folderName)) {
Expand Down
Loading