Skip to content

Commit

Permalink
Fixed JENKINS-26529
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Jan 26, 2015
1 parent 12b03a0 commit a008298
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 42 deletions.
48 changes: 10 additions & 38 deletions src/main/java/net/praqma/hudson/Util.java
Expand Up @@ -8,11 +8,9 @@
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.praqma.clearcase.Cool;
import net.praqma.clearcase.PVob;
import net.praqma.clearcase.exceptions.ClearCaseException;
import net.praqma.clearcase.exceptions.ViewException;
Expand All @@ -21,15 +19,13 @@
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;
import net.praqma.clearcase.ucm.view.SnapshotView.Components;
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 net.praqma.hudson.remoting.CreateChangeSetRemote;
import org.apache.commons.lang.SystemUtils;

public abstract class Util {
Expand Down Expand Up @@ -61,42 +57,18 @@ public Stream getDeveloperStream( String streamname, PVob pvob, Stream buildInte

return devstream;
}

public static String createChangelog(AbstractBuild<?, ?> build, List<Activity> activities, Baseline bl, boolean trimmed, File viewRoot, List<String> readonly, boolean ignoreReadOnly) throws IOException, InterruptedException {
return Util.createChangelog(build, activities, bl, trimmed, viewRoot, readonly, ignoreReadOnly, true);
}

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() + ".*$" );

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();
}

for( Activity activity : changeSet.keySet() ) {
csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), changeSet.get( activity ) );
}
public static String createChangelog(AbstractBuild<?, ?> build, List<Activity> activities, Baseline bl, boolean trimmed, File viewRoot, List<String> readonly, boolean ignoreReadOnly, boolean useSlaves ) throws IOException, InterruptedException {
if(useSlaves) {
return build.getWorkspace().act(new CreateChangeSetRemote(activities, bl, trimmed, viewRoot, readonly, ignoreReadOnly));
} 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 );
}
CreateChangeSetRemote set = new CreateChangeSetRemote(activities, bl, trimmed, viewRoot, readonly, ignoreReadOnly);
return set.invoke(null, null);
}

return csg.close().get();
}

public static class ChangeSetGenerator {
Expand Down
@@ -0,0 +1,87 @@
/*
* 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.Cool;
import net.praqma.clearcase.exceptions.UnableToLoadEntityException;
import net.praqma.clearcase.ucm.entities.Activity;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Version;
import net.praqma.clearcase.ucm.utils.ReadOnlyVersionFilter;
import net.praqma.clearcase.ucm.utils.VersionList;
import net.praqma.hudson.Util;

/**
*
* @author Mads
*/
public class CreateChangeSetRemote implements FilePath.FileCallable<String>{

private static final Logger logger = Logger.getLogger(CreateChangeSetRemote.class.getName());

public final List<Activity> activities;
public final Baseline bl;
public final boolean trimmed;
public final File viewRoot;
public final List<String> readOnly;
public final boolean ignoreReadOnly;

public CreateChangeSetRemote(List<Activity> activities, Baseline bl, boolean trimmed, File viewRoot, List<String> readonly, boolean ignoreReadOnly) {
this.activities = activities;
this.bl = bl;
this.trimmed = trimmed;
this.viewRoot = viewRoot;
this.readOnly = readonly;
this.ignoreReadOnly = ignoreReadOnly;
}

@Override
public String invoke(File file, VirtualChannel vc) throws IOException, InterruptedException {
logger.fine( String.format("Trim changeset: %s", trimmed));
Util.ChangeSetGenerator csg = new Util.ChangeSetGenerator().createHeader( bl.getShortname() );

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

if(ignoreReadOnly) {
vl = vl.addFilter(new ReadOnlyVersionFilter(viewRoot, readOnly)).apply();
}

Map<Activity, List<Version>> acts = vl.getLatestForActivities();
for(Activity a : acts.keySet()) {
try {
a.load();
} catch (UnableToLoadEntityException ex) {
logger.severe("Could not autoload actitity "+a);
}
}

for( Activity activity : acts.keySet() ) {
csg.addAcitivity( activity.getShortname(), activity.getHeadline(), activity.getUser(), acts.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 );
}
}

return csg.close().get();
}

}
7 changes: 3 additions & 4 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -642,7 +642,8 @@ public void generateChangeLog(AbstractBuild<?, ?> build, CCUCMBuildAction state,

String changelog = "";

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

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

/* Write change log */
Expand Down Expand Up @@ -806,9 +807,7 @@ private List<Baseline> getBaselinesFromStreams(FilePath workspace, TaskListener
streams = RemoteUtil.getRelatedStreams(workspace, listener, stream, polling, this.getSlavePolling(), this.getMultisitePolling(), this.getHLinkFeedFrom());
} catch (Exception e1) {
Throwable root = ExceptionUtils.getRootCause(e1);
logger.log(Level.WARNING, "Could not get related streams from " + stream, root);
//TODO:Remove this before 1.5.6
e1.printStackTrace(consoleOutput);
logger.log(Level.WARNING, "Could not get related streams from " + stream, root);
consoleOutput.println("[" + Config.nameShort + "] No streams found");
return baselines;
}
Expand Down

0 comments on commit a008298

Please sign in to comment.