Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace use-cases of internal PDE build Utils by standard Java methods #660

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -36,9 +37,9 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.equinox.frameworkadmin.BundleInfo;
import org.eclipse.equinox.internal.p2.publisher.QuotedTokenizer;

Check warning on line 40 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;

Check warning on line 42 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
Expand Down Expand Up @@ -177,7 +178,7 @@
if (initialInf.exists()) {
//copy over initial contents
try {
StringBuffer inf = Utils.readFile(initialInf);
String inf = Files.readString(initialInf.toPath(), StandardCharsets.ISO_8859_1);
buffer.append(inf);
buffer.append('\n');
} catch (IOException e) {
Expand All @@ -189,7 +190,7 @@

try {
Files.createDirectories(Path.of(root));
Files.writeString(Path.of(root, "p2.inf"), buffer.toString()); //$NON-NLS-1$
Files.writeString(Path.of(root, "p2.inf"), buffer.toString(), StandardCharsets.ISO_8859_1); //$NON-NLS-1$
} catch (IOException e) {
return false;
}
Expand Down Expand Up @@ -270,7 +271,7 @@

//in case of no version on the product, the branding defaults to the version of the launcher provider
if (executableFeature != null && productVersionString.equals(Version.emptyVersion.toString())) {
String brandedVersion = executableFeature.getVersion();

Check warning on line 274 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
brandedRange = new VersionRange(new Version(brandedVersion), true, new Version(brandedVersion), true).toString();
}

Expand Down Expand Up @@ -331,7 +332,7 @@
if (feature) {
BuildTimeFeature requiredFeature = getSite(false).findFeature(id, version.toString(), false);
if (requiredFeature != null)
versionString = requiredFeature.getVersion();

Check warning on line 335 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
} else {
BundleDescription bundle = getSite(false).getRegistry().getResolvedBundle(id, version.toString());
if (bundle != null)
Expand Down Expand Up @@ -377,13 +378,13 @@
environment.put("osgi.ws", config.getWs()); //$NON-NLS-1$
environment.put("osgi.arch", config.getArch()); //$NON-NLS-1$

List<FeatureEntry> pluginList = productFile.getProductEntries();

Check warning on line 381 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
List<BundleDescription> results = new ArrayList<>(pluginList.size());
for (FeatureEntry entry : pluginList) {

Check warning on line 383 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (!entry.isPlugin())

Check warning on line 384 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
continue;

BundleDescription bundle = assembly.getPlugin(entry.getId(), entry.getVersion());

Check warning on line 387 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (bundle != null) {
Filter filter = helper.getFilter(bundle);
if (filter == null || filter.match(environment))
Expand Down Expand Up @@ -661,9 +662,9 @@
String lineDelimiter = Platform.OS_WIN32.equals(os) ? "\r\n" : "\n"; //$NON-NLS-1$ //$NON-NLS-2$
try (PrintWriter writer = new PrintWriter(new FileWriter(new File(dir, launcher + ".ini")))) { //$NON-NLS-1$
if (programArgs != null && programArgs.length() > 0) {
QuotedTokenizer tokenizer = new QuotedTokenizer(programArgs);

Check warning on line 665 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
while (tokenizer.hasMoreTokens()) {

Check warning on line 666 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String token = tokenizer.nextToken().trim();

Check warning on line 667 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (!token.equals("")) { //$NON-NLS-1$
writer.print(token);
writer.print(lineDelimiter);
Expand All @@ -673,9 +674,9 @@
if (vmArgs != null && vmArgs.length() > 0) {
writer.print("-vmargs"); //$NON-NLS-1$
writer.print(lineDelimiter);
QuotedTokenizer tokenizer = new QuotedTokenizer(vmArgs);

Check warning on line 677 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
while (tokenizer.hasMoreTokens()) {

Check warning on line 678 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String token = tokenizer.nextToken().trim();

Check warning on line 679 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/ProductGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (!token.equals("")) { //$NON-NLS-1$
writer.print(token);
writer.print(lineDelimiter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;

Check warning on line 45 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.service.resolver.VersionRange;
import org.eclipse.osgi.util.ManifestElement;
Expand Down Expand Up @@ -136,8 +136,8 @@
return range;
}

public static VersionRange createVersionRange(FeatureEntry entry) {

Check warning on line 139 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String versionSpec = entry.getVersion();

Check warning on line 140 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (versionSpec == null)
return VersionRange.emptyRange;

Expand All @@ -145,8 +145,8 @@
if (version.equals(Version.emptyVersion))
return VersionRange.emptyRange;

String match = entry.getMatch();

Check warning on line 148 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (!entry.isRequires() || match == null) {

Check warning on line 149 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
return createVersionRange(versionSpec);
}

Expand Down Expand Up @@ -407,19 +407,19 @@
}
}

public static FeatureEntry[] getPluginEntry(BuildTimeFeature feature, String pluginId, boolean raw) {

Check warning on line 410 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
FeatureEntry[] plugins;

Check warning on line 411 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (raw)
plugins = feature.getRawPluginEntries();
else
plugins = feature.getPluginEntries();
List<FeatureEntry> foundEntries = new ArrayList<>(5);

Check warning on line 416 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:

for (FeatureEntry plugin2 : plugins) {

Check warning on line 418 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (plugin2.getId().equals(pluginId))

Check warning on line 419 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
foundEntries.add(plugin2);
}
return foundEntries.toArray(new FeatureEntry[foundEntries.size()]);

Check warning on line 422 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:

}

Expand Down Expand Up @@ -450,9 +450,9 @@
return collectedElements;
}

public static boolean isIn(FeatureEntry[] array, FeatureEntry element) {

Check warning on line 453 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
for (FeatureEntry element2 : array) {

Check warning on line 454 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (element2.getId().equals(element.getId()) && element2.getVersion().equals(element.getVersion()))

Check warning on line 455 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
return true;
}
return false;
Expand Down Expand Up @@ -826,52 +826,6 @@
return false;
}

/**
*
* @param buf
* @param start
* @param target
* @return int
*/
static public int scan(StringBuffer buf, int start, String target) {
return scan(buf, start, new String[] {target});
}

/**
*
* @param buf
* @param start
* @param targets
* @return int
*/
static public int scan(StringBuffer buf, int start, String[] targets) {
for (int i = start; i < buf.length(); i++) {
for (String target : targets) {
if (i < buf.length() - target.length()) {
String match = buf.substring(i, i + target.length());
if (target.equals(match))
return i;
}
}
}
return -1;
}

/**
* Return a buffer containing the contents of the file at the specified location.
*
* @param target the file
* @return StringBuffer
* @throws IOException
*/
static public StringBuffer readFile(File target) throws IOException {
return new StringBuffer(new String(Files.readAllBytes(target.toPath())));
}

static public StringBuffer readFile(InputStream stream) throws IOException {
return new StringBuffer(new String(stream.readAllBytes()));
}

/**
* Custom build scripts should have their version number matching the
* version number defined by the feature/plugin/fragment descriptor.
Expand All @@ -880,31 +834,29 @@
*
* @param buildFile
* @param propertyName
* @param version
* @param newVersion
* @throws IOException
*
*/
public static void updateVersion(File buildFile, String propertyName, String version) throws IOException {
StringBuffer buffer = readFile(buildFile);
int pos = scan(buffer, 0, propertyName);
public static void updateVersion(File buildFile, String propertyName, String newVersion) throws IOException {
String value = Files.readString(buildFile.toPath());
int pos = value.indexOf(propertyName);
if (pos == -1)
return;
pos = scan(buffer, pos, "value"); //$NON-NLS-1$
pos = value.indexOf("value", pos); //$NON-NLS-1$
if (pos == -1)
return;
int begin = scan(buffer, pos, "\""); //$NON-NLS-1$
int begin = value.indexOf("\"", pos); //$NON-NLS-1$
if (begin == -1)
return;
begin++;
int end = scan(buffer, begin, "\""); //$NON-NLS-1$
int end = value.indexOf("\"", begin); //$NON-NLS-1$
if (end == -1)
return;
String currentVersion = buffer.substring(begin, end);
String newVersion = version;
if (currentVersion.equals(newVersion))
return;
buffer.replace(begin, end, newVersion);
Files.writeString(buildFile.toPath(), buffer.toString());
String currentVersion = value.substring(begin, end);
if (!currentVersion.equals(newVersion)) {
Files.writeString(buildFile.toPath(), new StringBuilder(value).replace(begin, end, newVersion));
}
}

public static Enumeration<Object> getArrayEnumerator(Object[] array) {
Expand Down Expand Up @@ -941,30 +893,30 @@
return false;
}

public static String getEntryVersionMappings(FeatureEntry[] entries, BuildTimeSite site) {

Check warning on line 896 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
return getEntryVersionMappings(entries, site, null);
}

public static String getEntryVersionMappings(FeatureEntry[] entries, BuildTimeSite site, AssemblyInformation assembly) {

Check warning on line 900 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (entries == null || site == null)
return null;

StringBuffer result = new StringBuffer();
for (FeatureEntry entry : entries) {

Check warning on line 905 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String versionRequested = entry.getVersion();

Check warning on line 906 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (versionRequested == null)
versionRequested = GENERIC_VERSION_NUMBER;
String id = entry.getId();

Check warning on line 909 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String newVersion = null;

if (!needsReplacement(versionRequested))
continue;

try {
if (entry.isPlugin()) {

Check warning on line 916 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
BundleDescription model = null;
if (assembly != null)
model = assembly.getPlugin(entry.getId(), versionRequested);

Check warning on line 919 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (model == null)
model = site.getRegistry().getResolvedBundle(id, versionRequested);
if (model != null)
Expand All @@ -972,7 +924,7 @@
} else {
BuildTimeFeature feature = site.findFeature(id, versionRequested, false);
if (feature != null)
newVersion = feature.getVersion();

Check warning on line 927 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/Utils.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}
} catch (CoreException e) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.OutputStream;
import java.io.SequenceInputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
Expand All @@ -39,13 +40,16 @@
import java.util.jar.Attributes.Name;
import java.util.jar.Manifest;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.p2.publisher.eclipse.Feature;

Check warning on line 50 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.equinox.p2.publisher.eclipse.FeatureEntry;

Check warning on line 51 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.equinox.p2.publisher.eclipse.URLEntry;

Check warning on line 52 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.osgi.util.NLS;
import org.eclipse.pde.build.Constants;
Expand Down Expand Up @@ -120,19 +124,19 @@
return AbstractScriptGenerator.readProperties(model.getLocation(), PROPERTIES_FILE, IStatus.OK);
}

private String getSourcePluginName(FeatureEntry plugin, boolean versionSuffix) {

Check warning on line 127 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
return plugin.getId() + (versionSuffix ? "_" + plugin.getVersion() : ""); //$NON-NLS-1$ //$NON-NLS-2$

Check warning on line 128 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}

private void collectSourceEntries(BuildTimeFeature feature) throws CoreException {
FeatureEntry[] pluginList = feature.getPluginEntries();

Check warning on line 132 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
for (FeatureEntry entry : pluginList) {

Check warning on line 133 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
BundleDescription model;
if (director.selectConfigs(entry).size() == 0)
continue;

String versionRequested = entry.getVersion();

Check warning on line 138 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
model = getSite().getRegistry().getResolvedBundle(entry.getId(), versionRequested);

Check warning on line 139 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (model == null)
continue;

Expand All @@ -140,7 +144,7 @@
}
}

private void collectSourcePlugins(BuildTimeFeature feature, FeatureEntry pluginEntry, BundleDescription model) throws CoreException {

Check warning on line 147 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
//don't gather if we are doing individual source bundles
if (individualSourceBundles)
return;
Expand All @@ -148,7 +152,7 @@
// The generic entry may not be part of the configuration we are building however,
// the code for a non platform specific plugin still needs to go into a generic source plugin
String sourceId = computeSourceFeatureName(feature, false);
if (pluginEntry.getOS() == null && pluginEntry.getWS() == null && pluginEntry.getArch() == null) {

Check warning on line 155 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
director.sourceToGather.addElementEntry(sourceId, model);
return;
}
Expand All @@ -169,22 +173,22 @@

associateExtraEntries(sourceFeature);

FeatureEntry sourcePlugin;

Check warning on line 176 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (individualSourceBundles) {
/* individual source bundles */

// branding plugin for source feature will be the source bundle generated
//from the original branding plugin.
brandingPlugin = feature.getBrandingPlugin();

Check warning on line 182 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (brandingPlugin != null) {
brandingPlugin += ".source"; //$NON-NLS-1$
sourceFeature.setBrandingPlugin(brandingPlugin);

Check warning on line 185 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
} else {
brandingPlugin = sourceFeature.getId();

Check warning on line 187 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}

FeatureEntry[] plugins = feature.getPluginEntries();

Check warning on line 190 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
for (FeatureEntry plugin2 : plugins) {

Check warning on line 191 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (director.selectConfigs(plugin2).size() == 0)
continue;
createSourceBundle(sourceFeature, plugin2);
Expand All @@ -204,7 +208,7 @@
// Add extra plugins into the given feature.
private void associateExtraEntries(BuildTimeFeature sourceFeature) throws CoreException {
BundleDescription model;
FeatureEntry entry;

Check warning on line 211 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:

for (int i = 1; i < extraEntries.length; i++) {
Map<String, Object> items = Utils.parseExtraBundlesString(extraEntries[i], true);
Expand All @@ -213,11 +217,11 @@

// see if we have a plug-in or a fragment
if (extraEntries[i].startsWith("feature@")) { //$NON-NLS-1$
entry = new FeatureEntry(id, version.toString(), false);

Check warning on line 220 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (items.containsKey(Utils.EXTRA_OPTIONAL))
entry.setOptional(((Boolean) items.get(Utils.EXTRA_OPTIONAL)).booleanValue());

Check warning on line 222 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
entry.setEnvironment((String) items.get(Utils.EXTRA_OS), (String) items.get(Utils.EXTRA_WS), (String) items.get(Utils.EXTRA_ARCH), null);

Check warning on line 223 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
sourceFeature.addEntry(entry);

Check warning on line 224 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
} else if (extraEntries[i].startsWith("plugin@")) { //$NON-NLS-1$
model = getSite().getRegistry().getResolvedBundle((String) items.get(Utils.EXTRA_ID), ((Version) items.get(Utils.EXTRA_VERSION)).toString());
if (model == null) {
Expand All @@ -225,10 +229,10 @@
BundleHelper.getDefault().getLog().log(status);
continue;
}
entry = new FeatureEntry(model.getSymbolicName(), model.getVersion().toString(), true);

Check warning on line 232 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
entry.setUnpack(((Boolean) items.get(Utils.EXTRA_UNPACK)).booleanValue());

Check warning on line 233 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
entry.setEnvironment((String) items.get(Utils.EXTRA_OS), (String) items.get(Utils.EXTRA_WS), (String) items.get(Utils.EXTRA_ARCH), null);

Check warning on line 234 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
sourceFeature.addEntry(entry);

Check warning on line 235 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
} else if (extraEntries[i].startsWith("exclude@")) { //$NON-NLS-1$
if (excludedEntries == null)
excludedEntries = new HashMap<>();
Expand All @@ -244,70 +248,70 @@
}
}

private void generateSourceFragments(BuildTimeFeature sourceFeature, FeatureEntry sourcePlugin) throws CoreException {

Check warning on line 251 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
Map<String, Set<BundleDescription>> fragments = director.sourceToGather.getElementEntries();
for (Config configInfo : AbstractScriptGenerator.getConfigInfos()) {
if (configInfo.equals(Config.genericConfig()))
continue;
String sourceFragmentId = sourceFeature.getId() + "." + configInfo.toString("."); //$NON-NLS-1$ //$NON-NLS-2$

Check warning on line 256 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
Set<BundleDescription> fragmentEntries = fragments.get(sourceFragmentId);
if (fragmentEntries == null || fragmentEntries.size() == 0)
continue;
FeatureEntry sourceFragment = new FeatureEntry(sourceFragmentId, sourceFeature.getVersion(), true);

Check warning on line 260 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
sourceFragment.setEnvironment(configInfo.getOs(), configInfo.getWs(), configInfo.getArch(), null);

Check warning on line 261 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
sourceFragment.setFragment(true);

Check warning on line 262 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
//sourceFeature.addPluginEntryModel(sourceFragment);
create30SourceFragment(sourceFragment, sourcePlugin);

sourceFeature.addEntry(sourceFragment);

Check warning on line 266 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}
}

private String computeSourceFeatureName(Feature featureForName, boolean withNumber) throws CoreException {

Check warning on line 270 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String sourceFeatureName = getBuildProperties().getProperty(PROPERTY_SOURCE_FEATURE_NAME);
if (sourceFeatureName == null)
sourceFeatureName = sourceFeatureId;
if (sourceFeatureName == null)
sourceFeatureName = featureForName.getId() + ".source"; //$NON-NLS-1$

Check warning on line 275 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
return sourceFeatureName + (withNumber ? "_" + featureForName.getVersion() : ""); //$NON-NLS-1$ //$NON-NLS-2$

Check warning on line 276 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}

// Create a feature object representing a source feature based on the featureExample
private BuildTimeFeature createSourceFeature(Feature featureExample) throws CoreException {

Check warning on line 280 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String id = computeSourceFeatureName(featureExample, false);
String version = featureExample.getVersion();

Check warning on line 282 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
BuildTimeFeature result = new BuildTimeFeature(id, version);

result.setLabel(featureExample.getLabel());

Check warning on line 285 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setProviderName(featureExample.getProviderName());

Check warning on line 286 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setImage(featureExample.getImage());

Check warning on line 287 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setInstallHandler(featureExample.getInstallHandler());

Check warning on line 288 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setInstallHandlerLibrary(featureExample.getInstallHandlerLibrary());

Check warning on line 289 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setInstallHandlerURL(featureExample.getInstallHandlerURL());

Check warning on line 290 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setDescription(featureExample.getDescription());

Check warning on line 291 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setDescriptionURL(featureExample.getDescriptionURL());

Check warning on line 292 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setCopyright(featureExample.getCopyright());

Check warning on line 293 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setCopyrightURL(featureExample.getCopyrightURL());

Check warning on line 294 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setLicense(featureExample.getLicense());

Check warning on line 295 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setLicenseURL(featureExample.getLicenseURL());

Check warning on line 296 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setLicenseFeature(featureExample.getLicenseFeature());

Check warning on line 297 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setLicenseFeatureVersion(featureExample.getLicenseFeatureVersion());

Check warning on line 298 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setUpdateSiteLabel(featureExample.getUpdateSiteLabel());

Check warning on line 299 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.setUpdateSiteURL(featureExample.getUpdateSiteURL());

Check warning on line 300 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:

URLEntry[] siteEntries = featureExample.getDiscoverySites();

Check warning on line 302 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
for (URLEntry siteEntry : siteEntries) {

Check warning on line 303 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
result.addDiscoverySite(siteEntry.getAnnotation(), siteEntry.getURL());

Check warning on line 304 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
}

result.setEnvironment(featureExample.getOS(), featureExample.getWS(), featureExample.getArch(), null);

Check warning on line 307 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:

int contextLength = featureExample instanceof BuildTimeFeature ? ((BuildTimeFeature) featureExample).getContextQualifierLength() : -1;
result.setContextQualifierLength(contextLength);
return result;
}

private void create30SourceFragment(FeatureEntry fragment, FeatureEntry plugin) throws CoreException {

Check warning on line 314 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
// create the directory for the plugin
IPath sourceFragmentDirURL = IPath.fromOSString(getWorkingDirectory() + '/' + DEFAULT_PLUGIN_LOCATION + '/' + getSourcePluginName(fragment, true));
File sourceFragmentDir = new File(sourceFragmentDirURL.toOSString());
Expand All @@ -323,38 +327,41 @@
}

//Copy the fragment.xml
Path dest = new File(sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toOSString()).toPath();
Path dest = sourceFragmentDirURL.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR).toPath();
try (InputStream fragmentXML = BundleHelper.getDefault().getBundle().getEntry(TEMPLATE + "/30/fragment/fragment.xml").openStream()) { //$NON-NLS-1$
Files.copy(fragmentXML, dest, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e1) {
String message = NLS.bind(Messages.exception_readingFile, TEMPLATE + "/30/fragment/fragment.xml"); //$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, e1));
}

StringBuffer buffer = Utils.readFile(templateLocation.openStream());
StringBuilder buffer;
try (InputStream locationContent = templateLocation.openStream()) {
buffer = new StringBuilder(new String(locationContent.readAllBytes()));
}
//Set the Id of the fragment
int beginId = Utils.scan(buffer, 0, REPLACED_FRAGMENT_ID);
int beginId = buffer.indexOf(REPLACED_FRAGMENT_ID, 0);
buffer.replace(beginId, beginId + REPLACED_FRAGMENT_ID.length(), fragment.getId());

Check warning on line 344 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
// set the version number
beginId = Utils.scan(buffer, beginId, REPLACED_FRAGMENT_VERSION);
beginId = buffer.indexOf(REPLACED_FRAGMENT_VERSION, beginId);
buffer.replace(beginId, beginId + REPLACED_FRAGMENT_VERSION.length(), fragment.getVersion());

Check warning on line 347 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
// Set the Id of the plugin for the fragment
beginId = Utils.scan(buffer, beginId, REPLACED_PLUGIN_ID);
beginId = buffer.indexOf(REPLACED_PLUGIN_ID, beginId);
buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), plugin.getId());

Check warning on line 350 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
// set the version number of the plugin to which the fragment is attached to
BundleDescription effectivePlugin = getSite().getRegistry().getResolvedBundle(plugin.getId(), plugin.getVersion());

Check warning on line 352 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
beginId = Utils.scan(buffer, beginId, REPLACED_PLUGIN_VERSION);
beginId = buffer.indexOf(REPLACED_PLUGIN_VERSION, beginId);
buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), effectivePlugin.getVersion().toString());
// Set the platform filter of the fragment
beginId = Utils.scan(buffer, beginId, REPLACED_PLATFORM_FILTER);
beginId = buffer.indexOf(REPLACED_PLATFORM_FILTER, beginId);
buffer.replace(beginId, beginId + REPLACED_PLATFORM_FILTER.length(), "(& (osgi.ws=" + fragment.getWS() + ") (osgi.os=" + fragment.getOS() + ") (osgi.arch=" + fragment.getArch() + "))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$

Check warning on line 357 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
Path destManifest = sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toPath();
Files.writeString(destManifest, buffer.toString());
Collection<String> copiedFiles = Utils.copyFiles(featureRootLocation + '/' + "sourceTemplateFragment", sourceFragmentDir.getAbsolutePath()); //$NON-NLS-1$
if (copiedFiles.contains(Constants.BUNDLE_FILENAME_DESCRIPTOR)) {
//make sure the manifest.mf has the versions we want
replaceManifestValue(sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString(), org.osgi.framework.Constants.BUNDLE_VERSION, fragment.getVersion());

Check warning on line 363 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
String host = plugin.getId() + ';' + org.osgi.framework.Constants.BUNDLE_VERSION + '=' + effectivePlugin.getVersion().toString();

Check warning on line 364 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
replaceManifestValue(sourceFragmentDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString(), org.osgi.framework.Constants.FRAGMENT_HOST, host);
}
File buildProperty = sourceFragmentDirURL.append(PROPERTIES_FILE).toFile();
Expand All @@ -377,7 +384,7 @@
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_WRITING_FILE, message, null));
}
PDEState state = getSite().getRegistry();
BundleDescription oldBundle = state.getResolvedBundle(fragment.getId());

Check warning on line 387 in build/org.eclipse.pde.build/src/org/eclipse/pde/internal/build/builder/SourceGenerator.java

View check run for this annotation

Jenkins - eclipse-pde / Java Compiler

tycho-compiler:compile

NORMAL:
if (oldBundle != null)
state.getState().removeBundle(oldBundle);
state.addBundle(sourceFragmentDir);
Expand Down Expand Up @@ -418,31 +425,33 @@
}

private void replaceXMLAttribute(String location, String tag, String attr, String newValue) {
File featureFile = new File(location);
if (!featureFile.exists())
Path featureFile = Path.of(location);
if (!Files.isRegularFile(featureFile)) {
return;

StringBuffer buffer = null;
}
Charset fileCharset;
StringBuilder buffer = null;
try {
buffer = Utils.readFile(featureFile);
} catch (IOException e) {
fileCharset = getFileEncoding(featureFile);
buffer = new StringBuilder(Files.readString(featureFile, fileCharset));
} catch (IOException | XMLStreamException e) {
return;
}

int startComment = Utils.scan(buffer, 0, COMMENT_START_TAG);
int endComment = startComment > -1 ? Utils.scan(buffer, startComment, COMMENT_END_TAG) : -1;
int startTag = Utils.scan(buffer, 0, tag);
int startComment = buffer.indexOf(COMMENT_START_TAG, 0);
int endComment = startComment > -1 ? buffer.indexOf(COMMENT_END_TAG, startComment) : -1;
int startTag = buffer.indexOf(tag, 0);
while (startComment != -1 && startTag > startComment && startTag < endComment) {
startTag = Utils.scan(buffer, endComment, tag);
startComment = Utils.scan(buffer, endComment, COMMENT_START_TAG);
endComment = startComment > -1 ? Utils.scan(buffer, startComment, COMMENT_END_TAG) : -1;
startTag = buffer.indexOf(tag, endComment);
startComment = buffer.indexOf(COMMENT_START_TAG, endComment);
endComment = startComment > -1 ? buffer.indexOf(COMMENT_END_TAG, startComment) : -1;
}
if (startTag == -1)
return;
int endTag = Utils.scan(buffer, startTag, ">"); //$NON-NLS-1$
int endTag = buffer.indexOf(">", startTag); //$NON-NLS-1$
boolean attrFound = false;
while (!attrFound) {
int startAttributeWord = Utils.scan(buffer, startTag, attr);
int startAttributeWord = buffer.indexOf(attr, startTag);
if (startAttributeWord == -1 || startAttributeWord > endTag)
return;
if (!Character.isWhitespace(buffer.charAt(startAttributeWord - 1))) {
Expand All @@ -463,20 +472,29 @@
continue;
}

int startVersionId = Utils.scan(buffer, startAttributeWord + 1, "\""); //$NON-NLS-1$
int endVersionId = Utils.scan(buffer, startVersionId + 1, "\""); //$NON-NLS-1$
int startVersionId = buffer.indexOf("\"", startAttributeWord + 1); //$NON-NLS-1$
int endVersionId = buffer.indexOf("\"", startVersionId + 1); //$NON-NLS-1$
buffer.replace(startVersionId + 1, endVersionId, newValue);
attrFound = true;
}
if (attrFound) {
try {
Files.writeString(featureFile.toPath(), buffer.toString());
Files.writeString(featureFile, buffer.toString(), fileCharset);
} catch (IOException e) {
//ignore
}
}
}

private static Charset getFileEncoding(Path file) throws IOException, XMLStreamException {
try (InputStream is = Files.newInputStream(file)) {
XMLInputFactory factory = XMLInputFactory.newFactory();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
HannesWell marked this conversation as resolved.
Show resolved Hide resolved
String encoding = factory.createXMLStreamReader(is).getEncoding();
return Charset.forName(encoding);
}
}

private FeatureEntry createSourceBundle(BuildTimeFeature sourceFeature, FeatureEntry pluginEntry) throws CoreException {
BundleDescription bundle = getSite().getRegistry().getBundle(pluginEntry.getId(), pluginEntry.getVersion(), true);
if (bundle == null) {
Expand Down Expand Up @@ -672,28 +690,28 @@
new File(sourcePluginDir, "META-INF").mkdirs(); //$NON-NLS-1$

// Create the MANIFEST.MF
StringBuffer buffer;
StringBuilder buffer;
IPath templateManifest = IPath.fromOSString(TEMPLATE + "/30/plugin/" + Constants.BUNDLE_FILENAME_DESCRIPTOR); //$NON-NLS-1$
URL templateManifestURL = BundleHelper.getDefault().find(templateManifest);
if (templateManifestURL == null) {
IStatus status = new Status(IStatus.WARNING, PI_PDEBUILD, IPDEBuildConstants.EXCEPTION_READING_FILE, NLS.bind(Messages.error_readingDirectory, templateManifest), null);
BundleHelper.getDefault().getLog().log(status);
return null;
}
try {
buffer = Utils.readFile(templateManifestURL.openStream());
try (InputStream manifestStream = templateManifestURL.openStream()) {
buffer = new StringBuilder(new String(manifestStream.readAllBytes()));
} catch (IOException e1) {
String message = NLS.bind(Messages.exception_readingFile, templateManifestURL.toExternalForm());
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1));
}
int beginId = Utils.scan(buffer, 0, REPLACED_PLUGIN_ID);
int beginId = buffer.indexOf(REPLACED_PLUGIN_ID, 0);
buffer.replace(beginId, beginId + REPLACED_PLUGIN_ID.length(), result.getId());
//set the version number
beginId = Utils.scan(buffer, beginId, REPLACED_PLUGIN_VERSION);
beginId = buffer.indexOf(REPLACED_PLUGIN_VERSION, beginId);
buffer.replace(beginId, beginId + REPLACED_PLUGIN_VERSION.length(), result.getVersion());
String destName = sourcePluginDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toOSString();
Path destName = sourcePluginDirURL.append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toPath();
try {
Files.writeString(new File(destName).toPath(), buffer.toString());
Files.writeString(destName, buffer.toString());
} catch (IOException e1) {
String message = NLS.bind(Messages.exception_writingFile, templateManifestURL.toExternalForm());
throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_READING_FILE, message, e1));
Expand Down
Loading