Skip to content
Open
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008-2011 Sonatype, Inc.
* Copyright (c) 2008-2025 Sonatype, Inc. and others
* All rights reserved. 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
Expand Down Expand Up @@ -27,13 +27,18 @@

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.jface.text.DocumentRewriteSession;
import org.eclipse.jface.text.DocumentRewriteSessionType;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension4;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.IExecutionDelegate;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.text.IExecutionDelegatable;
import org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
Expand Down Expand Up @@ -454,18 +459,35 @@
// that were not yet initialized. Then we could avoid saving a file that is actually opened, but was never used so far (after restart)
try {
DocumentRewriteSession session = null;
IStructuredTextUndoManager undo = null;

Check warning on line 462 in org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java

View check run for this annotation

Jenkins - M2E / Compiler

Deprecation

NORMAL: The type IStructuredTextUndoManager is deprecated
if(tuple.isReadOnly()) {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(tuple.getDocument());
if(domModel == null) {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(
(IStructuredDocument) tuple.getDocument());
if(domModel.getStructuredDocument() instanceof IExecutionDelegatable) {
((IExecutionDelegatable) domModel.getStructuredDocument())
.setExecutionDelegate(new ExecutionDelegate());
}
}
} else {
domModel = tuple.getModel() != null ? tuple.getModel()
: (tuple.getFile() != null ? (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(
tuple.getFile()) : (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForEdit(
tuple.getDocument())); //existing shall be ok here..
if(tuple.getModel() != null) {
domModel = tuple.getModel();
} else if(tuple.getFile() != null) {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile());
if(domModel.getStructuredDocument() instanceof IExecutionDelegatable) {
((IExecutionDelegatable) domModel.getStructuredDocument())
.setExecutionDelegate(new ExecutionDelegate());
}

} else {
domModel = (IDOMModel) StructuredModelManager.getModelManager()
.getExistingModelForEdit(tuple.getDocument());
if(domModel.getStructuredDocument() instanceof IExecutionDelegatable) {
((IExecutionDelegatable) domModel.getStructuredDocument())
.setExecutionDelegate(new ExecutionDelegate());
}
}

//let the model know we make changes
domModel.aboutToChangeModel();
Expand All @@ -474,7 +496,7 @@
if(domModel.getStructuredDocument() instanceof IDocumentExtension4 ext4) {
session = ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
}
undo.beginRecording(domModel);

Check warning on line 499 in org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java

View check run for this annotation

Jenkins - M2E / Compiler

Deprecation

NORMAL: The method beginRecording(Object) from the type IStructuredTextUndoManager is deprecated

// fill with minimal pom content
Document doc = domModel.getDocument();
Expand All @@ -499,12 +521,12 @@
}
}

if(domModel != null) {

Check warning on line 524 in org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java

View check run for this annotation

Jenkins - M2E / Compiler

Potential Programming Problem

NORMAL: Redundant null check: The variable domModel cannot be null at this location
try {
tuple.getOperation().process(domModel.getDocument());
} finally {
if(!tuple.isReadOnly()) {
undo.endRecording(domModel);

Check warning on line 529 in org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java

View check run for this annotation

Jenkins - M2E / Compiler

Potential Programming Problem

NORMAL: Potential null pointer access: The variable undo may be null at this location

Check warning on line 529 in org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/editing/PomEdits.java

View check run for this annotation

Jenkins - M2E / Compiler

Deprecation

NORMAL: The method endRecording(Object) from the type IStructuredTextUndoManager is deprecated
if(session != null && domModel.getStructuredDocument() instanceof IDocumentExtension4 ext4) {
ext4.stopRewriteSession(session);
}
Expand All @@ -514,6 +536,9 @@
}
} finally {
if(domModel != null) {
if(domModel.getStructuredDocument() instanceof IExecutionDelegatable) {
((IExecutionDelegatable) domModel.getStructuredDocument()).setExecutionDelegate(null);
}
if(tuple.isReadOnly()) {
domModel.releaseFromRead();
} else if(domModel.getId() != null) { // id will be null for files outside of workspace
Expand Down Expand Up @@ -665,6 +690,26 @@
}
}

/**
* Ensure that document operations and the resulting event notifications happen on the UI thread
*/
static class ExecutionDelegate implements IExecutionDelegate {
public ExecutionDelegate() {
}

@Override
public void execute(ISafeRunnable runnable) {
final Display display = Display.getDefault();
if(display.getThread() == Thread.currentThread()) {
SafeRunner.run(runnable);
} else {
display.syncExec(() -> {
SafeRunner.run(runnable);
});
}
}
}

/**
* an interface for identifying child elements that fulfill conditions expressed by the matcher.
*
Expand Down
Loading