Skip to content

Commit

Permalink
Changes to support lucene 10.0.0
Browse files Browse the repository at this point in the history
- Update the target platform to use 4.35-I-builds and 2025-03 orbit.
- Because there is API breakage, require minimally lucene 10.
- Jenkinsfile must build with Java 21.
- Specialize TaskDataExternalizer.writeState to handle the failure to
serialize \u001 - \u001f as XML 1.0 so that it will use XML 1.1 when
necessary.
  • Loading branch information
merks authored and ruspl-afed committed Dec 23, 2024
1 parent e56a84c commit 83f856a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pipeline {
}
tools {
maven 'apache-maven-latest'
jdk 'openjdk-jdk17-latest'
jdk 'openjdk-jdk21-latest'
}
parameters {
choice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.eclipse.mylyn.internal.tasks.core.data;

import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.FilterInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -193,19 +194,34 @@ public TaskDataState readState(InputStream in) throws IOException, SAXException
}

public void writeState(OutputStream out, ITaskDataWorkingCopy state) throws IOException {
writeState(out, state, false);
}

private void writeState(OutputStream out, ITaskDataWorkingCopy state, boolean xml11) throws IOException {
try {
SAXTransformerFactory transformerFactory = (SAXTransformerFactory) TransformerFactory.newInstance();
TransformerHandler handler = transformerFactory.newTransformerHandler();
Transformer serializer = handler.getTransformer();
if (xml11) {
serializer.setOutputProperty(OutputKeys.VERSION, "1.1"); //$NON-NLS-1$
}
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
serializer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
handler.setResult(new StreamResult(out));
ByteArrayOutputStream temp = new ByteArrayOutputStream();
handler.setResult(new StreamResult(temp));
TaskDataStateWriter writer = new TaskDataStateWriter(handler);
writer.write(state);
out.write(temp.toByteArray());
} catch (TransformerException e) {
throw new IOException("Error writing task data" + e.getMessageAndLocation()); //$NON-NLS-1$
} catch (SAXException e) {
throw new IOException("Error writing task data" + e.getMessage()); //$NON-NLS-1$
// This condition is just like the one in org.eclipse.mylyn.internal.tasks.core.data.TaskDataStore.readState(File)
if (!xml11 && e.getMessage() != null && (e.getMessage().contains("invalid XML character") //$NON-NLS-1$
|| e.getMessage().contains(" \"&#"))) { //$NON-NLS-1$
writeState(out, state, true);
} else {
throw new IOException("Error writing task data" + e.getMessage()); //$NON-NLS-1$
}
}
}

Expand Down
20 changes: 10 additions & 10 deletions mylyn.tasks/org.eclipse.mylyn.tasks.index.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0",
Bundle-RequiredExecutionEnvironment: JavaSE-17
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.mylyn.internal.tasks.index.core;x-internal:=true
Import-Package: org.apache.lucene.analysis;version="9.10.0",
org.apache.lucene.analysis.core;version="9.10.0",
org.apache.lucene.analysis.miscellaneous;version="9.10.0",
org.apache.lucene.analysis.standard;version="9.10.0",
org.apache.lucene.document;version="9.10.0",
org.apache.lucene.index;version="9.10.0",
org.apache.lucene.queryparser.classic;version="9.10.0",
org.apache.lucene.search;version="9.10.0",
org.apache.lucene.store;version="9.10.0",
org.apache.lucene.util;version="9.10.0"
Import-Package: org.apache.lucene.analysis;version="10.0.0",
org.apache.lucene.analysis.core;version="10.0.0",
org.apache.lucene.analysis.miscellaneous;version="10.0.0",
org.apache.lucene.analysis.standard;version="10.0.0",
org.apache.lucene.document;version="10.0.0",
org.apache.lucene.index;version="10.0.0",
org.apache.lucene.queryparser.classic;version="10.0.0",
org.apache.lucene.search;version="10.0.0",
org.apache.lucene.store;version="10.0.0",
org.apache.lucene.util;version="10.0.0"

Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public boolean matches(ITask task, String patternString) {
Query query = computeQuery(patternString);
TopDocs results = indexSearcher.search(query, maxMatchSearchHits);
for (ScoreDoc scoreDoc : results.scoreDocs) {
Document document = indexReader.document(scoreDoc.doc);
Document document = indexReader.storedFields().document(scoreDoc.doc);
hits.add(document.get(FIELD_IDENTIFIER.getIndexKey()));
}
} catch (IOException e) {
Expand Down Expand Up @@ -671,7 +671,7 @@ public void find(String patternString, TaskCollector collector, int resultsLimit
Query query = computeQuery(patternString);
TopDocs results = indexSearcher.search(query, resultsLimit);
for (ScoreDoc scoreDoc : results.scoreDocs) {
Document document = indexReader.document(scoreDoc.doc);
Document document = indexReader.storedFields().document(scoreDoc.doc);
String taskIdentifier = document.get(FIELD_IDENTIFIER.getIndexKey());
AbstractTask task = taskList.getTask(taskIdentifier);
if (task != null) {
Expand Down Expand Up @@ -714,12 +714,12 @@ private Query computeQuery(String patternString) {

BooleanQuery query = (BooleanQuery) q;
for (BooleanClause clause : query.clauses()) {
if (clause.getQuery() instanceof TermQuery) {
TermQuery termQuery = (TermQuery) clause.getQuery();
if (clause.query() instanceof TermQuery) {
TermQuery termQuery = (TermQuery) clause.query();
clause = new BooleanClause(new PrefixQuery(termQuery.getTerm()),
computeOccur(clause, hasBooleanSpecifiers));
} else if (!hasBooleanSpecifiers) {
clause = new BooleanClause(clause.getQuery(), Occur.MUST);
clause = new BooleanClause(clause.query(), Occur.MUST);
}
qb.add(clause);
}
Expand All @@ -734,7 +734,7 @@ private Occur computeOccur(BooleanClause clause, boolean hasBooleanSpecifiers) {
if (!hasBooleanSpecifiers) {
return Occur.MUST;
}
return clause.getOccur();
return clause.occur();
}

private boolean containsSpecialCharacters(String patternString) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="0.0.0",
Export-Package: org.eclipse.mylyn.internal.tasks.index.tests;x-internal:=true,
org.eclipse.mylyn.internal.tasks.index.tests.ui;x-internal:=true,
org.eclipse.mylyn.internal.tasks.index.tests.util;x-internal:=true
Import-Package: org.apache.lucene.store;version="9.5.0"
Import-Package: org.apache.lucene.store;version="10.0.0"

Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ public void testReadWrite() throws Exception {
assertEquals(state.getRepositoryData().getRoot().toString(), state2.getRepositoryData().getRoot().toString());
}

public void testReadWriteInvalidCharacters() throws Exception {
public void testReadWriteInvalidCharactersXML11() throws Exception {
TaskData data = new TaskData(new TaskAttributeMapper(repository), repository.getConnectorKind(),
repository.getRepositoryUrl(), "1");
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F");
data.getRoot().createAttribute("attribute").setValue("\u0000");

TaskDataState state = new TaskDataState(repository.getConnectorKind(), repository.getRepositoryUrl(), "1");
state.setRepositoryData(data);
Expand All @@ -93,6 +93,19 @@ public void testReadWriteInvalidCharacters() throws Exception {
fail("Expected SAXParseException");
} catch (SAXParseException expected) {
}
}

public void testReadWriteInvalidCharactersXML10() throws Exception {
TaskData data = new TaskData(new TaskAttributeMapper(repository), repository.getConnectorKind(),
repository.getRepositoryUrl(), "1");
data.getRoot().createAttribute("attribute").setValue("\u0001\u001F");

TaskDataState state = new TaskDataState(repository.getConnectorKind(), repository.getRepositoryUrl(), "1");
state.setRepositoryData(data);

ByteArrayOutputStream out = new ByteArrayOutputStream();
externalizer.writeState(out, state);
externalizer.readState(new ByteArrayInputStream(out.toByteArray()));

TaskDataState state2 = externalizer
.readState(new Xml11InputStream(new ByteArrayInputStream(out.toByteArray())));
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.mylyn-target/org.eclipse.mylyn.target.target
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<unit id="org.eclipse.license.feature.group" version="0.0.0"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.34/R-4.34-202411201800/"/>
<repository location="https://download.eclipse.org/eclipse/updates/4.35-I-builds"/>
<unit id="org.eclipse.equinox.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.equinox.p2.sdk.feature.group" version="0.0.0"/>
<unit id="org.eclipse.sdk.feature.group" version="0.0.0"/>
Expand Down Expand Up @@ -73,7 +73,7 @@
<unit id="org.apache.commons.io" version="2.8.0.v20210415-0900"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2024-12/"/>
<repository location="https://download.eclipse.org/tools/orbit/simrel/orbit-aggregation/2025-03/"/>
<unit id="org.glassfish.hk2.osgi-resource-locator" version="0.0.0"/>
<unit id="org.apache.commons.lang3" version="0.0.0"/>
<unit id="org.apache.commons.logging" version="0.0.0"/>
Expand Down

0 comments on commit 83f856a

Please sign in to comment.