Permalink
Browse files

[#4] Move .mavenrc generation into a separate resource type and don't…

… create a user
  • Loading branch information...
1 parent fee3e4b commit 44cf065cb0c274c2006d66f54c3292cdf914febc @brettporter brettporter committed Apr 11, 2012
View
33 manifests/environment.pp
@@ -0,0 +1,33 @@
+# Copyright 2011 MaestroDev
+#
+# Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
+#
+# 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.
+
+# Define: maven::settings
+#
+# A puppet recipe to set the contents of the settings.xml file
+#
+define maven::environment( $user, $home = undef, $maven_opts = '', $maven_path_additions = '', $mavenrc_additions = '' ) {
+
+ if $home == undef {
+ $home_real = "/home/$user"
+ }
+ else {
+ $home_real = $home
+ }
+
+ file { "$home_real/.mavenrc":
+ mode => '0600',
+ owner => $user,
+ content => template('maven/mavenrc.erb'),
+ }
+}
View
21 manifests/maven.pp
@@ -32,23 +32,10 @@
#url => 'http://repo1.maven.org/maven2',
#username => '',
#password => '',
- }, $user = 'root', $home = '/root', $user_system = true,
- $maven_opts = '',
- $maven_path_additions = '',
- $mavenrc_additions = '') {
+ } ) {
$archive = "/tmp/apache-maven-${version}-bin.tar.gz"
- if !defined(User[$user]) {
- user { $user:
- ensure => present,
- home => $home,
- managehome => true,
- shell => '/bin/bash',
- system => $user_system,
- }
- }
-
# we could use puppet-stdlib function !empty(repo) but avoiding adding a new dependency for now
if "x${repo['url']}x" != 'xx' {
wget::authfetch { 'fetch-maven':
@@ -79,10 +66,4 @@
ensure => absent,
require => Exec['maven-untar'],
}
- file { "$home/.mavenrc":
- mode => '0600',
- owner => $user,
- content => template('maven/mavenrc.erb'),
- require => User[$user],
- }
}
View
11 spec/classes/maven_spec.rb
@@ -2,15 +2,6 @@
describe 'maven::maven' do
let(:title) { 'maven' }
- let(:params) { { :user => 'myuser' } }
-
- context "when user does not exist" do
- it { should contain_user('myuser') }
- end
-
- context "when running as root" do
- it { should contain_file('/root/.mavenrc') }
- end
context "when downloading maven" do
it do should contain_wget__fetch('fetch-maven').with(
@@ -21,7 +12,7 @@
end
context "when downloading maven from another repo" do
- let(:params) { { :user => 'myuser', :repo => {
+ let(:params) { { :repo => {
'url' => 'http://repo1.maven.org/maven2',
'username' => 'u',
'password' => 'p'
View
0 spec/defines/default-mavenrc
No changes.
View
36 spec/defines/environment_spec.rb
@@ -0,0 +1,36 @@
+require "#{File.join(File.dirname(__FILE__),'..','spec_helper')}"
+
+describe "maven::environment" do
+ let(:title) { 'environment' }
+ let(:params) { {
+ :user => "u",
+ } }
+
+ expected_filename = '/home/u/.mavenrc'
+ it { should contain_file(expected_filename).with_owner('u') }
+
+ it 'should generate valid mavenrc' do
+ content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
+ content.should == read_file("default-mavenrc")
+ end
+
+ context "provide options for mavenrc" do
+ let(:params) {{
+ :user => "u",
+ :maven_opts => "-Xmx256m",
+ :maven_path_additions => "/usr/local/bin",
+ :mavenrc_additions => "echo Hello World!"
+ }}
+
+ it 'should generate valid mavenrc' do
+ content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
+ content.should == read_file("populated-mavenrc")
+ end
+
+ end
+
+end
+
+def read_file(filename)
+ IO.read(File.expand_path(filename, File.dirname(__FILE__)))
+end
View
3 spec/defines/populated-mavenrc
@@ -0,0 +1,3 @@
+export MAVEN_OPTS="$MAVEN_OPTS -Xmx256m"
+export PATH="/usr/local/bin:$PATH"
+echo Hello World!
View
18 spec/defines/settings_spec.rb
@@ -1,4 +1,4 @@
-require "spec_helper"
+require "#{File.join(File.dirname(__FILE__),'..','spec_helper')}"
URL = 'http://localhost:8082/archiva/repository/all/'
MIRROR = {
@@ -47,7 +47,7 @@
it 'should generate valid settings.xml' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("default-settings.xml")
+ content.should == read_file("default-settings.xml")
end
context "with mirrors and settings" do
@@ -64,7 +64,7 @@
it 'should generate valid settings.xml when mirrors and servers are specified' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("mirror-servers-settings.xml")
+ content.should == read_file("mirror-servers-settings.xml")
end
end
@@ -81,7 +81,7 @@
it 'should generate valid settings.xml when default repository configuration is specified' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("default-repo-settings.xml")
+ content.should == read_file("default-repo-settings.xml")
end
end
@@ -100,7 +100,7 @@
it 'should generate valid settings.xml when default repository configuration is specified with only an url' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("default-repo-only-url-settings.xml")
+ content.should == read_file("default-repo-only-url-settings.xml")
end
end
@@ -118,7 +118,7 @@
it 'should generate valid settings.xml when properties are specified' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("properties-settings.xml")
+ content.should == read_file("properties-settings.xml")
end
end
@@ -136,7 +136,7 @@
it 'should generate valid settings.xml when local repository configuration is specified' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("local-repo-settings.xml")
+ content.should == read_file("local-repo-settings.xml")
end
end
@@ -158,13 +158,13 @@
it 'should generate valid settings.xml with everything specified' do
content = catalogue.resource('file', expected_filename).send(:parameters)[:content]
- content.should == read_settings_file("complete-settings.xml")
+ content.should == read_file("complete-settings.xml")
end
end
end
-def read_settings_file(filename)
+def read_file(filename)
IO.read(File.expand_path(filename, File.dirname(__FILE__)))
end
View
2 templates/mavenrc.erb
@@ -1,4 +1,4 @@
-<% if has_variable?("maven_opts") -%>
+<% if has_variable?("maven_opts") and maven_opts != "" -%>
export MAVEN_OPTS="$MAVEN_OPTS <%= maven_opts %>"
<% end -%>
<% if has_variable?("maven_path_additions") && maven_path_additions != "" -%>

0 comments on commit 44cf065

Please sign in to comment.