Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 546 #628

Merged
merged 3 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions org.eclipse.m2e.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,15 @@
class="org.eclipse.m2e.core.internal.project.WorkspaceTestsClassifierResolver">
</resolver>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="org.eclipse.core.resources.IResource"
class="org.eclipse.m2e.core.internal.project.registry.ProjectFacadeAdapterFactory">
<adapter
type="org.eclipse.m2e.core.project.IMavenProjectFacade">
</adapter>
</factory>
</extension>

</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.m2e.core.embedder.MavenModelManager;
import org.eclipse.m2e.core.embedder.MavenRuntimeManager;
import org.eclipse.m2e.core.internal.MavenPluginActivator;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
import org.eclipse.m2e.core.project.IProjectConfigurationManager;
import org.eclipse.m2e.core.project.IWorkspaceClassifierResolverManager;
Expand All @@ -41,6 +42,11 @@ public static MavenPlugin getDefault() {
return INSTANCE;
}

/**
* Use {@link IMavenProjectFacade#getMaven()} instead whenever possible
*
* @return a generic Maven instance (not customized by project).
*/
public static IMaven getMaven() {
return MavenPluginActivator.getDefault().getMaven();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.project.MavenProject;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
Expand Down Expand Up @@ -528,4 +529,10 @@ public List<MojoExecution> getExecutionPlan(String lifecycle, IProgressMonitor m
Map<String, List<MojoExecution>> executionPlans = getExecutionPlans(monitor);
return executionPlans != null ? executionPlans.get(lifecycle) : null;
}

@Override
public IMaven getMaven() {
// TODO: if project has Maven customization (such as a .mvn, MAVEN_OPTS...)
return MavenPlugin.getMaven();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.m2e.core.internal.project.registry;

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdapterFactory;

import org.eclipse.m2e.core.MavenPlugin;
import org.eclipse.m2e.core.project.IMavenProjectFacade;

public class ProjectFacadeAdapterFactory implements IAdapterFactory {
laeubi marked this conversation as resolved.
Show resolved Hide resolved

private static final Class<?>[] ADAPTER_LIST = {IMavenProjectFacade.class};

@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
if(adaptableObject instanceof IResource && adapterType == IMavenProjectFacade.class) {
return (T) MavenPlugin.getMavenProjectRegistry().getProject(((IResource) adaptableObject).getProject());
}
return null;
}

@Override
public Class<?>[] getAdapterList() {
return ADAPTER_LIST;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.m2e.core.embedder.ArtifactKey;
import org.eclipse.m2e.core.embedder.ArtifactRef;
import org.eclipse.m2e.core.embedder.ArtifactRepositoryRef;
import org.eclipse.m2e.core.embedder.IMaven;
import org.eclipse.m2e.core.lifecyclemapping.model.IPluginExecutionMetadata;
import org.eclipse.m2e.core.project.configurator.MojoExecutionKey;

Expand Down Expand Up @@ -137,6 +138,13 @@ public interface IMavenProjectFacade {

Set<ArtifactRepositoryRef> getPluginArtifactRepositoryRefs();

/**
* Gets an access to a Maven instance, configured according to this project.
*
* @return a Maven instance, configured according to this project
*/
IMaven getMaven();

/**
* Returns fully setup MojoExecution instance bound to project build lifecycle that matches provided mojoExecutionKey.
* Returns null if no such mojo execution.
Expand All @@ -156,4 +164,5 @@ List<MojoExecution> getMojoExecutions(String groupId, String artifactId, IProgre
String getLifecycleMappingId();

Map<MojoExecutionKey, List<IPluginExecutionMetadata>> getMojoExecutionMapping();

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public interface IMavenProjectRegistry {
IMavenProjectFacade[] getProjects();

/**
* You can also use <code>Adapters.adapt(resource, IMavenProjectFacade.class)</code>.
*
* @return IMavenProjectFacade cached IMavenProjectFacade corresponding to the project or null if there is no cache
* entry for the project.
*/
Expand Down