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

Enabling saving configuration to branch #23

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
83 changes: 41 additions & 42 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.409</version>
<relativePath>../pom.xml</relativePath>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.580.1</version>
<relativePath/>
</parent>

<artifactId>scm-sync-configuration</artifactId>
<name>SCM Sync Configuration Plugin</name>
<version>0.0.8.1-SNAPSHOT</version>
<version>0.0.8.2hybris</version>
<packaging>hpi</packaging>
<url>http://wiki.jenkins-ci.org/display/JENKINS/SCM+Sync+configuration+plugin</url>
<description>SCM Sync Configuration Jenkins plugin is aimed at 2 main features : First, keep sync'ed your config.xml (and other ressources) jenkins files with a SCM repository (backup), Secondly, track changes (and author) made on every file with commit messages.</description>
Expand All @@ -28,6 +28,7 @@
</developers>

<properties>
<sisuInjectVersion>0.3.0.M1</sisuInjectVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<powermock.version>1.4.8</powermock.version>
Expand Down Expand Up @@ -65,29 +66,35 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Needed to avoid some permgen space errors during test execution ... -->
<argLine>-XX:MaxPermSize=128m</argLine>
<argLine>-Xmx2048m -Xms512m -XX:MaxPermSize=512m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
<version>1.3.8</version>
<executions>
<execution>
<id>merge</id>
<configuration>
<descriptors>
<descriptor>src/main/resources/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
<phase>generate-resources</phase>
<goals>
<goal>merge-descriptors</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-maven-plugin</artifactId>
<executions>
<execution>
<id>merge</id>
<configuration>
<descriptors>
<descriptor>src/main/resources/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
<phase>generate-resources</phase>
<goals>
<goal>merge-descriptors</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -97,7 +104,7 @@
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>${project.parent.version}</version>
<version>2.8</version>
<exclusions>
<exclusion>
<!-- Conflicts with org.jenkins-ci.plugins:subversion dependency -->
Expand Down Expand Up @@ -125,23 +132,15 @@
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-manager-plexus</artifactId>
<version>1.9.1</version>
<!--
<exclusions>
<exclusion>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-container-default</artifactId>
</exclusion>
</exclusions>
-->
</dependency>
<!--
<dependency>
<groupId>org.sonatype.sisu</groupId>
<artifactId>sisu-inject-plexus</artifactId>
<version>1.4.3.1</version>
<version>1.9.2</version>
<exclusions>
<exclusion>
<artifactId>plexus-container-default</artifactId>
<groupId>org.codehaus.plexus</groupId>
</exclusion>
</exclusions>

</dependency>
-->

<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand Down Expand Up @@ -190,11 +189,11 @@
<type>jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>12.0.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.sisu</groupId>
<artifactId>org.eclipse.sisu.plexus</artifactId>
<version>${sisuInjectVersion}</version>
</dependency>
</dependencies>

<scm>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package hudson.plugins.scm_sync_configuration;

import hudson.model.Hudson;

import jenkins.model.Jenkins;

import java.io.File;

public class JenkinsFilesHelper {

public static String buildPathRelativeToHudsonRoot(File file){
File hudsonRoot = Hudson.getInstance().getRootDir();
File hudsonRoot = Jenkins.getInstance().getRootDir();
if(!file.getAbsolutePath().startsWith(hudsonRoot.getAbsolutePath())){
throw new IllegalArgumentException("Err ! File ["+file.getAbsolutePath()+"] seems not to reside in ["+hudsonRoot.getAbsolutePath()+"] !");
}
Expand All @@ -16,7 +17,7 @@ public static String buildPathRelativeToHudsonRoot(File file){
}

public static File buildFileFromPathRelativeToHudsonRoot(String pathRelativeToHudsonRoot){
File hudsonRoot = Hudson.getInstance().getRootDir();
File hudsonRoot = Jenkins.getInstance().getRootDir();
return new File(hudsonRoot.getAbsolutePath()+File.separator+pathRelativeToHudsonRoot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import hudson.plugins.scm_sync_configuration.model.ScmContext;
import hudson.plugins.scm_sync_configuration.scms.SCM;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFile;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.*;
import org.apache.maven.scm.command.add.AddScmResult;
import org.apache.maven.scm.command.checkin.CheckInScmResult;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
Expand Down Expand Up @@ -35,6 +33,7 @@ public class SCMManipulator {
private ScmManager scmManager;
private ScmRepository scmRepository = null;
private String scmSpecificFilename = null;
private String scmGitBranch;

public SCMManipulator(ScmManager _scmManager) {
this.scmManager = _scmManager;
Expand Down Expand Up @@ -65,7 +64,8 @@ public boolean scmConfigurationSettledUp(ScmContext scmContext, boolean resetScm
return false;
}
}


scmGitBranch = scmContext.getScmGitBranch();
return expectScmRepositoryInitiated();
}

Expand All @@ -88,7 +88,12 @@ public boolean checkout(File checkoutDirectory){
// Checkouting sources
LOGGER.fine("Checkouting SCM files into ["+checkoutDirectory.getAbsolutePath()+"] ...");
try {
CheckOutScmResult result = scmManager.checkOut(this.scmRepository, new ScmFileSet(checkoutDirectory));
ScmBranch scmBranch = null;
if (scmGitBranch != null && scmGitBranch.length() > 0){
scmBranch = new ScmBranch(scmGitBranch);
}
CheckOutScmResult result = scmManager.checkOut(this.scmRepository, new ScmFileSet(checkoutDirectory),scmBranch);

if(!result.isSuccess()){
LOGGER.severe("[checkout] Error during checkout : "+result.getProviderMessage()+" || "+result.getCommandOutput());
return checkoutOk;
Expand Down Expand Up @@ -262,5 +267,4 @@ public boolean checkinFiles(File scmRoot, String commitMessage){
public String getScmSpecificFilename() {
return scmSpecificFilename;
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package hudson.plugins.scm_sync_configuration;

import com.google.common.io.Files;
import hudson.model.Hudson;
import hudson.model.User;
import hudson.plugins.scm_sync_configuration.exceptions.LoggableException;
import hudson.plugins.scm_sync_configuration.model.*;
import hudson.plugins.scm_sync_configuration.strategies.ScmSyncStrategy;
import hudson.plugins.scm_sync_configuration.utils.Checksums;
import hudson.security.Permission;
import hudson.util.DaemonThreadFactory;
import jenkins.model.Jenkins;
import org.apache.commons.io.FileUtils;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.manager.ScmManager;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void init(ScmContext scmContext) throws ComponentLookupException, PlexusC
this.scmManipulator = new SCMManipulator(scmManager);
this.checkoutScmDirectory = new File(getCheckoutScmDirectoryAbsolutePath());
this.checkoutSucceeded = false;
initializeRepository(scmContext, false);
initializeRepository(scmContext, true);
}

public void initializeRepository(ScmContext scmContext, boolean deleteCheckoutScmDir){
Expand Down Expand Up @@ -304,15 +304,37 @@ public boolean scmCheckoutDirectorySettledUp(ScmContext scmContext){
}

public List<File> reloadAllFilesFromScm() throws IOException, ScmException {
//removeSourceJobsDuringReload();
this.scmManipulator.update(new File(getCheckoutScmDirectoryAbsolutePath()));
return syncDirectories(new File(getCheckoutScmDirectoryAbsolutePath() + File.separator), "");
}

/**
*
* @return
* @throws IOException
*/
public List<File> removeSourceJobsDuringReload() throws IOException {
List<File> l = new ArrayList<File>();
File jobsFolder = new File(Jenkins.getInstance().getRootDir().toString()+ "/jobs");
LOGGER.info("Configuration reload - jobs removal. Cleaning up folder:"+jobsFolder);

for(File f : jobsFolder.listFiles()){
l.add(f);
if (f.isDirectory()) {
FileUtils.deleteDirectory(f);
} else {
FileUtils.forceDelete(f);
}
}
return l;
}

private List<File> syncDirectories(File from, String relative) throws IOException {
List<File> l = new ArrayList<File>();
for(File f : from.listFiles()) {
String newRelative = relative + File.separator + f.getName();
File jenkinsFile = new File(Hudson.getInstance().getRootDir() + newRelative);
File jenkinsFile = new File(Jenkins.getInstance().getRootDir() + newRelative);
if (f.getName().equals(scmManipulator.getScmSpecificFilename())) {
// nothing to do
}
Expand Down Expand Up @@ -351,20 +373,20 @@ private void signal(String operation, boolean result) {
}

public static String getCheckoutScmDirectoryAbsolutePath(){
return Hudson.getInstance().getRootDir().getAbsolutePath()+WORKING_DIRECTORY_PATH+CHECKOUT_SCM_DIRECTORY;
return Jenkins.getInstance().getRootDir().getAbsolutePath()+WORKING_DIRECTORY_PATH+CHECKOUT_SCM_DIRECTORY;
}

public void purgeFailLogs() {
Hudson.getInstance().checkPermission(purgeFailLogPermission());
Jenkins.getInstance().checkPermission(purgeFailLogPermission());
scmSyncConfigurationStatusManager.purgeFailLogs();
}

public boolean canCurrentUserPurgeFailLogs() {
return Hudson.getInstance().hasPermission(purgeFailLogPermission());
return Jenkins.getInstance().hasPermission(purgeFailLogPermission());
}

private static Permission purgeFailLogPermission(){
// Only administrators should be able to purge logs
return Hudson.ADMINISTER;
return Jenkins.ADMINISTER;
}
}
Loading