-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support changing of version in pde.bnd files
Currently the set-version mojo does not support updating the pde.bnd file, this now adds support for updating pde.bnd files in similar fashion like MANIFEST.MF Fix #2706 (cherry picked from commit 2fcedec)
- Loading branch information
Showing
13 changed files
with
455 additions
and
22 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
tycho-its/projects/tycho-version-plugin/set-version/pde-bnd/.mvn/extensions.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<extensions> | ||
<extension> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-build</artifactId> | ||
<version>${tycho-version}</version> | ||
</extension> | ||
</extensions> |
4 changes: 4 additions & 0 deletions
4
tycho-its/projects/tycho-version-plugin/set-version/pde-bnd/bundle/pde.bnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Bundle-Name: Bnd | ||
Bundle-SymbolicName: pde.bnd | ||
Bundle-Vendor: | ||
Bundle-Version: 1.0.0 |
24 changes: 24 additions & 0 deletions
24
tycho-its/projects/tycho-version-plugin/set-version/pde-bnd/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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 https://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.eclipse.tycho.its</groupId> | ||
<artifactId>pde-parent</artifactId> | ||
<version>1.0.0</version> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>bundle</module> | ||
</modules> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-maven-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
4 changes: 4 additions & 0 deletions
4
tycho-its/projects/tycho-version-plugin/update-eclipse-metadata/pde-bnd/pde.bnd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Bundle-Name: Bnd | ||
Bundle-SymbolicName: pde.bnd | ||
Bundle-Vendor: | ||
Bundle-Version: 1.0.0 |
22 changes: 22 additions & 0 deletions
22
tycho-its/projects/tycho-version-plugin/update-eclipse-metadata/pde-bnd/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.eclipse.tycho.its</groupId> | ||
<artifactId>pde.bnd</artifactId> | ||
<version>2.0.0-SNAPSHOT</version> | ||
<packaging>eclipse-plugin</packaging> | ||
<name>PDE-BND Bundle</name> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.eclipse.tycho</groupId> | ||
<artifactId>tycho-maven-plugin</artifactId> | ||
<version>${tycho-version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/bundle/BndLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 org.eclipse.tycho.versions.bundle; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
class BndLine { | ||
|
||
String eol; | ||
String rawstring; | ||
BndLine nextline; | ||
String key; | ||
String value; | ||
String newValue; | ||
|
||
boolean isContinuation() { | ||
return rawstring.strip().endsWith("\\"); | ||
} | ||
|
||
void parse() { | ||
Properties properties = new Properties(); | ||
String collect = collect(); | ||
try { | ||
properties.load(new StringReader(collect)); | ||
} catch (IOException e) { | ||
throw new AssertionError("I/O error while reading a string!", e); | ||
} | ||
Set<String> names = properties.stringPropertyNames(); | ||
if (names.isEmpty()) { | ||
return; | ||
} | ||
if (names.size() == 1) { | ||
this.key = names.iterator().next(); | ||
this.value = properties.getProperty(key); | ||
return; | ||
} | ||
throw new AssertionError("Line yields more than one property: " + collect); | ||
} | ||
|
||
String collect() { | ||
if (nextline == null) { | ||
return rawstring; | ||
} | ||
return rawstring + nextline.collect(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (key == null) { | ||
return collect(); | ||
} | ||
return key + ": " + value; | ||
} | ||
|
||
} |
118 changes: 118 additions & 0 deletions
118
tycho-versions-plugin/src/main/java/org/eclipse/tycho/versions/bundle/MutableBndFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 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 org.eclipse.tycho.versions.bundle; | ||
|
||
import java.io.BufferedInputStream; | ||
import java.io.BufferedReader; | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PushbackReader; | ||
import java.io.Writer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class MutableBndFile { | ||
|
||
private final List<BndLine> bndLines = new ArrayList<BndLine>(); | ||
|
||
public void setValue(String key, String value) { | ||
if (key == null) { | ||
return; | ||
} | ||
for (BndLine bndLine : bndLines) { | ||
if (Objects.equals(key, bndLine.key)) { | ||
bndLine.newValue = value; | ||
return; | ||
} | ||
} | ||
} | ||
|
||
public String getValue(String key) { | ||
if (key == null) { | ||
return null; | ||
} | ||
for (BndLine bndLine : bndLines) { | ||
if (Objects.equals(key, bndLine.key)) { | ||
if (bndLine.newValue != null) { | ||
return bndLine.newValue; | ||
} | ||
return bndLine.value; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
public void write(File bndFile) throws IOException { | ||
try (BufferedWriter writer = Files.newBufferedWriter(bndFile.toPath())) { | ||
write(writer); | ||
} | ||
} | ||
|
||
public void write(Writer writer) throws IOException { | ||
for (BndLine bndLine : bndLines) { | ||
if (bndLine.newValue == null || bndLine.key == null) { | ||
writer.write(bndLine.collect()); | ||
} else { | ||
String value = bndLine.value; | ||
if (value == null) { | ||
writer.write(bndLine.collect() + bndLine.newValue); | ||
} else { | ||
writer.write(bndLine.collect().replace(value, bndLine.newValue)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
public static MutableBndFile read(File file) throws IOException { | ||
try (InputStream is = new FileInputStream(file)) { | ||
return read(is); | ||
} | ||
} | ||
|
||
public static MutableBndFile read(InputStream is) throws IOException { | ||
PushbackReader pushbackReader = new PushbackReader( | ||
new BufferedReader(new InputStreamReader(new BufferedInputStream(is), StandardCharsets.UTF_8)), 1); | ||
MutableBndFile bndFile = new MutableBndFile(); | ||
BndLine line; | ||
BndLine last = null; | ||
while ((line = readLine(pushbackReader)) != null) { | ||
if (last != null && last.isContinuation()) { | ||
last.nextline = line; | ||
} else { | ||
bndFile.bndLines.add(line); | ||
} | ||
last = line; | ||
} | ||
bndFile.bndLines.forEach(BndLine::parse); | ||
return bndFile; | ||
|
||
} | ||
|
||
private static BndLine readLine(PushbackReader reader) throws IOException { | ||
BndLine bndLine = new BndLine(); | ||
String str = MutableBundleManifest.readLineWithLineEnding(reader, lineEnding -> bndLine.eol = lineEnding); | ||
if (str == null) { | ||
return null; | ||
} | ||
bndLine.rawstring = str; | ||
return bndLine; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.