1 /*
2 * <copyright>
3 *
4 * Copyright (c) 2005-2007 Sven Efftinge (http://www.efftinge.de) and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *
10 * Contributors:
11 * Sven Efftinge (http://www.efftinge.de) - Initial API and implementation
12 *
13 * </copyright>
14 */
15 package org.mod4j.common.generator.admin;
16
17 //import java.io.BufferedInputStream;
18 //import java.io.BufferedReader;
19 //import java.io.IOException;
20 //import java.io.InputStream;
21 //import java.io.InputStreamReader;
22 //import java.util.Properties;
23 //import java.util.regex.Matcher;
24 //import java.util.regex.Pattern;
25 //
26 //import org.apache.commons.logging.Log;
27 //import org.apache.commons.logging.LogFactory;
28 //
29 //import org.openarchitectureware.workflow.util.ResourceLoaderFactory;
30 //import org.openarchitectureware.xpand2.output.FileHandle;
31 //import org.openarchitectureware.xpand2.output.PostProcessor;
32
33 /**
34 * Formats generated Java code using the Eclipse code formatter.
35 *
36 * @author Sven Efftinge (http://www.efftinge.de) (initial)
37 * @author Bernd Kolb
38 * @author Peter Friese
39 * @author Markus V�lter
40 * @author Michael Leopoldseder
41 * @author Karsten Thoms
42 * @since 4.0
43 */
44 public class PostGenerator { // implements PostProcessor {
45
46 /** Logger instance. */
47 // private final Log log = LogFactory.getLog(getClass());
48 // /**
49 // * Formats the file using Eclipse code formatter. The file must have the
50 // * extension '.java'.
51 // */
52 // public void beforeWriteAndClose(final FileHandle info) {
53 // if (info.getTargetFile() != null && info.getTargetFile().getAbsolutePath().endsWith(".java")) {
54 //
55 // info.getBuffer().toString();
56 //
57 // info.setBuffer(new StringBuffer());
58 // log.warn("File " + info.getTargetFile()
59 // + " could not be formatted. Make sure your template produces legal Java code!");
60 // }
61 // }
62 //
63 // /**
64 // * Return a Java Properties file representing the options that are in the
65 // * specified config file.
66 // */
67 // private Properties readConfig(String filename) {
68 // BufferedInputStream stream = null;
69 // BufferedReader reader = null;
70 //
71 // try {
72 // InputStream is = openStream(filename);
73 // final Properties formatterOptions = new Properties();
74 // if ( filename.endsWith(".xml")) {
75 // Pattern pattern = Pattern.compile("<setting id=\"([^\"]*)\" value=\"([^\"]*)\"\\/>");
76 // reader = new BufferedReader(new InputStreamReader(is));
77 // for (String line = reader.readLine(); line != null; line = reader.readLine()) {
78 // Matcher matcher = pattern.matcher(line);
79 // if ( matcher.matches() ) {
80 // formatterOptions.put(matcher.group(1), matcher.group(2));
81 // }
82 // }
83 // }
84 // else {
85 // stream = new BufferedInputStream(is);
86 // formatterOptions.load(stream);
87 // }
88 // // add some settings for the compiler options
89 // // which are not included in the Eclipse code style settings
90 // // to make the code formatter working
91 // // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=222736
92 // if( formatterOptions.get("org.eclipse.jdt.core.compiler.compliance") == null ) {
93 // formatterOptions.put("org.eclipse.jdt.core.compiler.compliance", "1.5");
94 // }
95 // if( formatterOptions.get("org.eclipse.jdt.core.compiler.codegen.targetPlatform") == null ) {
96 // formatterOptions.put("org.eclipse.jdt.core.compiler.codegen.targetPlatform", "1.5");
97 // }
98 // if( formatterOptions.get("org.eclipse.jdt.core.compiler.source") == null ) {
99 // formatterOptions.put("org.eclipse.jdt.core.compiler.source", "1.5");
100 // }
101 // return formatterOptions;
102 // } catch (IOException e) {
103 // log.warn("Problem reading code formatter config file (" + e.getMessage() + ").");
104 // } finally {
105 // if (stream != null) {
106 // try {
107 // stream.close();
108 // } catch (IOException e) {
109 // /* ignore */
110 // }
111 // }
112 // if ( reader != null ) {
113 // try {
114 // reader.close();
115 // } catch (IOException e) {
116 // /* ignore */
117 // }
118 // }
119 // }
120 // return null;
121 // }
122 //
123 // /**
124 // * Searches for the given filename as a ressource and returns a stream on it. Throws an IOException, if the file
125 // * cannot be found.
126 // *
127 // * @param filename
128 // * The name of the file to be searched in the ressources.
129 // * @return InputStream for subsequent reading
130 // * @throws IOException
131 // */
132 // protected InputStream openStream(String filename) throws IOException {
133 // InputStream is = ResourceLoaderFactory.createResourceLoader().getResourceAsStream(filename);
134 // if (is == null) {
135 // throw new IOException("Config file [" + filename + "] does not exist.");
136 // }
137 // return is;
138 // }
139 //
140 // /**
141 // * @return the configuration file for the formatter
142 // */
143 // public String getConfigFile() {
144 // return "configfile";
145 // }
146 //
147 // /**
148 // * @param configFile
149 // * configuration file for the formatter
150 // */
151 // public void setConfigFile(String configFile) {
152 // }
153 //
154 // /**
155 // * {@inheritDoc}
156 // */
157 // public void afterClose(final FileHandle impl) {
158 // // do nothing here
159 // }
160 }