private static AutoCompletionCandidates createAutoCompletionList(Iterable<File> files) { if (Iterables.size(files) == 0) { return NO_SUGGESTIONS; } AutoCompletionCandidates candidates = new AutoCompletionCandidates(); for (File file : files) { try { String absolutePath = file.getAbsolutePath(); candidates.add(absolutePath); } catch (SecurityException ex) { // no permissions to list a directory } } return candidates; }
public AutoCompletionCandidates doAutoCompletePin( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 0) { List<ILabelSummary> list; GetLabelsOptions opts = new GetLabelsOptions(); opts.setMaxResults(10); opts.setNameFilter(value + "*"); list = iserver.getLabels(null, opts); for (ILabelSummary l : list) { c.add(l.getName()); } } } catch (Exception e) { } return c; }
static public AutoCompletionCandidates autoCompleteName( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 0) { String user = iserver.getUserName(); List<IClientSummary> list; list = iserver.getClients(user, value + "*", 10); for (IClientSummary l : list) { c.add(l.getName()); } } } catch (Exception e) { } return c; }
static public AutoCompletionCandidates doAutoCompleteStreamName( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 1) { List<String> streamPaths = new ArrayList<String>(); streamPaths.add(value + "..."); GetStreamsOptions opts = new GetStreamsOptions(); opts.setMaxResults(10); List<IStreamSummary> list = iserver.getStreams(streamPaths, opts); for (IStreamSummary l : list) { c.add(l.getStream()); } } } catch (Exception e) { } return c; }
/** * Provides auto-completion for workspace names. Stapler finds this method * via the naming convention. * * @param value The text that the user entered. * @return suggestion */ static public AutoCompletionCandidates doAutoCompleteTemplateName( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 0) { List<IClientSummary> list; GetClientsOptions opts = new GetClientsOptions(); opts.setMaxResults(10); opts.setNameFilter(value + "*"); list = iserver.getClients(opts); for (IClientSummary l : list) { c.add(l.getName()); } } } catch (Exception e) { } return c; }
public AutoCompletionCandidates doAutoCompleteUser( @QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); try { IOptionsServer iserver = ConnectionFactory.getConnection(); if (iserver != null && value.length() > 0) { List<String> users = new ArrayList<String>(); users.add(value + "*"); List<IUserSummary> list; list = iserver.getUsers(users, 10); for (IUserSummary l : list) { c.add(l.getLoginName()); } } } catch (Exception e) { } return c; }
@Test public void testAutoComplete() { new ConnectionHelper(auth); // Initialise default connection NavigateHelper nav = new NavigateHelper(5); AutoCompletionCandidates results = nav.getCandidates("//"); assertNotNull(results); assertEquals(2, results.getValues().size()); results = nav.getCandidates("//de"); assertNotNull(results); assertEquals("//depot/", results.getValues().get(0)); results = nav.getCandidates("//depot/"); assertNotNull(results); assertEquals("//depot/Data/", results.getValues().get(0)); results = nav.getCandidates("//depot/Data/"); assertNotNull(results); assertEquals("//depot/Data/file-0.dat", results.getValues().get(0)); }
@Test public void testDoAutoCompleteStageName() throws Exception { final PipelineProperty.DescriptorImpl descriptor = new PipelineProperty.DescriptorImpl(); FreeStyleProject build = jenkins.createFreeStyleProject("build"); FreeStyleProject build2 = jenkins.createFreeStyleProject("build2"); jenkins.createFreeStyleProject("build3"); build2.addProperty(new PipelineProperty()); build.addProperty(new PipelineProperty("Build", "Build", "")); AutoCompletionCandidates c1 = descriptor.doAutoCompleteStageName("B"); assertEquals(c1.getValues().size(), 1); AutoCompletionCandidates c2 = descriptor.doAutoCompleteStageName("A"); assertEquals(c2.getValues().size(), 0); AutoCompletionCandidates c3 = descriptor.doAutoCompleteStageName(null); assertEquals(c3.getValues().size(), 0); }
public AutoCompletionCandidates doAutoCompleteComposition(@QueryParameter String cloudTestServerID) throws IOException, InterruptedException { CloudTestServer s = CloudTestServer.getByID(cloudTestServerID); ArgumentListBuilder args = new ArgumentListBuilder(); args.add(install(s)) .add("list", "type=composition") .add("url=" + s.getUrl()) .add("username=" + s.getUsername()); if (s.getPassword() != null) args.addMasked("password=" + s.getPassword()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int exit = new LocalLauncher(TaskListener.NULL).launch().cmds(args).stdout(out).join(); if (exit==0) { BufferedReader r = new BufferedReader(new StringReader(out.toString())); AutoCompletionCandidates a = new AutoCompletionCandidates(); String line; while ((line=r.readLine())!=null) { if (line.endsWith("object(s) found.")) continue; a.add(line); } return a; } return new AutoCompletionCandidates(); // no candidate }
/** * This method provides auto-completion items for the 'state' field. * Stapler finds this method via the naming convention. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteState(@QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); for (String state : STATES) if (state.toLowerCase().startsWith(value.toLowerCase())) c.add(state); return c; }
/** * Fill the project name automatically. * * @param value Seed value. * @param project Ancestor project. * @return the autocompletion candidates. */ public AutoCompletionCandidates doAutoCompleteUpstreamProjectName( @QueryParameter String value, @AncestorInPath Job<?,?> project ) { // Specified Item to allow to autocomplete folders (maybe confusing...). return project == null ? new AutoCompletionCandidates() : AutoCompletionCandidates.ofJobNames(Item.class, value, project, project.getParent()); }
/** * Autocompletion method * * Copied from hudson.tasks.BuildTrigger.doAutoCompleteChildProjects(String value) * * @param value * @return */ public AutoCompletionCandidates doAutoCompleteProjects(@QueryParameter String value, @AncestorInPath ItemGroup context) { AutoCompletionCandidates candidates = new AutoCompletionCandidates(); List<Job> jobs = Jenkins.getInstance().getAllItems(Job.class); for (Job job: jobs) { String relativeName = job.getRelativeNameFrom(context); if (relativeName.startsWith(value)) { if (job.hasPermission(Item.READ)) { candidates.add(relativeName); } } } return candidates; }
public AutoCompletionCandidates doAutoCompleteLabels(Job<?, ?> job, String query) { AutoCompletionCandidates result = new AutoCompletionCandidates(); // show all suggestions for short strings if (query.length() < 2) { result.add(getProjectLabelsAsArray(job)); } else { for (String branch : getProjectLabelsAsArray(job)) { if (branch.toLowerCase().contains(query.toLowerCase())) { result.add(branch); } } } return result; }
public AutoCompletionCandidates doAutoCompleteBranchesSpec(Job<?, ?> job, String query) { AutoCompletionCandidates result = new AutoCompletionCandidates(); // show all suggestions for short strings if (query.length() < 2) { result.add(getProjectBranchesAsArray(job)); } else { for (String branch : getProjectBranchesAsArray(job)) { if (branch.toLowerCase().contains(query.toLowerCase())) { result.add(branch); } } } return result; }
private AutoCompletionCandidates getCandidates() { AutoCompletionCandidates c = new AutoCompletionCandidates(); for (Node node : nodes) { c.add(node.getDepotPath()); } return c; }
@Test public void testFreeStyleProject_TemplateWs() throws Exception { String client = "test.ws"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins.createFreeStyleProject("Template-Head"); TemplateWorkspaceImpl workspace = new TemplateWorkspaceImpl("none", false, client, format); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Template (view generated for each node)", desc.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); TemplateWorkspaceImpl.DescriptorImpl impl = (TemplateWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckTemplateName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = WorkspaceDescriptor.doAutoCompleteTemplateName("t"); assertTrue(list.getValues().contains("test.ws")); form = WorkspaceDescriptor.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); }
@Test public void testFreeStyleProject_StreamWs() throws Exception { String stream = "//stream/main"; String format = "jenkins-${node}-${project}.ws"; FreeStyleProject project = jenkins.createFreeStyleProject("Stream-Head"); StreamWorkspaceImpl workspace = new StreamWorkspaceImpl("none", false, stream, format); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Streams (view generated by Perforce for each node)", desc.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); FormValidation form = WorkspaceDescriptor.doCheckStreamName("//stream/main"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates list = WorkspaceDescriptor.doAutoCompleteStreamName("//"); assertTrue(list.getValues().contains("//stream/main")); form = WorkspaceDescriptor.doCheckFormat(format); assertEquals(FormValidation.Kind.OK, form.kind); // delete worksapce project.doDoWipeOutWorkspace(); }
public AutoCompletionCandidates doAutoCompleteStageName(@QueryParameter String value) { if (value != null) { AutoCompletionCandidates candidates = new AutoCompletionCandidates(); Set<String> stages = getStageNames(); for (String stage : stages) { if (stage.toLowerCase().startsWith(value.toLowerCase())) { candidates.add(stage); } } return candidates; } else { return new AutoCompletionCandidates(); } }
public AutoCompletionCandidates doAutoCompleteChrootName(@QueryParameter String value) { AutoCompletionCandidates c = new AutoCompletionCandidates(); for (ChrootToolset set : ChrootToolset.list()) { if(set.getName().startsWith(value)) c.add(set.getName()); } return c; }
public AutoCompletionCandidates doAutoCompleteStream( @QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteStreamName(value); }
public AutoCompletionCandidates doAutoCompleteTemplate( @QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteTemplateName(value); }
public static AutoCompletionCandidates suggestFiles(@Nullable String filePath) { Iterable<File> files = INSTANCE.listFileSystemItems(filePath); return createAutoCompletionList(files); }
public static AutoCompletionCandidates suggestDirectories(@Nullable String filePath) { Iterable<File> files = INSTANCE.listFileSystemItems(filePath); Iterable<File> directories = Iterables.filter(files, IS_DIRECTORY); return createAutoCompletionList(directories); }
public AutoCompletionCandidates doAutoCompleteIncludeBranchesSpec(@AncestorInPath final Job<?, ?> job, @QueryParameter final String value) { return ProjectBranchesProvider.instance().doAutoCompleteBranchesSpec(job, value); }
public AutoCompletionCandidates doAutoCompleteExcludeBranchesSpec(@AncestorInPath final Job<?, ?> job, @QueryParameter final String value) { return ProjectBranchesProvider.instance().doAutoCompleteBranchesSpec(job, value); }
public AutoCompletionCandidates doAutoCompleteIncludeMergeRequestLabels(@AncestorInPath final Job<?, ?> job, @QueryParameter final String value) { return ProjectLabelsProvider.instance().doAutoCompleteLabels(job, value); }
public AutoCompletionCandidates doAutoCompleteExcludeMergeRequestLabels(@AncestorInPath final Job<?, ?> job, @QueryParameter final String value) { return ProjectLabelsProvider.instance().doAutoCompleteLabels(job, value); }
public AutoCompletionCandidates doAutoCompleteStream(@QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteStreamName(value); }
public AutoCompletionCandidates doAutoCompleteTemplate(@QueryParameter String value) { return WorkspaceDescriptor.doAutoCompleteTemplateName(value); }
public AutoCompletionCandidates doAutoCompletePath(@QueryParameter String value) { NavigateHelper nav = new NavigateHelper(10); return nav.getCandidates(value); }
@Test public void testFreeStyleProject_buildChange() throws Exception { FreeStyleProject project = jenkins.createFreeStyleProject("BuildChange"); StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", false, defaultClient()); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); List<ParameterValue> list = new ArrayList<ParameterValue>(); list.add(new StringParameterValue(ReviewProp.STATUS.toString(), "committed")); list.add(new StringParameterValue(ReviewProp.CHANGE.toString(), "9")); Action actions = new SafeParametersAction(new ArrayList<ParameterValue>(), list); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause, actions).get(); assertEquals(Result.SUCCESS, build.getResult()); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("P4 Task: syncing files at change: 9")); // Check web pages for changes HtmlPage page = jenkins.createWebClient().getPage(build); String text = page.asText(); assertTrue(text.contains("9 by jenkins (jenkins.data.ws)")); page = jenkins.createWebClient().getPage(build, "changes"); text = page.asText(); assertTrue(text.contains("//depot/Main/file-11.txt #4")); // Check workspace descriptors WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Static (static view, master only)", desc.getDisplayName()); ListBoxModel charsets = WorkspaceDescriptor.doFillCharsetItems(); assertTrue(charsets.size() > 1); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); StaticWorkspaceImpl.DescriptorImpl impl = (StaticWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); AutoCompletionCandidates clients = impl.doAutoCompleteName("j"); assertTrue(clients.getValues().contains("jenkins.data.ws")); }
@Test public void testFreeStyleProject_ManualWs() throws Exception { String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/Data/... //" + client + "/..."; WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view); FreeStyleProject project = jenkins.createFreeStyleProject("Manual-Head"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; Cause.UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); WorkspaceDescriptor desc = workspace.getDescriptor(); assertNotNull(desc); assertEquals("Manual (custom view)", desc.getDisplayName()); Descriptor<WorkspaceSpec> descSpec = spec.getDescriptor(); assertNotNull(descSpec); assertEquals("Perforce Client Spec", descSpec.getDisplayName()); // Log in for next set of tests... ConnectionHelper p4 = new ConnectionHelper(auth); p4.login(); WorkspaceSpec.DescriptorImpl implSpec = (WorkspaceSpec.DescriptorImpl) descSpec; AutoCompletionCandidates list = implSpec.doAutoCompleteStreamName("//"); assertTrue(list.getValues().contains("//stream/main")); ListBoxModel lineItems = implSpec.doFillLineItems(); assertFalse(lineItems.isEmpty()); ListBoxModel typeItems = implSpec.doFillTypeItems(); assertFalse(typeItems.isEmpty()); ManualWorkspaceImpl.DescriptorImpl impl = (ManualWorkspaceImpl.DescriptorImpl) desc; FormValidation form = impl.doCheckName("test.ws"); assertEquals(FormValidation.Kind.OK, form.kind); list = impl.doAutoCompleteName("m"); assertTrue(list.getValues().contains(client)); JSONObject json = workspace.getSpecJSON("test.ws"); assertEquals("//depot/... //test.ws/...\n", json.getString("view")); p4.disconnect(); json = workspace.getSpecJSON("test.ws"); assertEquals("please define view...", json.getString("view")); }
/** * Autocomplete for LabelExpression. * * @param value * @return */ public AutoCompletionCandidates doAutoCompleteLabelExpression( @QueryParameter String value ) { AutoCompletionCandidates c = new AutoCompletionCandidates(); if(StringUtils.isEmpty(value)) { return c; } // candidate labels Set<Label> labels = Jenkins.getInstance().getLabels(); // current inputting value StringTokenizer t = new StringTokenizer(value); String currentValue = null; while(t.hasMoreTokens()) { currentValue = t.nextToken(); } if(StringUtils.isEmpty(currentValue)) { return c; } List<String> cands = new ArrayList<String>(); for(Label l : labels) { if(l.getName().startsWith(currentValue)) { cands.add(l.getName()); } } Collections.sort(cands); for(String s: cands) { c.add(s); } return c; }
/** * Auto completion for jobs. * * @param value the user-entered value * @param container the folder being configured * @return candidates inside container based on value */ public AutoCompletionCandidates doAutoCompleteJobs(@QueryParameter String value, @AncestorInPath ItemGroup container) { return AutoCompletionCandidates.ofJobNames(Job.class, value, container); }
/** * Matches for a partial depot path * * @param depotPath a Perforce Depot path e.g. //depot/pro * @return matches for the depot path e.g. //depot/projA */ public AutoCompletionCandidates getCandidates(String depotPath) { nodes = new ArrayList<>(); buildPaths(depotPath); return getCandidates(); }
/** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value The text that the user entered. * @return suggestion */ public AutoCompletionCandidates doAutoCompleteName(@QueryParameter String value) { return autoCompleteName(value); }
/** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value The text that the user entered. * @return suggestion */ public AutoCompletionCandidates doAutoCompleteStreamName( @QueryParameter String value) { return StreamDescImpl.doAutoCompleteStreamName(value); }