Skip to content

Commit

Permalink
Merge pull request #6401 from pkriens/issue/6393-non-workspace-handli…
Browse files Browse the repository at this point in the history
…ng-of-bndrun

Fixes a number of errors in the bndrun handling
  • Loading branch information
pkriens authored Dec 13, 2024
2 parents cc15633 + 0ed37df commit 8e5cfa7
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ public Bndrun init(File runFile, String task, File workingDir) throws Exception
run.setParent(getProcessor(workspace));
run.clear();
run.forceRefresh(); // setBase must be called after forceRefresh
run.setBase(temporaryDir);
// this should imho not be there, it should
// be the parent directory of the properties file, as it was.
// run.setBase(temporaryDir);
run.getInfo(workspace);
setRunrequiresFromProjectArtifact(run);
setEEfromBuild(run);
Expand Down
89 changes: 89 additions & 0 deletions biz.aQute.bndlib.tests/test/test/BndEditModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

import java.io.ByteArrayInputStream;
import java.io.File;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import org.junit.jupiter.api.Test;
import org.osgi.framework.namespace.IdentityNamespace;
Expand All @@ -19,12 +23,15 @@
import aQute.bnd.build.Workspace;
import aQute.bnd.build.model.BndEditModel;
import aQute.bnd.build.model.clauses.ExportedPackage;
import aQute.bnd.build.model.clauses.VersionedClause;
import aQute.bnd.osgi.Constants;
import aQute.bnd.osgi.Processor;
import aQute.bnd.osgi.resource.CapReqBuilder;
import aQute.bnd.properties.Document;
import aQute.lib.collections.ExtList;
import aQute.lib.io.IO;
import aQute.lib.strings.Strings;
import aQute.lib.utf8properties.UTF8Properties;

public class BndEditModelTest {
static CapReqBuilder cp = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
Expand Down Expand Up @@ -255,6 +262,88 @@ public void testGetPropertiesWithOnlyWorkspace() throws Exception {
assertThat(p.getProperty("foo")).isEqualTo("FOO");
}

/**
* Test the testresources/bndtools-resolve-reproducer project (m2). There
* were issues with the inheritance and inclusion of properties.
*/

static final File REPRODUCER = IO.getFile("testresources/bndtools-resolve-reproducer");
static final File DEBUG_BNDRUN = IO.getFile(REPRODUCER, "debug.bndrun");
static final Map<String, String> PROPERTIES = Map.of("-runbundles",
"org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)'", //
"-resolve.effective", "active", //
"-runfw", "org.eclipse.osgi;version='3.21.0'", //
"-runproperties.debug", "osgi.console=,osgi.console.enable.builtin=false", //
"-runrequires", "bnd.identity;id='org.example.bndtools.bndrun.reproducer'", //
"-runee", "JavaSE-17", //
"-runrequires.debug",
"osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.runtime)',osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'" //

);
static final Set<String> EXISTING_KEYS = Set.of("-runbundles", "-runrequires.debug",
"-runproperties.debug", "-include");

@Test
public void testBasicReproducer() throws Exception {
assertThat(DEBUG_BNDRUN).isFile();
Run run = Run.createRun(null, DEBUG_BNDRUN);
assertThat(run.getProperties()).containsExactlyInAnyOrderEntriesOf(PROPERTIES);
BndEditModel model = new BndEditModel(run);

assertThat(model.getAllPropertyNames()).containsAll(EXISTING_KEYS);

test("-runbundles", m -> m.setRunBundles(Collections.emptyList()), null);
test("-runfw", m -> m.setRunFw("foobar"), "foobar");
test("-runbundles", m -> m.setRunBundles(new ExtList<>(new VersionedClause("foobar"))), "foobar");
test("Bundle-Version", m -> m.setBundleVersion("1.2.3"), "1.2.3");
test("-runfw", m -> m.setRunFw(null), null);

}

void test(String key, Consumer<BndEditModel> c, String value) throws Exception {
assertThat(DEBUG_BNDRUN).isFile();
Run run = Run.createRun(null, DEBUG_BNDRUN);
BndEditModel model = new BndEditModel(run);
String oldValue = PROPERTIES.get(key);
boolean isInFile = EXISTING_KEYS.contains(key);

assertThat(model.getDocumentChanges()).isEmpty();

c.accept(model);

assertThat(model.getDocumentChanges()).containsEntry(key, value);
if (oldValue != null && isInFile)
assertThat(model.getDocumentProperties()).containsEntry(key, oldValue);

assertThat(model.getProperties()
.getProperties()
.get(key)).isEqualTo(value);

Document d = new Document(IO.collect(DEBUG_BNDRUN));
UTF8Properties p = new UTF8Properties();
p.load(d.get(), null, null);

if (isInFile && oldValue != null)
assertThat(p.get(key)).isEqualTo(oldValue);
else
assertThat(p.get(key)).isNull();

model.saveChangesTo(d);

if (value != null) {
assertThat(d.get()).contains(value);
} else {
assertThat(d.get()).doesNotContain(key);
}

assertThat(model.getDocumentChanges()).isEmpty();
if (value != null)
assertThat(model.getDocumentProperties()).containsEntry(key, value);
else
assertThat(model.getDocumentProperties()).doesNotContainKey(key);

}

private String getPortablePath(File base) {
String path = base.getAbsolutePath();
if (File.separatorChar != '/') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org/>.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Bundle-Activator: org.example.bndtools.bndrun.reproducer.Activator
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-include: ~run.bndrun
-standalone: target/index.xml
-resolve.effective: active
-runfw: org.eclipse.osgi;version='3.21.0'
-runee: JavaSE-17
-runproperties.debug: \
osgi.console=,\
osgi.console.enable.builtin=false
-runrequires.debug: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.shell)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.runtime)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'
-runbundles: \
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)',\
org.example.bndtools.bndrun.reproducer;version='[1.0.0,1.0.1)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-include: ~run.bndrun
-runproperties.debug: \
osgi.console=,\
osgi.console.enable.builtin=false
-runrequires.debug: \
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.runtime)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.gogo.command)'
-runbundles: \
org.apache.felix.gogo.command;version='[1.1.2,1.1.3)',\
org.apache.felix.gogo.runtime;version='[1.1.6,1.1.7)',\
org.apache.felix.gogo.shell;version='[1.1.4,1.1.5)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.example</groupId>
<artifactId>org.example.bndtools.bndrun.reproducer</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bnd.version>7.1.0</bnd.version>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.platform</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.21.0</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.shell</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.runtime</artifactId>
<version>1.1.6</version>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.gogo.command</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifestFile>
${project.build.outputDirectory}/META-INF/MANIFEST.MF
</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-indexer-maven-plugin</artifactId>
<version>${bnd.version}</version>
<configuration>
<includeJar>true</includeJar>
<localURLs>REQUIRED</localURLs>
<attach>false</attach>
</configuration>
<executions>
<execution>
<goals>
<goal>index</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-resolver-maven-plugin</artifactId>
<version>${bnd.version}</version>
<configuration>
<failOnChanges>false</failOnChanges>
<bndruns>
<bndrun>run.bndrun</bndrun>
<bndrun>debug.bndrun</bndrun>
<bndrun>debug-standalone.bndrun</bndrun>
</bndruns>
</configuration>
<executions>
<execution>
<id>resolve</id>
<goals>
<goal>resolve</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-export-maven-plugin</artifactId>
<version>${bnd.version}</version>
<executions>
<execution>
<goals>
<goal>export</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-resolve.effective: active
-runfw: org.eclipse.osgi;version='3.21.0'
-runee: JavaSE-17
-runrequires: bnd.identity;id='org.example.bndtools.bndrun.reproducer'
-runbundles: org.example.bndtools.bndrun.reproducer;version='[1.0.0,1.0.1)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.bndtools.bndrun.reproducer;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator{
}
Loading

0 comments on commit 8e5cfa7

Please sign in to comment.