Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-16641] Improving throwns
  • Loading branch information
wolfgarnet committed Feb 5, 2013
1 parent 7015741 commit 6bddf24
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 160 deletions.
11 changes: 3 additions & 8 deletions src/main/java/net/praqma/hudson/notifier/CCUCMNotifier.java
Expand Up @@ -143,14 +143,9 @@ public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListe

if( action != null && action.getViewTag() != null ) {
/* End the view */
try {
logger.fine( "Ending view " + action.getViewTag() );
RemoteUtil.endView( build.getWorkspace(), action.getViewTag() );
} catch( CCUCMException e ) {
out.println("CCUCMException: "+ e.getMessage() );
logger.warning( e.getMessage() );
}
}
logger.fine( "Ending view " + action.getViewTag() );
RemoteUtil.endView( build.getWorkspace(), action.getViewTag() );
}

out.println( "[" + Config.nameShort + "] Post build steps done" );

Expand Down
85 changes: 27 additions & 58 deletions src/main/java/net/praqma/hudson/remoting/RemoteUtil.java
@@ -1,6 +1,7 @@
package net.praqma.hudson.remoting;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -30,78 +31,46 @@ public static void completeRemoteDeliver( FilePath workspace, BuildListener list
}
}

public static Baseline createRemoteBaseline( FilePath workspace, BuildListener listener, String baseName, Component component, File view, String username ) throws CCUCMException {
try {
return workspace.act( new CreateRemoteBaseline( baseName, component, view, username, listener ) );
} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil(createRemoteBaseline): %s", e));
throw new CCUCMException( e );
}
public static Baseline createRemoteBaseline( FilePath workspace, BuildListener listener, String baseName, Component component, File view, String username ) throws IOException, InterruptedException {
return workspace.act( new CreateRemoteBaseline( baseName, component, view, username, listener ) );
}


public static UCMEntity loadEntity( FilePath workspace, UCMEntity entity, boolean slavePolling ) throws CCUCMException {
try {
if( slavePolling ) {
return workspace.act( new LoadEntity( entity ) );
} else {
LoadEntity t = new LoadEntity( entity );
return t.invoke( null, null );
}
} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil(loadEntity): %s", e));
throw new CCUCMException( e );
}
public static UCMEntity loadEntity( FilePath workspace, UCMEntity entity, boolean slavePolling ) throws IOException, InterruptedException {
if( slavePolling ) {
return workspace.act( new LoadEntity( entity ) );
} else {
LoadEntity t = new LoadEntity( entity );
return t.invoke( null, null );
}
}

public static String getClearCaseVersion( FilePath workspace, Project project ) throws CCUCMException {
try {
return workspace.act( new GetClearCaseVersion( project ) );
} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil(getClearCaseVersion): %s", e));
throw new CCUCMException( e );
}
public static String getClearCaseVersion( FilePath workspace, Project project ) throws IOException, InterruptedException {
return workspace.act( new GetClearCaseVersion( project ) );
}

public static void endView( FilePath workspace, String viewtag ) throws CCUCMException {
try {
workspace.act( new EndView( viewtag ) );
} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil(endView): %s", e));
throw new CCUCMException( e );
}
public static void endView( FilePath workspace, String viewtag ) throws IOException, InterruptedException {
workspace.act( new EndView( viewtag ) );

}

public static List<Stream> getRelatedStreams( FilePath workspace, TaskListener listener, Stream stream, boolean pollingChildStreams, boolean slavePolling, boolean multisitePolling ) throws CCUCMException {
try {
if( slavePolling ) {
return workspace.act( new GetRelatedStreams( listener, stream, pollingChildStreams, multisitePolling ) );
} else {
GetRelatedStreams t = new GetRelatedStreams( listener, stream, pollingChildStreams, multisitePolling );
return t.invoke( null, null );
}
} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil: %s", e.getMessage()));
logger.warning(String.format("Caught exception in RemoteUtil(getRealtedStreams): %s",e));
throw new CCUCMException( e );
public static List<Stream> getRelatedStreams( FilePath workspace, TaskListener listener, Stream stream, boolean pollingChildStreams, boolean slavePolling, boolean multisitePolling ) throws IOException, InterruptedException {
if( slavePolling ) {
return workspace.act( new GetRelatedStreams( listener, stream, pollingChildStreams, multisitePolling ) );
} else {
GetRelatedStreams t = new GetRelatedStreams( listener, stream, pollingChildStreams, multisitePolling );
return t.invoke( null, null );
}
}


public static List<Baseline> getRemoteBaselinesFromStream( FilePath workspace, Component component, Stream stream, Project.PromotionLevel plevel, boolean slavePolling, boolean multisitePolling, Date date ) throws CCUCMException {
public static List<Baseline> getRemoteBaselinesFromStream( FilePath workspace, Component component, Stream stream, Project.PromotionLevel plevel, boolean slavePolling, boolean multisitePolling, Date date ) throws IOException, InterruptedException {

try {
if( slavePolling ) {
return workspace.act( new GetRemoteBaselineFromStream( component, stream, plevel, multisitePolling, date ) );
} else {
GetRemoteBaselineFromStream t = new GetRemoteBaselineFromStream( component, stream, plevel, multisitePolling, date );
return t.invoke( null, null );
}

} catch( Exception e ) {
logger.warning(String.format("Caught exception in RemoteUtil: %s", e.getMessage()));
logger.warning(String.format("Caught exception in RemoteUtil: %s", e.toString()));
throw new CCUCMException( e );
if( slavePolling ) {
return workspace.act( new GetRemoteBaselineFromStream( component, stream, plevel, multisitePolling, date ) );
} else {
GetRemoteBaselineFromStream t = new GetRemoteBaselineFromStream( component, stream, plevel, multisitePolling, date );
return t.invoke( null, null );
}
}
}
151 changes: 57 additions & 94 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -32,7 +32,6 @@
import net.praqma.clearcase.ucm.entities.Project;
import net.praqma.clearcase.ucm.entities.Stream;
import net.praqma.clearcase.ucm.entities.UCMEntity.LabelStatus;
import net.praqma.clearcase.util.ExceptionUtils;
import net.praqma.hudson.CCUCMBuildAction;
import net.praqma.hudson.Config;
import net.praqma.hudson.Util;
Expand All @@ -47,6 +46,8 @@
import net.sf.json.JSONException;
import net.sf.json.JSONObject;

import org.apache.commons.httpclient.util.ExceptionUtil;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
Expand Down Expand Up @@ -146,9 +147,8 @@ public boolean checkout( AbstractBuild<?, ?> build, Launcher launcher, FilePath
try {
workspace.act( new RemoteClearCaseCheck() );
} catch( AbnormalProcessTerminationException e ) {
ExceptionUtils.print( e, out, true );
build.setDescription( e.getMessage() );
throw new AbortException( e.getMessage() );
throw e;
}

/* Make build action */
Expand Down Expand Up @@ -295,46 +295,27 @@ private boolean checkInput( TaskListener listener ) {
return true;
}

private boolean initializeWorkspace( AbstractBuild<?, ?> build, FilePath workspace, File changelogFile, BuildListener listener, CCUCMBuildAction action ) {
private boolean initializeWorkspace( AbstractBuild<?, ?> build, FilePath workspace, File changelogFile, BuildListener listener, CCUCMBuildAction action ) throws IOException, InterruptedException {

PrintStream consoleOutput = listener.getLogger();

EstablishResult er = null;
try {
CheckoutTask ct = new CheckoutTask( listener, jobName, build.getNumber(), action.getStream(), loadModule, action.getBaseline(), buildProject, ( plevel == null ) );
er = workspace.act( ct );
String changelog = er.getMessage();
CheckoutTask ct = new CheckoutTask( listener, jobName, build.getNumber(), action.getStream(), loadModule, action.getBaseline(), buildProject, ( plevel == null ) );
er = workspace.act( ct );
String changelog = er.getMessage();

this.viewtag = er.getViewtag();
this.viewtag = er.getViewtag();

/* Write change log */
try {
FileOutputStream fos = new FileOutputStream( changelogFile );
fos.write( changelog.getBytes() );
fos.close();
} catch( IOException e ) {
logger.fine( id + "Could not write change log file" );
consoleOutput.println( "[" + Config.nameShort + "] Could not write change log file" );
}
/* Write change log */
try {
FileOutputStream fos = new FileOutputStream( changelogFile );
fos.write( changelog.getBytes() );
fos.close();
} catch( IOException e ) {
logger.fine( id + "Could not write change log file" );
consoleOutput.println( "[" + Config.nameShort + "] Could not write change log file" );
}

} catch( Exception e ) {
consoleOutput.println( "[" + Config.nameShort + "] Unable to initialize workspace" );
Exception cause = (Exception) e.getCause();

if( cause != null ) {
try {
throw cause;
} catch( Exception e1 ) {
ExceptionUtils.print( cause, consoleOutput, true );
ExceptionUtils.log( cause, true );
}
} else {
ExceptionUtils.print( cause, consoleOutput, true );
ExceptionUtils.log( cause, true );
}

return false;
}

return true;
}
Expand All @@ -348,7 +329,7 @@ private boolean initializeWorkspace( AbstractBuild<?, ?> build, FilePath workspa
* @throws UnableToInitializeEntityException
* @throws CCUCMException
*/
public void resolveBaselineInput( AbstractBuild<?, ?> build, String baselineInput, CCUCMBuildAction action, BuildListener listener ) throws UnableToInitializeEntityException, CCUCMException {
public void resolveBaselineInput( AbstractBuild<?, ?> build, String baselineInput, CCUCMBuildAction action, BuildListener listener ) throws UnableToInitializeEntityException, IOException, InterruptedException {

PrintStream consoleOutput = listener.getLogger();

Expand Down Expand Up @@ -387,7 +368,7 @@ public String getBaselineValue( AbstractBuild<?, ?> build ) {
* @param listener
* @throws CCUCMException is thrown if no valid baselines are found
*/
private void resolveBaseline( FilePath workspace, AbstractProject<?, ?> project, CCUCMBuildAction action, BuildListener listener ) throws CCUCMException {
private void resolveBaseline( FilePath workspace, AbstractProject<?, ?> project, CCUCMBuildAction action, BuildListener listener ) throws IOException, InterruptedException, CCUCMException {
logger.fine( "Resolving Baseline from the Stream " + action.getStream().getNormalizedName() );
PrintStream out = listener.getLogger();

Expand Down Expand Up @@ -476,7 +457,7 @@ public boolean beginDeliver( AbstractBuild<?, ?> build, CCUCMBuildAction state,

/* Re-throw */
try {
ExceptionUtils.log( cause, true );
logger.log( Level.WARNING, "", cause );
throw cause;
} catch( DeliverException de ) {

Expand All @@ -498,12 +479,8 @@ public boolean beginDeliver( AbstractBuild<?, ?> build, CCUCMBuildAction state,

} catch( Exception ex ) {
consoleOutput.println( "[" + Config.nameShort + "] Failed to cancel deliver" );
consoleOutput.println( "[" + Config.nameShort + "] Original error:" );
ExceptionUtils.print( de, consoleOutput, true );
consoleOutput.println( "[" + Config.nameShort + "] Cancellation error:" );
ExceptionUtils.print( ex, consoleOutput, true );
logger.log( Level.WARNING, "", de );
logger.log( Level.WARNING, "", ex );
consoleOutput.println( ExceptionUtils.getFullStackTrace( e ) );
logger.warning( ExceptionUtils.getFullStackTrace( e ) );
}
} else {
logger.fine( id + "No need for completing deliver" );
Expand All @@ -522,7 +499,7 @@ public boolean beginDeliver( AbstractBuild<?, ?> build, CCUCMBuildAction state,
state.setNeedsToBeCompleted( false );
} catch( Exception e1 ) {
logger.log( Level.WARNING, "", e );
ExceptionUtils.print( e, consoleOutput, true );
e.printStackTrace( consoleOutput );
}
}

Expand Down Expand Up @@ -582,13 +559,8 @@ public void buildEnvVars( AbstractBuild<?, ?> build, Map<String, String> env ) {
@Override
public PollingResult compareRemoteRevisionWith( AbstractProject<?, ?> project, Launcher launcher, FilePath workspace, TaskListener listener, SCMRevisionState rstate ) throws IOException, InterruptedException {

/**/
try {
workspace.act( new RemoteClearCaseCheck() );
} catch( AbnormalProcessTerminationException e ) {
throw new AbortException( e.getMessage() );
}

workspace.act( new RemoteClearCaseCheck() );

jobName = project.getDisplayName().replace( ' ', '_' );
jobNumber = project.getNextBuildNumber();
this.id = "[" + jobName + "::" + jobNumber + "]";
Expand Down Expand Up @@ -631,36 +603,30 @@ public PollingResult compareRemoteRevisionWith( AbstractProject<?, ?> project, L

printParameters( out );

try {
List<Baseline> baselines = null;

Baseline foundBaseline = null;
CCUCMBuildAction lastAction = getLastAction( project );
Date date = null;
if( lastAction != null ) {
out.println( lastAction );
date = lastAction.getBaseline().getDate();
lastBaseline = lastAction.getBaseline();
}

/* Old skool self polling */
if( polling.isPollingSelf() ) {
baselines = getValidBaselinesFromStream( workspace, plevel, stream, component, date );
} else {
/* Find the Baselines and store them */
baselines = getBaselinesFromStreams( workspace, listener, out, stream, component, polling.isPollingChilds(), date );
}
List<Baseline> baselines = null;

if( baselines.size() > 0 ) {
p = PollingResult.BUILD_NOW;
}
Baseline foundBaseline = null;
CCUCMBuildAction lastAction = getLastAction( project );
Date date = null;
if( lastAction != null ) {
out.println( lastAction );
date = lastAction.getBaseline().getDate();
lastBaseline = lastAction.getBaseline();
}

} catch( CCUCMException e ) {
out.println( "Error while retrieving baselines: " + e.getMessage() );
logger.warning( "Error while retrieving baselines: " + e.getMessage() );
p = PollingResult.NO_CHANGES;
}
}
/* Old skool self polling */
if( polling.isPollingSelf() ) {
baselines = getValidBaselinesFromStream( workspace, plevel, stream, component, date );
} else {
/* Find the Baselines and store them */
baselines = getBaselinesFromStreams( workspace, listener, out, stream, component, polling.isPollingChilds(), date );
}

if( baselines.size() > 0 ) {
p = PollingResult.BUILD_NOW;
}

}

return p;
}
Expand All @@ -682,9 +648,9 @@ private List<Baseline> getBaselinesFromStreams( FilePath workspace, TaskListener

try {
streams = RemoteUtil.getRelatedStreams( workspace, listener, stream, pollingChildStreams, this.getSlavePolling(), this.getMultisitePolling() );
} catch( CCUCMException e1 ) {
e1.printStackTrace( consoleOutput );
logger.warning( "Could not retrieve streams: " + e1.getMessage() );
} catch( Exception e1 ) {
Throwable root = ExceptionUtils.getRootCause( e1 );
logger.log( Level.WARNING, "Could not get related streams from " + stream, root );
consoleOutput.println( "[" + Config.nameShort + "] No streams found" );
return baselines;
}
Expand All @@ -701,8 +667,10 @@ private List<Baseline> getBaselinesFromStreams( FilePath workspace, TaskListener
baselines.add( b );
}
consoleOutput.println( found.size() + " baseline" + ( found.size() == 1 ? "" : "s" ) + " found" );
} catch( CCUCMException e ) {
consoleOutput.println( "No baselines: " + e.getMessage() );
} catch( Exception e ) {
Throwable root = ExceptionUtils.getRootCause( e );
logger.log( Level.WARNING, "Could not get baselines from " + s, root );
consoleOutput.println( "No baselines: " + root.getMessage() );
}
}

Expand All @@ -721,7 +689,7 @@ private List<Baseline> getBaselinesFromStreams( FilePath workspace, TaskListener
* @return A list of {@link Baseline}'s
* @throws CCUCMException
*/
private List<Baseline> getValidBaselinesFromStream( FilePath workspace, Project.PromotionLevel plevel, Stream stream, Component component, Date date ) throws CCUCMException {
private List<Baseline> getValidBaselinesFromStream( FilePath workspace, Project.PromotionLevel plevel, Stream stream, Component component, Date date ) throws IOException, InterruptedException {
logger.fine( id + "Retrieving valid baselines." );

/* The baseline list */
Expand All @@ -732,13 +700,8 @@ private List<Baseline> getValidBaselinesFromStream( FilePath workspace, Project.
*
* TODO:Needs to be reviewed by chw and les. Remove upon release.
*/

try {
baselines = RemoteUtil.getRemoteBaselinesFromStream( workspace, component, stream, plevel, this.getSlavePolling(), this.getMultisitePolling(), date );
} catch( CCUCMException e1 ) {
logger.fine( "No baselines: " + e1.getMessage() );
throw new CCUCMException("Unable to get baselines from " + stream.getShortname(), e1 );
}

baselines = RemoteUtil.getRemoteBaselinesFromStream( workspace, component, stream, plevel, this.getSlavePolling(), this.getMultisitePolling(), date );

return baselines;
}
Expand Down

0 comments on commit 6bddf24

Please sign in to comment.