CPD Results
The following document contains the results of PMD's CPD 5.3.5.
Duplications
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
361 |
org/jomc/cli/commands/MergeModulesCommand.java |
376 |
this.log( Level.INFO, Messages.getMessage( "writingResource", modletFile.getAbsolutePath() ), null );
}
classLoader.close();
classLoader = null;
}
catch ( final IOException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
catch ( final TransformerException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final ModelException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
this.log( Level.SEVERE, Messages.getMessage( e ), e );
}
}
}
} |
File |
Line |
org/jomc/cli/Messages.java |
43 |
org/jomc/cli/commands/Messages.java |
43 |
abstract class 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( Messages.class.getName() ).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/cli/commands/CommitClassesCommand.java |
102 |
org/jomc/cli/commands/GenerateResourcesCommand.java |
91 |
org/jomc/cli/commands/ManageSourcesCommand.java |
89 |
protected void processClassFiles( final CommandLine commandLine ) throws CommandExecutionException
{
if ( commandLine == null )
{
throw new NullPointerException( "commandLine" );
}
CommandLineClassLoader classLoader = null;
try
{
classLoader = new CommandLineClassLoader( commandLine );
final ModelContext context = this.createModelContext( commandLine, classLoader );
final Model model = this.getModel( context, commandLine );
final JAXBContext jaxbContext = context.createContext( model.getIdentifier() );
final Marshaller marshaller = context.createMarshaller( model.getIdentifier() );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) );
final ModelValidationReport validationReport = context.validateModel( model.getIdentifier(), source );
this.log( validationReport, marshaller );
if ( !validationReport.isModelValid() )
{
throw new CommandExecutionException( Messages.getMessage( "invalidModel",
this.getModel( commandLine ) ) );
}
final ClassFileProcessor tool = this.createClassFileProcessor( commandLine ); |
File |
Line |
org/jomc/cli/commands/CommitClassesCommand.java |
186 |
org/jomc/cli/commands/ValidateClassesCommand.java |
179 |
}
}
classLoader.close();
classLoader = null;
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final ModelException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
catch ( final IOException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
this.log( Level.SEVERE, Messages.getMessage( e ), e );
}
}
}
} |
File |
Line |
org/jomc/cli/commands/GenerateResourcesCommand.java |
145 |
org/jomc/cli/commands/ManageSourcesCommand.java |
143 |
tool.writeResourceBundleResourceFiles( resourcesDirectory );
}
classLoader.close();
classLoader = null;
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final ModelException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
catch ( final IOException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
this.log( Level.SEVERE, Messages.getMessage( e ), e );
}
}
}
} |
File |
Line |
org/jomc/cli/commands/CommitClassesCommand.java |
187 |
org/jomc/cli/commands/GenerateResourcesCommand.java |
146 |
org/jomc/cli/commands/ManageSourcesCommand.java |
144 |
org/jomc/cli/commands/ValidateClassesCommand.java |
180 |
}
classLoader.close();
classLoader = null;
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final ModelException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
catch ( final IOException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
this.log( Level.SEVERE, Messages.getMessage( e ), e );
}
}
}
} |
File |
Line |
org/jomc/cli/commands/AbstractModelCommand.java |
162 |
org/jomc/cli/commands/MergeModulesCommand.java |
170 |
Object o = u.unmarshal( f );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Module )
{
modules.getModule().add( (Module) o );
}
else if ( o instanceof Modules )
{
modules.getModule().addAll( ( (Modules) o ).getModule() );
}
else if ( this.isLoggable( Level.WARNING ) )
{
this.log( Level.WARNING,
Messages.getMessage( "failureProcessing", f.getAbsolutePath(), o.toString() ),
null );
}
}
} |
File |
Line |
org/jomc/cli/commands/CommitClassesCommand.java |
94 |
org/jomc/cli/commands/ValidateClassesCommand.java |
80 |
return Messages.getMessage( "commitClassesShortDescription" );
}
public String getLongDescription( final Locale locale )
{
return null;
}
protected void processClassFiles( final CommandLine commandLine ) throws CommandExecutionException
{
if ( commandLine == null )
{
throw new NullPointerException( "commandLine" );
}
CommandLineClassLoader classLoader = null;
try
{
classLoader = new CommandLineClassLoader( commandLine );
final ModelContext context = this.createModelContext( commandLine, classLoader );
final Model model = this.getModel( context, commandLine );
final JAXBContext jaxbContext = context.createContext( model.getIdentifier() );
final Marshaller marshaller = context.createMarshaller( model.getIdentifier() );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) ); |
File |
Line |
org/jomc/cli/commands/CommitClassesCommand.java |
102 |
org/jomc/cli/commands/GenerateResourcesCommand.java |
91 |
org/jomc/cli/commands/ManageSourcesCommand.java |
89 |
org/jomc/cli/commands/ShowModelCommand.java |
104 |
protected void processClassFiles( final CommandLine commandLine ) throws CommandExecutionException
{
if ( commandLine == null )
{
throw new NullPointerException( "commandLine" );
}
CommandLineClassLoader classLoader = null;
try
{
classLoader = new CommandLineClassLoader( commandLine );
final ModelContext context = this.createModelContext( commandLine, classLoader );
final Model model = this.getModel( context, commandLine );
final JAXBContext jaxbContext = context.createContext( model.getIdentifier() );
final Marshaller marshaller = context.createMarshaller( model.getIdentifier() );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) );
final ModelValidationReport validationReport = context.validateModel( model.getIdentifier(), source ); |
File |
Line |
org/jomc/cli/commands/AbstractModletCommand.java |
365 |
org/jomc/cli/commands/AbstractModletCommand.java |
512 |
final String[] elements = commandLine.getOptionValues( Options.DOCUMENTS_OPTION.getOpt() );
if ( elements != null )
{
for ( final String e : elements )
{
if ( e.startsWith( "@" ) )
{
final File file = new File( e.substring( 1 ) );
BufferedReader reader = null;
try
{
reader = new BufferedReader( new FileReader( file ) );
for ( String line = reader.readLine(); line != null; line = reader.readLine() )
{
line = line.trim();
if ( !line.startsWith( "#" ) )
{
final File f = new File( line );
if ( f.exists() )
{ |
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
207 |
org/jomc/cli/commands/MergeModulesCommand.java |
207 |
DefaultModletProvider.getDefaultModletLocation()
};
}
for ( final String resource : resourceNames )
{
for ( final Enumeration<URL> e = classLoader.getResources( resource ); e.hasMoreElements(); )
{
final URL url = e.nextElement();
if ( this.isLoggable( Level.FINEST ) )
{
this.log( Level.FINEST,
Messages.getMessage( "readingResource", url.toExternalForm() ),
null );
}
Object o = unmarshaller.unmarshal( url );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Modlet ) |
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
182 |
org/jomc/cli/commands/MergeModulesCommand.java |
182 |
modlets.getModlet().addAll( ( (Modlets) o ).getModlet() );
}
else if ( this.isLoggable( Level.WARNING ) )
{
this.log( Level.WARNING,
Messages.getMessage( "failureProcessing", f.getAbsolutePath(), o.toString() ),
null );
}
}
}
if ( commandLine.hasOption( Options.CLASSPATH_OPTION.getOpt() ) )
{
String[] resourceNames = null;
if ( commandLine.hasOption( Options.RESOURCES_OPTION.getOpt() ) )
{
resourceNames = commandLine.getOptionValues( Options.RESOURCES_OPTION.getOpt() );
}
if ( resourceNames == null )
{
resourceNames = new String[]
{ |
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
379 |
org/jomc/cli/commands/MergeModulesCommand.java |
394 |
org/jomc/cli/commands/ShowModelCommand.java |
236 |
throw new CommandExecutionException( message, e );
}
catch ( final JAXBException e )
{
String message = Messages.getMessage( e );
if ( message == null )
{
message = Messages.getMessage( e.getLinkedException() );
}
throw new CommandExecutionException( message, e );
}
catch ( final ModelException e )
{
throw new CommandExecutionException( Messages.getMessage( e ), e );
}
finally
{
try
{
if ( classLoader != null )
{
classLoader.close();
}
}
catch ( final IOException e )
{
this.log( Level.SEVERE, Messages.getMessage( e ), e );
}
}
}
} |
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
158 |
org/jomc/cli/commands/MergeModulesCommand.java |
158 |
modletVendor = commandLine.getOptionValue( Options.MODLET_VENDOR_OPTION.getOpt() );
}
if ( commandLine.hasOption( Options.DOCUMENTS_OPTION.getOpt() ) )
{
for ( final File f : this.getDocumentFiles( commandLine ) )
{
if ( this.isLoggable( Level.FINEST ) )
{
this.log( Level.FINEST, Messages.getMessage( "readingResource", f.getAbsolutePath() ), null );
}
Object o = unmarshaller.unmarshal( f );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Modlet ) |
File |
Line |
org/jomc/cli/commands/GenerateResourcesCommand.java |
91 |
org/jomc/cli/commands/ManageSourcesCommand.java |
89 |
org/jomc/cli/commands/ShowModelCommand.java |
104 |
org/jomc/cli/commands/ValidateClassesCommand.java |
88 |
protected void processResourceFiles( final CommandLine commandLine ) throws CommandExecutionException
{
if ( commandLine == null )
{
throw new NullPointerException( "commandLine" );
}
CommandLineClassLoader classLoader = null;
try
{
classLoader = new CommandLineClassLoader( commandLine );
final ModelContext context = this.createModelContext( commandLine, classLoader );
final Model model = this.getModel( context, commandLine );
final JAXBContext jaxbContext = context.createContext( model.getIdentifier() );
final Marshaller marshaller = context.createMarshaller( model.getIdentifier() );
final Source source = new JAXBSource( jaxbContext, new ObjectFactory().createModel( model ) ); |
File |
Line |
org/jomc/cli/commands/AbstractModelCommand.java |
162 |
org/jomc/cli/commands/MergeModulesCommand.java |
170 |
org/jomc/cli/commands/MergeModulesCommand.java |
225 |
Object o = u.unmarshal( f );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Module )
{
modules.getModule().add( (Module) o );
}
else if ( o instanceof Modules )
{
modules.getModule().addAll( ( (Modules) o ).getModule() );
}
else if ( this.isLoggable( Level.WARNING ) )
{
this.log( Level.WARNING,
Messages.getMessage( "failureProcessing", f.getAbsolutePath(), o.toString() ), |
File |
Line |
org/jomc/cli/commands/MergeModletsCommand.java |
170 |
org/jomc/cli/commands/MergeModletsCommand.java |
225 |
Object o = unmarshaller.unmarshal( f );
if ( o instanceof JAXBElement<?> )
{
o = ( (JAXBElement<?>) o ).getValue();
}
if ( o instanceof Modlet )
{
modlets.getModlet().add( (Modlet) o );
}
else if ( o instanceof Modlets )
{
modlets.getModlet().addAll( ( (Modlets) o ).getModlet() );
}
else if ( this.isLoggable( Level.WARNING ) )
{
this.log( Level.WARNING,
Messages.getMessage( "failureProcessing", f.getAbsolutePath(), o.toString() ), |