Skip to content

Commit f4e4034

Browse files
committed
Merge branch 'colorize'
2 parents c09cb38 + bb76ea8 commit f4e4034

6 files changed

Lines changed: 169 additions & 7 deletions

File tree

lib/java_buildpack/buildpack.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
require 'java_buildpack/component/mutable_java_home'
2626
require 'java_buildpack/component/security_providers'
2727
require 'java_buildpack/logging/logger_factory'
28+
require 'java_buildpack/util/colorize'
2829
require 'java_buildpack/util/configuration_utils'
2930
require 'java_buildpack/util/constantize'
3031
require 'java_buildpack/util/snake_case'
@@ -100,7 +101,7 @@ def release
100101

101102
private
102103

103-
BUILDPACK_MESSAGE = '-----> Java Buildpack Version: %s'.freeze
104+
BUILDPACK_MESSAGE = "#{'----->'.red.bold} #{'Java Buildpack'.blue.bold} %s".freeze
104105

105106
LOAD_ROOT = (Pathname.new(__FILE__).dirname + '..').freeze
106107

lib/java_buildpack/buildpack_version.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
require 'java_buildpack'
17+
require 'java_buildpack/util/colorize'
1718
require 'java_buildpack/util/configuration_utils'
1819
require 'java_buildpack/util/to_b'
1920

@@ -83,15 +84,15 @@ def to_hash
8384
# @return [String] a +String+ representation of the version
8485
def to_s(human_readable = true)
8586
s = []
86-
s << @version if @version
87-
s << (human_readable ? '(offline)' : 'offline') if @offline
87+
s << @version.blue if @version
88+
s << (human_readable ? '(offline)'.blue : 'offline') if @offline
8889

8990
if remote_string
9091
s << '|' if @version && human_readable
9192
s << remote_string
9293
end
9394

94-
s << 'unknown' if s.empty?
95+
s << 'unknown'.yellow if s.empty?
9596
s.join(human_readable ? ' ' : '-')
9697
end
9798

lib/java_buildpack/component/base_component.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
require 'fileutils'
1717
require 'java_buildpack/component'
1818
require 'java_buildpack/util/cache/application_cache'
19+
require 'java_buildpack/util/colorize'
1920
require 'java_buildpack/util/format_duration'
2021
require 'java_buildpack/util/shell'
2122
require 'java_buildpack/util/space_case'
@@ -86,10 +87,15 @@ def release
8687
# @return [Void]
8788
def download(version, uri, name = @component_name)
8889
download_start_time = Time.now
89-
print "-----> Downloading #{name} #{version} from #{uri.sanitize_uri} "
90+
print "#{'----->'.red.bold} Downloading #{name.blue.bold} #{version.to_s.blue} from #{uri.sanitize_uri} "
9091

9192
JavaBuildpack::Util::Cache::ApplicationCache.new.get(uri) do |file, downloaded|
92-
puts downloaded ? "(#{(Time.now - download_start_time).duration})" : '(found in cache)'
93+
if downloaded
94+
puts "(#{(Time.now - download_start_time).duration})".green.italic
95+
else
96+
puts '(found in cache)'.green.italic
97+
end
98+
9399
yield file
94100
end
95101
end
@@ -167,7 +173,7 @@ def with_timing(caption)
167173

168174
yield
169175

170-
puts "(#{(Time.now - start_time).duration})"
176+
puts "(#{(Time.now - start_time).duration})".green.italic
171177
end
172178

173179
private
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2017 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
class String
17+
18+
@color_enabled = true
19+
20+
class << self
21+
attr_accessor :color_enabled
22+
end
23+
24+
# Sets the string to bold
25+
def bold
26+
return self unless @color_enabled
27+
"\e[1m#{self}\e[22m"
28+
end
29+
30+
# Sets the string to italic
31+
def italic
32+
return self unless @color_enabled
33+
"\e[3m#{self}\e[23m"
34+
end
35+
36+
# Sets the string to underlined
37+
def underline
38+
return self unless @color_enabled
39+
"\e[4m#{self}\e[24m"
40+
end
41+
42+
# Sets the string to blink
43+
def blink
44+
return self unless @color_enabled
45+
"\e[5m#{self}\e[25m"
46+
end
47+
48+
# Sets the string reverse the current colors
49+
def reverse_color
50+
return self unless @color_enabled
51+
"\e[7m#{self}\e[27m"
52+
end
53+
54+
# Sets the string to black
55+
def black
56+
return self unless @color_enabled
57+
"\e[30m#{self}\e[0m"
58+
end
59+
60+
# Sets the string to red
61+
def red
62+
return self unless @color_enabled
63+
"\e[31m#{self}\e[0m"
64+
end
65+
66+
# Sets the string to green
67+
def green
68+
return self unless @color_enabled
69+
"\e[32m#{self}\e[0m"
70+
end
71+
72+
# Sets the string to yellow
73+
def yellow
74+
return self unless @color_enabled
75+
"\e[33m#{self}\e[0m"
76+
end
77+
78+
# Sets the string to blue
79+
def blue
80+
return self unless @color_enabled
81+
"\e[34m#{self}\e[0m"
82+
end
83+
84+
# Sets the string to magenta
85+
def magenta
86+
return self unless @color_enabled
87+
"\e[35m#{self}\e[0m"
88+
end
89+
90+
# Sets the string to cyan
91+
def cyan
92+
return self unless @color_enabled
93+
"\e[36m#{self}\e[0m"
94+
end
95+
96+
# Sets the string to white
97+
def white
98+
return self unless @color_enabled
99+
"\e[37m#{self}\e[0m"
100+
end
101+
102+
# Sets the string background to black
103+
def bg_black
104+
return self unless @color_enabled
105+
"\e[40m#{self}\e[0m"
106+
end
107+
108+
# Sets the string background to red
109+
def bg_red
110+
return self unless @color_enabled
111+
"\e[41m#{self}\e[0m"
112+
end
113+
114+
# Sets the string background to green
115+
def bg_green
116+
return self unless @color_enabled
117+
"\e[42m#{self}\e[0m"
118+
end
119+
120+
# Sets the string background to yellow
121+
def bg_yellow
122+
return self unless @color_enabled
123+
"\e[43m#{self}\e[0m"
124+
end
125+
126+
# Sets the string background to blue
127+
def bg_blue
128+
return self unless @color_enabled
129+
"\e[44m#{self}\e[0m"
130+
end
131+
132+
# Sets the string background to magenta
133+
def bg_magenta
134+
return self unless @color_enabled
135+
"\e[45m#{self}\e[0m"
136+
end
137+
138+
# Sets the string background to cyan
139+
def bg_cyan
140+
return self unless @color_enabled
141+
"\e[46m#{self}\e[0m"
142+
end
143+
144+
# Sets the string background to white
145+
def bg_white
146+
return self unless @color_enabled
147+
"\e[47m#{self}\e[0m"
148+
end
149+
150+
end

spec/console_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
require 'spec_helper'
1717
require 'tee'
18+
require 'java_buildpack/util/colorize'
1819

1920
shared_context 'console_helper' do
2021

@@ -32,6 +33,8 @@
3233
$stdout.add STDOUT
3334
$stderr.add STDERR
3435
end
36+
37+
String.color_enabled = false
3538
end
3639

3740
after do

spec/java_buildpack/buildpack_version_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
describe JavaBuildpack::BuildpackVersion do
2323
include_context 'application_helper'
24+
include_context 'console_helper'
2425
include_context 'logging_helper'
2526

2627
let(:buildpack_version) { described_class.new }

0 commit comments

Comments
 (0)