Skip to content
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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2017 IBM Corporation and others.
* Copyright (c) 2000, 2017, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -19,6 +19,7 @@
import java.util.Map;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jface.text.BadLocationException;
Expand Down Expand Up @@ -61,6 +62,15 @@ private String getHeaderName(String line) {
return null;
}

private boolean isInvalidHeader(String line) {
int colonInd = line.indexOf(':');
if (colonInd > 0) {
String headerPart = line.substring(0, colonInd);
return headerPart.matches(".*[^a-zA-Z0-9-_].*"); //$NON-NLS-1$
}
return false;
}

protected int getPackageLine(IHeader header, ManifestElement element) {
String packageName = element.getValue();
if (element.getDirectiveKeys() != null || element.getKeys() != null) {
Expand Down Expand Up @@ -174,7 +184,15 @@ protected void parseManifest(IDocument document, IProgressMonitor monitor) {
}
String headerName = getHeaderName(line);
if (headerName == null) {
report(PDECoreMessages.BundleErrorReporter_invalidHeaderName, lineNumber, CompilerFlags.ERROR, PDEMarkerFactory.CAT_FATAL);
boolean hasInvalidChars = isInvalidHeader(line);
if (hasInvalidChars) {
VirtualMarker marker = report(PDECoreMessages.BundleErrorReporter_invalidHeaderName, lineNumber,
CompilerFlags.ERROR, PDEMarkerFactory.M_HEADER_INCORRECT, PDEMarkerFactory.CAT_FATAL);
marker.setAttribute(IMarker.LINE_NUMBER, lineNumber);
return;
}
report(PDECoreMessages.BundleErrorReporter_invalidHeaderName, lineNumber, CompilerFlags.ERROR,
PDEMarkerFactory.CAT_FATAL);
return;
}
if (line.length() < colon + 2 || line.charAt(colon + 1) != ' ') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class PDEMarkerFactory {
public static final int M_ONLY_CONFIG_SEV = 0x1027; // other problem
public static final int M_NO_AUTOMATIC_MODULE = 0x1028; // other problem
public static final int M_EXEC_ENV_TOO_LOW = 0x1029; // other problem
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other
// problem
public static final int M_CONFLICTING_AUTOMATIC_MODULE = 0x1030; // other problem
public static final int M_HEADER_INCORRECT = 0x1031; // other problem
public static final int M_SINGLETON_DIR_CHANGE = 0x1033; // other problem

// build properties fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ public class PDEUIMessages extends NLS {

public static String UpdateClasspathResolution_label;
public static String UpdateExecutionEnvironment_label;
public static String RemoveInvalidCharacters;

//
// PDE resource strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ public IMarkerResolution[] getNonConfigSevResolutions(IMarker marker) {
case PDEMarkerFactory.M_CONFLICTING_AUTOMATIC_MODULE:
return new IMarkerResolution[] {
new RemoveRedundantAutomaticModuleHeader(AbstractPDEMarkerResolution.REMOVE_TYPE, marker) };
case PDEMarkerFactory.M_HEADER_INCORRECT:
return new IMarkerResolution[] {
new UpdateCorrectHeaderName(AbstractPDEMarkerResolution.RENAME_TYPE, marker) };
}
return NO_RESOLUTIONS;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (c) 2025 IBM Corporation 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:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.pde.internal.ui.correction;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.eclipse.core.resources.IMarker;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.pde.internal.core.text.bundle.BundleModel;
import org.eclipse.pde.internal.ui.PDEUIMessages;

/**
* Resolution to remove invalid characters from header in MANIFEST. Remove all
* the invalid characters (characters other than alpha numeric characters, '-'
* and '_') Also adding a space after 'Require-Bundle' header(before the colon)
* when not present.
*/
public class UpdateCorrectHeaderName extends AbstractManifestMarkerResolution {

private static final Logger logger = Logger.getLogger(UpdateCorrectHeaderName.class.getName());

public UpdateCorrectHeaderName(int type, IMarker marker) {
super(type, marker);
}

@Override
public String getLabel() {
return PDEUIMessages.RemoveInvalidCharacters;
}

private String removeInvalidChars(String userHeader) {
return userHeader.replaceAll("[^a-zA-Z0-9-_]", ""); //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
protected void createChange(BundleModel model) {
model.getBundle();
IDocument doc = model.getDocument();
try {
int lineNum = marker.getAttribute(IMarker.LINE_NUMBER, -1);
IRegion lineInfo = doc.getLineInformation(lineNum - 1);
int offset = lineInfo.getOffset();
int length = lineInfo.getLength();

String getLine = doc.get(offset, length);
int colonInd = getLine.indexOf(':');

if (colonInd > 0) {
String userHeader = getLine.substring(0, colonInd);
String correctHeader = removeInvalidChars(userHeader);
doc.replace(offset, colonInd, correctHeader);
}

} catch (BadLocationException e) {
logger.log(Level.SEVERE,
"Failed to apply UpdateCorrectHeaderName quick fix, unexpected location in the doc", //$NON-NLS-1$
e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,7 @@ LocationSection_0=&Locations
AppendSeperatorBuildEntryResolution_label=Append a trailing separator to {0}.
AddExportPackageResolution_Label=Add missing packages
AddExportPackageInternalDirectiveResolution_Label=Add missing packages with x-internal directive
RemoveInvalidCharacters=Remove invalid characters from header

DependencyManagementSection_jobName=Analyzing Code
DescriptionSection_nameLabel=Name:
Expand Down
Loading