Re: CVS update: /hudson/www/, /hudson/hudson/main/core/src/main/java/hudson/model/, /hudson/hudson/main/core/src/main/java/hudson/scm/, /hudson/hudson/...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: CVS update: /hudson/www/, /hudson/hudson/main/core/src/main/java/hudson/model/, /hudson/hudson/main/core/src/main/java/hudson/scm/, /hudson/hudson/...

Kohsuke Kawaguchi
Administrator
Thanks for making this change. I made a minor tweak and hidden the
disabled variable in the makeDisabled() method, as the state change
needs to be persisted by the save() call.

My rule of thumb for making a field public is (1) whether a field is
final, and if so it can be public, (2) whether an update to a field
would require other side effects, and if so it cannot be final.


[hidden email] wrote:

> User: jbq    
> Date: 2007-09-06 15:56:11+0000
> Modified:
>    hudson/www/changelog.html
>    hudson/hudson/main/core/src/main/java/hudson/model/AbstractProject.java
>    hudson/hudson/main/core/src/main/java/hudson/scm/SubversionSCM.java
>    hudson/hudson/extras/tester/src/test/java/hudson/model/HudsonTestCase.java
>    hudson/hudson/extras/tester/src/test/java/hudson/model/SubversionSCMTest.java
>
> Log:
>  Issue number:  763
>  
>  Gracefully handle project deleted in SVN.  Had to make AbstractProject.disabled
>  field public, but we might want to find a more elegant solution for this.  I've
>  seen other fields public in Hudson, so I guess it's OK, but I'd rather put some
>  more setters everywhere...
>  
>
> File Changes:
>
> Directory: /hudson/www/
> =======================
>
> File [changed]: changelog.html
> Url: https://hudson.dev.java.net/source/browse/hudson/www/changelog.html?r1=1.855&r2=1.856
> Delta lines:  +3 -0
> -------------------
> --- changelog.html 2007-09-06 04:33:55+0000 1.855
> +++ changelog.html 2007-09-06 15:56:08+0000 1.856
> @@ -21,6 +21,9 @@
>    <li class=bug>
>      Slave thread dump was not working in JDK5.
>      (<a href="https://hudson.dev.java.net/issues/show_bug.cgi?id=792">issue 792</a>)
> +  <li class="rfe">
> +    Gracefully handle project deleted in SVN (<a href="https://hudson.dev.java.net/issues/show_bug.cgi?id=763">issue 763</a>)
> +  </li>
>  </ul>
>  </div><!--=END=-->
>  <a name=v1.136><h3>What's new in 1.136</h3></a>
>
> Directory: /hudson/hudson/main/core/src/main/java/hudson/model/
> ===============================================================
>
> File [changed]: AbstractProject.java
> Url: https://hudson.dev.java.net/source/browse/hudson/hudson/main/core/src/main/java/hudson/model/AbstractProject.java?r1=1.54&r2=1.55
> Delta lines:  +13 -11
> ---------------------
> --- AbstractProject.java 2007-08-15 04:48:43+0000 1.54
> +++ AbstractProject.java 2007-09-06 15:56:09+0000 1.55
> @@ -3,44 +3,46 @@
>  import hudson.FeedAdapter;
>  import hudson.FilePath;
>  import hudson.Launcher;
> -import hudson.search.SearchIndexBuilder;
> -import hudson.tasks.BuildTrigger;
>  import hudson.maven.MavenModule;
>  import hudson.model.Descriptor.FormException;
>  import hudson.model.Fingerprint.RangeSet;
>  import hudson.model.RunMap.Constructor;
>  import hudson.scm.ChangeLogSet;
> -import hudson.scm.ChangeLogSet.Entry;
>  import hudson.scm.NullSCM;
>  import hudson.scm.SCM;
>  import hudson.scm.SCMS;
> +import hudson.scm.ChangeLogSet.Entry;
> +import hudson.search.SearchIndexBuilder;
> +import hudson.tasks.BuildTrigger;
>  import hudson.triggers.Trigger;
>  import hudson.triggers.TriggerDescriptor;
>  import hudson.triggers.Triggers;
>  import hudson.util.EditDistance;
> -import org.kohsuke.stapler.StaplerRequest;
> -import org.kohsuke.stapler.StaplerResponse;
> -import org.kohsuke.stapler.export.Exported;
>  
> -import javax.servlet.ServletException;
>  import java.io.File;
>  import java.io.IOException;
>  import java.lang.reflect.InvocationTargetException;
>  import java.util.ArrayList;
>  import java.util.Calendar;
>  import java.util.Collection;
> +import java.util.Collections;
>  import java.util.Comparator;
> +import java.util.HashSet;
>  import java.util.List;
>  import java.util.Map;
> +import java.util.Set;
>  import java.util.SortedMap;
>  import java.util.TreeMap;
>  import java.util.Vector;
> -import java.util.Set;
> -import java.util.Collections;
> -import java.util.HashSet;
>  import java.util.logging.Level;
>  import java.util.logging.Logger;
>  
> +import javax.servlet.ServletException;
> +
> +import org.kohsuke.stapler.StaplerRequest;
> +import org.kohsuke.stapler.StaplerResponse;
> +import org.kohsuke.stapler.export.Exported;
> +
>  /**
>   * Base implementation of {@link Job}s that build software.
>   *
> @@ -92,7 +94,7 @@
>      /**
>       * True to suspend new builds.
>       */
> -    protected boolean disabled;
> +    public boolean disabled;
>  
>      /**
>       * Identifies {@link JDK} to be used.
>
> Directory: /hudson/hudson/main/core/src/main/java/hudson/scm/
> =============================================================
>
> File [changed]: SubversionSCM.java
> Url: https://hudson.dev.java.net/source/browse/hudson/hudson/main/core/src/main/java/hudson/scm/SubversionSCM.java?r1=1.97&r2=1.98
> Delta lines:  +37 -10
> ---------------------
> --- SubversionSCM.java 2007-09-06 14:46:03+0000 1.97
> +++ SubversionSCM.java 2007-09-06 15:56:09+0000 1.98
> @@ -292,7 +292,7 @@
>      }
>  
>      public boolean checkout(AbstractBuild build, Launcher launcher, FilePath workspace, final BuildListener listener, File changelogFile) throws IOException, InterruptedException {
> -        List<String> externals = checkout(build.getTimestamp().getTime(),workspace,listener);
> +        List<String> externals = checkout(build,workspace,listener);
>  
>          if(externals==null)
>              return false;
> @@ -333,9 +333,14 @@
>       *      if the operation failed. Otherwise the set of local workspace paths
>       *      (relative to the workspace root) that has loaded due to svn:external.
>       */
> -    private List<String> checkout(Date timestamp, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
> -        boolean isUpdatable = useUpdate && workspace.act(new IsUpdatableTask(this, listener));
> -        return workspace.act(new CheckOutTask(this, timestamp, isUpdatable, listener));
> +    private List<String> checkout(AbstractBuild build, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
> +        if (projectDeleted(listener)) {
> +            // Disable this project, see issue #763
> +            build.getProject().disabled = true;
> +            return null;
> +        }
> +        Boolean isUpdatable = useUpdate && workspace.act(new IsUpdatableTask(this, listener));
> +        return workspace.act(new CheckOutTask(this, build.getTimestamp().getTime(), isUpdatable, listener));
>      }
>  
>      private static class CheckOutTask implements FileCallable<List<String>> {
> @@ -487,7 +492,7 @@
>       * @param remoteUrl
>       *      The target to run "svn info".
>       */
> -    private SVNInfo parseSvnInfo(SVNURL remoteUrl, ISVNAuthenticationProvider authProvider) throws SVNException {
> +    private static SVNInfo parseSvnInfo(SVNURL remoteUrl, ISVNAuthenticationProvider authProvider) throws SVNException {
>          SVNWCClient svnWc = createSvnClientManager(authProvider).getWCClient();
>          return svnWc.doInfo(remoteUrl, SVNRevision.HEAD, SVNRevision.HEAD);
>      }
> @@ -580,7 +585,9 @@
>                  }
>  
>                  try {
> -                    SvnInfo svnInfo = new SvnInfo(parseSvnInfo(module, authProvider));
> +                    SVNInfo svnkitInfo = parseSvnInfo(module, authProvider);
> +                    SvnInfo svnInfo = new SvnInfo(svnkitInfo);
> +    
>                      if(!svnInfo.url.equals(url)) {
>                          listener.getLogger().println("Checking out a fresh workspace because the workspace is not "+url);
>                          return false;
> @@ -596,6 +603,26 @@
>          private static final long serialVersionUID = 1L;
>      }
>  
> +    /**
> +     * Returns true if the project does not exist in SVN anymore
> +     */
> +    public boolean projectDeleted(TaskListener listener) {
> +        for (ModuleLocation l : locations) {
> +            String url = l.remote;
> +            try {
> +                ISVNAuthenticationProvider authProvider = getDescriptor().createAuthenticationProvider();
> +                // This will throw an SVNException if the remote path does not exist anymore
> +                parseSvnInfo(SVNURL.parseURIDecoded(url), authProvider);
> +            } catch (SVNException e) {
> +                // issue #763 Gracefully handle project deleted in SVN
> +                listener.getLogger().println("Project does not exist anymore in SVN: " + url);
> +                e.printStackTrace(listener.error(e.getMessage()));
> +                return true;
> +            }
> +        }
> +        return false;
> +    }
> +
>      public boolean pollChanges(AbstractProject project, Launcher launcher, FilePath workspace, TaskListener listener) throws IOException, InterruptedException {
>          AbstractBuild lastBuild = (AbstractBuild) project.getLastBuild();
>          if(lastBuild==null) {
>
> Directory: /hudson/hudson/extras/tester/src/test/java/hudson/model/
> ===================================================================
>
> File [changed]: HudsonTestCase.java
> Url: https://hudson.dev.java.net/source/browse/hudson/hudson/extras/tester/src/test/java/hudson/model/HudsonTestCase.java?r1=1.1&r2=1.2
> Delta lines:  +3 -2
> -------------------
> --- HudsonTestCase.java 2007-09-06 14:46:21+0000 1.1
> +++ HudsonTestCase.java 2007-09-06 15:56:09+0000 1.2
> @@ -76,13 +76,14 @@
>       *
>       * @param project
>       *            the project to build
> -     * @return build result
> +     * @return build result, or null if project is disabled
>       * @throws Exception
>       */
>      protected Result build(Project project) {
>          try {
>              int numbuilds = project.getBuilds().size() + 1;
> -            project.scheduleBuild();
> +            if (! project.scheduleBuild())
> +                return null;
>              while (project.getBuilds().size() != numbuilds || project.getBuildByNumber(numbuilds).isBuilding()) {
>                  Thread.sleep(100);
>              }
>
> File [changed]: SubversionSCMTest.java
> Url: https://hudson.dev.java.net/source/browse/hudson/hudson/extras/tester/src/test/java/hudson/model/SubversionSCMTest.java?r1=1.1&r2=1.2
> Delta lines:  +4 -0
> -------------------
> --- SubversionSCMTest.java 2007-09-06 14:46:21+0000 1.1
> +++ SubversionSCMTest.java 2007-09-06 15:56:09+0000 1.2
> @@ -41,7 +41,11 @@
>          exec(new String[] { "svn", "up", projectDir.getPath() });
>          exec(new String[] { "svn", "rm", projectDir.getPath() });
>          exec(new String[] { "svn", "commit", "-m", "deleted", projectDir.getPath() });
> +
>          result = build(project);
>          assertFailure(result);
> +
> +        result = build(project);
> +        assertNull("Project should be disabled", result);
>      }
>  }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

--
Kohsuke Kawaguchi
Sun Microsystems                   [hidden email]

smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Gracefully handle project deleted in SVN (Was: CVS update: /hudson/www/, /hudson/hudson/main/core/src/main/java/hudson/model/, /hudson/hudson/main/core/src/main/java/hudson/scm/, /hudson/hudson/...)

Jean-Baptiste Quenot
* Kohsuke Kawaguchi:

> Thanks for making  this change. I made a minor  tweak and hidden
> the disabled variable in the makeDisabled() method, as the state
> change needs to be persisted by the save() call.
>
> My rule  of thumb  for making  a field public  is (1)  whether a
> field  is final,  and if  so it  can be  public, (2)  whether an
> update to a field would require other side effects, and if so it
> cannot be final.

Thanks for the update.

FYI I reopened #763 because the  same happens during polling and I
only handled checkout().
--
     Jean-Baptiste Quenot
aka  John Banana   Qwerty
http://caraldi.com/jbq/

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]