Skip to content

Commit

Permalink
[OpenLiberty#1651] remove m2 API, unify Maven versions, rework log an…
Browse files Browse the repository at this point in the history
…d Mojo
  • Loading branch information
bmarwell committed Mar 24, 2023
1 parent eccc148 commit 60c78a6
Show file tree
Hide file tree
Showing 39 changed files with 379 additions and 384 deletions.
29 changes: 3 additions & 26 deletions liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,11 @@
<artifactId>liberty-ant-tasks</artifactId>
<version>1.9.11</version>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>plugin-support</artifactId>
<version>1.0-alpha-1</version>
<exclusions>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-mapping</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.8.6</version>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<!-- dependencies to annotations -->
<dependency>
Expand Down Expand Up @@ -354,6 +331,6 @@
</profiles>

<prerequisites>
<maven>3.0</maven>
<maven>${maven.version}</maven>
</prerequisites>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class HelloBatch implements Batchlet {
@GET
@Produces(TEXT_PLAIN)
public String process() {
log.info("Called Batchlet.process()");
getLog().info("Called Batchlet.process()");
return "Batchlet.process()";
}
public void stop() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
log.info("SLF4J Logger is ready for messages.");
response.getWriter().append("hello world");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class HelloLogger {
@GET
@Produces(TEXT_PLAIN)
public String showLog() {
log.info("Here is the Log");
getLog().info("Here is the Log");
return "Log has been shown";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
Expand All @@ -53,7 +55,7 @@
* Liberty Abstract Mojo Support
*
*/
public abstract class AbstractLibertySupport extends MojoSupport {
public abstract class AbstractLibertySupport extends AbstractMojo {
/**
* Maven Project
*/
Expand Down Expand Up @@ -98,8 +100,7 @@ public RepositorySystemSession getRepoSession() {
return repoSession;
}

protected void init() throws MojoExecutionException, MojoFailureException {
super.init();
AbstractLibertySupport() throws MojoExecutionException, MojoFailureException {
// Initialize ant helper instance
ant.setProject(getProject());
}
Expand Down Expand Up @@ -151,7 +152,6 @@ public boolean include(Artifact artifact) {
*
* @throws MojoExecutionException Failed to create artifact
*/
@Override
protected Artifact getArtifact(final ArtifactItem item) throws MojoExecutionException {
Artifact artifact = getResolvedArtifact(item);

Expand Down Expand Up @@ -304,7 +304,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String
resolvedDependencies.add(artifact);
findTransitiveDependencies(artifact, getProject().getArtifacts(), resolvedDependencies);
} else {
log.warn("Unable to find artifact matching groupId "+ groupId +", artifactId "+artifactId+", version "+version+", type "+type+" and classifier "+classifier+" in configured repositories.");
getLog().warn("Unable to find artifact matching groupId "+ groupId +", artifactId "+artifactId+", version "+version+", type "+type+" and classifier "+classifier+" in configured repositories.");
}
} else {
Set<Artifact> artifacts = getProject().getArtifacts();
Expand Down Expand Up @@ -338,7 +338,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String
}
// Ignore test-scoped artifacts, by design
if (!"test".equals(projectArtifact.getScope())) {
log.debug("Found resolved dependency from project dependencies: " + projectArtifact.getGroupId() + ":"
getLog().debug("Found resolved dependency from project dependencies: " + projectArtifact.getGroupId() + ":"
+ projectArtifact.getArtifactId() + ":" + projectArtifact.getVersion());
resolvedDependencies.add(projectArtifact);
findTransitiveDependencies(projectArtifact, getProject().getArtifacts(), resolvedDependencies);
Expand All @@ -356,7 +356,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String
Artifact artifact = getArtifact(item);
// Ignore test-scoped artifacts, by design
if (!"test".equals(artifact.getScope())) {
log.debug("Found resolved dependency from project dependencyManagement " + dependency.getGroupId() + ":"
getLog().debug("Found resolved dependency from project dependencyManagement " + dependency.getGroupId() + ":"
+ dependency.getArtifactId() + ":" + dependency.getVersion());
resolvedDependencies.add(artifact);
findTransitiveDependencies(artifact, getProject().getArtifacts(), resolvedDependencies);
Expand All @@ -367,7 +367,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String

if (resolvedDependencies.isEmpty()) {
// No matching artifacts were found in the resolved dependencies. Send warning.
log.warn("Unable to find artifact matching groupId "+ groupId +", artifactId "+artifactId+" of any version in either project dependencies or in project dependencyManagement (note test-scoped dependencies are excluded).");
getLog().warn("Unable to find artifact matching groupId "+ groupId +", artifactId "+artifactId+" of any version in either project dependencies or in project dependencyManagement (note test-scoped dependencies are excluded).");
}
}

Expand Down Expand Up @@ -459,7 +459,7 @@ protected void findTransitiveDependencies(Artifact resolvedArtifact, Set<Artifac
if (!artifact.equals(resolvedArtifact) && (!isProvidedScope || isProvidedScopeAllowed)) {
List<String> depTrail = artifact.getDependencyTrail();
if (dependencyTrailContainsArtifact(coords, resolvedArtifact.getVersion(), depTrail)) {
log.info("Adding transitive dependency with scope: "+artifact.getScope()+" and GAV: "+artifact.getGroupId()+":"+artifact.getArtifactId()+":"+artifact.getVersion());
getLog().info("Adding transitive dependency with scope: "+artifact.getScope()+" and GAV: "+artifact.getGroupId()+":"+artifact.getArtifactId()+":"+artifact.getVersion());
resolvedDependencies.add(artifact);
}
}
Expand All @@ -484,7 +484,6 @@ protected boolean dependencyTrailContainsArtifact(String gaCoords, String versio
*
* @throws MojoExecutionException Failed to create artifact
*/
@Override
protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionException {
assert item != null;

Expand Down Expand Up @@ -512,16 +511,16 @@ private Artifact resolveFromProjectDependencies(ArtifactItem item) {
if (artifact.getGroupId().equals(item.getGroupId()) &&
artifact.getArtifactId().equals(item.getArtifactId()) &&
artifact.getType().equals(item.getType())) {
log.debug("Found ArtifactItem from project dependencies: " + artifact.getGroupId() + ":"
getLog().debug("Found ArtifactItem from project dependencies: " + artifact.getGroupId() + ":"
+ artifact.getArtifactId() + ":" + artifact.getVersion());
// if (!artifact.getVersion().equals(item.getVersion())) {
// item.setVersion(artifact.getVersion());
// }
return artifact;
}
}
log.debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()

getLog().debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
+ " is not found from project dependencies.");
return null;
}
Expand All @@ -535,13 +534,13 @@ private Dependency resolveFromProjectDepMgmt(ArtifactItem item) {
if (dependency.getGroupId().equals(item.getGroupId()) &&
dependency.getArtifactId().equals(item.getArtifactId()) &&
dependency.getType().equals(item.getType())) {
log.debug("Found ArtifactItem from project dependencyManagement " + dependency.getGroupId() + ":"
getLog().debug("Found ArtifactItem from project dependencyManagement " + dependency.getGroupId() + ":"
+ dependency.getArtifactId() + ":" + dependency.getVersion());
return dependency;
}
}
}
log.debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
getLog().debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
+ " is not found from project dependencyManagement.");
return null;
}
Expand All @@ -567,7 +566,7 @@ private Artifact resolveArtifactItem(final ArtifactItem item) throws MojoExecuti
artifact.setFile(artifactFile);
}
artifact.setResolved(true);
log.debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
getLog().debug(item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
+ " is resolved from project repositories.");
} else {
getLog().warn("Artifact " + item.getGroupId() + ":" + item.getArtifactId() + ":" + item.getVersion()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
*
*
*/
public class BasicSupport extends AbstractLibertySupport {
public abstract class BasicSupport extends AbstractLibertySupport {

//Note these next two are regular expressions, not just the code.
protected static final String START_APP_MESSAGE_REGEXP = "CWWKZ0001I.*";
Expand Down Expand Up @@ -198,12 +198,11 @@ protected static enum InstallType {
@Parameter(alias = "libertyRuntimeVersion", property = "liberty.runtime.version")
protected String libertyRuntimeVersion = null;

@Override
protected void init() throws MojoExecutionException, MojoFailureException {
public BasicSupport() throws MojoExecutionException, MojoFailureException {
super();
if (skip) {
return;
}
super.init();

if (skipServerConfigSetup) {
return;
Expand Down Expand Up @@ -388,9 +387,9 @@ private class InitLog {
public void flush() {
for (int i = 0; i < msgTypes.size(); i++) {
if (msgTypes.get(i) == MessageType.INFO) {
log.info(messages.get(i));
getLog().info(messages.get(i));
} else {
log.debug(messages.get(i));
getLog().debug(messages.get(i));
}
}
msgTypes.clear();
Expand All @@ -412,12 +411,12 @@ public void debug(String msg) {
/**
* Performs assembly installation unless the install type is pre-existing.
*
* @throws Exception
* @throws MojoExecutionException
*/
protected void installServerAssembly() throws Exception {
protected void installServerAssembly() throws MojoExecutionException, IOException {
initLog.flush();
if (installType == InstallType.ALREADY_EXISTS) {
log.info(MessageFormat.format(messages.getString("info.install.type.preexisting"), ""));
getLog().info(MessageFormat.format(messages.getString("info.install.type.preexisting"), ""));
} else {
if (installType == InstallType.FROM_ARCHIVE) {
installFromArchive();
Expand All @@ -428,26 +427,26 @@ protected void installServerAssembly() throws Exception {
}
}

protected void installFromFile() throws Exception {
protected void installFromFile() throws MojoExecutionException, IOException {
// Check if there is a different/newer archive or missing marker to trigger assembly install
File installMarker = new File(installDirectory, ".installed");

if (!refresh) {
if (!installMarker.exists()) {
refresh = true;
} else if (assemblyArchive.lastModified() > installMarker.lastModified()) {
log.debug(MessageFormat.format(messages.getString("debug.detect.assembly.archive"), ""));
getLog().debug(MessageFormat.format(messages.getString("debug.detect.assembly.archive"), ""));
refresh = true;
} else if(!assemblyArchive.getCanonicalPath().equals(FileUtils.fileRead(installMarker))) {
refresh = true;
}
} else {
log.debug(MessageFormat.format(messages.getString("debug.request.refresh"), ""));
getLog().debug(MessageFormat.format(messages.getString("debug.request.refresh"), ""));
}

String userDirectoryPath = userDirectory.getCanonicalPath();
if (refresh && installDirectory.exists() && installDirectory.isDirectory()) {
log.info(MessageFormat.format(messages.getString("info.uninstalling.server.home"), installDirectory));
getLog().info(MessageFormat.format(messages.getString("info.uninstalling.server.home"), installDirectory));
// Delete everything in the install directory except usr directory
for(File f : installDirectory.listFiles()) {
if(!(f.isDirectory() && f.getCanonicalPath().equals(userDirectoryPath))) {
Expand All @@ -458,7 +457,7 @@ protected void installFromFile() throws Exception {

// Install the assembly
if (!installMarker.exists()) {
log.info("Installing assembly...");
getLog().info("Installing assembly...");

FileUtils.forceMkdir(installDirectory);

Expand All @@ -483,11 +482,11 @@ protected void installFromFile() throws Exception {
// Write the assembly archive path so we can determine whether to install a different assembly in future invocations
FileUtils.fileWrite(installMarker, assemblyArchive.getCanonicalPath());
} else {
log.info(MessageFormat.format(messages.getString("info.reuse.installed.assembly"), ""));
getLog().info(MessageFormat.format(messages.getString("info.reuse.installed.assembly"), ""));
}
}

protected void installFromArchive() throws Exception {
protected void installFromArchive() throws MojoExecutionException {
InstallLibertyTask installTask = (InstallLibertyTask) ant.createTask("antlib:io/openliberty/tools/ant:install-liberty");
if (installTask == null) {
throw new IllegalStateException(MessageFormat.format(messages.getString("error.dependencies.not.found"), "install-liberty"));
Expand Down Expand Up @@ -540,7 +539,7 @@ protected void installLicense() throws MojoExecutionException, IOException {
if (licenseArtifact != null) {
Artifact license = getArtifact(licenseArtifact);
if (!hasSameLicense(license)) {
log.info(MessageFormat.format(messages.getString("info.install.license"),
getLog().info(MessageFormat.format(messages.getString("info.install.license"),
licenseArtifact.getGroupId() + ":" + licenseArtifact.getArtifactId() + ":" + licenseArtifact.getVersion()));
Java installLicenseTask = (Java) ant.createTask("java");
installLicenseTask.setJar(license.getFile());
Expand Down Expand Up @@ -581,7 +580,7 @@ private boolean hasSameLicense(Artifact license) throws MojoExecutionException,
if (license != null) {
InputStream licenseInfo = getZipEntry(license.getFile(), "wlp/lafiles/LI_en");
if (licenseInfo == null) {
log.warn(MessageFormat.format(messages.getString("warn.install.license"), license.getId()));
getLog().warn(MessageFormat.format(messages.getString("warn.install.license"), license.getId()));
return sameLicense;
}

Expand Down Expand Up @@ -661,11 +660,11 @@ protected Map<String,File> getLibertyDirectoryPropertyFiles() {
try {
return getLibertyDirectoryPropertyFiles(installDirectory, userDirectory, serverDirectory);
} catch (Exception e) {
log.warn("The properties for directories could not be initialized because an error occurred when accessing the directories.");
log.debug("Exception received: "+e.getMessage(), (Throwable) e);
getLog().warn("The properties for directories could not be initialized because an error occurred when accessing the directories.");
getLog().debug("Exception received: "+e.getMessage(), (Throwable) e);
}
} else {
log.warn("The " + serverDirectory + " directory cannot be accessed. The properties for directories could not be initialized.");
getLog().warn("The " + serverDirectory + " directory cannot be accessed. The properties for directories could not be initialized.");
}

return new HashMap<String,File> ();
Expand Down
Loading

0 comments on commit 60c78a6

Please sign in to comment.