Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #19 from Praqma/JENKINS-25069
JENKINS-25069, JENKINS-23533
  • Loading branch information
MadsNielsen committed Nov 4, 2014
2 parents 725f99b + a20a816 commit f65deb4
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 69 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -430,14 +430,14 @@
<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.31</version>
<version>0.6.35</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.31</version>
<version>0.6.35</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/praqma/hudson/CCUCMBuildAction.java
Expand Up @@ -353,7 +353,7 @@ public String toString() {


public String stringify() {
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
sb.append( "Stream : " + stream + "\n" );
sb.append( "Component : " + component + "\n" );
sb.append( "Promotion Level : " + promotionLevel + "\n" );
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/net/praqma/hudson/Util.java
@@ -1,6 +1,7 @@
package net.praqma.hudson;

import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;

import java.io.*;
Expand Down Expand Up @@ -28,6 +29,7 @@
import net.praqma.clearcase.ucm.view.SnapshotView.LoadRules2;
import net.praqma.clearcase.ucm.view.UpdateView;
import net.praqma.hudson.exception.ScmException;
import net.praqma.hudson.remoting.GetLatestForActivities;
import org.apache.commons.lang.SystemUtils;

public abstract class Util {
Expand Down Expand Up @@ -60,31 +62,36 @@ public Stream getDeveloperStream( String streamname, PVob pvob, Stream buildInte
return devstream;
}

public static String createChangelog( List<Activity> activities, Baseline bl, boolean trimmed, File viewRoot, List<String> readonly ) {
public static String createChangelog(AbstractBuild<?, ?> build, List<Activity> activities, Baseline bl, boolean trimmed, File viewRoot, List<String> readonly, boolean ignoreReadOnly ) throws IOException, InterruptedException {
logger.fine( String.format("Trim changeset: %s", trimmed));
ChangeSetGenerator csg = new ChangeSetGenerator().createHeader( bl.getShortname() );

if( trimmed ) {
logger.fine("Creating trimmed change set");
VersionList vl = new VersionList().addActivities( activities ).setBranchName( "^.*" + Cool.qfs + bl.getStream().getShortname() + ".*$" );
logger.fine("Versions before filter: " + vl.size());

Map<Activity, List<Version>> changeSet = vl.getLatestForActivities();
int now = 0;
if(ignoreReadOnly) {
vl = vl.addFilter(new ReadOnlyVersionFilter(viewRoot, readonly)).apply();
}

Map<Activity, List<Version>> changeSet = build.getWorkspace().act(new GetLatestForActivities(vl));
int now = 0;

for(List<Version> vlist : changeSet.values()) {
now+=vlist.size();
}

logger.fine("Versions after filter: " + now);

for( Activity activity : changeSet.keySet() ) {
csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), changeSet.get( activity ) );
}
} else {
logger.fine("Creating non-trimmed changeset");
for( Activity activity : activities ) {
VersionList versions = new VersionList( activity.changeset.versions ).getLatest();
if(ignoreReadOnly) {
versions = versions.addFilter(new ReadOnlyVersionFilter(viewRoot, readonly)).apply();
}

csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), versions );
}
}
Expand Down Expand Up @@ -137,11 +144,11 @@ public String get() {
return buffer.toString();
}
}

/*
public static SnapshotView makeView( Stream stream, File workspace, BuildListener listener, String loadModule, File viewroot, String viewtag ) throws ScmException {
return makeView( stream, workspace, listener, loadModule, viewroot, viewtag, true );
}

*/
public static SnapshotView makeView( Stream stream, File workspace, BuildListener listener, String loadModule, File viewroot, String viewtag, boolean update ) throws ScmException {

PrintStream hudsonOut = listener.getLogger();
Expand Down Expand Up @@ -187,7 +194,7 @@ public static SnapshotView makeView( Stream stream, File workspace, BuildListene
} catch( Exception e ) {
throw new ScmException( "Unable to recursively prepare view root", e );
}
makeView( stream, workspace, listener, loadModule, viewroot, viewtag );
makeView( stream, workspace, listener, loadModule, viewroot, viewtag, true );
}
} catch( ClearCaseException ucmE ) {
try {
Expand Down Expand Up @@ -232,8 +239,7 @@ public static SnapshotView makeView( Stream stream, File workspace, BuildListene
try {
hudsonOut.println( "[" + Config.nameShort + "] Updating view using " + loadModule.toLowerCase() + " modules." );
UpdateView uw = new UpdateView(snapview).swipe().generate().overwrite().setLoadRules(new LoadRules2( snapview, Components.valueOf( loadModule.toUpperCase() ) ));
uw.update();
//snapview.Update( true, true, true, false, new LoadRules2( snapview, Components.valueOf( loadModule.toUpperCase() ) ) );
uw.update();
} catch( ClearCaseException e ) {
e.print( hudsonOut );
if( e instanceof ViewException ) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/praqma/hudson/remoting/CheckoutTask.java
Expand Up @@ -192,7 +192,7 @@ private void makeWorkspace(File workspace, String viewtag) throws ScmException,

upview.setLoadRules(new LoadRules2(sv, Components.valueOf(loadModule.toUpperCase())));
//sv.Update(swipe, true, true, false, new LoadRules2(sv, Components.valueOf(loadModule.toUpperCase())));
upview.update();
upview.update();
logger.fine("Updating done");
} catch (ClearCaseException e) {
e.print(hudsonOut);
Expand Down
@@ -0,0 +1,60 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package net.praqma.hudson.remoting;

import hudson.FilePath;
import hudson.remoting.VirtualChannel;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import net.praqma.clearcase.exceptions.UnableToLoadEntityException;
import net.praqma.clearcase.ucm.entities.Activity;
import net.praqma.clearcase.ucm.entities.Version;
import net.praqma.clearcase.ucm.utils.VersionList;

/**
*
* @author Mads
*/
public class GetLatestForActivities implements FilePath.FileCallable<Map<Activity, List<Version>>> {

private static final Logger LOG = Logger.getLogger(GetLatestForActivities.class.getName());
private VersionList list;

public GetLatestForActivities(VersionList list) {
this.list = list;
}

@Override
public Map<Activity, List<Version>> invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
Map<Activity, List<Version>> activities = list.getLatestForActivities();
for(Activity a : activities.keySet()) {
try {
a.load();
} catch (UnableToLoadEntityException ex) {
LOG.severe("Could not autoload actitity "+a);
}
}
return activities;
}

/**
* @return the list
*/
public VersionList getList() {
return list;
}

/**
* @param list the list to set
*/
public void setList(VersionList list) {
this.list = list;
}

}
Expand Up @@ -46,10 +46,8 @@ public Boolean invoke( File f, VirtualChannel channel ) throws IOException, Inte

Deliver deliver = new Deliver( baseline, baseline.getStream(), stream, viewPath, viewtag );
if( complete ) {

try {
deliver.complete();
//baseline.deliver( baseline.getStream(), stream, view.getViewRoot(), view.getViewtag(), true, true, true );
} catch( Exception ex ) {
try {
deliver.cancel();
Expand All @@ -61,8 +59,7 @@ public Boolean invoke( File f, VirtualChannel channel ) throws IOException, Inte

} else {
out.println( "Cancelling" );
try {
//baseline.cancel( view.getViewRoot() );
try {
deliver.cancel();
} catch( Exception ex ) {
throw new IOException( "Could not cancel the deliver.", ex );
Expand Down
Expand Up @@ -46,9 +46,8 @@ public SnapshotView invoke( File workspace, VirtualChannel channel ) throws IOEx

private SnapshotView makeDeliverView( Stream stream, File workspace ) throws ScmException {
viewtag = Util.createViewTag( jobName, stream );

File viewroot = new File( workspace, "view" );

return Util.makeView( stream, workspace, listener, loadModule, viewroot, viewtag );
SnapshotView view = Util.makeView( stream, workspace, listener, loadModule, viewroot, viewtag, true );
return view;
}
}
16 changes: 12 additions & 4 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -135,7 +135,7 @@ public CCUCMScm(String component, String levelToPoll, String loadModule, boolean
this.setDescription = setDescription;
this.plevel = Util.getLevel(levelToPoll);
this.levelToPoll = levelToPoll;
this.discard = false;
this.discard = discard;
}

@Override
Expand Down Expand Up @@ -407,11 +407,12 @@ private boolean checkInput(TaskListener listener) {
private boolean initializeWorkspace(AbstractBuild<?, ?> build, FilePath workspace, File changelogFile, BuildListener listener, CCUCMBuildAction action) throws IOException, InterruptedException {
PrintStream consoleOutput = listener.getLogger();
EstablishResult er = null;

CheckoutTask ct = new CheckoutTask(listener, jobName, build.getNumber(), action.getStream(), loadModule, action.getBaseline(), buildProject, (plevel == null), action.doRemoveViewPrivateFiles());
er = workspace.act(ct);
//String changelog = er.getMessage();

String changelog = "";
changelog = Util.createChangelog(er.getActivities(), action.getBaseline(), trimmedChangeSet, er.getView().getViewRoot(), er.getView().getReadOnlyLoadLines());
changelog = Util.createChangelog(build, er.getActivities(), action.getBaseline(), trimmedChangeSet, er.getView().getViewRoot(), er.getView().getReadOnlyLoadLines(), discard);
action.setActivities(er.getActivities());

this.viewtag = er.getViewtag();
Expand Down Expand Up @@ -535,6 +536,7 @@ public SnapshotView initializeDeliverView(AbstractBuild<?, ?> build, CCUCMBuildA
state.setViewPath(view.getViewRoot());
state.setViewTag(view.getViewtag());
state.setSnapshotView(view);

this.viewtag = view.getViewtag();

return view;
Expand All @@ -543,6 +545,11 @@ public SnapshotView initializeDeliverView(AbstractBuild<?, ?> build, CCUCMBuildA
/**
* Generate the change log for poll/sibling mode
* @param build
* @param state
* @param listener
* @param changelogFile
* @param snapshotView
* @throws java.io.IOException
* @throws java.lang.InterruptedException
*/
public void generateChangeLog(AbstractBuild<?, ?> build, CCUCMBuildAction state, BuildListener listener, File changelogFile, SnapshotView snapshotView) throws IOException, InterruptedException {
Expand All @@ -556,7 +563,8 @@ public void generateChangeLog(AbstractBuild<?, ?> build, CCUCMBuildAction state,
List<Activity> activities = workspace.act(gc);

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

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

/* Write change log */
Expand Down
86 changes: 43 additions & 43 deletions src/main/resources/net/praqma/hudson/scm/CCUCMScm/config.jelly
@@ -1,6 +1,5 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:entry title="Stream" help="/plugin/clearcase-ucm-plugin/scm/help-stream.html">
<f:textbox name="CCUCM.stream" value="${scm.stream}"/>
Expand All @@ -16,7 +15,7 @@
<j:forEach var="l" items="${levels}">
<f:option selected="${scm.levelToPoll==l}" value="${l}">${l}</f:option>
</j:forEach>
</select>
</select>
</f:entry>

<f:entry title="Load modules" help="/plugin/clearcase-ucm-plugin/scm/help-loadModules.html">
Expand All @@ -28,15 +27,13 @@
</select>
</f:entry>

<f:entry title="Polling" help="/plugin/clearcase-ucm-plugin/scm/help-polling.html">
<select class="setting-input" name="CCUCM.polling" checkUrl="'${rootURL}/scm/CCUCMScm/levelCheck?polling='+encodeURIComponent(this.value)+'&amp;level='+encodeURIComponent(Form.findMatchingInput(this,'CCUCM.levelToPoll').value)">
<f:option selected="${instance.polling == 'self'}" value="self">Poll self</f:option>
<f:option selected="${instance.polling == 'childs'}" value="child">Poll child streams</f:option>
<f:option selected="${instance.polling == 'siblings'}" value="sibling">Poll sibling streams</f:option>
</select>
</f:entry>

<!-- unstable -->
<f:entry title="Polling" help="/plugin/clearcase-ucm-plugin/scm/help-polling.html">
<select class="setting-input" name="CCUCM.polling" checkUrl="'${rootURL}/scm/CCUCMScm/levelCheck?polling='+encodeURIComponent(this.value)+'&amp;level='+encodeURIComponent(Form.findMatchingInput(this,'CCUCM.levelToPoll').value)">
<f:option selected="${instance.polling == 'self'}" value="self">Poll self</f:option>
<f:option selected="${instance.polling == 'childs'}" value="child">Poll child streams</f:option>
<f:option selected="${instance.polling == 'siblings'}" value="sibling">Poll sibling streams</f:option>
</select>
</f:entry>

<f:entry title="Create baseline" help="/plugin/clearcase-ucm-plugin/scm/help-createBaseline.html">
<f:checkbox name="CCUCM.createBaseline" checked="${scm.createBaseline}" checkUrl="'${rootURL}/scm/CCUCMScm/checkMode?checked='+(this.checked)+'&amp;mode='+encodeURIComponent(Form.findMatchingInput(this,'CCUCM.polling').value)" />
Expand All @@ -46,8 +43,6 @@
<f:textbox name="CCUCM.nameTemplate" value="${scm.nameTemplate}" default="[project]_[date]_[time]" />
</f:entry>

<!-- Force deliver -->

<f:entry title="Recommend baseline" help="/plugin/clearcase-ucm-plugin/scm/help-recommendBaseline.html">
<f:checkbox name="CCUCM.recommend" checked="${scm.recommend}" />
</f:entry>
Expand All @@ -59,34 +54,39 @@
<f:entry title="Set description" help="/plugin/clearcase-ucm-plugin/scm/help-setDescription.html">
<f:checkbox name="CCUCM.setDescription" checked="${h.defaultToTrue(scm.setDescription)}" default="checked" />
</f:entry>
<f:section title="Advanced ClearCase UCM Options">
<f:advanced>

<f:entry title="Unstable" help="/plugin/clearcase-ucm-plugin/scm/help-unstable.html">
<select class="setting-input" name="CCUCM.treatUnstable">
<f:option selected="${instance.treatUnstable == 'successful'}" value="successful">Unstable jobs are treated as successful</f:option>
<f:option selected="${instance.treatUnstable == 'failed'}" value="failed">Unstable jobs are treated as failed</f:option>
</select>
</f:entry>

<f:entry title="Force deliver" help="/plugin/clearcase-ucm-plugin/scm/help-forceDeliver.html">
<f:checkbox name="CCUCM.forceDeliver" checked="${scm.forceDeliver}" />
</f:entry>

<f:entry title="Remove view private files" help="/plugin/clearcase-ucm-plugin/scm/help-removeViewPrivateFiles.html">
<f:checkbox name="CCUCM.removeViewPrivateFiles" checked="${scm.removeViewPrivateFiles}" default="true"/>
</f:entry>

<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="Build project" help="/plugin/clearcase-ucm-plugin/scm/help-buildProject.html">
<f:textbox name="buildProject" value="${scm.buildProject}"/>
</f:entry>

</f:advanced>

</f:section>

<f:section title="Advanced ClearCase UCM Options">
<f:advanced>

<f:entry title="Unstable" help="/plugin/clearcase-ucm-plugin/scm/help-unstable.html">
<select class="setting-input" name="CCUCM.treatUnstable">
<f:option selected="${instance.treatUnstable == 'successful'}" value="successful">Unstable jobs are treated as successful</f:option>
<f:option selected="${instance.treatUnstable == 'failed'}" value="failed">Unstable jobs are treated as failed</f:option>
</select>
</f:entry>

<f:entry title="Force deliver" help="/plugin/clearcase-ucm-plugin/scm/help-forceDeliver.html">
<f:checkbox name="CCUCM.forceDeliver" checked="${scm.forceDeliver}" />
</f:entry>

<f:entry title="Remove view private files" help="/plugin/clearcase-ucm-plugin/scm/help-removeViewPrivateFiles.html">
<f:checkbox name="CCUCM.removeViewPrivateFiles" checked="${scm.removeViewPrivateFiles}" default="true"/>
</f:entry>

<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="Ignore changes under non-modifiable components when calculating change-set" 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}"/>
</f:entry>

</f:advanced>

</f:section>

</j:jelly>

0 comments on commit f65deb4

Please sign in to comment.