diff --git a/pom.xml b/pom.xml index ab9637f..a873a86 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,6 @@ - + - 4.0.0 + 4.0.0 org.codehaus.mojo mojo-parent @@ -8,46 +8,44 @@ idlj-maven-plugin + 1.2.3-SNAPSHOT maven-plugin CORBA IDL Compiler Maven Plugin - 1.2.3-SNAPSHOT - - This plugin is for processing IDL files into java sources. - - - ${mavenVersion} - - - - github - https://github.com/mojohaus/idlj-maven-plugin/issues/ - + This plugin is for processing IDL files into java sources. 2005 + + + Apache License 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + - - russgold - Russell Gold - russell.gold@oracle.com - Oracle Corp. - http://www.oracle.com - - Maintainer - - EST - - - kbravo - Kris Bravo - m2@corridor-software.us - Corridor Software, Inc. - http://www.corridor-software.us - - Maintainer - - EST - + + russgold + Russell Gold + russell.gold@oracle.com + Oracle Corp. + http://www.oracle.com + + Maintainer + + EST + + + kbravo + Kris Bravo + m2@corridor-software.us + Corridor Software, Inc. + http://www.corridor-software.us + + Maintainer + + EST + maguro Alan D. Cabrera @@ -90,14 +88,21 @@ + + ${mavenVersion} + - - - Apache License 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - + + scm:git:https://github.com/mojohaus/idlj-maven-plugin.git + scm:git:ssh://git@github.com/mojohaus/idlj-maven-plugin.git + HEAD + https://github.com/mojohaus/idlj-maven-plugin + + + + github + https://github.com/mojohaus/idlj-maven-plugin/issues/ + 3.9.6 @@ -105,13 +110,6 @@ 8 - - scm:git:https://github.com/mojohaus/idlj-maven-plugin.git - scm:git:ssh://git@github.com/mojohaus/idlj-maven-plugin.git - https://github.com/mojohaus/idlj-maven-plugin - HEAD - - @@ -128,81 +126,81 @@ - - org.apache.maven - maven-model - ${mavenVersion} - provided - - - org.apache.maven - maven-core - ${mavenVersion} - provided - - - org.apache.maven - maven-plugin-api - ${mavenVersion} - provided - - - org.apache.maven.plugin-tools - maven-plugin-annotations - provided - - - org.codehaus.plexus - plexus-utils - 4.0.0 - - - org.codehaus.plexus - plexus-compiler-api - 2.14.2 - + + org.apache.maven + maven-model + ${mavenVersion} + provided + + + org.apache.maven + maven-core + ${mavenVersion} + provided + + + org.apache.maven + maven-plugin-api + ${mavenVersion} + provided + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + + + org.codehaus.plexus + plexus-utils + 4.0.0 + + + org.codehaus.plexus + plexus-compiler-api + 2.14.2 + - - org.glassfish.corba - idlj - ${glassfish.corba.version} - + + org.glassfish.corba + idlj + ${glassfish.corba.version} + - - org.jacorb - jacorb-idl-compiler - 3.9 - true - + + org.jacorb + jacorb-idl-compiler + 3.9 + true + - - org.hamcrest - hamcrest-all - 1.3 - test - - - junit - junit - 4.13.2 - test - - - com.meterware.simplestub - simplestub - 1.3.3 - test - - - org.glassfish.corba - glassfish-corba-omgapi - test - - - org.glassfish.corba - glassfish-corba-orb - test - + + org.hamcrest + hamcrest-all + 1.3 + test + + + junit + junit + 4.13.2 + test + + + com.meterware.simplestub + simplestub + 1.3.3 + test + + + org.glassfish.corba + glassfish-corba-omgapi + test + + + org.glassfish.corba + glassfish-corba-orb + test + @@ -220,7 +218,7 @@ - enforce + enforce diff --git a/src/main/java/org/codehaus/mojo/idlj/AbstractIDLJMojo.java b/src/main/java/org/codehaus/mojo/idlj/AbstractIDLJMojo.java index ee586fc..b61cdcf 100644 --- a/src/main/java/org/codehaus/mojo/idlj/AbstractIDLJMojo.java +++ b/src/main/java/org/codehaus/mojo/idlj/AbstractIDLJMojo.java @@ -19,14 +19,6 @@ * under the License. */ -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugins.annotations.Parameter; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; -import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; -import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; - import java.io.File; import java.io.IOException; import java.net.URI; @@ -35,6 +27,14 @@ import java.util.List; import java.util.Set; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.compiler.util.scan.InclusionScanException; +import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; +import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping; + import static org.codehaus.mojo.idlj.TranslatorType.AUTO; /** @@ -43,8 +43,7 @@ * @author Anders Hessellund Jensen * @version $Id$ */ -public abstract class AbstractIDLJMojo extends AbstractMojo -{ +public abstract class AbstractIDLJMojo extends AbstractMojo { /** * A List of Source configurations to compile. */ @@ -102,22 +101,18 @@ public abstract class AbstractIDLJMojo extends AbstractMojo */ private static final DependenciesFacade DEPENDENCIES_FACADE = new DependenciesFacadeImpl(); - /** * Creates the abstract class using a production implementation of the dependencies. */ - protected AbstractIDLJMojo() - { - this( DEPENDENCIES_FACADE ); + protected AbstractIDLJMojo() { + this(DEPENDENCIES_FACADE); } - AbstractIDLJMojo( DependenciesFacade dependencies ) - { + AbstractIDLJMojo(DependenciesFacade dependencies) { this(dependencies, AUTO); } - AbstractIDLJMojo(DependenciesFacade dependencies, TranslatorType translatorType) - { + AbstractIDLJMojo(DependenciesFacade dependencies, TranslatorType translatorType) { this.dependencies = dependencies; this.compiler = translatorType.getSelector(); } @@ -135,8 +130,7 @@ protected AbstractIDLJMojo() /** * @return a List of directory to use as include */ - final File[] getIncludeDirs() - { + final File[] getIncludeDirs() { return includeDirs; } @@ -145,70 +139,56 @@ final File[] getIncludeDirs() * * @throws MojoExecutionException if the compilation fails or the compiler crashes */ - public void execute() throws MojoExecutionException - { - prepareGeneratedSourceDirectory( getOutputDirectory() ); - createIfAbsent( timestampDirectory ); - - if ( isSourceSpecified() ) - { - translateSources( createTranslator(), sources ); - } - else - { - translateInferredSource( createTranslator() ); + public void execute() throws MojoExecutionException { + prepareGeneratedSourceDirectory(getOutputDirectory()); + createIfAbsent(timestampDirectory); + + if (isSourceSpecified()) { + translateSources(createTranslator(), sources); + } else { + translateInferredSource(createTranslator()); } } - private void prepareGeneratedSourceDirectory( File directory ) throws MojoExecutionException - { - createIfAbsent( directory ); - failIfNotWriteable( directory ); - addCompileSourceRoot( directory ); + private void prepareGeneratedSourceDirectory(File directory) throws MojoExecutionException { + createIfAbsent(directory); + failIfNotWriteable(directory); + addCompileSourceRoot(directory); } - private boolean isSourceSpecified() - { + private boolean isSourceSpecified() { return sources != null; } - private void translateInferredSource( CompilerTranslator translator ) throws MojoExecutionException - { - processSource( new Source(), translator ); + private void translateInferredSource(CompilerTranslator translator) throws MojoExecutionException { + processSource(new Source(), translator); } - private void translateSources( CompilerTranslator translator, List sourceList ) - throws MojoExecutionException - { - for ( Source source : sourceList ) - { - processSource( source, translator ); + private void translateSources(CompilerTranslator translator, List sourceList) + throws MojoExecutionException { + for (Source source : sourceList) { + processSource(source, translator); } } - private CompilerTranslator createTranslator() throws MojoExecutionException - { - CompilerTranslator translator = TranslatorType.selectTranslator( compiler ); + private CompilerTranslator createTranslator() throws MojoExecutionException { + CompilerTranslator translator = TranslatorType.selectTranslator(compiler); - translator.setDebug( debug ); - translator.setFailOnError( failOnError ); - translator.setLog( getLog() ); + translator.setDebug(debug); + translator.setFailOnError(failOnError); + translator.setLog(getLog()); return translator; } - private void failIfNotWriteable( File directory ) throws MojoExecutionException - { - if ( !dependencies.isWriteable( directory ) ) - { - throw new MojoExecutionException( "Cannot write in : " + directory ); + private void failIfNotWriteable(File directory) throws MojoExecutionException { + if (!dependencies.isWriteable(directory)) { + throw new MojoExecutionException("Cannot write in : " + directory); } } - private void createIfAbsent( File directory ) - { - if ( !dependencies.exists( directory ) ) - { - dependencies.createDirectory( directory ); + private void createIfAbsent(File directory) { + if (!dependencies.exists(directory)) { + dependencies.createDirectory(directory); } } @@ -219,58 +199,47 @@ private void createIfAbsent( File directory ) * @param translator the CompilerTranslator that raprresents idl compiler backend that will be used * @throws MojoExecutionException if the compilation fails or the compiler crashes */ - private void processSource( Source source, CompilerTranslator translator ) - throws MojoExecutionException - { - Set staleGrammars = computeStaleGrammars( source ); - reportProcessingNeeded( staleGrammars ); - - for ( File idlFile : staleGrammars ) - { - processIdlFile( source, translator, idlFile ); + private void processSource(Source source, CompilerTranslator translator) throws MojoExecutionException { + Set staleGrammars = computeStaleGrammars(source); + reportProcessingNeeded(staleGrammars); + + for (File idlFile : staleGrammars) { + processIdlFile(source, translator, idlFile); } } - private void processIdlFile( Source source, CompilerTranslator translator, File idlFile ) - throws MojoExecutionException - { - try - { - translateIdlFile( idlFile, source, translator ); - copyToTimestampDirectory( idlFile ); - } - catch ( IOException e ) - { - getLog().warn( "Failed to copy IDL file to timestamp directory: " + e ); + private void processIdlFile(Source source, CompilerTranslator translator, File idlFile) + throws MojoExecutionException { + try { + translateIdlFile(idlFile, source, translator); + copyToTimestampDirectory(idlFile); + } catch (IOException e) { + getLog().warn("Failed to copy IDL file to timestamp directory: " + e); } } - private void translateIdlFile( File idlFile, Source source, CompilerTranslator translator ) - throws MojoExecutionException - { - getLog().debug( "Processing: " + idlFile.toString() ); - translator.invokeCompiler( getSourceDirectory().getAbsolutePath(), - getIncludeDirs(), - getOutputDirectory().getAbsolutePath(), - idlFile.toString(), source ); + private void translateIdlFile(File idlFile, Source source, CompilerTranslator translator) + throws MojoExecutionException { + getLog().debug("Processing: " + idlFile.toString()); + translator.invokeCompiler( + getSourceDirectory().getAbsolutePath(), + getIncludeDirs(), + getOutputDirectory().getAbsolutePath(), + idlFile.toString(), + source); } - private void copyToTimestampDirectory( File idlFile ) throws IOException - { - URI relativeURI = getSourceDirectory().toURI().relativize( idlFile.toURI() ); - File timestampFile = new File( timestampDirectory.toURI().resolve( relativeURI ) ); - dependencies.copyFile( idlFile, timestampFile ); + private void copyToTimestampDirectory(File idlFile) throws IOException { + URI relativeURI = getSourceDirectory().toURI().relativize(idlFile.toURI()); + File timestampFile = new File(timestampDirectory.toURI().resolve(relativeURI)); + dependencies.copyFile(idlFile, timestampFile); } - private void reportProcessingNeeded( Set staleGrammars ) - { - if ( staleGrammars.size() > 0 ) - { - getLog().info( "Processing " + staleGrammars.size() + " grammar files to " + getOutputDirectory() ); - } - else - { - getLog().info( "Nothing to compile - all idl files are up to date" ); + private void reportProcessingNeeded(Set staleGrammars) { + if (staleGrammars.size() > 0) { + getLog().info("Processing " + staleGrammars.size() + " grammar files to " + getOutputDirectory()); + } else { + getLog().info("Nothing to compile - all idl files are up to date"); } } @@ -281,63 +250,50 @@ private void reportProcessingNeeded( Set staleGrammars ) * @return a set of files that need to be compiled * @throws MojoExecutionException if the selection of the files to compile fails */ - private Set computeStaleGrammars( Source source ) throws MojoExecutionException - { + private Set computeStaleGrammars(Source source) throws MojoExecutionException { File sourceDir = getSourceDirectory(); - getLog().debug( "sourceDir : " + sourceDir ); + getLog().debug("sourceDir : " + sourceDir); - return getStaleSources( createIdlScanner( source ), sourceDir ); + return getStaleSources(createIdlScanner(source), sourceDir); } - private Set getStaleSources( SourceInclusionScanner scanner, File sourceDir ) throws MojoExecutionException - { - try - { - return tryToGetStaleSources( scanner, sourceDir ); - } - catch ( InclusionScanException e ) - { - throw new MojoExecutionException( "Error scanning source root: '" + sourceDir - + "' for stale CORBA IDL files to reprocess.", e ); + private Set getStaleSources(SourceInclusionScanner scanner, File sourceDir) throws MojoExecutionException { + try { + return tryToGetStaleSources(scanner, sourceDir); + } catch (InclusionScanException e) { + throw new MojoExecutionException( + "Error scanning source root: '" + sourceDir + "' for stale CORBA IDL files to reprocess.", e); } } - private Set tryToGetStaleSources( SourceInclusionScanner scanner, - File sourceDir ) throws InclusionScanException - { - if ( isExistingDirectory( sourceDir ) ) - { - return scanner.getIncludedSources( sourceDir, timestampDirectory ); - } - else - { - getLog().debug( "sourceDir isn't a directory" ); + private Set tryToGetStaleSources(SourceInclusionScanner scanner, File sourceDir) + throws InclusionScanException { + if (isExistingDirectory(sourceDir)) { + return scanner.getIncludedSources(sourceDir, timestampDirectory); + } else { + getLog().debug("sourceDir isn't a directory"); return new HashSet<>(); } } - private boolean isExistingDirectory( File sourceDir ) - { - return dependencies.exists( sourceDir ) && dependencies.isDirectory( sourceDir ); + private boolean isExistingDirectory(File sourceDir) { + return dependencies.exists(sourceDir) && dependencies.isDirectory(sourceDir); } - private SourceInclusionScanner createIdlScanner( Source source ) - { - Set includes = getNonNullSet( "includes", source.getIncludes(), "**/*.idl" ); - Set excludes = getNonNullSet( "excludes", source.getExcludes() ); + private SourceInclusionScanner createIdlScanner(Source source) { + Set includes = getNonNullSet("includes", source.getIncludes(), "**/*.idl"); + Set excludes = getNonNullSet("excludes", source.getExcludes()); - SourceInclusionScanner scanner = dependencies.createSourceInclusionScanner( staleMillis, includes, excludes ); - scanner.addSourceMapping( new SuffixMapping( ".idl", ".idl" ) ); + SourceInclusionScanner scanner = dependencies.createSourceInclusionScanner(staleMillis, includes, excludes); + scanner.addSourceMapping(new SuffixMapping(".idl", ".idl")); return scanner; } - private Set getNonNullSet( String comment, Set set, String... defaultValues ) - { - getLog().debug( comment + ": " + set ); - if ( set == null ) - { + private Set getNonNullSet(String comment, Set set, String... defaultValues) { + getLog().debug(comment + ": " + set); + if (set == null) { set = new HashSet<>(); - Collections.addAll( set, defaultValues ); + Collections.addAll(set, defaultValues); } return set; } @@ -347,13 +303,12 @@ private Set getNonNullSet( String comment, Set set, String... de * * @param directory a directory containing generated java files to be compiled. */ - protected abstract void addCompileSourceRoot( File directory ); + protected abstract void addCompileSourceRoot(File directory); /** * @return the current MavenProject instance */ - protected MavenProject getProject() - { + protected MavenProject getProject() { return project; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/AbstractTranslator.java b/src/main/java/org/codehaus/mojo/idlj/AbstractTranslator.java index e8dcc1f..91d9d4a 100644 --- a/src/main/java/org/codehaus/mojo/idlj/AbstractTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/AbstractTranslator.java @@ -19,9 +19,6 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.logging.Log; - import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -29,15 +26,16 @@ import java.net.URLClassLoader; import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.logging.Log; + /** * Shared capabilities for translators. * * @author Arnaud Heritier * @version $Id: AbstractIDLJMojo.java 9189 2009-03-10 21:47:46Z aheritier $ */ -abstract class AbstractTranslator - implements CompilerTranslator -{ +abstract class AbstractTranslator implements CompilerTranslator { /** * enable/disable debug messages @@ -65,48 +63,42 @@ abstract class AbstractTranslator /** * @return the debug */ - public boolean isDebug() - { + public boolean isDebug() { return debug; } /** * @param debug the debug to set */ - public void setDebug( boolean debug ) - { + public void setDebug(boolean debug) { this.debug = debug; } /** * @return the log */ - Log getLog() - { + Log getLog() { return log; } /** * @param log the log to set */ - public void setLog( Log log ) - { + public void setLog(Log log) { this.log = log; } /** * @return the failOnError */ - boolean isFailOnError() - { + boolean isFailOnError() { return failOnError; } /** * @param failOnError the failOnError to set */ - public void setFailOnError( boolean failOnError ) - { + public void setFailOnError(boolean failOnError) { this.failOnError = failOnError; } @@ -114,8 +106,7 @@ public void setFailOnError( boolean failOnError ) * Returns true if the translator is allowed to create a new forked process. * @return true if forking is permitted */ - static boolean isFork() - { + static boolean isFork() { return fork; } @@ -123,8 +114,7 @@ static boolean isFork() * Specifies the implementation of the classloader facade to use * @param classLoaderFacade a wrapper for class loading. */ - static void setClassLoaderFacade( ClassLoaderFacade classLoaderFacade ) - { + static void setClassLoaderFacade(ClassLoaderFacade classLoaderFacade) { AbstractTranslator.classLoaderFacade = classLoaderFacade; AbstractTranslator.fork = false; } @@ -133,8 +123,7 @@ static void setClassLoaderFacade( ClassLoaderFacade classLoaderFacade ) * Returns the object to use for classloading. * @return the appropriate loader facade */ - static ClassLoaderFacade getClassLoaderFacade() - { + static ClassLoaderFacade getClassLoaderFacade() { return classLoaderFacade; } @@ -144,55 +133,44 @@ static ClassLoaderFacade getClassLoaderFacade() * @param args the arguments to pass to the compiler * @throws MojoExecutionException if any error occurs */ - void invokeCompilerInProcess( Class compilerClass, List args ) throws MojoExecutionException - { - String[] arguments = args.toArray( new String[args.size()] ); + void invokeCompilerInProcess(Class compilerClass, List args) throws MojoExecutionException { + String[] arguments = args.toArray(new String[args.size()]); - getLog().debug( getCommandLine( compilerClass, arguments ) ); + getLog().debug(getCommandLine(compilerClass, arguments)); // Local channels ByteArrayOutputStream err = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); - int exitCode = runCompilerAndRecordOutput( compilerClass, arguments, err, out ); - logOutputMessages( err, out ); + int exitCode = runCompilerAndRecordOutput(compilerClass, arguments, err, out); + logOutputMessages(err, out); - if ( isFailOnError() && isCompilationFailed( err, exitCode ) ) - { - throw new MojoExecutionException( "IDL compilation failed" ); + if (isFailOnError() && isCompilationFailed(err, exitCode)) { + throw new MojoExecutionException("IDL compilation failed"); } } - private int runCompilerAndRecordOutput( Class compilerClass, String[] arguments, ByteArrayOutputStream err, - ByteArrayOutputStream out ) throws MojoExecutionException - { + private int runCompilerAndRecordOutput( + Class compilerClass, String[] arguments, ByteArrayOutputStream err, ByteArrayOutputStream out) + throws MojoExecutionException { // Backup std channels PrintStream stdErr = System.err; PrintStream stdOut = System.out; - System.setErr( new PrintStream( err ) ); - System.setOut( new PrintStream( out ) ); - try - { - return runCompiler( compilerClass, arguments ); - } - catch ( NoSuchMethodException e ) - { - throw new MojoExecutionException( "Error: Compiler had no main method" ); - } - catch ( InvocationTargetException e ) - { - throw new MojoExecutionException( "IDL compilation failed", e.getTargetException() ); - } - catch ( Throwable e ) - { - throw new MojoExecutionException( "IDL compilation failed", e ); - } - finally - { + System.setErr(new PrintStream(err)); + System.setOut(new PrintStream(out)); + try { + return runCompiler(compilerClass, arguments); + } catch (NoSuchMethodException e) { + throw new MojoExecutionException("Error: Compiler had no main method"); + } catch (InvocationTargetException e) { + throw new MojoExecutionException("IDL compilation failed", e.getTargetException()); + } catch (Throwable e) { + throw new MojoExecutionException("IDL compilation failed", e); + } finally { // Restore std channels - System.setErr( stdErr ); - System.setOut( stdOut ); + System.setErr(stdErr); + System.setOut(stdOut); } } @@ -205,49 +183,39 @@ private int runCompilerAndRecordOutput( Class compilerClass, String[] argumen * @throws IllegalAccessException if no constructor is available * @throws InvocationTargetException if an error occurs while invoking the compiler */ - protected abstract int runCompiler( Class compilerClass, String... arguments ) + protected abstract int runCompiler(Class compilerClass, String... arguments) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException; - private boolean isCompilationFailed( ByteArrayOutputStream err, int exitCode ) - { - return exitCode != 0 || hasErrors( err ); + private boolean isCompilationFailed(ByteArrayOutputStream err, int exitCode) { + return exitCode != 0 || hasErrors(err); } - private boolean hasErrors( ByteArrayOutputStream err ) - { - for ( String message : err.toString().split( "\n" ) ) - { - if ( message.contains( "(line " ) && !message.contains( "WARNING" ) ) - { - getLog().debug( "Failed due to error: <" + message + ">" ); + private boolean hasErrors(ByteArrayOutputStream err) { + for (String message : err.toString().split("\n")) { + if (message.contains("(line ") && !message.contains("WARNING")) { + getLog().debug("Failed due to error: <" + message + ">"); return true; } } return false; } - private void logOutputMessages( ByteArrayOutputStream err, ByteArrayOutputStream out ) - { - if ( isNotEmpty( out ) ) - { - getLog().info( out.toString() ); + private void logOutputMessages(ByteArrayOutputStream err, ByteArrayOutputStream out) { + if (isNotEmpty(out)) { + getLog().info(out.toString()); } - if ( isNotEmpty( err ) ) - { - getLog().error( err.toString() ); + if (isNotEmpty(err)) { + getLog().error(err.toString()); } } - private boolean isNotEmpty( ByteArrayOutputStream outputStream ) - { - return !"".equals( outputStream.toString() ); + private boolean isNotEmpty(ByteArrayOutputStream outputStream) { + return !"".equals(outputStream.toString()); } - private String getCommandLine( Class compilerClass, String[] arguments ) - { + private String getCommandLine(Class compilerClass, String[] arguments) { String command = compilerClass.getName(); - for ( String argument : arguments ) - { + for (String argument : arguments) { command += " " + argument; } return command; @@ -256,14 +224,13 @@ private String getCommandLine( Class compilerClass, String[] arguments ) /** * An interface for loading the proper IDL compiler class. */ - interface ClassLoaderFacade - { + interface ClassLoaderFacade { /** * Updates the active classloader to include the specified URLs before the original definitions. * * @param urls a list of URLs to include when searching for classes. */ - void prependUrls( URL... urls ); + void prependUrls(URL... urls); /** * Loads the specified class using the appropriate classloader. @@ -272,25 +239,21 @@ interface ClassLoaderFacade * @throws ClassNotFoundException if the specified class doesn't exist * @return the actual compiler class to use */ - Class loadClass( String idlCompilerClass ) throws ClassNotFoundException; + Class loadClass(String idlCompilerClass) throws ClassNotFoundException; } /** * The implementation of ClassLoaderFacade used at runtime. */ - private static class ClassLoaderFacadeImpl implements ClassLoaderFacade - { + private static class ClassLoaderFacadeImpl implements ClassLoaderFacade { ClassLoader classLoader = getClass().getClassLoader(); - public void prependUrls( URL... urls ) - { - classLoader = new URLClassLoader( urls, classLoader ); + public void prependUrls(URL... urls) { + classLoader = new URLClassLoader(urls, classLoader); } - public Class loadClass( String idlCompilerClass ) throws ClassNotFoundException - { - return classLoader.loadClass( idlCompilerClass ); + public Class loadClass(String idlCompilerClass) throws ClassNotFoundException { + return classLoader.loadClass(idlCompilerClass); } - } } diff --git a/src/main/java/org/codehaus/mojo/idlj/BuiltInTranslator.java b/src/main/java/org/codehaus/mojo/idlj/BuiltInTranslator.java index 13e709e..61999f8 100644 --- a/src/main/java/org/codehaus/mojo/idlj/BuiltInTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/BuiltInTranslator.java @@ -19,13 +19,13 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; - import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; + import static org.codehaus.mojo.idlj.TranslatorType.isJavaModuleSystemPresent; /** @@ -34,104 +34,84 @@ * @author Anders Hessellund Jensen * @version $Id$ */ -class BuiltInTranslator - extends IdljTranslator -{ +class BuiltInTranslator extends IdljTranslator { private static final String AIX_IDLJ_COMPILER_NAME = "com.ibm.idl.toJavaPortable.Compile"; private static final String ORACLE_IDLJ_COMPILER_NAME = "com.sun.tools.corba.se.idl.toJavaPortable.Compile"; private static final String USE_GLASSFISH_IDL = - " Built-in IDL compiler not available in JDK9. Use the glassfish compiler instead."; + " Built-in IDL compiler not available in JDK9. Use the glassfish compiler instead."; private static final String IDL_COMPILER_NOT_AVAILABLE = " IDL compiler not available"; /** * Default constructor */ - BuiltInTranslator() - { + BuiltInTranslator() { super(); } @Override - void invokeCompiler( List args ) throws MojoExecutionException - { + void invokeCompiler(List args) throws MojoExecutionException { Class compilerClass = getCompilerClass(); - invokeCompiler( compilerClass, args ); + invokeCompiler(compilerClass, args); } /** * @return the Class that implements the idlj compiler * @throws MojoExecutionException if the search for the class fails */ - private static Class getCompilerClass() - throws MojoExecutionException - { - try - { - return getClassLoaderFacade().loadClass( getIDLCompilerClassName() ); - } - catch ( ClassNotFoundException e ) - { - try - { + private static Class getCompilerClass() throws MojoExecutionException { + try { + return getClassLoaderFacade().loadClass(getIDLCompilerClassName()); + } catch (ClassNotFoundException e) { + try { addToolsJarToPath(); - return getClassLoaderFacade().loadClass( getIDLCompilerClassName() ); + return getClassLoaderFacade().loadClass(getIDLCompilerClassName()); + } catch (Exception e2) { + throw new MojoExecutionException(getSecondTryMessage(e2), e); } - catch ( Exception e2 ) - { - throw new MojoExecutionException( getSecondTryMessage( e2 ), e ); - } - } - catch ( Exception e ) - { - throw new MojoExecutionException( IDL_COMPILER_NOT_AVAILABLE, e ); + } catch (Exception e) { + throw new MojoExecutionException(IDL_COMPILER_NOT_AVAILABLE, e); } } - private static String getSecondTryMessage( Exception e ) - { - return builtInCompilerHidden( e ) ? USE_GLASSFISH_IDL : IDL_COMPILER_NOT_AVAILABLE; + private static String getSecondTryMessage(Exception e) { + return builtInCompilerHidden(e) ? USE_GLASSFISH_IDL : IDL_COMPILER_NOT_AVAILABLE; } - private static boolean builtInCompilerHidden( Exception e ) - { - return compilerNotFound( e ) && isJavaModuleSystemPresent(); + private static boolean builtInCompilerHidden(Exception e) { + return compilerNotFound(e) && isJavaModuleSystemPresent(); } - private static boolean compilerNotFound( Exception e ) - { + private static boolean compilerNotFound(Exception e) { return e instanceof ClassNotFoundException; } - private static void addToolsJarToPath() throws MalformedURLException, ClassNotFoundException - { - File javaHome = new File( System.getProperty( "java.home" ) ); - File toolsJar = new File( javaHome, "../lib/tools.jar" ); + private static void addToolsJarToPath() throws MalformedURLException, ClassNotFoundException { + File javaHome = new File(System.getProperty("java.home")); + File toolsJar = new File(javaHome, "../lib/tools.jar"); URL toolsJarUrl = toolsJar.toURI().toURL(); - getClassLoaderFacade().prependUrls( toolsJarUrl ); + getClassLoaderFacade().prependUrls(toolsJarUrl); // Unfortunately the idlj compiler reads messages using the system class path. // Therefore this really nasty hack is required. - System.setProperty( "java.class.path", System.getProperty( "java.class.path" ) - + System.getProperty( "path.separator" ) + toolsJar.getAbsolutePath() ); - if ( System.getProperty( "java.vm.name" ).contains( "HotSpot" ) ) - { - getClassLoaderFacade().loadClass( "com.sun.tools.corba.se.idl.som.cff.FileLocator" ); + System.setProperty( + "java.class.path", + System.getProperty("java.class.path") + + System.getProperty("path.separator") + + toolsJar.getAbsolutePath()); + if (System.getProperty("java.vm.name").contains("HotSpot")) { + getClassLoaderFacade().loadClass("com.sun.tools.corba.se.idl.som.cff.FileLocator"); } } - /** * @return the name of the class that implements the compiler */ - private static String getIDLCompilerClassName() - { + private static String getIDLCompilerClassName() { return isAix() ? AIX_IDLJ_COMPILER_NAME : ORACLE_IDLJ_COMPILER_NAME; } - - private static boolean isAix() - { - return System.getProperty( "java.vm.vendor" ).contains( "IBM" ); + private static boolean isAix() { + return System.getProperty("java.vm.vendor").contains("IBM"); } } diff --git a/src/main/java/org/codehaus/mojo/idlj/CompilerTranslator.java b/src/main/java/org/codehaus/mojo/idlj/CompilerTranslator.java index 3b385e4..789ba0e 100644 --- a/src/main/java/org/codehaus/mojo/idlj/CompilerTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/CompilerTranslator.java @@ -19,19 +19,18 @@ * under the License. */ +import java.io.File; + import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; -import java.io.File; - /** * This is the interface to implement in order to add a new compiler backend to this plugin * * @author Anders Hessellund Jensen * @version $Id$ */ -public interface CompilerTranslator -{ +public interface CompilerTranslator { /** * This method it's used to invoke the compiler @@ -43,8 +42,8 @@ public interface CompilerTranslator * @param source the source set on which to run the compiler * @throws MojoExecutionException the exeception is thrown whenever the compilation fails or crashes */ - void invokeCompiler( String sourceDirectory, File[] includeDirs, - String targetDirectory, String idlFile, Source source ) + void invokeCompiler( + String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, Source source) throws MojoExecutionException; /** @@ -52,19 +51,19 @@ void invokeCompiler( String sourceDirectory, File[] includeDirs, * * @param debug the debug to set */ - void setDebug( boolean debug ); + void setDebug(boolean debug); /** * The Log that will used for the messages * * @param log the log to set */ - void setLog( Log log ); + void setLog(Log log); /** * Set to true to fail the build if an error occur while compiling the IDL. * * @param failOnError the failOnError to set */ - void setFailOnError( boolean failOnError ); + void setFailOnError(boolean failOnError); } diff --git a/src/main/java/org/codehaus/mojo/idlj/Define.java b/src/main/java/org/codehaus/mojo/idlj/Define.java index 39be5a9..eb5850f 100644 --- a/src/main/java/org/codehaus/mojo/idlj/Define.java +++ b/src/main/java/org/codehaus/mojo/idlj/Define.java @@ -2,41 +2,40 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, + * + * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations * under the License. */ /** * This class is used to rappresent the definition of a define - * + * * @author Anders Hessellund Jensen * @version $Id$ */ -public class Define -{ +public class Define { /** * The symbol to define - * + * * @parameter symbol */ private String symbol; /** * The value of the symbol. This is optional. - * + * * @parameter value */ private String value; @@ -44,16 +43,14 @@ public class Define /** * @return The name of the symbol defined */ - public String getSymbol() - { + public String getSymbol() { return symbol; } /** * @return The value of the symbol defined */ - public String getValue() - { + public String getValue() { return value; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/DependenciesFacade.java b/src/main/java/org/codehaus/mojo/idlj/DependenciesFacade.java index 68da490..05e5708 100644 --- a/src/main/java/org/codehaus/mojo/idlj/DependenciesFacade.java +++ b/src/main/java/org/codehaus/mojo/idlj/DependenciesFacade.java @@ -1,23 +1,22 @@ package org.codehaus.mojo.idlj; -import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; - import java.io.File; import java.io.IOException; import java.util.Set; -interface DependenciesFacade -{ - SourceInclusionScanner createSourceInclusionScanner(int updatedWithinMsecs, Set includes, - Set excludes ); +import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; + +interface DependenciesFacade { + SourceInclusionScanner createSourceInclusionScanner( + int updatedWithinMsecs, Set includes, Set excludes); - void copyFile(File sourceFile, File targetFile ) throws IOException; + void copyFile(File sourceFile, File targetFile) throws IOException; - boolean exists( File outputDirectory ); + boolean exists(File outputDirectory); - void createDirectory( File directory ); + void createDirectory(File directory); - boolean isWriteable( File directory ); + boolean isWriteable(File directory); - boolean isDirectory( File file ); + boolean isDirectory(File file); } diff --git a/src/main/java/org/codehaus/mojo/idlj/DependenciesFacadeImpl.java b/src/main/java/org/codehaus/mojo/idlj/DependenciesFacadeImpl.java index 651496d..878176a 100644 --- a/src/main/java/org/codehaus/mojo/idlj/DependenciesFacadeImpl.java +++ b/src/main/java/org/codehaus/mojo/idlj/DependenciesFacadeImpl.java @@ -1,42 +1,36 @@ package org.codehaus.mojo.idlj; -import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; -import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner; -import org.codehaus.plexus.util.FileUtils; - import java.io.File; import java.io.IOException; import java.util.Set; +import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; +import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner; +import org.codehaus.plexus.util.FileUtils; + class DependenciesFacadeImpl implements DependenciesFacade { - public void copyFile(File sourceFile, File targetFile) throws IOException - { + public void copyFile(File sourceFile, File targetFile) throws IOException { FileUtils.copyFile(sourceFile, targetFile); } - public SourceInclusionScanner createSourceInclusionScanner(int updatedWithinMsecs, Set includes, - Set excludes) - { + public SourceInclusionScanner createSourceInclusionScanner( + int updatedWithinMsecs, Set includes, Set excludes) { return new StaleSourceScanner(updatedWithinMsecs, includes, excludes); } - public boolean exists(File file) - { + public boolean exists(File file) { return file.exists(); } - public void createDirectory(File directory) - { + public void createDirectory(File directory) { directory.mkdirs(); } - public boolean isWriteable(File directory) - { + public boolean isWriteable(File directory) { return directory.canWrite(); } - public boolean isDirectory(File file) - { + public boolean isDirectory(File file) { return file.isDirectory(); } } diff --git a/src/main/java/org/codehaus/mojo/idlj/GlassfishTranslator.java b/src/main/java/org/codehaus/mojo/idlj/GlassfishTranslator.java index d905482..9b36923 100644 --- a/src/main/java/org/codehaus/mojo/idlj/GlassfishTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/GlassfishTranslator.java @@ -19,35 +19,28 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; - import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; + /** * This class implements the CompilerTranslator for the Glassfish idlj compiler * * @author Russell Gold */ -class GlassfishTranslator - extends IdljTranslator -{ +class GlassfishTranslator extends IdljTranslator { private static final String GLASSFISH_IDLJ_COMPILER_NAME = "com.sun.tools.corba.ee.idl.toJavaPortable.Compile"; @Override - void invokeCompiler( List args ) throws MojoExecutionException - { - invokeCompilerInProcess( getCompilerClass(), args ); + void invokeCompiler(List args) throws MojoExecutionException { + invokeCompilerInProcess(getCompilerClass(), args); } - private Class getCompilerClass() throws MojoExecutionException - { - try - { - return getClassLoaderFacade().loadClass( GLASSFISH_IDLJ_COMPILER_NAME ); - } - catch ( ClassNotFoundException e ) - { - throw new MojoExecutionException( " IDL compiler not available", e ); + private Class getCompilerClass() throws MojoExecutionException { + try { + return getClassLoaderFacade().loadClass(GLASSFISH_IDLJ_COMPILER_NAME); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException(" IDL compiler not available", e); } } } diff --git a/src/main/java/org/codehaus/mojo/idlj/IDLJMojo.java b/src/main/java/org/codehaus/mojo/idlj/IDLJMojo.java index 83d93b0..eb5bbca 100644 --- a/src/main/java/org/codehaus/mojo/idlj/IDLJMojo.java +++ b/src/main/java/org/codehaus/mojo/idlj/IDLJMojo.java @@ -19,12 +19,12 @@ * under the License. */ +import java.io.File; + import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; - /** * Process CORBA IDL files in IDLJ. * @@ -32,9 +32,7 @@ * @version $Id$ */ @Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES) -public class IDLJMojo - extends AbstractIDLJMojo -{ +public class IDLJMojo extends AbstractIDLJMojo { /** * The source directory containing *.idl files. */ @@ -47,32 +45,26 @@ public class IDLJMojo @Parameter(defaultValue = "${project.build.directory}/generated-sources/idl") private File outputDirectory; - /** * Constructs a standard IDL translation Mojo. */ - public IDLJMojo() - { - } + public IDLJMojo() {} - IDLJMojo( DependenciesFacade dependenciesFacade ) - { - super( dependenciesFacade ); + IDLJMojo(DependenciesFacade dependenciesFacade) { + super(dependenciesFacade); } /** * @return the source directory that contains the IDL files */ - protected File getSourceDirectory() - { + protected File getSourceDirectory() { return sourceDirectory; } /** * @return the path of the directory that will contains the results of the compilation */ - protected File getOutputDirectory() - { + protected File getOutputDirectory() { return outputDirectory; } @@ -81,8 +73,7 @@ protected File getOutputDirectory() * * @param dir the path of directory that contains the IDL files */ - protected void setSourceDirectory( File dir ) - { + protected void setSourceDirectory(File dir) { this.sourceDirectory = dir; } @@ -91,9 +82,7 @@ protected void setSourceDirectory( File dir ) * * @param directory a directory containing generated java files to be compiled. */ - protected void addCompileSourceRoot( File directory ) - { - getProject().addCompileSourceRoot( directory.getPath() ); + protected void addCompileSourceRoot(File directory) { + getProject().addCompileSourceRoot(directory.getPath()); } - } diff --git a/src/main/java/org/codehaus/mojo/idlj/IdljTranslator.java b/src/main/java/org/codehaus/mojo/idlj/IdljTranslator.java index 9fbb9f3..227dfad 100644 --- a/src/main/java/org/codehaus/mojo/idlj/IdljTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/IdljTranslator.java @@ -19,9 +19,6 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; -import org.codehaus.plexus.util.StringUtils; - import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -29,20 +26,21 @@ import java.util.ArrayList; import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.StringUtils; + /** * Parent class for translators that use the IDLJ parameters. */ -abstract class IdljTranslator extends AbstractTranslator implements CompilerTranslator -{ +abstract class IdljTranslator extends AbstractTranslator implements CompilerTranslator { /** * Convert the provided filename from a Windows separator \\ to a unix/java separator / * * @param filename file name to fix separator * @return filename with all \\ replaced with / */ - private static String fixSeparator( String filename ) - { - return StringUtils.replace( filename, '\\', '/' ); + private static String fixSeparator(String filename) { + return StringUtils.replace(filename, '\\', '/'); } /** @@ -52,16 +50,11 @@ private static String fixSeparator( String filename ) * @return the computed path * @throws MojoExecutionException if the infrastructure detects a problem */ - private static String getCanonicalPath( File file ) - throws MojoExecutionException - { - try - { + private static String getCanonicalPath(File file) throws MojoExecutionException { + try { return file.getCanonicalPath(); - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Can't canonicalize system path: " + file.getAbsolutePath(), e ); + } catch (IOException e) { + throw new MojoExecutionException("Can't canonicalize system path: " + file.getAbsolutePath(), e); } } @@ -73,25 +66,19 @@ private static String getCanonicalPath( File file ) * @return the relative path between fromdir to todir * @throws MojoExecutionException thrown if an error is detected by the mojo infrastructure */ - private static String toRelativeAndFixSeparator( File fromdir, File todir ) - throws MojoExecutionException - { - if ( !todir.isAbsolute() ) - { - todir = new File( fromdir, todir.getPath() ); + private static String toRelativeAndFixSeparator(File fromdir, File todir) throws MojoExecutionException { + if (!todir.isAbsolute()) { + todir = new File(fromdir, todir.getPath()); } - String basedirPath = getCanonicalPath( fromdir ); - String absolutePath = getCanonicalPath( todir ); + String basedirPath = getCanonicalPath(fromdir); + String absolutePath = getCanonicalPath(todir); String relative; - if ( absolutePath.equals( basedirPath ) ) - { - relative = "."; //$NON-NLS-1$ - } - else if ( absolutePath.startsWith( basedirPath ) ) - { + if (absolutePath.equals(basedirPath)) { + relative = "."; // $NON-NLS-1$ + } else if (absolutePath.startsWith(basedirPath)) { // MECLIPSE-261 // The canonical form of a windows root dir ends in a slash, whereas // the canonical form of any other file @@ -102,18 +89,15 @@ else if ( absolutePath.startsWith( basedirPath ) ) // since it is contained within // basedirPath. int length = basedirPath.length() + 1; - if ( basedirPath.endsWith( "\\" ) ) - { + if (basedirPath.endsWith("\\")) { length--; } - relative = absolutePath.substring( length ); - } - else - { + relative = absolutePath.substring(length); + } else { relative = absolutePath; } - relative = fixSeparator( relative ); + relative = fixSeparator(relative); return relative; } @@ -128,113 +112,93 @@ else if ( absolutePath.startsWith( basedirPath ) ) * @param source the source tag available in the configuration tree of the maven plugin * @throws MojoExecutionException the exception is thrown whenever the compilation fails or crashes */ - public void invokeCompiler( String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, - Source source ) - throws MojoExecutionException - { - List args = getArguments( sourceDirectory, includeDirs, targetDirectory, idlFile, source ); + public void invokeCompiler( + String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, Source source) + throws MojoExecutionException { + List args = getArguments(sourceDirectory, includeDirs, targetDirectory, idlFile, source); - invokeCompiler( args ); + invokeCompiler(args); } - abstract void invokeCompiler( List args ) throws MojoExecutionException; + abstract void invokeCompiler(List args) throws MojoExecutionException; - private List getArguments( String sourceDirectory, File[] includeDirs, String targetDirectory, - String idlFile, Source source ) throws MojoExecutionException - { + private List getArguments( + String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, Source source) + throws MojoExecutionException { List args = new ArrayList<>(); - args.add( "-i" ); - args.add( sourceDirectory ); + args.add("-i"); + args.add(sourceDirectory); // add idl files from other directories as well - if ( includeDirs != null && includeDirs.length > 0 ) - { - for ( File includeDir : includeDirs ) - { - args.add( "-i" ); - args.add( includeDir.toString() ); + if (includeDirs != null && includeDirs.length > 0) { + for (File includeDir : includeDirs) { + args.add("-i"); + args.add(includeDir.toString()); } } - args.add( "-td" ); - args.add( toRelativeAndFixSeparator( new File( System.getProperty( "user.dir" ) ), new File( targetDirectory ) ) ); + args.add("-td"); + args.add(toRelativeAndFixSeparator(new File(System.getProperty("user.dir")), new File(targetDirectory))); - if ( source.getPackagePrefix() != null ) - { - throw new MojoExecutionException( "idlj compiler does not support packagePrefix" ); + if (source.getPackagePrefix() != null) { + throw new MojoExecutionException("idlj compiler does not support packagePrefix"); } - if ( source.getPackagePrefixes() != null ) - { - for ( PackagePrefix prefix : source.getPackagePrefixes() ) - { - args.add( "-pkgPrefix" ); - args.add( prefix.getType() ); - args.add( prefix.getPrefix() ); + if (source.getPackagePrefixes() != null) { + for (PackagePrefix prefix : source.getPackagePrefixes()) { + args.add("-pkgPrefix"); + args.add(prefix.getType()); + args.add(prefix.getPrefix()); } } - if ( source.getPackageTranslations() != null ) - { - for ( PackageTranslation translation : source.getPackageTranslations() ) - { - args.add( "-pkgTranslate" ); - args.add( translation.getType() ); - args.add( translation.getReplacementPackage() ); + if (source.getPackageTranslations() != null) { + for (PackageTranslation translation : source.getPackageTranslations()) { + args.add("-pkgTranslate"); + args.add(translation.getType()); + args.add(translation.getReplacementPackage()); } } - if ( source.getDefines() != null ) - { - for ( Define define : source.getDefines() ) - { - addSymbolDefinition( args, define ); + if (source.getDefines() != null) { + for (Define define : source.getDefines()) { + addSymbolDefinition(args, define); } } - addEmitOption( args, source ); + addEmitOption(args, source); - if ( isOptionEnabled( source.compatible() ) ) - { - args.add( "-oldImplBase" ); + if (isOptionEnabled(source.compatible())) { + args.add("-oldImplBase"); } - if ( source.getAdditionalArguments() != null ) - { - for ( String arg : source.getAdditionalArguments() ) - { - args.add( arg ); + if (source.getAdditionalArguments() != null) { + for (String arg : source.getAdditionalArguments()) { + args.add(arg); } } - args.add( idlFile ); + args.add(idlFile); return args; } - private void addSymbolDefinition( List args, Define define ) throws MojoExecutionException - { - if ( define.getValue() != null ) - { - throw new MojoExecutionException( "idlj compiler unable to define symbol values" ); + private void addSymbolDefinition(List args, Define define) throws MojoExecutionException { + if (define.getValue() != null) { + throw new MojoExecutionException("idlj compiler unable to define symbol values"); } - args.add( "-d" ); - args.add( define.getSymbol() ); + args.add("-d"); + args.add(define.getSymbol()); } - private void addEmitOption( List args, Source source ) - { - if ( isOptionEnabled( source.emitStubs() ) ) - { - args.add( source.emitSkeletons() ? "-fallTIE" : "-fclient" ); - } - else - { - args.add( isOptionEnabled( source.emitSkeletons() ) ? "-fserver" : "-fserverTIE" ); + private void addEmitOption(List args, Source source) { + if (isOptionEnabled(source.emitStubs())) { + args.add(source.emitSkeletons() ? "-fallTIE" : "-fclient"); + } else { + args.add(isOptionEnabled(source.emitSkeletons()) ? "-fserver" : "-fserverTIE"); } } - private boolean isOptionEnabled( Boolean option ) - { + private boolean isOptionEnabled(Boolean option) { return option != null && option; } @@ -245,26 +209,22 @@ private boolean isOptionEnabled( Boolean option ) * @param args a List that contains the arguments to use for the compiler * @throws MojoExecutionException if the compilation fail or the compiler crashes */ - void invokeCompiler( Class compilerClass, List args ) - throws MojoExecutionException - { - getLog().debug( "Current dir : " + System.getProperty( "user.dir" ) ); - - if ( isDebug() ) - { - args.add( 0, "-verbose" ); + void invokeCompiler(Class compilerClass, List args) throws MojoExecutionException { + getLog().debug("Current dir : " + System.getProperty("user.dir")); + + if (isDebug()) { + args.add(0, "-verbose"); } - invokeCompilerInProcess( compilerClass, args ); + invokeCompilerInProcess(compilerClass, args); } @Override - protected int runCompiler( Class compilerClass, String... arguments ) - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException - { - Method compilerMainMethod = compilerClass.getMethod( "main", String[].class ); - Object retVal = compilerMainMethod.invoke( compilerClass, new Object[]{arguments} ); - getLog().debug( "Completed with code " + retVal ); - return ( retVal != null ) && ( retVal instanceof Integer ) ? (Integer) retVal : 0; + protected int runCompiler(Class compilerClass, String... arguments) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + Method compilerMainMethod = compilerClass.getMethod("main", String[].class); + Object retVal = compilerMainMethod.invoke(compilerClass, new Object[] {arguments}); + getLog().debug("Completed with code " + retVal); + return (retVal != null) && (retVal instanceof Integer) ? (Integer) retVal : 0; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/JacorbTranslator.java b/src/main/java/org/codehaus/mojo/idlj/JacorbTranslator.java index 0390d67..d3b057e 100644 --- a/src/main/java/org/codehaus/mojo/idlj/JacorbTranslator.java +++ b/src/main/java/org/codehaus/mojo/idlj/JacorbTranslator.java @@ -19,9 +19,6 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; -import org.codehaus.plexus.util.StringUtils; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -37,22 +34,21 @@ import java.util.ArrayList; import java.util.List; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.StringUtils; + /** * This class implement the CompilerTranslator for the JacORB IDL compiler * * @author Anders Hessellund Jensen * @version $Id$ */ -class JacorbTranslator - extends AbstractTranslator - implements CompilerTranslator -{ +class JacorbTranslator extends AbstractTranslator implements CompilerTranslator { /** * Default constructor */ - JacorbTranslator() - { + JacorbTranslator() { super(); } @@ -63,21 +59,16 @@ class JacorbTranslator * @param args a List that contains the arguments to use for the compiler * @throws MojoExecutionException if the compilation fail or the compiler crashes */ - private void invokeCompiler( Class compilerClass, List args ) - throws MojoExecutionException - { + private void invokeCompiler(Class compilerClass, List args) throws MojoExecutionException { // It would be great to use some 3rd party library for this stuff - if ( !isFork() ) - { - invokeCompilerInProcess( compilerClass, args ); - } - else - { + if (!isFork()) { + invokeCompilerInProcess(compilerClass, args); + } else { // Forks a new java process. // Get path to java binary - File javaHome = new File( System.getProperty( "java.home" ) ); - File javaBin = new File( new File( javaHome, "bin" ), "java" ); + File javaHome = new File(System.getProperty("java.home")); + File javaBin = new File(new File(javaHome, "bin"), "java"); // Get current class path URLClassLoader cl = (URLClassLoader) this.getClass().getClassLoader(); @@ -87,64 +78,54 @@ private void invokeCompiler( Class compilerClass, List args ) List binArgs = new ArrayList<>(); // First argument is the java binary to run - binArgs.add( javaBin.getPath() ); + binArgs.add(javaBin.getPath()); // Add the classpath to argument list - binArgs.add( "-classpath" ); - String classPath = "" + new File( classPathUrls[0].getPath().replaceAll( "%20", " " ) ); - for ( URL url : classPathUrls ) - { - classPath += File.pathSeparator + new File( url.getPath().replaceAll( "%20", " " ) ); + binArgs.add("-classpath"); + String classPath = "" + new File(classPathUrls[0].getPath().replaceAll("%20", " ")); + for (URL url : classPathUrls) { + classPath += File.pathSeparator + new File(url.getPath().replaceAll("%20", " ")); } - binArgs.add( classPath ); + binArgs.add(classPath); // Add class containing main method to arg list - binArgs.add( compilerClass.getName() ); + binArgs.add(compilerClass.getName()); // Add java arguments - for ( String arg : args ) - { - binArgs.add( arg ); + for (String arg : args) { + binArgs.add(arg); } // Convert arg list to array - String[] argArray = binArgs.toArray( new String[binArgs.size()] ); + String[] argArray = binArgs.toArray(new String[binArgs.size()]); - if ( isDebug() ) - { - getLog().debug( StringUtils.join( argArray, " " ) ); + if (isDebug()) { + getLog().debug(StringUtils.join(argArray, " ")); } - try - { - Process p = Runtime.getRuntime().exec( argArray ); - redirectStream( p.getErrorStream(), System.err ); - redirectStream( p.getInputStream(), System.out ); + try { + Process p = Runtime.getRuntime().exec(argArray); + redirectStream(p.getErrorStream(), System.err); + redirectStream(p.getInputStream(), System.out); p.waitFor(); - if ( isFailOnError() && p.exitValue() != 0 ) - { - throw new MojoExecutionException( "IDL Compilation failure" ); + if (isFailOnError() && p.exitValue() != 0) { + throw new MojoExecutionException("IDL Compilation failure"); } - } - catch ( IOException e ) - { - throw new MojoExecutionException( "Error forking compiler", e ); - } - catch ( InterruptedException e ) - { - throw new MojoExecutionException( "Thread interrupted unexpectedly", e ); + } catch (IOException e) { + throw new MojoExecutionException("Error forking compiler", e); + } catch (InterruptedException e) { + throw new MojoExecutionException("Thread interrupted unexpectedly", e); } } } @Override - protected int runCompiler( Class compilerClass, String... arguments ) - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException - { - Method compileMethod = compilerClass.getMethod( "compile", String[].class ); - compileMethod.invoke( compilerClass, new Object[]{arguments} ); + protected int runCompiler(Class compilerClass, String... arguments) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + Method compileMethod = compilerClass.getMethod("compile", String[].class); + compileMethod.invoke(compilerClass, new Object[] {arguments}); return 0; } @@ -158,84 +139,68 @@ protected int runCompiler( Class compilerClass, String... arguments ) * @param source the source set on which to run the compiler * @throws MojoExecutionException the exeception is thrown whenever the compilation fails or crashes */ - public void invokeCompiler( String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, - Source source ) - throws MojoExecutionException - { + public void invokeCompiler( + String sourceDirectory, File[] includeDirs, String targetDirectory, String idlFile, Source source) + throws MojoExecutionException { List args = new ArrayList<>(); - args.add( "-I" + sourceDirectory ); + args.add("-I" + sourceDirectory); // add idl files from other directories as well - if ( includeDirs != null ) - { - for ( File includeDir : includeDirs ) - { - args.add( "-I" + includeDir.getPath() ); + if (includeDirs != null) { + for (File includeDir : includeDirs) { + args.add("-I" + includeDir.getPath()); } } - args.add( "-d" ); - args.add( targetDirectory ); + args.add("-d"); + args.add(targetDirectory); - if ( source.emitSkeletons() != null && !source.emitSkeletons() ) - { - args.add( "-noskel" ); + if (source.emitSkeletons() != null && !source.emitSkeletons()) { + args.add("-noskel"); } - if ( source.emitStubs() != null && !source.emitStubs() ) - { - args.add( "-nostub" ); + if (source.emitStubs() != null && !source.emitStubs()) { + args.add("-nostub"); } - if ( source.getPackagePrefix() != null ) - { - args.add( "-i2jpackage" ); - args.add( ":" + source.getPackagePrefix() ); + if (source.getPackagePrefix() != null) { + args.add("-i2jpackage"); + args.add(":" + source.getPackagePrefix()); } - if ( source.getPackagePrefixes() != null ) - { - for ( PackagePrefix prefix : source.getPackagePrefixes() ) - { - args.add( "-i2jpackage" ); - args.add( prefix.getType() + ":" + prefix.getPrefix() + "." + prefix.getType() ); + if (source.getPackagePrefixes() != null) { + for (PackagePrefix prefix : source.getPackagePrefixes()) { + args.add("-i2jpackage"); + args.add(prefix.getType() + ":" + prefix.getPrefix() + "." + prefix.getType()); } } - if ( source.getDefines() != null ) - { - for ( Define define : source.getDefines() ) - { + if (source.getDefines() != null) { + for (Define define : source.getDefines()) { String arg = "-D" + define.getSymbol(); - if ( define.getValue() != null ) - { + if (define.getValue() != null) { arg += "=" + define.getValue(); } - args.add( arg ); + args.add(arg); } } - if ( source.getAdditionalArguments() != null ) - { - for ( String addArg : source.getAdditionalArguments() ) - { - args.add( addArg ); + if (source.getAdditionalArguments() != null) { + for (String addArg : source.getAdditionalArguments()) { + args.add(addArg); } } - args.add( idlFile ); + args.add(idlFile); Class compilerClass; - try - { - compilerClass = getClassLoaderFacade().loadClass( "org.jacorb.idl.parser" ); - } - catch ( ClassNotFoundException e ) - { - throw new MojoExecutionException( "JacORB IDL compiler not found", e ); + try { + compilerClass = getClassLoaderFacade().loadClass("org.jacorb.idl.parser"); + } catch (ClassNotFoundException e) { + throw new MojoExecutionException("JacORB IDL compiler not found", e); } - invokeCompiler( compilerClass, args ); + invokeCompiler(compilerClass, args); } /** @@ -244,24 +209,17 @@ public void invokeCompiler( String sourceDirectory, File[] includeDirs, String t * @param in the InputStream to read from * @param out the OutputStream to write into */ - private static void redirectStream( final InputStream in, final OutputStream out ) - { - Thread stdoutTransferThread = new Thread() - { - public void run() - { - PrintWriter pw = new PrintWriter( new OutputStreamWriter( out ), true ); - try - { - BufferedReader reader = new BufferedReader( new InputStreamReader( in ) ); + private static void redirectStream(final InputStream in, final OutputStream out) { + Thread stdoutTransferThread = new Thread() { + public void run() { + PrintWriter pw = new PrintWriter(new OutputStreamWriter(out), true); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; - while ( ( line = reader.readLine() ) != null ) - { - pw.println( line ); + while ((line = reader.readLine()) != null) { + pw.println(line); } - } - catch ( Throwable e ) - { + } catch (Throwable e) { e.printStackTrace(); } } diff --git a/src/main/java/org/codehaus/mojo/idlj/PackagePrefix.java b/src/main/java/org/codehaus/mojo/idlj/PackagePrefix.java index d2723ec..3e6538a 100644 --- a/src/main/java/org/codehaus/mojo/idlj/PackagePrefix.java +++ b/src/main/java/org/codehaus/mojo/idlj/PackagePrefix.java @@ -2,20 +2,20 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, + * + * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations * under the License. */ @@ -23,18 +23,17 @@ * @author Alan D. Cabrera * @version $Revision$ $Date$ */ -public class PackagePrefix -{ +public class PackagePrefix { /** * The simple name of either a top-level module, or an IDL type defined outside of any module - * + * * @parameter type */ private String type; /** * The generated Java package name with prefix for all files generated for that type - * + * * @parameter prefix */ private String prefix; @@ -42,16 +41,14 @@ public class PackagePrefix /** * @return the name of either a top-level module or IDL type to match to use this prefix */ - public String getType() - { + public String getType() { return type; } /** * @return the package name that will applied to all the idl types that match the criteria */ - public String getPrefix() - { + public String getPrefix() { return prefix; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/PackageTranslation.java b/src/main/java/org/codehaus/mojo/idlj/PackageTranslation.java index dc9e271..63a03ef 100644 --- a/src/main/java/org/codehaus/mojo/idlj/PackageTranslation.java +++ b/src/main/java/org/codehaus/mojo/idlj/PackageTranslation.java @@ -22,8 +22,7 @@ /** * Attributes for performing package translation. */ -public class PackageTranslation -{ +public class PackageTranslation { /** * The simple name of either a top-level module, or an IDL type defined outside of any module * @@ -41,16 +40,14 @@ public class PackageTranslation /** * @return the name of a top-level module */ - public String getType() - { + public String getType() { return type; } /** * @return the package name to replace the module name */ - public String getReplacementPackage() - { + public String getReplacementPackage() { return replacementPackage; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/Source.java b/src/main/java/org/codehaus/mojo/idlj/Source.java index 8bcd269..dacc1f9 100644 --- a/src/main/java/org/codehaus/mojo/idlj/Source.java +++ b/src/main/java/org/codehaus/mojo/idlj/Source.java @@ -24,58 +24,57 @@ /** * This class represent the source tag available in the configuration tree of the maven plugin - * + * * @author Anders Hessellund Jensen * @version $Id$ */ -public class Source -{ +public class Source { /** * Active the generation of java source compatible with jdk previous to 1.4 - * + * * @parameter compatible */ private Boolean compatible = Boolean.TRUE; /** * Whether the compiler should emit client stubs. Defaults to true. - * + * * @parameter emitStubs; */ private Boolean emitStubs = Boolean.TRUE; /** * Whether the compiler should emit server skeletons. Defaults to true. - * + * * @parameter emitSkeletons; */ private Boolean emitSkeletons = Boolean.TRUE; /** * Specifies a single, global packageprefix to use for all modules. - * + * * @parameter packagePrefix; */ private String packagePrefix; /** * Specifies which files to include in compilation. - * + * * @parameter includes; */ private Set includes; /** * Specifies which files to exclude from compilation. - * + * * @parameter excludes; */ private Set excludes; /** * The list of package prefixes for certain types. - * + * * @parameter packagePrefixes; */ private List packagePrefixes; @@ -100,80 +99,70 @@ public class Source /** * @return a List with all the defines with this source */ - public List getDefines() - { + public List getDefines() { return defines; } /** * @return a Boolean true if and only if the creation of the stubs is enabled */ - public Boolean emitStubs() - { + public Boolean emitStubs() { return emitStubs; } /** * @return a Boolean true if and only if the creation of the skeleton is enabled */ - public Boolean emitSkeletons() - { + public Boolean emitSkeletons() { return emitSkeletons; } /** * @return a Boolean true if and only if the creation of compatible code is enabled */ - public Boolean compatible() - { + public Boolean compatible() { return compatible; } /** * @return a Set with all the exclusions pattern */ - public Set getExcludes() - { + public Set getExcludes() { return excludes; } /** * @return a Set with all the inclusions pattern */ - public Set getIncludes() - { + public Set getIncludes() { return includes; } /** * @return the default package name that will be used as for all the generated classes */ - public String getPackagePrefix() - { + public String getPackagePrefix() { return packagePrefix; } /** * @return a List of PackagePrefix to use for the generated files */ - public List getPackagePrefixes() - { + public List getPackagePrefixes() { return packagePrefixes; } /** * @return a List of String that will be added as compiler parameters */ - public List getAdditionalArguments() - { + public List getAdditionalArguments() { return additionalArguments; } /** * @return a List of PackageTranslation that map IDL module names to package names */ - public List getPackageTranslations() - { + public List getPackageTranslations() { return packageTranslations; } } diff --git a/src/main/java/org/codehaus/mojo/idlj/TestIDLJMojo.java b/src/main/java/org/codehaus/mojo/idlj/TestIDLJMojo.java index 6b692fd..85b4417 100644 --- a/src/main/java/org/codehaus/mojo/idlj/TestIDLJMojo.java +++ b/src/main/java/org/codehaus/mojo/idlj/TestIDLJMojo.java @@ -19,12 +19,12 @@ * under the License. */ +import java.io.File; + import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import java.io.File; - /** * Process CORBA IDL test files in IDLJ. * @@ -32,9 +32,7 @@ * @version $Id$ */ @Mojo(name = "generate-test", defaultPhase = LifecyclePhase.GENERATE_TEST_SOURCES) -public class TestIDLJMojo - extends AbstractIDLJMojo -{ +public class TestIDLJMojo extends AbstractIDLJMojo { /** * The source directory containing *.idl files. */ @@ -50,16 +48,14 @@ public class TestIDLJMojo /** * @return the directory that contains the source */ - protected File getSourceDirectory() - { + protected File getSourceDirectory() { return sourceDirectory; } /** * @return the directory that will contain the generated code */ - protected File getOutputDirectory() - { + protected File getOutputDirectory() { return outputDirectory; } @@ -68,8 +64,7 @@ protected File getOutputDirectory() * compile tests. * @param directory the directory from which compilation should occur */ - protected void addCompileSourceRoot( File directory ) - { - getProject().addTestCompileSourceRoot( directory.getAbsolutePath() ); + protected void addCompileSourceRoot(File directory) { + getProject().addTestCompileSourceRoot(directory.getAbsolutePath()); } } diff --git a/src/main/java/org/codehaus/mojo/idlj/TranslatorType.java b/src/main/java/org/codehaus/mojo/idlj/TranslatorType.java index 511d6ec..0122d27 100644 --- a/src/main/java/org/codehaus/mojo/idlj/TranslatorType.java +++ b/src/main/java/org/codehaus/mojo/idlj/TranslatorType.java @@ -19,16 +19,15 @@ * under the License. */ -import org.apache.maven.plugin.MojoExecutionException; - import java.util.function.Supplier; +import org.apache.maven.plugin.MojoExecutionException; + /** * A selector for the types of IDL translators supported */ -enum TranslatorType -{ - AUTO("auto", () -> isJavaModuleSystemPresent() ? new GlassfishTranslator() : new BuiltInTranslator()), +enum TranslatorType { + AUTO("auto", () -> isJavaModuleSystemPresent() ? new GlassfishTranslator() : new BuiltInTranslator()), BUILT_IN("idlj", BuiltInTranslator::new), GLASSFISH("glassfish", GlassfishTranslator::new), JACORB("jacorb", JacorbTranslator::new); @@ -48,25 +47,21 @@ String getSelector() { return selector; } - static boolean isJavaModuleSystemPresent() - { - return !System.getProperty( "java.version" ).startsWith( "1." ); + static boolean isJavaModuleSystemPresent() { + return !System.getProperty("java.version").startsWith("1."); } - static CompilerTranslator selectTranslator( String compiler ) throws MojoExecutionException - { - for ( TranslatorType type : TranslatorType.values() ) - { - if ( type.select( compiler ) ) - { + static CompilerTranslator selectTranslator(String compiler) throws MojoExecutionException { + for (TranslatorType type : TranslatorType.values()) { + if (type.select(compiler)) { return type.createTranslator(); } } - throw new MojoExecutionException( "Compiler not supported: " + compiler ); + throw new MojoExecutionException("Compiler not supported: " + compiler); } - final boolean select( String compilerSetting ) { + final boolean select(String compilerSetting) { return selector.equals(compilerSetting); } diff --git a/src/test/java/org/codehaus/mojo/idlj/IDLJTestBase.java b/src/test/java/org/codehaus/mojo/idlj/IDLJTestBase.java index d938306..cb99dc6 100644 --- a/src/test/java/org/codehaus/mojo/idlj/IDLJTestBase.java +++ b/src/test/java/org/codehaus/mojo/idlj/IDLJTestBase.java @@ -1,13 +1,5 @@ package org.codehaus.mojo.idlj; -import org.apache.maven.model.Model; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.compiler.util.scan.InclusionScanException; -import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; -import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping; -import org.junit.After; -import org.junit.Before; - import java.io.File; import java.io.IOException; import java.lang.reflect.Field; @@ -19,6 +11,14 @@ import java.util.Properties; import java.util.Set; +import org.apache.maven.model.Model; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.compiler.util.scan.InclusionScanException; +import org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner; +import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping; +import org.junit.After; +import org.junit.Before; + import static org.junit.Assert.fail; public class IDLJTestBase { @@ -48,7 +48,7 @@ public void setUp() throws Exception { @After public void tearDown() { - System.setProperties( savedProperties ); + System.setProperties(savedProperties); } private void ignoreMavenProject() throws NoSuchFieldException, IllegalAccessException { @@ -56,33 +56,33 @@ private void ignoreMavenProject() throws NoSuchFieldException, IllegalAccessExce } private void defineTimestampDirectory(String path) throws NoSuchFieldException, IllegalAccessException { - setPrivateFieldValue( mojo, "timestampDirectory", new File( path ) ); + setPrivateFieldValue(mojo, "timestampDirectory", new File(path)); } private void defineOutputDirectory(String path) throws NoSuchFieldException, IllegalAccessException { - setPrivateFieldValue( mojo, "outputDirectory", new File( path ) ); + setPrivateFieldValue(mojo, "outputDirectory", new File(path)); } private void defineSourceDirectory(String path) throws NoSuchFieldException, IllegalAccessException { mojo.setSourceDirectory(new File(path)); - testDependenciesFacade.readOnlyDirectories.add( new File( path ) ); + testDependenciesFacade.readOnlyDirectories.add(new File(path)); } - private void setPrivateFieldValue(Object obj, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { + private void setPrivateFieldValue(Object obj, String fieldName, Object value) + throws NoSuchFieldException, IllegalAccessException { Class theClass = obj.getClass(); setPrivateFieldValue(obj, theClass, fieldName, value); } - private void setPrivateFieldValue(Object obj, Class theClass, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException { + private void setPrivateFieldValue(Object obj, Class theClass, String fieldName, Object value) + throws NoSuchFieldException, IllegalAccessException { try { Field field = theClass.getDeclaredField(fieldName); field.setAccessible(true); field.set(obj, value); } catch (NoSuchFieldException e) { - if (theClass.equals(Object.class)) - throw e; - else - setPrivateFieldValue(obj, theClass.getSuperclass(), fieldName, value); + if (theClass.equals(Object.class)) throw e; + else setPrivateFieldValue(obj, theClass.getSuperclass(), fieldName, value); } } @@ -90,7 +90,8 @@ final void defineSinglePrefix(Source source, String aPrefix) throws NoSuchFieldE setPrivateFieldValue(source, "packagePrefix", aPrefix); } - final void createPrefix(Source source, String aType, String aPrefix) throws NoSuchFieldException, IllegalAccessException { + final void createPrefix(Source source, String aType, String aPrefix) + throws NoSuchFieldException, IllegalAccessException { PackagePrefix prefix = createPrefix(source); setPrivateFieldValue(prefix, "type", aType); setPrivateFieldValue(prefix, "prefix", aPrefix); @@ -105,20 +106,19 @@ private PackagePrefix createPrefix(Source source) throws NoSuchFieldException, I private List getPrefixes(Source source) throws NoSuchFieldException, IllegalAccessException { List prefixes = getPrivateFieldValue(source, "packagePrefixes"); - if (prefixes == null) - setPrivateFieldValue(source, "packagePrefixes", prefixes = new ArrayList<>()); + if (prefixes == null) setPrivateFieldValue(source, "packagePrefixes", prefixes = new ArrayList<>()); return prefixes; } - final void createTranslation(Source source, String aType, String aPackage) throws NoSuchFieldException, - IllegalAccessException { - PackageTranslation translation = createTranslation( source ); + final void createTranslation(Source source, String aType, String aPackage) + throws NoSuchFieldException, IllegalAccessException { + PackageTranslation translation = createTranslation(source); setPrivateFieldValue(translation, "type", aType); setPrivateFieldValue(translation, "replacementPackage", aPackage); } private PackageTranslation createTranslation(Source source) throws NoSuchFieldException, IllegalAccessException { - List translations = getTranslations( source ); + List translations = getTranslations(source); PackageTranslation translation = new PackageTranslation(); translations.add(translation); return translation; @@ -126,10 +126,8 @@ private PackageTranslation createTranslation(Source source) throws NoSuchFieldEx private List getTranslations(Source source) throws NoSuchFieldException, IllegalAccessException { - List translations = - getPrivateFieldValue(source, "packageTranslations"); - if (translations == null) - setPrivateFieldValue(source, "packageTranslations", translations = new ArrayList<>()); + List translations = getPrivateFieldValue(source, "packageTranslations"); + if (translations == null) setPrivateFieldValue(source, "packageTranslations", translations = new ArrayList<>()); return translations; } @@ -146,10 +144,8 @@ private T getPrivateFieldValue(Object obj, Class theClass, String fieldName) field.setAccessible(true); return (T) field.get(obj); } catch (NoSuchFieldException e) { - if (theClass.equals(Object.class)) - throw e; - else - return (T) getPrivateFieldValue(obj, theClass.getSuperclass(), fieldName); + if (theClass.equals(Object.class)) throw e; + else return (T) getPrivateFieldValue(obj, theClass.getSuperclass(), fieldName); } } @@ -161,8 +157,7 @@ final Source createSource() throws NoSuchFieldException, IllegalAccessException private List getSources() throws NoSuchFieldException, IllegalAccessException { List sources = getPrivateFieldValue(mojo, "sources"); - if (sources == null) - setPrivateFieldValue(mojo, "sources", sources = new ArrayList<>()); + if (sources == null) setPrivateFieldValue(mojo, "sources", sources = new ArrayList<>()); return sources; } @@ -182,8 +177,7 @@ private Define createDefine(Source source) throws NoSuchFieldException, IllegalA private List getDefines(Source source) throws NoSuchFieldException, IllegalAccessException { List defines = getPrivateFieldValue(source, "defines"); - if (defines == null) - setPrivateFieldValue(source, "defines", defines = new ArrayList<>()); + if (defines == null) setPrivateFieldValue(source, "defines", defines = new ArrayList<>()); return defines; } @@ -207,17 +201,16 @@ final void createDefine(Source source, String aName) throws NoSuchFieldException } final String getCurrentDir() { - return System.getProperty("user.dir").replace('\\','/'); + return System.getProperty("user.dir").replace('\\', '/'); } final void assertArgumentsDoesNotContain(String... expectedArgs) { - if (contains(args, expectedArgs)) - fail( toArgumentString( expectedArgs ) + " found in " + toArgumentString(args)); + if (contains(args, expectedArgs)) fail(toArgumentString(expectedArgs) + " found in " + toArgumentString(args)); } final void assertArgumentsContains(String... expectedArgs) { if (!contains(args, expectedArgs)) - fail( toArgumentString( expectedArgs ) + " not found in " + toArgumentString(args)); + fail(toArgumentString(expectedArgs) + " not found in " + toArgumentString(args)); } private boolean contains(String[] container, String[] candidate) { @@ -226,16 +219,14 @@ private boolean contains(String[] container, String[] candidate) { return false; } - private boolean isSubArrayAt( String[] container, int start, String[] candidate ) { - for (int j = 0; j < candidate.length; j++) - if (!container[start+j].equals( candidate[j])) return false; + private boolean isSubArrayAt(String[] container, int start, String[] candidate) { + for (int j = 0; j < candidate.length; j++) if (!container[start + j].equals(candidate[j])) return false; return true; } private String toArgumentString(String... args) { StringBuilder sb = new StringBuilder(); - for (String arg : args) - sb.append( arg ).append( ' ' ); + for (String arg : args) sb.append(arg).append(' '); return sb.toString().trim(); } @@ -244,9 +235,8 @@ final void setFailOnError() throws NoSuchFieldException, IllegalAccessException } final void defineIncludePaths(String... paths) throws NoSuchFieldException, IllegalAccessException { - File[] dirs = new File[ paths.length ]; - for (int i = 0; i < dirs.length; i++) - dirs[i] = new File( paths[i] ); + File[] dirs = new File[paths.length]; + for (int i = 0; i < dirs.length; i++) dirs[i] = new File(paths[i]); setPrivateFieldValue(mojo, "includeDirs", dirs); } @@ -283,10 +273,9 @@ public void prependUrls(URL... urls) { } public Class loadClass(String className) throws ClassNotFoundException { - toolsJarSpecified = containsToolsJar( prependedURLs ); + toolsJarSpecified = containsToolsJar(prependedURLs); idlCompilerClass = className; - if (filter.throwException(prependedURLs.toArray(new URL[prependedURLs.size()]))) - { + if (filter.throwException(prependedURLs.toArray(new URL[prependedURLs.size()]))) { throw new ClassNotFoundException(className); } return TestIdlCompiler.class; @@ -296,21 +285,18 @@ String getIdlCompilerClass() { return idlCompilerClass; } - public boolean isToolsJarSpecified() - { + public boolean isToolsJarSpecified() { return toolsJarSpecified; } - private boolean containsToolsJar( List prependedUrls) { - for (URL url : prependedUrls) - if (!url.getPath().contains("tools.jar")) return true; + private boolean containsToolsJar(List prependedUrls) { + for (URL url : prependedUrls) if (!url.getPath().contains("tools.jar")) return true; return true; } } - boolean isToolsJarSpecified() - { + boolean isToolsJarSpecified() { return loaderFacade.isToolsJarSpecified(); } @@ -318,8 +304,7 @@ boolean isToolsJarSpecified() * Specifies a filter to determine whether to throw CNFE when the translator attempts to look up a compiler. * @param filter the new filter */ - void setClassNotFoundFilter(ClassNotFoundFilter filter) - { + void setClassNotFoundFilter(ClassNotFoundFilter filter) { loaderFacade.filter = filter; } @@ -327,15 +312,13 @@ static class TestIdlCompiler { private static String errorMessage; public static void main(String... args) { - IDLJTestBase.args = new String[ args.length]; - for (int i = 0; i < args.length; i++) - IDLJTestBase.args[i] = args[i].replace('\\','/'); + IDLJTestBase.args = new String[args.length]; + for (int i = 0; i < args.length; i++) IDLJTestBase.args[i] = args[i].replace('\\', '/'); - if ( errorMessage != null ) - System.err.println( errorMessage ); + if (errorMessage != null) System.err.println(errorMessage); } - @SuppressWarnings("unused") // used via reflection + @SuppressWarnings("unused") // used via reflection public static void compile(String... args) { main(args); } @@ -349,8 +332,7 @@ private static class TestScanner implements SourceInclusionScanner { private Set includedSources = new HashSet<>(); - public void addSourceMapping(SourceMapping sourceMapping) { - } + public void addSourceMapping(SourceMapping sourceMapping) {} public Set getIncludedSources(File sourceDir, File targetDir) throws InclusionScanException { return includedSources; @@ -362,53 +344,41 @@ public boolean isDebugEnabled() { return false; } - public void debug(CharSequence charSequence) { - } + public void debug(CharSequence charSequence) {} - public void debug(CharSequence charSequence, Throwable throwable) { - } + public void debug(CharSequence charSequence, Throwable throwable) {} - public void debug(Throwable throwable) { - } + public void debug(Throwable throwable) {} public boolean isInfoEnabled() { return false; } - public void info(CharSequence charSequence) { - } + public void info(CharSequence charSequence) {} - public void info(CharSequence charSequence, Throwable throwable) { - } + public void info(CharSequence charSequence, Throwable throwable) {} - public void info(Throwable throwable) { - } + public void info(Throwable throwable) {} public boolean isWarnEnabled() { return false; } - public void warn(CharSequence charSequence) { - } + public void warn(CharSequence charSequence) {} - public void warn(CharSequence charSequence, Throwable throwable) { - } + public void warn(CharSequence charSequence, Throwable throwable) {} - public void warn(Throwable throwable) { - } + public void warn(Throwable throwable) {} public boolean isErrorEnabled() { return false; } - public void error(CharSequence charSequence) { - } + public void error(CharSequence charSequence) {} - public void error(CharSequence charSequence, Throwable throwable) { - } + public void error(CharSequence charSequence, Throwable throwable) {} - public void error(Throwable throwable) { - } + public void error(Throwable throwable) {} } private class TestDependenciesFacade implements DependenciesFacade { diff --git a/src/test/java/org/codehaus/mojo/idlj/IDLJTestCase.java b/src/test/java/org/codehaus/mojo/idlj/IDLJTestCase.java index b41614b..975ceef 100644 --- a/src/test/java/org/codehaus/mojo/idlj/IDLJTestCase.java +++ b/src/test/java/org/codehaus/mojo/idlj/IDLJTestCase.java @@ -19,6 +19,10 @@ * under the License. */ +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + import com.meterware.simplestub.Memento; import com.meterware.simplestub.SystemPropertySupport; import org.apache.maven.plugin.MojoExecutionException; @@ -27,10 +31,6 @@ import org.junit.Before; import org.junit.Test; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - import static org.codehaus.mojo.idlj.TranslatorType.BUILT_IN; import static org.codehaus.mojo.idlj.TranslatorType.isJavaModuleSystemPresent; import static org.hamcrest.MatcherAssert.assertThat; @@ -86,23 +86,19 @@ public void whenGlassfishCompilerSpecified_chooseGlassfishCompiler() throws Exce @Test public void whenCompilerNotSpecifiedAndNoModuleSystem_chooseOracleJdkCompiler() throws Exception { - assumeFalse( isJavaModuleSystemPresent() ); - assumeTrue( isBuiltInOrbPresent() ); + assumeFalse(isJavaModuleSystemPresent()); + assumeTrue(isBuiltInOrbPresent()); mojo.execute(); assertEquals(ORACLE_JDK_IDL_CLASS, getIdlCompilerClass()); } - private boolean isBuiltInOrbPresent() - { - try - { - Class.forName( "javax.rmi.PortableRemoteObject" ); + private boolean isBuiltInOrbPresent() { + try { + Class.forName("javax.rmi.PortableRemoteObject"); return true; - } - catch ( ClassNotFoundException e ) - { + } catch (ClassNotFoundException e) { return false; } } @@ -139,8 +135,7 @@ public void whenCompilerNotFound_throwException() throws Exception { mojo.execute(); } - private void declareAllClassesNotFound() - { + private void declareAllClassesNotFound() { setClassNotFoundFilter(new ClassNotFoundFilter() { @Override public boolean throwException(URL... prependedUrls) { @@ -162,8 +157,7 @@ public void whenCompilerNotFound_tryAgainWithToolsJar() throws Exception { } private boolean containsToolsJar(URL[] prependedUrls) { - for (URL url : prependedUrls) - if (!url.getPath().contains("tools.jar")) return true; + for (URL url : prependedUrls) if (!url.getPath().contains("tools.jar")) return true; return true; } diff --git a/src/test/java/org/codehaus/mojo/idlj/IdljCommonTests.java b/src/test/java/org/codehaus/mojo/idlj/IdljCommonTests.java index a18da1f..15af14e 100644 --- a/src/test/java/org/codehaus/mojo/idlj/IdljCommonTests.java +++ b/src/test/java/org/codehaus/mojo/idlj/IdljCommonTests.java @@ -70,14 +70,16 @@ public void whenPackageTranslationDefined_createTranslationArguments() throws Ex } @Test(expected = MojoExecutionException.class) - public void whenSymbolDefineWithValue_throwException() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenSymbolDefineWithValue_throwException() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); createDefine(source, "symbol1", "value1"); mojo.execute(); } @Test - public void whenSymbolsDefined_createSymbolArguments() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenSymbolsDefined_createSymbolArguments() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); createDefine(source, "symbol1"); createDefine(source, "symbol2"); @@ -93,7 +95,8 @@ public void whenNoOptionsAreSpecified_generateFallArguments() throws Exception { } @Test - public void whenEmitStubsOnly_generateFClientArgument() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenEmitStubsOnly_generateFClientArgument() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); setGenerateStubs(source, true); setGenerateSkeletons(source, false); @@ -102,7 +105,8 @@ public void whenEmitStubsOnly_generateFClientArgument() throws NoSuchFieldExcept } @Test - public void whenEmitSkeletonsOnly_generateFServerArgument() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenEmitSkeletonsOnly_generateFServerArgument() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); setGenerateStubs(source, false); setGenerateSkeletons(source, true); @@ -111,7 +115,8 @@ public void whenEmitSkeletonsOnly_generateFServerArgument() throws NoSuchFieldEx } @Test - public void whenEmitNeitherStubsNorSkeletons_generateFServerTieArgument() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenEmitNeitherStubsNorSkeletons_generateFServerTieArgument() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); setGenerateStubs(source, false); setGenerateSkeletons(source, false); @@ -120,7 +125,8 @@ public void whenEmitNeitherStubsNorSkeletons_generateFServerTieArgument() throws } @Test - public void whenAdditionalArgumentsSpecified_copyToCommand() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenAdditionalArgumentsSpecified_copyToCommand() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); defineAdditionalArguments(source, "-arg1", "arg2"); mojo.execute(); diff --git a/src/test/java/org/codehaus/mojo/idlj/JacorbIdlTestCase.java b/src/test/java/org/codehaus/mojo/idlj/JacorbIdlTestCase.java index 830fcc2..5374fdc 100644 --- a/src/test/java/org/codehaus/mojo/idlj/JacorbIdlTestCase.java +++ b/src/test/java/org/codehaus/mojo/idlj/JacorbIdlTestCase.java @@ -13,7 +13,6 @@ public void setUpJacorb() throws NoSuchFieldException, IllegalAccessException { defineCompiler("jacorb"); } - @Test public void whenSpecified_chooseJacorbCompiler() throws Exception { mojo.execute(); @@ -58,7 +57,8 @@ public void whenPackagePrefixDefined_createPrefixArguments() throws Exception { } @Test - public void whenSymbolsDefinedWithoutValues_createSymbolArguments() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenSymbolsDefinedWithoutValues_createSymbolArguments() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); createDefine(source, "symbol1"); createDefine(source, "symbol2"); @@ -68,7 +68,8 @@ public void whenSymbolsDefinedWithoutValues_createSymbolArguments() throws NoSuc } @Test - public void whenSymbolsDefinedWithValues_createSymbolArguments() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenSymbolsDefinedWithValues_createSymbolArguments() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); createDefine(source, "symbol1", "value1"); createDefine(source, "symbol2", "value2"); @@ -78,7 +79,8 @@ public void whenSymbolsDefinedWithValues_createSymbolArguments() throws NoSuchFi } @Test - public void whenEmitStubsOnly_generateNoSkelArgument() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenEmitStubsOnly_generateNoSkelArgument() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); setGenerateStubs(source, true); setGenerateSkeletons(source, false); @@ -87,7 +89,8 @@ public void whenEmitStubsOnly_generateNoSkelArgument() throws NoSuchFieldExcepti } @Test - public void whenEmitSkeletonsOnly_generateNoStubArgument() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenEmitSkeletonsOnly_generateNoStubArgument() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); setGenerateStubs(source, false); setGenerateSkeletons(source, true); @@ -96,7 +99,8 @@ public void whenEmitSkeletonsOnly_generateNoStubArgument() throws NoSuchFieldExc } @Test - public void whenAdditionalArgumentsSpecified_copyToCommand() throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { + public void whenAdditionalArgumentsSpecified_copyToCommand() + throws NoSuchFieldException, IllegalAccessException, MojoExecutionException { Source source = createSource(); defineAdditionalArguments(source, "-arg1", "arg2", "-sloppy_names"); mojo.execute();