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

[MNG-6693] Various speed improvements #259

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,17 +54,22 @@ else if ( Artifact.VERSION_FILE_PATTERN.matcher( version ).matches() )

public static String toSnapshotVersion( String version )
{
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
if ( m.matches() )
int lastHyphen = version.lastIndexOf( '-' );
if ( lastHyphen > 0 )
{
return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
}
else
{
return version;
int prevHyphen = version.lastIndexOf( '-', lastHyphen - 1 );
if ( prevHyphen > 0 )
{
Matcher m = Artifact.VERSION_FILE_PATTERN.matcher( version );
if ( m.matches() )
{
return m.group( 1 ) + "-" + Artifact.SNAPSHOT_VERSION;
}
}
}
return version;
}

public static String versionlessKey( Artifact artifact )
Expand All @@ -74,8 +79,8 @@ public static String versionlessKey( Artifact artifact )

public static String versionlessKey( String groupId, String artifactId )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );

return groupId + ":" + artifactId;
}
Expand All @@ -87,13 +92,22 @@ public static String key( Artifact artifact )

public static String key( String groupId, String artifactId, String version )
{
Validate.notBlank( groupId, "groupId can neither be null, empty nor blank" );
Validate.notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
Validate.notBlank( version, "version can neither be null, empty nor blank" );
notBlank( groupId, "groupId can neither be null, empty nor blank" );
notBlank( artifactId, "artifactId can neither be null, empty nor blank" );
notBlank( version, "version can neither be null, empty nor blank" );

return groupId + ":" + artifactId + ":" + version;
}

private static void notBlank( String str, String message )
{
int c = str != null ? str.charAt( 0 ) : 0;
michael-o marked this conversation as resolved.
Show resolved Hide resolved
if ( ( c < '0' || c > '9' ) && ( c < 'a' || c > 'z' ) )
{
Validate.notBlank( str, message );
}
}

public static Map<String, Artifact> artifactMapByVersionlessId( Collection<Artifact> artifacts )
{
Map<String, Artifact> artifactMap = new LinkedHashMap<>();
Expand Down
Expand Up @@ -25,7 +25,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
Expand Down Expand Up @@ -387,16 +386,7 @@ public void setBaseVersion( String baseVersion )

protected void setBaseVersionInternal( String baseVersion )
{
Matcher m = VERSION_FILE_PATTERN.matcher( baseVersion );

if ( m.matches() )
{
this.baseVersion = m.group( 1 ) + "-" + SNAPSHOT_VERSION;
}
else
{
this.baseVersion = baseVersion;
}
this.baseVersion = ArtifactUtils.toSnapshotVersion( baseVersion );
}

public int compareTo( Artifact a )
Expand Down
Expand Up @@ -396,9 +396,12 @@ else if ( !parentIds.add( parentData.getId() ) )
if ( resultModel.getParent() != null )
{
final ModelData parentData = lineage.get( 1 );
final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
// parentData.setModel( interpolatedParent );
parentData.setVersion( interpolatedParent.getVersion() );
if ( parentData.getVersion() == null || parentData.getVersion().contains( "${" ) )
{
final Model interpolatedParent = interpolateModel( parentData.getModel(), request, problems );
// parentData.setModel( interpolatedParent );
parentData.setVersion( interpolatedParent.getVersion() );
}
}

// url normalization
Expand Down
Expand Up @@ -25,7 +25,7 @@
import org.apache.maven.model.inheritance.DefaultInheritanceAssembler;
import org.apache.maven.model.inheritance.InheritanceAssembler;
import org.apache.maven.model.interpolation.ModelInterpolator;
import org.apache.maven.model.interpolation.StringSearchModelInterpolator;
import org.apache.maven.model.interpolation.StringVisitorModelInterpolator;
import org.apache.maven.model.io.DefaultModelReader;
import org.apache.maven.model.io.ModelReader;
import org.apache.maven.model.locator.DefaultModelLocator;
Expand Down Expand Up @@ -126,7 +126,7 @@ protected ModelInterpolator newModelInterpolator()
{
UrlNormalizer normalizer = newUrlNormalizer();
PathTranslator pathTranslator = newPathTranslator();
return new StringSearchModelInterpolator().setPathTranslator( pathTranslator ).setUrlNormalizer( normalizer );
return new StringVisitorModelInterpolator().setPathTranslator( pathTranslator ).setUrlNormalizer( normalizer );
}

protected ModelValidator newModelValidator()
Expand Down
Expand Up @@ -31,16 +31,11 @@

import org.apache.maven.model.Model;
import org.apache.maven.model.building.ModelBuildingRequest;
import org.apache.maven.model.building.ModelProblem.Severity;
import org.apache.maven.model.building.ModelProblem.Version;
import org.apache.maven.model.building.ModelProblemCollector;
import org.apache.maven.model.building.ModelProblemCollectorRequest;
import org.apache.maven.model.path.PathTranslator;
import org.apache.maven.model.path.UrlNormalizer;
import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.InterpolationException;
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.MapBasedValueSource;
import org.codehaus.plexus.interpolation.ObjectBasedValueSource;
import org.codehaus.plexus.interpolation.PrefixAwareRecursionInterceptor;
Expand Down Expand Up @@ -93,14 +88,8 @@ public abstract class AbstractStringBasedModelInterpolator
@Inject
private UrlNormalizer urlNormalizer;

private Interpolator interpolator;

private RecursionInterceptor recursionInterceptor;

public AbstractStringBasedModelInterpolator()
{
interpolator = createInterpolator();
recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
}

public AbstractStringBasedModelInterpolator setPathTranslator( PathTranslator pathTranslator )
Expand Down Expand Up @@ -218,75 +207,9 @@ protected List<? extends InterpolationPostProcessor> createPostProcessors( final
return processors;
}

protected String interpolateInternal( String src, List<? extends ValueSource> valueSources,
List<? extends InterpolationPostProcessor> postProcessors,
ModelProblemCollector problems )
{
if ( !src.contains( "${" ) )
{
return src;
}

String result = src;
synchronized ( this )
{

for ( ValueSource vs : valueSources )
{
interpolator.addValueSource( vs );
}

for ( InterpolationPostProcessor postProcessor : postProcessors )
{
interpolator.addPostProcessor( postProcessor );
}

try
{
try
{
result = interpolator.interpolate( result, recursionInterceptor );
}
catch ( InterpolationException e )
{
problems.add( new ModelProblemCollectorRequest( Severity.ERROR, Version.BASE )
.setMessage( e.getMessage() ).setException( e ) );
}

interpolator.clearFeedback();
}
finally
{
for ( ValueSource vs : valueSources )
{
interpolator.removeValuesSource( vs );
}

for ( InterpolationPostProcessor postProcessor : postProcessors )
{
interpolator.removePostProcessor( postProcessor );
}
}
}

return result;
}

protected RecursionInterceptor getRecursionInterceptor()
{
return recursionInterceptor;
}

protected void setRecursionInterceptor( RecursionInterceptor recursionInterceptor )
{
this.recursionInterceptor = recursionInterceptor;
}

protected abstract Interpolator createInterpolator();

protected final Interpolator getInterpolator()
protected RecursionInterceptor createRecursionInterceptor()
{
return interpolator;
return new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
}

}