[ https://issues.apache.org/jira/browse/MNG-7629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17649086#comment-17649086 ]
ASF GitHub Bot commented on MNG-7629: ------------------------------------- mthmulders commented on code in PR #912: URL: https://github.com/apache/maven/pull/912#discussion_r1051659869 ########## maven-core/src/main/java/org/apache/maven/ReactorReader.java: ########## @@ -139,187 +132,75 @@ private File find(MavenProject project, Artifact artifact) { return project.getFile(); } - Artifact projectArtifact = findMatchingArtifact(project, artifact); - File packagedArtifactFile = determinePreviouslyPackagedArtifactFile(project, projectArtifact); - - if (hasArtifactFileFromPackagePhase(projectArtifact)) { - return projectArtifact.getFile(); - } - // Check whether an earlier Maven run might have produced an artifact that is still on disk. - else if (packagedArtifactFile != null - && packagedArtifactFile.exists() - && isPackagedArtifactUpToDate(project, packagedArtifactFile, artifact)) { - return packagedArtifactFile; - } else if (!hasBeenPackagedDuringThisSession(project)) { - // fallback to loose class files only if artifacts haven't been packaged yet - // and only for plain old jars. Not war files, not ear files, not anything else. - return determineBuildOutputDirectoryForArtifact(project, artifact); - } - - // The fall-through indicates that the artifact cannot be found; - // for instance if package produced nothing or classifier problems. - return null; + Path target = getArtifactPath(artifact); + return Files.isRegularFile(target) ? target.toFile() : null; } - private File determineBuildOutputDirectoryForArtifact(final MavenProject project, final Artifact artifact) { - if (isTestArtifact(artifact)) { - if (project.hasLifecyclePhase("test-compile")) { - return new File(project.getBuild().getTestOutputDirectory()); - } - } else { - String type = artifact.getProperty("type", ""); - File outputDirectory = new File(project.getBuild().getOutputDirectory()); + public void processProject(MavenProject project) { + List<Artifact> artifacts = new ArrayList<>(); - // Check if the project is being built during this session, and if we can expect any output. - // There is no need to check if the build has created any outputs, see MNG-2222. - boolean projectCompiledDuringThisSession = - project.hasLifecyclePhase("compile") && COMPILE_PHASE_TYPES.contains(type); - - // Check if the project is part of the session (not filtered by -pl, -rf, etc). If so, we check - // if a possible earlier Maven invocation produced some output for that project which we can use. - boolean projectHasOutputFromPreviousSession = - !session.getProjects().contains(project) && outputDirectory.exists(); - - if (projectHasOutputFromPreviousSession || projectCompiledDuringThisSession) { - return outputDirectory; - } + artifacts.add(RepositoryUtils.toArtifact(new ProjectArtifact(project))); + if (!"pom".equals(project.getPackaging())) { + org.apache.maven.artifact.Artifact mavenMainArtifact = project.getArtifact(); + artifacts.add(RepositoryUtils.toArtifact(mavenMainArtifact)); } - - // The fall-through indicates that the artifact cannot be found; - // for instance if package produced nothing or classifier problems. - return null; - } - - private File determinePreviouslyPackagedArtifactFile(MavenProject project, Artifact artifact) { - if (artifact == null) { - return null; + for (org.apache.maven.artifact.Artifact attached : project.getAttachedArtifacts()) { + artifacts.add(RepositoryUtils.toArtifact(attached)); } - String fileName = String.format("%s.%s", project.getBuild().getFinalName(), artifact.getExtension()); - return new File(project.getBuild().getDirectory(), fileName); - } - - private boolean hasArtifactFileFromPackagePhase(Artifact projectArtifact) { - return projectArtifact != null - && projectArtifact.getFile() != null - && projectArtifact.getFile().exists(); - } - - private boolean isPackagedArtifactUpToDate(MavenProject project, File packagedArtifactFile, Artifact artifact) { - Path outputDirectory = Paths.get(project.getBuild().getOutputDirectory()); - if (!outputDirectory.toFile().exists()) { - return true; - } - - try (Stream<Path> outputFiles = Files.walk(outputDirectory)) { - // Not using File#lastModified() to avoid a Linux JDK8 milliseconds precision bug: JDK-8177809. - long artifactLastModified = - Files.getLastModifiedTime(packagedArtifactFile.toPath()).toMillis(); - - if (session.getProjectBuildingRequest().getBuildStartTime() != null) { - long buildStartTime = - session.getProjectBuildingRequest().getBuildStartTime().getTime(); - if (artifactLastModified > buildStartTime) { - return true; - } - } - - Iterator<Path> iterator = outputFiles.iterator(); - while (iterator.hasNext()) { - Path outputFile = iterator.next(); - - if (Files.isDirectory(outputFile)) { - continue; - } - - long outputFileLastModified = - Files.getLastModifiedTime(outputFile).toMillis(); - if (outputFileLastModified > artifactLastModified) { - File alternative = determineBuildOutputDirectoryForArtifact(project, artifact); - if (alternative != null) { - LOGGER.warn( - "File '{}' is more recent than the packaged artifact for '{}'; using '{}' instead", - relativizeOutputFile(outputFile), - project.getArtifactId(), - relativizeOutputFile(alternative.toPath())); - } else { - LOGGER.warn( - "File '{}' is more recent than the packaged artifact for '{}'; " - + "cannot use the build output directory for this type of artifact", - relativizeOutputFile(outputFile), - project.getArtifactId()); - } - return false; + for (Artifact artifact : artifacts) { + if (artifact.getFile() != null && artifact.getFile().isFile()) { + Path target = getArtifactPath(artifact); + try { + Files.createDirectories(target.getParent()); + Files.copy(artifact.getFile().toPath(), target, StandardCopyOption.REPLACE_EXISTING); Review Comment: I was thinking about 'info', but I'm not sure about it and your question made me rethink. Thinking out loud... Is it meaningful to the user? Not sure. Is it meaningful to Maven developers? Pretty sure. So from that POV, I think 'debug' would be the best option. > Revert MNG-6118 and provide a better solution for it > ---------------------------------------------------- > > Key: MNG-7629 > URL: https://issues.apache.org/jira/browse/MNG-7629 > Project: Maven > Issue Type: Task > Reporter: Guillaume Nodet > Assignee: Guillaume Nodet > Priority: Major > Fix For: 4.0.0-alpha-4 > > -- This message was sent by Atlassian Jira (v8.20.10#820010)