本文整理汇总了Java中org.apache.maven.plugin.LegacySupport类的典型用法代码示例。如果您正苦于以下问题:Java LegacySupport类的具体用法?Java LegacySupport怎么用?Java LegacySupport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LegacySupport类属于org.apache.maven.plugin包,在下文中一共展示了LegacySupport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadExtensions
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
/**
* adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)}
*/
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> lifecycleParticipants = getLifecycleParticipants(Arrays.asList(project));
if (!lifecycleParticipants.isEmpty()) {
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
for (AbstractMavenLifecycleParticipant listener : lifecycleParticipants) {
Thread.currentThread().setContextClassLoader(listener.getClass().getClassLoader());
try {
listener.afterProjectsRead(session);
}
catch (MavenExecutionException e) {
exceptions.add(e);
}
finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
}
}
示例2: provideLocalRepository
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
/**
* maven-plugin-testing-harness can not inject local repositories (though the real runtime supports it).
* and the default stubs have no sufficient implementation of getPath():
* @see "http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/examples/repositories.html"
*/
private ArtifactRepository provideLocalRepository() throws IllegalAccessException
{
DefaultArtifactRepositoryFactory factory = new DefaultArtifactRepositoryFactory();
setVariableValueToObject(factory, "factory", new org.apache.maven.repository.legacy.repository.DefaultArtifactRepositoryFactory());
LegacySupport legacySupport = new DefaultLegacySupport();
setVariableValueToObject(factory, "legacySupport", legacySupport);
ArtifactRepository localRepository = factory.createArtifactRepository("local", "http://localhost",
new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(), new ArtifactRepositoryPolicy());
setVariableValueToObject(localRepository, "basedir", LOCAL_REPOSITORY);
return localRepository;
}
示例3: loadExtensions
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
private void loadExtensions(MavenProject project, List<Exception> exceptions) {
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
Collection<AbstractMavenLifecycleParticipant> participants =
getLifecycleParticipants(Collections.singletonList(project));
if (!participants.isEmpty()) {
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession session = legacySupport.getSession();
session.setCurrentProject(project);
session.setProjects(Collections.singletonList(project));
for (AbstractMavenLifecycleParticipant participant : participants) {
Thread.currentThread().setContextClassLoader(participant.getClass().getClassLoader());
try {
participant.afterProjectsRead(session);
} catch (MavenExecutionException e) {
exceptions.add(e);
} finally {
Thread.currentThread().setContextClassLoader(currentClassLoader);
}
}
}
}
示例4: runMavenRequest
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
public void runMavenRequest(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySystemSession);
MavenSession mavenSession =
new MavenSession(
container, repositorySystemSession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getMavenComponent(LegacySupport.class);
MavenSession previousSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
for (AbstractMavenLifecycleParticipant participant :
getLifecycleParticipants(Collections.emptyList())) {
participant.afterSessionStart(mavenSession);
}
runnable.run();
} catch (MavenExecutionException e) {
throw new RuntimeException(e);
} finally {
legacySupport.setSession(previousSession);
}
}
示例5: newMavenSession
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
@Override
protected MavenSession newMavenSession(MavenProject project) {
MavenExecutionResult result = new DefaultMavenExecutionResult();
MavenSession session = new MavenSession(getContainer(),
project.getProjectBuildingRequest().getRepositorySession(), currentMavenExecutionRequest, result);
session.setCurrentProject(project);
session.setProjects(Arrays.asList(project));
try {
LegacySupport legacySupport = this.lookup(LegacySupport.class);
legacySupport.setSession(session);
} catch (Exception e) {
e.printStackTrace();
}
return session;
}
示例6: executeWithMavenSession
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven)getComponent(Maven.class);
RepositorySystemSession repositorySession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySession);
MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession oldSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
try {
runnable.run();
}
finally {
legacySupport.setSession(oldSession);
}
}
示例7: setUp
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
@Override
protected void setUp()
throws Exception
{
super.setUp();
artifactFactory = lookup( ArtifactFactory.class);
artifactRepositoryFactory = lookup( ArtifactRepositoryFactory.class );
RepositorySystemSession repoSession = initRepoSession();
MavenSession session =
new MavenSession( getContainer(), repoSession, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() );
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession( session );
}
示例8: from
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
public static SystemProperties from(LegacySupport legacySupport, MavenRuntime mavenRuntime) {
SystemProperties systemProperties = new SystemProperties();
try {
MavenProjectProperties projectProperties = mavenRuntime.getProjectProperties(SystemProperties.class);
systemProperties.values.put("deadcode4j.version", projectProperties.getVersion());
} catch (MavenRuntimeException e) {
LoggerFactory.getLogger(SystemProperties.class).debug("Failed to determine MavenRuntime.", e);
}
Properties properties = legacySupport.getSession().getRequest().getSystemProperties();
for (String key : KEYS.keySet()) {
String property = emptyToNull(properties.getProperty(key));
if (property != null) {
systemProperties.values.put(key, property);
}
}
return systemProperties;
}
示例9: executeWithMavenSession
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
public void executeWithMavenSession(MavenExecutionRequest request, Runnable runnable) {
DefaultMaven maven = (DefaultMaven)getComponent(Maven.class);
RepositorySystemSession repositorySession = maven.newRepositorySession(request);
request.getProjectBuildingRequest().setRepositorySession(repositorySession);
MavenSession mavenSession = new MavenSession(myContainer, repositorySession, request, new DefaultMavenExecutionResult());
LegacySupport legacySupport = getComponent(LegacySupport.class);
MavenSession oldSession = legacySupport.getSession();
legacySupport.setSession(mavenSession);
/** adapted from {@link DefaultMaven#doExecute(MavenExecutionRequest)} */
try {
for (AbstractMavenLifecycleParticipant listener : getLifecycleParticipants(Collections.<MavenProject>emptyList())) {
listener.afterSessionStart(mavenSession);
}
}
catch (MavenExecutionException e) {
throw new RuntimeException(e);
}
try {
runnable.run();
}
finally {
legacySupport.setSession(oldSession);
}
}
示例10: rss
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
private static RepositorySystemSession rss( PlexusContainer c )
{
try
{
LegacySupport legacySupport = c.lookup( LegacySupport.class );
return legacySupport.getRepositorySession();
}
catch ( ComponentLookupException e )
{
throw new IllegalStateException( e );
}
}
示例11: setUp
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
objectUnderTest = new UpdateChecker();
repositoryMetadataManager = mock(RepositoryMetadataManager.class);
mavenSession = mock(MavenSession.class);
when(mavenSession.getCurrentProject()).thenReturn(new MavenProject());
LegacySupport legacySupport = mock(LegacySupport.class);
when(legacySupport.getSession()).thenReturn(mavenSession);
ReflectionUtils.setVariableValueInObject(objectUnderTest, "legacySupport", legacySupport);
ReflectionUtils.setVariableValueInObject(objectUnderTest, "repositoryMetadataManager",
repositoryMetadataManager);
}
示例12: givenModes
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
@SuppressWarnings("deprecation") // there's no non-deprecated constructor for MavenSession :|
private void givenModes(NetworkModes networkMode, InteractivityModes interactivity) throws IllegalAccessException {
DefaultMavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
mavenExecutionRequest.setOffline(NetworkModes.OFFLINE == networkMode);
mavenExecutionRequest.setInteractiveMode(InteractivityModes.INTERACTIVE == interactivity);
mavenExecutionRequest.setSystemProperties(System.getProperties());
LegacySupport legacySupport = mock(LegacySupport.class);
when(legacySupport.getSession()).thenReturn(new MavenSession(null, null, mavenExecutionRequest, null));
setVariableValueInObject(objectUnderTest, "legacySupport", legacySupport);
}
示例13: internalResolveProject
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
private MavenResult internalResolveProject(
File pom,
List<String> activeProfiles,
List<String> inactiveProfiles,
List<ResolutionListener> dependencyTreeResolutionListeners) {
MavenExecutionRequest request =
newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList());
request.setUpdateSnapshots(updateSnapshots);
AtomicReference<MavenResult> reference = new AtomicReference<>();
runMavenRequest(
request,
() -> {
try {
ProjectBuilder builder = getMavenComponent(ProjectBuilder.class);
List<ProjectBuildingResult> resultList =
builder.build(
Collections.singletonList(pom), false, request.getProjectBuildingRequest());
ProjectBuildingResult result = resultList.get(0);
MavenProject mavenProject = result.getProject();
RepositorySystemSession repositorySession =
getMavenComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
((DefaultRepositorySystemSession) repositorySession)
.setTransferListener(new ArtifactTransferListener(mavenProgressNotifier));
if (workspaceCache != null) {
((DefaultRepositorySystemSession) repositorySession)
.setWorkspaceReader(new MavenWorkspaceReader(workspaceCache));
}
}
List<Exception> exceptions = new ArrayList<>();
loadExtensions(mavenProject, exceptions);
mavenProject.setDependencyArtifacts(
mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null));
ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
resolutionRequest.setArtifact(mavenProject.getArtifact());
resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts());
resolutionRequest.setListeners(dependencyTreeResolutionListeners);
resolutionRequest.setLocalRepository(localRepo);
resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap());
resolutionRequest.setResolveTransitively(true);
resolutionRequest.setResolveRoot(false);
ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class);
ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest);
mavenProject.setArtifacts(resolve.getArtifacts());
reference.set(new MavenResult(mavenProject, exceptions));
} catch (Exception e) {
reference.set(new MavenResult(null, null, Collections.singletonList(e)));
}
});
return reference.get();
}
示例14: doResolveProject
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
@NotNull
public MavenExecutionResult doResolveProject(@NotNull final File file,
@NotNull final List<String> activeProfiles,
final List<ResolutionListener> listeners) throws RemoteException {
final MavenExecutionRequest request = createRequest(file, activeProfiles, Collections.<String>emptyList(), Collections.<String>emptyList());
final AtomicReference<MavenExecutionResult> ref = new AtomicReference<MavenExecutionResult>();
executeWithMavenSession(request, new Runnable() {
@Override
public void run() {
try {
// copied from DefaultMavenProjectBuilder.buildWithDependencies
ProjectBuilder builder = getComponent(ProjectBuilder.class);
ProjectBuildingResult buildingResult = builder.build(new File(file.getPath()), request.getProjectBuildingRequest());
//builder.calculateConcreteState(project, config, false);
MavenProject project = buildingResult.getProject();
// copied from DefaultLifecycleExecutor.execute
//findExtensions(project);
// end copied from DefaultLifecycleExecutor.execute
//Artifact projectArtifact = project.getArtifact();
//Map managedVersions = project.getManagedVersionMap();
//ArtifactMetadataSource metadataSource = getComponent(ArtifactMetadataSource.class);
project.setDependencyArtifacts(project.createArtifacts(getComponent(ArtifactFactory.class), null, null));
//
ArtifactResolver resolver = getComponent(ArtifactResolver.class);
ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
resolutionRequest.setArtifactDependencies(project.getDependencyArtifacts());
resolutionRequest.setArtifact(project.getArtifact());
resolutionRequest.setManagedVersionMap(project.getManagedVersionMap());
resolutionRequest.setLocalRepository(myLocalRepository);
resolutionRequest.setRemoteRepositories(project.getRemoteArtifactRepositories());
resolutionRequest.setListeners(listeners);
resolutionRequest.setResolveRoot(false);
resolutionRequest.setResolveTransitively(true);
RepositorySystemSession repositorySession = getComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
((DefaultRepositorySystemSession)repositorySession).setTransferListener(new TransferListenerAdapter(myCurrentIndicator));
if (myWorkspaceMap != null) {
((DefaultRepositorySystemSession)repositorySession).setWorkspaceReader(new Maven3WorkspaceReader(myWorkspaceMap));
}
}
ArtifactResolutionResult result = resolver.resolve(resolutionRequest);
project.setArtifacts(result.getArtifacts());
// end copied from DefaultMavenProjectBuilder.buildWithDependencies
ref.set(new MavenExecutionResult(project, new ArrayList<Exception>()));
}
catch (Exception e) {
ref.set(handleException(e));
}
}
});
return ref.get();
}
示例15: testThatASystemScopedDependencyIsNotResolvedFromRepositories
import org.apache.maven.plugin.LegacySupport; //导入依赖的package包/类
public void testThatASystemScopedDependencyIsNotResolvedFromRepositories()
throws Exception
{
//
// We should get a whole slew of dependencies resolving this artifact transitively
//
Dependency d = new Dependency();
d.setGroupId( "org.apache.maven.its" );
d.setArtifactId( "b" );
d.setVersion( "0.1" );
d.setScope( Artifact.SCOPE_COMPILE );
Artifact artifact = repositorySystem.createDependencyArtifact( d );
ArtifactResolutionRequest request = new ArtifactResolutionRequest()
.setArtifact( artifact )
.setResolveRoot( true )
.setResolveTransitively( true )
.setRemoteRepositories( getRemoteRepositories() )
.setLocalRepository( getLocalRepository() );
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
session.setLocalRepositoryManager( new SimpleLocalRepositoryManager( request.getLocalRepository().getBasedir() ) );
LegacySupport legacySupport = lookup( LegacySupport.class );
legacySupport.setSession( new MavenSession( getContainer(), session, new DefaultMavenExecutionRequest(),
new DefaultMavenExecutionResult() ) );
ArtifactResolutionResult result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
assertEquals( 2, result.getArtifacts().size() );
//
// System scoped version which should
//
d.setScope( Artifact.SCOPE_SYSTEM );
File file = new File( getBasedir(), "src/test/repository-system/maven-core-2.1.0.jar" );
assertTrue( file.exists() );
d.setSystemPath( file.getCanonicalPath() );
artifact = repositorySystem.createDependencyArtifact( d );
//
// The request has not set any local or remote repositories as the system scoped dependency being resolved should only
// give us the dependency off the disk and nothing more.
//
request = new ArtifactResolutionRequest()
.setArtifact( artifact )
.setResolveRoot( true )
.setResolveTransitively( true );
result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
assertEquals( 1, result.getArtifacts().size() );
//
// Put in a bogus file to make sure missing files cause the resolution to fail.
//
file = new File( getBasedir(), "src/test/repository-system/maven-monkey-2.1.0.jar" );
assertFalse( file.exists() );
d.setSystemPath( file.getCanonicalPath() );
artifact = repositorySystem.createDependencyArtifact( d );
//
// The request has not set any local or remote repositories as the system scoped dependency being resolved should only
// give us the dependency off the disk and nothing more.
//
request = new ArtifactResolutionRequest()
.setArtifact( artifact )
.setResolveRoot( true )
.setResolveTransitively( true );
try
{
result = repositorySystem.resolve( request );
resolutionErrorHandler.throwErrors( request, result );
}
catch( Exception e )
{
assertTrue( result.hasMissingArtifacts() );
}
}