Skip to content

Commit

Permalink
[OpenLiberty#1651] convert ArtifactItem and CommonLogger; add constru…
Browse files Browse the repository at this point in the history
…ctors
  • Loading branch information
bmarwell committed Mar 24, 2023
1 parent fff9bc0 commit 380329f
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 60 deletions.
8 changes: 7 additions & 1 deletion liberty-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,17 @@
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<!-- TODO: replace -->
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-mapping</artifactId>
<version>3.0.0</version>
</dependency>
<!-- dependencies to annotations -->
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.4</version>
<version>3.2</version>
<scope>provided</scope> <!-- annotations are needed only to build the plugin -->
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,18 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
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;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.settings.Settings;
import org.codehaus.mojo.pluginsupport.MojoSupport;
import org.codehaus.mojo.pluginsupport.ant.AntHelper;
import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -152,7 +148,7 @@ public boolean include(Artifact artifact) {
*
* @throws MojoExecutionException Failed to create artifact
*/
protected Artifact getArtifact(final ArtifactItem item) throws MojoExecutionException {
protected Artifact getArtifact(final Dependency item) throws MojoExecutionException {
Artifact artifact = getResolvedArtifact(item);

if (artifact == null) {
Expand All @@ -175,7 +171,7 @@ protected Artifact getArtifact(final ArtifactItem item) throws MojoExecutionExce
*
* @throws MojoExecutionException Failed to create artifact
*/
protected Artifact getResolvedArtifact(final ArtifactItem item) throws MojoExecutionException {
protected Artifact getResolvedArtifact(final Dependency item) throws MojoExecutionException {
assert item != null;
Artifact artifact = null;

Expand Down Expand Up @@ -205,7 +201,7 @@ protected Artifact getResolvedArtifact(final ArtifactItem item) throws MojoExecu
}

/**
* Equivalent to {@link #getArtifact(ArtifactItem)} with an ArtifactItem
* Equivalent to {@link #getArtifact(Dependency)} with an ArtifactItem
* defined by the given the coordinates. Retrieves the main artifact (i.e. with no classifier).
*
* <p>This is the same as calling
Expand All @@ -230,7 +226,7 @@ protected Artifact getArtifact(String groupId, String artifactId, String type, S
}

/**
* Equivalent to {@link #getArtifact(ArtifactItem)} with an ArtifactItem
* Equivalent to {@link #getArtifact(Dependency)} with an ArtifactItem
* defined by the given the coordinates.
*
* @param groupId
Expand All @@ -249,7 +245,7 @@ protected Artifact getArtifact(String groupId, String artifactId, String type, S
* Failed to create artifact
*/
protected Artifact getArtifact(String groupId, String artifactId, String type, String version, String classifier ) throws MojoExecutionException {
ArtifactItem item = new ArtifactItem();
Dependency item = new Dependency();
item.setGroupId(groupId);
item.setArtifactId(artifactId);
item.setType(type);
Expand All @@ -259,16 +255,16 @@ protected Artifact getArtifact(String groupId, String artifactId, String type, S
return getArtifact(item);
}

protected ArtifactItem createArtifactItem(String groupId, String artifactId, String type, String version) {
protected Dependency createArtifactItem(String groupId, String artifactId, String type, String version) {
return getArtifactItem( groupId, artifactId, type, version, null );
}

protected ArtifactItem createArtifactItem(String groupId, String artifactId, String type, String version, String classifier) {
protected Dependency createArtifactItem(String groupId, String artifactId, String type, String version, String classifier) {
return getArtifactItem( groupId, artifactId, type, version, classifier );
}

private ArtifactItem getArtifactItem( String groupId, String artifactId, String type, String version, String classifier ) {
ArtifactItem item = new ArtifactItem();
private Dependency getArtifactItem( String groupId, String artifactId, String type, String version, String classifier ) {
Dependency item = new Dependency();
item.setGroupId(groupId);
item.setArtifactId(artifactId);
item.setType(type);
Expand Down Expand Up @@ -333,7 +329,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String
for (Artifact projectArtifact : artifacts) {
if (isMatchingProjectDependency(projectArtifact, groupId, isWildcard, compareArtifactId, isClassifierWildcard, compareClassifier)) {
if (!projectArtifact.isResolved()) {
ArtifactItem item = createArtifactItem(projectArtifact.getGroupId(), projectArtifact.getArtifactId(), projectArtifact.getType(), projectArtifact.getVersion(), projectArtifact.getClassifier());
Dependency item = createArtifactItem(projectArtifact.getGroupId(), projectArtifact.getArtifactId(), projectArtifact.getType(), projectArtifact.getVersion(), projectArtifact.getClassifier());
projectArtifact = getArtifact(item);
}
// Ignore test-scoped artifacts, by design
Expand All @@ -352,7 +348,7 @@ protected Set<Artifact> getResolvedDependencyWithTransitiveDependencies( String

for (Dependency dependency : list) {
if (isMatchingProjectDependency(dependency, groupId, isWildcard, compareArtifactId, isClassifierWildcard, compareClassifier)) {
ArtifactItem item = createArtifactItem(dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getVersion(), dependency.getClassifier());
Dependency item = createArtifactItem(dependency.getGroupId(), dependency.getArtifactId(), dependency.getType(), dependency.getVersion(), dependency.getClassifier());
Artifact artifact = getArtifact(item);
// Ignore test-scoped artifacts, by design
if (!"test".equals(artifact.getScope())) {
Expand Down Expand Up @@ -484,7 +480,7 @@ protected boolean dependencyTrailContainsArtifact(String gaCoords, String versio
*
* @throws MojoExecutionException Failed to create artifact
*/
protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionException {
protected Artifact createArtifact(final Dependency item) throws MojoExecutionException {
assert item != null;

if (item.getVersion() == null) {
Expand All @@ -504,7 +500,7 @@ protected Artifact createArtifact(final ArtifactItem item) throws MojoExecutionE
return resolveArtifactItem(item);
}

private Artifact resolveFromProjectDependencies(ArtifactItem item) {
private Artifact resolveFromProjectDependencies(Dependency item) {
Set<Artifact> actifacts = getProject().getArtifacts();

for (Artifact artifact : actifacts) {
Expand All @@ -525,7 +521,7 @@ private Artifact resolveFromProjectDependencies(ArtifactItem item) {
return null;
}

private Dependency resolveFromProjectDepMgmt(ArtifactItem item) {
private Dependency resolveFromProjectDepMgmt(Dependency item) {
// if project has dependencyManagement section
if (getProject().getDependencyManagement() != null) {
List<Dependency> list = getProject().getDependencyManagement().getDependencies();
Expand All @@ -545,7 +541,7 @@ private Dependency resolveFromProjectDepMgmt(ArtifactItem item) {
return null;
}

private Artifact resolveArtifactItem(final ArtifactItem item) throws MojoExecutionException {
private Artifact resolveArtifactItem(final Dependency item) throws MojoExecutionException {
org.eclipse.aether.artifact.Artifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(
item.getGroupId(), item.getArtifactId(), item.getType(), item.getVersion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.zip.ZipInputStream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -40,7 +41,6 @@
import org.apache.tools.ant.taskdefs.Expand;
import org.apache.tools.ant.taskdefs.Java;
import org.apache.tools.ant.types.Commandline.Argument;
import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;

Expand Down Expand Up @@ -146,7 +146,7 @@ protected static enum InstallType {
* be omitted.
*/
@Parameter(alias="runtimeArtifact", property="runtimeArtifact")
protected ArtifactItem assemblyArtifact;
protected Dependency assemblyArtifact;

/**
* Liberty install option. If set, Liberty will be downloaded and installed from the WASdev repository or
Expand All @@ -160,7 +160,7 @@ protected static enum InstallType {
* be omitted.
*/
@Parameter
protected ArtifactItem licenseArtifact;
protected Dependency licenseArtifact;

/**
* Location of customized configuration directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import javax.xml.parsers.ParserConfigurationException;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Profile;
import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
import org.w3c.dom.Element;

import io.openliberty.tools.common.plugins.config.XmlDocument;
Expand Down Expand Up @@ -77,7 +77,7 @@ public void createElement(String name, List<String> values) {
doc.getDocumentElement().appendChild(child);
}

public void createElement(String name, ArtifactItem value) {
public void createElement(String name, Dependency value) {
if (value == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
Expand All @@ -50,6 +51,10 @@
@Mojo(name = "deploy", requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME)
public class DeployMojo extends DeployMojoSupport {

public DeployMojo() throws MojoExecutionException, MojoFailureException {
super();
}

@Override
public void execute() throws MojoExecutionException {
if (skip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import io.openliberty.tools.common.plugins.util.PluginScenarioException;
import org.apache.commons.lang3.Validate;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.taskdefs.Copy;
import org.codehaus.mojo.pluginsupport.util.ArtifactItem;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.w3c.dom.Element;

import io.openliberty.tools.ant.ServerTask;
Expand Down Expand Up @@ -66,6 +64,10 @@ public abstract class DeployMojoSupport extends LooseAppSupport {

protected ApplicationXmlDocument applicationXml = new ApplicationXmlDocument();

public DeployMojoSupport() throws MojoExecutionException, MojoFailureException {
super();
}

protected void installApp(Artifact artifact) throws MojoExecutionException, IOException {

if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
Expand Down Expand Up @@ -429,9 +431,9 @@ protected void invokeSpringBootUtilCommand(File installDirectory, String fatArch
MessageFormat.format(messages.getString("error.dependencies.not.found"), "springBootUtil"));
}

Validate.notNull(fatArchiveSrcLocation, "Spring Boot source archive location cannot be null");
Validate.notNull(thinArchiveTargetLocation, "Target thin archive location cannot be null");
Validate.notNull(libIndexCacheTargetLocation, "Library cache location cannot be null");
Objects.requireNonNull(fatArchiveSrcLocation, "Spring Boot source archive location cannot be null");
Objects.requireNonNull(thinArchiveTargetLocation, "Target thin archive location cannot be null");
Objects.requireNonNull(libIndexCacheTargetLocation, "Library cache location cannot be null");

springBootUtilTask.setInstallDir(installDirectory);
springBootUtilTask.setTargetThinAppPath(thinArchiveTargetLocation);
Expand All @@ -440,7 +442,7 @@ protected void invokeSpringBootUtilCommand(File installDirectory, String fatArch
springBootUtilTask.execute();
}

protected boolean matches(Artifact artifact, ArtifactItem assemblyArtifact) {
protected boolean matches(Artifact artifact, Dependency assemblyArtifact) {
return artifact.getGroupId().equals(assemblyArtifact.getGroupId())
&& artifact.getArtifactId().equals(assemblyArtifact.getArtifactId())
&& artifact.getType().equals(assemblyArtifact.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;

import io.openliberty.tools.common.plugins.util.PluginScenarioException;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.shared.mapping.MappingUtils;
import org.apache.maven.project.MavenProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.text.MessageFormat;
import java.util.Set;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
Expand All @@ -43,7 +44,11 @@ public class UndeployAppMojo extends DeployMojoSupport {
private static final long APP_STOP_TIMEOUT_DEFAULT = 30 * 1000;

private ServerConfigDocument scd;


public UndeployAppMojo() throws MojoExecutionException, MojoFailureException {
super();
}

/*
* (non-Javadoc)
* @see org.codehaus.mojo.pluginsupport.MojoSupport#doExecute()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.apache.maven.MavenExecutionException;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;

import io.openliberty.tools.ant.ServerTask;
Expand All @@ -30,6 +31,10 @@
@Mojo(name = "status")
public class CheckStatusMojo extends StartDebugMojoSupport {

public CheckStatusMojo() throws MojoExecutionException, MojoFailureException {
super();
}

public void execute() throws MojoExecutionException {
if (skip) {
getLog().info("\nSkipping status goal.\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.openliberty.tools.maven.server;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

Expand Down Expand Up @@ -51,6 +52,10 @@ public class CleanServerMojo extends StartDebugMojoSupport {
@Parameter(property = "cleanApps", defaultValue = "false")
private boolean cleanApps = false;

public CleanServerMojo() throws MojoExecutionException, MojoFailureException {
super();
}

@Override
public void execute() throws MojoExecutionException {
if (skip) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.IOException;
import java.text.MessageFormat;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -50,7 +51,11 @@ public class CreateServerMojo extends PluginConfigSupport {
*/
@Parameter(property = "noPassword", defaultValue = "false")
private boolean noPassword;


public CreateServerMojo() throws MojoExecutionException, MojoFailureException {
super();
}

@Override
public void execute() throws MojoExecutionException {
if (skip) {
Expand Down
Loading

0 comments on commit 380329f

Please sign in to comment.