Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Bricon2018-03-13 19:13:12 +0000
committerFred Bricon2018-03-13 19:13:12 +0000
commitdcdfbd23f9698dc768243e32a59f191bc74c65ee (patch)
treefb666c4db9f9ef3c247a0236c7b5d50db5422f47 /org.eclipse.m2e.jdt
parentc37f9e65db255fff1281647b55fe8477561f9050 (diff)
downloadm2e-core-dcdfbd23f9698dc768243e32a59f191bc74c65ee.tar.gz
m2e-core-dcdfbd23f9698dc768243e32a59f191bc74c65ee.tar.xz
m2e-core-dcdfbd23f9698dc768243e32a59f191bc74c65ee.zip
Bug 385391: serialize user-selected source attachment encoding
Change-Id: I07bb15b842f0345891238928e552e37e28922f18 Signed-off-by: Fred Bricon <fbricon@gmail.com>
Diffstat (limited to 'org.eclipse.m2e.jdt')
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java27
-rw-r--r--org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathHelpers.java14
2 files changed, 27 insertions, 14 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
index 25da83b0..19790d2a 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/BuildPathManager.java
@@ -100,6 +100,8 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
private static final String PROPERTY_SRC_ROOT = ".srcRoot"; //$NON-NLS-1$
+ private static final String PROPERTY_SRC_ENCODING = ".srcEncoding"; //$NON-NLS-1$
+
private static final String PROPERTY_SRC_PATH = ".srcPath"; //$NON-NLS-1$
private static final String PROPERTY_JAVADOC_URL = ".javadoc"; //$NON-NLS-1$
@@ -299,6 +301,12 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
if(srcPath == null && a != null) {
srcPath = getSourcePath(a);
}
+ if(sourceAttachment != null) {
+ String srcEncoding = sourceAttachment.getProperty(key + PROPERTY_SRC_ENCODING);
+ if(srcEncoding != null) {
+ desc.getClasspathAttributes().put(IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING, srcEncoding);
+ }
+ }
// configure javadocs if available
String javaDocUrl = desc.getJavadocUrl();
@@ -510,6 +518,10 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
if(entry.getSourceAttachmentRootPath() != null) {
props.put(path + PROPERTY_SRC_ROOT, entry.getSourceAttachmentRootPath().toPortableString());
}
+ String sourceAttachmentEncoding = getSourceAttachmentEncoding(entry);
+ if(sourceAttachmentEncoding != null) {
+ props.put(path + PROPERTY_SRC_ENCODING, sourceAttachmentEncoding);
+ }
String javadocUrl = getJavadocLocation(entry);
if(javadocUrl != null) {
props.put(path + PROPERTY_JAVADOC_URL, javadocUrl);
@@ -556,14 +568,11 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
/** public for unit tests only */
public String getJavadocLocation(IClasspathEntry entry) {
- IClasspathAttribute[] attributes = entry.getExtraAttributes();
- for(int j = 0; j < attributes.length; j++ ) {
- IClasspathAttribute attribute = attributes[j];
- if(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attribute.getName())) {
- return attribute.getValue();
- }
- }
- return null;
+ return MavenClasspathHelpers.getAttribute(entry, IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME);
+ }
+
+ public String getSourceAttachmentEncoding(IClasspathEntry entry) {
+ return MavenClasspathHelpers.getAttribute(entry, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
}
/** public for unit tests only */
@@ -721,7 +730,7 @@ public class BuildPathManager implements IMavenProjectChangedListener, IResource
}
public void scheduleDownload(IPackageFragmentRoot fragment, boolean downloadSources, boolean downloadJavadoc) {
- ArtifactKey artifact = (ArtifactKey) fragment.getAdapter(ArtifactKey.class);
+ ArtifactKey artifact = fragment.getAdapter(ArtifactKey.class);
if(artifact == null) {
// we don't know anything about this JAR/ZIP
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathHelpers.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathHelpers.java
index a45902c2..d9254a4c 100644
--- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathHelpers.java
+++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/MavenClasspathHelpers.java
@@ -15,6 +15,7 @@ import java.util.stream.Stream;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.JavaCore;
@@ -37,11 +38,14 @@ public class MavenClasspathHelpers {
}
public static boolean isTestSource(IClasspathEntry entry) {
- if(entry == null || entry.getEntryKind() != IClasspathEntry.CPE_SOURCE || entry.getExtraAttributes().length == 0) {
- return false;
+ return "true".equals(getAttribute(entry, IClasspathManager.TEST_ATTRIBUTE));
+ }
+
+ public static String getAttribute(IClasspathEntry entry, String key) {
+ if(entry == null || entry.getExtraAttributes().length == 0 || key == null) {
+ return null;
}
- return Stream.of(entry.getExtraAttributes())
- .filter(a -> IClasspathManager.TEST_ATTRIBUTE.equals(a.getName()) && "true".equals(a.getValue())).findAny()
- .isPresent();
+ return Stream.of(entry.getExtraAttributes()).filter(a -> key.equals(a.getName())).findFirst()
+ .map(IClasspathAttribute::getValue).orElse(null);
}
}

Back to the top