Skip to content

Commit 1f4b47b

Browse files
committed
Merge branch '473-aspect-weaver-agent'
2 parents 7af5346 + 6416566 commit 1f4b47b

14 files changed

Lines changed: 189 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ To learn how to configure various properties of the buildpack, follow the "Confi
7373
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
7474
* Standard Frameworks
7575
* [AppDynamics Agent](docs/framework-app_dynamics_agent.md) ([Configuration](docs/framework-app_dynamics_agent.md#configuration))
76+
* [AspectJ Weaver Agent](docs/framework-aspectj_weaver_agent.md) ([Configuration](docs/framework-aspectj_weaver_agent.md#configuration))
7677
* [Client Certificate Mapper](docs/framework-client_certificate_mapper.md) ([Configuration](docs/framework-client_certificate_mapper.md#configuration))
7778
* [Container Customizer](docs/framework-container_customizer.md) ([Configuration](docs/framework-container_customizer.md#configuration))
7879
* [Container Security Provider](docs/framework-container_security_provider.md) ([Configuration](docs/framework-container_security_provider.md#configuration))

config/aspectj_weaver_agent.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
# AspectJ Weaver Agent configuration
17+
---
18+
enabled: true

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jres:
3838
# command after any Java Opts added by previous frameworks.
3939
frameworks:
4040
- "JavaBuildpack::Framework::AppDynamicsAgent"
41+
- "JavaBuildpack::Framework::AspectjWeaverAgent"
4142
- "JavaBuildpack::Framework::ClientCertificateMapper"
4243
- "JavaBuildpack::Framework::ContainerCustomizer"
4344
- "JavaBuildpack::Framework::ContainerSecurityProvider"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# AspectJ Weaver Agent Framework
2+
The AspectJ Weaver Agent Framework configures the AspectJ Runtime Weaving Agent at runtime.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td>
7+
<td><tt>aspectjweaver-*.jar</tt> existing and <tt>BOOT-INF/classes/META-INF/aop.xml</tt>, <tt>BOOT-INF/classes/org/aspectj/aop.xml</tt>, or <tt>META-INF/aop.xml</tt> existing.</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td>
11+
<td><tt>aspectj-weaver-agent=&lt;version&gt;</tt></td>
12+
</tr>
13+
</table>
14+
Tags are printed to standard output by the buildpack detect script
15+
16+
## Configuration
17+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
18+
19+
The framework can be configured by creating or modifying the [`config/aspectj_weaver_agent.yml`][] file in the buildpack fork.
20+
21+
| Name | Description
22+
| ---- | -----------
23+
| `enabled` | Whether to enable the AspectJ Runtime Weaving agent.
24+
25+
[`config/aspectj_weaver_agent.yml`]: ../config/aspect_weaver_agent.yml
26+
[Configuration and Extension]: ../README.md#configuration-and-extension
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
require 'java_buildpack/component/base_component'
17+
require 'java_buildpack/framework'
18+
require 'java_buildpack/util/dash_case'
19+
require 'java_buildpack/util/jar_finder'
20+
21+
module JavaBuildpack
22+
module Framework
23+
24+
# Encapsulates the functionality for contributing AspectJ Runtime Weaving configuration an application.
25+
class AspectjWeaverAgent < JavaBuildpack::Component::BaseComponent
26+
27+
# Creates an instance. In addition to the functionality inherited from +BaseComponent+, +@version+ and +@uri+
28+
# instance variables are exposed.
29+
#
30+
# @param [Hash] context a collection of utilities used by components
31+
def initialize(context)
32+
super(context)
33+
34+
@jar_finder = JavaBuildpack::Util::JarFinder.new(/.*aspectjweaver-([\d].*)\.jar/)
35+
end
36+
37+
# (see JavaBuildpack::Component::BaseComponent#detect)
38+
def detect
39+
supports? ? "#{self.class.to_s.dash_case}=#{@jar_finder.version(@application)}" : nil
40+
end
41+
42+
# (see JavaBuildpack::Component::BaseComponent#compile)
43+
def compile
44+
puts "-----> AspectJ #{version} Runtime Weaving Enabled"
45+
end
46+
47+
# (see JavaBuildpack::Component::BaseComponent#release)
48+
def release
49+
@droplet.java_opts.add_javaagent @jar_finder.is?(@application)
50+
end
51+
52+
private
53+
54+
def aop_xml_exist?
55+
(@application.root + 'BOOT-INF/classes/META-INF/aop.xml').exist? ||
56+
(@application.root + 'BOOT-INF/classes/org/aspectj/aop.xml').exist? ||
57+
(@application.root + 'META-INF/aop.xml').exist?
58+
end
59+
60+
def enabled?
61+
@configuration['enabled']
62+
end
63+
64+
def supports?
65+
enabled? && @jar_finder.is?(@application) && aop_xml_exist?
66+
end
67+
68+
def version
69+
@jar_finder.version(@application)
70+
end
71+
72+
end
73+
74+
end
75+
end

spec/fixtures/framework_aspectj_weaver_aop_xml_only/BOOT-INF/classes/META-INF/aop.xml

Whitespace-only changes.

spec/fixtures/framework_aspectj_weaver_classes/BOOT-INF/classes/org/aspectj/aop.xml

Whitespace-only changes.

spec/fixtures/framework_aspectj_weaver_classes/BOOT-INF/lib/aspectjweaver-1.8.10.jar

Whitespace-only changes.

spec/fixtures/framework_aspectj_weaver_classes_meta_inf/BOOT-INF/classes/META-INF/aop.xml

Whitespace-only changes.

spec/fixtures/framework_aspectj_weaver_classes_meta_inf/BOOT-INF/lib/aspectjweaver-1.8.10.jar

Whitespace-only changes.

0 commit comments

Comments
 (0)