Skip to content

Commit 53d51a0

Browse files
committed
Upgraded to maven-javadoc-plugin 3.10.0
1 parent 8a8a16b commit 53d51a0

File tree

4 files changed

+149
-25
lines changed

4 files changed

+149
-25
lines changed

guava/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@
5656
<option>summary</option>
5757
</additionalOptions>
5858
<links>
59-
<link>https://guava.dev/releases/${guava.version}/api/docs/</link>
60-
</links>
61-
<offlineLinks>
6259
<!--
6360
The plugin looks for Javadoc at ${project.url}/apidocs but Github doesn't support
6461
this layout
6562
-->
63+
<link>https://guava.dev/releases/${guava.version}/api/docs/</link>
64+
</links>
65+
<offlineLinks>
6666
<offlineLink>
6767
<url>https://cowwoc.github.io/requirements.java/${project.version}/docs/api/</url>
68-
<location>${rootBaseDir}/guava/target/apidocs/</location>
68+
<location>${rootBaseDir}/java/target/reports/apidocs/</location>
6969
</offlineLink>
7070
</offlineLinks>
7171
<excludePackageNames>

jackson/pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@
5656
<option>summary</option>
5757
</additionalOptions>
5858
<links>
59-
<link>https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/${jackson.version}/
60-
</link>
61-
</links>
62-
<offlineLinks>
6359
<!--
6460
The plugin looks for Javadoc at ${project.url}/apidocs but Github doesn't support
6561
this layout
6662
-->
63+
<link>https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-databind/${jackson.version}/
64+
</link>
65+
</links>
66+
<offlineLinks>
6767
<offlineLink>
6868
<url>https://cowwoc.github.io/requirements.java/${project.version}/docs/api/</url>
69-
<location>${rootBaseDir}/java/target/apidocs/</location>
69+
<location>${rootBaseDir}/java/target/reports/apidocs/</location>
7070
</offlineLink>
7171
</offlineLinks>
7272
<excludePackageNames>

java/src/main/java/com/github/cowwoc/requirements10/java/internal/util/StampedLocks.java

Lines changed: 139 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.concurrent.Callable;
66
import java.util.concurrent.locks.StampedLock;
7+
import java.util.function.Supplier;
78

89
/**
910
* Helper functions for {@code StampedLock}s.
@@ -29,7 +30,7 @@ private StampedLocks()
2930
*
3031
* @param <V> the type of value returned by the task
3132
* @param lock a lock
32-
* @param task the task to run while holding the lock
33+
* @param task the task to run
3334
* @return the value returned by the task
3435
* @throws NullPointerException if any of the arguments are null
3536
* @throws WrappedCheckedException if any checked exceptions are thrown
@@ -51,7 +52,7 @@ public static <V> V optimisticRead(StampedLock lock, Callable<V> task)
5152
*
5253
* @param <V> the type of value returned by the task
5354
* @param lock a lock
54-
* @param task the task to run while holding the lock
55+
* @param task the task to run
5556
* @return the value returned by the task
5657
* @throws NullPointerException if any of the arguments are null
5758
* @throws WrappedCheckedException if {@code task} throws a checked exception
@@ -73,26 +74,30 @@ public static <V> V read(StampedLock lock, Callable<V> task)
7374
* Acquires a write lock and runs a task.
7475
*
7576
* @param lock a lock
76-
* @param task the task to run while holding the lock
77-
* @return a write lock as a resource
78-
* @throws NullPointerException if {@code lock} is null
77+
* @param task the task to run
78+
* @throws NullPointerException if any of the arguments are null
7979
*/
80-
public static <V> V write(StampedLock lock, Runnable task)
80+
public static void write(StampedLock lock, Runnable task)
8181
{
82-
return write(lock, () ->
82+
long stamp = lock.writeLock();
83+
try
8384
{
84-
task.run();
85-
return null;
86-
});
85+
runTask(task);
86+
}
87+
finally
88+
{
89+
lock.unlockWrite(stamp);
90+
}
8791
}
8892

8993
/**
9094
* Acquires a write lock and runs a task.
9195
*
96+
* @param <V> the type of value returned by the task
9297
* @param lock a lock
93-
* @param task the task to run while holding the lock
94-
* @return a write lock as a resource
95-
* @throws NullPointerException if {@code lock} is null
98+
* @param task the task to run
99+
* @return the value returned by the task
100+
* @throws NullPointerException if any of the arguments are null
96101
*/
97102
public static <V> V write(StampedLock lock, Callable<V> task)
98103
{
@@ -107,11 +112,30 @@ public static <V> V write(StampedLock lock, Callable<V> task)
107112
}
108113
}
109114

115+
/**
116+
* Runs a task.
117+
*
118+
* @param task the task to run
119+
* @throws NullPointerException if {@code task} is null
120+
* @throws WrappedCheckedException if {@code task} throws a checked exception
121+
*/
122+
private static void runTask(Runnable task)
123+
{
124+
try
125+
{
126+
task.run();
127+
}
128+
catch (Exception e)
129+
{
130+
throw WrappedCheckedException.wrap(e);
131+
}
132+
}
133+
110134
/**
111135
* Runs a task.
112136
*
113137
* @param <V> the type of value returned by the task
114-
* @param task the task to run while holding the lock
138+
* @param task the task to run
115139
* @return the value returned by the task
116140
* @throws NullPointerException if {@code task} is null
117141
* @throws WrappedCheckedException if {@code task} throws a checked exception
@@ -127,4 +151,105 @@ private static <V> V runTask(Callable<V> task)
127151
throw WrappedCheckedException.wrap(e);
128152
}
129153
}
154+
155+
/**
156+
* Returns a value, initializing it if it hasn't been initialized yet.
157+
*
158+
* @param <V> the type of value returned by the task
159+
* @param lock the lock used to ensure thread safety
160+
* @param supplier returns the value, or {@code null} if it hasn't been initialized yet
161+
* @param initializer initializes the value if it hasn't been initialized yet and returns it
162+
* @return the initialized value
163+
* @throws NullPointerException if any of the arguments are null
164+
*/
165+
public static <V> V getLazilyInitializedValue(StampedLock lock, Supplier<V> supplier,
166+
Callable<V> initializer)
167+
{
168+
long stamp = lock.tryOptimisticRead();
169+
if (stamp == 0)
170+
return getLazilyInitializedValueUsingRead(lock, supplier, initializer);
171+
V value = supplier.get();
172+
if (!lock.validate(stamp))
173+
return getLazilyInitializedValueUsingRead(lock, supplier, initializer);
174+
if (value != null)
175+
return value;
176+
stamp = lock.tryConvertToWriteLock(stamp);
177+
if (stamp == 0)
178+
return getLazilyInitializedValueUsingWrite(lock, supplier, initializer);
179+
try
180+
{
181+
return runTask(initializer);
182+
}
183+
finally
184+
{
185+
lock.unlockWrite(stamp);
186+
}
187+
}
188+
189+
/**
190+
* Returns a value, initializing it if it hasn't been initialized yet, using a read lock.
191+
*
192+
* @param <V> the type of value returned by the task
193+
* @param lock the lock used to ensure thread safety
194+
* @param supplier returns the value, or {@code null} if it hasn't been initialized yet
195+
* @param initializer initializes the value if it hasn't been initialized yet
196+
* @return the initialized value
197+
* @throws NullPointerException if any of the arguments are null
198+
*/
199+
private static <V> V getLazilyInitializedValueUsingRead(StampedLock lock, Supplier<V> supplier,
200+
Callable<V> initializer)
201+
{
202+
long stamp = lock.readLock();
203+
V value;
204+
try
205+
{
206+
value = supplier.get();
207+
}
208+
catch (RuntimeException e)
209+
{
210+
lock.unlockRead(stamp);
211+
throw e;
212+
}
213+
if (value != null)
214+
{
215+
lock.unlockRead(stamp);
216+
return value;
217+
}
218+
stamp = lock.tryConvertToWriteLock(stamp);
219+
if (stamp == 0)
220+
{
221+
lock.unlockRead(stamp);
222+
return getLazilyInitializedValueUsingWrite(lock, supplier, initializer);
223+
}
224+
try
225+
{
226+
return runTask(initializer);
227+
}
228+
finally
229+
{
230+
lock.unlockWrite(stamp);
231+
}
232+
}
233+
234+
/**
235+
* Returns a value, initializing it if it hasn't been initialized yet, using a write lock.
236+
*
237+
* @param <V> the type of value returned by the task
238+
* @param lock the lock used to ensure thread safety
239+
* @param supplier returns the value, or {@code null} if it hasn't been initialized yet
240+
* @param initializer initializes the value if it hasn't been initialized yet
241+
* @return the value
242+
* @throws NullPointerException if any of the arguments are null
243+
*/
244+
private static <V> V getLazilyInitializedValueUsingWrite(StampedLock lock, Supplier<V> supplier,
245+
Callable<V> initializer)
246+
{
247+
return write(lock, () ->
248+
{
249+
V value = supplier.get();
250+
if (value != null)
251+
return value;
252+
return runTask(initializer);
253+
});
254+
}
130255
}

pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@
185185
<plugin>
186186
<groupId>org.apache.maven.plugins</groupId>
187187
<artifactId>maven-javadoc-plugin</artifactId>
188-
<!-- WORKAROUND: https://issues.apache.org/jira/browse/MJAVADOC-813 -->
189-
<version>3.8.0</version>
188+
<version>3.10.0</version>
190189
<executions>
191190
<execution>
192191
<id>default-cli</id>

0 commit comments

Comments
 (0)