mirror of https://github.com/apache/maven.git
o Improved support for classifier parsing and added test artifact to the test repository for this.
o Fixed issue in createXXX(..) method for constructing an artifact with a classifier...it was not actually calling the constructor that passes in the classifier. PR: MNG-312 git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
84e67faf30
commit
0e5b4e565c
|
@ -69,6 +69,8 @@ public class ArtifactConstructionSupport
|
||||||
desiredScope = Artifact.SCOPE_TEST;
|
desiredScope = Artifact.SCOPE_TEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultArtifact( groupId, artifactId, version, desiredScope, type );
|
DefaultArtifact artifact = new DefaultArtifact( groupId, artifactId, version, desiredScope, type, classifier );
|
||||||
|
|
||||||
|
return artifact;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,65 +156,95 @@ public class LegacyArtifactDiscoverer
|
||||||
// Since version is at the end, we have to move in from the back.
|
// Since version is at the end, we have to move in from the back.
|
||||||
Collections.reverse( avceTokenList );
|
Collections.reverse( avceTokenList );
|
||||||
|
|
||||||
String classifier = null;
|
StringBuffer classifierBuffer = new StringBuffer();
|
||||||
StringBuffer versionBuffer = new StringBuffer();
|
StringBuffer versionBuffer = new StringBuffer();
|
||||||
|
|
||||||
boolean inFirstToken = true;
|
boolean firstVersionTokenEncountered = false;
|
||||||
|
boolean firstToken = true;
|
||||||
|
|
||||||
|
int tokensIterated = 0;
|
||||||
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
String token = (String) it.next();
|
String token = (String) it.next();
|
||||||
|
|
||||||
boolean tokenIsVersionPart = token.matches( validVersionParts );
|
boolean tokenIsVersionPart = token.matches( validVersionParts );
|
||||||
if ( inFirstToken && !tokenIsVersionPart )
|
|
||||||
{
|
|
||||||
classifier = token;
|
|
||||||
}
|
|
||||||
else if ( tokenIsVersionPart )
|
|
||||||
{
|
|
||||||
if ( !inFirstToken )
|
|
||||||
{
|
|
||||||
versionBuffer.insert( 0, '-' );
|
|
||||||
}
|
|
||||||
|
|
||||||
versionBuffer.insert( 0, token );
|
StringBuffer bufferToUpdate = null;
|
||||||
|
|
||||||
|
// NOTE: logic in code is reversed, since we're peeling off the back
|
||||||
|
// Any token after the last versionPart will be in the classifier.
|
||||||
|
// Any token UP TO first non-versionPart is part of the version.
|
||||||
|
if ( !tokenIsVersionPart )
|
||||||
|
{
|
||||||
|
if ( firstVersionTokenEncountered )
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bufferToUpdate = classifierBuffer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if we didn't find a version, but we did find a 'classifier',
|
firstVersionTokenEncountered = true;
|
||||||
// then push that classifier back onto the list...chances are,
|
|
||||||
// it doesn't have a version or a classifier if this is the case.
|
|
||||||
if ( versionBuffer.length() < 1 && classifier != null )
|
|
||||||
{
|
|
||||||
avceTokenList.addFirst( classifier );
|
|
||||||
}
|
|
||||||
|
|
||||||
// we've discovered all the version parts. break the loop.
|
bufferToUpdate = versionBuffer;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( inFirstToken )
|
if ( firstToken )
|
||||||
{
|
{
|
||||||
inFirstToken = false;
|
firstToken = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
bufferToUpdate.insert( 0, '-' );
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop the token off the list so it doesn't appear in the
|
bufferToUpdate.insert( 0, token );
|
||||||
// artifactId.
|
|
||||||
it.remove();
|
tokensIterated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLogger().debug("After parsing loop, state of buffers:\no Version Buffer: \'" + versionBuffer + "\'\no Classifier Buffer: \'" + classifierBuffer + "\'\no Number of Tokens Iterated: " + tokensIterated);
|
||||||
|
|
||||||
// Now, restore the proper ordering so we can build the artifactId.
|
// Now, restore the proper ordering so we can build the artifactId.
|
||||||
Collections.reverse( avceTokenList );
|
Collections.reverse( avceTokenList );
|
||||||
|
|
||||||
|
getLogger().debug("Before repairing bad version and/or cleaning up used tokens, avce token list is:\n" + avceTokenList);
|
||||||
|
|
||||||
|
// if we didn't find a version, then punt. Use the last token
|
||||||
|
// as the version, and set the classifier empty.
|
||||||
|
if ( versionBuffer.length() < 1 )
|
||||||
|
{
|
||||||
|
int lastIdx = avceTokenList.size() - 1;
|
||||||
|
|
||||||
|
versionBuffer.append( avceTokenList.get( lastIdx ) );
|
||||||
|
avceTokenList.remove( lastIdx );
|
||||||
|
|
||||||
|
classifierBuffer.setLength( 0 );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
getLogger().debug("Removing " + tokensIterated + " tokens from avce token list.");
|
||||||
|
|
||||||
|
// if everything is kosher, then pop off all the classifier and
|
||||||
|
// version tokens, leaving the naked artifact id in the list.
|
||||||
|
avceTokenList = new LinkedList( avceTokenList.subList( 0, avceTokenList.size() - ( tokensIterated ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
getLogger().debug("Now, remainder of avce token list is:\n" + avceTokenList);
|
||||||
|
|
||||||
StringBuffer artifactIdBuffer = new StringBuffer();
|
StringBuffer artifactIdBuffer = new StringBuffer();
|
||||||
|
|
||||||
inFirstToken = true;
|
firstToken = true;
|
||||||
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
for ( Iterator it = avceTokenList.iterator(); it.hasNext(); )
|
||||||
{
|
{
|
||||||
String token = (String) it.next();
|
String token = (String) it.next();
|
||||||
|
|
||||||
if ( inFirstToken )
|
if ( firstToken )
|
||||||
{
|
{
|
||||||
inFirstToken = false;
|
firstToken = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -240,20 +270,29 @@ public class LegacyArtifactDiscoverer
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().debug(
|
getLogger().debug(
|
||||||
"Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n"
|
"Extracted artifact information from path:\n" + "groupId: \'" + groupId + "\'\n"
|
||||||
+ "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'"
|
+ "artifactId: \'" + artifactId + "\'\n" + "type: \'" + type + "\'\n" + "version: \'"
|
||||||
+ version + "\'\n" + "classifier: \'" + classifier + "\'" );
|
+ version + "\'\n" + "classifier: \'" + classifierBuffer.toString() + "\'" );
|
||||||
|
|
||||||
if ( classifier != null )
|
Artifact result = null;
|
||||||
|
|
||||||
|
if ( classifierBuffer.length() > 0 )
|
||||||
{
|
{
|
||||||
return artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, version,
|
getLogger().debug("Creating artifact with classifier.");
|
||||||
Artifact.SCOPE_RUNTIME, type, classifier );
|
|
||||||
|
result = artifactConstructionSupport.createArtifactWithClassifier( groupId, artifactId, version,
|
||||||
|
Artifact.SCOPE_RUNTIME, type,
|
||||||
|
classifierBuffer.toString() );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return artifactConstructionSupport.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
|
result = artifactConstructionSupport.createArtifact( groupId, artifactId, version, Artifact.SCOPE_RUNTIME,
|
||||||
type );
|
type );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLogger().debug( "Resulting artifact is: " + result.getId() + " and has classifier of: " + result.getClassifier() + "\n\n" );
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue