Skip to content

Commit

Permalink
BndTools: fix warnings
Browse files Browse the repository at this point in the history
mostly 'Non-externalized string literal' warning
  • Loading branch information
EcljpseB0T committed Dec 5, 2023
1 parent eb34cab commit 4427467
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,29 @@

public abstract class BndTargetLocation extends AbstractBundleContainer
implements ITargetLocationHandler, ILabelProvider {
static final String PLUGIN_ID = "bndtools.pde";
static final String PLUGIN_ID = "bndtools.pde"; //$NON-NLS-1$

static final String MESSAGE_UNABLE_TO_LOCATE_WORKSPACE = "Unable to locate the Bnd workspace";
static final String MESSAGE_UNABLE_TO_RESOLVE_BUNDLES = "Unable to resolve bundles";
static final String MESSAGE_UNABLE_TO_LOCATE_WORKSPACE = "Unable to locate the Bnd workspace"; //$NON-NLS-1$
static final String MESSAGE_UNABLE_TO_RESOLVE_BUNDLES = "Unable to resolve bundles"; //$NON-NLS-1$

static final String ELEMENT_LOCATION = "location";
static final String ATTRIBUTE_LOCATION_TYPE = "type";
static final String ELEMENT_LOCATION = "location"; //$NON-NLS-1$
static final String ATTRIBUTE_LOCATION_TYPE = "type"; //$NON-NLS-1$

private final String type;
private final Image containerIcon;

public BndTargetLocation(String type, String containerIconName) {
this.type = Objects.requireNonNull(type);
this.containerIcon = PDEPluginImages.get("/icons/bndtools/" + containerIconName);
this.containerIcon = PDEPluginImages.get("/icons/bndtools/" + containerIconName); //$NON-NLS-1$
}

@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
if (adapter == ILabelProvider.class) {
return (T) this;

} else {
return super.getAdapter(adapter);
}
return super.getAdapter(adapter);
}


Expand Down Expand Up @@ -146,7 +144,7 @@ public String serialize() {
Transformer transformer = org.eclipse.core.internal.runtime.XmlProcessorFactory
.createTransformerFactoryWithErrorOnDOCTYPE()
.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
transformer.transform(new DOMSource(document), result);
return result.getWriter()
.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,19 @@ public ITargetLocation getTargetLocation(String type, String serializedXML) thro
if (this.type.equals(type)) {
Element locationElement;
try {
@SuppressWarnings("restriction")
DocumentBuilder docBuilder = org.eclipse.core.internal.runtime.XmlProcessorFactory
.createDocumentBuilderFactoryIgnoringDOCTYPE()
.newDocumentBuilder();
Document document = docBuilder.parse(new ByteArrayInputStream(serializedXML.getBytes("UTF-8")));
Document document = docBuilder.parse(new ByteArrayInputStream(serializedXML.getBytes("UTF-8"))); //$NON-NLS-1$
locationElement = document.getDocumentElement();

if (this.type.equals(locationElement.getAttribute(BndTargetLocation.ATTRIBUTE_LOCATION_TYPE))) {
return getTargetLocation(locationElement);
}
} catch (Exception e) {
ILog.get()
.error("Problem reading target location " + type);
.error("Problem reading target location " + type); //$NON-NLS-1$
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public abstract class BndTargetLocationPage extends WizardPage implements IEditBundleContainerPage {
private final String message;
private final ITargetDefinition targetDefinition;
private static final Image bundleIcon = PDEPluginImages.get("/icons/bndtools/bundle.png");
private static final Image bundleIcon = PDEPluginImages.get("/icons/bndtools/bundle.png"); //$NON-NLS-1$

public BndTargetLocationPage(String pageName, String title, String message, ITargetDefinition targetDefinition) {
super(pageName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.eclipse.pde.internal.ui.bndtools;

import org.eclipse.osgi.util.NLS;

public class BndToolsMessages extends NLS {
private static final String BUNDLE_NAME = BndToolsMessages.class.getPackageName() + ".messages"; //$NON-NLS-1$
public static String RepositoryTargetLocationPage_AddBndRepository;
public static String RepositoryTargetLocationPage_AddBndRepositoryContainer;
public static String RepositoryTargetLocationPage_Contents;
public static String RepositoryTargetLocationPage_Location;
public static String RepositoryTargetLocationPage_Repository;
public static String RepositoryTargetLocationPage_ToBeAdded;
public static String RepositoryTargetLocationWizard_BndRepositoryTargetLocation;
public static String RunDescriptorTargetLocationPage_AddBndRunDescriptor;
public static String RunDescriptorTargetLocationPage_AddBndRunDescriptorContainer;
public static String RunDescriptorTargetLocationPage_RunBundles;
public static String RunDescriptorTargetLocationPage_RunDescriptor;
public static String RunDescriptorTargetLocationPage_Select;
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, BndToolsMessages.class);
}

private BndToolsMessages() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@
import aQute.bnd.version.Version;

public class RepositoryTargetLocation extends BndTargetLocation {
static final String TYPE = "BndRepositoryLocation";
static final String TYPE = "BndRepositoryLocation"; //$NON-NLS-1$

static final String MESSAGE_UNABLE_TO_RESOLVE_REPOSITORIES = "Unable to resolve Bnd repository plugins";
static final String MESSAGE_UNABLE_TO_RESOLVE_REPOSITORIES = "Unable to resolve Bnd repository plugins"; //$NON-NLS-1$

static final String ELEMENT_REPOSITORY = "repository";
static final String ATTRIBUTE_REPOSITORY_NAME = "name";
static final String ELEMENT_REPOSITORY = "repository"; //$NON-NLS-1$
static final String ATTRIBUTE_REPOSITORY_NAME = "name"; //$NON-NLS-1$

private String repositoryName;
private RepositoryPlugin repository;

public RepositoryTargetLocation() {
super(TYPE, "database.png");
super(TYPE, "database.png"); //$NON-NLS-1$
}

public RepositoryTargetLocation setRepository(String repositoryName) {
Expand Down Expand Up @@ -95,12 +95,12 @@ protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressM
try {
List<TargetBundle> bundles = new ArrayList<>();

List<String> bsns = repository.list("*");
monitor.beginTask("Resolving Bundles", bsns.size());
List<String> bsns = repository.list("*"); //$NON-NLS-1$
monitor.beginTask("Resolving Bundles", bsns.size()); //$NON-NLS-1$

int i = 0;
for (String bsn : bsns) {
if (bsn.contains(":")) {
if (bsn.contains(":")) { //$NON-NLS-1$
continue;
}
Version version = repository.versions(bsn)
Expand All @@ -111,7 +111,7 @@ protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressM
bundles.add(new TargetBundle(download));
} catch (Exception e) {
throw new CoreException(new Status(IStatus.WARNING, PLUGIN_ID,
"Invalid plugin in repository: " + bsn + " @ " + getLocation(false), e));
"Invalid plugin in repository: " + bsn + " @ " + getLocation(false), e)); //$NON-NLS-1$ //$NON-NLS-2$
}

if (monitor.isCanceled())
Expand Down Expand Up @@ -152,14 +152,14 @@ private void resolveRepository() throws CoreException {

if (this.repository == null)
throw new CoreException(
new Status(IStatus.ERROR, PLUGIN_ID, "Unable to locate the named repository: " + repositoryName));
new Status(IStatus.ERROR, PLUGIN_ID, "Unable to locate the named repository: " + repositoryName)); //$NON-NLS-1$
}

@Override
public String getLocation(boolean resolve) throws CoreException {
if (resolve)
resolveRepository();
return repository != null ? repository.getLocation() : "";
return repository != null ? repository.getLocation() : ""; //$NON-NLS-1$
}

@Override
Expand Down Expand Up @@ -188,7 +188,7 @@ public ITargetLocation getTargetLocation(Element locationElement) throws CoreExc
}
}

throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No repository name specified"));
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No repository name specified")); //$NON-NLS-1$
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import aQute.bnd.service.ResolutionPhase;

public class RepositoryTargetLocationPage extends BndTargetLocationPage {
private static final String CACHE_REPOSITORY = "cache";
private static final String CACHE_REPOSITORY = "cache"; //$NON-NLS-1$

private RepositoryTargetLocation targetLocation;

Expand All @@ -49,7 +49,7 @@ public class RepositoryTargetLocationPage extends BndTargetLocationPage {
private Text pluginLocationText;

public RepositoryTargetLocationPage(ITargetDefinition targetDefinition, RepositoryTargetLocation targetLocation) {
super("AddBndRepositoryContainer", "Add Bnd Repository", "Select a Bnd repository to be added to your target",
super(BndToolsMessages.RepositoryTargetLocationPage_AddBndRepositoryContainer, BndToolsMessages.RepositoryTargetLocationPage_AddBndRepository, BndToolsMessages.RepositoryTargetLocationPage_ToBeAdded,
targetDefinition);

if (targetLocation != null) {
Expand Down Expand Up @@ -88,15 +88,15 @@ public RepositoryTargetLocationPage(ITargetDefinition targetDefinition, Reposito
}

private String getLocation() {
return repository != null ? repository.getLocation() : "";
return repository != null ? repository.getLocation() : ""; //$NON-NLS-1$
}

@Override
public void createControl(Composite parent) {
Composite composite = SWTFactory.createComposite(parent, 2, 1, GridData.FILL_BOTH, 0, 0);

Combo pluginsCombo = createRepositoryComboArea(composite);
SWTFactory.createLabel(composite, "Contents: ", 2);
SWTFactory.createLabel(composite, BndToolsMessages.RepositoryTargetLocationPage_Contents, 2);
bundleList = createBundleListArea(composite, 2);

updateTarget();
Expand Down Expand Up @@ -127,10 +127,10 @@ protected Combo createRepositoryComboArea(Composite composite) {
names[i++] = plugin.getName();
}

SWTFactory.createLabel(composite, "Repository: ", 1);
SWTFactory.createLabel(composite, BndToolsMessages.RepositoryTargetLocationPage_Repository, 1);
final Combo pluginsCombo = SWTFactory.createCombo(composite, SWT.READ_ONLY, 1, GridData.FILL_HORIZONTAL, names);

SWTFactory.createLabel(composite, "Location: ", 1);
SWTFactory.createLabel(composite, BndToolsMessages.RepositoryTargetLocationPage_Location, 1);
pluginLocationText = SWTFactory.createText(composite, SWT.READ_ONLY, 1, GridData.FILL_HORIZONTAL);
pluginLocationText.setText(getLocation());

Expand Down Expand Up @@ -162,7 +162,7 @@ protected void updateTarget() {
pluginLocationText.setText(getLocation());
setPageComplete(true);
} catch (Exception e) {
logError("Unable to list bundles for repository: " + repository.getName(), e);
logError("Unable to list bundles for repository: " + repository.getName(), e); //$NON-NLS-1$
clearTarget();
}
}
Expand All @@ -176,12 +176,12 @@ private void clearTarget() {
protected Collection<?> getBundles() throws Exception {
List<String> bundles = new ArrayList<>();
if (repository != null) {
for (String bsn : repository.list("*")) {
bundles.add(bsn + " - " + repository.versions(bsn)
for (String bsn : repository.list("*")) { //$NON-NLS-1$
bundles.add(bsn + " - " + repository.versions(bsn) //$NON-NLS-1$
.last());
}
if (bundles.isEmpty())
logWarning("Repository is empty: " + repository.getName(), null);
logWarning("Repository is empty: " + repository.getName(), null); //$NON-NLS-1$
else
resetMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RepositoryTargetLocationWizard extends Wizard implements ITargetLoc
private RepositoryTargetLocationPage targetLocationPage;

public RepositoryTargetLocationWizard() {
setWindowTitle("Bnd Repository Target Location");
setWindowTitle(BndToolsMessages.RepositoryTargetLocationWizard_BndRepositoryTargetLocation);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
import biz.aQute.resolve.Bndrun;

public class RunDescriptorTargetLocation extends BndTargetLocation {
static final String TYPE = "BndRunDescriptorLocation";
static final String TYPE = "BndRunDescriptorLocation"; //$NON-NLS-1$

static final String ELEMENT_RUN_DESCRIPTOR = "bndrun";
static final String ATTRIBUTE_RUN_DESCRIPTOR_FILE = "file";
static final String ELEMENT_RUN_DESCRIPTOR = "bndrun"; //$NON-NLS-1$
static final String ATTRIBUTE_RUN_DESCRIPTOR_FILE = "file"; //$NON-NLS-1$

private String bndrunFileName;
private IFile bndrunFile;

public RunDescriptorTargetLocation() {
super(TYPE, "bndrun.gif");
super(TYPE, "bndrun.gif"); //$NON-NLS-1$
}

public RunDescriptorTargetLocation setRunDescriptor(IFile bndrunFile) {
Expand Down Expand Up @@ -106,15 +106,15 @@ protected TargetBundle[] resolveBundles(ITargetDefinition definition, IProgressM
Collection<Container> containers = bndRun.getRunbundles();
List<TargetBundle> bundles = new ArrayList<>(containers.size());

monitor.beginTask("Resolving Bundles", containers.size());
monitor.beginTask("Resolving Bundles", containers.size()); //$NON-NLS-1$

int i = 0;
for (Container container : containers) {
try {
bundles.add(new TargetBundle(container.getFile()));
} catch (Exception e) {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "Invalid plugin in run descriptor: "
+ container.getBundleSymbolicName() + " @ " + getLocation(false), e));
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "Invalid plugin in run descriptor: " //$NON-NLS-1$
+ container.getBundleSymbolicName() + " @ " + getLocation(false), e)); //$NON-NLS-1$
}

if (monitor.isCanceled())
Expand All @@ -141,7 +141,7 @@ private void resolveBndrunFile() throws CoreException {
if (resource instanceof IFile) {
bndrunFile = (IFile) resource;
} else {
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No file at path: " + bndrunFileName));
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No file at path: " + bndrunFileName)); //$NON-NLS-1$
}
}

Expand Down Expand Up @@ -176,7 +176,7 @@ public ITargetLocation getTargetLocation(Element locationElement) throws CoreExc
}
}

throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No run descriptor file specified"));
throw new CoreException(new Status(IStatus.ERROR, PLUGIN_ID, "No run descriptor file specified")); //$NON-NLS-1$
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import biz.aQute.resolve.Bndrun;

public class RunDescriptorTargetLocationPage extends BndTargetLocationPage {
private static final String FILE_EXTENSION = "bndrun";
private static final String FILE_EXTENSION = "bndrun"; //$NON-NLS-1$

private RunDescriptorTargetLocation targetLocation;

Expand All @@ -51,8 +51,8 @@ public class RunDescriptorTargetLocationPage extends BndTargetLocationPage {

public RunDescriptorTargetLocationPage(ITargetDefinition targetDefinition,
RunDescriptorTargetLocation targetLocation) {
super("AddBndRunDescriptorContainer", "Add Bnd Run Descriptor",
"Select a Bnd run descriptor to be added to your target", targetDefinition);
super(BndToolsMessages.RunDescriptorTargetLocationPage_AddBndRunDescriptorContainer, BndToolsMessages.RunDescriptorTargetLocationPage_AddBndRunDescriptor,
BndToolsMessages.RunDescriptorTargetLocationPage_Select, targetDefinition);

if (targetLocation != null) {
this.targetLocation = targetLocation;
Expand All @@ -64,9 +64,9 @@ public RunDescriptorTargetLocationPage(ITargetDefinition targetDefinition,
public void createControl(Composite parent) {
Composite composite = SWTFactory.createComposite(parent, 1, 1, GridData.FILL_BOTH, 0, 0);

SWTFactory.createLabel(composite, "Run descriptor:", 1);
SWTFactory.createLabel(composite, BndToolsMessages.RunDescriptorTargetLocationPage_RunDescriptor, 1);
TreeViewer projectTree = createRunDescriptorSelectionArea(composite);
SWTFactory.createLabel(composite, "Run bundles:", 1);
SWTFactory.createLabel(composite, BndToolsMessages.RunDescriptorTargetLocationPage_RunBundles, 1);
bundleList = createBundleListArea(composite, 1);

setControl(composite);
Expand All @@ -77,7 +77,7 @@ public void createControl(Composite parent) {

if (projectTree.getTree()
.getItems().length == 0)
logError("No run descriptors found in workspace", null);
logError("No run descriptors found in workspace", null); //$NON-NLS-1$
}

private TreeViewer createRunDescriptorSelectionArea(Composite composite) {
Expand Down Expand Up @@ -118,7 +118,7 @@ public boolean isElementSelectable(Object element) {
return element instanceof IFile;
}
};
bndrunFilter.setPattern("*");
bndrunFilter.setPattern("*"); //$NON-NLS-1$
return new ViewerFilter[] {
bndrunFilter
};
Expand All @@ -137,15 +137,15 @@ private void updateTarget() {

try (Bndrun bndRun = new Bndrun(workspace, file)) {
for (Container bundle : bndRun.getRunbundles()) {
bundles.add(bundle.getBundleSymbolicName() + " - " + bundle.getVersion());
bundles.add(bundle.getBundleSymbolicName() + " - " + bundle.getVersion()); //$NON-NLS-1$
}
bundleList.setInput(bundles);
}

setPageComplete(true);

if (bundles.isEmpty())
logWarning("Run descriptor is empty: " + runDescriptorFile.getFullPath(), null);
logWarning("Run descriptor is empty: " + runDescriptorFile.getFullPath(), null); //$NON-NLS-1$
else
resetMessage();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RunDescriptorTargetLocationWizard extends Wizard implements ITarget
private RunDescriptorTargetLocationPage targetLocationPage;

public RunDescriptorTargetLocationWizard() {
setWindowTitle("Run Descriptor Target Location");
setWindowTitle("Run Descriptor Target Location"); //$NON-NLS-1$
}

@Override
Expand Down
Loading

0 comments on commit 4427467

Please sign in to comment.