@Test public void requestFileOnNonzeroReturnCodeReturnsEmptyOptional() throws IOException, MavenInvocationException { Path targetDirectory = temporaryFolder.newFolder("target").toPath(); final String expectedJarBaseName = mir.getExpectedJarBaseName(mavenCoordinate, ClassifierInformation.DEFAULT_JAR); File expectedJarFile = new File(targetDirectory.toFile(), expectedJarBaseName); Mockito.when(defaultInvokerMock.execute(ArgumentMatchers.any(InvocationRequest.class))) .then((Answer<InvocationResult>) invocationOnMock -> { new FileOutputStream(expectedJarFile).close(); return getDummyInvocationResult(1); }); Optional<File> requestResult = mir.requestFile(mavenCoordinate, targetDirectory, ClassifierInformation.DEFAULT_JAR); assertThat(requestResult).isEmpty(); }
@Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { File expectedJarFile = getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation); if (expectedJarFile.exists()) { LOGGER.debug("The file " + expectedJarFile + " already exists and won't be downloaded again"); return Optional.of(expectedJarFile); } LOGGER.debug("Requesting artifact with id " + mavenCoordinate.toString()); boolean requestSuccessful = callMavenInvoker(mavenCoordinate, targetDirectory, classifierInformation.classifier); String jarType = classifierInformation.isSource ? "sources jar" : classifierInformation.classifier + " jar"; if (!requestSuccessful) { LOGGER.warn("Failed to find " + jarType + ": Artifact " + mavenCoordinate.toString() + " not found in repo."); return Optional.empty(); } else if (!expectedJarFile.exists()) { LOGGER.warn("Failed to find " + jarType + ": Maven call succeeded but Artifact was not generated in the expected place."); return Optional.empty(); } return Optional.of(getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation)); }
MavenInvokerRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { File expectedJarFile = getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation); if (expectedJarFile.exists()) { LOGGER.debug("The file " + expectedJarFile + " already exists and won't be downloaded again"); return Optional.of(expectedJarFile); } LOGGER.debug("Requesting artifact with id " + mavenCoordinate.toString()); boolean requestSuccessful = callMavenInvoker(mavenCoordinate, targetDirectory, classifierInformation.classifier); String jarType = classifierInformation.isSource ? "sources jar" : classifierInformation.classifier + " jar"; if (!requestSuccessful) { LOGGER.warn("Failed to find " + jarType + ": Artifact " + mavenCoordinate.toString() + " not found in repo."); return Optional.empty(); } else if (!expectedJarFile.exists()) { LOGGER.warn("Failed to find " + jarType + ": Maven call succeeded but Artifact was not generated in the expected place."); return Optional.empty(); } return Optional.of(getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation)); } }
MavenInvokerRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { File expectedJarFile = getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation); if (expectedJarFile.exists()) { LOGGER.debug("The file " + expectedJarFile + " already exists and won't be downloaded again"); return Optional.of(expectedJarFile); } LOGGER.debug("Requesting artifact with id " + mavenCoordinate.toString()); boolean requestSuccessful = callMavenInvoker(mavenCoordinate, targetDirectory, classifierInformation.classifier); String jarType = classifierInformation.isSource ? "sources jar" : classifierInformation.classifier + " jar"; if (!requestSuccessful) { LOGGER.warn("Failed to find " + jarType + ": Artifact " + mavenCoordinate.toString() + " not found in repo."); return Optional.empty(); } else if (!expectedJarFile.exists()) { LOGGER.warn("Failed to find " + jarType + ": Maven call succeeded but Artifact was not generated in the expected place."); return Optional.empty(); } return Optional.of(getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation)); } MavenInvokerRequester(File basedir);  MavenInvokerRequester(File basedir, URL sourceRepositoryUrl);  MavenInvokerRequester(File basedir, DefaultInvoker defaultInvoker, Optional<URL> sourceRepositoryUrl); }
MavenInvokerRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { File expectedJarFile = getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation); if (expectedJarFile.exists()) { LOGGER.debug("The file " + expectedJarFile + " already exists and won't be downloaded again"); return Optional.of(expectedJarFile); } LOGGER.debug("Requesting artifact with id " + mavenCoordinate.toString()); boolean requestSuccessful = callMavenInvoker(mavenCoordinate, targetDirectory, classifierInformation.classifier); String jarType = classifierInformation.isSource ? "sources jar" : classifierInformation.classifier + " jar"; if (!requestSuccessful) { LOGGER.warn("Failed to find " + jarType + ": Artifact " + mavenCoordinate.toString() + " not found in repo."); return Optional.empty(); } else if (!expectedJarFile.exists()) { LOGGER.warn("Failed to find " + jarType + ": Maven call succeeded but Artifact was not generated in the expected place."); return Optional.empty(); } return Optional.of(getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation)); } MavenInvokerRequester(File basedir);  MavenInvokerRequester(File basedir, URL sourceRepositoryUrl);  MavenInvokerRequester(File basedir, DefaultInvoker defaultInvoker, Optional<URL> sourceRepositoryUrl); @Override Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation); }
MavenInvokerRequester extends IArtifactRequester { @Override public Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation) { File expectedJarFile = getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation); if (expectedJarFile.exists()) { LOGGER.debug("The file " + expectedJarFile + " already exists and won't be downloaded again"); return Optional.of(expectedJarFile); } LOGGER.debug("Requesting artifact with id " + mavenCoordinate.toString()); boolean requestSuccessful = callMavenInvoker(mavenCoordinate, targetDirectory, classifierInformation.classifier); String jarType = classifierInformation.isSource ? "sources jar" : classifierInformation.classifier + " jar"; if (!requestSuccessful) { LOGGER.warn("Failed to find " + jarType + ": Artifact " + mavenCoordinate.toString() + " not found in repo."); return Optional.empty(); } else if (!expectedJarFile.exists()) { LOGGER.warn("Failed to find " + jarType + ": Maven call succeeded but Artifact was not generated in the expected place."); return Optional.empty(); } return Optional.of(getExpectedJarFile(mavenCoordinate, targetDirectory, classifierInformation)); } MavenInvokerRequester(File basedir);  MavenInvokerRequester(File basedir, URL sourceRepositoryUrl);  MavenInvokerRequester(File basedir, DefaultInvoker defaultInvoker, Optional<URL> sourceRepositoryUrl); @Override Optional<File> requestFile(Coordinate mavenCoordinate, Path targetDirectory, ClassifierInformation classifierInformation); static final String POM_FILENAME; }