Skip to content

Commit 98651e5

Browse files
committed
added checking for parent to decide not found resource is still clean or a failure
1 parent 1455712 commit 98651e5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

WebSphereClearCaches/src/main/java/de/novensa/techniques/maven/plugin/web/as/WebSphere/ClearCachesMojo.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
* consulting the mentioned script inside my WebSphere instance. This plugin helps in automating these tasks in your maven build chain.
3030
*
3131
* @author Daniel Schulz
32-
*
33-
* @goal clearCache
3432
*/
3533
@SuppressWarnings("UnusedDeclaration")
3634
@Mojo(name = "clearCaches", defaultPhase = LifecyclePhase.INSTALL)
@@ -155,6 +153,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
155153
wsHomeCanonical +
156154
locationsRelSteam;// location´s relative stem -- what does not change for any cleaning item
157155

156+
final File wsHomeProfileStemFile = new File(wsHomeProfileStem);
157+
if (!wsHomeProfileStemFile.exists()) {
158+
throw new IllegalStateException(String.format(ErrorMessages.PROFILES_DIRECTORY_DOES_NOT_EXIST,
159+
appServerProfile, locationsRelSteam));
160+
}
161+
158162
for (String cleaningItem : listOfCleaningItems) {
159163
processFile(wsHomeProfileStem + cleaningItem);
160164
}
@@ -245,6 +249,10 @@ private void processFile(final String path) throws MojoFailureException, MojoExe
245249
final File effectivePath = new File(dropEndingString(path, ANY_FILES_WITHIN));
246250

247251
if (!effectivePath.exists()) {
252+
// look for the parent to exist
253+
possiblyReportNotExistingParent(effectivePath.getParentFile());
254+
255+
// only iff parent was there -- else this is an exception and we are not here any more
248256
log(INFO, String.format(DIRECTORY_DOES_NOT_EXIST, effectivePath));
249257
cleanedCount++;
250258
filesToCleanCount++;
@@ -256,6 +264,9 @@ private void processFile(final String path) throws MojoFailureException, MojoExe
256264
if (effectivePath.exists()) {
257265
final File[] files = effectivePath.listFiles();
258266
if (null != files) {
267+
// check for existing parent
268+
possiblyReportNotExistingParent(effectivePath);
269+
259270
filesToCleanCount += files.length;
260271

261272
for (File file : files) {
@@ -266,12 +277,21 @@ private void processFile(final String path) throws MojoFailureException, MojoExe
266277
log(ERROR, String.format(DIRECTORY_DOES_NOT_EXIST, effectivePath));
267278
}
268279
} else {
280+
// check for existing parent
281+
possiblyReportNotExistingParent(effectivePath.getParentFile());
282+
269283
// clear the whole folder
270284
filesToCleanCount++;
271285
cleanFile(effectivePath);
272286
}
273287
}
274288

289+
private void possiblyReportNotExistingParent(final File effectivePath) {
290+
if (!effectivePath.exists() || !effectivePath.isDirectory()) {
291+
throw new IllegalStateException(String.format(ErrorMessages.DIRECTORY_DOES_NOT_EXIST, effectivePath));
292+
}
293+
}
294+
275295
private void cleanFile(final File file) throws MojoFailureException, MojoExecutionException {
276296
// check permissions
277297
if (!file.canWrite()) {

WebSphereClearCaches/src/main/java/de/novensa/techniques/maven/plugin/web/as/WebSphere/runtime/ErrorMessages.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public interface ErrorMessages {
3535

3636
static final String DIRECTORY_DOES_NOT_EXIST = "The directory '%s' cannot be found.";
3737

38+
static final String PROFILES_DIRECTORY_DOES_NOT_EXIST = "The profiles directory for the profile '%s' is not located in " +
39+
"'%s' where it is expected.";
40+
3841
static final String FILE_CANNOT_BE_RETRIEVED_ITS_CANONICAL_PATH_FROM = "The file '%s' cannot be retrieved it´s " +
3942
"canonical path from.";
4043

0 commit comments

Comments
 (0)