/** * Historical synonym for {@link #canAdd}. * * @param tid the potential child item. * @return {@code true} if it can be added. */ public boolean isAllowedChild(TopLevelItem tid) { for (FolderProperty<?> p : getProperties().getAll(FolderProperty.class)) { if (!p.allowsParentToHave(tid)) { return false; } } return true; }
/** * Historical synonym for {@link #canAdd}. * * @param tid the potential child item. * @return {@code true} if it can be added. */ public boolean isAllowedChild(TopLevelItem tid) { for (FolderProperty<?> p : getProperties().getAll(FolderProperty.class)) { if (!p.allowsParentToHave(tid)) { return false; } } return true; }
ConfigFileStore getStore() { // TODO only add property when its really needed (eg. don't add it if there is no config to be saved) FolderConfigFileProperty folderConfigFileProperty = folder.getProperties().get(FolderConfigFileProperty.class); if(folderConfigFileProperty == null) { folderConfigFileProperty = new FolderConfigFileProperty(folder); try { folder.addProperty(folderConfigFileProperty); } catch (IOException e) { throw new RuntimeException(e); } } return folderConfigFileProperty; }
@Deprecated protected List<Action> createTransientActions() { Vector<Action> ta = new Vector<Action>(); for (TransientFolderActionFactory tpaf : TransientFolderActionFactory.all()) { ta.addAll(Util.fixNull(tpaf.createFor(this))); // be defensive against null } for (FolderProperty<?> p: getProperties().getAll(FolderProperty.class)) { ta.addAll(Util.fixNull(p.getFolderActions())); } return ta; }
@SuppressWarnings("deprecation") protected List<Action> createTransientActions() { Vector<Action> ta = new Vector<Action>(); for (TransientFolderActionFactory tpaf : TransientFolderActionFactory.all()) { ta.addAll(Util.fixNull(tpaf.createFor(this))); // be defensive against null } for (FolderProperty<?> p: getProperties().getAll(FolderProperty.class)) { ta.addAll(Util.fixNull(p.getFolderActions())); } return ta; }
/** * Ensures that the specified property points to the folder. * @param <T> Property type * @param folder Folder * @param propertyClass Property class * @param step Failure message prefix */ private <T extends AbstractFolderProperty<AbstractFolder<?>>> void assertPropertyOwner (String step, Folder folder, Class<T> propertyClass) { AbstractFolder<?> propertyOwner = folder.getProperties().get(propertyClass).getOwner(); assertThat(step + ": The property owner should be instance of Folder", propertyOwner, instanceOf(Folder.class)); assertThat(step + ": The owner field of the " + propertyClass + " property should point to the owner folder " + folder, (Folder)propertyOwner, equalTo(folder)); }
/** * Returns true if the specified descriptor type is allowed for this container. * * @param tid the type of child item. * @return {@code true} if it can be added. */ public boolean isAllowedChildDescriptor(TopLevelItemDescriptor tid) { for (FolderProperty<?> p : getProperties().getAll(FolderProperty.class)) { if (!p.allowsParentToCreate(tid)) { return false; } } if (!getACL().hasCreatePermission(Jenkins.getAuthentication(), this, tid)) { return false; } return tid.isApplicableIn(this); }
/** * Returns true if the specified descriptor type is allowed for this container. * * @param tid the type of child item. * @return {@code true} if it can be added. */ public boolean isAllowedChildDescriptor(TopLevelItemDescriptor tid) { for (FolderProperty<?> p : getProperties().getAll(FolderProperty.class)) { if (!p.allowsParentToCreate(tid)) { return false; } } if (!getACL().hasCreatePermission(Jenkins.getAuthentication(), this, tid)) { return false; } return tid.isApplicableIn(this); }
assertThat("Folder has not been found after the reloading", reloadedFolder, notNullValue()); assertThat("Property has not been reloaded, hence it has not been saved properly", reloadedFolder.getProperties().get(com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty.class), notNullValue());
@Issue("JENKINS-46547") @Test public void pipelineDefinedInLibraryInFolder() throws Exception { otherRepo.init(); otherRepo.write("vars/fromLib.groovy", pipelineSourceFromResources("libForPipelineDefinedInLibrary")); otherRepo.git("add", "vars"); otherRepo.git("commit", "--message=init"); LibraryConfiguration firstLib = new LibraryConfiguration("from-lib", new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))); Folder folder = j.jenkins.createProject(Folder.class, "libInFolder"); folder.getProperties().add(new FolderLibraries(Collections.singletonList(firstLib))); expect("pipelineDefinedInLibrary") .inFolder(folder) .logContains("[Pipeline] { (One)", "[Pipeline] { (Two)") .logNotContains("World") .go(); }
@BeforeClass public static void setup() throws Exception { CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next(); String usernamePasswordCredentialsId = "FOOcredentials"; UsernamePasswordCredentialsImpl usernamePassword = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, usernamePasswordCredentialsId, "sample", usernamePasswordUsername, usernamePasswordPassword); store.addCredentials(Domain.global(), usernamePassword); StringCredentialsImpl mixedEnvCred1 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvCred1Secret)); store.addCredentials(Domain.global(), mixedEnvCred1); UsernamePasswordCredentialsImpl mixedEnvCred2 = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvCred2U, mixedEnvCred2P); store.addCredentials(Domain.global(), mixedEnvCred2); StringCredentialsImpl mixedEnvCred3 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred3Id, "test", Secret.fromString(mixedEnvCred3Secret)); store.addCredentials(Domain.global(), mixedEnvCred3); FileCredentialsImpl fileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, fileCredId, "test", fileCredName, SecretBytes.fromBytes(fileCredContent.getBytes())); store.addCredentials(Domain.global(), fileCred); FileCredentialsImpl otherFileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, otherFileCredId, "test", otherFileCredName, SecretBytes.fromBytes(otherFileCredContent.getBytes())); store.addCredentials(Domain.global(), otherFileCred); folder = j.jenkins.createProject(Folder.class, "testFolder"); folder.addProperty(new FolderCredentialsProvider.FolderCredentialsProperty(new DomainCredentials[0])); j.configRoundtrip(folder); CredentialsStore folderStore = folder.getProperties().get(FolderCredentialsProvider.FolderCredentialsProperty.class).getStore(); StringCredentialsImpl sc = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvInFolderCred1Secret)); folderStore.addCredentials(Domain.global(), sc); UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvInFoldercred2U, mixedEnvInFolderCred2P); folderStore.addCredentials(Domain.global(), c); SSHUserPrivateKey k = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, "sshCred1", "bobby", new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource("abc123"), null, "sample"); store.addCredentials(Domain.global(), k); }
@Issue("JENKINS-42473") @Test public void folderLibraryParsing() throws Exception { otherRepo.init(); otherRepo.git("checkout", "-b", "test"); otherRepo.write("src/org/foo/Zot.groovy", "package org.foo;\n" + "\n" + "def echo(msg) {\n" + " echo \"-> ${msg}\"\n" + "}\n"); otherRepo.git("add", "src"); otherRepo.git("commit", "--message=init"); Folder folder = j.jenkins.createProject(Folder.class, "testFolder"); LibraryConfiguration echoLib = new LibraryConfiguration("zot-stuff", new SCMSourceRetriever(new GitSCMSource(null, otherRepo.toString(), "", "*", "", true))); folder.getProperties().add(new FolderLibraries(Collections.singletonList(echoLib))); WorkflowRun firstRun = expect("folderLibraryParsing") .inFolder(folder) .logContains("Hello world") .go(); WorkflowRun secondRun = j.buildAndAssertSuccess(firstRun.getParent()); ExecutionModelAction action = secondRun.getAction(ExecutionModelAction.class); assertNotNull(action); ModelASTStages stages = action.getStages(); assertNull(stages.getSourceLocation()); assertNotNull(stages); }