Skip to content

Commit 079e5ec

Browse files
committed
Apply PR #19 from upstream jdcasey/directory-maven-plugin
See jdcasey/directory-maven-plugin#19
1 parent 06dbb7c commit 079e5ec

File tree

1 file changed

+78
-72
lines changed

1 file changed

+78
-72
lines changed

README.md

Lines changed: 78 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,47 @@ Using
2424

2525
The basic plugin declaration looks like the following:
2626

27-
<build>
28-
<plugins>
29-
<plugin>
30-
<groupId>org.commonjava.maven.plugins</groupId>
31-
<artifactId>directory-maven-plugin</artifactId>
32-
<version>0.1</version>
33-
<executions>
34-
<execution>
35-
<id>directories</id>
36-
<goals>
37-
<goal>[GOAL NAME]</goal>
38-
</goals>
39-
<phase>initialize</phase>
40-
<configuration>
41-
<property>myDirectory</property>
42-
</configuration>
43-
</execution>
44-
</executions>
45-
</plugin>
46-
<plugin>
47-
<artifactId>maven-antrun-plugin</artifactId>
48-
<version>1.7</version>
49-
<executions>
50-
<execution>
51-
<id>echo</id>
52-
<phase>initialize</phase>
53-
<goals>
54-
<goal>run</goal>
55-
</goals>
56-
<configuration>
57-
<target>
58-
<echo>Test Configuration Directory: ${myDirectory}/src/test/configs</echo>
59-
</target>
60-
</configuration>
61-
</execution>
62-
</executions>
63-
</plugin>
64-
</plugins>
65-
</build>
27+
```xml
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.commonjava.maven.plugins</groupId>
32+
<artifactId>directory-maven-plugin</artifactId>
33+
<version>0.1</version>
34+
<executions>
35+
<execution>
36+
<id>directories</id>
37+
<goals>
38+
<goal>[GOAL NAME]</goal>
39+
</goals>
40+
<phase>initialize</phase>
41+
<configuration>
42+
<property>myDirectory</property>
43+
</configuration>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-antrun-plugin</artifactId>
49+
<version>1.7</version>
50+
<executions>
51+
<execution>
52+
<id>echo</id>
53+
<phase>initialize</phase>
54+
<goals>
55+
<goal>run</goal>
56+
</goals>
57+
<configuration>
58+
<target>
59+
<echo>Test Configuration Directory: ${myDirectory}/src/test/configs</echo>
60+
</target>
61+
</configuration>
62+
</execution>
63+
</executions>
64+
</plugin>
65+
</plugins>
66+
</build>
67+
```
6668

6769
Note: We're using the `antrun` plugin here to illustrate the proper way to make use of the discovered directories. They will be useful **ONLY IN PLUGIN CONFIGURATIONS, NOT DURING POM INTERPOLATION**.
6870

@@ -71,15 +73,16 @@ execution-root Goal
7173

7274
This goal's output is roughly equivalent to using the `${session.executionRootDirectory}` expression in a plugin parameter value. Using the `execution-root` goal in place of `[GOAL NAME]` above, we see the following:
7375

74-
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:execution-root (directories) @ routem-web-admin ---
75-
[INFO] Execution-Root set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem
76-
[INFO]
77-
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
78-
[INFO] Executing tasks
79-
80-
main:
81-
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/src/test/configs
76+
```
77+
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:execution-root (directories) @ routem-web-admin ---
78+
[INFO] Execution-Root set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem
79+
[INFO]
80+
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
81+
[INFO] Executing tasks
8282
83+
main:
84+
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/src/test/configs
85+
```
8386

8487
**NOTE:** This goal will inject a property that contains the absolute path of the directory in which Maven was invoked. Each project will have the property, and any plugins that execute after the `directory:execution-root` runs will have access to it.
8588

@@ -88,27 +91,28 @@ directory-of Goal
8891

8992
If, instead of the execution root, you need to reference a directory in a specific module within the reactor, but don't want to do endless relative-path calculus, you can use the `directory-of` goal. For this goal to function properly, you need to specify a `project` parameter containing `groupId` and `artifactId`, like this:
9093

91-
<configuration>
92-
<property>myDirectory</property>
93-
<project>
94-
<groupId>org.commonjava.routem</groupId>
95-
<artifactId>routem-api</artifactId>
96-
</project>
97-
</configuration>
98-
94+
```xml
95+
<configuration>
96+
<property>myDirectory</property>
97+
<project>
98+
<groupId>org.commonjava.routem</groupId>
99+
<artifactId>routem-api</artifactId>
100+
</project>
101+
</configuration>
102+
```
99103

100104
Now, when we substitute `directory-of` for `[GOAL NAME]` in the usage template above, we get output like this:
101105

106+
```
107+
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:directory-of (directories) @ routem-web-admin ---
108+
[INFO] Directory of org.commonjava.routem:routem-api set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/api
109+
[INFO]
110+
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
111+
[INFO] Executing tasks
102112
103-
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:directory-of (directories) @ routem-web-admin ---
104-
[INFO] Directory of org.commonjava.routem:routem-api set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/api
105-
[INFO]
106-
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
107-
[INFO] Executing tasks
108-
109-
main:
110-
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/api/src/test/configs
111-
113+
main:
114+
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/api/src/test/configs
115+
```
112116

113117
**NOTE:** This goal will function similarly to `execution-root` in terms of injecting a project property for later plugins to use. **HOWEVER**, if the reference project isn't found in the current build session, this goal will fail the build.
114118

@@ -121,13 +125,15 @@ If the multimodule hierarchy uses multiple sibling parents from the disk that ar
121125

122126
If we modify the `execution-root` example to use the `highest-basedir` goal, then execute from the web/admin subdirectory of our sample project, we will see the following:
123127

124-
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:highest-basedir (directories) @ routem-web-admin ---
125-
[INFO] Highest basedir set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem
126-
[INFO]
127-
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
128-
[INFO] Executing tasks
128+
```
129+
[INFO] --- directory-maven-plugin:0.1-SNAPSHOT:highest-basedir (directories) @ routem-web-admin ---
130+
[INFO] Highest basedir set to: /Users/jdcasey/workspace/couch-java-looseLeaf/routem
131+
[INFO]
132+
[INFO] --- maven-antrun-plugin:1.7:run (echo) @ routem-web-admin ---
133+
[INFO] Executing tasks
129134
130-
main:
131-
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/src/test/configs
135+
main:
136+
[echo] Test Configuration Directory: /Users/jdcasey/workspace/couch-java-looseLeaf/routem/src/test/configs
137+
```
132138

133-
That is, the highest parent basedir attainable using the `relativePath` element of the projects' `parent` specifications.
139+
That is, the highest parent basedir attainable using the `relativePath` element of the projects' `parent` specifications.

0 commit comments

Comments
 (0)