Skip to content

Commit

Permalink
Fix eclipse-tycho#189 Support multiple maven-dependencies for one tar…
Browse files Browse the repository at this point in the history
…get location

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Jul 19, 2021
1 parent 4d14753 commit 24cbd6e
Show file tree
Hide file tree
Showing 13 changed files with 378 additions and 141 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2020 SAP AG and others.
* Copyright (c) 2011, 2021 SAP AG 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
Expand All @@ -12,6 +12,7 @@
* Christoph Läubrich - [Bug 538144] - support other target locations (Directory, Feature, Installations)
* [Bug 568729] - Support new "Maven" Target location
* [Bug 569481] - Support for maven target location includeSource="true" attribute
* [Issue 189] - Support multiple maven-dependencies for one target location
*******************************************************************************/
package org.eclipse.tycho.p2.target.facade;

Expand Down Expand Up @@ -80,18 +81,10 @@ enum MissingManifestStrategy {

MissingManifestStrategy getMissingManifestStrategy();

String getGroupId();

String getArtifactId();

String getVersion();

String getArtifactType();

String getClassifier();

Collection<BNDInstructions> getInstructions();

Collection<MavenDependency> getRoots();

boolean includeSource();
}

Expand Down Expand Up @@ -175,4 +168,17 @@ public interface BNDInstructions {
public Properties getInstructions();
}

public interface MavenDependency {

String getGroupId();

String getArtifactId();

String getVersion();

String getArtifactType();

String getClassifier();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* - [Bug 533747] - Target file is read and parsed over and over again
* - [Bug 568729] - Support new "Maven" Target location
* - [Bug 569481] - Support for maven target location includeSource="true" attribute
* - [Issue 189] - Support multiple maven-dependencies for one target location
*******************************************************************************/
package org.eclipse.tycho.core.ee;

Expand Down Expand Up @@ -164,6 +165,73 @@ public boolean includeSource() {
return Boolean.parseBoolean(dom.getAttributeValue("includeSource"));
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder("MavenDependencyRoots = ");
builder.append(getRoots());
builder.append(", IncludeDependencyScope = ");
builder.append(getIncludeDependencyScope());
builder.append(", MissingManifestStrategy = ");
builder.append(getMissingManifestStrategy());
builder.append(", IncludeSource = ");
builder.append(includeSource());
return builder.toString();
}

@Override
public Collection<BNDInstructions> getInstructions() {
List<BNDInstructions> list = new ArrayList<>();
for (Element element : dom.getChildren("instructions")) {
String reference = element.getAttributeValue("reference");
String text = element.getText();
Properties properties = new Properties();
try {
properties.load(new StringReader(text));
} catch (IOException e) {
throw new TargetDefinitionSyntaxException("parsing instructions into properties failed", e);
}
list.add(new BNDInstructions() {

@Override
public String getReference() {
if (reference == null) {
return "";
}
return reference;
}

@Override
public Properties getInstructions() {
return properties;
}
});
}
return list;
}

@Override
public Collection<MavenDependency> getRoots() {
for (Element dependencies : dom.getChildren("dependencies")) {
List<MavenDependency> roots = new ArrayList<>();
for (Element dependency : dependencies.getChildren("dependency")) {
roots.add(new MavenDependencyRoot(dependency));
}
return roots;
}
//backward compatibility for old format...
return Collections.singleton(new MavenDependencyRoot(dom));
}

}

private static final class MavenDependencyRoot implements MavenDependency {

private Element dom;

public MavenDependencyRoot(Element dom) {
this.dom = dom;
}

@Override
public String getGroupId() {
return getTextFromChild("groupId", null);
Expand Down Expand Up @@ -211,45 +279,9 @@ public String toString() {
builder.append(", ArtifactType = ");
builder.append(getArtifactType());
builder.append(", IncludeDependencyScope = ");
builder.append(getIncludeDependencyScope());
builder.append(", MissingManifestStrategy = ");
builder.append(getMissingManifestStrategy());
builder.append(", IncludeSource = ");
builder.append(includeSource());
return builder.toString();
}

@Override
public Collection<BNDInstructions> getInstructions() {
List<BNDInstructions> list = new ArrayList<>();
for (Element element : dom.getChildren("instructions")) {
String reference = element.getAttributeValue("reference");
String text = element.getText();
Properties properties = new Properties();
try {
properties.load(new StringReader(text));
} catch (IOException e) {
throw new TargetDefinitionSyntaxException("parsing instructions into properties failed", e);
}
list.add(new BNDInstructions() {

@Override
public String getReference() {
if (reference == null) {
return "";
}
return reference;
}

@Override
public Properties getInstructions() {
return properties;
}
});
}
return list;
}

}

public class IULocation implements TargetDefinition.InstallableUnitLocation {
Expand Down
49 changes: 49 additions & 0 deletions tycho-its/projects/target.mavenMulti/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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-189-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
<tycho-version>2.5.0-SNAPSHOT</tycho-version>
</properties>

<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,9 @@
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: org.eclipse.jetty.http;bundle-version="11.0.6",
slf4j.api;bundle-version="2.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
20 changes: 20 additions & 0 deletions tycho-its/projects/target.mavenMulti/test.bundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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-189-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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 org.eclipse.jetty.http.HttpField;

public class TestClass {
public static void main(String[] args) {
HttpField field = new HttpField("test", "me");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin.includes = feature.xml
40 changes: 40 additions & 0 deletions tycho-its/projects/target.mavenMulti/test.feature/feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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="test.bundle"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

<plugin
id="org.eclipse.jetty.http"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

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

</feature>
20 changes: 20 additions & 0 deletions tycho-its/projects/target.mavenMulti/test.feature/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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-189-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

</project>
22 changes: 22 additions & 0 deletions tycho-its/projects/target.mavenMulti/test.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target name="test">
<locations>
<location includeDependencyScope="compile" includeSource="true" missingManifest="generate" type="Maven">
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>11.0.6</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>11.0.6</version>
<type>jar</type>
</dependency>
</dependencies>
</location>
</locations>
</target>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020 Christoph Läubrich and others.
* Copyright (c) 2020, 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
Expand All @@ -25,6 +25,13 @@ public void testMavenLocation() throws Exception {
verifier.verifyErrorFreeLog();
}

@Test
public void testMavenLocationMulti() throws Exception {
Verifier verifier = getVerifier("target.mavenMulti", false, true);
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
}

public void testDirectoryLocation() throws Exception {
Verifier verifier = getVerifier("target.directory", false, true);
verifier.executeGoal("verify");
Expand Down

0 comments on commit 24cbd6e

Please sign in to comment.