CPD Results
The following document contains the results of PMD's CPD 5.1.2.
Duplications
File |
Line |
org/jomc/ant/MergeModletsTask.java |
480 |
org/jomc/ant/MergeModulesTask.java |
442 |
urls[i].toExternalForm() ) );
}
suppressExceptionOnClose = false;
}
catch ( final SocketTimeoutException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceTimeout", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
}
catch ( final IOException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceFailure", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
}
finally
{
try
{
if ( in != null )
{
in.close();
}
}
catch ( final IOException e )
{
if ( suppressExceptionOnClose )
{
this.logMessage( Level.SEVERE, Messages.getMessage( e ), e );
}
else
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
}
}
}
suppressExceptionOnClose = true;
}
for ( String defaultExclude : classLoader.getModletExcludes() ) |
File |
Line |
org/jomc/ant/MergeModletsTask.java |
615 |
org/jomc/ant/MergeModulesTask.java |
586 |
marshaller.marshal( new ObjectFactory().createModlet( mergedModlet ), this.getModletFile() );
suppressExceptionOnClose = false;
}
catch ( final URISyntaxException e )
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new BuildException( message, e, this.getLocation() );
}
catch ( final TransformerConfigurationException e )
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final TransformerException e )
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final ModelException e )
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
if ( suppressExceptionOnClose )
{
this.logMessage( Level.SEVERE, Messages.getMessage( e ), e );
}
else
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
}
}
}
/**
* Tests inclusion of a given modlet based on property {@code modletIncludes}.
*
* @param modlet The modlet to test.
*
* @return {@code true}, if {@code modlet} is included based on property {@code modletIncludes}.
*
* @throws NullPointerException if {@code modlet} is {@code null}.
*
* @see #getModletIncludes()
*/
public boolean isModletIncluded( final Modlet modlet ) |
File |
Line |
org/jomc/ant/ValidateClassesTask.java |
181 |
org/jomc/ant/ValidateClasspathTask.java |
144 |
validationReport = tool.validateModelObjects( context, this.getClassesDirectory() );
if ( validationReport != null )
{
this.logValidationReport( context, validationReport );
if ( !validationReport.isModelValid() )
{
throw new ModelException( Messages.getMessage( "invalidModel", this.getModel() ) );
}
}
}
suppressExceptionOnClose = false;
}
else
{
throw new ModelException( Messages.getMessage( "invalidModel", this.getModel() ) );
}
}
catch ( final IOException e )
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final JAXBException e )
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final ModelException e )
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
if ( suppressExceptionOnClose )
{
this.logMessage( Level.SEVERE, Messages.getMessage( e ), e );
}
else
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
}
}
}
/** {@inheritDoc} */
@Override
public ValidateClassesTask clone() |
File |
Line |
org/jomc/ant/JomcTask.java |
460 |
org/jomc/ant/types/TransformerResourceType.java |
60 |
}
/**
* Gets the global transformation parameters to apply.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
* to the returned list will be present inside the object. This is why there is no {@code set} method for the
* transformation parameters property.</p>
*
* @return The global transformation parameters to apply.
*
* @see #createTransformationParameter()
* @see #getTransformer(org.jomc.ant.types.TransformerResourceType)
*/
public final List<KeyValueType> getTransformationParameters()
{
if ( this.transformationParameters == null )
{
this.transformationParameters = new LinkedList<KeyValueType>();
}
return this.transformationParameters;
}
/**
* Creates a new {@code transformationParameter} element instance.
*
* @return A new {@code transformationParameter} element instance.
*
* @see #getTransformationParameters()
*/
public KeyValueType createTransformationParameter()
{
final KeyValueType transformationParameter = new KeyValueType();
this.getTransformationParameters().add( transformationParameter );
return transformationParameter;
}
/**
* Gets the global transformation parameter resources to apply.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
* to the returned list will be present inside the object. This is why there is no {@code set} method for the
* transformation parameter resources property.</p>
*
* @return The global transformation parameter resources to apply.
*
* @see #createTransformationParameterResource()
* @see #getTransformer(org.jomc.ant.types.TransformerResourceType)
*/
public final List<PropertiesResourceType> getTransformationParameterResources()
{
if ( this.transformationParameterResources == null )
{
this.transformationParameterResources = new LinkedList<PropertiesResourceType>();
}
return this.transformationParameterResources;
}
/**
* Creates a new {@code transformationParameterResource} element instance.
*
* @return A new {@code transformationParameterResource} element instance.
*
* @see #getTransformationParameterResources()
*/
public PropertiesResourceType createTransformationParameterResource()
{
final PropertiesResourceType transformationParameterResource = new PropertiesResourceType();
this.getTransformationParameterResources().add( transformationParameterResource );
return transformationParameterResource;
}
/**
* Gets the global transformation output properties to apply.
* <p>This accessor method returns a reference to the live list, not a snapshot. Therefore any modification you make
* to the returned list will be present inside the object. This is why there is no {@code set} method for the
* transformation output properties property.</p>
*
* @return The global transformation output properties to apply.
*
* @see #createTransformationOutputProperty()
*/
public final List<KeyValueType> getTransformationOutputProperties()
{
if ( this.transformationOutputProperties == null )
{
this.transformationOutputProperties = new LinkedList<KeyValueType>();
}
return this.transformationOutputProperties;
}
/**
* Creates a new {@code transformationOutputProperty} element instance.
*
* @return A new {@code transformationOutputProperty} element instance.
*
* @see #getTransformationOutputProperties()
*/
public KeyValueType createTransformationOutputProperty()
{
final KeyValueType transformationOutputProperty = new KeyValueType();
this.getTransformationOutputProperties().add( transformationOutputProperty );
return transformationOutputProperty;
} |
File |
Line |
org/jomc/ant/JomcModelTask.java |
340 |
org/jomc/ant/MergeModulesTask.java |
437 |
modules.getModule().add( (Module) o );
}
else
{
this.log( Messages.getMessage( "unsupportedModuleResource", urls[i].toExternalForm() ),
Project.MSG_WARN );
}
suppressExceptionOnClose = false;
}
catch ( final SocketTimeoutException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceTimeout", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
}
catch ( final IOException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceFailure", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
} |
File |
Line |
org/jomc/ant/Messages.java |
43 |
org/jomc/ant/types/Messages.java |
43 |
abstract class Messages
{
/** Constant for the name of the resource bundle backing the tasks. */
private static final String RESOURCE_BUNDLE_NAME =
Messages.class.getPackage().getName().replace( '.', '/' ) + "/Messages";
/** Creates a new {@code Messages} instance. */
Messages()
{
super();
}
/**
* Gets a message for a given key from the resource bundle backing the tasks formatted using the given arguments.
*
* @param key The key of the string to get.
* @param arguments The arguments to format the string with.
*
* @return The string matching {@code key} formatted using {@code arguments}.
*
* @throws NullPointerException if {@code key} is {@code null}.
*/
static String getMessage( final String key, final Object... arguments )
{
if ( key == null )
{
throw new NullPointerException( "key" );
}
try
{
return MessageFormat.format( ResourceBundle.getBundle( RESOURCE_BUNDLE_NAME ).getString( key ), arguments );
}
catch ( final MissingResourceException e )
{
throw new AssertionError( e );
}
catch ( final ClassCastException e )
{
throw new AssertionError( e );
}
catch ( final IllegalArgumentException e )
{
throw new AssertionError( e );
}
}
/**
* Gets the message of a given {@code Throwable} recursively.
*
* @param t The {@code Throwable} to get the message of or {@code null}.
*
* @return The message of {@code t} or {@code null}.
*/
static String getMessage( final Throwable t )
{
return t != null
? t.getMessage() != null && t.getMessage().trim().length() > 0
? t.getMessage()
: getMessage( t.getCause() )
: null;
}
} |
File |
Line |
org/jomc/ant/JomcModelTask.java |
345 |
org/jomc/ant/MergeModletsTask.java |
480 |
Project.MSG_WARN );
}
suppressExceptionOnClose = false;
}
catch ( final SocketTimeoutException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceTimeout", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
}
catch ( final IOException e )
{
String message = Messages.getMessage( e );
message = Messages.getMessage( "resourceFailure", message != null ? " " + message : "" );
if ( resource.isOptional() )
{
this.getProject().log( message, e, Project.MSG_WARN );
}
else
{
throw new BuildException( message, e, this.getLocation() );
}
} |
File |
Line |
org/jomc/ant/ValidateClassesTask.java |
115 |
org/jomc/ant/ValidateClasspathTask.java |
78 |
this.log( Messages.getMessage( "validatingModelObjects", this.getModel() ) );
classLoader = this.newProjectClassLoader();
final ModelContext context = this.newModelContext( classLoader );
final ClassFileProcessor tool = this.newClassFileProcessor();
final JAXBContext jaxbContext = context.createContext( this.getModel() );
final Model model = this.getModel( context );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) );
ModelValidationReport validationReport = context.validateModel( this.getModel(), source );
this.logValidationReport( context, validationReport );
tool.setModel( model );
if ( validationReport.isModelValid() )
{
final Specification s = this.getSpecification( model );
final Implementation i = this.getImplementation( model );
final Module m = this.getModule( model );
if ( s != null )
{
validationReport = tool.validateModelObjects( s, context, this.getClassesDirectory() ); |
File |
Line |
org/jomc/ant/MergeModletsTask.java |
442 |
org/jomc/ant/MergeModulesTask.java |
403 |
resource.getLocation() ) );
}
}
for ( int i = urls.length - 1; i >= 0; i-- )
{
InputStream in = null;
suppressExceptionOnClose = true;
try
{
this.logMessage( Level.FINEST, Messages.getMessage( "reading", urls[i].toExternalForm() ) );
final URLConnection con = urls[i].openConnection();
con.setConnectTimeout( resource.getConnectTimeout() );
con.setReadTimeout( resource.getReadTimeout() );
con.connect();
in = con.getInputStream();
final Source source = new StreamSource( in, urls[i].toURI().toASCIIString() );
Object o = unmarshaller.unmarshal( source );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Modlet ) |
File |
Line |
org/jomc/ant/JomcTask.java |
1629 |
org/jomc/ant/types/TransformerResourceType.java |
174 |
if ( this.transformationParameters != null )
{
clone.transformationParameters =
new ArrayList<KeyValueType>( this.transformationParameters.size() );
for ( KeyValueType e : this.transformationParameters )
{
clone.transformationParameters.add( e.clone() );
}
}
if ( this.transformationParameterResources != null )
{
clone.transformationParameterResources =
new ArrayList<PropertiesResourceType>( this.transformationParameterResources.size() );
for ( PropertiesResourceType e : this.transformationParameterResources )
{
clone.transformationParameterResources.add( e.clone() );
}
}
if ( this.transformationOutputProperties != null )
{
clone.transformationOutputProperties =
new ArrayList<KeyValueType>( this.transformationOutputProperties.size() );
for ( KeyValueType e : this.transformationOutputProperties )
{
clone.transformationOutputProperties.add( e.clone() );
}
}
return clone;
} |
File |
Line |
org/jomc/ant/JomcTask.java |
1071 |
org/jomc/ant/JomcTask.java |
1187 |
if ( resource.isOptional() )
{
this.getProject().log( Messages.getMessage( "resourceFailure", message != null ? " " + message : "" ),
e, Project.MSG_WARN );
}
else
{
throw new BuildException( Messages.getMessage( "resourceFailure", message != null ? " " + message : "" ),
e, this.getLocation() );
}
}
finally
{
try
{
if ( in != null )
{
in.close();
}
}
catch ( final IOException e )
{
if ( suppressExceptionOnClose )
{
this.logMessage( Level.SEVERE, Messages.getMessage( e ), e );
}
else
{
throw new BuildException( Messages.getMessage( e ), e, this.getLocation() );
}
}
}
return null; |
File |
Line |
org/jomc/ant/CommitClassesTask.java |
248 |
org/jomc/ant/ValidateClassesTask.java |
205 |
org/jomc/ant/ValidateClasspathTask.java |
168 |
catch ( final TransformerConfigurationException e )
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
catch ( final ModelException e )
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
if ( suppressExceptionOnClose )
{
this.logMessage( Level.SEVERE, Messages.getMessage( e ), e );
}
else
{
throw new ClassProcessingException( Messages.getMessage( e ), e, this.getLocation() );
}
}
}
}
/** {@inheritDoc} */
@Override
public CommitClassesTask clone() |
File |
Line |
org/jomc/ant/GenerateResourcesTask.java |
119 |
org/jomc/ant/ManageSourcesTask.java |
119 |
final ResourceFileProcessor tool = this.newResourceFileProcessor();
final JAXBContext jaxbContext = context.createContext( this.getModel() );
final Model model = this.getModel( context );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) );
final ModelValidationReport validationReport = context.validateModel( this.getModel(), source );
this.logValidationReport( context, validationReport );
tool.setModel( model );
if ( validationReport.isModelValid() )
{
final Specification s = this.getSpecification( model );
final Implementation i = this.getImplementation( model );
final Module m = this.getModule( model );
if ( s != null )
{
tool.writeResourceBundleResourceFiles( s, this.getResourcesDirectory() ); |
File |
Line |
org/jomc/ant/JomcModelTask.java |
286 |
org/jomc/ant/MergeModulesTask.java |
387 |
for ( ResourceType resource : this.getModuleResources() )
{
final URL[] urls = this.getResources( context, resource.getLocation() );
if ( urls.length == 0 )
{
if ( resource.isOptional() )
{
this.logMessage( Level.WARNING, Messages.getMessage( "moduleResourceNotFound",
resource.getLocation() ) );
}
else
{
throw new BuildException( Messages.getMessage( "moduleResourceNotFound", resource.getLocation() ),
this.getLocation() );
}
}
for ( int i = urls.length - 1; i >= 0; i-- )
{
InputStream in = null; |
File |
Line |
org/jomc/ant/JomcToolTask.java |
419 |
org/jomc/ant/WriteModelTask.java |
277 |
public final Specification getSpecification( final Model model )
{
if ( model == null )
{
throw new NullPointerException( "model" );
}
Specification s = null;
if ( this.getSpecification() != null )
{
final Modules modules = ModelHelper.getModules( model );
if ( modules != null )
{
s = modules.getSpecification( this.getSpecification() );
}
if ( s == null )
{
this.log( Messages.getMessage( "specificationNotFound", this.getSpecification() ), Project.MSG_WARN );
}
}
return s;
}
/**
* Gets the identifier of an implementation to process.
*
* @return The identifier of an implementation to process or {@code null}.
*
* @see #setImplementation(java.lang.String)
*/
public final String getImplementation() |
File |
Line |
org/jomc/ant/JomcToolTask.java |
543 |
org/jomc/ant/WriteModelTask.java |
401 |
public final Module getModule( final Model model )
{
if ( model == null )
{
throw new NullPointerException( "model" );
}
Module m = null;
if ( this.getModule() != null )
{
final Modules modules = ModelHelper.getModules( model );
if ( modules != null )
{
m = modules.getModule( this.getModule() );
}
if ( m == null )
{
this.log( Messages.getMessage( "moduleNotFound", this.getModule() ), Project.MSG_WARN );
}
}
return m;
} |