/** Invoked to actually tag the workspace. */ public synchronized void doSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { build.checkPermission(getPermission()); Map<AbstractBuild, String> tagSet = new HashMap<AbstractBuild, String>(); String name = fixNull(req.getParameter("name")).trim(); String reason = isInvalidTag(name); if (reason != null) { sendError(reason, req, rsp); return; } tagSet.put(build, name); if (req.getParameter("upstream") != null) { // tag all upstream builds Enumeration e = req.getParameterNames(); Map<AbstractProject, Integer> upstreams = build.getTransitiveUpstreamBuilds(); // TODO: define them at AbstractBuild level while (e.hasMoreElements()) { String upName = (String) e.nextElement(); if (!upName.startsWith("upstream.")) { continue; } String tag = fixNull(req.getParameter(upName)).trim(); reason = isInvalidTag(tag); if (reason != null) { sendError( hudson.scm.cvs.Messages.CVSSCM_NoValidTagNameGivenFor(upName, reason), req, rsp); return; } upName = upName.substring(9); // trim off 'upstream.' AbstractProject p = Hudson.getInstance().getItemByFullName(upName, AbstractProject.class); if (p == null) { sendError(hudson.scm.cvs.Messages.CVSSCM_NoSuchJobExists(upName), req, rsp); return; } Integer buildNum = upstreams.get(p); if (buildNum == null) { sendError(hudson.scm.cvs.Messages.CVSSCM_NoUpstreamBuildFound(upName), req, rsp); return; } Run build = p.getBuildByNumber(buildNum); tagSet.put((AbstractBuild) build, tag); } } new TagWorkerThread(this, tagSet).start(); doIndex(req, rsp); }
public String getDisplayName() { if (tagName == null) { return hudson.scm.cvs.Messages.CVSSCM_TagThisBuild(); } if (tagName.indexOf(' ') >= 0) { return hudson.scm.cvs.Messages.CVSSCM_DisplayName2(); } else { return hudson.scm.cvs.Messages.CVSSCM_DisplayName1(); } }
/** Performs tagging. */ public void perform(String tagName, TaskListener listener) { File destdir = null; try { destdir = Util.createTempDir(); // unzip the archive listener .getLogger() .println(hudson.scm.cvs.Messages.CVSSCM_ExpandingWorkspaceArchive(destdir)); Expand e = new Expand(); e.setProject(new org.apache.tools.ant.Project()); e.setDest(destdir); e.setSrc(CVSSCM.getArchiveFile(build)); e.setTaskType("unzip"); e.execute(); // run cvs tag command listener.getLogger().println(hudson.scm.cvs.Messages.CVSSCM_TaggingWorkspace()); for (ModuleLocation moduleLocation : scmInstance.getModuleLocations()) { @SuppressWarnings("unchecked") ModuleLocation parametrizedLocation = new ParametrizedModuleLocationImpl(moduleLocation, build.getBuildVariables()); for (String module : parametrizedLocation.getNormalizedModules()) { if (!createTag( tagName, listener, destdir, parametrizedLocation.getLocalDir(), module, scmInstance.isFlatten())) { return; } } } // completed successfully onTagCompleted(tagName); build.save(); } catch (Throwable e) { e.printStackTrace(listener.fatalError(e.getMessage())); } finally { try { if (destdir != null) { listener.getLogger().println("cleaning up " + destdir); Util.deleteRecursive(destdir); } } catch (IOException e) { e.printStackTrace(listener.fatalError(e.getMessage())); } } }
private boolean createTag( String tagName, TaskListener listener, File destdir, String moduleLocalDir, String module, boolean isFlatten) throws IOException, InterruptedException { FilePath path = (isFlatten ? new FilePath(destdir).child(module) : new FilePath(destdir).child(moduleLocalDir).child(module)); boolean isDir = path.isDirectory(); ArgumentListBuilder cmd = new ArgumentListBuilder(); cmd.add(scmInstance.getDescriptor().getCvsExeOrDefault(), "tag"); if (isDir) { cmd.add("-R"); } cmd.add(tagName); if (!isDir) { cmd.add(path.getName()); path = path.getParent(); } if (!scmInstance.run(new Launcher.LocalLauncher(listener), cmd, listener, path)) { listener.getLogger().println(Messages.CVSSCM_TaggingFailed()); return false; } return true; }
protected void perform(TaskListener listener) { for (Map.Entry<AbstractBuild, String> e : tagSet.entrySet()) { TagAction ta = e.getKey().getAction(TagAction.class); if (ta == null) { listener.error(e.getKey() + " doesn't have CVS tag associated with it. Skipping"); continue; } listener.getLogger().println(Messages.CVSSCM_TagginXasY(e.getKey(), e.getValue())); try { e.getKey().keepLog(); } catch (IOException x) { x.printStackTrace(listener.error(Messages.CVSSCM_FailedToMarkForKeep(e.getKey()))); } ta.perform(e.getValue(), listener); listener.getLogger().println(); } }
/** * Checks if the given value is a valid CVS tag. * * <p>If it's invalid, this method gives you the reason as string. */ private String isInvalidTag(String name) { // source code from CVS rcs.c // void // RCS_check_tag (tag) // const char *tag; // { // char *invalid = "$,.:;@"; /* invalid RCS tag characters */ // const char *cp; // // /* // * The first character must be an alphabetic letter. The remaining // * characters cannot be non-visible graphic characters, and must not be // * in the set of "invalid" RCS identifier characters. // */ // if (isalpha ((unsigned char) *tag)) // { // for (cp = tag; *cp; cp++) // { // if (!isgraph ((unsigned char) *cp)) // error (1, 0, "tag `%s' has non-visible graphic characters", // tag); // if (strchr (invalid, *cp)) // error (1, 0, "tag `%s' must not contain the characters `%s'", // tag, invalid); // } // } // else // error (1, 0, "tag `%s' must start with a letter", tag); // } if (name == null || name.length() == 0) { return hudson.scm.cvs.Messages.CVSSCM_TagIsEmpty(); } char ch = name.charAt(0); if (!(('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z'))) { return hudson.scm.cvs.Messages.CVSSCM_TagNeedsToStartWithAlphabet(); } for (char invalid : "$,.:;@".toCharArray()) { if (name.indexOf(invalid) >= 0) { return hudson.scm.cvs.Messages.CVSSCM_TagContainsIllegalChar(invalid); } } return null; }