Skip to content

Commit d0e9044

Browse files
committed
APIs for Embedding Nginx-Clojure into a Clojure/Java/Groovy App nginx-clojure#86
1 parent c121cbc commit d0e9044

File tree

23 files changed

+1536
-39
lines changed

23 files changed

+1536
-39
lines changed

nginx-clojure-embed/.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src/java"/>
4+
<classpathentry kind="src" path="test/clojure"/>
5+
<classpathentry kind="src" path="src/clojure"/>
6+
<classpathentry kind="src" path="test/java"/>
7+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
8+
<classpathentry combineaccessrules="false" kind="src" path="/nginx-clojure"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

nginx-clojure-embed/.cproject

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
3+
<storageModule moduleId="org.eclipse.cdt.core.settings">
4+
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.462319580">
5+
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.462319580" moduleId="org.eclipse.cdt.core.settings" name="Default">
6+
<externalSettings/>
7+
<extensions>
8+
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
9+
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
10+
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
11+
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
12+
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
13+
<extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
14+
</extensions>
15+
</storageModule>
16+
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
17+
<configuration artifactName="${ProjName}" buildProperties="" description="" id="cdt.managedbuild.toolchain.gnu.base.462319580" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
18+
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.462319580.368433803" name="/" resourcePath="">
19+
<toolChain id="cdt.managedbuild.toolchain.gnu.base.425888929" name="cdt.managedbuild.toolchain.gnu.base" superClass="cdt.managedbuild.toolchain.gnu.base">
20+
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="cdt.managedbuild.target.gnu.platform.base.498022717" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
21+
<builder id="cdt.managedbuild.target.gnu.builder.base.443178568" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
22+
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1817145567" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
23+
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1359665258" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
24+
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1667345015" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
25+
<option id="gnu.c.compiler.option.include.paths.1083125429" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
26+
<listOptionValue builtIn="false" value="/usr/lib/jvm/java-6-oracle/include"/>
27+
<listOptionValue builtIn="false" value="/usr/lib/jvm/java-6-oracle/include/linux"/>
28+
</option>
29+
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1571571834" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
30+
</tool>
31+
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.528083659" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base">
32+
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1901829430" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
33+
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
34+
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
35+
</inputType>
36+
</tool>
37+
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1697905506" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
38+
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1957621802" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
39+
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.473902444" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
40+
</tool>
41+
</toolChain>
42+
</folderInfo>
43+
<sourceEntries>
44+
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src/c"/>
45+
</sourceEntries>
46+
</configuration>
47+
</storageModule>
48+
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
49+
</cconfiguration>
50+
</storageModule>
51+
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
52+
<project id="nginx-clojure-embed.null.1768795332" name="nginx-clojure-embed"/>
53+
</storageModule>
54+
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
55+
<storageModule moduleId="refreshScope" versionNumber="2">
56+
<configuration configurationName="Default">
57+
<resource resourceType="PROJECT" workspacePath="/nginx-clojure-embed"/>
58+
</configuration>
59+
</storageModule>
60+
<storageModule moduleId="scannerConfiguration">
61+
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
62+
<scannerConfigBuildInfo instanceId="cdt.managedbuild.toolchain.gnu.base.462319580;cdt.managedbuild.toolchain.gnu.base.462319580.368433803;cdt.managedbuild.tool.gnu.c.compiler.base.1667345015;cdt.managedbuild.tool.gnu.c.compiler.input.1571571834">
63+
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
64+
</scannerConfigBuildInfo>
65+
</storageModule>
66+
</cproject>

nginx-clojure-embed/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/Makefile
2+
*.o
3+
*.class
4+
*.so
5+
/target
6+
/bin
7+
.settings
8+
/.README.md.html
9+
/logs
10+
/temp
11+
/res
12+
/ngx-memoryleak
13+
/.lein-failures

nginx-clojure-embed/.project

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>nginx-clojure-embed</name>
4+
<comment></comment>
5+
<projects>
6+
<project>nginx-clojure</project>
7+
<project>nginx-current</project>
8+
</projects>
9+
<buildSpec>
10+
<buildCommand>
11+
<name>ccw.builder</name>
12+
<arguments>
13+
</arguments>
14+
</buildCommand>
15+
<buildCommand>
16+
<name>ccw.leiningen.builder</name>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
<buildCommand>
21+
<name>org.eclipse.jdt.core.javabuilder</name>
22+
<arguments>
23+
</arguments>
24+
</buildCommand>
25+
<buildCommand>
26+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
27+
<triggers>clean,full,incremental,</triggers>
28+
<arguments>
29+
</arguments>
30+
</buildCommand>
31+
<buildCommand>
32+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
33+
<triggers>full,incremental,</triggers>
34+
<arguments>
35+
</arguments>
36+
</buildCommand>
37+
</buildSpec>
38+
<natures>
39+
<nature>org.eclipse.cdt.core.cnature</nature>
40+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
41+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
42+
<nature>org.eclipse.jdt.core.javanature</nature>
43+
<nature>ccw.leiningen.nature</nature>
44+
<nature>ccw.nature</nature>
45+
</natures>
46+
</projectDescription>

nginx-clojure-embed/LICENSE

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Copyright (c) Zhang, Yuexiang (xfeep)
2+
All rights reserved.
3+
4+
The BSD 3-Clause License
5+
6+
Redistribution and use in source and binary forms, with or without modification,
7+
are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice, this
13+
list of conditions and the following disclaimer in the documentation and/or
14+
other materials provided with the distribution.
15+
16+
* Neither the name of Zhang, Yuexiang (xfeep) nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
24+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+

nginx-clojure-embed/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# nginx-clojure-embed
2+
3+
Embeding Nginx-Clojure into a standard java/clojure app without additional Nginx process
4+
5+
Jar Repository
6+
================
7+
8+
For Clojure
9+
10+
```clojure
11+
[nginx-clojure/nginx-clojure-embed "0.4.1"]
12+
```
13+
14+
For Java (Maven)
15+
16+
```xml
17+
<repository>
18+
<id>clojars.org</id>
19+
<url>http://clojars.org/repo</url>
20+
</repository>
21+
```
22+
23+
```xml
24+
<dependency>
25+
<groupId>nginx-clojure</groupId>
26+
<artifactId>nginx-clojure-embed</artifactId>
27+
<version>0.4.1</version>
28+
</dependency>
29+
```
30+
31+
Quick Start
32+
================
33+
34+
For Clojure
35+
36+
```clojure
37+
;;(1) Starts it with ring handler and an options map
38+
;;my-app can be a simple ring hanler or a compojure router.
39+
(run-server my-app {:port 8080})
40+
41+
42+
;;(2) Starts it with a nginx.conf file
43+
(run-server \"/my-dir/nginx.conf\")
44+
45+
;;(3) Starts it with a given work dir
46+
(binding [*nginx-work-dir* my-work-dir]
47+
(run-server ...))
48+
```
49+
50+
For Java
51+
52+
```java
53+
54+
```

nginx-clojure-embed/configure

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/sh
2+
3+
# Copyright (C) Zhang,Yuexiang (xfeep)
4+
5+
NGINX_SRC=$NGINX_SRC
6+
NGINX_CLOJURE_SRC=$(pwd)/..
7+
NGINX_CLOJURE_EMBED_SRC=$(pwd)
8+
9+
help(){
10+
echo "[Usage]:" \
11+
"env NGINX_SRC=nginx-src-path ./configure"
12+
echo "[example]: env NGINX_SRC=/home/who/share/tmp/nginx-release-1.8.0 ./configure"
13+
}
14+
15+
if ! [ -f $NGINX_SRC/src/core/nginx.c ]; then
16+
echo "[ERROR]:nginx source not found:\$NGINX_SRC=\"$NGINX_SRC\""
17+
help
18+
exit 1
19+
fi
20+
21+
if ! [ -f $NGINX_CLOJURE_SRC/src/c/ngx_http_clojure_mem.c ]; then
22+
echo "[ERROR]:nginx-clojure source not found:\$NGINX_CLOJURE_SRC=\"$NGINX_CLOJURE_SRC\""
23+
help
24+
exit 1
25+
fi
26+
27+
28+
29+
##check jdk
30+
if ! type javac; then
31+
echo "javac not found, please put it in your PATH"
32+
exit 1
33+
fi
34+
35+
if ! type java; then
36+
echo "java not found, please put it in your PATH"
37+
exit 1
38+
fi
39+
40+
javac $NGINX_CLOJURE_SRC/src/java/nginx/clojure/DiscoverJvm.java
41+
42+
if [ -z $JNI_INCS ]; then
43+
JNI_INCS=`java -classpath $NGINX_CLOJURE_SRC/src/java nginx.clojure.DiscoverJvm getJniIncludes`;
44+
fi
45+
46+
nginx_clojure_embed_ext=`java -classpath $NGINX_CLOJURE_SRC/src/java nginx.clojure.DiscoverJvm detectOSArchExt`
47+
nginx_clojure_embed_ext="-$nginx_clojure_embed_ext"
48+
rm $NGINX_CLOJURE_SRC/src/java/nginx/clojure/DiscoverJvm.class
49+
50+
cd $NGINX_SRC
51+
if ! [ -f src/core/nginx.c.org ]; then
52+
cp src/core/nginx.c src/core/nginx.c.org
53+
# sed -e ':a' -e 'N' -e '$!ba' -e 's/static[ ]ngx_int_t ngx_save_argv/ngx_int_t ngx_save_argv/g' src/core/nginx.c > src/core/nginx.c-new
54+
# sed -e ':a' -e 'N' -e '$!ba' -e 's/static[ ]ngx_int_t\s*\n*ngx_save_argv/ngx_int_t ngx_save_argv/g' src/core/nginx.c-new > src/core/nginx.c
55+
sed -e ':a' -e 'N' -e '$!ba' -e 's/static[ ]ngx_int_t/ngx_int_t/g' src/core/nginx.c > src/core/nginx.c-new
56+
mv src/core/nginx.c-new src/core/nginx.c
57+
fi
58+
59+
set -- --prefix= \
60+
--conf-path=conf/nginx.conf --pid-path=logs/nginx.pid \
61+
--http-log-path=logs/access.log --error-log-path=logs/error.log \
62+
--sbin-path=nginx --http-client-body-temp-path=temp/client_body_temp \
63+
--http-proxy-temp-path=temp/proxy_temp \
64+
--without-http_charset_module \
65+
--without-http_ssi_module \
66+
--without-http_userid_module \
67+
--without-http_auth_basic_module \
68+
--without-http_autoindex_module \
69+
--without-http_geo_module \
70+
--without-http_map_module \
71+
--without-http_split_clients_module \
72+
--without-http_referer_module \
73+
--without-http_fastcgi_module \
74+
--without-http_uwsgi_module \
75+
--without-http_scgi_module \
76+
--without-http_memcached_module \
77+
--without-http_limit_conn_module \
78+
--without-http_limit_req_module \
79+
--without-http_empty_gif_module \
80+
--without-http_browser_module \
81+
--without-http_upstream_hash_module \
82+
--without-http_upstream_ip_hash_module \
83+
--without-http_upstream_least_conn_module \
84+
--without-http_upstream_keepalive_module \
85+
--without-http-cache \
86+
--without-mail_pop3_module \
87+
--without-mail_imap_module \
88+
--without-mail_smtp_module \
89+
--with-debug \
90+
--add-module=${NGINX_CLOJURE_SRC}/src/c \
91+
--add-module=${NGINX_CLOJURE_EMBED_SRC}/src/c \
92+
93+
if [ -f "auto/configure" ]; then
94+
. auto/configure
95+
else
96+
. ./configure
97+
fi
98+
99+
100+
101+
nginx_clojure_embed_shared_lib=nginx-clojure-embed${nginx_clojure_embed_ext}
102+
103+
cat << END >> objs/Makefile
104+
105+
106+
$NGX_OBJS${ngx_dirsep}${nginx_clojure_embed_shared_lib}: $ngx_deps$ngx_spacer
107+
\$(LINK) ${ngx_long_start}${ngx_binout}$NGX_OBJS${ngx_dirsep}${nginx_clojure_embed_shared_lib}$ngx_long_cont$ngx_objs$ngx_libs$ngx_link
108+
$ngx_rcc
109+
${ngx_long_end}
110+
111+
embed: $NGX_OBJS${ngx_dirsep}${nginx_clojure_embed_shared_lib}
112+
mkdir -p "$NGINX_CLOJURE_EMBED_SRC/res/slib"
113+
cp $NGX_OBJS${ngx_dirsep}${nginx_clojure_embed_shared_lib} $NGINX_CLOJURE_EMBED_SRC/res/slib
114+
if type strip; then \
115+
strip -x -S $NGINX_CLOJURE_EMBED_SRC/res/slib/${nginx_clojure_embed_shared_lib}; \
116+
fi
117+
cd $NGINX_CLOJURE_EMBED_SRC; \
118+
echo "finish build nginx-clojure embed"
119+
END
120+
121+
echo "creating $NGINX_CLOJURE_EMBED_SRC\Makefile"
122+
cd $NGINX_CLOJURE_EMBED_SRC
123+
cat << END > Makefile
124+
default:
125+
cd $NGINX_SRC; \
126+
\$(MAKE) -f objs/Makefile embed
127+
cd $NGINX_CLOJURE_EMBED_SRC
128+
129+
clean:
130+
cd $NGINX_SRC; \
131+
\$(MAKE) clean
132+
cd $NGINX_CLOJURE_EMBED_SRC; \
133+
rm $NGINX_CLOJURE_EMBED_SRC/res/slib/${nginx_clojure_embed_shared_lib} && \
134+
rm Makefile
135+
END
136+
137+
echo "done"
138+
echo "please try make to compile shared library of nginx-clojure-embed"

nginx-clojure-embed/project.clj

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
(defproject nginx-clojure/nginx-clojure-embed "0.4.1"
2+
:description "Embeding Nginx-Clojure into a standard clojure/java/groovy app without additional Nginx process"
3+
:url "https://github.com/nginx-clojure/nginx-clojure/nginx-clojure-embed"
4+
:license {:name "BSD 3-Clause license"
5+
:url "http://opensource.org/licenses/BSD-3-Clause"}
6+
:plugins []
7+
:dependencies [
8+
[nginx-clojure/nginx-clojure "0.4.1"]
9+
]
10+
:source-paths ["src/clojure"]
11+
:java-source-paths ["src/java"]
12+
:resource-paths ["res" "src/java"]
13+
:target-path "target/"
14+
:jar-exclusions [#"^test" #"Test.*class$" #".*for_test.clj$"]
15+
:javac-options ["-target" "1.6" "-source" "1.6" "-g" "-nowarn"]
16+
:test-paths ["test/clojure"]
17+
:profiles {
18+
:provided {
19+
:dependencies [
20+
[org.clojure/clojure "1.5.1"]]
21+
}
22+
:dev {:dependencies [;only for test / compile usage
23+
[ring/ring-core "1.2.1"]
24+
[compojure "1.1.6"]
25+
[clj-http "0.7.8"]
26+
[stylefruits/gniazdo "0.4.0"]
27+
]}}
28+
)

0 commit comments

Comments
 (0)