com.cloudbees.hudson.plugins.folder.AbstractFolder Java Examples

The following examples show how to use com.cloudbees.hudson.plugins.folder.AbstractFolder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FavoriteContainerImpl.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Override
public Iterator<BlueFavorite> iterator(int start, int limit) {
    List<BlueFavorite> favorites = new ArrayList<>();

    Iterator<Item> favoritesIterator = Favorites.getFavorites(user.user).iterator();
    Utils.skip(favoritesIterator, start);
    int count = 0;
    while(count < limit && favoritesIterator.hasNext()) {
        Item item = favoritesIterator.next();
        if(item instanceof AbstractFolder) {
            continue;
        }
        BlueFavorite blueFavorite = FavoriteUtil.getFavorite(item);
        if(blueFavorite != null){
            favorites.add(blueFavorite);
            count++;
        }
    }
    return favorites.iterator();
}
 
Example #2
Source File: WithMavenStepExecution2.java    From pipeline-maven-plugin with MIT License 6 votes vote down vote up
@CheckForNull
private MavenConfigFolderOverrideProperty getMavenConfigOverrideProperty() {
    Job<?, ?> job = build.getParent(); // Get the job

    // Iterate until we find an override or until we reach the top. We need it to be an item to be able to do
    // getParent, AbstractFolder which has the properties is also an Item
    for (ItemGroup<?> group = job.getParent(); group != null && group instanceof Item && !(group instanceof Jenkins); group = ((Item) group).getParent()) {
        if (group instanceof AbstractFolder) {
            MavenConfigFolderOverrideProperty mavenConfigProperty = ((AbstractFolder<?>) group).getProperties().get(MavenConfigFolderOverrideProperty.class);
            if (mavenConfigProperty != null && mavenConfigProperty.isOverride()) {
                return mavenConfigProperty;
            }
        }
    }
    return null;
}
 
Example #3
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 6 votes vote down vote up
private Job generateMockJob(final AbstractFolder firstParent) {
    return new Job(firstParent, "test-job") {
        @Override
        public boolean isBuildable() {
            return true;
        }

        @Override
        protected SortedMap _getRuns() {
            return null;
        }

        @Override
        protected void removeRun(Run run) {

        }

        @NonNull
        @Override
        public ItemGroup getParent() {
            return firstParent;
        }
    };
}
 
Example #4
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 6 votes vote down vote up
@Test
public void resolverShouldCorrectlyMerge() {
    final DescribableList firstFolderProperties = mock(DescribableList.class);
    when(firstFolderProperties.get(FolderVaultConfiguration.class))
        .thenReturn(completeTestConfigFolder("firstParent", null));

    final DescribableList secondFolderProperties = mock(DescribableList.class);
    when(secondFolderProperties.get(FolderVaultConfiguration.class))
        .thenReturn(completeTestConfigFolder("secondParent", 2));

    final AbstractFolder secondParent = generateMockFolder(secondFolderProperties, null);

    final AbstractFolder firstParent = generateMockFolder(firstFolderProperties, secondParent);

    final Job job = generateMockJob(firstParent);

    VaultConfiguration result = new FolderVaultConfiguration.ForJob().forJob(job);

    VaultConfiguration expected = completeTestConfig("firstParent", null)
        .mergeWithParent(completeTestConfig("secondParent", 2));

    assertThat(result.getVaultCredentialId(), is(expected.getVaultCredentialId()));
    assertThat(result.getVaultUrl(), is(expected.getVaultUrl()));
    assertThat(result.getEngineVersion(), is(expected.getEngineVersion()));
}
 
Example #5
Source File: FolderVaultConfiguration.java    From hashicorp-vault-plugin with MIT License 6 votes vote down vote up
@NonNull
@Override
public VaultConfiguration forJob(@NonNull Item job) {
    VaultConfiguration resultingConfig = null;
    for (ItemGroup g = job.getParent(); g instanceof AbstractFolder;
        g = ((AbstractFolder) g).getParent()) {
        FolderVaultConfiguration folderProperty = ((AbstractFolder<?>) g).getProperties()
            .get(FolderVaultConfiguration.class);
        if (folderProperty == null) {
            continue;
        }
        if (resultingConfig != null) {
            resultingConfig = resultingConfig
                .mergeWithParent(folderProperty.getConfiguration());
        } else {
            resultingConfig = folderProperty.getConfiguration();
        }
    }

    return resultingConfig;
}
 
Example #6
Source File: BlueOceanCredentialsProvider.java    From blueocean-plugin with MIT License 6 votes vote down vote up
private static FolderPropertyImpl propertyOf(ModelObject object) {
    if (object instanceof AbstractFolder) {
        FolderPropertyImpl prop = ((AbstractFolder<?>)object).getProperties().get(FolderPropertyImpl.class);

        if(prop == null){
            ItemGroup parent = ((AbstractFolder)object).getParent();
            if(parent instanceof Jenkins){
                return null;
            }
            return propertyOf(parent);
        }else{
            return prop;
        }
    }
    return null;
}
 
Example #7
Source File: GithubIssueTest.java    From blueocean-plugin with MIT License 6 votes vote down vote up
@Test
public void changeSetJobParentNotMultibranch() throws Exception {
    AbstractFolder project = mock(AbstractFolder.class);
    Job job = mock(MockJob.class);
    Run run = mock(Run.class);
    ChangeLogSet logSet = mock(ChangeLogSet.class);
    ChangeLogSet.Entry entry = mock(ChangeLogSet.Entry.class);

    when(project.getProperties()).thenReturn(new DescribableList(project));
    when(entry.getParent()).thenReturn(logSet);
    when(logSet.getRun()).thenReturn(run);
    when(run.getParent()).thenReturn(job);
    when(job.getParent()).thenReturn(project);

    when(entry.getMsg()).thenReturn("Closed #123 #124");

    Collection<BlueIssue> resolved = BlueIssueFactory.resolve(entry);
    Assert.assertEquals(0, resolved.size());
}
 
Example #8
Source File: Disabler.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@SuppressFBWarnings(value = "NP_BOOLEAN_RETURN_NULL", justification = "isDisabled will return null if the job type doesn't support it")
public static Boolean isDisabled(Object item) {
    if (item instanceof AbstractFolder) {
        return Disabler.isDisabled((AbstractFolder) item);
    }
    if (item instanceof AbstractProject) {
        return Disabler.isDisabled((AbstractProject) item);
    }
    if (item instanceof ParameterizedJobMixIn.ParameterizedJob ) {
        return Disabler.isDisabled((ParameterizedJobMixIn.ParameterizedJob ) item);
    }
    return null;
}
 
Example #9
Source File: SelectJobsBallColorFolderIcon.java    From multi-branch-project-plugin with MIT License 5 votes vote down vote up
/**
 * Form validation method.  Similar to
 * {@link hudson.tasks.BuildTrigger.DescriptorImpl#doCheck(AbstractProject, String)}.
 *
 * @param folder the folder being configured
 * @param value  the user-entered value
 * @return validation result
 */
public FormValidation doCheck(@AncestorInPath AbstractFolder folder, @QueryParameter String value) {
    // Require CONFIGURE permission on this project
    if (!folder.hasPermission(Item.CONFIGURE)) {
        return FormValidation.ok();
    }

    boolean hasJobs = false;

    StringTokenizer tokens = new StringTokenizer(Util.fixNull(value), ",");
    while (tokens.hasMoreTokens()) {
        String jobName = tokens.nextToken().trim();

        if (StringUtils.isNotBlank(jobName)) {
            Item item = Jenkins.getActiveInstance().getItem(jobName, (ItemGroup) folder, Item.class);

            if (item == null) {
                Job nearest = Items.findNearest(Job.class, jobName, folder);
                String alternative = nearest != null ? nearest.getRelativeNameFrom((ItemGroup) folder) : "?";
                return FormValidation.error(
                        hudson.tasks.Messages.BuildTrigger_NoSuchProject(jobName, alternative));
            }

            if (!(item instanceof Job)) {
                return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NotBuildable(jobName));
            }

            hasJobs = true;
        }
    }

    if (!hasJobs) {
        return FormValidation.error(hudson.tasks.Messages.BuildTrigger_NoProjectSpecified());
    }

    return FormValidation.ok();
}
 
Example #10
Source File: Disabler.java    From blueocean-plugin with MIT License 5 votes vote down vote up
public static void makeDisabled(Object item, boolean b) throws IOException {
    if (item instanceof AbstractFolder) {
        Disabler.makeDisabled((AbstractFolder) item, b);
    }
    if (item instanceof AbstractProject) {
        Disabler.makeDisabled((AbstractProject) item, b);
    }
    if (item instanceof ParameterizedJobMixIn.ParameterizedJob ) {
        Disabler.makeDisabled((ParameterizedJobMixIn.ParameterizedJob ) item, b);
    }
}
 
Example #11
Source File: KubernetesFolderProperty.java    From kubernetes-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively collect all allowed clouds from this folder and its parents.
 * 
 * @param allowedClouds
 *            This Set contains all allowed clouds after returning.
 * @param itemGroup
 *            The itemGroup to inspect.
 */
public static void collectAllowedClouds(Set<String> allowedClouds, ItemGroup<?> itemGroup) {
    if (itemGroup instanceof AbstractFolder) {
        AbstractFolder<?> folder = (AbstractFolder<?>) itemGroup;
        KubernetesFolderProperty kubernetesFolderProperty = folder.getProperties()
                .get(KubernetesFolderProperty.class);

        if (kubernetesFolderProperty != null) {
            allowedClouds.addAll(kubernetesFolderProperty.getPermittedClouds());
        }

        collectAllowedClouds(allowedClouds, folder.getParent());
    }
}
 
Example #12
Source File: FolderAuthorizationStrategyManagementLink.java    From folder-auth-plugin with MIT License 5 votes vote down vote up
/**
 * Get all {@link AbstractFolder}s in the system
 *
 * @return full names of all {@link AbstractFolder}s in the system
 */
@GET
@Nonnull
@Restricted(NoExternalUse.class)
public JSONArray doGetAllFolders() {
    Jenkins jenkins = Jenkins.get();
    jenkins.checkPermission(Jenkins.ADMINISTER);
    List<AbstractFolder> folders;

    try (ACLContext ignored = ACL.as(ACL.SYSTEM)) {
        folders = jenkins.getAllItems(AbstractFolder.class);
    }

    return JSONArray.fromObject(folders.stream().map(AbstractItem::getFullName).collect(Collectors.toList()));
}
 
Example #13
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 5 votes vote down vote up
private AbstractFolder generateMockFolder(final DescribableList firstFolderProperties,
    final AbstractFolder parentToReturn) {
    return new AbstractFolder<TopLevelItem>(null, null) {
        @NonNull
        @Override
        public ItemGroup getParent() {
            return parentToReturn;
        }

        @Override
        public DescribableList<AbstractFolderProperty<?>, AbstractFolderPropertyDescriptor> getProperties() {
            return firstFolderProperties;
        }
    };
}
 
Example #14
Source File: WithAWSStepTest.java    From pipeline-aws-plugin with Apache License 2.0 5 votes vote down vote up
private CredentialsStore getFolderStore(AbstractFolder f) {
	Iterable<CredentialsStore> stores = CredentialsProvider.lookupStores(f);
	CredentialsStore folderStore = null;
	for (CredentialsStore s : stores) {
		if (s.getProvider() instanceof FolderCredentialsProvider && s.getContext() == f) {
			folderStore = s;
			break;
		}
	}
	return folderStore;
}
 
Example #15
Source File: FolderConfig.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public String getLabel(@Nullable Run run) {
    if (run != null) {
        Job job = run.getParent();
        ItemGroup parent = job.getParent();
        while (parent != null) {

            if (parent instanceof AbstractFolder) {
                AbstractFolder folder = (AbstractFolder) parent;
                FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
                if (config != null) {
                    String label = config.getDockerLabel();
                    if (!StringUtils.isBlank(label)) {
                        return label;
                    }
                }
            }

            if (parent instanceof Item) {
                parent = ((Item) parent).getParent();
            } else {
                parent = null;
            }
        }
    }
    return null;
}
 
Example #16
Source File: FolderConfig.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public String getRegistryUrl(@Nullable Run run) {
    if (run != null) {
        Job job = run.getParent();
        ItemGroup parent = job.getParent();
        while (parent != null) {

            if (parent instanceof AbstractFolder) {
                AbstractFolder folder = (AbstractFolder) parent;
                FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
                if (config != null) {
                    DockerRegistryEndpoint registry = config.getRegistry();
                    if (registry != null && !StringUtils.isBlank(registry.getUrl())) {
                        return registry.getUrl();
                    }
                }
            }

            if (parent instanceof Item) {
                parent = ((Item) parent).getParent();
            } else {
                parent = null;
            }
        }
    }
    return null;
}
 
Example #17
Source File: FolderConfig.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public String getRegistryCredentialsId(@Nullable Run run) {
    if (run != null) {
        Job job = run.getParent();
        ItemGroup parent = job.getParent();
        while (parent != null) {

            if (parent instanceof AbstractFolder) {
                AbstractFolder folder = (AbstractFolder) parent;
                FolderConfig config = (FolderConfig) folder.getProperties().get(FolderConfig.class);
                if (config != null) {
                    DockerRegistryEndpoint registry = config.getRegistry();
                    if (registry != null && !StringUtils.isBlank(registry.getCredentialsId())) {
                        return registry.getCredentialsId();
                    }
                }
            }

            if (parent instanceof Item) {
                parent = ((Item) parent).getParent();
            } else {
                parent = null;
            }
        }
    }
    return null;
}
 
Example #18
Source File: SelectJobsBallColorFolderIcon.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
@Override
public void setOwner(AbstractFolder<?> folder) {
    this.owner = folder;
}
 
Example #19
Source File: BallColorFolderIcon.java    From multi-branch-project-plugin with MIT License 4 votes vote down vote up
@Override
public void setOwner(AbstractFolder<?> folder) {
    this.owner = folder;
}
 
Example #20
Source File: FolderVaultConfigurationSpec.java    From hashicorp-vault-plugin with MIT License 4 votes vote down vote up
@Test
public void resolverShouldHandleAbsentConfigurationOnFolders() {

    final DescribableList firstFolderProperties = mock(DescribableList.class);
    when(firstFolderProperties.get(FolderVaultConfiguration.class))
        .thenReturn(completeTestConfigFolder("firstParent"));

    final DescribableList secondFolderProperties = mock(DescribableList.class);
    when(secondFolderProperties.get(FolderVaultConfiguration.class)).thenReturn(null);

    final AbstractFolder secondParent = generateMockFolder(secondFolderProperties, null);

    final AbstractFolder firstParent = generateMockFolder(firstFolderProperties, secondParent);

    final Job job = generateMockJob(firstParent);

    VaultConfiguration result = new FolderVaultConfiguration.ForJob().forJob(job);

    VaultConfiguration expected = completeTestConfig("firstParent").mergeWithParent(null);

    assertThat(result.getVaultCredentialId(), is(expected.getVaultCredentialId()));
    assertThat(result.getVaultUrl(), is(expected.getVaultUrl()));
    assertThat(result.getEngineVersion(), is(expected.getEngineVersion()));
}
 
Example #21
Source File: BlueOceanCredentialsProvider.java    From blueocean-plugin with MIT License 4 votes vote down vote up
private boolean isApplicable(ModelObject object){
    return object instanceof AbstractFolder &&
            ((AbstractFolder)object).getProperties().get(FolderPropertyImpl.class) != null;
}
 
Example #22
Source File: Disabler.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public static Boolean isDisabled(AbstractFolder folder) {
    return folder.isDisabled();
}
 
Example #23
Source File: Disabler.java    From blueocean-plugin with MIT License 4 votes vote down vote up
public static void makeDisabled(AbstractFolder folder, boolean b) throws IOException {
    folder.makeDisabled(b);
}