@Test public void advancedGet() throws IOException, ClearCaseException { File path = createTempPath(); String viewTag = ccenv.getUniqueName() + "_TAG2b"; Stream oneInt = ccenv.context.streams.get("one_int"); Baseline model1 = ccenv.context.baselines.get("model-1"); Baseline model2 = ccenv.context.baselines.get("model-2"); Stream container = Stream.create(oneInt, "container2b", true, model1); GetView gv = new GetView(path, viewTag).createIfAbsent().setStream(container); SnapshotView view = gv.get(); SnapshotView.LoadRules lr = new SnapshotView.LoadRules(view, SnapshotView.Components.ALL); new UpdateView(view).setLoadRules(lr).update(); /* Verify first */ listFiles(view.getViewRoot()); verifyView(gv, ccenv.getUniqueName() + "/Model/model.h", "#1"); new Rebase(container).addBaseline(model2).rebase(true); /* Verify second */ GetView gv2 = new GetView(path, viewTag); verifyView(gv2, ccenv.getUniqueName() + "/Model/model.h", "#1#2"); }
@Test(expected = ViewException.class) public void testNonExistent() throws IOException, ClearCaseException { File path = createTempPath(); String viewTag = ccenv.getUniqueName() + "_TAG3"; Stream oneInt = ccenv.context.streams.get("one_int"); Baseline model1 = ccenv.context.baselines.get("model-1"); Stream container = Stream.create(oneInt, "container3", true, model1); GetView gv = new GetView(path, viewTag).createIfAbsent().setStream(container); SnapshotView view = gv.get(); SnapshotView.LoadRules lr = new SnapshotView.LoadRules(view, SnapshotView.Components.ALL); new UpdateView(view).setLoadRules(lr).update(); /* Verify first */ listFiles(view.getViewRoot()); verifyView(gv, ccenv.getUniqueName() + "/Model/model.h", "#1"); /* Verify second */ GetView gv2 = new GetView( new File(path.getParent(), "98u2n918u2n9831u2n3981nu23981u2398/hahahaha"), viewTag); gv2.get(); }
private SnapshotView makeDeliverView(Stream stream, File workspace) throws ScmException { /* Replace evil characters with less evil characters */ String newJobName = jobName.replaceAll("\\s", "_"); viewtag = "CCUCM_" + newJobName + "_" + System.getenv("COMPUTERNAME") + "_" + stream.getShortname(); File viewroot = new File(workspace, "view"); return Util.makeView(stream, workspace, listener, loadModule, viewroot, viewtag); }
@Test public void basicSibling() throws Exception { Stream one = ccenv.context.streams.get("one_int"); Stream two = ccenv.context.streams.get("two_int"); one.setDefaultTarget(two); /* The baseline that should be built */ Baseline baseline = ccenv.context.baselines.get("model-1"); AbstractBuild<?, ?> build = initiateBuild("no-options-" + ccenv.getUniqueName(), false, false, false, false); /* Validate */ SystemValidator validator = new SystemValidator(build) .validateBuild(build.getResult()) .validateBuiltBaseline(PromotionLevel.BUILT, baseline, false) .validateCreatedBaseline(true); validator.validate(); }
@Test public void basicCreate() throws IOException, ClearCaseException { File path = createTempPath(); String viewTag = ccenv.getUniqueName() + "_TAG1"; Stream oneInt = ccenv.context.streams.get("one_int"); Baseline model1 = ccenv.context.baselines.get("model-1"); Stream container = Stream.create(oneInt, "container1", true, model1); GetView gv = new GetView(path, viewTag).createIfAbsent().setStream(container); SnapshotView view = gv.get(); SnapshotView.LoadRules lr = new SnapshotView.LoadRules(view, SnapshotView.Components.ALL); new UpdateView(view).setLoadRules(lr).update(); listFiles(view.getViewRoot()); verifyView(gv, ccenv.getUniqueName() + "/Model/model.h", "#1"); }
/** * Apply all the given filters and rules to this * * @return * @throws UnableToInitializeEntityException * @throws UnableToListBaselinesException */ public BaselineList apply() throws UnableToInitializeEntityException, UnableToListBaselinesException { /* Printing info for debug */ logger.fine(" --- Get baselines information --- "); logger.fine("Component: " + component.getNormalizedName()); logger.fine("Stream : " + stream.getNormalizedName()); logger.fine("Level : " + level); logger.fine("Limit : " + limit); logger.fine("Filters : " + filters); logger.fine("Multisite: " + multisitePolling); logger.finest("Requiring: " + required); if (stream.hasPostedDelivery()) { if (multisitePolling) { this.addAll(stream.getPostedBaselines(component, level)); } } else { this.addAll(_get()); } logger.fine("Pre filter steps"); for (BaselineFilter filter : filters) { filter.preFilter(this); } if (required.size() > 0) { for (Baseline b : required) { if (!this.contains(b)) { this.add(b); } } } /* Sort the baselines */ if (sorter != null) { Collections.sort(this, sorter); } logger.fine(" --- Bare retrieval --- "); logger.fine("Baselines: " + this); /* Do the filtering */ int pruned = 0; for (BaselineFilter filter : filters) { logger.fine("Filter: " + filter.getName()); pruned += filter.filter(this); logger.fine("Baselines: " + this); } /* Load em? */ if (load) { Iterator<Baseline> it = this.iterator(); while (it.hasNext()) { Baseline baseline = it.next(); try { baseline.load(); } catch (Exception e) { logger.warning( "[ClearCase] Unable to load " + baseline.getNormalizedName() + ": " + e.getMessage()); it.remove(); pruned++; continue; /* Just continue */ } } } if (pruned > 0) { logger.config("[ClearCase] Pruned " + pruned + " baselines"); } /* Limit? 0 = unlimited */ if (limit > 0 && this.size() > 0) { BaselineList n = new BaselineList(); n.addAll(this.subList(0, limit)); logger.fine("Final list of baselines: " + n); return n; } else { logger.fine("Final list of baselines: " + this); return this; } }
public EstablishResult invoke(File workspace, VirtualChannel channel) throws IOException { out = listener.getLogger(); logger = Logger.getLogger(); StreamAppender app = null; if (pipe != null) { PrintStream toMaster = new PrintStream(pipe.getOut()); app = new StreamAppender(toMaster); app.lockToCurrentThread(); Logger.addAppender(app); app.setSettings(loggerSetting); } else if (pstream != null) { app = new StreamAppender(pstream); app.lockToCurrentThread(); Logger.addAppender(app); app.setSettings(loggerSetting); } logger.debug("Starting remote deliver"); this.workspace = workspace; /* Create the baseline object */ Baseline baseline = null; try { baseline = Baseline.get(this.baseline).load(); } catch (Exception e) { Logger.removeAppender(app); throw new IOException("Could not create Baseline object: " + e.getMessage(), e); } logger.debug(baseline + " created"); /* Create the development stream object */ /* Append vob to dev stream */ Stream destinationStream = null; try { destinationStream = Stream.get(this.destinationstream).load(); } catch (Exception e) { Logger.removeAppender(app); throw new IOException("Could not create destination Stream object: " + e.getMessage(), e); } logger.debug(destinationStream + " created"); /* Make deliver view */ try { snapview = makeDeliverView(destinationStream, workspace); } catch (Exception e) { Logger.removeAppender(app); throw new IOException("Could not create deliver view: " + e.getMessage(), e); } logger.debug("View: " + workspace); String diff = ""; ClearCaseChangeset changeset = new ClearCaseChangeset(); try { List<Activity> bldiff = Version.getBaselineDiff(destinationStream, baseline, true, snapview.getViewRoot()); out.print( "[" + Config.nameShort + "] Found " + bldiff.size() + " activit" + (bldiff.size() == 1 ? "y" : "ies") + ". "); int c = 0; for (Activity a : bldiff) { c += a.changeset.versions.size(); for (Version version : a.changeset.versions) { changeset.addChange(version.getFullyQualifiedName(), version.getUser()); } } out.println(c + " version" + (c == 1 ? "" : "s") + " involved"); diff = Util.createChangelog(bldiff, baseline); } catch (Exception e1) { out.println("[" + Config.nameShort + "] Unable to create change log: " + e1.getMessage()); } logger.debug("Changeset created"); EstablishResult er = new EstablishResult(viewtag); er.setView(snapview); er.setMessage(diff); er.setChangeset(changeset); /* Make the deliver. Inline manipulation of er */ deliver(baseline, destinationStream, er, forceDeliver, 2); /* End of deliver */ Logger.removeAppender(app); return er; }
private void deliver( Baseline baseline, Stream dstream, EstablishResult er, boolean forceDeliver, int triesLeft) throws IOException { logger.verbose( "Delivering " + baseline.getShortname() + " to " + dstream.getShortname() + ". Tries left: " + triesLeft); if (triesLeft < 1) { out.println("[" + Config.nameShort + "] Unable to deliver, giving up."); er.setResultType(ResultType.DELIVER_IN_PROGRESS_NOT_CANCELLED); return; } Deliver deliver = null; try { out.println("[" + Config.nameShort + "] Starting deliver(tries left: " + triesLeft + ")"); deliver = new Deliver( baseline, baseline.getStream(), dstream, snapview.getViewRoot(), snapview.getViewtag()); deliver.deliver(true, false, true, false); // baseline.deliver( baseline.getStream(), dstream, snapview.getViewRoot(), // snapview.getViewtag(), true, false, true ); er.setResultType(ResultType.SUCCESS); } catch (DeliverException e) { out.println("[" + Config.nameShort + "] Failed to deliver: " + e.getMessage()); logger.debug("Failed to deliver: " + e.getMessage()); logger.debug(e); /* Figure out what happened */ if (e.getType().equals(DeliverException.Type.REQUIRES_REBASE)) { er.setResultType(ResultType.DELIVER_REQUIRES_REBASE); } if (e.getType().equals(DeliverException.Type.MERGE_ERROR)) { er.setResultType(ResultType.MERGE_ERROR); } if (e.getType().equals(DeliverException.Type.INTERPROJECT_DELIVER_DENIED)) { er.setResultType(ResultType.INTERPROJECT_DELIVER_DENIED); } if (e.getType().equals(DeliverException.Type.DELIVER_IN_PROGRESS)) { out.println("[" + Config.nameShort + "] Deliver already in progress"); if (!forceDeliver) { er.setResultType(ResultType.DELIVER_IN_PROGRESS); } else { /** * rollback deliver.. *******A DELIVER OPERATION IS ALREADY IN PROGRESS. Details about the * delivery: * * <p><b Deliver operation in progress on stream "stream:pds316_deliver_test@\PDS_PVOB"/> * Started by "PDS316" on "2011-09-28T11:23:53+02:00" Using integration activity * "deliver.pds316_deliver_test.20110928.112353". <bUsing view "pds316_deliver_test_int" * />. Baselines will be delivered to the default target stream * "stream:deliver_test_int@\PDS_PVOB" in project "project:deliver_test@\PDS_PVOB". * * <p>Baselines to be delivered: * * <p>*******Please try again later. */ String msg = e.getMessage(); String stream = ""; String oldViewtag = null; out.println("[" + Config.nameShort + "] Forcing this deliver."); Pattern STREAM_PATTERN = Pattern.compile("Deliver operation .* on stream \\\"(.*)\\\"", Pattern.MULTILINE); Pattern TAG_PATTERN = Pattern.compile("Using view \\\"(.*)\\\".", Pattern.MULTILINE); Matcher mSTREAM = STREAM_PATTERN.matcher(msg); while (mSTREAM.find()) { stream = mSTREAM.group(1); } Matcher mTAG = TAG_PATTERN.matcher(msg); while (mTAG.find()) { oldViewtag = mTAG.group(1); } File newView = null; if (oldViewtag == null) { newView = snapview.getViewRoot(); } else { newView = new File(workspace + "\\rm_delv_view"); } try { // rolling back the previous deliver operation Stream ostream = Stream.get(stream, baseline.getPVob()) .load(); // .deliverRollBack( oldViewtag, newView ); Deliver.rollBack(oldViewtag, ostream, newView); } catch (ClearCaseException ex) { out.println(ex.getMessage()); throw new IOException(ex.getMessage(), ex.getCause()); } // Recursive method call of INVOKE(...); logger.verbose("Trying to deliver again..."); deliver(baseline, dstream, er, forceDeliver, triesLeft - 1); } } } catch (CleartoolException e) { logger.warning("Unable to get status from stream: " + e.getMessage()); throw new IOException(e); } catch (Exception e) { logger.warning("Unable deliver: " + e.getMessage()); throw new IOException(e); } }