1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.efaps.rest;
22
23 import java.io.File;
24 import java.io.FilenameFilter;
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import javax.ws.rs.GET;
29 import javax.ws.rs.Path;
30 import javax.ws.rs.QueryParam;
31 import javax.ws.rs.core.Response;
32
33 import org.efaps.admin.EFapsSystemConfiguration;
34 import org.efaps.admin.KernelSettings;
35 import org.efaps.admin.common.SystemConfiguration;
36 import org.efaps.update.schema.program.esjp.ESJPCompiler;
37 import org.efaps.update.schema.program.jasperreport.JasperReportCompiler;
38 import org.efaps.update.schema.program.staticsource.CSSCompiler;
39 import org.efaps.update.schema.program.staticsource.JavaScriptCompiler;
40 import org.efaps.update.schema.program.staticsource.WikiCompiler;
41 import org.efaps.update.util.InstallationException;
42 import org.efaps.util.EFapsException;
43
44
45
46
47
48
49
50 @Path("/compile")
51 public class Compile
52 extends AbstractRest
53 {
54
55
56
57
58
59
60
61 @GET
62 public Response compile(@QueryParam("type") final String _type)
63 {
64 boolean success = false;
65 try {
66 if (hasAccess()) {
67 AbstractRest.LOG.info("===Starting Compiler via REST===");
68 if ("java".equalsIgnoreCase(_type)) {
69 AbstractRest.LOG.info("==Compiling Java==");
70 new ESJPCompiler(getClassPathElements()).compile(null, false);
71 } else if ("css".equalsIgnoreCase(_type)) {
72 AbstractRest.LOG.info("==Compiling CSS==");
73 new CSSCompiler().compile();
74 } else if ("js".equalsIgnoreCase(_type)) {
75 AbstractRest.LOG.info("==Compiling Javascript==");
76 new JavaScriptCompiler().compile();
77 } else if ("wiki".equalsIgnoreCase(_type)) {
78 AbstractRest.LOG.info("==Compiling Wiki==");
79 new WikiCompiler().compile();
80 } else if ("jasper".equalsIgnoreCase(_type)) {
81 AbstractRest.LOG.info("==Compiling JasperReports==");
82 new JasperReportCompiler(getClassPathElements()).compile();
83 }
84 success = true;
85 AbstractRest.LOG.info("===Ending Compiler via REST===");
86 }
87 } catch (final InstallationException e) {
88 AbstractRest.LOG.error("InstallationException", e);
89 } catch (final EFapsException e) {
90 AbstractRest.LOG.error("EFapsException", e);
91 }
92 return success ? Response.ok().build() : Response.noContent().build();
93 }
94
95
96
97
98
99 public static List<String> getClassPathElements()
100 throws EFapsException
101 {
102 final List<String> ret = new ArrayList<String>();
103 final SystemConfiguration config = EFapsSystemConfiguration.get();
104 final String paths = config.getAttributeValue(KernelSettings.CLASSPATHS);
105
106 if (paths != null) {
107 final File folder = new File(paths);
108 File[] files = null;
109 if (folder.isDirectory()) {
110 files = folder.listFiles(new FilenameFilter() {
111
112 @Override
113 public boolean accept(final File _dir,
114 final String _name)
115 {
116 final boolean ret;
117 if (new File(_dir, _name).isDirectory()) {
118 ret = false;
119 } else {
120 final String name = _name.toLowerCase();
121 ret = name.endsWith(".jar");
122 }
123 return ret;
124 }
125 });
126 for (final File file : files) {
127 ret.add(file.getAbsolutePath());
128 }
129 }
130 } else {
131 AbstractRest.LOG.info("==ClassPath is not configurated==");
132 }
133 return ret;
134 }
135 }