Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public Set<File> getIncludedSources(File sourceDir, File targetDir) throws Inclu
for (SourceMapping mapping : srcMappings) {
Set<File> targetFiles = mapping.getTargetFiles(targetDir, path);

if (targetFiles == null) {
continue;
}

// never include files that don't have corresponding target mappings.
// the targets don't have to exist on the filesystem, but the
// mappers must tell us to look for them.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.shared.io.scan;

import java.io.File;
import java.nio.file.Files;
import java.util.Set;

import org.apache.maven.shared.io.scan.mapping.SourceMapping;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

class StaleResourceScannerTest {

@Test
void shouldNotNpeWhenGetTargetFilesReturnsNull() throws Exception {
StaleResourceScanner scanner = new StaleResourceScanner();
scanner.addSourceMapping(new SourceMapping() {
@Override
public Set<File> getTargetFiles(File targetDir, String source) {
return null;
}
});

File baseDir = new File("target");
baseDir.mkdirs();
File sourceDir = Files.createTempDirectory(baseDir.toPath(), "stale-scanner-src-")
.toFile();
File targetDir = Files.createTempDirectory(baseDir.toPath(), "stale-scanner-tgt-")
.toFile();
Files.createTempFile(sourceDir.toPath(), "source", ".txt");

assertDoesNotThrow(() -> scanner.getIncludedSources(sourceDir, targetDir));
}
}
Loading