Skip to content

Commit

Permalink
Implemented JENKINS-28983
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Aug 26, 2015
1 parent 14d38e2 commit 46d3b92
Show file tree
Hide file tree
Showing 28 changed files with 518 additions and 222 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.4</version>
<version>1.532.3</version>
</parent>
<developers>
<developer>
Expand Down
@@ -1,8 +1,6 @@
package net.praqma.jenkins.configrotator;

import hudson.model.AbstractBuild;
import net.praqma.jenkins.configrotator.scm.ConfigRotatorChangeLogEntry;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -19,30 +17,32 @@ public String getView( Class<?> clazz ) {
return clazz.getName().replace( '.', '/' ).replace( '$', '/' ) + "/" + "cr.jelly";
}

public AbstractConfigurationComponent getChangedComponent() {
public List<AbstractConfigurationComponent> getChangedComponents() {
List<AbstractConfigurationComponent> changedComponents = new ArrayList<AbstractConfigurationComponent>();
for( AbstractConfigurationComponent configuration : this.getList() ) {
if( configuration.isChangedLast() ) {
return (AbstractConfigurationComponent) configuration;
changedComponents.add(configuration);
}
}
return null;
return changedComponents;
}

/**
* Gets the index of the changed component.
*
* @return the index of the changed component. If there is no changed component default return value is -1
*/
public int getChangedComponentIndex() {
int index = -1;

for( AbstractConfigurationComponent configuration : this.getList() ) {
public List<Integer> getChangedComponentIndecies() {
List<Integer> indicies = new ArrayList<Integer>();
List<? extends AbstractConfigurationComponent> l = this.getList();
for( AbstractConfigurationComponent configuration : l ) {
if( configuration.isChangedLast() ) {
index = getList().indexOf( configuration );
int i = l.indexOf( configuration );
indicies.add(i);
}
}

return index;
return indicies;
}

@Override
Expand All @@ -58,22 +58,30 @@ public List<T> getList() {

public abstract String toHtml();

public String getDescription( AbstractBuild<?, ?> build ) {

public String getDescription( ConfigurationRotatorBuildAction action ) {
if( description == null ) {
ConfigurationRotator rotator = (ConfigurationRotator) build.getProject().getScm();
if( getChangedComponent() == null ) {
ConfigurationRotator rotator = (ConfigurationRotator) action.getBuild().getProject().getScm();
if( getChangedComponents().isEmpty() ) {
return "New Configuration - no changes yet";
} else {
ConfigurationRotatorBuildAction previous = rotator.getAcrs().getPreviousResult( build, null );

//return String.format( "Commit changed:<br/>%s<br/>%s", previous.getConfigurationWithOutCast().getList().get( getChangedComponentIndex() ).prettyPrint(), getChangedComponent().prettyPrint() );
return String.format( "%s<br/>%s", ((T)previous.getConfigurationWithOutCast().getList().get( getChangedComponentIndex() ) ).prettyPrint(), getChangedComponent().prettyPrint() );
ConfigurationRotatorBuildAction previous = rotator.getAcrs().getPreviousResult( action.getBuild(), null );
List<Integer> changes = getChangedComponentIndecies();
List<AbstractConfigurationComponent> changedComps = getChangedComponents();

StringBuilder builder = new StringBuilder();
for(Integer i : changes) {
String c = String.format( "%s<br/>%s%n", ((T)previous.getConfigurationWithOutCast().getList().get( i) ).prettyPrint(), changedComps.get(i).prettyPrint() );
builder.append(c);
}

return builder.toString();
}
}

return description;
}


public String basicHtml( StringBuilder builder, String ... titles ) {

Expand Down
Expand Up @@ -73,7 +73,7 @@ public Entry getFeedEntry( AbstractBuild<?, ?> build, Date updated ) {
entry.author = new Person( "Jenkins config-rotator job: "
+ build.getParent().getDisplayName() + ", build: #" + build.getNumber() );

entry.content = configuration.getDescription( build );
entry.content = configuration.getDescription( action );
Html.Break br1 = new Html.Break();
Html.Anchor linkFeeds = new Html.Anchor( ConfigurationRotatorReport.FeedFrontpageUrl(), "Click here for a list of available feeds" );
Html.Break br2 = new Html.Break();
Expand Down
@@ -1,5 +1,4 @@
package net.praqma.jenkins.configrotator;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,14 +21,16 @@
import net.praqma.jenkins.configrotator.scm.ConfigRotatorChangeLogParser;
import net.praqma.jenkins.configrotator.scm.ConfigRotatorVersion;
import net.praqma.jenkins.configrotator.scm.contribute.ConfigRotatorCompatabilityConverter;
import org.kohsuke.stapler.DataBoundSetter;

public abstract class AbstractConfigurationRotatorSCM implements Describable<AbstractConfigurationRotatorSCM>, ExtensionPoint {

private static final Logger logger = Logger.getLogger(AbstractConfigurationRotatorSCM.class.getName());
protected AbstractConfiguration projectConfiguration;
private boolean useNewest = false;

/**
* Return the name of the type
* @return The name of the abstract configuration rotator SCM.
*/
public abstract String getName();

Expand All @@ -51,6 +52,21 @@ public AbstractConfiguration getConfiguration() {

public abstract AbstractConfigurationRotatorSCM.Poller getPoller(AbstractProject<?, ?> project, Launcher launcher, FilePath workspace, TaskListener listener);

/**
* @return the useNewest
*/
public boolean isUseNewest() {
return useNewest;
}

/**
* @param useNewest the useNewest to set
*/
@DataBoundSetter
public void setUseNewest(boolean useNewest) {
this.useNewest = useNewest;
}

/**
*
* @param <C>
Expand Down Expand Up @@ -286,6 +302,7 @@ public Descriptor<AbstractConfigurationRotatorSCM> getDescriptor() {

/**
* All registered {@link AbstractConfigurationRotatorSCM}s.
* @return
*/
public static DescriptorExtensionList<AbstractConfigurationRotatorSCM, ConfigurationRotatorSCMDescriptor<AbstractConfigurationRotatorSCM>> all() {
return Jenkins.getInstance().<AbstractConfigurationRotatorSCM, ConfigurationRotatorSCMDescriptor<AbstractConfigurationRotatorSCM>>getDescriptorList(AbstractConfigurationRotatorSCM.class);
Expand All @@ -296,22 +313,16 @@ public static List<ConfigurationRotatorSCMDescriptor<?>> getDescriptors() {
for (ConfigurationRotatorSCMDescriptor<?> d : all()) {
list.add(d);
}

return list;
}

public ConfigurationRotatorBuildAction getLastResult(AbstractProject<?, ?> project, Class<? extends AbstractConfigurationRotatorSCM> clazz) {

for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(project); b != null; b = b.getPreviousBuild()) {
ConfigurationRotatorBuildAction r = b.getAction(ConfigurationRotatorBuildAction.class);

if (r != null) {
if (r.isDetermined() && (clazz == null || r.getClazz().equals(clazz))) {
return r;
}
if (r != null && r.isDetermined() && (clazz == null || r.getClazz().equals(clazz)) ) {
return r;
}
}

return null;
}

Expand All @@ -320,32 +331,26 @@ public DiedBecauseAction getLastDieAction(AbstractProject<?, ?> project) {
}

public ConfigurationRotatorBuildAction getPreviousResult(AbstractBuild<?, ?> build, Class<? extends AbstractConfigurationRotatorSCM> clazz) {

for (AbstractBuild<?, ?> b = build.getPreviousBuild(); b != null; b = b.getPreviousBuild()) {
ConfigurationRotatorBuildAction r = b.getAction(ConfigurationRotatorBuildAction.class);

if (r != null) {
if (r.isDetermined() && (clazz == null || r.getClazz().equals(clazz))) {
return r;
}
if (r != null && r.isDetermined() && (clazz == null || r.getClazz().equals(clazz)) ) {
return r;
}
}

return null;
}

public ArrayList<ConfigurationRotatorBuildAction> getLastResults(AbstractProject<?, ?> project, Class<? extends AbstractConfigurationRotatorSCM> clazz, int limit) {
ArrayList<ConfigurationRotatorBuildAction> actions = new ArrayList<ConfigurationRotatorBuildAction>();
for (AbstractBuild<?, ?> b = getLastBuildToBeConsidered(project); b != null; b = b.getPreviousBuild()) {
ConfigurationRotatorBuildAction r = b.getAction(ConfigurationRotatorBuildAction.class);
if (r != null) {
if (r.isDetermined() && ((clazz == null || r.getClazz().equals(clazz)))) {
actions.add(r);
if (actions.size() >= limit) {
return actions;
}
if (r!= null && r.isDetermined() && (clazz == null || r.getClazz().equals(clazz))) {
actions.add(r);
if (actions.size() >= limit) {
return actions;
}
}

}
return actions;
}
Expand Down
Expand Up @@ -13,10 +13,8 @@ public abstract class AbstractPostConfigurationRotator implements ExtensionPoint

public static boolean doit( FilePath workspace, TaskListener listener, ConfigurationRotatorBuildAction action ) {
for( AbstractPostConfigurationRotator l : all() ) {
if( l.tiedTo().equals( action.getClazz() ) ) {
if( !l.perform( workspace, listener, action ) ) {
return false;
}
if( l.tiedTo().equals( action.getClazz()) && !l.perform( workspace, listener, action ) ) {
return false;
}
}
return true;
Expand Down
Expand Up @@ -43,9 +43,6 @@ public enum ResultType {
COMPATIBLE,
INCOMPATIBLE,
FAILED,
/*
* The tests failed and was unable to determine compatibility
*/
UNDETERMINED
}

Expand All @@ -61,16 +58,10 @@ public enum ResultType {
private static String VERSION = "Unresolved";

static {
try {
if( Jenkins.getInstance() != null ) {
FEED_PATH = new File( Jenkins.getInstance().getRootDir(), FEED_DIR );
VERSION = Jenkins.getInstance().getPlugin( "config-rotator" ).getWrapper().getVersion();
} else {

}
} catch ( Exception e ) {
/* No op */
}
if( Jenkins.getInstance() != null ) {
FEED_PATH = new File( Jenkins.getInstance().getRootDir(), FEED_DIR );
VERSION = Jenkins.getInstance().getPlugin( "config-rotator" ).getWrapper().getVersion();
}
}

public static File getFeedPath() {
Expand Down Expand Up @@ -249,6 +240,7 @@ protected PollingResult compareRemoteRevisionWith( AbstractProject<?, ?> project
try {
if( reconfigure ) {
logger.fine( "Reconfigured, build now!" );

out.println( LOGGERNAME + "Configuration from scratch, build now!" );
return PollingResult.BUILD_NOW;
} else if( lastAction == null) {
Expand Down

0 comments on commit 46d3b92

Please sign in to comment.