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

jelly files fix for new version of Jenkins after table to div #81

Open
wants to merge 7 commits 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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>

<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void onLocationChanged(Item item, String oldFullName, String newFullName)
// Figure out where the item previously might have been.
File oldDir = null;
Jenkins jenkins = Jenkins.getInstance();
int i = oldFullName.lastIndexOf('/');
int i = oldFullName.replace('\\', '/').lastIndexOf('/');
String oldSimpleName = i > 0 ? oldFullName.substring(i+1) : oldFullName;
Object oldParent = i > 0 ? jenkins.getItemByFullName(oldFullName.substring(0, i)) : jenkins;
Object newParent = item.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@ public List<File> collect(File directory) {
if (pathRelativeToRoot == null) {
throw new IllegalArgumentException(directory.getAbsolutePath() + " is not under " + jenkinsRoot.getAbsolutePath());
}
pathRelativeToRoot = pathRelativeToRoot.replace('\\', '/');
final String restrictedPath = pathRelativeToRoot.endsWith("/") ? pathRelativeToRoot : pathRelativeToRoot + '/';
selector = new FileSelector() {
@Override
public boolean isSelected(File basedir, String pathRelativeToBasedir, File file) throws BuildException {
// Only include directories leading to our directory (parent directories and the directory itself) and then whatever is below.
pathRelativeToBasedir = pathRelativeToBasedir.replace('\\', '/');
if (file.isDirectory()) {
pathRelativeToBasedir = pathRelativeToBasedir.endsWith("/") ? pathRelativeToBasedir : pathRelativeToBasedir + '/';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public boolean matches(Saveable saveable, File file) {
@Override
public boolean matches(Saveable saveable, String pathRelativeToRoot, boolean isDirectory) {
if ((saveable instanceof AbstractItem) && pathRelativeToRoot != null) {
pathRelativeToRoot = pathRelativeToRoot.replace('\\', '/');
if (isDirectory) {
if (!pathRelativeToRoot.endsWith("/")) {
pathRelativeToRoot += '/';
Expand Down Expand Up @@ -80,6 +81,7 @@ public boolean isSelected(File basedir, String pathRelativeToBaseDir, File file)
if (originalSelector != null && !originalSelector.isSelected(basedir, pathRelativeToBaseDir, file)) {
return false;
}
pathRelativeToBaseDir = pathRelativeToBaseDir.replace('\\', '/');
if (CONFIGS_TO_MATCH.matcher(pathRelativeToBaseDir).matches()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public boolean matches(Saveable saveable, File file) {
public boolean matches(Saveable saveable, String pathRelativeToRoot, boolean isDirectory) {
if (pathRelativeToRoot != null) {
// Guard our own SCM workspace and the war directory. User-defined includes might inadvertently include those if they start with * or **!
pathRelativeToRoot = pathRelativeToRoot.replace('\\', '/');
if (pathRelativeToRoot.equals(SCM_WORKING_DIRECTORY) || pathRelativeToRoot.startsWith(SCM_WORKING_DIRECTORY + '/')) {
return false;
} else if (pathRelativeToRoot.equals(WAR_DIRECTORY) || pathRelativeToRoot.startsWith(WAR_DIRECTORY + '/')) {
Expand All @@ -47,7 +48,7 @@ public boolean matches(Saveable saveable, String pathRelativeToRoot, boolean isD
return true;
} else if (isDirectory) {
// pathRelativeFromRoot is be a directory, and the pattern end in a file name. In this case, we must claim a match.
int i = pattern.lastIndexOf('/');
int i = pattern.replace('\\', '/').lastIndexOf('/');
if (directoryName == null) {
directoryName = pathRelativeToRoot.endsWith("/") ? pathRelativeToRoot.substring(0, pathRelativeToRoot.length() - 1) : pathRelativeToRoot;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,44 @@
package hudson.plugins.scm_sync_configuration.utils;

import com.google.common.io.ByteStreams;
import com.google.common.io.Files;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;

/**
* @author fcamblor
* Utility class allowing to provide easy access to jenkins files checksums
*/
public class Checksums {

private static final int BUF_SIZE = 0x1000; // 4K

public static boolean fileAndByteArrayContentAreEqual(File file, byte[] content) throws IOException {
if(!file.exists()){
return content == null || content.length == 0;
}

long fileChecksum;
CheckedInputStream in = null;
try {
in = new CheckedInputStream(new FileInputStream(file), createChecksum());
byte[] buffer = new byte[BUF_SIZE];
while (in.read(buffer, 0, buffer.length) >= 0) {
// keep updating checksum
}
fileChecksum = in.getChecksum().getValue();
} finally {
if (in != null) {
in.close();
}
}

Checksum checksum = createChecksum();
long fileChecksum = Files.getChecksum(file, checksum);
long contentChecksum = ByteStreams.getChecksum(ByteStreams.newInputStreamSupplier(content), checksum);
checksum.update(content, 0, content.length);
long contentChecksum = checksum.getValue();

return fileChecksum == contentChecksum;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?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" xmlns:p="/lib/hudson/project">

<f:section title="${%SCM Sync configuration}">
<f:entry title="${%SCM}" help="${rootUrl}/plugin/scm-sync-configuration/help/scm-help.html">
<table width="100%">
<div>
<j:forEach var="scm" items="${it.scms}">
<f:radioBlock name="scm" value="${scm.id}" title="${scm.title}" checked="${it.isScmSelected(scm)}">
<st:include from="${it}" page="scms/${scm.configPage}" />
</f:radioBlock>
</j:forEach>
</table>
</div>
</f:entry>
<f:entry title="${%Never bother me with commit messages}" help="${rootUrl}/plugin/scm-sync-configuration/help/noUserCommitMessage-help.html">
<j:choose>
Expand Down Expand Up @@ -40,12 +41,12 @@
-->
<f:entry title="${%Manual synchronization includes}" help="${rootUrl}/plugin/scm-sync-configuration/manualIncludesHelp">
<f:repeatable var="include" items="${it.manualSynchronizationIncludes}" add="${%Add new include}" minimum="0">
<table width="100%">
<div>
<f:entry title="${%Include}">
<f:textbox name="manualSynchronizationIncludes" value="${include}" />
<f:repeatableDeleteButton value="${%Delete include}"/>
</f:entry>
</table>
</div>
</f:repeatable>
</f:entry>
<f:entry title="${%Reload config from SCM}" help="${rootUrl}/plugin/scm-sync-configuration/help/reloadScmConfig-help.html">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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" xmlns:i="jelly:fmt">
<div>
${%List of ant-like includes allowing to specify additional files to synchronize with the repository}.<br/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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" xmlns:p="/lib/hudson/project">

<f:entry title="${%Repository URL}" help="${rootURL}/plugin/scm-sync-configuration/helpForRepositoryUrl?scm=${scm.id}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<l:ajax>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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" xmlns:p="/lib/hudson/project">

</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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" xmlns:p="/lib/hudson/project">

<!-- TODO: fix help url... -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?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" xmlns:i="jelly:fmt">
<l:ajax>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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" xmlns:i="jelly:fmt">

<j:set var="url" value="${request.requestURL}" />
Expand Down Expand Up @@ -68,13 +69,13 @@
}
</script>

<table width="100%">
<div>
<tr><td id="footer">
<span style="color:gray">SCM Sync status : <img src="${imagesURL}/16x16/${icon}.png" alt="" height="16" width="16"/>
${msg}
<j:out value="${msg}"/>
</span>
</td></tr>
</table>
</div>
</j:if>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?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">

<l:layout>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/index.jelly
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?jelly escape-by-default='true'?>
<div>
This plugin allows you to synchronize your hudson configuration files with an SCM, allowing you to specify a commit message every time a config file is modified.
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void initRepo(File path) throws Exception {
}

public String createUrl(String url) {
return "scm:git:" + url;
return "scm:git:file:///" + url.replace('\\', '/');
}

public Class<? extends SCM> getClazz() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void initRepo(File path) throws Exception {
}

public String createUrl(String url) {
return "scm:svn:file://" + url;
return "scm:svn:file:///" + url.replace('\\', '/');
}

public Class<? extends SCM> getClazz() {
Expand Down