Skip to content

Commit

Permalink
Implemented JENKINS-30191
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Sep 1, 2015
1 parent 59da3f1 commit 50c963a
Show file tree
Hide file tree
Showing 40 changed files with 397 additions and 244 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -436,14 +436,14 @@
<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.40</version>
<version>0.6.43-SNAPSHOT</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>net.praqma</groupId>
<artifactId>cool</artifactId>
<version>0.6.40</version>
<version>0.6.43-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
105 changes: 21 additions & 84 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -11,6 +11,7 @@
import hudson.scm.SCMRevisionState;
import hudson.scm.SCM;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;

import java.io.File;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -47,6 +48,7 @@
import static net.praqma.hudson.scm.CCUCMScm.getLastAction;
import net.praqma.hudson.scm.Polling.PollingType;
import net.praqma.hudson.scm.pollingmode.BaselineCreationEnabled;
import net.praqma.hudson.scm.pollingmode.NewestFeatureToggle;
import net.praqma.hudson.scm.pollingmode.PollChildMode;
import net.praqma.hudson.scm.pollingmode.PollRebaseMode;
import net.praqma.hudson.scm.pollingmode.PollSelfMode;
Expand Down Expand Up @@ -275,9 +277,8 @@ public boolean checkout(AbstractBuild<?, ?> build, Launcher launcher, FilePath w

logger.warning(e.getMessage());
/* If the promotion level is not set, ANY, use the last found Baseline */
/* This also applies if you're configured to forward to the newest */
if (isUseLatestAlways(mode)) {
logger.fine("Promotion level was null [=ANY], finding the last built baseline");
if (mode.getPromotionLevel() == null) {
logger.fine("Configured to use the latest always.");
CCUCMBuildAction last = getLastAction(build.getProject());
if (last != null) {
action.setBaseline(last.getBaseline());
Expand Down Expand Up @@ -522,13 +523,10 @@ 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, (_getPlevel() == null), action.doRemoveViewPrivateFiles());
er = workspace.act(ct);
EstablishResult er = workspace.act(ct);

String changelog = "";
changelog = Util.createChangelog(build, er.getActivities(), action.getBaseline(), trimmedChangeSet, er.getView().getViewRoot(), er.getView().getReadOnlyLoadLines(), discard);
String 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 @@ -696,18 +694,11 @@ private Result resolveBaseline(AbstractBuild<?,?> build, AbstractProject<?, ?> p
action.setRebaseTargets(baselines);
action.setNewFoundationStructure(results.t2);
}




/* if we did not find any baselines we should return false */
if (baselines.size() < 1) {
throw new CCUCMException("No valid Baselines found");
}


/* If the exlusion list contains invalid elements */

}

/* Select and load baseline */
Baseline blSelected = selectBaseline(baselines, mode, build.getWorkspace());
Expand Down Expand Up @@ -810,10 +801,7 @@ public void generateChangeLog(AbstractBuild<?, ?> build, CCUCMBuildAction state,
GetChanges gc = new GetChanges(listener, state.getStream(), state.getBaseline(), snapshotView.getPath());
List<Activity> activities = workspace.act(gc);

String changelog = "";


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

/* Write change log */
Expand All @@ -840,15 +828,9 @@ public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
String CC_VIEWPATH = "";

try {

CCUCMBuildAction action = build.getAction(CCUCMBuildAction.class);
CC_BASELINE = action.getBaseline().getFullyQualifiedName();
} catch (Exception e1) {
if (build != null) {
System.out.println( String.format ( "Failure in build environment variables (buildEnvVars) for job %s %nFull trace written to log", build.getProject().getName()) );
} else {
System.out.println( String.format ( "Build is null in buildEnvVars.%nTrace written to log as no other information can be gathered" ) );
}
} catch (Exception e1) {
logger.log(Level.WARNING, "Exception caught in buildEnvVars method", e1);
}

Expand Down Expand Up @@ -932,10 +914,6 @@ public PollingResult compareRemoteRevisionWith(AbstractProject<?, ?> project, La

List<Baseline> baselines = null;

/* We need to discriminate on promotion level, JENKINS-16620.
*
* This is ONLY for ANY!
* */
Date date = null;
if (isUseLatestAlways(mode)) {
CCUCMBuildAction lastAction = getLastAction(project);
Expand Down Expand Up @@ -1082,7 +1060,6 @@ private Tuple<Result,List<Baseline>> getValidBaselinesFromStreamWithSubscribe(Li
}
}


/**
* Returns the last {@link CCUCMBuildAction}, that has a valid
* {@link Baseline}
Expand Down Expand Up @@ -1139,30 +1116,10 @@ public SCMRevisionState calcRevisionsFromBuild(AbstractBuild<?, ?> build, Launch
}
return scmRS;
}

@Deprecated
private Baseline selectBaseline(List<Baseline> baselines, Project.PromotionLevel plevel, FilePath workspace) throws IOException, InterruptedException {
Baseline selected = null;
if (baselines.size() > 0) {
if (plevel != null) {
selected = baselines.get(0);
} else {
selected = baselines.get(baselines.size() - 1);
}

return (Baseline) RemoteUtil.loadEntity(workspace, selected, true);
} else {
return null;
}
}

private boolean isUseLatestAlways(PollingMode mode) {

if(mode.getPromotionLevel() == null) {
return true;
}
if(mode instanceof PollSubscribeMode) {
return ((PollSubscribeMode)mode).isNewest();
if(mode instanceof NewestFeatureToggle) {
return ((NewestFeatureToggle)mode).isNewest();
}
return false;
}
Expand Down Expand Up @@ -1364,11 +1321,8 @@ public static class CCUCMScmDescriptor extends SCMDescriptor<CCUCMScm> implement
private String hLinkFeedFrom;
private boolean slavePolling;
private boolean multisitePolling;
private List<String> loadModules;

public CCUCMScmDescriptor() {
super(CCUCMScm.class, null);
loadModules = getLoadModules();
load();
}

Expand Down Expand Up @@ -1456,21 +1410,17 @@ public FormValidation doCheckStream(@QueryParameter String stream) {
}
return FormValidation.ok();
}

public ListBoxModel doFillLoadModuleItems() {
ListBoxModel model = new ListBoxModel();
model.add("All", "ALL");
model.add("Modifiable","MODIFIABLE");
return model;
}

@Override
public CCUCMScm newInstance(StaplerRequest req, JSONObject formData) throws Descriptor.FormException {
CCUCMScm temp;
CCUCMScm instance;
try {
temp = req.bindJSON(CCUCMScm.class, formData);
} catch (JSONException e) {
throw new Descriptor.FormException("You missed some fields: " + e.getMessage(), "CCUCM.polling");
}
instance = temp;


/* TODO This is actually where the Notifier check should be!!! */
return instance;
public CCUCMScm newInstance(StaplerRequest req, JSONObject formData) {
return req.bindJSON(CCUCMScm.class, formData);
}

/**
Expand All @@ -1483,20 +1433,7 @@ public CCUCMScm newInstance(StaplerRequest req, JSONObject formData) throws Desc
public List<String> getLevels() {
return Config.getLevels();
}

/**
* Used by Hudson to display a list of loadModules (whether to poll all
* or only modifiable elements
*
* @return
*/
public List<String> getLoadModules() {
loadModules = new ArrayList<String>();
loadModules.add("All");
loadModules.add("Modifiable");
return loadModules;
}


/**
* @return the hLinkFeedFrom
*/
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/net/praqma/hudson/scm/ChangeLogEntryImpl.java
Expand Up @@ -20,7 +20,6 @@
*/
public class ChangeLogEntryImpl extends Entry {


/*Pattern we use to tablify the 'file' entry */
private static final transient Pattern splitChangeSet = Pattern.compile("^([^\\(]+)\\(([^\\)]+)(.*?)(\\S+)(\\S+)(.*)");
private ChangeLogSetImpl parent;
Expand Down Expand Up @@ -102,7 +101,6 @@ public void setMyAuthor( String author ) {

/**
* This is to tell the Entry which Changeset it belongs to
*
* @param parent
*/
public void setParent( ChangeLogSetImpl parent ) {
Expand All @@ -129,6 +127,4 @@ public String getActHeadline() {
return actHeadline;
}



}
3 changes: 2 additions & 1 deletion src/main/java/net/praqma/hudson/scm/ChangeLogParserImpl.java
Expand Up @@ -15,6 +15,7 @@
import hudson.scm.ChangeLogSet;
import hudson.scm.ChangeLogSet.Entry;
import hudson.util.Digester2;
import java.util.logging.Level;

/**
*
Expand Down Expand Up @@ -43,7 +44,7 @@ public ChangeLogSet<? extends Entry> parse( AbstractBuild build, File changelogF
try {
digester.parse( reader );
} catch( Exception e ) {
System.out.println( "Whoops, unable to digest. " + e.getMessage() );
logger.log(Level.SEVERE, "Unable to parse change log", e);
} finally {
reader.close();
}
Expand Down
@@ -0,0 +1,10 @@
package net.praqma.hudson.scm.pollingmode;

/**
* Marker interface indicating if this mode should use the newest baseline among all candidates always.
*
* @author Mads
*/
public interface NewestFeatureToggle {
public boolean isNewest();
}
Expand Up @@ -15,9 +15,10 @@
/**
* @author Mads
*/
public class PollChildMode extends PollingMode implements BaselineCreationEnabled {
public class PollChildMode extends PollingMode implements BaselineCreationEnabled, NewestFeatureToggle {

private boolean createBaseline = false;
private boolean newest = false;

@DataBoundConstructor
public PollChildMode(String levelToPoll) {
Expand All @@ -41,6 +42,15 @@ public void setCreateBaseline(boolean createBaseline) {
this.createBaseline = createBaseline;
}

@DataBoundSetter
public void setNewest(boolean newest) {
this.newest = newest;
}

public boolean isNewest() {
return newest;
}

@Extension
public static final class PollChildDescriptor extends PollingModeDescriptor<PollingMode> {

Expand Down
Expand Up @@ -10,12 +10,15 @@
import net.praqma.hudson.Config;
import net.praqma.hudson.scm.Polling;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.DataBoundSetter;

/**
*
* @author Mads
*/
public class PollSelfMode extends PollingMode {
public class PollSelfMode extends PollingMode implements NewestFeatureToggle {

private boolean newest;

@DataBoundConstructor
public PollSelfMode(String levelToPoll) {
Expand All @@ -28,6 +31,19 @@ public boolean isPromotionSkipped() {
return this.getPromotionLevel() == null;
}

@DataBoundSetter
public void setNewest(boolean newest) {
this.newest = newest;
}

@Override
public boolean isNewest() {
if (getPromotionLevel() == null) {
return true;
}
return newest;
}

@Extension
public static final class PollSelfDescriptor extends PollingModeDescriptor<PollingMode> {

Expand Down
Expand Up @@ -16,10 +16,11 @@
*
* @author Mads
*/
public class PollSiblingMode extends PollingMode implements BaselineCreationEnabled {
public class PollSiblingMode extends PollingMode implements BaselineCreationEnabled, NewestFeatureToggle {

private boolean useHyperLinkForPolling = false;
private boolean createBaseline = false;
private boolean newest = false;


@DataBoundConstructor
Expand Down Expand Up @@ -63,6 +64,16 @@ public void setCreateBaseline(boolean createBaseline) {
this.createBaseline = createBaseline;
}

@DataBoundSetter
public void setNewest(boolean newest) {
this.newest = newest;
}

@Override
public boolean isNewest() {
return newest;
}

@Extension
public static class PollSiblingDescriptor extends PollingModeDescriptor<PollingMode> {

Expand Down
Expand Up @@ -5,13 +5,8 @@
<f:textbox/>
</f:entry>

<f:entry title="Load modules" help="/plugin/clearcase-ucm-plugin/scm/help-loadModules.html">
<select class="setting-input" name="CCUCM.loadModule">
<j:set var="modules" value="${descriptor.getLoadModules()}"/>
<j:forEach var="lm" items="${modules}">
<f:option selected="${scm.loadModule==lm}" value="${lm}">${lm}</f:option>
</j:forEach>
</select>
<f:entry title="Load modules" help="/plugin/clearcase-ucm-plugin/scm/help-loadModules.html" field="loadModule">
<f:select/>
</f:entry>

<f:dropdownDescriptorSelector field="mode" title="Polling"/>
Expand Down
Expand Up @@ -7,4 +7,7 @@
<f:entry field="createBaseline" title="Create baseline">
<f:checkbox/>
</f:entry>
<f:entry field="newest" title="Use newest">
<f:checkbox/>
</f:entry>
</j:jelly>

0 comments on commit 50c963a

Please sign in to comment.