You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2015/07/31 17:21:24 UTC
svn commit: r1693614 -
/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/
Author: elecharny
Date: Fri Jul 31 15:21:23 2015
New Revision: 1693614
URL: http://svn.apache.org/r1693614
Log:
Removed PMD warnings
Modified:
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCoreConstants.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCorePlugin.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/Messages.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioBulkRunnableWithProgress.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioJob.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitor.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitorWatcherJob.java
directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioRunnableWithProgress.java
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCoreConstants.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCoreConstants.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCoreConstants.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCoreConstants.java Fri Jul 31 15:21:23 2015
@@ -29,6 +29,13 @@ package org.apache.directory.studio.comm
*/
public final class CommonCoreConstants
{
+
+ /** The plug-in ID */
+ public static final String PLUGIN_ID = "org.apache.directory.studio.common.core"; //$NON-NLS-1$
+
+ /** The Job family ID */
+ public static final String JOB_FAMILY_ID = "org.apache.directory.studio.common.core.jobs.family"; //$NON-NLS-1$
+
/**
* Ensures no construction of this class, also ensures there is no need for final keyword above
* (Implicit super constructor is not visible for default constructor),
@@ -37,10 +44,4 @@ public final class CommonCoreConstants
private CommonCoreConstants()
{
}
-
- /** The plug-in ID */
- public static final String PLUGIN_ID = "org.apache.directory.studio.common.core"; //$NON-NLS-1$
-
- /** The Job family ID */
- public static final String JOB_FAMILY_ID = "org.apache.directory.studio.common.core.jobs.family"; //$NON-NLS-1$
}
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCorePlugin.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCorePlugin.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCorePlugin.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/CommonCorePlugin.java Fri Jul 31 15:21:23 2015
@@ -37,8 +37,12 @@ public class CommonCorePlugin extends Pl
private StudioProgressMonitorWatcherJob studioProgressMonitorWatcherJob;
+ /**
+ * The default constructor for this class
+ */
public CommonCorePlugin()
{
+ super();
plugin = this;
}
@@ -46,6 +50,7 @@ public class CommonCorePlugin extends Pl
/**
* @see Plugin#start(org.osgi.framework.BundleContext)
*/
+ @Override
public void start( BundleContext context ) throws Exception
{
super.start( context );
@@ -59,6 +64,7 @@ public class CommonCorePlugin extends Pl
/**
* @see Plugin#stop(org.osgi.framework.BundleContext)
*/
+ @Override
public void stop( BundleContext context ) throws Exception
{
plugin = null;
@@ -82,6 +88,9 @@ public class CommonCorePlugin extends Pl
}
+ /**
+ * @return The watcher job
+ */
public StudioProgressMonitorWatcherJob getStudioProgressMonitorWatcherJob()
{
return studioProgressMonitorWatcherJob;
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/Messages.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/Messages.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/Messages.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/Messages.java Fri Jul 31 15:21:23 2015
@@ -30,13 +30,21 @@ import java.util.ResourceBundle;
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
*/
-public class Messages
+public final class Messages
{
/** The resource name */
private static final ResourceBundle RESOURCE_BUNDLE =
ResourceBundle.getBundle( Messages.class.getPackage().getName() + ".messages" );
/**
+ * private constructor
+ */
+ private Messages()
+ {
+ }
+
+
+ /**
* Get back a message from the resource file given a key
*
* @param key The key associated with the message
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioBulkRunnableWithProgress.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioBulkRunnableWithProgress.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioBulkRunnableWithProgress.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioBulkRunnableWithProgress.java Fri Jul 31 15:21:23 2015
@@ -35,5 +35,5 @@ public interface StudioBulkRunnableWithP
*
* @param monitor the monitor
*/
- public void runNotification( StudioProgressMonitor monitor );
+ void runNotification( StudioProgressMonitor monitor );
}
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioJob.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioJob.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioJob.java Fri Jul 31 15:21:23 2015
@@ -68,6 +68,7 @@ public class StudioJob<T extends StudioR
{
StudioBulkRunnableWithProgress bulkRunnable = ( StudioBulkRunnableWithProgress ) runnable;
suspendEventFiringInCurrentThread();
+
try
{
bulkRunnable.run( monitor );
@@ -76,6 +77,7 @@ public class StudioJob<T extends StudioR
{
resumeEventFiringInCurrentThread();
}
+
bulkRunnable.runNotification( monitor );
}
else
@@ -107,7 +109,6 @@ public class StudioJob<T extends StudioR
{
return Status.OK_STATUS;
}
-
}
@@ -153,27 +154,26 @@ public class StudioJob<T extends StudioR
String[] myLockedObjectsIdentifiers = getLockIdentifiers( myLockedObjects );
Job[] jobs = getJobManager().find( null );
- for ( int i = 0; i < jobs.length; i++ )
+
+ for ( Job job : jobs )
{
- Job job = jobs[i];
if ( job instanceof StudioJob )
{
@SuppressWarnings("unchecked")
StudioJob<StudioRunnableWithProgress> otherJob = ( StudioJob<StudioRunnableWithProgress> ) job;
+
for ( StudioRunnableWithProgress otherRunnable : otherJob.runnables )
{
- if ( runnable.getClass() == otherRunnable.getClass() && runnable != otherRunnable )
+ if ( ( runnable.getClass() == otherRunnable.getClass() ) && ( runnable != otherRunnable ) )
{
Object[] otherLockedObjects = otherRunnable.getLockedObjects();
String[] otherLockedObjectIdentifiers = getLockIdentifiers( otherLockedObjects );
- for ( int j = 0; j < otherLockedObjectIdentifiers.length; j++ )
+ for ( String other : otherLockedObjectIdentifiers )
{
- String other = otherLockedObjectIdentifiers[j];
- for ( int k = 0; k < myLockedObjectsIdentifiers.length; k++ )
+ for ( String myLockedObjectIdentifier : myLockedObjectsIdentifiers )
{
- String my = myLockedObjectsIdentifiers[k];
- if ( other.startsWith( my ) || my.startsWith( other ) )
+ if ( other.startsWith( myLockedObjectIdentifier ) || myLockedObjectIdentifier.startsWith( other ) )
{
return false;
}
@@ -184,6 +184,7 @@ public class StudioJob<T extends StudioR
}
}
}
+
return super.shouldSchedule();
}
@@ -191,18 +192,18 @@ public class StudioJob<T extends StudioR
/**
* Gets the string identifiers for the given objects.
*
- * @param objects
- * the objects
- * @return
- * the string identifiers associated with the objects
+ * @param objects the objects
+ * @return the string identifiers associated with the objects
*/
- protected String[] getLockIdentifiers( Object[] objects )
+ protected String[] getLockIdentifiers( Object... objects )
{
String[] identifiers = new String[objects.length];
+
for ( int i = 0; i < identifiers.length; i++ )
{
identifiers[i] = getLockIdentifier( objects[i] );
}
+
return identifiers;
}
@@ -210,14 +211,19 @@ public class StudioJob<T extends StudioR
/**
* Gets the generic lock identifier for an object.
*
- * @param object
- * the object
- * @return
- * the lock identifier for the object
+ * @param object the object
+ * @return the lock identifier for the object
*/
private String getLockIdentifier( Object object )
{
- return ( object != null ? object.toString() : "null" ); //$NON-NLS-1$
+ if ( object == null )
+ {
+ return "null";
+ }
+ else
+ {
+ return object.toString();
+ }
}
@@ -233,8 +239,7 @@ public class StudioJob<T extends StudioR
/**
* Get the object corresponding to the family of the Job.
*
- * @return
- * the object corresponding to the family of the Job
+ * @return the object corresponding to the family of the Job
*/
public Object getFamily()
{
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitor.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitor.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitor.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitor.java Fri Jul 31 15:21:23 2015
@@ -47,7 +47,7 @@ public class StudioProgressMonitor exten
protected String pluginId;
/** The flag indicating if the work is done */
- protected boolean done;
+ protected boolean isDone;
/** The list of error statuses */
protected List<Status> errorStatusList;
@@ -82,7 +82,7 @@ public class StudioProgressMonitor exten
{
super( monitor );
this.pluginId = pluginId;
- done = false;
+ isDone = false;
CommonCorePlugin.getDefault().getStudioProgressMonitorWatcherJob().addMonitor(this);
allowMessageReporting = new AtomicBoolean( true );
}
@@ -91,10 +91,11 @@ public class StudioProgressMonitor exten
/**
* @see org.eclipse.core.runtime.ProgressMonitorWrapper#setCanceled(boolean)
*/
- public void setCanceled( boolean b )
+ public void setCanceled( boolean canceled )
{
- super.setCanceled( b );
- if ( b )
+ super.setCanceled( canceled );
+
+ if ( canceled )
{
fireCancelRequested();
}
@@ -108,7 +109,7 @@ public class StudioProgressMonitor exten
{
synchronized ( this )
{
- done = true;
+ isDone = true;
super.done();
}
}
@@ -125,6 +126,7 @@ public class StudioProgressMonitor exten
{
cancelListenerList = new ArrayList<CancelListener>();
}
+
if ( !cancelListenerList.contains( listener ) )
{
cancelListenerList.add( listener );
@@ -139,22 +141,22 @@ public class StudioProgressMonitor exten
*/
public void removeCancelListener( CancelListener listener )
{
- if ( cancelListenerList != null && cancelListenerList.contains( listener ) )
+ if ( ( cancelListenerList != null ) && cancelListenerList.contains( listener ) )
{
cancelListenerList.remove( listener );
}
}
- void fireCancelRequested()
+ /* Package protected */void fireCancelRequested()
{
CancelEvent event = new CancelEvent( this );
+
if ( cancelListenerList != null )
{
- for ( int i = 0; i < cancelListenerList.size(); i++ )
+ for ( CancelListener cancelListener : cancelListenerList )
{
- CancelListener listener = cancelListenerList.get( i );
- listener.cancelRequested( event );
+ cancelListener.cancelRequested( event );
}
}
}
@@ -168,6 +170,7 @@ public class StudioProgressMonitor exten
public void reportProgress( String message )
{
boolean doReport = allowMessageReporting.getAndSet( false );
+
if ( doReport )
{
subTask( message );
@@ -182,7 +185,7 @@ public class StudioProgressMonitor exten
*/
public void reportError( String message )
{
- this.reportError( message, null );
+ reportError( message, null );
}
@@ -240,79 +243,77 @@ public class StudioProgressMonitor exten
*/
public IStatus getErrorStatus( String message )
{
- if ( errorStatusList != null && !errorStatusList.isEmpty() )
+ if ( ( errorStatusList == null ) || errorStatusList.isEmpty() )
{
+ if ( isCanceled() )
+ {
+ return Status.CANCEL_STATUS;
+ }
+ else
+ {
+ return Status.OK_STATUS;
+ }
+ }
+ else
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append( message );
+
// append status messages to message
for ( Status status : errorStatusList )
{
String statusMessage = status.getMessage();
Throwable exception = status.getException();
- String exceptionMessage = exception != null ? exception.getMessage() : null;
-
- // TODO Check if this commented code could be removed
- // // Tweak exception message for some well-know exceptions
- // Throwable e = exception;
- // while ( e != null )
- // {
- // if ( e instanceof UnknownHostException )
- // {
- // exceptionMessage = "Unknown Host: " + e.getMessage(); //$NON-NLS-1$
- // }
- // else if ( e instanceof SocketException )
- // {
- // exceptionMessage = e.getMessage() + " (" + exceptionMessage + ")";; //$NON-NLS-1$ //$NON-NLS-2$
- // }
- //
- // // next cause
- // e = e.getCause();
- // }
+ String exceptionMessage = null;
+
+ if ( exception != null)
+ {
+ exceptionMessage = exception.getMessage();
+ }
// append explicit status message
if ( !StringUtils.isEmpty( statusMessage ) )
{
- message += "\n - " + statusMessage; //$NON-NLS-1$
+ buffer.append( "\n - " ).append( statusMessage );
}
+
// append exception message if different to status message
- if ( exception != null && exceptionMessage != null && !exceptionMessage.equals( statusMessage ) )
+ if ( (exception != null ) && ( exceptionMessage != null ) && !exceptionMessage.equals( statusMessage ) )
{
// strip control characters
int indexOfAny = StringUtils.indexOfAny( exceptionMessage, "\n\r\t" ); //$NON-NLS-1$
+
if ( indexOfAny > -1 )
{
exceptionMessage = exceptionMessage.substring( 0, indexOfAny - 1 );
}
- message += "\n - " + exceptionMessage; //$NON-NLS-1$
+
+ buffer.append( "\n - " ).append( exceptionMessage ); //$NON-NLS-1$
}
}
// create main status
- MultiStatus multiStatus = new MultiStatus( pluginId, IStatus.ERROR, message, null );
+ MultiStatus multiStatus = new MultiStatus( pluginId, IStatus.ERROR, buffer.toString(), null );
// append child status
for ( Status status : errorStatusList )
{
String statusMessage = status.getMessage();
+
if ( status.getException() != null )
{
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter( sw );
- status.getException().printStackTrace( pw );
- statusMessage = sw.toString();
+ StringWriter stringWriter = new StringWriter();
+ PrintWriter printWriter = new PrintWriter( stringWriter );
+ status.getException().printStackTrace( printWriter );
+ statusMessage = stringWriter.toString();
}
+
multiStatus.add( new Status( status.getSeverity(), status.getPlugin(), status.getCode(), statusMessage,
status.getException() ) );
}
return multiStatus;
}
- else if ( isCanceled() )
- {
- return Status.CANCEL_STATUS;
- }
- else
- {
- return Status.OK_STATUS;
- }
}
@@ -327,6 +328,7 @@ public class StudioProgressMonitor exten
{
return ( Exception ) errorStatusList.get( 0 ).getException();
}
+
return null;
}
@@ -336,8 +338,8 @@ public class StudioProgressMonitor exten
*/
public void reset()
{
- this.done = false;
- this.errorStatusList = null;
+ isDone = false;
+ errorStatusList = null;
}
/**
@@ -347,6 +349,7 @@ public class StudioProgressMonitor exten
*/
public static class CancelEvent
{
+ /** The Monitor used by the Cancel Event */
private IProgressMonitor monitor;
@@ -372,6 +375,7 @@ public class StudioProgressMonitor exten
}
}
+
/**
* CancelListener.
*
@@ -379,13 +383,11 @@ public class StudioProgressMonitor exten
*/
public interface CancelListener
{
-
/**
* Cancel requested.
*
* @param event the event
*/
- public void cancelRequested( CancelEvent event );
+ void cancelRequested( CancelEvent event );
}
-
}
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitorWatcherJob.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitorWatcherJob.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitorWatcherJob.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioProgressMonitorWatcherJob.java Fri Jul 31 15:21:23 2015
@@ -45,26 +45,40 @@ public class StudioProgressMonitorWatche
private final ConcurrentLinkedQueue<StudioProgressMonitor> monitors;
+ /**
+ * The constructor
+ */
public StudioProgressMonitorWatcherJob()
{
super( Messages.getString( "StudioProgressMonitor.CheckCancellation" ) );
- this.running = new AtomicBoolean( true );
- this.monitors = new ConcurrentLinkedQueue<StudioProgressMonitor>();
+ running = new AtomicBoolean( true );
+ monitors = new ConcurrentLinkedQueue<StudioProgressMonitor>();
}
+ /**
+ * Set the running flag to false
+ */
public void stop()
{
- this.running.set( false );
+ running.set( false );
}
+ /**
+ * Add a new monitor to the list of monitors being watched
+ *
+ * @param monitor The monitor to add
+ */
public void addMonitor( StudioProgressMonitor monitor )
{
- this.monitors.add( monitor );
+ monitors.add( monitor );
}
+ /**
+ * {@inheritDoc}
+ */
@Override
protected IStatus run( IProgressMonitor monitor )
{
@@ -78,7 +92,7 @@ public class StudioProgressMonitorWatche
do
{
// reset allow message reporting
- if ( !spm.isCanceled() && !spm.done )
+ if ( !spm.isCanceled() && !spm.isDone )
{
spm.allowMessageReporting.set( true );
}
@@ -88,7 +102,8 @@ public class StudioProgressMonitorWatche
{
spm.fireCancelRequested();
}
- if ( spm.isCanceled() || spm.done )
+
+ if ( spm.isCanceled() || spm.isDone )
{
it.remove();
break;
@@ -114,7 +129,7 @@ public class StudioProgressMonitorWatche
{
}
}
+
return Status.OK_STATUS;
}
-
}
Modified: directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioRunnableWithProgress.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioRunnableWithProgress.java?rev=1693614&r1=1693613&r2=1693614&view=diff
==============================================================================
--- directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioRunnableWithProgress.java (original)
+++ directory/studio/trunk/plugins/common.core/src/main/java/org/apache/directory/studio/common/core/jobs/StudioRunnableWithProgress.java Fri Jul 31 15:21:23 2015
@@ -33,7 +33,7 @@ public interface StudioRunnableWithProgr
*
* @param monitor the monitor
*/
- public void run( StudioProgressMonitor monitor );
+ void run( StudioProgressMonitor monitor );
/**
@@ -41,7 +41,7 @@ public interface StudioRunnableWithProgr
*
* @return the locked objects
*/
- public Object[] getLockedObjects();
+ Object[] getLockedObjects();
/**
@@ -49,7 +49,7 @@ public interface StudioRunnableWithProgr
*
* @return the error message
*/
- public String getErrorMessage();
+ String getErrorMessage();
/**
@@ -57,5 +57,5 @@ public interface StudioRunnableWithProgr
*
* @return the name
*/
- public String getName();
+ String getName();
}