Skip to content

Commit

Permalink
Issue a warning when unexpected override is added
Browse files Browse the repository at this point in the history
Also move to SLF4j logging.
  • Loading branch information
cstamas committed Aug 14, 2024
1 parent 36ad2ec commit c22d3b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
<version>${mavenVersion}</version>
<scope>provided</scope>
</dependency>
<!-- This is here to override 3.0 coming with maven-artifact-transfer -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
Expand All @@ -130,6 +129,12 @@
<!-- To work in Maven versions older than 3.9.0 -->
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
Expand Down Expand Up @@ -171,12 +176,6 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -57,6 +58,8 @@
import org.eclipse.aether.repository.LocalRepository;
import org.eclipse.aether.repository.LocalRepositoryManager;
import org.eclipse.aether.util.artifact.SubArtifact;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static java.util.Objects.isNull;

Expand All @@ -68,6 +71,7 @@
@Mojo(name = "install-file", requiresProject = false, aggregator = true, threadSafe = true)
public class InstallFileMojo extends AbstractMojo {
private static final String LS = System.lineSeparator();
private final Logger log = LoggerFactory.getLogger(InstallFileMojo.class);

@Component
private RepositorySystem repositorySystem;
Expand Down Expand Up @@ -178,7 +182,7 @@ public class InstallFileMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
if (!file.exists()) {
String message = "The specified file '" + file.getPath() + "' does not exist";
getLog().error(message);
log.error(message);
throw new MojoFailureException(message);
}

Expand All @@ -198,8 +202,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
newSession, new LocalRepository(localRepositoryPath, contentType));
newSession.setLocalRepositoryManager(localRepositoryManager);
repositorySystemSession = newSession;
getLog().debug("localRepoPath: "
+ localRepositoryManager.getRepository().getBasedir());
log.debug("localRepoPath: " + localRepositoryManager.getRepository().getBasedir());
}

File temporaryPom = null;
Expand All @@ -208,7 +211,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
temporaryPom = readingPomFromJarFile();
if (!Boolean.TRUE.equals(generatePom)) {
pomFile = temporaryPom;
getLog().debug("Using JAR embedded POM as pomFile");
log.debug("Using JAR embedded POM as pomFile");
}
} else {
processModel(readModel(pomFile));
Expand Down Expand Up @@ -240,6 +243,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
mainArtifactExtension = packaging;
}
}
if (extension != null && !Objects.equals(extension, mainArtifactExtension)) {
log.warn(
"Main artifact extension should be '{}' but was overridden to '{}'",
mainArtifactExtension,
extension);
}
Artifact mainArtifact = new DefaultArtifact(
groupId, artifactId, classifier, extension != null ? extension : mainArtifactExtension, version)
.setFile(file);
Expand All @@ -257,10 +266,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (isNull(pomFile)) {
if (Boolean.TRUE.equals(generatePom) || (generatePom == null && !pomLocalFile.exists())) {
temporaryPom = generatePomFile();
getLog().debug("Installing generated POM");
log.debug("Installing generated POM");
installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", temporaryPom));
} else if (generatePom == null) {
getLog().debug("Skipping installation of generated POM, already present in local repository");
log.debug("Skipping installation of generated POM, already present in local repository");
}
} else {
installRequest.addArtifact(new SubArtifact(mainArtifact, "", "pom", pomFile));
Expand Down Expand Up @@ -305,15 +314,15 @@ private File readingPomFromJarFile() throws MojoExecutionException {

if (isNull(pomEntry)) {
// This means there is no entry which matches the "pom.xml"...(or in other words: not packaged by Maven)
getLog().info("pom.xml not found in " + file.getName());
log.info("pom.xml not found in " + file.getName());
return null;
}

Path tempPomFile = Files.createTempFile(base, ".pom");

Files.copy(jarFile.getInputStream(pomEntry), tempPomFile, StandardCopyOption.REPLACE_EXISTING);

getLog().debug("Loading " + pomEntry.getName());
log.debug("Loading " + pomEntry.getName());
processModel(readModel(tempPomFile.toFile()));
return tempPomFile.toFile();

Expand Down

0 comments on commit c22d3b5

Please sign in to comment.