could you apply the Maven Codestyle? [1] -Robert [1] http://maven.apache.org/developers/committer-environment.html#Maven_Code_Style From: [email protected] To: [email protected] Date: Fri, 27 Jan 2012 11:41:14 -0600 Subject: [mojo-scm] [15786] trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/ argouml/TranformMojo.java: MOJO-1696: Refactoring of TransformMojo.java
[15786] trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/argouml/TranformMojo.java: MOJO-1696: Refactoring of TransformMojo.java Revision 15786 Author slonopotamus Date 2012-01-27 11:41:13 -0600 (Fri, 27 Jan 2012) Log Message MOJO-1696: Refactoring of TransformMojo.java Contributed by Thomas ([email protected]) Modified Paths trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/argouml/TranformMojo.java Diff Modified: trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/argouml/TranformMojo.java (15785 => 15786) --- trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/argouml/TranformMojo.java 2012-01-27 10:12:12 UTC (rev 15785) +++ trunk/sandbox/argouml-maven-plugin/src/main/java/org/codehaus/mojo/argouml/TranformMojo.java 2012-01-27 17:41:13 UTC (rev 15786) @@ -20,15 +20,9 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + */ package org.codehaus.mojo.argouml; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - import org.apache.commons.lang.ArrayUtils; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -59,6 +53,8 @@ import org.tigris.gef.base.Globals; import org.tigris.gef.base.SaveGraphicsAction; +import java.io.*; + /** * Transforms ArgoUML files into images. * @goal transform @@ -107,7 +103,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // Prepare input files. if (ArrayUtils.isEmpty(inputFiles)) { - inputFiles = new File[] { defaultInputDirectory }; + inputFiles = new File[]{ defaultInputDirectory }; } // Prepare output directory @@ -142,7 +138,10 @@ throw new MojoExecutionException("Could not init argouml", e); } - // Process files + processFiles(); + } + + private void processFiles() throws MojoExecutionException { for (final File file : inputFiles) { process(file); } @@ -150,33 +149,86 @@ private void process(final File fileOrDirectory) throws MojoExecutionException { if (!fileOrDirectory.exists()) { - throw new MojoExecutionException("Input " - + fileOrDirectory.getAbsolutePath() + " does not exist"); + throw new MojoExecutionException("Input " + fileOrDirectory.getAbsolutePath() + " does not exist"); } else if (fileOrDirectory.isDirectory()) { - for (final File file : fileOrDirectory.listFiles()) { - if (recursive) { - process(file); - } else if (file.isFile()) { - convert(file); - } - } + processDirectory(fileOrDirectory); } else if (fileOrDirectory.isFile()) { convert(fileOrDirectory); } } + private void processDirectory(final File directory) throws MojoExecutionException { + for (final File file : directory.listFiles()) { + if (recursive) { + process(file); + } else if (file.isFile()) { + convert(file); + } + } + } + /** * Perform conversion of single file. * @param input input file. * @throws MojoExecutionException if there was a error during conversion. */ private void convert(final File input) throws MojoExecutionException { + final Project project = loadProjectFromFile(input); + + for (final ArgoDiagram argoDiagram : project.getDiagramList()) { + processDiagram(argoDiagram); + } + } + + private void processDiagram(final ArgoDiagram argoDiagram) throws MojoExecutionException { + final Diagram dia = (Diagram) argoDiagram; + Globals.curEditor(new Editor(dia)); + + final String name = filterIllegalSymbolsFromDiagramName(dia.getName()); + writeFile(name); + } + + private void writeFile(final String name) throws MojoExecutionException { + final SaveGraphicsAction cmd = SaveGraphicsManager.getInstance().getSaveActionBySuffix(outputFormat); + cmd.setScale(scale); + + final File file = new File(outputDirectory, name + "." + outputFormat); + getLog().info("Writing " + file.getAbsolutePath()); + OutputStream os = null; + try { + os = new FileOutputStream(file); + cmd.setStream(os); + cmd.actionPerformed(null); + } catch (FileNotFoundException e) { + throw new MojoExecutionException("Could not write " + file, e); + } finally { + if (os != null) { + try { + os.close(); + } catch (IOException e) { + // no-op + } + } + } + } + + private String filterIllegalSymbolsFromDiagramName(final String origName) { + final String name; + if (origName.indexOf('/') > -1 || origName.indexOf('\\') > -1) { + name = origName.replaceAll("[/\\\\]", "_"); + getLog().warn("Diagram name '" + origName + "' contains illegal symbols. Renamed to '" + name + "'"); + } else { + name = origName; + } + return name; + } + + private Project loadProjectFromFile(final File input) throws MojoExecutionException { final PersistenceManager persistenceManager = PersistenceManager.getInstance(); final ProjectFilePersister persister = persistenceManager.getPersisterFromFileName(input.getAbsolutePath()); final Project project; if (persister == null) { - getLog().warn("Could not get argouml persister for " + input); - return; + throw new MojoExecutionException("Could not get argouml persister for " + input); } try { project = persister.doLoad(input); @@ -185,37 +237,6 @@ } catch (InterruptedException e) { throw new MojoExecutionException("Could not load file " + input.getAbsolutePath(), e); } - for (final ArgoDiagram argoDiagram : project.getDiagramList()) { - final Diagram dia = (Diagram) argoDiagram; - Globals.curEditor(new Editor(dia)); - final SaveGraphicsAction cmd = SaveGraphicsManager.getInstance().getSaveActionBySuffix(outputFormat); - cmd.setScale(scale); - final String origName = dia.getName(); - final String name; - if (origName.indexOf('/') > -1 || origName.indexOf('\\') > -1) { - name = origName.replaceAll("[/\\\\]", "_"); - getLog().warn("Diagram name '" + origName + "' contains illegal symbols. Renamed to '" + name + "'"); - } else { - name = origName; - } - final File file = new File(outputDirectory, name + "." + outputFormat); - getLog().info("Writing " + file.getAbsolutePath()); - OutputStream os = null; - try { - os = new FileOutputStream(file); - cmd.setStream(os); - cmd.actionPerformed(null); - } catch (FileNotFoundException e) { - throw new MojoExecutionException("Could not write " + file, e); - } finally { - if (os != null) { - try { - os.close(); - } catch (IOException e) { - // no-op - } - } - } - } + return project; } } To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email
