Skip to content
Permalink
Browse files
Implemented JENKINS-23533
  • Loading branch information
MadsNielsen committed Jun 25, 2014
1 parent 0e558c7 commit c6e44f7c3188ffed83aaefdd43f982e911c38ca1
@@ -20,6 +20,7 @@
import net.praqma.clearcase.ucm.entities.Project;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.ucm.entities.Version;
import net.praqma.clearcase.ucm.utils.ReadOnlyVersionFilter;
import net.praqma.clearcase.ucm.utils.VersionList;
import net.praqma.clearcase.ucm.view.SnapshotView;
import net.praqma.clearcase.ucm.view.UCMView;
@@ -58,19 +59,27 @@ public Stream getDeveloperStream( String streamname, PVob pvob, Stream buildInte
return devstream;
}

public static String createChangelog( List<Activity> activities, Baseline bl, boolean trimmed ) {
public static String createChangelog( List<Activity> activities, Baseline bl, boolean trimmed, boolean discard, File viewRoot, List<String> readonly ) {
logger.fine( "Generating change set, " + trimmed );
ChangeSetGenerator csg = new ChangeSetGenerator().createHeader( bl.getShortname() );

if( trimmed ) {
VersionList vl = new VersionList().addActivities( activities ).setBranchName( "^.*" + Cool.qfs + bl.getStream().getShortname() + ".*$" );
if(discard) {
logger.fine("Discard enabled...enabling read-only filter");
vl = vl.addFilter(new ReadOnlyVersionFilter(viewRoot, readonly)).apply();
}

Map<Activity, List<Version>> changeSet = vl.getLatestForActivities();
for( Activity activity : changeSet.keySet() ) {
csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), changeSet.get( activity ) );
}
} else {
for( Activity activity : activities ) {
VersionList versions = new VersionList( activity.changeset.versions ).getLatest();
if(discard) {
versions = versions.addFilter(new ReadOnlyVersionFilter(viewRoot, readonly)).apply();
}
csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), versions );
}
}
@@ -92,21 +101,22 @@ public ChangeSetGenerator createHeader( String header ) {
}

public ChangeSetGenerator addAcitivity( String name, String header, String username, List<Version> versions ) {
buffer.append( "<activity>" );
buffer.append( "<actName>" + name + "</actName>" );
buffer.append( "<actHeadline>" + header + "</actHeadline>" );
buffer.append( "<author>" + username + "</author>" );
String temp = null;
for( Version v : versions ) {
try {
temp = "<file>" + v.getSFile() + " (" + v.getVersion() + ") user: " + v.blame() + "</file>";
} catch( ClearCaseException e ) {
logger.warning( "Could not generate log" );
if(versions.size() > 0) {
buffer.append( "<activity>" );
buffer.append( "<actName>" + name + "</actName>" );
buffer.append( "<actHeadline>" + header + "</actHeadline>" );
buffer.append( "<author>" + username + "</author>" );
String temp = null;
for( Version v : versions ) {
try {
temp = "<file>" + v.getSFile() + " (" + v.getVersion() + ") user: " + v.blame() + "</file>";
} catch( ClearCaseException e ) {
logger.warning( "Could not generate log" );
}
buffer.append( temp );
}
buffer.append( temp );
buffer.append( "</activity>" );
}
buffer.append( "</activity>" );

return this;
}

@@ -128,7 +128,8 @@ public EstablishResult invoke(File workspace, VirtualChannel channel) throws IOE
} catch (Exception e) {
throw new IOException("", new UnableToInitializeWorkspaceException("Unable to initialize workspace", e));
}


er.setView(sv);
er.setMessage(diff);
er.setViewtag(viewtag);

@@ -1,6 +1,7 @@
package net.praqma.hudson.remoting;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import net.praqma.clearcase.ucm.entities.Activity;
@@ -10,7 +11,7 @@ public class EstablishResult implements Serializable {

private String viewtag = "";
private String log = "";
private List<Activity> activities;
private List<Activity> activities = new ArrayList<Activity>();
private SnapshotView view;
private String message;

@@ -16,8 +16,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -59,8 +57,9 @@
*/
public class CCUCMScm extends SCM {


private static final Logger logger = Logger.getLogger(CCUCMScm.class.getName());
/* Currently only for testing */

private Boolean multisitePolling;
private Project.PromotionLevel plevel;
private String loadModule;
@@ -73,11 +72,13 @@ public class CCUCMScm extends SCM {
private String jobName = "";
private Integer jobNumber;
private boolean forceDeliver;

/**
* Determines whether to remove the view private files or not
*/
private boolean removeViewPrivateFiles;
private boolean trimmedChangeSet;
private boolean discard;

/* Old notifier fields */
private boolean recommend;
@@ -96,6 +97,7 @@ public class CCUCMScm extends SCM {
* Default constructor, mainly used for unit tests.
*/
public CCUCMScm() {
discard = false;
}

/**
@@ -106,12 +108,12 @@ public CCUCMScm() {
public CCUCMScm(String component, String levelToPoll, String loadModule, boolean newest, String polling, String stream, String treatUnstable,
boolean createBaseline, String nameTemplate, boolean forceDeliver, boolean recommend, boolean makeTag, boolean setDescription, String buildProject) {

this(component, levelToPoll, loadModule, newest, polling, stream, treatUnstable, createBaseline, nameTemplate, forceDeliver, recommend, makeTag, setDescription, buildProject, true, false);
this(component, levelToPoll, loadModule, newest, polling, stream, treatUnstable, createBaseline, nameTemplate, forceDeliver, recommend, makeTag, setDescription, buildProject, true, false, false);
}

@DataBoundConstructor
public CCUCMScm(String component, String levelToPoll, String loadModule, boolean newest, String polling, String stream, String treatUnstable,
boolean createBaseline, String nameTemplate, boolean forceDeliver, boolean recommend, boolean makeTag, boolean setDescription, String buildProject, boolean removeViewPrivateFiles, boolean trimmedChangeSet) {
boolean createBaseline, String nameTemplate, boolean forceDeliver, boolean recommend, boolean makeTag, boolean setDescription, String buildProject, boolean removeViewPrivateFiles, boolean trimmedChangeSet, boolean discard) {

this.component = component;
this.loadModule = loadModule;
@@ -133,6 +135,7 @@ public CCUCMScm(String component, String levelToPoll, String loadModule, boolean
this.setDescription = setDescription;
this.plevel = Util.getLevel(levelToPoll);
this.levelToPoll = levelToPoll;
this.discard = discard;
}

@Override
@@ -172,8 +175,6 @@ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath w

action.setBuild(build);
build.addAction(action);

//out.println( "LISTENER IS " + listener );
action.setListener(listener);

/* Determining the user has parameterized a Baseline */
@@ -236,9 +237,7 @@ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath w
/* If a baseline is found */
if (action.getBaseline() != null) {
out.println("[" + Config.nameShort + "] Using " + action.getBaseline().getNormalizedName());

//baselineName = state.getBaseline().getFullyQualifiedName();


if (polling.isPollingSelf() || !polling.isPolling()) {
logger.fine("Initializing workspace");
result = initializeWorkspace(build, workspace, changelogFile, listener, action);
@@ -416,7 +415,7 @@ private boolean initializeWorkspace(AbstractBuild<?, ?> build, FilePath workspac
er = workspace.act(ct);
//String changelog = er.getMessage();
String changelog = "";
changelog = Util.createChangelog(er.getActivities(), action.getBaseline(), trimmedChangeSet);
changelog = Util.createChangelog(er.getActivities(), action.getBaseline(), trimmedChangeSet, discard, er.getView().getViewRoot(), er.getView().getReadOnlyLoadLines());
action.setActivities(er.getActivities());

this.viewtag = er.getViewtag();
@@ -547,18 +546,21 @@ public SnapshotView initializeDeliverView(AbstractBuild<?, ?> build, CCUCMBuildA

/**
* Generate the change log for poll/sibling mode
* @param build
* @throws java.lang.InterruptedException
*/
public void generateChangeLog(AbstractBuild<?, ?> build, CCUCMBuildAction state, BuildListener listener, File changelogFile, SnapshotView snapshotView) throws IOException, InterruptedException {
FilePath workspace = build.getWorkspace();
PrintStream consoleOutput = listener.getLogger();

logger.fine("Generating change log");
logger.fine(String.format( "Trim changeset = %s, Discard changes under read-only = %s", trimmedChangeSet, discard ) );

GetChanges gc = new GetChanges(listener, state.getStream(), state.getBaseline(), snapshotView.getPath());
List<Activity> activities = workspace.act(gc);

String changelog = "";
changelog = Util.createChangelog(activities, state.getBaseline(), trimmedChangeSet);
changelog = Util.createChangelog(activities, state.getBaseline(), trimmedChangeSet, discard, new File(snapshotView.getPath()), snapshotView.getReadOnlyLoadLines());
state.setActivities(activities);

/* Write change log */
@@ -970,6 +972,15 @@ public boolean isRecommend() {
public void setMultisitePolling(boolean mp) {
this.multisitePolling = mp;
}

public boolean isDiscard() {
return discard;
}


public void setDiscard(boolean discard) {
this.discard = discard;
}

/**
* This class is used to describe the plugin to Hudson
@@ -81,6 +81,12 @@
<f:entry title="Trimmed change set" help="/plugin/clearcase-ucm-plugin/scm/help-trimmedChangeSet.html">
<f:checkbox name="CCUCM.trimmedChangeSet" checked="${scm.trimmedChangeSet}" default="false" />
</f:entry>

<f:entry title="Discard read-only, rebase and deliver activities" field="discard">
<f:checkbox checked="${scm.discard}" default="false" />
</f:entry>



<f:entry title="Build project" help="/plugin/clearcase-ucm-plugin/scm/help-buildProject.html">
<f:textbox name="buildProject" value="${scm.buildProject}"/>
@@ -0,0 +1,3 @@
<div>
Discard activities under read only components from the changeset.
</div>

0 comments on commit c6e44f7

Please sign in to comment.