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
Expand Up @@ -9,6 +9,7 @@
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -201,13 +202,13 @@ public void testPmdEnabledTRUE() throws CoreException, PropertiesException {
*
*/
@Test
public void testProjectRuleSet() throws PropertiesException {
public void testProjectRuleSet() throws PropertiesException, UnsupportedEncodingException {
final IProjectPropertiesManager mgr = PMDPlugin.getDefault().getPropertiesManager();
final IProjectProperties model = mgr.loadProjectProperties(this.testProject);

final IPreferencesManager pmgr = PMDPlugin.getDefault().getPreferencesManager();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
PrintStream out = new PrintStream(byteStream);
PrintStream out = new PrintStream(byteStream, false, StandardCharsets.UTF_8.name());

Assert.assertTrue("A new project is not created with the default plugin ruleset", EclipseUtils
.assertRuleSetEquals(model.getProjectRuleSet().getRules(), pmgr.getRuleSet().getRules(), out));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,8 @@ public static String markerTypeFor(RuleViolation violation) {
return PMDRuntimeConstants.PMD_MARKER_4;
case LOW:
return PMDRuntimeConstants.PMD_MARKER_5;
default:
return PMDRuntimeConstants.PMD_MARKER;
}
return PMDRuntimeConstants.PMD_MARKER;
}

private void prepareMarkerAccumulator(IFile file) {
Expand Down Expand Up @@ -418,7 +417,7 @@ private List<Review> findReviewedViolations(final IFile file) {
boolean findLine = false;
boolean comment = false;
final Deque<String> pendingReviews = new ArrayDeque<>();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents()))) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(file.getContents(), file.getCharset()))) {
while (reader.ready()) {
String line = reader.readLine();
if (line != null) {
Expand Down Expand Up @@ -491,7 +490,6 @@ private MarkerInfo2 getMarkerInfo(RuleViolation violation, String type) throws P
break;

case LOW:
default:
info.add(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -273,7 +274,7 @@ private void renderReport(CPDReport cpdResult) {

byte[] data = new byte[0];
try (ByteArrayOutputStream renderedReport = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(renderedReport);) {
Writer writer = new OutputStreamWriter(renderedReport, StandardCharsets.UTF_8);) {
renderer.render(cpdResult, writer);
writer.flush();
data = renderedReport.toByteArray();
Expand All @@ -286,6 +287,7 @@ private void renderReport(CPDReport cpdResult) {
if (reportFile.exists()) {
LOG.debug(" Overwriting report file");
reportFile.setContents(contentsStream, true, false, getMonitor());
reportFile.setCharset(StandardCharsets.UTF_8.name(), getMonitor());
} else {
LOG.debug(" Creating report file");
reportFile.create(contentsStream, true, getMonitor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -107,12 +108,13 @@ private void render(Report report, IFolder folder, String reportName, Renderer r

LOG.debug(" Creating the report file");
IFile reportFile = folder.getFile(reportName);
try (InputStream contentsStream = new ByteArrayInputStream(reportString.getBytes())) {
try (InputStream contentsStream = new ByteArrayInputStream(reportString.getBytes(StandardCharsets.UTF_8))) {
if (reportFile.exists()) {
reportFile.setContents(contentsStream, true, false, getMonitor());
} else {
reportFile.create(contentsStream, true, getMonitor());
}
reportFile.setCharset(StandardCharsets.UTF_8.name(), getMonitor());
}
reportFile.refreshLocal(IResource.DEPTH_INFINITE, getMonitor());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,11 @@ private void writeProjectProperties(final IProject project, final ProjectPropert

final IFile propertiesFile = project.getFile(ProjectPropertiesTimestampTupel.PROPERTIES_FILE);
if (propertiesFile.exists() && propertiesFile.isAccessible()) {
propertiesFile.setContents(new ByteArrayInputStream(writer.getBytes()), false, false, null);
propertiesFile.setContents(new ByteArrayInputStream(writer.getBytes(StandardCharsets.UTF_8)), false, false, null);
} else {
propertiesFile.create(new ByteArrayInputStream(writer.getBytes()), false, null);
propertiesFile.create(new ByteArrayInputStream(writer.getBytes(StandardCharsets.UTF_8)), false, null);
}
propertiesFile.setCharset(StandardCharsets.UTF_8.name(), null);
} catch (CoreException e) {
throw new PropertiesException("Error while writing project properties file for project " + project.getName(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* A string that maintains a set of interesting indicies about itself.
Expand Down Expand Up @@ -35,4 +36,23 @@ public int compareTo(IndexedString other) {
return deltaLength == 0 ? other.string.compareTo(string) : deltaLength;
}

@Override
public int hashCode() {
return Objects.hash(string);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
IndexedString other = (IndexedString) obj;
return compareTo(other) == 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -143,4 +144,24 @@ public int compareTo(RuleGroup<T> otherGroup) {

return id.compareTo(otherGroup.id());
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
RuleGroup<?> other = (RuleGroup<?>) obj;
return Objects.equals(id, other.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -830,23 +830,6 @@ public void populateRuleTable() {
updateCheckControls();
}

// private void popupRuleSelectionMenu(Event event) {
//
// // have to do it here or else the ruleset var is null in the menu setup -
// timing issue
//// if (rulesetMenusByName == null) {
// // addRulesetMenuOptions(ruleListMenu);
// // new MenuItem(ruleListMenu, SWT.SEPARATOR);
// // addColumnSelectionOptions(ruleListMenu);
//// }
//
// // adjustMenuPrioritySettings();
//// adjustMenuRulesetSettings();
//// adjustMenuUseDefaultsOption();
//// ruleListMenu.setLocation(event.x, event.y);
//// ruleListMenu.setVisible(true);
// }

@Override
protected void redrawTable(String sortColumnLabel, int sortDir) {
groupBy(groupingColumn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,6 @@ private void implementationType(ImplementationType type) {
implementationTypeCombo.deselectAll();
break;
}

default: {
throw new IllegalStateException();
}
}
validateRuleParams();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte
monitor.worked(1);

String fixCode = this.fix.fix(sw.toString(), this.lineNumber);
file.setContents(new ByteArrayInputStream(fixCode.getBytes()), false, true, monitor);
file.setContents(new ByteArrayInputStream(fixCode.getBytes(file.getCharset())), false, true, monitor);

monitor.worked(1);
} catch (CoreException e) {
Expand Down
Loading