Skip to content

Commit

Permalink
Bug 571369: Add source for p2infExtender to git
Browse files Browse the repository at this point in the history
Until now this code was pulled in binary format from Eclipse Source
website.

Change-Id: I7257722ec3cfeb17cb827d185721d5bc1c251336
  • Loading branch information
jonahgraham committed Mar 29, 2021
1 parent 7367f57 commit c4689d6
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
1 change: 1 addition & 0 deletions releng/p2infExtender/README.md
@@ -0,0 +1 @@
Please see comments in run.sh
Binary file added releng/p2infExtender/p2infExtender.jar
Binary file not shown.
55 changes: 55 additions & 0 deletions releng/p2infExtender/pom.xml
@@ -0,0 +1,55 @@
<?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.eclipse.epp.tools</groupId>
<artifactId>p2infExtender</artifactId>
<version>1.0-SNAPSHOT</version>

<name>p2infExtender</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>org.eclipse.epp.tools.Updater</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
26 changes: 26 additions & 0 deletions releng/p2infExtender/run.sh
@@ -0,0 +1,26 @@
#!/bin/bash


####
# This directory was supposed to try to recreate a Java program that has been lost to time. See
# the history of it in https://bugs.eclipse.org/bugs/show_bug.cgi?id=571369.
# The source here was supposed to create the same output as p2infExtender.jar does,
# but it is nothing like it.
# Therefore for now we are continuing to use the built jar, but no longer relying
# on pulling it from an external website.


set -u # run with unset flag error so that missing parameters cause build failure
set -e # error out on any failed commands
set -x # echo all commands used for debugging purposes

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
java -jar ${DIR}/p2infExtender.jar


exit 0
# The rest of this script can be used instead of the above if someone writes the
# expected Java code

mvn -f ${DIR} package
java -jar ${DIR}/target/p2infExtender-1.0-SNAPSHOT.jar
128 changes: 128 additions & 0 deletions releng/p2infExtender/src/main/java/org/eclipse/epp/tools/Updater.java
@@ -0,0 +1,128 @@
/****************************************************************************
* Copyright (c) 2016, 2021 Ed Merks (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*******************************************************************************/
package org.eclipse.epp.tools;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Updater {

public static void main(String[] args) throws Exception {
System.out.println("####" + System.getProperty("user.dir"));

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
documentBuilderFactory.setValidating(false);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

File file = new File(System.getProperty("user.dir"), "../../packages").getCanonicalFile();
for (File project : file.listFiles()) {
if (project.getName().endsWith(".product")) {

List<String> rootFeatures = new ArrayList<String>();
File productFile = new File(project, "epp.product");
Document document = documentBuilder.parse(new FileInputStream(productFile));
NodeList features = document.getElementsByTagName("feature");
for (int i = 0, length = features.getLength(); i < length; ++i) {
Element feature = (Element) features.item(i);
if ("root".equals(feature.getAttribute("installMode"))) {
rootFeatures.add(feature.getAttribute("id"));
}
}

if (rootFeatures.isEmpty()) {
System.out.println("Skipping " + productFile);

} else {
System.out.println("Processing " + productFile);
System.out.println(rootFeatures);

File p2InfFile = new File(project, "p2.inf");
FileInputStream in = new FileInputStream(p2InfFile);
byte[] bytes = new byte[in.available()];
in.read(bytes);
in.close();
String content = new String(bytes, "8859_1");

Pattern propertyPattern = Pattern.compile(
"^properties\\.([0-9]*)\\.(name|value)\\s*=\\s*((:?[^\r\n\\\\]|\\\\\r?\n|\\\\[^\r\n])*)(\r?\n)",
Pattern.DOTALL | Pattern.MULTILINE);

int newProperty = 0;
int newPosition = -1;
String nl = null;
int oldStart = -1;
int oldEnd = -1;
int oldProperty = -1;
for (Matcher matcher = propertyPattern.matcher(content); matcher.find();) {
String propertyKind = matcher.group(2);
int property = Integer.parseInt(matcher.group(1));
if ("name".equals(propertyKind)
&& "org.eclipse.equinox.p2.product.install.roots".equals(matcher.group(3))) {
oldStart = matcher.start();
oldProperty = property;
} else if ("value".equals(propertyKind) && property == oldProperty) {
oldEnd = matcher.end(4);
}

newProperty = Math.max(newProperty, property + 1);
// System.err.println(">" + matcher.group(1) + " " + propertyKind + " '" + matcher.group(3) + "'");
newPosition = matcher.end(4);
nl = matcher.group(5);
}

if (true) {
OutputStream o = new FileOutputStream(p2InfFile);
PrintStream out = new PrintStream(p2InfFile, "8859_1");

if (oldProperty != -1) {
newProperty = oldProperty;
}

if (oldStart == -1) {
out.print(content.substring(0, newPosition));
out.print(nl);
out.print(nl);
} else {
out.print(content.substring(0, oldStart));
}

out.print("properties." + newProperty + ".name = org.eclipse.equinox.p2.product.install.roots");
out.print(nl);
out.print("properties." + newProperty + ".value =");
for (int i = 0, size = rootFeatures.size(); i < size; ++i) {
out.print(" \\");
out.print(nl);
out.print(' ');
out.print(rootFeatures.get(i));
}

out.print(content.substring(oldEnd != -1 ? oldEnd : newPosition));

out.close();
o.close();
}
}
}
}
}
}

0 comments on commit c4689d6

Please sign in to comment.