Skip to content
Permalink
Browse files

[JENKINS-41124] Pick up API changes in cloudbees-folder

  • Loading branch information...
stephenc committed Jan 18, 2017
1 parent e59d147 commit 61e5af591751bfd81f25f4fb1fa30d9f9ad2e90d
@@ -93,7 +93,7 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>cloudbees-folder</artifactId>
<version>5.17-SNAPSHOT</version>
<version>5.17-20170118.164532-2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -24,6 +24,8 @@

package jenkins.branch;

import com.cloudbees.hudson.plugins.folder.AbstractFolder;
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;
@@ -1798,13 +1800,14 @@ public void observe(@NonNull SCMHead head, @NonNull SCMRevision revision) {
listener.getLogger().println("Ignoring duplicate branch project " + rawName);
return;
}
MultiBranchProjectDescriptor.BranchNameKey branchNameKey =
MultiBranchProjectDescriptor.ChildNameGeneratorImpl.INSTANCE
.beforeNewProject(MultiBranchProject.this, encodedName, branch);
ChildNameGenerator<AbstractFolder<P>, P> childNameGenerator = getDescriptor().<P>childNameGenerator();
ChildNameGenerator.Trace trace = childNameGenerator.beforeCreateItem(
MultiBranchProject.this, branch.getEncodedName(), branch.getName()
);
try {
project = _factory.newInstance(branch);
} finally {
MultiBranchProjectDescriptor.ChildNameGeneratorImpl.INSTANCE.afterNewProject(branchNameKey);
childNameGenerator.afterItemCreated(trace);
}
if (!project.getName().equals(encodedName)) {
throw new IllegalStateException(
@@ -225,20 +225,6 @@ public boolean isIconConfigurable() {
R extends Run<P, R>> extends ChildNameGenerator<MultiBranchProject<P,R>,P> {

/*package*/ static final ChildNameGeneratorImpl INSTANCE = new ChildNameGeneratorImpl();
private final WeakHashMap<BranchNameKey, Branch> awaitingCreation =
new WeakHashMap<>();

public synchronized BranchNameKey beforeNewProject(
@NonNull MultiBranchProject<?,?> parent, @NonNull String name, Branch branch) {
BranchNameKey key = new BranchNameKey(parent, name);
awaitingCreation.put(key, branch);
return key;
}

public synchronized void afterNewProject(BranchNameKey key) {
awaitingCreation.remove(key); // not critical as will get cleared by GC but we can help it out too
}


@Override
@CheckForNull
@@ -247,14 +233,9 @@ public String itemNameFromItem(@NonNull MultiBranchProject<P,R> parent, @NonNull
if (factory.isProject(item)) {
return NameEncoder.encode(factory.getBranch(item).getName());
}
if (item.getName() != null) {
Branch branch;
synchronized (this) {
branch = awaitingCreation.get(new BranchNameKey(parent, item.getName()));
}
if (branch != null) {
return NameEncoder.encode(branch.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameEncoder.encode(idealName);
}
return null;
}
@@ -266,14 +247,9 @@ public String dirNameFromItem(@NonNull MultiBranchProject<P,R> parent, @NonNull
if (factory.isProject(item)) {
return NameMangler.apply(factory.getBranch(item).getName());
}
if (item.getName() != null) {
Branch branch;
synchronized (this) {
branch = awaitingCreation.get(new BranchNameKey(parent, item.getName()));
}
if (branch != null) {
return NameMangler.apply(branch.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameMangler.apply(idealName);
}
return null;
}
@@ -292,37 +268,4 @@ public String dirNameFromLegacy(@NonNull MultiBranchProject<P, R> parent, @NonNu

}

/*package*/ static class BranchNameKey {
private final MultiBranchProject<?, ?> parent;
private final String projectName;

public BranchNameKey(MultiBranchProject<?, ?> parent, String projectName) {
this.parent = parent;
this.projectName = projectName;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

BranchNameKey that = (BranchNameKey) o;

if (parent != that.parent) {
return false;
}
return projectName.equals(that.projectName);
}

@Override
public int hashCode() {
return projectName.hashCode();
}

}

}
@@ -70,7 +70,6 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
@@ -93,7 +92,6 @@
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.impl.SingleSCMNavigator;
import jenkins.scm.impl.UncategorizedSCMSourceCategory;
import net.jcip.annotations.GuardedBy;
import org.acegisecurity.AccessDeniedException;
import org.apache.commons.io.Charsets;
import org.apache.commons.lang.StringUtils;
@@ -771,17 +769,6 @@ public boolean isIconConfigurable() {
private static class ChildNameGeneratorImpl extends ChildNameGenerator<OrganizationFolder, MultiBranchProject<?,?>> {

private static final ChildNameGeneratorImpl INSTANCE = new ChildNameGeneratorImpl();
private final WeakHashMap<ProjectNamePropertyKey, ProjectNameProperty> awaitingCreation = new WeakHashMap<>();

public synchronized ProjectNamePropertyKey beforeNewProject(@NonNull OrganizationFolder parent, @NonNull String name, ProjectNameProperty property) {
ProjectNamePropertyKey key = new ProjectNamePropertyKey(parent, name);
awaitingCreation.put(key, property);
return key;
}

public synchronized void afterNewProject(ProjectNamePropertyKey key) {
awaitingCreation.remove(key); // not critical as will get cleared by GC but we can help it out too
}

@Override
@CheckForNull
@@ -790,13 +777,9 @@ public String itemNameFromItem(@NonNull OrganizationFolder parent, @NonNull Mult
if (property != null) {
return NameEncoder.encode(property.getName());
}
if (item.getName() != null) {
synchronized (this) {
property = awaitingCreation.get(new ProjectNamePropertyKey(parent, item.getName()));
}
if (property != null) {
return NameEncoder.encode(property.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameEncoder.encode(idealName);
}
return null;
}
@@ -808,13 +791,9 @@ public String dirNameFromItem(@NonNull OrganizationFolder parent, @NonNull Multi
if (property != null) {
return NameMangler.apply(property.getName());
}
if (item.getName() != null) {
synchronized (this) {
property = awaitingCreation.get(new ProjectNamePropertyKey(parent, item.getName()));
}
if (property != null) {
return NameMangler.apply(property.getName());
}
String idealName = idealNameFromItem(parent, item);
if (idealName != null) {
return NameMangler.apply(idealName);
}
return null;
}
@@ -832,38 +811,6 @@ public String dirNameFromLegacy(@NonNull OrganizationFolder parent, @NonNull Str
}
}

private static class ProjectNamePropertyKey {
private final OrganizationFolder parent;
private final String projectName;

public ProjectNamePropertyKey(OrganizationFolder parent, String projectName) {
this.parent = parent;
this.projectName = projectName;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ProjectNamePropertyKey that = (ProjectNamePropertyKey) o;

if (parent != that.parent) {
return false;
}
return projectName.equals(that.projectName);
}

@Override
public int hashCode() {
return projectName.hashCode();
}
}

/**
* Our scan.
*/
@@ -1220,23 +1167,23 @@ public void complete() throws IllegalStateException, InterruptedException {
listener.getLogger().println("Ignoring duplicate child " + projectName + " named " + folderName);
return;
}
ProjectNameProperty property = new ProjectNameProperty(projectName);
ProjectNamePropertyKey propertyKey = ChildNameGeneratorImpl.INSTANCE
.beforeNewProject(OrganizationFolder.this, folderName, property);
ChildNameGenerator.Trace trace = ChildNameGeneratorImpl.INSTANCE.beforeCreateItem(
OrganizationFolder.this, folderName, projectName
);
MultiBranchProject<?, ?> project;
try {
project = factory.createNewProject(
OrganizationFolder.this, folderName, sources, attributes, listener
);
} finally {
ChildNameGeneratorImpl.INSTANCE.afterNewProject(propertyKey);
ChildNameGeneratorImpl.INSTANCE.afterItemCreated(trace);
}
BulkChange bc = new BulkChange(project);
try {
if (!projectName.equals(folderName)) {
project.setDisplayName(projectName);
}
project.addProperty(property);
project.addProperty(new ProjectNameProperty(projectName));
project.setOrphanedItemStrategy(getOrphanedItemStrategy());
project.getSourcesList().addAll(createBranchSources());
try {

0 comments on commit 61e5af5

Please sign in to comment.
You can’t perform that action at this time.