Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
#63 Added an --app-type parameter to "ml new". Still in testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcassel committed Mar 15, 2013
1 parent 8fb3a95 commit ba86623
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 1 deletion.
24 changes: 24 additions & 0 deletions deploy/lib/server_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ def self.init
sample_config = File.expand_path("../../sample/ml-config.sample.xml", __FILE__)
sample_properties = File.expand_path("../../sample/build.sample.properties", __FILE__)
build_properties = File.expand_path("../../build.properties", __FILE__)
options_dir = File.expand_path("../../../rest-api/options", __FILE__)
options_file = File.expand_path("../../../rest-api/options/all.xml", __FILE__)
sample_options = File.expand_path("../../sample/all.sample.xml", __FILE__)

force = find_arg(['--force']).present?
force_props = find_arg(['--force-properties']).present?
force_config = find_arg(['--force-config']).present?
app_type = find_arg(['--app-type'])

error_msg = []
if !force && !force_props && File.exists?(build_properties)
Expand All @@ -113,6 +117,20 @@ def self.init
name = ARGV.shift
properties_file.gsub!(/app-name=roxy/, "app-name=#{name}") if name

# do app-type customizations
properties_file.gsub!(/app-type=mvc/, "app-type=#{app_type}")

# If this app will use the ML REST API, we need rewrite-resolved-globally to get those URLs to work
if ["rest", "hybrid"].include? app_type
properties_file.gsub!(/rewrite-resolves-globally=/, "rewrite-resolves-globally=true")
end

if app_type == "rest"
# rest applications don't use Roxy's MVC structure, so they can use MarkLogic's rewriter and error handler
properties_file.gsub!(/url-rewriter=\/roxy\/rewrite.xqy/, "url-rewriter=/MarkLogic/rest-api/rewriter.xqy")
properties_file.gsub!(/error-handler=\/roxy\/error.xqy/, "error-handler=/MarkLogic/rest-api/error-handler.xqy")
end

# replace the text =random with a random string
o = (33..126).to_a
properties_file.gsub!(/=random/) do |match|
Expand All @@ -124,6 +142,12 @@ def self.init
open(build_properties, 'w') {|f| f.write(properties_file) }
end

# If this is a rest or hybrid app, set up some initial options
if ["rest", "hybrid"].include? app_type
FileUtils.mkdir_p options_dir
FileUtils.cp sample_options, options_file
end

target_config = File.expand_path(ServerConfig.properties["ml.config.file"], __FILE__)

if !force && !force_config && File.exists?(target_config)
Expand Down
57 changes: 57 additions & 0 deletions deploy/sample/all.sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<search:options xmlns:search="http://marklogic.com/appservices/search">
<search:search-option>unfiltered</search:search-option>
<search:page-length>10</search:page-length>
<search:term apply="term">
<search:empty apply="all-results"/>
<search:term-option>punctuation-insensitive</search:term-option>
<search:term-option>stemmed</search:term-option>
</search:term>
<search:grammar>
<search:quotation>"</search:quotation>
<search:implicit>
<cts:and-query strength="20" xmlns:cts="http://marklogic.com/cts"/>
</search:implicit>
<search:starter strength="30" apply="grouping" delimiter=")">(</search:starter>
<search:starter strength="40" apply="prefix" element="cts:not-query">-</search:starter>
<search:joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</search:joiner>
<search:joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</search:joiner>
<search:joiner strength="30" apply="infix" element="cts:near-query" tokenize="word">NEAR</search:joiner>
<search:joiner strength="30" apply="near2" consume="2" element="cts:near-query">NEAR/</search:joiner>
<search:joiner strength="50" apply="constraint">:</search:joiner>
<search:joiner strength="50" apply="constraint" compare="LT" tokenize="word">LT</search:joiner>
<search:joiner strength="50" apply="constraint" compare="LE" tokenize="word">LE</search:joiner>
<search:joiner strength="50" apply="constraint" compare="GT" tokenize="word">GT</search:joiner>
<search:joiner strength="50" apply="constraint" compare="GE" tokenize="word">GE</search:joiner>
<search:joiner strength="50" apply="constraint" compare="NE" tokenize="word">NE</search:joiner>
</search:grammar>
<search:sort-order direction="descending">
<search:score/>
</search:sort-order>
<search:transform-results apply="snippet">
<search:preferred-elements><search:element ns="" name="body"/></search:preferred-elements>
<search:max-matches>1</search:max-matches>
<search:max-snippet-chars>150</search:max-snippet-chars>
<search:per-match-tokens>20</search:per-match-tokens>
</search:transform-results>
<search:return-query>1</search:return-query>
<search:operator name="results">
<search:state name="compact">
<search:transform-results apply="snippet">
<search:preferred-elements><search:element ns="" name="body"/></search:preferred-elements>
<search:max-matches>1</search:max-matches>
<search:max-snippet-chars>150</search:max-snippet-chars>
<search:per-match-tokens>20</search:per-match-tokens>
</search:transform-results>
</search:state>
<search:state name="detailed">
<search:transform-results apply="snippet">
<search:preferred-elements><search:element ns="" name="body"/></search:preferred-elements>
<search:max-matches>2</search:max-matches>
<search:max-snippet-chars>400</search:max-snippet-chars>
<search:per-match-tokens>30</search:per-match-tokens>
</search:transform-results>
</search:state>
</search:operator>
<annotation xmlns="http://marklogic.com/appservices/search">Delta options here</annotation>
</search:options>
22 changes: 22 additions & 0 deletions deploy/sample/build.sample.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,28 @@ authentication-method=digest
#
appuser-password=random

#
# The type of application. Choices are:
# mvc: a normal, XQuery-based Roxy MVC app
# rest: an app based on the ML6 REST API
# hybrid: an app that uses Roxy rewriting and the ML6 REST API
# other: something other than the above
#
app-type=mvc

#
# the location of your REST API options
# relevant to app-types rest and hybrid.
#
rest-options.dir=${basedir}/rest-api

#
# The default values point to Roxy file
#
url-rewriter=/roxy/rewrite.xqy
error-handler=/roxy/error.xqy
rewrite-resolves-globally=

#
# the uris or IP addresses of your servers
# WARNING: if you are running these scripts on WINDOWS you may need to change localhost to 127.0.0.1
Expand Down
20 changes: 19 additions & 1 deletion ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ then

BRANCH="master"
INIT_GIT=0
APPTYPE="mvc"
for (( i = 0; i < ${#PARAMS[@]}; i++ )); do
if [[ ${PARAMS[${i}]} == --branch=* ]]
then
Expand All @@ -50,14 +51,31 @@ then
elif [[ ${PARAMS[${i}]} == --git* ]]
then
INIT_GIT=1
elif [[ ${PARAMS[${i}]} == --app-type* ]]
then
splits=(${PARAMS[${i}]//=/ })
APPTYPE=${splits[1]}
fi
done

if [ "$APPTYPE" != "mvc" ] && [ "$APPTYPE" != "rest" ] && [ "$APPTYPE" != "hybrid" ]
then
printf "\nValid values for app-type are mvc, rest and hybrid. Aborting\n"
exit 1
fi

printf "\nCreating new Application: ${app_name}..."
git clone git://github.com/marklogic/roxy.git -b ${BRANCH} ${app_name}
pushd ${app_name} > /dev/null
rm -rf .git*
./ml init ${app_name}
if [ "$APPTYPE" = "rest" ]
then
# For a REST application, we won't be using the MVC code. Remove it.
# mvc and hybrid apps will use it.
rm -rf src/*
printf "\nNo initial source code is provided for REST apps. You can copy code from Application Builder under the source directory."
fi
./ml init ${app_name} --app-type=${APPTYPE}
popd > /dev/null
printf " done\n"
if [ -e $app_name ]
Expand Down

0 comments on commit ba86623

Please sign in to comment.