Skip to content

Commit

Permalink
[FELIX-6073] Upgrade to Maven 3
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1854549 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
gnodet committed Feb 28, 2019
1 parent 4857cb9 commit e12e94c
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 265 deletions.
18 changes: 17 additions & 1 deletion tools/maven-bundle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,17 @@
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.2.0</version>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>3.3.9</version>
</dependency>
<dependency>
<groupId>org.apache.maven.reporting</groupId>
<artifactId>maven-reporting-api</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down Expand Up @@ -236,6 +246,12 @@
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.aether</groupId>
<artifactId>aether-impl</artifactId>
<version>1.1.0</version>
<scope>tet</scope>
</dependency>
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import org.apache.maven.artifact.Artifact;
Expand All @@ -35,13 +34,6 @@
import aQute.bnd.header.Attrs;
import aQute.bnd.header.OSGiHeader;
import aQute.bnd.osgi.Instruction;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.apache.maven.shared.dependency.graph.filter.ArtifactDependencyNodeFilter;
import org.apache.maven.shared.dependency.graph.filter.DependencyNodeFilter;
import org.apache.maven.shared.dependency.graph.traversal.BuildingDependencyNodeVisitor;
import org.apache.maven.shared.dependency.graph.traversal.CollectingDependencyNodeVisitor;
import org.apache.maven.shared.dependency.graph.traversal.DependencyNodeVisitor;
import org.apache.maven.shared.dependency.graph.traversal.FilteringDependencyNodeVisitor;


/**
Expand All @@ -54,19 +46,14 @@ public abstract class AbstractDependencyFilter
private static final Pattern MISSING_KEY_PATTERN = Pattern.compile( "(^|,)\\p{Blank}*(!)?\\p{Blank}*([a-zA-Z]+=)" );
private static final String PLACEHOLDER = "$$PLACEHOLDER$$";

/**
* Dependency Graph.
*/
private final DependencyNode m_dependencyGraph;
/**
* Dependency artifacts.
*/
private final Collection<Artifact> m_dependencyArtifacts;


public AbstractDependencyFilter( DependencyNode dependencyGraph, Collection<Artifact> dependencyArtifacts )
public AbstractDependencyFilter( Collection<Artifact> dependencyArtifacts )
{
m_dependencyGraph = dependencyGraph;
m_dependencyArtifacts = dependencyArtifacts;
}

Expand Down Expand Up @@ -107,27 +94,6 @@ boolean matches( String text )
}
}

private static class TrimmingDependencyNodeFilter implements DependencyNodeFilter
{
private DependencyNodeFilter dependencyNodeFilter;

public TrimmingDependencyNodeFilter( DependencyNodeFilter dependencyNodeFilter )
{
this.dependencyNodeFilter = dependencyNodeFilter;
}

public boolean accept( DependencyNode node )
{
boolean accepted = dependencyNodeFilter.accept( node );
if( !accepted )
{
List<DependencyNode> children = node.getChildren();
children.clear();
}
return accepted;
}
}

protected final void processInstructions( String header ) throws MojoExecutionException
{
Map<String,Attrs> instructions = OSGiHeader.parseHeader( MISSING_KEY_PATTERN.matcher( header ).replaceAll( "$1$2*;$3" ) );
Expand Down Expand Up @@ -297,40 +263,6 @@ else if ( "inline".equals( attr.getKey() ) )

private void filteredDependencies( final ArtifactFilter artifactFilter, Collection<Artifact> filteredDependencies )
{
CollectingDependencyNodeVisitor collectingDependencyNodeVisitor = new CollectingDependencyNodeVisitor();
final Artifact rootArtifact = m_dependencyGraph.getArtifact();
ArtifactFilter filter = new ArtifactFilter()
{


public boolean include( Artifact artifact )
{
return artifact.equals( rootArtifact ) || artifactFilter.include( artifact );
}


};
DependencyNodeFilter dependencyNodeFilter = new ArtifactDependencyNodeFilter( filter );
dependencyNodeFilter = new TrimmingDependencyNodeFilter( dependencyNodeFilter );
DependencyNodeVisitor dependencyNodeVisitor =
new FilteringDependencyNodeVisitor( collectingDependencyNodeVisitor, dependencyNodeFilter );
dependencyNodeVisitor = new BuildingDependencyNodeVisitor( dependencyNodeVisitor );
m_dependencyGraph.accept( dependencyNodeVisitor );
List<DependencyNode> dependencyNodes = collectingDependencyNodeVisitor.getNodes();
Set<String> ids = new LinkedHashSet<String>( dependencyNodes.size() );
for( DependencyNode dependencyNode : dependencyNodes ) {
Artifact artifact = dependencyNode.getArtifact();
String id = artifact.getId();
ids.add(id);
}
for (Iterator<Artifact> iterator = filteredDependencies.iterator(); iterator.hasNext();)
{
Artifact artifact = iterator.next();
String id = artifact.getId();
if (!ids.contains(id))
{
iterator.remove();
}
}
filteredDependencies.removeIf( artifact -> !artifactFilter.include( artifact ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.dependency.graph.DependencyNode;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.IOUtil;
Expand All @@ -50,7 +49,7 @@ public class AntPlugin extends BundlePlugin


@Override
protected void execute( MavenProject currentProject, DependencyNode dependencyGraph, Map<String, String> originalInstructions, Properties properties,
protected void execute( Map<String, String> originalInstructions,
Jar[] classpath ) throws MojoExecutionException
{
final String artifactId = getProject().getArtifactId();
Expand All @@ -59,8 +58,8 @@ protected void execute( MavenProject currentProject, DependencyNode dependencyGr
try
{
// assemble bundle as usual, but don't save it - this way we have all the instructions we need
Builder builder = buildOSGiBundle( currentProject,
dependencyGraph, originalInstructions, properties, classpath );
Builder builder = buildOSGiBundle(project,
originalInstructions, classpath );
Properties bndProperties = builder.getProperties();

// cleanup and remove all non-strings from the builder properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.jar.Manifest;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -342,8 +341,7 @@ protected BundleInfo bundle( MavenProject project ) throws MojoExecutionExceptio
// + " to the same file, try cleaning: " + outputFile );
}

org.apache.maven.shared.dependency.graph.DependencyNode dependencyGraph = buildDependencyGraph( project );
Analyzer analyzer = getAnalyzer( project, dependencyGraph, instructions, new Properties(), getClasspath( project, dependencyGraph ) );
Analyzer analyzer = getAnalyzer( project, instructions, getClasspath( project) );

Jar osgiJar = new Jar( project.getArtifactId(), project.getArtifact().getFile() );

Expand Down
Loading

2 comments on commit e12e94c

@martin-g
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that these changes lead to errors like:

INFO] --- maven-bundle-plugin:4.2.0:bundle (default-bundle) @
wicketstuff-bundle ---
[ERROR] An internal error occurred
java.lang.IllegalArgumentException: A Jar can only accept a file or
directory that exists:
/home/solomax/work/wicketstuff-core/wicket-bundle-parent/wicket-bundle/target/classes
    at aQute.bnd.osgi.Jar.<init> (Jar.java:124)
    at aQute.bnd.osgi.Jar.<init> (Jar.java:172)
    at org.apache.felix.bundleplugin.BundlePlugin.getOSGiBuilder
(BundlePlugin.java:603)

It started failing after upgrading to maven-bundle-plugin:4.2.0.
The sources of the problematic Maven module are at https://github.com/wicketstuff/core/tree/master/wicket-bundle-parent/wicket-bundle. There is no src/main/java there.

@martin-g
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think it is caused by : 9487647#diff-20f133aa64b3be0d651687991d1afe16R594

Please sign in to comment.