diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata')
21 files changed, 2822 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java new file mode 100644 index 00000000..2666eafb --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ArtifactMetadata.java @@ -0,0 +1,353 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.Collection; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.ArtifactScopeEnum; + +/** + * Artifact Metadata that is resolved independent of Artifact itself. + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + */ +public class ArtifactMetadata +{ + /** + * standard glorified artifact coordinates + */ + protected String groupId; + protected String artifactId; + protected String version; + protected String type; + protected ArtifactScopeEnum artifactScope; + protected String classifier; + + /** + * explanation: why this MD was chosen over it's siblings + * in the resulting structure (classpath for now) + */ + protected String why; + + /** dependencies of the artifact behind this metadata */ + protected Collection<ArtifactMetadata> dependencies; + + /** metadata URI */ + protected String uri; + + /** is metadata found anywhere */ + protected boolean resolved = false; + + /** does the actual artifact for this metadata exists */ + protected boolean artifactExists = false; + /** artifact URI */ + protected String artifactUri; + + /** error message */ + private String error; + + //------------------------------------------------------------------ + /** + * + */ + public ArtifactMetadata( String name ) + { + if ( name == null ) + { + return; + } + int ind1 = name.indexOf( ':' ); + int ind2 = name.lastIndexOf( ':' ); + + if ( ind1 == -1 || ind2 == -1 ) + { + return; + } + + this.groupId = name.substring( 0, ind1 ); + if ( ind1 == ind2 ) + { + this.artifactId = name.substring( ind1 + 1 ); + } + else + { + this.artifactId = name.substring( ind1 + 1, ind2 ); + this.version = name.substring( ind2 + 1 ); + } + } + + // ------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version ) + { + this( groupId, name, version, null ); + } + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type ) + { + this( groupId, name, version, type, null ); + } + + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope ) + { + this( groupId, name, version, type, artifactScope, null ); + } + + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, + String classifier ) + { + this( groupId, name, version, type, artifactScope, classifier, null ); + } + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, + String classifier, String artifactUri ) + { + this( groupId, name, version, type, artifactScope, classifier, artifactUri, null, true, null ); + } + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type, ArtifactScopeEnum artifactScope, + String classifier, String artifactUri, String why, boolean resolved, String error ) + { + this.groupId = groupId; + this.artifactId = name; + this.version = version; + this.type = type; + this.artifactScope = artifactScope; + this.classifier = classifier; + this.artifactUri = artifactUri; + this.why = why; + this.resolved = resolved; + this.error = error; + } + //------------------------------------------------------------------ + public ArtifactMetadata( String groupId, String name, String version, String type, String scopeString, + String classifier, String artifactUri, String why, boolean resolved, String error ) + { + this( groupId, name, version, type, + scopeString == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scopeString ), + classifier, artifactUri, why, resolved, error ); + } + + //------------------------------------------------------------------ + public ArtifactMetadata( Artifact af ) + { + /* + if ( af != null ) + { + init( af ); + } + */ + } + //------------------------------------------------------------------ +// public void init( ArtifactMetadata af ) +// { +// setGroupId( af.getGroupId() ); +// setArtifactId( af.getArtifactId() ); +// setVersion( af.getVersion() ); +// setType( af.getType() ); +// setScope( af.getScope() ); +// setClassifier( af.getClassifier() ); +// //setUri( af.getDownloadUrl() ); +// +// this.resolved = af.isResolved(); +// } + + //------------------------------------------------------------------ + @Override + public String toString() + { + return groupId + ":" + artifactId + ":" + version; + } + + //------------------------------------------------------------------ + public String toDomainString() + { + return groupId + ":" + artifactId; + } + + //------------------------------------------------------------------ + public String getGroupId() + { + return groupId; + } + + public void setGroupId( String groupId ) + { + this.groupId = groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public void setArtifactId( String name ) + { + this.artifactId = name; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public String getType() + { + return type; + } + + public String getCheckedType() + { + return type == null ? "jar" : type; + } + + public void setType( String type ) + { + this.type = type; + } + + public ArtifactScopeEnum getArtifactScope() + { + return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope; + } + + public void setArtifactScope( ArtifactScopeEnum artifactScope ) + { + this.artifactScope = artifactScope; + } + + public void setScope( String scope ) + { + this.artifactScope = scope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : ArtifactScopeEnum.valueOf( scope ); + } + + public String getClassifier() + { + return classifier; + } + + public void setClassifier( String classifier ) + { + this.classifier = classifier; + } + + public boolean isResolved() + { + return resolved; + } + + public void setResolved( boolean resolved ) + { + this.resolved = resolved; + } + + public String getUri() + { + return uri; + } + + public void setUri( String uri ) + { + this.uri = uri; + } + + public String getScope() + { + return getArtifactScope().getScope(); + } + + public ArtifactScopeEnum getScopeAsEnum() + { + return artifactScope == null ? ArtifactScopeEnum.DEFAULT_SCOPE : artifactScope; + } + + public boolean isArtifactExists() + { + return artifactExists; + } + + public void setArtifactExists( boolean artifactExists ) + { + this.artifactExists = artifactExists; + } + + + public Collection<ArtifactMetadata> getDependencies() + { + return dependencies; + } + + public void setDependencies( Collection<ArtifactMetadata> dependencies ) + { + this.dependencies = dependencies; + } + + public String getArtifactUri() + { + return artifactUri; + } + + public void setArtifactUri( String artifactUri ) + { + this.artifactUri = artifactUri; + } + + + public String getWhy() + { + return why; + } + + public void setWhy( String why ) + { + this.why = why; + } + + //------------------------------------------------------------------- + public String getError() + { + return error; + } + + public void setError( String error ) + { + this.error = error; + } + + public boolean isError() + { + return error == null; + } + + //------------------------------------------------------------------ + public String getDependencyConflictId() + { + return groupId + ":" + artifactId; + } + //------------------------------------------------------------------ + //------------------------------------------------------------------ +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathContainer.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathContainer.java new file mode 100644 index 00000000..b0cb5b2f --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathContainer.java @@ -0,0 +1,144 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.artifact.ArtifactScopeEnum; + +/** + * classpath container that is aware of the classpath scope + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public class ClasspathContainer +implements Iterable<ArtifactMetadata> +{ + private List<ArtifactMetadata> classpath; + + private ArtifactScopeEnum scope; + + // ------------------------------------------------------------------------------------------- + public ClasspathContainer( ArtifactScopeEnum scope ) + { + this.scope = ArtifactScopeEnum.checkScope( scope ); + } + + // ------------------------------------------------------------------------------------------- + public ClasspathContainer( List<ArtifactMetadata> classpath, ArtifactScopeEnum scope ) + { + this( scope ); + this.classpath = classpath; + } + + // ------------------------------------------------------------------------------------------- + public Iterator<ArtifactMetadata> iterator() + { + return classpath == null ? null : classpath.iterator(); + } + + // ------------------------------------------------------------------------------------------- + public ClasspathContainer add( ArtifactMetadata md ) + { + if ( classpath == null ) + { + classpath = new ArrayList<ArtifactMetadata>( 16 ); + } + + classpath.add( md ); + + return this; + } + + // ------------------------------------------------------------------------------------------- + public List<ArtifactMetadata> getClasspath() + { + return classpath; + } + + // ------------------------------------------------------------------------------------------- + public MetadataTreeNode getClasspathAsTree() + throws MetadataResolutionException + { + if ( classpath == null || classpath.size() < 1 ) + { + return null; + } + + MetadataTreeNode tree = null; + MetadataTreeNode parent = null; + + for ( ArtifactMetadata md : classpath ) + { + MetadataTreeNode node = new MetadataTreeNode( md, parent, md.isResolved(), md.getArtifactScope() ); + if ( tree == null ) + { + tree = node; + } + + if ( parent != null ) + { + parent.setNChildren( 1 ); + parent.addChild( 0, node ); + } + + parent = node; + + } + return tree; + } + + public void setClasspath( List<ArtifactMetadata> classpath ) + { + this.classpath = classpath; + } + + public ArtifactScopeEnum getScope() + { + return scope; + } + + public void setScope( ArtifactScopeEnum scope ) + { + this.scope = scope; + } + + // ------------------------------------------------------------------------------------------- + @Override + public String toString() + { + StringBuilder sb = new StringBuilder( 256 ); + sb.append( "[scope=" ).append( scope.getScope() ); + if ( classpath != null ) + { + for ( ArtifactMetadata md : classpath ) + { + sb.append( ": " ).append( md.toString() ).append( '{' ).append( md.getArtifactUri() ).append( '}' ); + } + } + sb.append( ']' ); + return sb.toString(); + } + // ------------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathTransformation.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathTransformation.java new file mode 100644 index 00000000..eece4133 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/ClasspathTransformation.java @@ -0,0 +1,46 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.ArtifactScopeEnum; + +/** + * Helper class to conver an Md Graph into some form of a classpath + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public interface ClasspathTransformation +{ + String ROLE = ClasspathTransformation.class.getName(); + + /** + * Transform Graph into a Collection of metadata objects that + * could serve as a classpath for a particular scope + * + * @param dirtyGraph - dependency graph + * @param scope - which classpath to extract + * @param resolve - whether to resolve artifacts. + * @return Collection of metadata objects in the linked subgraph of the graph which + * contains the graph.getEntry() vertice + */ + ClasspathContainer transform( MetadataGraph dirtyGraph, ArtifactScopeEnum scope, boolean resolve ) + throws MetadataGraphTransformationException; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java new file mode 100644 index 00000000..03984fbd --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultClasspathTransformation.java @@ -0,0 +1,183 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; + +import org.apache.maven.artifact.ArtifactScopeEnum; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +/** + * default implementation of the metadata classpath transformer + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +@Component( role = ClasspathTransformation.class ) +public class DefaultClasspathTransformation + implements ClasspathTransformation +{ + @Requirement + GraphConflictResolver conflictResolver; + + //---------------------------------------------------------------------------------------------------- + public ClasspathContainer transform( MetadataGraph dirtyGraph, ArtifactScopeEnum scope, boolean resolve ) + throws MetadataGraphTransformationException + { + try + { + if ( dirtyGraph == null || dirtyGraph.isEmpty() ) + { + return null; + } + + MetadataGraph cleanGraph = conflictResolver.resolveConflicts( dirtyGraph, scope ); + + if ( cleanGraph == null || cleanGraph.isEmpty() ) + { + return null; + } + + ClasspathContainer cpc = new ClasspathContainer( scope ); + if ( cleanGraph.isEmptyEdges() ) + { + // single entry in the classpath, populated from itself + ArtifactMetadata amd = cleanGraph.getEntry().getMd(); + cpc.add( amd ); + } + else + { + ClasspathGraphVisitor v = new ClasspathGraphVisitor( cleanGraph, cpc ); + MetadataGraphVertex entry = cleanGraph.getEntry(); + // entry point + v.visit( entry ); + } + + return cpc; + } + catch ( GraphConflictResolutionException e ) + { + throw new MetadataGraphTransformationException( e ); + } + } + + //=================================================================================================== + /** + * Helper class to traverse graph. Required to make the containing method thread-safe + * and yet use class level data to lessen stack usage in recursion + */ + private class ClasspathGraphVisitor + { + MetadataGraph graph; + + ClasspathContainer cpc; + + List<MetadataGraphVertex> visited; + + // ----------------------------------------------------------------------- + protected ClasspathGraphVisitor( MetadataGraph cleanGraph, ClasspathContainer cpc ) + { + this.cpc = cpc; + this.graph = cleanGraph; + + visited = new ArrayList<MetadataGraphVertex>( cleanGraph.getVertices().size() ); + } + + // ----------------------------------------------------------------------- + protected void visit( MetadataGraphVertex node ) // , String version, String artifactUri ) + { + ArtifactMetadata md = node.getMd(); + if ( visited.contains( node ) ) + { + return; + } + + cpc.add( md ); +// +// TreeSet<MetadataGraphEdge> deps = new TreeSet<MetadataGraphEdge>( +// new Comparator<MetadataGraphEdge>() +// { +// public int compare( MetadataGraphEdge e1 +// , MetadataGraphEdge e2 +// ) +// { +// if( e1.getDepth() == e2.getDepth() ) +// { +// if( e2.getPomOrder() == e1.getPomOrder() ) +// return e1.getTarget().toString().compareTo(e2.getTarget().toString() ); +// +// return e2.getPomOrder() - e1.getPomOrder(); +// } +// +// return e2.getDepth() - e1.getDepth(); +// } +// } +// ); + + List<MetadataGraphEdge> exits = graph.getExcidentEdges( node ); + + if ( exits != null && exits.size() > 0 ) + { + MetadataGraphEdge[] sortedExits = exits.toArray( new MetadataGraphEdge[exits.size()] ); + Arrays.sort( sortedExits + , + new Comparator<MetadataGraphEdge>() + { + public int compare( MetadataGraphEdge e1 + , MetadataGraphEdge e2 + ) + { + if ( e1.getDepth() == e2.getDepth() ) + { + if ( e2.getPomOrder() == e1.getPomOrder() ) + { + return e1.getTarget().toString().compareTo( e2.getTarget().toString() ); + } + return e2.getPomOrder() - e1.getPomOrder(); + } + + return e2.getDepth() - e1.getDepth(); + } + } + ); + + for ( MetadataGraphEdge e : sortedExits ) + { + MetadataGraphVertex targetNode = e.getTarget(); + targetNode.getMd().setArtifactScope( e.getScope() ); + targetNode.getMd().setWhy( e.getSource().getMd().toString() ); + visit( targetNode ); + } + } + + } + //----------------------------------------------------------------------- + //----------------------------------------------------------------------- + } + //---------------------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------------------------------- +} + + + diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java new file mode 100644 index 00000000..bb764227 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolutionPolicy.java @@ -0,0 +1,73 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Configuration; + +/** + * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> + * + */ +@Component( role = GraphConflictResolutionPolicy.class ) +public class DefaultGraphConflictResolutionPolicy + implements GraphConflictResolutionPolicy +{ + /** + * artifact, closer to the entry point, is selected + */ + @Configuration( name = "closer-first", value = "true" ) + private boolean closerFirst = true; + + /** + * newer artifact is selected + */ + @Configuration( name = "newer-first", value = "true" ) + private boolean newerFirst = true; + + public MetadataGraphEdge apply( MetadataGraphEdge e1, MetadataGraphEdge e2 ) + { + int depth1 = e1.getDepth(); + int depth2 = e2.getDepth(); + + if ( depth1 == depth2 ) + { + ArtifactVersion v1 = new DefaultArtifactVersion( e1.getVersion() ); + ArtifactVersion v2 = new DefaultArtifactVersion( e2.getVersion() ); + + if ( newerFirst ) + { + return v1.compareTo( v2 ) > 0 ? e1 : e2; + } + + return v1.compareTo( v2 ) > 0 ? e2 : e1; + } + + if ( closerFirst ) + { + return depth1 < depth2 ? e1 : e2; + } + + return depth1 < depth2 ? e2 : e1; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java new file mode 100644 index 00000000..77060299 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/DefaultGraphConflictResolver.java @@ -0,0 +1,249 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.ArrayList; +import java.util.List; +import java.util.TreeSet; + +import org.apache.maven.artifact.ArtifactScopeEnum; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +/** + * Default conflict resolver.Implements closer newer first policy by default, but could be configured via plexus + * + * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> + */ +@Component( role = GraphConflictResolver.class ) +public class DefaultGraphConflictResolver + implements GraphConflictResolver +{ + /** + * artifact, closer to the entry point, is selected + */ + @Requirement( role = GraphConflictResolutionPolicy.class ) + protected GraphConflictResolutionPolicy policy; + + // ------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------------------- + public MetadataGraph resolveConflicts( MetadataGraph graph, ArtifactScopeEnum scope ) + throws GraphConflictResolutionException + { + if ( policy == null ) + { + throw new GraphConflictResolutionException( "no GraphConflictResolutionPolicy injected" ); + } + + if ( graph == null ) + { + return null; + } + + final MetadataGraphVertex entry = graph.getEntry(); + if ( entry == null ) + { + return null; + } + + if ( graph.isEmpty() ) + { + throw new GraphConflictResolutionException( "graph with an entry, but not vertices do not exist" ); + } + + if ( graph.isEmptyEdges() ) + { + return null; // no edges - nothing to worry about + } + + final TreeSet<MetadataGraphVertex> vertices = graph.getVertices(); + + try + { + // edge case - single vertex graph + if ( vertices.size() == 1 ) + { + return new MetadataGraph( entry ); + } + + final ArtifactScopeEnum requestedScope = ArtifactScopeEnum.checkScope( scope ); + + MetadataGraph res = new MetadataGraph( vertices.size() ); + res.setVersionedVertices( false ); + res.setScopedVertices( false ); + + MetadataGraphVertex resEntry = res.addVertex( entry.getMd() ); + res.setEntry( resEntry ); + + res.setScope( requestedScope ); + + for ( MetadataGraphVertex v : vertices ) + { + final List<MetadataGraphEdge> ins = graph.getIncidentEdges( v ); + final MetadataGraphEdge edge = cleanEdges( v, ins, requestedScope ); + + if ( edge == null ) + { // no edges - don't need this vertex any more + if ( entry.equals( v ) ) + { // unless it's an entry point. + // currently processing the entry point - it should not have any entry incident edges + res.getEntry().getMd().setWhy( "This is a graph entry point. No links." ); + } + else + { + // System.out.println("--->"+v.getMd().toDomainString() + // +" has been terminated on this entry set\n-------------------\n" + // +ins + // +"\n-------------------\n" + // ); + } + } + else + { + // System.out.println("+++>"+v.getMd().toDomainString()+" still has "+edge.toString() ); + // fill in domain md with actual version data + ArtifactMetadata md = v.getMd(); + ArtifactMetadata newMd = + new ArtifactMetadata( md.getGroupId(), md.getArtifactId(), edge.getVersion(), md.getType(), + md.getScopeAsEnum(), md.getClassifier(), edge.getArtifactUri(), + edge.getSource() == null ? "" : edge.getSource().getMd().toString(), + edge.isResolved(), edge.getTarget() == null ? null + : edge.getTarget().getMd().getError() ); + MetadataGraphVertex newV = res.addVertex( newMd ); + MetadataGraphVertex sourceV = res.addVertex( edge.getSource().getMd() ); + + res.addEdge( sourceV, newV, edge ); + } + } + MetadataGraph linkedRes = findLinkedSubgraph( res ); + // System.err.println("Original graph("+graph.getVertices().size()+"):\n"+graph.toString()); + // System.err.println("Cleaned("+requestedScope+") graph("+res.getVertices().size()+"):\n"+res.toString()); + // System.err.println("Linked("+requestedScope+") + // subgraph("+linkedRes.getVertices().size()+"):\n"+linkedRes.toString()); + return linkedRes; + } + catch ( MetadataResolutionException e ) + { + throw new GraphConflictResolutionException( e ); + } + } + + // ------------------------------------------------------------------------------------- + private MetadataGraph findLinkedSubgraph( MetadataGraph g ) + { + if ( g.getVertices().size() == 1 ) + { + return g; + } + + List<MetadataGraphVertex> visited = new ArrayList<MetadataGraphVertex>( g.getVertices().size() ); + visit( g.getEntry(), visited, g ); + + List<MetadataGraphVertex> dropList = new ArrayList<MetadataGraphVertex>( g.getVertices().size() ); + + // collect drop list + for ( MetadataGraphVertex v : g.getVertices() ) + { + if ( !visited.contains( v ) ) + { + dropList.add( v ); + } + } + + if ( dropList.size() < 1 ) + { + return g; + } + + // now - drop vertices + TreeSet<MetadataGraphVertex> vertices = g.getVertices(); + for ( MetadataGraphVertex v : dropList ) + { + vertices.remove( v ); + } + + return g; + } + + // ------------------------------------------------------------------------------------- + private void visit( MetadataGraphVertex from, List<MetadataGraphVertex> visited, MetadataGraph graph ) + { + if ( visited.contains( from ) ) + { + return; + } + + visited.add( from ); + + List<MetadataGraphEdge> exitList = graph.getExcidentEdges( from ); + // String s = "|---> "+from.getMd().toString()+" - "+(exitList == null ? -1 : exitList.size()) + " exit links"; + if ( exitList != null && exitList.size() > 0 ) + { + for ( MetadataGraphEdge e : graph.getExcidentEdges( from ) ) + { + visit( e.getTarget(), visited, graph ); + } + } + } + + // ------------------------------------------------------------------------------------- + private MetadataGraphEdge cleanEdges( MetadataGraphVertex v, List<MetadataGraphEdge> edges, + ArtifactScopeEnum scope ) + { + if ( edges == null || edges.isEmpty() ) + { + return null; + } + + if ( edges.size() == 1 ) + { + MetadataGraphEdge e = edges.get( 0 ); + if ( scope.encloses( e.getScope() ) ) + { + return e; + } + + return null; + } + + MetadataGraphEdge res = null; + + for ( MetadataGraphEdge e : edges ) + { + if ( !scope.encloses( e.getScope() ) ) + { + continue; + } + + if ( res == null ) + { + res = e; + } + else + { + res = policy.apply( e, res ); + } + } + + return res; + } + // ------------------------------------------------------------------------------------- + // ------------------------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionException.java new file mode 100644 index 00000000..035904aa --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionException.java @@ -0,0 +1,51 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public class GraphConflictResolutionException + extends Exception +{ + private static final long serialVersionUID = 2677613140287940255L; + + public GraphConflictResolutionException() + { + } + + public GraphConflictResolutionException( String message ) + { + super( message ); + } + + public GraphConflictResolutionException( Throwable cause ) + { + super( cause ); + } + + public GraphConflictResolutionException( String message, Throwable cause ) + { + super( message, cause ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionPolicy.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionPolicy.java new file mode 100644 index 00000000..979d3831 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolutionPolicy.java @@ -0,0 +1,35 @@ +package org.apache.maven.repository.metadata; + +/* + * 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. + */ + +/** + * MetadataGraph edge selection policy. Complements + * GraphConflictResolver by being injected into it + * + * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> + * + */ + +public interface GraphConflictResolutionPolicy +{ + String ROLE = GraphConflictResolutionPolicy.class.getName(); + + MetadataGraphEdge apply( MetadataGraphEdge e1, MetadataGraphEdge e2 ); +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolver.java new file mode 100644 index 00000000..ef70baa2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/GraphConflictResolver.java @@ -0,0 +1,48 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.ArtifactScopeEnum; + +/** + * Resolves conflicts in the supplied dependency graph. + * Different implementations will implement different conflict resolution policies. + * + * @author <a href="mailto:oleg@codehaus.org">Oleg Gusakov</a> + */ +public interface GraphConflictResolver +{ + String ROLE = GraphConflictResolver.class.getName(); + + /** + * Cleanses the supplied graph by leaving only one directed versioned edge\ + * between any two nodes, if multiple exists. Uses scope relationships, defined + * in <code>ArtifactScopeEnum</code> + * + * @param graph the "dirty" graph to be simplified via conflict resolution + * @param scope scope for which the graph should be resolved + * + * @return resulting "clean" graph for the specified scope + * + * @since 3.0 + */ + MetadataGraph resolveConflicts( MetadataGraph graph, ArtifactScopeEnum scope ) + throws GraphConflictResolutionException; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraph.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraph.java new file mode 100644 index 00000000..55b02504 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraph.java @@ -0,0 +1,523 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeSet; + +import org.apache.maven.artifact.ArtifactScopeEnum; + +/** + * maven dependency metadata graph + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public class MetadataGraph +{ + public static final int DEFAULT_VERTICES = 32; + public static final int DEFAULT_EDGES = 64; + + // flags to indicate the granularity of vertices + private boolean versionedVertices = false; + private boolean scopedVertices = false; + /** + * the entry point we started building the graph from + */ + MetadataGraphVertex entry; + + // graph vertices + TreeSet<MetadataGraphVertex> vertices; + + /** + * incident and excident edges per node + */ + Map<MetadataGraphVertex, List<MetadataGraphEdge>> incidentEdges; + Map<MetadataGraphVertex, List<MetadataGraphEdge>> excidentEdges; + + /** + * null in dirty graph, actual + * scope for conflict-resolved graph + */ + ArtifactScopeEnum scope; + + //------------------------------------------------------------------------ + /** + * init graph + */ + public MetadataGraph( int nVertices ) + { + init( nVertices, 2 * nVertices ); + } + public MetadataGraph( int nVertices, int nEdges ) + { + init( nVertices, nEdges ); + } + //------------------------------------------------------------------------ + /** + * construct a single vertex + */ + public MetadataGraph( MetadataGraphVertex entry ) + throws MetadataResolutionException + { + checkVertex( entry ); + checkVertices( 1 ); + + entry.setCompareVersion( versionedVertices ); + entry.setCompareScope( scopedVertices ); + + vertices.add( entry ); + this.entry = entry; + } + //------------------------------------------------------------------------ + /** + * construct graph from a "dirty" tree + */ + public MetadataGraph( MetadataTreeNode tree ) + throws MetadataResolutionException + { + this( tree, false, false ); + } + //------------------------------------------------------------------------ + /** + * construct graph from a "dirty" tree + * + * @param tree "dirty" tree root + * @param versionedVertices true if graph nodes should be versioned (different versions -> different nodes) + * @param scopedVertices true if graph nodes should be versioned and scoped (different versions and/or scopes -> different nodes) + * + */ + public MetadataGraph( MetadataTreeNode tree, boolean versionedVertices, boolean scopedVertices ) + throws MetadataResolutionException + { + if ( tree == null ) + { + throw new MetadataResolutionException( "tree is null" ); + } + + setVersionedVertices( versionedVertices ); + setScopedVertices( scopedVertices ); + + this.versionedVertices = scopedVertices || versionedVertices; + this.scopedVertices = scopedVertices; + + int count = countNodes( tree ); + + init( count, count + ( count / 2 ) ); + + processTreeNodes( null, tree, 0, 0 ); + } + //------------------------------------------------------------------------ + private void processTreeNodes( MetadataGraphVertex parentVertex, MetadataTreeNode node, int depth, int pomOrder ) + throws MetadataResolutionException + { + if ( node == null ) + { + return; + } + + MetadataGraphVertex vertex = new MetadataGraphVertex( node.md, versionedVertices, scopedVertices ); + if ( !vertices.contains( vertex ) ) + { + vertices.add( vertex ); + } + + if ( parentVertex != null ) // then create the edge + { + ArtifactMetadata md = node.getMd(); + MetadataGraphEdge e = + new MetadataGraphEdge( md.version, md.resolved, md.artifactScope, md.artifactUri, depth, pomOrder ); + addEdge( parentVertex, vertex, e ); + } + else + { + entry = vertex; + } + + MetadataTreeNode[] kids = node.getChildren(); + if ( kids == null || kids.length < 1 ) + { + return; + } + + for ( int i = 0; i < kids.length; i++ ) + { + MetadataTreeNode n = kids[i]; + processTreeNodes( vertex, n, depth + 1, i ); + } + } + //------------------------------------------------------------------------ + public MetadataGraphVertex findVertex( ArtifactMetadata md ) + { + if ( md == null || vertices == null || vertices.size() < 1 ) + { + return null; + } + + MetadataGraphVertex v = new MetadataGraphVertex( md ); + v.setCompareVersion( versionedVertices ); + v.setCompareScope( scopedVertices ); + + for ( MetadataGraphVertex gv : vertices ) + { + if ( gv.equals( v ) ) + { + return gv; + } + } + + return null; + } + //------------------------------------------------------------------------ + public MetadataGraphVertex addVertex( ArtifactMetadata md ) + { + if ( md == null ) + { + return null; + } + + checkVertices(); + + MetadataGraphVertex v = findVertex( md ); + if ( v != null ) + { + return v; + } + + v = new MetadataGraphVertex( md ); + + v.setCompareVersion( versionedVertices ); + v.setCompareScope( scopedVertices ); + + vertices.add( v ); + return v; + } + //------------------------------------------------------------------------ + /** + * init graph + */ + private void init( int nVertices, int nEdges ) + { + int nV = nVertices; + if ( nVertices < 1 ) + { + nV = 1; + } + + checkVertices( nV ); + + int nE = nVertices; + if ( nEdges <= nV ) + { + nE = 2 * nE; + } + + checkEdges( nE ); + } + + private void checkVertices() + { + checkVertices( DEFAULT_VERTICES ); + } + + private void checkVertices( int nVertices ) + { + if ( vertices == null ) + { + vertices = new TreeSet<MetadataGraphVertex>(); + } + } + private void checkEdges() + { + int count = DEFAULT_EDGES; + + if ( vertices != null ) + { + count = vertices.size() + vertices.size() / 2; + } + + checkEdges( count ); + } + private void checkEdges( int nEdges ) + { + if ( incidentEdges == null ) + { + incidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges ); + } + if ( excidentEdges == null ) + { + excidentEdges = new HashMap<MetadataGraphVertex, List<MetadataGraphEdge>>( nEdges ); + } + } + //------------------------------------------------------------------------ + private static void checkVertex( MetadataGraphVertex v ) + throws MetadataResolutionException + { + if ( v == null ) + { + throw new MetadataResolutionException( "null vertex" ); + } + if ( v.getMd() == null ) + { + throw new MetadataResolutionException( "vertex without metadata" ); + } + } + //------------------------------------------------------------------------ + private static void checkEdge( MetadataGraphEdge e ) + throws MetadataResolutionException + { + if ( e == null ) + { + throw new MetadataResolutionException( "badly formed edge" ); + } + } + //------------------------------------------------------------------------ + public List<MetadataGraphEdge> getEdgesBetween( MetadataGraphVertex vFrom, MetadataGraphVertex vTo ) + { + List<MetadataGraphEdge> edges = getIncidentEdges( vTo ); + if ( edges == null || edges.isEmpty() ) + { + return null; + } + + List<MetadataGraphEdge> res = new ArrayList<MetadataGraphEdge>( edges.size() ); + + for ( MetadataGraphEdge e : edges ) + { + if ( e.getSource().equals( vFrom ) ) + { + res.add( e ); + } + } + + return res; + } + //------------------------------------------------------------------------ + public MetadataGraph addEdge( MetadataGraphVertex vFrom, MetadataGraphVertex vTo, MetadataGraphEdge e ) + throws MetadataResolutionException + { + checkVertex( vFrom ); + checkVertex( vTo ); + + checkVertices(); + + checkEdge( e ); + checkEdges(); + + e.setSource( vFrom ); + e.setTarget( vTo ); + + vFrom.setCompareVersion( versionedVertices ); + vFrom.setCompareScope( scopedVertices ); + + List<MetadataGraphEdge> exList = excidentEdges.get( vFrom ); + if ( exList == null ) + { + exList = new ArrayList<MetadataGraphEdge>(); + excidentEdges.put( vFrom, exList ); + } + + if ( !exList.contains( e ) ) + { + exList.add( e ); + } + + List<MetadataGraphEdge> inList = incidentEdges.get( vTo ); + if ( inList == null ) + { + inList = new ArrayList<MetadataGraphEdge>(); + incidentEdges.put( vTo, inList ); + } + + if ( !inList.contains( e ) ) + { + inList.add( e ); + } + + return this; + } + //------------------------------------------------------------------------ + public MetadataGraph removeVertex( MetadataGraphVertex v ) + { + if ( vertices != null && v != null ) + { + vertices.remove( v ); + } + + if ( incidentEdges != null ) + { + incidentEdges.remove( v ); + } + + if ( excidentEdges != null ) + { + excidentEdges.remove( v ); + } + + return this; + + } + //------------------------------------------------------------------------ + private static int countNodes( MetadataTreeNode tree ) + { + if ( tree == null ) + { + return 0; + } + + int count = 1; + MetadataTreeNode[] kids = tree.getChildren(); + if ( kids == null || kids.length < 1 ) + { + return count; + } + for ( MetadataTreeNode n : kids ) + { + count += countNodes( n ); + } + + return count; + } + + //------------------------------------------------------------------------ + public MetadataGraphVertex getEntry() + { + return entry; + } + + public void setEntry( MetadataGraphVertex entry ) + { + this.entry = entry; + } + + public TreeSet<MetadataGraphVertex> getVertices() + { + return vertices; + } + + public List<MetadataGraphEdge> getIncidentEdges( MetadataGraphVertex vertex ) + { + checkEdges(); + return incidentEdges.get( vertex ); + } + + public List<MetadataGraphEdge> getExcidentEdges( MetadataGraphVertex vertex ) + { + checkEdges(); + return excidentEdges.get( vertex ); + } + + public boolean isVersionedVertices() + { + return versionedVertices; + } + + public void setVersionedVertices( boolean versionedVertices ) + { + this.versionedVertices = versionedVertices; + } + + public boolean isScopedVertices() + { + return scopedVertices; + } + + public void setScopedVertices( boolean scopedVertices ) + { + this.scopedVertices = scopedVertices; + + // scoped graph is versioned by definition + if ( scopedVertices ) + { + versionedVertices = true; + } + } + + public ArtifactScopeEnum getScope() + { + return scope; + } + + public void setScope( ArtifactScopeEnum scope ) + { + this.scope = scope; + } + + // ------------------------------------------------------------------------ + public boolean isEmpty() + { + return entry == null || vertices == null || vertices.isEmpty(); + } + + //------------------------------------------------------------------------ + public boolean isEmptyEdges() + { + return isEmpty() || incidentEdges == null || incidentEdges.isEmpty(); + } + //------------------------------------------------------------------------ + @Override + public String toString() + { + StringBuilder sb = new StringBuilder( 512 ); + if ( isEmpty() ) + { + return "empty"; + } + for ( MetadataGraphVertex v : vertices ) + { + sb.append( "Vertex: " ).append( v.getMd().toString() ).append( "\n" ); + List<MetadataGraphEdge> ins = getIncidentEdges( v ); + if ( ins != null ) + { + for ( MetadataGraphEdge e : ins ) + { + sb.append( " from : " ).append( e.toString() ).append( "\n" ); + } + } + else + { + sb.append( " no entries\n" ); + } + + List<MetadataGraphEdge> outs = getExcidentEdges( v ); + if ( outs != null ) + { + for ( MetadataGraphEdge e : outs ) + { + sb.append( " to : " ).append( e.toString() ).append( "\n" ); + } + } + else + { + sb.append( " no exit\n" ); + } + + sb.append( "-------------------------------------------------\n" ); + } + sb.append( "=============================================================\n" ); + return sb.toString(); + } + + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphEdge.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphEdge.java new file mode 100644 index 00000000..5f16df06 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphEdge.java @@ -0,0 +1,189 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.ArtifactScopeEnum; + +/** + * metadata graph edge - combination of version, scope and depth define + * an edge in the graph + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ + +public class MetadataGraphEdge +{ + String version; + ArtifactScopeEnum scope; + int depth = -1; + int pomOrder = -1; + boolean resolved = true; + String artifactUri; + + /** + * capturing where this link came from + * and where it is linked to. + * + * In the first implementation only source used for explanatory function + */ + MetadataGraphVertex source; + MetadataGraphVertex target; + + //---------------------------------------------------------------------------- + public MetadataGraphEdge( String version, boolean resolved, ArtifactScopeEnum scope, String artifactUri, int depth, + int pomOrder ) + { + super(); + this.version = version; + this.scope = scope; + this.artifactUri = artifactUri; + this.depth = depth; + this.resolved = resolved; + this.pomOrder = pomOrder; + } + //---------------------------------------------------------------------------- + /** + * helper for equals + */ + private static boolean objectsEqual( Object o1, Object o2 ) + { + if ( o1 == null && o2 == null ) + { + return true; + } + if ( o1 == null || o2 == null ) + { + return false; // as they are not both null + } + return o1.equals( o2 ); + } + + //---------------------------------------------------------------------------- + /** + * used to eliminate exact duplicates in the edge list + */ + @Override + public boolean equals( Object o ) + { + if ( o instanceof MetadataGraphEdge ) + { + MetadataGraphEdge e = (MetadataGraphEdge) o; + + return objectsEqual( version, e.version ) + && ArtifactScopeEnum.checkScope( scope ).getScope().equals( ArtifactScopeEnum.checkScope( e.scope ).getScope() ) + && depth == e.depth; + } + return false; + } + + //---------------------------------------------------------------------------- + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public ArtifactScopeEnum getScope() + { + return scope; + } + + public void setScope( ArtifactScopeEnum scope ) + { + this.scope = scope; + } + + public int getDepth() + { + return depth; + } + + public void setDepth( int depth ) + { + this.depth = depth; + } + + public boolean isResolved() + { + return resolved; + } + + public void setResolved( boolean resolved ) + { + this.resolved = resolved; + } + + public int getPomOrder() + { + return pomOrder; + } + + public void setPomOrder( int pomOrder ) + { + this.pomOrder = pomOrder; + } + + public String getArtifactUri() + { + return artifactUri; + } + + public void setArtifactUri( String artifactUri ) + { + this.artifactUri = artifactUri; + } + + public MetadataGraphVertex getSource() + { + return source; + } + + public void setSource( MetadataGraphVertex source ) + { + this.source = source; + } + + public MetadataGraphVertex getTarget() + { + return target; + } + + public void setTarget( MetadataGraphVertex target ) + { + this.target = target; + } + + @Override + public String toString() + { + return "[ " + "FROM:(" + + ( source == null ? "no source" : ( source.md == null ? "no source MD" : source.md.toString() ) ) + ") " + + "TO:(" + ( target == null ? "no target" : ( target.md == null ? "no target MD" : target.md.toString() ) ) + + ") " + "version=" + version + ", scope=" + ( scope == null ? "null" : scope.getScope() ) + ", depth=" + + depth + "]"; + } + //---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphTransformationException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphTransformationException.java new file mode 100644 index 00000000..16a34a8c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphTransformationException.java @@ -0,0 +1,50 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public class MetadataGraphTransformationException + extends Exception +{ + private static final long serialVersionUID = -4029897098314019152L; + + public MetadataGraphTransformationException() + { + } + + public MetadataGraphTransformationException( String message ) + { + super( message ); + } + + public MetadataGraphTransformationException( Throwable cause ) + { + super( cause ); + } + + public MetadataGraphTransformationException( String message, Throwable cause ) + { + super( message, cause ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphVertex.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphVertex.java new file mode 100644 index 00000000..bdccf6a5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataGraphVertex.java @@ -0,0 +1,216 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.ArtifactScopeEnum; + +/** + * metadata graph vertice - just a wrapper around artifact's metadata + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + */ +public class MetadataGraphVertex + implements Comparable<MetadataGraphVertex> +{ + ArtifactMetadata md; + + // indications to use these in comparrison + private boolean compareVersion = false; + private boolean compareScope = false; + + public MetadataGraphVertex( ArtifactMetadata md ) + { + super(); + this.md = md; + } + + public MetadataGraphVertex( ArtifactMetadata md, boolean compareVersion, boolean compareScope ) + { + this( md ); + this.compareVersion = compareVersion; + this.compareScope = compareScope; + } + + public ArtifactMetadata getMd() + { + return md; + } + + public void setMd( ArtifactMetadata md ) + { + this.md = md; + } + + // --------------------------------------------------------------------- + public boolean isCompareVersion() + { + return compareVersion; + } + + public void setCompareVersion( boolean compareVersion ) + { + this.compareVersion = compareVersion; + } + + public boolean isCompareScope() + { + return compareScope; + } + + public void setCompareScope( boolean compareScope ) + { + this.compareScope = compareScope; + } + + // --------------------------------------------------------------------- + @Override + public String toString() + { + return "[" + ( md == null ? "no metadata" : md.toString() ) + "]"; + } + + // --------------------------------------------------------------------- + private static int compareStrings( String s1, String s2 ) + { + if ( s1 == null && s2 == null ) + { + return 0; + } + + if ( s1 == null /* && s2 != null */ ) + { + return -1; + } + + if ( /* s1 != null && */ s2 == null ) + { + return 1; + } + + return s1.compareTo( s2 ); + } + + // --------------------------------------------------------------------- + public int compareTo( MetadataGraphVertex vertex ) + { + if ( vertex == null || vertex.getMd() == null ) + { + return 1; + } + + ArtifactMetadata vmd = vertex.getMd(); + + if ( vmd == null ) + { + if ( md == null ) + { + return 0; + } + else + { + return 1; + } + } + + int g = compareStrings( md.groupId, vmd.groupId ); + + if ( g == 0 ) + { + int a = compareStrings( md.artifactId, vmd.artifactId ); + if ( a == 0 ) + { + if ( compareVersion ) + { + int v = compareStrings( md.version, vmd.version ); + if ( v == 0 ) + { + if ( compareScope ) + { + String s1 = ArtifactScopeEnum.checkScope( md.artifactScope ).getScope(); + String s2 = ArtifactScopeEnum.checkScope( vmd.artifactScope ).getScope(); + return s1.compareTo( s2 ); + } + else + { + return 0; + } + } + else + { + return v; + } + } + else + { + return 0; + } + } + else + { + return a; + } + } + + return g; + } + + // --------------------------------------------------------------------- + @Override + public boolean equals( Object vo ) + { + if ( vo == null || !( vo instanceof MetadataGraphVertex ) ) + { + return false; + } + return compareTo( (MetadataGraphVertex) vo ) == 0; + } + + // --------------------------------------------------------------------- + + @Override + public int hashCode() + { + if ( md == null ) + { + return super.hashCode(); + } + StringBuilder hashString = new StringBuilder( 128 ); + hashString.append( md.groupId ).append( "|" ); + hashString.append( md.artifactId ).append( "|" ); + + if ( compareVersion ) + { + hashString.append( md.version ).append( "|" ); + } + + if ( compareScope ) + { + hashString.append( md.getArtifactScope() ).append( "|" ); + } + + return hashString.toString().hashCode(); + + // BASE64Encoder b64 = new BASE64Encoder(); + // return b64.encode( hashString.toString().getBytes() ).hashCode(); + } + + // --------------------------------------------------------------------- + // --------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolution.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolution.java new file mode 100644 index 00000000..9a9130b2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolution.java @@ -0,0 +1,71 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.Collection; + +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * + * @author Jason van Zyl + * + */ +public class MetadataResolution +{ + /** resolved MD */ + private ArtifactMetadata artifactMetadata; + + /** repositories, added by this POM */ + private Collection<ArtifactRepository> metadataRepositories; + //------------------------------------------------------------------- + public MetadataResolution( ArtifactMetadata artifactMetadata ) + { + this.artifactMetadata = artifactMetadata; + } + //------------------------------------------------------------------- + public MetadataResolution( ArtifactMetadata artifactMetadata, Collection<ArtifactRepository> metadataRepositories ) + { + this( artifactMetadata ); + this.metadataRepositories = metadataRepositories; + } + //------------------------------------------------------------------- + public Collection<ArtifactRepository> getMetadataRepositories() + { + return metadataRepositories; + } + + public void setMetadataRepositories( Collection<ArtifactRepository> metadataRepositories ) + { + this.metadataRepositories = metadataRepositories; + } + //------------------------------------------------------------------- + public ArtifactMetadata getArtifactMetadata() + { + return artifactMetadata; + } + + public void setArtifactMetadata( ArtifactMetadata artifactMetadata ) + { + this.artifactMetadata = artifactMetadata; + } + //------------------------------------------------------------------- + //------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionException.java new file mode 100644 index 00000000..24f832ef --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionException.java @@ -0,0 +1,49 @@ +package org.apache.maven.repository.metadata; + +/* + * 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. + */ + +public class MetadataResolutionException + extends Exception +{ + + public MetadataResolutionException() + { + // TODO Auto-generated constructor stub + } + + public MetadataResolutionException( String message ) + { + super( message ); + // TODO Auto-generated constructor stub + } + + public MetadataResolutionException( Throwable cause ) + { + super( cause ); + // TODO Auto-generated constructor stub + } + + public MetadataResolutionException( String message, Throwable cause ) + { + super( message, cause ); + // TODO Auto-generated constructor stub + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequest.java new file mode 100644 index 00000000..e1f6fe1e --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequest.java @@ -0,0 +1,79 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.List; + +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** @author Oleg Gusakov */ +public class MetadataResolutionRequest +{ + protected ArtifactMetadata query; + protected ArtifactRepository localRepository; + protected List<ArtifactRepository> remoteRepositories; + + //-------------------------------------------------------------------- + public MetadataResolutionRequest() + { + } + + //-------------------------------------------------------------------- + public MetadataResolutionRequest( ArtifactMetadata query, ArtifactRepository localRepository, + List<ArtifactRepository> remoteRepositories ) + { + this.query = query; + this.localRepository = localRepository; + this.remoteRepositories = remoteRepositories; + } + + //-------------------------------------------------------------------- + public ArtifactMetadata getQuery() + { + return query; + } + + public void setQuery( ArtifactMetadata query ) + { + this.query = query; + } + + public ArtifactRepository getLocalRepository() + { + return localRepository; + } + + public void setLocalRepository( ArtifactRepository localRepository ) + { + this.localRepository = localRepository; + } + + public List<ArtifactRepository> getRemoteRepositories() + { + return remoteRepositories; + } + + public void setRemoteRepositories( List<ArtifactRepository> remoteRepositories ) + { + this.remoteRepositories = remoteRepositories; + } + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequestTypeEnum.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequestTypeEnum.java new file mode 100644 index 00000000..f305497a --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionRequestTypeEnum.java @@ -0,0 +1,45 @@ +package org.apache.maven.repository.metadata; + +/* + * 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. + */ + +public enum MetadataResolutionRequestTypeEnum +{ + tree( 1 ) + , graph( 2 ) + , classpathCompile( 3 ) + , classpathTest( 4 ) + , classpathRuntime( 5 ) + , versionedGraph( 6 ) + , scopedGraph( 7 ) + ; + + private int id; + + // Constructor + MetadataResolutionRequestTypeEnum( int id ) + { + this.id = id; + } + + int getId() + { + return id; + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionResult.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionResult.java new file mode 100644 index 00000000..1d9e9c46 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataResolutionResult.java @@ -0,0 +1,172 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.ArtifactScopeEnum; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; + +/** + * This object is tinted with ClasspathTransformation and GraphConflictResolver. + * Get rid of them after debugging + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + */ +public class MetadataResolutionResult +{ + MetadataTreeNode treeRoot; + + /** + * these components are are initialized on demand by + * explicit call of the initTreeProcessing() + */ + ClasspathTransformation classpathTransformation; + GraphConflictResolver conflictResolver; + + //---------------------------------------------------------------------------- + public MetadataResolutionResult( ) + { + } + //---------------------------------------------------------------------------- + public MetadataResolutionResult( MetadataTreeNode root ) + { + this.treeRoot = root; + } + //---------------------------------------------------------------------------- + public MetadataTreeNode getTree() + { + return treeRoot; + } + //---------------------------------------------------------------------------- + public void setTree( MetadataTreeNode root ) + { + this.treeRoot = root; + } + + public void initTreeProcessing( PlexusContainer plexus ) + throws ComponentLookupException + { + classpathTransformation = plexus.lookup( ClasspathTransformation.class ); + conflictResolver = plexus.lookup( GraphConflictResolver.class ); + } + //---------------------------------------------------------------------------- + public MetadataGraph getGraph() + throws MetadataResolutionException + { + return treeRoot == null ? null : new MetadataGraph( treeRoot ); + } + //---------------------------------------------------------------------------- + public MetadataGraph getGraph( ArtifactScopeEnum scope ) + throws MetadataResolutionException, GraphConflictResolutionException + { + if ( treeRoot == null ) + { + return null; + } + + if ( conflictResolver == null ) + { + return null; + } + + return conflictResolver.resolveConflicts( getGraph(), scope ); + } + //---------------------------------------------------------------------------- + public MetadataGraph getGraph( MetadataResolutionRequestTypeEnum requestType ) + throws MetadataResolutionException, GraphConflictResolutionException + { + if ( requestType == null ) + { + return null; + } + + if ( treeRoot == null ) + { + return null; + } + + if ( conflictResolver == null ) + { + return null; + } + + if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathCompile ) ) + { + return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.compile ); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) ) + { + return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.runtime ); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) ) + { + return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test ); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.classpathRuntime ) ) + { + return conflictResolver.resolveConflicts( getGraph(), ArtifactScopeEnum.test ); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.graph ) ) + { + return getGraph(); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.versionedGraph ) ) + { + return new MetadataGraph( getTree(), true, false ); + } + else if ( requestType.equals( MetadataResolutionRequestTypeEnum.scopedGraph ) ) + { + return new MetadataGraph( getTree(), true, true ); + } + return null; + } + //---------------------------------------------------------------------------- + public ClasspathContainer getClasspath( ArtifactScopeEnum scope ) + throws MetadataGraphTransformationException, MetadataResolutionException + { + if ( classpathTransformation == null ) + { + return null; + } + + MetadataGraph dirtyGraph = getGraph(); + if ( dirtyGraph == null ) + { + return null; + } + + return classpathTransformation.transform( dirtyGraph, scope, false ); + } + + //---------------------------------------------------------------------------- + public MetadataTreeNode getClasspathTree( ArtifactScopeEnum scope ) + throws MetadataGraphTransformationException, MetadataResolutionException + { + ClasspathContainer cpc = getClasspath( scope ); + if ( cpc == null ) + { + return null; + } + + return cpc.getClasspathAsTree(); + } + //---------------------------------------------------------------------------- + //---------------------------------------------------------------------------- +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataRetrievalException.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataRetrievalException.java new file mode 100644 index 00000000..f5461d71 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataRetrievalException.java @@ -0,0 +1,59 @@ +package org.apache.maven.repository.metadata; + +/* + * 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. + */ + +/** + * Error while retrieving repository metadata from the repository. + * + * @author Jason van Zyl + */ +public class MetadataRetrievalException + extends Exception +{ + + private ArtifactMetadata artifact; + + public MetadataRetrievalException( String message ) + { + this( message, null, null ); + } + + public MetadataRetrievalException( Throwable cause ) + { + this( null, cause, null ); + } + + public MetadataRetrievalException( String message, Throwable cause ) + { + this( message, cause, null ); + } + + public MetadataRetrievalException( String message, Throwable cause, ArtifactMetadata artifact ) + { + super( message, cause ); + + this.artifact = artifact; + } + + public ArtifactMetadata getArtifactMetadata() + { + return artifact; + } +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataSource.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataSource.java new file mode 100644 index 00000000..3ca6ce84 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataSource.java @@ -0,0 +1,39 @@ +package org.apache.maven.repository.metadata; + +/* + * 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 java.util.List; + +import org.apache.maven.artifact.repository.ArtifactRepository; + +/** + * Provides some metadata operations, like querying the remote repository for a list of versions available for an + * artifact. + * + * @author Jason van Zyl + */ +public interface MetadataSource +{ + String ROLE = MetadataSource.class.getName(); + + MetadataResolution retrieve( ArtifactMetadata artifact, ArtifactRepository localRepository, + List<ArtifactRepository> remoteRepositories ) + throws MetadataRetrievalException; +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataTreeNode.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataTreeNode.java new file mode 100644 index 00000000..dd720d38 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/main/java/org/apache/maven/repository/metadata/MetadataTreeNode.java @@ -0,0 +1,148 @@ +package org.apache.maven.repository.metadata; + +/* + * 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.Artifact; +import org.apache.maven.artifact.ArtifactScopeEnum; + +/** + * metadata [dirty] Tree + * + * @author <a href="oleg@codehaus.org">Oleg Gusakov</a> + * + */ +public class MetadataTreeNode +{ + ArtifactMetadata md; // this node + + MetadataTreeNode parent; // papa + + /** default # of children. Used for tree creation optimization only */ + int nChildren = 8; + + MetadataTreeNode[] children; // of cause + + public int getNChildren() + { + return nChildren; + } + + public void setNChildren( int children ) + { + nChildren = children; + } + + //------------------------------------------------------------------------ + public MetadataTreeNode() + { + } + //------------------------------------------------------------------------ + public MetadataTreeNode( ArtifactMetadata md, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope ) + { + if ( md != null ) + { + md.setArtifactScope( ArtifactScopeEnum.checkScope( scope ) ); + md.setResolved( resolved ); + } + + this.md = md; + this.parent = parent; + } + //------------------------------------------------------------------------ + public MetadataTreeNode( Artifact af, MetadataTreeNode parent, boolean resolved, ArtifactScopeEnum scope ) + { + this( new ArtifactMetadata( af ), parent, resolved, scope ); + } + + // ------------------------------------------------------------------------ + public void addChild( int index, MetadataTreeNode kid ) + { + if ( kid == null ) + { + return; + } + + if ( children == null ) + { + children = new MetadataTreeNode[nChildren]; + } + + children[index % nChildren] = kid; + } + + //------------------------------------------------------------------ + @Override + public String toString() + { + return md == null ? "no metadata" : md.toString(); + } + + //------------------------------------------------------------------ + public String graphHash() + throws MetadataResolutionException + { + if ( md == null ) + { + throw new MetadataResolutionException( "treenode without metadata, parent: " + + ( parent == null ? "null" : parent.toString() ) ); + } + + return md.groupId + ":" + md.artifactId; + } + + //------------------------------------------------------------------------ + public boolean hasChildren() + { + return children != null; + } + //------------------------------------------------------------------------ + public ArtifactMetadata getMd() + { + return md; + } + + public void setMd( ArtifactMetadata md ) + { + this.md = md; + } + + public MetadataTreeNode getParent() + { + return parent; + } + + public void setParent( MetadataTreeNode parent ) + { + this.parent = parent; + } + + public MetadataTreeNode[] getChildren() + { + return children; + } + + public void setChildren( MetadataTreeNode[] children ) + { + this.children = children; + } + //------------------------------------------------------------------------ + //------------------------------------------------------------------------ + +} |