| | |
| | | package de.uhilger.filecms.api;
|
| | |
|
| | | import de.uhilger.filecms.data.CompilerIssue;
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.File;
|
| | | import java.io.FileFilter;
|
| | | import java.io.IOException;
|
| | | import java.io.PrintStream;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Iterator;
|
| | |
| | | import javax.tools.StandardJavaFileManager;
|
| | | import javax.tools.ToolProvider;
|
| | | import org.apache.commons.io.FileUtils;
|
| | | import org.apache.tomcat.util.log.SystemLogHandler;
|
| | | import org.apache.tools.ant.Project;
|
| | | import org.apache.tools.ant.ProjectHelper;
|
| | |
|
| | | /**
|
| | | *
|
| | |
| | | public class CompileService extends Api {
|
| | |
|
| | | private static final Logger logger = Logger.getLogger(CompileService.class.getName());
|
| | | |
| | | public String antBuild(String relPath) {
|
| | | |
| | | // Create a stream to hold the output
|
| | | ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
| | | PrintStream ps = new PrintStream(baos);
|
| | | // IMPORTANT: Save the old System.out!
|
| | | PrintStream old = System.out;
|
| | | PrintStream err = System.err;
|
| | | // Tell Java to use your special stream
|
| | | System.setOut(ps); |
| | | System.setErr(ps);
|
| | | |
| | | File targetDir = getTargetDir(relPath); // App-Ordner
|
| | | StringBuilder sb = new StringBuilder();
|
| | | sb.append("Ant build ist noch nicht implementiert.");
|
| | |
|
| | | sb.append("<br/>");
|
| | | sb.append("targetDir: ");
|
| | | sb.append(targetDir.getAbsolutePath());
|
| | | |
| | | File buildFile = new File(targetDir, "build.xml");
|
| | | Project p = new Project();
|
| | | //p.setName("FileCms Build");
|
| | | FileCmsBuildListener listener = new FileCmsBuildListener();
|
| | | p.addBuildListener(listener);
|
| | | p.setUserProperty("ant.file", buildFile.getAbsolutePath());
|
| | | p.init();
|
| | | ProjectHelper helper = ProjectHelper.getProjectHelper();
|
| | | p.addReference("ant.projectHelper", helper);
|
| | | helper.parse(p, buildFile);
|
| | | p.executeTarget(p.getDefaultTarget()); |
| | | sb.append("<br/>");
|
| | | sb.append(listener.getOutput());
|
| | | |
| | | |
| | | // Print some output: goes to your special stream
|
| | | //System.out.println("Foofoofoo!");
|
| | | // Put things back
|
| | | System.out.flush();
|
| | | System.err.flush();
|
| | | System.setOut(old);
|
| | | System.setErr(err);
|
| | | // Show what happened
|
| | | //System.out.println("Here: " + baos.toString()); |
| | | |
| | | sb.append("<br/>");
|
| | | sb.append(baos.toString());
|
| | | |
| | | |
| | | return sb.toString();
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Annahme: relPath zeigt auf einen Ordner, in dem ein build-Ordner die
|
| | |
| | | }
|
| | |
|
| | | private final Iterable<String> buildOptions(File targetDir) {
|
| | | String cbase = getCatalinaBase();
|
| | | String cbase = getCatalinaBase(getServletContext());
|
| | | File lib = new File(cbase, "lib");
|
| | | String cp = "";
|
| | | cp = buildCPFromDir(cp, lib);
|