geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r506873 - /geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy
Date Tue, 13 Feb 2007 05:43:15 GMT
Author: jdillon
Date: Mon Feb 12 21:43:15 2007
New Revision: 506873

URL: http://svn.apache.org/viewvc?view=rev&rev=506873
Log:
Basic library impl, backed up by svn repo

Modified:
    geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy

Modified: geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy?view=diff&rev=506873&r1=506872&r2=506873
==============================================================================
--- geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy
(original)
+++ geronimo/sandbox/build-support/libraries/system/1/groovy/gbuild/system/library/Library.groovy
Mon Feb 12 21:43:15 2007
@@ -30,6 +30,197 @@
  */
 class Library extends LogSupport
 {
-
+    private static AntBuilder ant = new gbuild.system.util.AntBuilder()
+    
+    URL sourceURL
+    
+    File baseDir
+    
+    boolean isCopy = false
+    
+    def Library(URL sourceURL, File baseDir) {
+        assert sourceURL
+        assert baseDir
+        
+        this.sourceURL = sourceURL
+        this.baseDir = baseDir
+    }
+    
+    boolean exists() {
+        return baseDir.exists()
+    }
+    
+    private chmod(File dir, String perm) {
+        assert dir
+        assert perm
+        
+        log.info "Changing '$perm' for $dir"
+        
+        //
+        // NOTE: Don't use Ant's chmod task, since it ignors dirs
+        //
+        
+        ant.exec(executable: 'chmod') {
+            arg(value: '-R')
+            arg(value: perm)
+            arg(file: dir)
+        }
+    }
+    
+    def lock() {
+        chmod(baseDir, 'a-w')
+    }
+    
+    def unlock() {
+        chmod(baseDir, 'u+w')
+    }
+    
+    /**
+     * Check out the library.
+     */
+    def checkout() {
+        log.info "Checking out library from: $sourceURL"
+        
+        assert !exists()
+        
+        ant.mkdir(dir: baseDir)
+        
+        ant.exec(executable: 'svn', dir: baseDir) {
+            arg(value: 'checkout')
+            arg(value: '--non-interactive')
+            arg(value: sourceURL)
+            arg(file: baseDir)
+        }
+    }
+    
+    /**
+     * Commit changes to the library.
+     */
+    def commit(String message) {
+        assert message
+        
+        log.info "Commiting changes; message: $message"
+        
+        assert exists()
+        
+        ant.exec(executable: 'svn', dir: baseDir) {
+            arg(value: 'checkin')
+            arg(value: '--non-interactive')
+            arg(value: '--message')
+            arg(value: message)
+            arg(file: baseDir)
+        }
+    }
+    
+    /**
+     * Check if the library is the latest revision
+     */
+    boolean isLatest() {
+        log.info "Checking if library contains the latest changes"
+        
+        assert exists()
+        
+        def lastCommit = { target ->
+            assert target
+            
+            // Any does not like to replace props, so make a unique one each time
+            def propname = 'svnoutput.' + UUID.randomUUID()
+            
+            ant.exec(executable: 'svn', dir: baseDir, outputproperty: propname) {
+                arg(value: 'info')
+                arg(value: '--non-interactive')
+                arg(value: '--xml')
+                arg(value: target)
+            }
+            
+            def info = new XmlParser().parseText(ant.antProject.properties[propname])
+            return info.entry[0].commit[0]
+        }
+        
+        def rcommit = lastCommit(sourceURL)
+        def lcommit = lastCommit(baseDir)
+        
+        return rcommit.'@revision' == lcommit.'@revision'
+    }
+    
+    /**
+     * Update the library.
+     */
+    def update() {
+        log.info "Updating library"
+        
+        assert exists()
+        
+        // Update the local copy
+        ant.exec(executable: 'svn', dir: baseDir) {
+            arg(value: 'update')
+            arg(value: '--non-interactive')
+            arg(file: baseDir)
+        }
+    }
+    
+    /**
+     * Remove the library (local workspace)
+     */
+    def remove() {
+        log.info "Removing library"
+        
+        assert exists()
+        
+        //
+        // NOTE: Use native 'rm' for speed, since some libraries can be large
+        //       and Ant's mechanism can take forever
+        //
+        
+        ant.exec(executable: 'rm') {
+            arg(value: '-rf')
+            arg(file: baseDir)
+        }
+    }
+    
+    /**
+     * Make a copy of the library somewhere.
+     */
+    Library copy(File targetDir, String perms) {
+        assert targetDir
+        
+        log.info "Copying library to: $targetDir; w/perms: $perms"
+        
+        assert exists()
+        
+        // Make sure we don't clobber anything, start out with no dir
+        assert !targetDir.exists()
+        
+        ant.mkdir(dir: targetDir)
+        
+        //
+        // NOTE: Use native 'cp' for speed, since some libraries can be large
+        //       and Ant's mechanism can take forever
+        //
+        
+        ant.exec(executable: 'cp') {
+            arg(value: '-r')
+            arg(file: baseDir)
+            arg(file: targetDir)
+        }
+        
+        // If we have some perms, then set them
+        if (perms) {
+            chmod(targetDir, perms)
+        }
+        
+        // Return new library instance, which is rooted to new dir
+        def lib = new Library(sourceURL, targetDir)
+        lib.isCopy = true
+        
+        return lib
+    }
+    
+    /**
+     * Make a read-write copy of the library somewhere.
+     */
+    Library copy(File dir) {
+        return copy(dir, 'u+rw')
+    }
 }
 



Mime
View raw message