o Restored backward-compat for plugins that create MavenSession

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@821082 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-10-02 16:24:54 +00:00
parent 896a85cf5e
commit 608ac9f30c
4 changed files with 318 additions and 0 deletions

View File

@ -19,8 +19,10 @@
* under the License.
*/
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@ -29,6 +31,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.RepositoryCache;
import org.apache.maven.monitor.event.EventDispatcher;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
@ -72,6 +75,32 @@ public MavenSession( PlexusContainer container, MavenExecutionRequest request, M
this( container, request, result, Arrays.asList( new MavenProject[]{ project } ) );
}
@Deprecated
public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, ReactorManager unused, List<String> goals,
String executionRootDir, Properties executionProperties, Date startTime )
{
this( container, settings, localRepository, eventDispatcher, unused, goals, executionRootDir,
executionProperties, null, startTime );
}
@Deprecated
public MavenSession( PlexusContainer container, Settings settings, ArtifactRepository localRepository,
EventDispatcher eventDispatcher, ReactorManager unused, List<String> goals,
String executionRootDir, Properties executionProperties, Properties userProperties,
Date startTime )
{
this.container = container;
this.settings = settings;
this.executionProperties = executionProperties;
this.request = new DefaultMavenExecutionRequest();
this.request.setUserProperties( userProperties );
this.request.setLocalRepository( localRepository );
this.request.setGoals( goals );
this.request.setBaseDirectory( ( executionRootDir != null ) ? new File( executionRootDir ) : null );
this.request.setStartTime( startTime );
}
@Deprecated
public MavenSession( PlexusContainer container, MavenExecutionRequest request, MavenExecutionResult result, List<MavenProject> projects )
{
@ -321,4 +350,15 @@ private String getId( MavenProject project )
return project.getGroupId() + ':' + project.getArtifactId() + ':' + project.getVersion();
}
@Deprecated
public EventDispatcher getEventDispatcher()
{
return null;
}
public Date getStartTime()
{
return request.getStartTime();
}
}

View File

@ -0,0 +1,206 @@
package org.apache.maven.execution;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.ArtifactUtils;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@Deprecated
public class ReactorManager
{
public static final String FAIL_FAST = "fail-fast";
public static final String FAIL_AT_END = "fail-at-end";
public static final String FAIL_NEVER = "fail-never";
public static final String MAKE_MODE = "make";
public static final String MAKE_DEPENDENTS_MODE = "make-dependents";
// make projects that depend on me, and projects that I depend on
public static final String MAKE_BOTH_MODE = "make-both";
private List blackList = new ArrayList();
private Map buildFailuresByProject = new HashMap();
private Map pluginContextsByProjectAndPluginKey = new HashMap();
private String failureBehavior = FAIL_FAST;
private final ProjectSorter sorter;
private Map buildSuccessesByProject = new HashMap();
public ReactorManager( List projects )
throws CycleDetectedException, DuplicateProjectException
{
this.sorter = new ProjectSorter( projects );
}
public Map getPluginContext( PluginDescriptor plugin, MavenProject project )
{
Map pluginContextsByKey = (Map) pluginContextsByProjectAndPluginKey.get( project.getId() );
if ( pluginContextsByKey == null )
{
pluginContextsByKey = new HashMap();
pluginContextsByProjectAndPluginKey.put( project.getId(), pluginContextsByKey );
}
Map pluginContext = (Map) pluginContextsByKey.get( plugin.getPluginLookupKey() );
if ( pluginContext == null )
{
pluginContext = new HashMap();
pluginContextsByKey.put( plugin.getPluginLookupKey(), pluginContext );
}
return pluginContext;
}
public void setFailureBehavior( String failureBehavior )
{
if ( failureBehavior == null )
{
this.failureBehavior = FAIL_FAST; // default
return;
}
if ( FAIL_FAST.equals( failureBehavior ) || FAIL_AT_END.equals( failureBehavior )
|| FAIL_NEVER.equals( failureBehavior ) )
{
this.failureBehavior = failureBehavior;
}
else
{
throw new IllegalArgumentException( "Invalid failure behavior (must be one of: \'" + FAIL_FAST + "\', \'"
+ FAIL_AT_END + "\', \'" + FAIL_NEVER + "\')." );
}
}
public String getFailureBehavior()
{
return failureBehavior;
}
public void blackList( MavenProject project )
{
blackList( getProjectKey( project ) );
}
private void blackList( String id )
{
if ( !blackList.contains( id ) )
{
blackList.add( id );
List dependents = sorter.getDependents( id );
if ( dependents != null && !dependents.isEmpty() )
{
for ( Iterator it = dependents.iterator(); it.hasNext(); )
{
String dependentId = (String) it.next();
if ( !buildSuccessesByProject.containsKey( dependentId )
&& !buildFailuresByProject.containsKey( dependentId ) )
{
blackList( dependentId );
}
}
}
}
}
public boolean isBlackListed( MavenProject project )
{
return blackList.contains( getProjectKey( project ) );
}
private static String getProjectKey( MavenProject project )
{
return ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() );
}
public void registerBuildFailure( MavenProject project, Exception error, String task, long time )
{
buildFailuresByProject.put( getProjectKey( project ), new BuildFailure( project, time, error ) );
}
public boolean hasBuildFailures()
{
return !buildFailuresByProject.isEmpty();
}
public boolean hasBuildFailure( MavenProject project )
{
return buildFailuresByProject.containsKey( getProjectKey( project ) );
}
public boolean hasMultipleProjects()
{
return sorter.hasMultipleProjects();
}
public List<MavenProject> getSortedProjects()
{
return sorter.getSortedProjects();
}
public MavenProject getTopLevelProject()
{
return sorter.getTopLevelProject();
}
public boolean hasBuildSuccess( MavenProject project )
{
return buildSuccessesByProject.containsKey( getProjectKey( project ) );
}
public void registerBuildSuccess( MavenProject project, long time )
{
buildSuccessesByProject.put( getProjectKey( project ), new BuildSuccess( project, time ) );
}
public BuildFailure getBuildFailure( MavenProject project )
{
return (BuildFailure) buildFailuresByProject.get( getProjectKey( project ) );
}
public BuildSuccess getBuildSuccess( MavenProject project )
{
return (BuildSuccess) buildSuccessesByProject.get( getProjectKey( project ) );
}
public boolean executedMultipleProjects()
{
return buildFailuresByProject.size() + buildSuccessesByProject.size() > 1;
}
}

View File

@ -0,0 +1,37 @@
package org.apache.maven.monitor.event;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author jdcasey
*/
@Deprecated
public interface EventDispatcher
{
void addEventMonitor( EventMonitor monitor );
void dispatchStart( String event, String target );
void dispatchEnd( String event, String target );
void dispatchError( String event, String target, Throwable cause );
}

View File

@ -0,0 +1,35 @@
package org.apache.maven.monitor.event;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author jdcasey
*/
@Deprecated
public interface EventMonitor
{
void startEvent( String eventName, String target, long timestamp );
void endEvent( String eventName, String target, long timestamp );
void errorEvent( String eventName, String target, long timestamp, Throwable cause );
}