Skip to content

Commit

Permalink
Fix #331 Support pom dependecies in maven targets
Browse files Browse the repository at this point in the history
Signed-off-by: Christoph Läubrich <[email protected]>
  • Loading branch information
laeubi committed Dec 5, 2021
1 parent 7fc1694 commit 288d802
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public interface MavenDependenciesResolver {
* @return
*/
default Collection<? /* IArtifactFacade */> resolve(String groupId, String artifactId, String version,
String packaging, String classifier, String dependencyScope,
String packaging, String classifier, String dependencyScope, boolean resolveTransitive,
Collection<MavenArtifactRepositoryReference> additionalRepositories) {
return resolve(groupId, artifactId, version, packaging, classifier, dependencyScope, additionalRepositories,
null);
return resolve(groupId, artifactId, version, packaging, classifier, dependencyScope, resolveTransitive,
additionalRepositories, null);
}

Collection<? /* IArtifactFacade */> resolve(String groupId, String artifactId, String version, String packaging,
String classifier, String dependencyScope,
String classifier, String dependencyScope, boolean resolveTransitive,
Collection<MavenArtifactRepositoryReference> additionalRepositories,
Object/* MavenSession */ session);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Export-Package: org.eclipse.tycho.p2.impl;x-friends:="org.eclipse.tycho.p2.impl.
org.eclipse.tycho.p2.target,
org.eclipse.tycho.p2.target.ee;x-friends:="org.eclipse.tycho.p2.tools.impl",
org.eclipse.tycho.p2.util.resolution
Import-Package: org.eclipse.tycho,
Import-Package: org.apache.commons.io;version="2.8.0",
org.eclipse.tycho,
org.eclipse.tycho.artifacts,
org.eclipse.tycho.core.ee.shared,
org.eclipse.tycho.core.resolver.shared,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.jar.Manifest;
import java.util.zip.ZipEntry;

import org.apache.commons.io.FilenameUtils;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
Expand Down Expand Up @@ -87,18 +88,28 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
logger.info((reference.isEmpty() ? "default instructions" : reference) + " = " + properties);
}
for (MavenDependency mavenDependency : location.getRoots()) {
boolean isPom = "pom".equalsIgnoreCase(mavenDependency.getArtifactType());
Collection<?> resolve = mavenDependenciesResolver.resolve(mavenDependency.getGroupId(),
mavenDependency.getArtifactId(), mavenDependency.getVersion(),
mavenDependency.getArtifactType(), mavenDependency.getClassifier(),
location.getIncludeDependencyScope(), location.getRepositoryReferences());
location.getIncludeDependencyScope(), isPom, location.getRepositoryReferences());

Iterator<IArtifactFacade> resolvedArtifacts = resolve.stream().filter(IArtifactFacade.class::isInstance)
.map(IArtifactFacade.class::cast).iterator();
Properties defaultProperties = WrappedArtifact.createPropertiesForPrefix("wrapped");
while (resolvedArtifacts.hasNext()) {
IArtifactFacade mavenArtifact = resolvedArtifacts.next();
if (mavenDependency.isIgnored(mavenArtifact)) {
logger.debug("Skipp ignored " + mavenArtifact + "...");
logger.debug("Skip ignored " + mavenArtifact + "...");
continue;
}
if ("pom".equalsIgnoreCase(mavenArtifact.getPackagingType())) {
logger.debug("Skip pom artifact " + mavenArtifact + "...");
continue;
}
String fileName = mavenArtifact.getLocation().getName();
if (!"jar".equalsIgnoreCase(FilenameUtils.getExtension(fileName))) {
logger.info("Skip non-jar artifact ... (" + fileName + ")");
continue;
}
logger.debug("Resolved " + mavenArtifact + "...");
Expand Down Expand Up @@ -182,7 +193,7 @@ public MavenTargetDefinitionContent(MavenGAVLocation location, MavenDependencies
|| (sourceMode == IncludeSourceMode.honor && location.includeSource())) {
Collection<?> sourceArtifacts = mavenDependenciesResolver.resolve(mavenArtifact.getGroupId(),
mavenArtifact.getArtifactId(), mavenArtifact.getVersion(),
mavenArtifact.getPackagingType(), "sources", null, Collections.emptyList());
mavenArtifact.getPackagingType(), "sources", null, false, Collections.emptyList());
Iterator<IArtifactFacade> sources = sourceArtifacts.stream()
.filter(IArtifactFacade.class::isInstance).map(IArtifactFacade.class::cast).iterator();
while (sources.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public class MavenDependenciesResolverConfigurer extends EquinoxLifecycleListene

@Override
public Collection<?> resolve(String groupId, String artifactId, String version, String packaging, String classifier,
String dependencyScope, Collection<MavenArtifactRepositoryReference> additionalRepositories,
Object session) {
String dependencyScope, boolean resolveTransitive,
Collection<MavenArtifactRepositoryReference> additionalRepositories, Object session) {
Artifact artifact;
if (classifier != null && !classifier.isEmpty()) {
artifact = repositorySystem.createArtifactWithClassifier(groupId, artifactId, version, packaging,
Expand All @@ -65,7 +65,7 @@ public Collection<?> resolve(String groupId, String artifactId, String version,
MavenSession mavenSession = getMavenSession(session);
request.setOffline(mavenSession.isOffline());
request.setLocalRepository(mavenSession.getLocalRepository());
request.setResolveTransitively(dependencyScope != null && !dependencyScope.isEmpty());
request.setResolveTransitively(resolveTransitive || (dependencyScope != null && !dependencyScope.isEmpty()));
if (additionalRepositories != null && additionalRepositories.size() > 0) {
List<ArtifactRepository> repositories = new ArrayList<>(
mavenSession.getCurrentProject().getRemoteArtifactRepositories());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public void connect() throws IOException {
String type = coordinates.length > 3 ? coordinates[3] : "jar";
String classifier = coordinates.length > 4 ? coordinates[4] : null;
Collection<?> resolve = resolver.resolve(coordinates[0], coordinates[1], coordinates[2], type,
classifier, null, Collections.emptyList(), session);
classifier, null, false, Collections.emptyList(), session);
if (resolve.isEmpty()) {
throw new IOException("artifact " + Arrays.toString(coordinates)
+ " could not be downloaded from any of the available repositories");
+ " could not be retrieved from any of the available repositories");
}
if (resolve.size() > 1) {
throw new IOException(
Expand Down
46 changes: 46 additions & 0 deletions tycho-its/projects/target.maven.pom/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Copyright (c) 2015, 2020 SAP SE and others. - All rights reserved. This
program and the accompanying materials - are made available under the terms
of the Eclipse Public License v1.0 - which accompanies this distribution,
and is available at - http://www.eclipse.org/legal/epl-v10.html - - Contributors:
- SAP SE - initial API and implementation -->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>issue-331-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>test.bundle</module>
<module>test.feature</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>

<target>
<file>../test.target</file>
</target>
</configuration>
</plugin>
</plugins>
</build>



</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Bundle
Bundle-SymbolicName: test.bundle
Bundle-Version: 0.0.1.qualifier
Automatic-Module-Name: test.bundle
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: jakarta.xml.bind-api;bundle-version="[3.0.1,4.0.0)"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
21 changes: 21 additions & 0 deletions tycho-its/projects/target.maven.pom/test.bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 SAP AG All rights reserved. This program
and the accompanying materials are made available under the terms of
the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>test.bundle</artifactId>
<packaging>eclipse-plugin</packaging>

<parent>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>issue-331-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2021 Christoph Läubrich and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package test.bundle;

import jakarta.xml.bind.annotation.XmlAttribute;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class TestClass {

@XmlElement
private String element;

@XmlAttribute
private String attribute;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = feature.xml
61 changes: 61 additions & 0 deletions tycho-its/projects/target.maven.pom/test.feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="test.feature"
label="Feature"
version="0.0.1.qualifier">

<description url="http://www.example.com/description">
[Enter Feature Description here.]
</description>

<copyright url="http://www.example.com/copyright">
[Enter Copyright Description here.]
</copyright>

<license url="http://www.example.com/license">
[Enter License Description here.]
</license>

<plugin
id="com.sun.xml.ws.jaxws-rt"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="jakarta.jws-api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="jakarta.xml.bind-api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="jakarta.xml.soap-api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="jakarta.xml.ws-api"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="com.sun.activation.jakarta.activation"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
21 changes: 21 additions & 0 deletions tycho-its/projects/target.maven.pom/test.feature/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012 SAP AG All rights reserved. This program
and the accompanying materials are made available under the terms of
the Eclipse Public License v1.0 which accompanies this distribution,
and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<artifactId>test.feature</artifactId>
<packaging>eclipse-feature</packaging>

<parent>
<groupId>org.eclipse.tycho.itests</groupId>
<artifactId>issue-331-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
20 changes: 20 additions & 0 deletions tycho-its/projects/target.maven.pom/test.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="test">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="http://download.eclipse.org/releases/2020-06"/>
<unit id="org.eclipse.sdk.feature.group" version="4.16.0.v20200604-0951"/>
</location>
<location includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-ri</artifactId>
<version>3.0.2</version>
<type>pom</type>
</dependency>
</dependencies>
</location>
</locations>
</target>

0 comments on commit 288d802

Please sign in to comment.