Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add includeUserConfig option #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static interface AtomicTransactionFactory {
// when commit occurs
private String commitMessagePattern = "[message]";
private List<File> filesModifiedByLastReload;
private boolean includeUserConfig = true;
private List<String> manualSynchronizationIncludes;

public ScmSyncConfigurationPlugin(){
Expand Down Expand Up @@ -165,6 +166,7 @@ public void loadData(ScmSyncConfigurationPOJO pojo){
this.commitMessagePattern = pojo.getCommitMessagePattern();
this.manualSynchronizationIncludes = pojo.getManualSynchronizationIncludes();
this.business.setManualSynchronizationIncludes(manualSynchronizationIncludes);
this.includeUserConfig = pojo.isIncludeUserConfig();
}

protected void initialInit() throws Exception {
Expand Down Expand Up @@ -201,6 +203,7 @@ public void configure(StaplerRequest req, JSONObject formData)
this.noUserCommitMessage = formData.getBoolean("noUserCommitMessage");
this.displayStatus = formData.getBoolean("displayStatus");
this.commitMessagePattern = req.getParameter("commitMessagePattern");
this.includeUserConfig = formData.getBoolean("includeUserConfig");

String oldScmRepositoryUrl = this.scmRepositoryUrl;
String scmType = req.getParameter("scm");
Expand Down Expand Up @@ -432,6 +435,10 @@ public boolean isDisplayStatus() {
return displayStatus;
}

public boolean isIncludeUserConfig() {
return includeUserConfig;
}

public String getCommitMessagePattern() {
return commitMessagePattern;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import hudson.model.Item;
import hudson.model.Saveable;
import hudson.model.User;
import hudson.plugins.scm_sync_configuration.ScmSyncConfigurationPlugin;
import hudson.plugins.scm_sync_configuration.model.MessageWeight;
import hudson.plugins.scm_sync_configuration.model.WeightedMessage;
import hudson.plugins.scm_sync_configuration.strategies.AbstractScmSyncStrategy;
import hudson.plugins.scm_sync_configuration.strategies.model.ClassAndFileConfigurationEntityMatcher;
import hudson.plugins.scm_sync_configuration.strategies.model.ConfigurationEntityMatcher;
import hudson.plugins.scm_sync_configuration.strategies.model.PageMatcher;

import java.io.File;
import java.util.List;

import com.google.common.collect.ImmutableList;
Expand All @@ -34,6 +36,24 @@ public UserConfigScmSyncStrategy(){
super(CONFIG_ENTITY_MATCHER, PAGE_MATCHERS);
}

@Override
public boolean isSaveableApplicable(Saveable saveable, File file) {
if(!ScmSyncConfigurationPlugin.getInstance().isIncludeUserConfig()){
return false;
} else {
return super.isSaveableApplicable(saveable, file);
}
}

@Override
public boolean isCurrentUrlApplicable(String url) {
if(!ScmSyncConfigurationPlugin.getInstance().isIncludeUserConfig()){
return false;
} else {
return super.isCurrentUrlApplicable(url);
}
}

@Override
public CommitMessageFactory getCommitMessageFactory(){
return new CommitMessageFactory(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public void marshal(Object source, HierarchicalStreamWriter writer,
writer.endNode();
}

writer.startNode(AbstractMigrator.SCM_INCLUDE_USERCONFIG);
writer.setValue(Boolean.toString(plugin.isIncludeUserConfig()));
writer.endNode();

if(plugin.getManualSynchronizationIncludes() != null){
writer.startNode(AbstractMigrator.SCM_MANUAL_INCLUDES);
for(String include : plugin.getManualSynchronizationIncludes()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class AbstractMigrator<TFROM extends ScmSyncConfigurationPOJO, T
public static final String SCM_NO_USER_COMMIT_MESSAGE = "noUserCommitMessage";
public static final String SCM_DISPLAY_STATUS = "displayStatus";
public static final String SCM_COMMIT_MESSAGE_PATTERN = "commitMessagePattern";
public static final String SCM_INCLUDE_USERCONFIG = "includeUserConfig";
public static final String SCM_MANUAL_INCLUDES = "manualSynchronizationIncludes";

private static final Logger LOGGER = Logger.getLogger(AbstractMigrator.class.getName());
Expand All @@ -41,6 +42,7 @@ public TTO readScmSyncConfigurationPOJO(
boolean noUserCommitMessage = false;
boolean displayStatus = true;
String commitMessagePattern = "[message]";
boolean includeUserConfig = true;
List<String> manualIncludes = null;

while(reader.hasMoreChildren()){
Expand All @@ -56,6 +58,8 @@ public TTO readScmSyncConfigurationPOJO(
scmContent = reader.getValue();
} else if(SCM_COMMIT_MESSAGE_PATTERN.equals(reader.getNodeName())){
commitMessagePattern = reader.getValue();
} else if(SCM_INCLUDE_USERCONFIG.equals(reader.getNodeName())){
includeUserConfig = Boolean.parseBoolean(reader.getValue());
} else if(SCM_MANUAL_INCLUDES.equals(reader.getNodeName())){
manualIncludes = new ArrayList<String>();
while(reader.hasMoreChildren()){
Expand All @@ -71,14 +75,15 @@ public TTO readScmSyncConfigurationPOJO(
}
reader.moveUp();
}

pojo.setScm(createSCMFrom(scmClassAttribute, scmContent));
pojo.setScmRepositoryUrl(scmRepositoryUrl);
pojo.setNoUserCommitMessage(noUserCommitMessage);
pojo.setDisplayStatus(displayStatus);
pojo.setCommitMessagePattern(commitMessagePattern);
pojo.setManualSynchronizationIncludes(manualIncludes);

pojo.setIncludeUserConfig(includeUserConfig);

return pojo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class DefaultSSCPOJO implements ScmSyncConfigurationPOJO {
private boolean noUserCommitMessage;
private boolean displayStatus;
private String commitMessagePattern;
private boolean includeUserConfig;
private List<String> manualSynchronizationIncludes;

public String getScmRepositoryUrl() {
Expand Down Expand Up @@ -46,6 +47,14 @@ public void setCommitMessagePattern(String commitMessagePattern) {
this.commitMessagePattern = commitMessagePattern;
}

public boolean isIncludeUserConfig() {
return includeUserConfig;
}

public void setIncludeUserConfig(boolean includeUserConfig) {
this.includeUserConfig = includeUserConfig;
}

public void setManualSynchronizationIncludes(List<String> _manualSynchronizationIncludes){
this.manualSynchronizationIncludes = _manualSynchronizationIncludes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ public interface ScmSyncConfigurationPOJO {
public void setCommitMessagePattern(String commitMessagePattern);
public List<String> getManualSynchronizationIncludes();
public void setManualSynchronizationIncludes(List<String> manualSynchronizationIncludes);
public boolean isIncludeUserConfig();
public void setIncludeUserConfig(boolean includeUserConfig);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@
<f:textbox name="commitMessagePattern" value="${it.commitMessagePattern}" />
</f:entry>

<f:entry title="${%Include user config}">
<j:choose>
<j:when test="${it.includeUserConfig}">
<f:checkbox name="includeUserConfig" checked="${it.includeUserConfig}" value="true" />
</j:when>
<j:otherwise>
<f:checkbox name="includeUserConfig" value="true" />
</j:otherwise>
</j:choose>
</f:entry>
<!--
Help url for manualSynchronizationIncludes field is a jelly script and not a html file
because we need default includes list to be displayed in it !
Expand Down