Skip to content

Commit

Permalink
[JENKINS-15098] - Refactoring
Browse files Browse the repository at this point in the history
Moved base class to another package, modified visibility and javadoc.

Related issues: https://issues.jenkins-ci.org/browse/JENKINS-15098

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
  • Loading branch information
oleg-nenashev committed Mar 28, 2014
1 parent dc5e7a6 commit 9e45adf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 2 additions & 4 deletions src/main/java/hudson/scm/SubversionSCM.java
Expand Up @@ -202,11 +202,9 @@
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import com.thoughtworks.xstream.XStream;
import com.trilead.ssh2.DebugLogger;
import com.trilead.ssh2.SCPClient;
import com.trilead.ssh2.crypto.Base64;
import hudson.scm.subversion.ExternalsFileManager;

/**
* Subversion SCM.
Expand Down Expand Up @@ -556,7 +554,7 @@ private List<External> getExternals(AbstractProject context) throws IOException
}

if (projectExternals == null) {
projectExternals = ExternalsFileManager.parseExternalsFile(context);
projectExternals = SvnExternalsFileManager.parseExternalsFile(context);

synchronized (projectExternalsCache) {
if (!projectExternalsCache.containsKey(context)) {
Expand Down Expand Up @@ -866,7 +864,7 @@ public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspa
}

// write out the externals info
ExternalsFileManager.writeExternalsFile(build.getProject(), externals);
SvnExternalsFileManager.writeExternalsFile(build.getProject(), externals);
Map<AbstractProject, List<External>> projectExternalsCache = getProjectExternalsCache();
synchronized (projectExternalsCache) {
projectExternalsCache.put(build.getProject(), externals);
Expand Down
Expand Up @@ -25,12 +25,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.scm.subversion;
package hudson.scm;

import com.thoughtworks.xstream.XStream;
import hudson.XmlFile;
import hudson.model.AbstractProject;
import hudson.scm.SubversionSCM;
import hudson.util.XStream2;
import java.io.File;
import java.io.IOException;
Expand All @@ -42,12 +41,13 @@
/**
* Implements local file storage of externals information.
* Most of functionality has been copied from {@link SubversionSCM}.
* The class also prevents conflicts between
* The class also prevents conflicts between read/write operations using
* {@link SVN_EXTERNALS_FILE}.
* @author Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
* @since TODO
*/
public class ExternalsFileManager {

//TODO: This class should also handle MultipleSCMs (JENKINS-20450)
class SvnExternalsFileManager {
private static final String SVN_EXTERNALS_FILE = "svnexternals.txt";
private static final XStream XSTREAM = new XStream2();
private static Map<AbstractProject, CacheItem> projectExternalsCache;
Expand All @@ -58,7 +58,7 @@ public class ExternalsFileManager {
/**
* Provides a lock item for the project.
* @param project Project to be used
* @return CacheItem (will be created on-demand)
* @return A lock object (will be created on-demand)
*/
private static synchronized CacheItem getFileLockItem(AbstractProject project) {
if (projectExternalsCache == null) {
Expand Down Expand Up @@ -90,10 +90,10 @@ private static File getExternalsFile(AbstractProject project) {
*
* @return immutable list. Can be empty but never null.
*/
/*package*/ @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
public static List<SubversionSCM.External> parseExternalsFile(AbstractProject project) throws IOException {
File file = getExternalsFile(project);
CacheItem lock = getFileLockItem(project);
Object lock = getFileLockItem(project);

synchronized(lock) {
if (file.exists()) {
Expand All @@ -108,8 +108,14 @@ public static List<SubversionSCM.External> parseExternalsFile(AbstractProject pr
}
}

/**
* Writes a list of externals to the file.
* @param project Project, which uses provided externals.
* @param externals List of externals
* @throws IOException File write error
*/
public static void writeExternalsFile(AbstractProject project, List<SubversionSCM.External> externals) throws IOException {
CacheItem lock = getFileLockItem(project);
Object lock = getFileLockItem(project);

synchronized (lock) {
new XmlFile(XSTREAM, getExternalsFile(project)).write(externals);
Expand All @@ -121,6 +127,6 @@ public static void writeExternalsFile(AbstractProject project, List<SubversionSC
* In the current state, class does not contain any specific data;
*/
private static final class CacheItem {

// Yes, the file is empty
}
}

0 comments on commit 9e45adf

Please sign in to comment.