
org.tinygroup.ProcessMdaCompile Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 1997-2013, tinygroup.org ([email protected]).
*
* Licensed under the GPL, Version 3.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.gnu.org/licenses/gpl.html
*
* 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 under the License.
* --------------------------------------------------------------------------
* 版权 (c) 1997-2013, tinygroup.org ([email protected]).
*
* 本开源软件遵循 GPL 3.0 协议;
* 如果您不遵循此协议,则不被允许使用此文件。
* 你可以从下面的地址获取完整的协议文本
*
* http://www.gnu.org/licenses/gpl.html
*/
package org.tinygroup;
import java.io.File;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.tinygroup.mdatool.util.FileCreateUtil;
/**
* @goal compile
* @phase generate-sources
* @requiresDependencyResolution compile+runtime
*
*/
public class ProcessMdaCompile extends AbstractMojo {
/**
* @parameter expression="${project.compileClasspathElements}"
* @required
* @readonly
*
*/
private List classpathElements;
/**
* @parameter expression="${project.basedir}"
* @required
* @readonly
*/
private File baseDir;
/**
* @parameter expression="${project.build.sourceDirectory}"
* @required
* @readonly
*/
private File sourceDir;
/**
* @parameter expression="${project.build.testSourceDirectory}"
* @required
* @readonly
*/
private File testSourceDir;
/**
*
* Parameter expression = "${project.build.compileClasspathElements}"
* readonly required private List classpathElements;
*/
/**
* @parameter expression="${project.build.resources}"
* @readonly
*/
private List resources;
/**
* @parameter expression="${project.build.testResources}"
* @readonly
*/
private List testResources;
public void execute() throws MojoExecutionException {
getLog().info("Begin process Mda compile...");
try {
getLog().info(classpathElements.toString());
if (classpathElements == null) {
classpathElements = new ArrayList();
}
classpathElements.addAll(getClassPath());
FileCreateUtil.MDATrans(sourceDir.getPath(), resources.get(0)
.getDirectory(), classpathElements);
// StringBuffer cmd = new StringBuffer("java -classpath ");
// for (String path : classpathElements) {
// cmd.append(path);
// if (path != classpathElements.get(classpathElements.size() - 1)) {
// cmd.append(";");
// }
// }
// cmd.append(" org.tinygroup.mdatool.util.FileCreateUtil");
// cmd.append(" \"");
// cmd.append(sourceDir.getPath());
// cmd.append("\" \"");
// cmd.append(resources.get(0).getDirectory());
// cmd.append("\"");
// getLog().info("exceute command:" + cmd.toString());
// Process process = Runtime.getRuntime().exec(cmd.toString());
// InputStreamReader ir = new InputStreamReader(
// process.getInputStream());
// LineNumberReader input = new LineNumberReader(ir);
// PrintThread thread = new PrintThread(input);
// thread.start();
// process.waitFor();
// thread.end = true;
// if (process != null) {
// process.destroy();
// }
// ProcessBuilder builder = new ProcessBuilder(cmd.toString());
// //both read inputstream and errstream
// builder.redirectErrorStream(true);
// Process process = builder.start();
// BufferedReader br = new BufferedReader(new InputStreamReader(process
// .getInputStream()));
// String readLine = br.readLine();
// while (readLine != null) {
// System.out.println(readLine);
// readLine = br.readLine();
// }
// process.waitFor();
// if(process!=null){
// process.destroy();
// }
} catch (Exception e) {
getLog().error(e);
throw new MojoExecutionException(
"org.tinygroup.mdatool.util.FileCreateUtil执行失败"
+ e.getMessage());
}
getLog().info("End process Mda compile.");
}
private List getClassPath() {
List classPaths = new ArrayList();
String classPathProperty = System.getProperties()
.get("java.class.path").toString();
String[] classPathsArray = classPathProperty.split(";");
for (String classPath : classPathsArray) {
classPaths.add(classPath);
}
return classPaths;
}
}
class PrintThread extends Thread {
private LineNumberReader reader;
volatile boolean end = false;
PrintThread(LineNumberReader reader) {
this.reader = reader;
}
public void run() {
while (!end) {
try {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
sleep(5);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy