Skip to content

Commit

Permalink
Merge pull request #190 from gnodet/refactor
Browse files Browse the repository at this point in the history
Use issue annotations, move some classes out of org.apache.maven package
  • Loading branch information
gnodet committed Nov 6, 2020
2 parents b78d4c6 + 7e6e127 commit a6e4c47
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 361 deletions.
Expand Up @@ -126,14 +126,16 @@ public Path userDir() {
return value(Environment.USER_DIR)
.orSystemProperty()
.orFail()
.asPath();
.asPath()
.toAbsolutePath();
}

public Path userHome() {
return value(Environment.USER_HOME)
.orSystemProperty()
.orFail()
.asPath();
.asPath()
.toAbsolutePath();
}

public Path suppliedPropertiesPath() {
Expand Down
76 changes: 0 additions & 76 deletions daemon/src/main/java/org/apache/maven/cli/CliRequestBuilder.java

This file was deleted.

24 changes: 14 additions & 10 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Expand Up @@ -54,7 +54,6 @@
import org.apache.maven.cli.event.ExecutionEventLogger;
import org.apache.maven.cli.internal.BootstrapCoreExtensionManager;
import org.apache.maven.cli.internal.extension.model.CoreExtension;
import org.apache.maven.cli.logging.Slf4jLoggerManager;
import org.apache.maven.cli.transfer.ConsoleMavenTransferListener;
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
import org.apache.maven.cli.transfer.Slf4jMavenTransferListener;
Expand All @@ -72,7 +71,6 @@
import org.apache.maven.extension.internal.CoreExtensionEntry;
import org.apache.maven.lifecycle.LifecycleExecutionException;
import org.apache.maven.model.building.ModelProcessor;
import org.apache.maven.plugin.PluginRealmCache;
import org.apache.maven.project.MavenProject;
import org.apache.maven.properties.internal.EnvironmentUtils;
import org.apache.maven.properties.internal.SystemProperties;
Expand All @@ -93,8 +91,9 @@
import org.codehaus.plexus.util.StringUtils;
import org.eclipse.aether.transfer.TransferListener;
import org.jboss.fuse.mvnd.common.Environment;
import org.jboss.fuse.mvnd.logging.internal.Slf4jLoggerManager;
import org.jboss.fuse.mvnd.logging.smart.AbstractLoggingSpy;
import org.jboss.fuse.mvnd.plugin.CliPluginRealmCache;
import org.jboss.fuse.mvnd.logging.smart.LoggingExecutionListener;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -103,8 +102,6 @@

import static org.apache.maven.shared.utils.logging.MessageUtils.buffer;

// TODO push all common bits back to plexus cli and prepare for transition to Guice. We don't need 50 ways to make CLIs

/**
* File origin:
* https://github.com/apache/maven/blob/maven-3.6.2/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Expand Down Expand Up @@ -167,7 +164,17 @@ public DaemonMavenCli() throws Exception {
container();
}

// TODO need to externalize CliRequest
public int main(List<String> arguments,
String workingDirectory,
String projectDirectory,
Map<String, String> clientEnv) throws Exception {
CliRequest req = new CliRequest(null, null);
req.args = arguments.toArray(new String[0]);
req.workingDirectory = workingDirectory;
req.multiModuleProjectDirectory = new File(projectDirectory);
return doMain(req, clientEnv);
}

public int doMain(CliRequest cliRequest, Map<String, String> clientEnv) throws Exception {
Properties props = (Properties) System.getProperties().clone();
try {
Expand Down Expand Up @@ -451,14 +458,12 @@ void container()
}

final CoreExports exports = new CoreExports(containerRealm, exportedArtifacts, exportedPackages);
final CliPluginRealmCache realmCache = new CliPluginRealmCache();

container = new DefaultPlexusContainer(cc, new AbstractModule() {
@Override
protected void configure() {
bind(ILoggerFactory.class).toInstance(slf4jLoggerFactory);
bind(CoreExports.class).toInstance(exports);
bind(PluginRealmCache.class).toInstance(realmCache);
}
});

Expand All @@ -474,7 +479,6 @@ protected void configure() {
}

eventSpyDispatcher = container.lookup(EventSpyDispatcher.class);
eventSpyDispatcher.getEventSpies().add(realmCache.asEventSpy());

maven = container.lookup(Maven.class);

Expand Down Expand Up @@ -1042,7 +1046,7 @@ private void populateRequest(CliRequest cliRequest, MavenExecutionRequest reques

ExecutionListener executionListener = new ExecutionEventLogger();
if (eventSpyDispatcher != null) {
executionListener = eventSpyDispatcher.chainListener(executionListener);
executionListener = new LoggingExecutionListener(eventSpyDispatcher.chainListener(executionListener));
}

String alternatePomFile = null;
Expand Down

This file was deleted.

Expand Up @@ -31,6 +31,9 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidArtifactRTException;
Expand Down Expand Up @@ -61,8 +64,6 @@
import org.apache.maven.model.building.StringModelSource;
import org.apache.maven.model.resolution.ModelResolver;
import org.apache.maven.repository.internal.ArtifactDescriptorUtils;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
Expand All @@ -74,43 +75,49 @@
import org.eclipse.aether.repository.WorkspaceRepository;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResult;
import org.eclipse.sisu.Typed;

/**
* DefaultProjectBuilder
*
* File origin:
* https://github.com/apache/maven/blob/maven-3.6.2/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
*/
@Component(role = ProjectBuilder.class)
@Named
@Singleton
@Typed(ProjectBuilder.class)
public class CachingProjectBuilder
implements ProjectBuilder {

@Requirement
@Inject
private Logger logger;

@Requirement
@Inject
private ModelBuilder modelBuilder;

@Requirement
@Inject
private ModelProcessor modelProcessor;

@Requirement
@Inject
private ProjectBuildingHelper projectBuildingHelper;

@Requirement
@Inject
private MavenRepositorySystem repositorySystem;

@Requirement
@Inject
private org.eclipse.aether.RepositorySystem repoSystem;

@Requirement
@Inject
private RemoteRepositoryManager repositoryManager;

@Requirement
@Inject
private ProjectDependenciesResolver dependencyResolver;

private final ModelCache modelCache = new ReactorModelCache();

public CachingProjectBuilder() {
}

// ----------------------------------------------------------------------
// MavenProjectBuilder Implementation
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -161,7 +168,8 @@ private ProjectBuildingResult build(File pomFile, ModelSource modelSource, Inter
} catch (ModelBuildingException e) {
result = e.getResult();
if (result == null || result.getEffectiveModel() == null) {
throw new ProjectBuildingException(e.getModelId(), e.getMessage(), pomFile, e);
throw (ProjectBuildingException) new ProjectBuildingException(e.getModelId(), e.getMessage(), pomFile)
.initCause(e);
}
// validation error, continue project building and delay failing to help IDEs
error = e;
Expand Down

0 comments on commit a6e4c47

Please sign in to comment.