View | Details | Raw Unified | Return to bug 101425 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClasspathEntry.java (-49 / +180 lines)
Lines 10-20 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.core;
11
package org.eclipse.jdt.internal.core;
12
12
13
import java.io.CharArrayWriter;
13
import java.io.File;
14
import java.io.File;
15
import java.io.IOException;
16
import java.util.ArrayList;
14
import java.util.HashMap;
17
import java.util.HashMap;
15
import java.util.HashSet;
18
import java.util.HashSet;
16
import java.util.Map;
19
import java.util.Map;
17
20
21
import org.apache.crimson.tree.XmlWritable;
22
import org.apache.crimson.tree.XmlWriteContext;
18
import org.eclipse.core.resources.IProject;
23
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
24
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.resources.IWorkspaceRoot;
25
import org.eclipse.core.resources.IWorkspaceRoot;
Lines 39-45 Link Here
39
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
44
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
40
import org.eclipse.jdt.internal.core.util.Messages;
45
import org.eclipse.jdt.internal.core.util.Messages;
41
import org.eclipse.jdt.internal.core.util.Util;
46
import org.eclipse.jdt.internal.core.util.Util;
47
import org.w3c.dom.DOMException;
42
import org.w3c.dom.Element;
48
import org.w3c.dom.Element;
49
import org.w3c.dom.NamedNodeMap;
43
import org.w3c.dom.Node;
50
import org.w3c.dom.Node;
44
import org.w3c.dom.NodeList;
51
import org.w3c.dom.NodeList;
45
52
Lines 119-124 Link Here
119
	private String rootID;
126
	private String rootID;
120
	private AccessRuleSet accessRuleSet;
127
	private AccessRuleSet accessRuleSet;
121
	
128
	
129
	
130
	static class UnknownXmlElements {
131
		String[] attributes;
132
		ArrayList children;
133
	}
134
	
122
	/*
135
	/*
123
	 * Default inclusion pattern set
136
	 * Default inclusion pattern set
124
	 */
137
	 */
Lines 278-287 Link Here
278
		return result;
291
		return result;
279
	}
292
	}
280
293
281
	static IClasspathAttribute[] decodeExtraAttributes(Element element) {
294
	static IClasspathAttribute[] decodeExtraAttributes(NodeList attributes) {
282
		Node extra = element.getElementsByTagName(TAG_ATTRIBUTES).item(0);
283
		if (extra == null) return NO_EXTRA_ATTRIBUTES;
284
		NodeList attributes = element.getElementsByTagName(TAG_ATTRIBUTE);
285
		if (attributes == null) return NO_EXTRA_ATTRIBUTES;
295
		if (attributes == null) return NO_EXTRA_ATTRIBUTES;
286
		int length = attributes.getLength();
296
		int length = attributes.getLength();
287
		if (length == 0) return NO_EXTRA_ATTRIBUTES;
297
		if (length == 0) return NO_EXTRA_ATTRIBUTES;
Lines 303-333 Link Here
303
		return result;
313
		return result;
304
	}
314
	}
305
	
315
	
306
	static IAccessRule[] decodeAccessRules(Element element) {
316
	static IAccessRule[] decodeAccessRules(NodeList list) {
307
		Node accessRules = element.getElementsByTagName(TAG_ACCESS_RULES).item(0);
317
		if (list == null) return null;
308
		if (accessRules == null || accessRules.getNodeType() != Node.ELEMENT_NODE) return null;
309
		NodeList list = ((Element) accessRules).getElementsByTagName(TAG_ACCESS_RULE);
310
		int length = list.getLength();
318
		int length = list.getLength();
311
		if (length == 0) return null;
319
		if (length == 0) return null;
312
		IAccessRule[] result = new IAccessRule[length];
320
		IAccessRule[] result = new IAccessRule[length];
313
		int index = 0;
321
		int index = 0;
314
		for (int i = 0; i < length; i++) {
322
		for (int i = 0; i < length; i++) {
315
			Node accessRule = list.item(i);
323
			Node accessRule = list.item(i);
316
			if (accessRule == null || accessRule.getNodeType() != Node.ELEMENT_NODE) return null;
324
			if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
317
			Element elementAccessRule = (Element) accessRule;
325
				Element elementAccessRule = (Element) accessRule;
318
			String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
326
				String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
319
			if (pattern == null) continue;
327
				if (pattern == null) continue;
320
			String tagKind =  elementAccessRule.getAttribute(TAG_KIND);
328
				String tagKind =  elementAccessRule.getAttribute(TAG_KIND);
321
			int kind;
329
				int kind;
322
			if (TAG_ACCESSIBLE.equals(tagKind))
330
				if (TAG_ACCESSIBLE.equals(tagKind))
323
				kind = IAccessRule.K_ACCESSIBLE;
331
					kind = IAccessRule.K_ACCESSIBLE;
324
			else if (TAG_NON_ACCESSIBLE.equals(tagKind))
332
				else if (TAG_NON_ACCESSIBLE.equals(tagKind))
325
				kind = IAccessRule.K_NON_ACCESSIBLE;
333
					kind = IAccessRule.K_NON_ACCESSIBLE;
326
			else if (TAG_DISCOURAGED.equals(tagKind))
334
				else if (TAG_DISCOURAGED.equals(tagKind))
327
				kind = IAccessRule.K_DISCOURAGED;
335
					kind = IAccessRule.K_DISCOURAGED;
328
			else
336
				else
329
				continue;
337
					continue;
330
			result[index++] = new ClasspathAccessRule(new Path(pattern), kind);
338
				result[index++] = new ClasspathAccessRule(new Path(pattern), kind);
339
			}
331
		}
340
		}
332
		if (index != length)
341
		if (index != length)
333
			System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
342
			System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
Lines 337-344 Link Here
337
	/**
346
	/**
338
	 * Decode some element tag containing a sequence of patterns into IPath[]
347
	 * Decode some element tag containing a sequence of patterns into IPath[]
339
	 */
348
	 */
340
	private static IPath[] decodePatterns(Element element, String tag) {
349
	private static IPath[] decodePatterns(NamedNodeMap nodeMap, String tag) {
341
		String sequence = element.getAttribute(tag);
350
		String sequence = removeAttribute(tag, nodeMap);
342
		if (!sequence.equals("")) { //$NON-NLS-1$ 
351
		if (!sequence.equals("")) { //$NON-NLS-1$ 
343
			char[][] patterns = CharOperation.splitOn('|', sequence.toCharArray());
352
			char[][] patterns = CharOperation.splitOn('|', sequence.toCharArray());
344
			int patternCount;
353
			int patternCount;
Lines 352-357 Link Here
352
		}
361
		}
353
		return null;
362
		return null;
354
	}
363
	}
364
	
365
	private static void decodeUnknownChild(Node child, StringBuffer buffer) {
366
		if (child instanceof XmlWritable) {
367
		    CharArrayWriter writer = new CharArrayWriter();
368
		    XmlWriteContext	context = new XmlWriteContext(writer);
369
	    	try {
370
				((XmlWritable) child).writeXml(context);
371
				buffer.append(writer.toString());
372
			} catch (IOException e) {
373
				buffer.append("<exception reading unknown elements (see previous version from local history)>"); //$NON-NLS-1$
374
			}
375
		} else {
376
			buffer.append("<unknown elements detected (see previous version from local history)>"); //$NON-NLS-1$
377
		}
378
	}
379
	
355
	/*
380
	/*
356
	 * Returns a char based representation of the exclusions patterns full path.
381
	 * Returns a char based representation of the exclusions patterns full path.
357
	 */
382
	 */
Lines 389-395 Link Here
389
	/**
414
	/**
390
	 * Returns the XML encoding of the class path.
415
	 * Returns the XML encoding of the class path.
391
	 */
416
	 */
392
	public void elementEncode(XMLWriter writer, IPath projectPath, boolean indent, boolean newLine) {
417
	public void elementEncode(XMLWriter writer, IPath projectPath, boolean indent, boolean newLine, Map unknownElements) {
393
		HashMap parameters = new HashMap();
418
		HashMap parameters = new HashMap();
394
		
419
		
395
		parameters.put(TAG_KIND, ClasspathEntry.kindToString(this.entryKind));
420
		parameters.put(TAG_KIND, ClasspathEntry.kindToString(this.entryKind));
Lines 433-438 Link Here
433
			parameters.put(TAG_COMBINE_ACCESS_RULES, "false"); //$NON-NLS-1$
458
			parameters.put(TAG_COMBINE_ACCESS_RULES, "false"); //$NON-NLS-1$
434
		
459
		
435
		
460
		
461
		// unknown attributes
462
		UnknownXmlElements unknownXmlElements = unknownElements == null ? null : (UnknownXmlElements) unknownElements.get(this.path);
463
		String[] unknownAttributes;
464
		if (unknownXmlElements != null && (unknownAttributes = unknownXmlElements.attributes) != null)
465
			for (int i = 0, length = unknownAttributes.length; i < length; i+=2) {
466
				String tagName = unknownAttributes[i];
467
				String tagValue = unknownAttributes[i+1];
468
				parameters.put(tagName, tagValue);
469
			}
470
		
436
		if (this.specificOutputLocation != null) {
471
		if (this.specificOutputLocation != null) {
437
			IPath outputLocation = this.specificOutputLocation.removeFirstSegments(1);
472
			IPath outputLocation = this.specificOutputLocation.removeFirstSegments(1);
438
			outputLocation = outputLocation.makeRelative();
473
			outputLocation = outputLocation.makeRelative();
Lines 441-455 Link Here
441
476
442
		boolean hasExtraAttributes = this.extraAttributes.length != 0;
477
		boolean hasExtraAttributes = this.extraAttributes.length != 0;
443
		boolean hasRestrictions = getAccessRuleSet() != null; // access rule set is null if no access rules
478
		boolean hasRestrictions = getAccessRuleSet() != null; // access rule set is null if no access rules
444
		writer.printTag(TAG_CLASSPATHENTRY, parameters, indent, newLine, !hasExtraAttributes && !hasRestrictions /*close tag if no extra attributes and no restriction*/);
479
		ArrayList unknownChildren = unknownXmlElements != null ? unknownXmlElements.children : null;
480
		boolean hasUnknownChildren = unknownChildren != null;
481
		writer.printTag(
482
			TAG_CLASSPATHENTRY, 
483
			parameters, 
484
			indent, 
485
			newLine, 
486
			!hasExtraAttributes && !hasRestrictions && !hasUnknownChildren/*close tag if no extra attributes, no restriction and no unknown children*/);
445
		
487
		
446
		if (hasExtraAttributes)
488
		if (hasExtraAttributes)
447
			encodeExtraAttributes(writer, indent, newLine);
489
			encodeExtraAttributes(writer, indent, newLine);
448
	
490
	
449
		if (hasRestrictions)
491
		if (hasRestrictions)
450
			encodeAccessRules(writer, indent, newLine);
492
			encodeAccessRules(writer, indent, newLine);
493
		
494
		if (hasUnknownChildren)
495
			encodeUnknownChildren(writer, indent, newLine, unknownChildren);
451
496
452
		if (hasExtraAttributes || hasRestrictions)
497
		if (hasExtraAttributes || hasRestrictions || hasUnknownChildren)
453
			writer.endTag(TAG_CLASSPATHENTRY, indent);
498
			writer.endTag(TAG_CLASSPATHENTRY, indent);
454
	}
499
	}
455
	
500
	
Lines 496-506 Link Here
496
541
497
	}
542
	}
498
	
543
	
499
	public static IClasspathEntry elementDecode(Element element, IJavaProject project) {
544
	private void encodeUnknownChildren(XMLWriter writer, boolean indent, boolean newLine, ArrayList unknownChildren) {
545
		for (int i = 0, length = unknownChildren.size(); i < length; i++) {
546
			String child = (String) unknownChildren.get(i);
547
			writer.printString(child, indent, newLine);
548
		}
549
	}
550
	
551
	public static IClasspathEntry elementDecode(Element element, IJavaProject project, Map unknownElements) {
500
	
552
	
501
		IPath projectPath = project.getProject().getFullPath();
553
		IPath projectPath = project.getProject().getFullPath();
502
		String kindAttr = element.getAttribute(TAG_KIND);
554
		NamedNodeMap attributes = element.getAttributes();
503
		String pathAttr = element.getAttribute(TAG_PATH);
555
		NodeList children = element.getChildNodes();
556
		boolean[] foundChildren = new boolean[children.getLength()];
557
		String kindAttr = removeAttribute(TAG_KIND, attributes);
558
		String pathAttr = removeAttribute(TAG_PATH, attributes);
504
559
505
		// ensure path is absolute
560
		// ensure path is absolute
506
		IPath path = new Path(pathAttr); 		
561
		IPath path = new Path(pathAttr); 		
Lines 511-539 Link Here
511
		// source attachment info (optional)
566
		// source attachment info (optional)
512
		IPath sourceAttachmentPath = 
567
		IPath sourceAttachmentPath = 
513
			element.hasAttribute(TAG_SOURCEPATH)	
568
			element.hasAttribute(TAG_SOURCEPATH)	
514
			? new Path(element.getAttribute(TAG_SOURCEPATH))
569
			? new Path(removeAttribute(TAG_SOURCEPATH, attributes))
515
			: null;
570
			: null;
516
		if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) {
571
		if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) {
517
			sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
572
			sourceAttachmentPath = projectPath.append(sourceAttachmentPath);
518
		}
573
		}
519
		IPath sourceAttachmentRootPath = 
574
		IPath sourceAttachmentRootPath = 
520
			element.hasAttribute(TAG_ROOTPATH)
575
			element.hasAttribute(TAG_ROOTPATH)
521
			? new Path(element.getAttribute(TAG_ROOTPATH))
576
			? new Path(removeAttribute(TAG_ROOTPATH, attributes))
522
			: null;
577
			: null;
523
		
578
		
524
		// exported flag (optional)
579
		// exported flag (optional)
525
		boolean isExported = element.getAttribute(TAG_EXPORTED).equals("true"); //$NON-NLS-1$
580
		boolean isExported = removeAttribute(TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$
526
581
527
		// inclusion patterns (optional)
582
		// inclusion patterns (optional)
528
		IPath[] inclusionPatterns = decodePatterns(element, TAG_INCLUDING);
583
		IPath[] inclusionPatterns = decodePatterns(attributes, TAG_INCLUDING);
529
		if (inclusionPatterns == null) inclusionPatterns = INCLUDE_ALL;
584
		if (inclusionPatterns == null) inclusionPatterns = INCLUDE_ALL;
530
		
585
		
531
		// exclusion patterns (optional)
586
		// exclusion patterns (optional)
532
		IPath[] exclusionPatterns = decodePatterns(element, TAG_EXCLUDING);
587
		IPath[] exclusionPatterns = decodePatterns(attributes, TAG_EXCLUDING);
533
		if (exclusionPatterns == null) exclusionPatterns = EXCLUDE_NONE;
588
		if (exclusionPatterns == null) exclusionPatterns = EXCLUDE_NONE;
534
		
589
		
535
		// access rules (optional)
590
		// access rules (optional)
536
		IAccessRule[] accessRules = decodeAccessRules(element);
591
		NodeList attributeList = getChildAttributes(TAG_ACCESS_RULES, children, foundChildren);
592
		IAccessRule[] accessRules = decodeAccessRules(attributeList);
537
		
593
		
538
		// backward compatibility
594
		// backward compatibility
539
		if (accessRules == null) {
595
		if (accessRules == null) {
Lines 541-565 Link Here
541
		}
597
		}
542
598
543
		// combine access rules (optional)
599
		// combine access rules (optional)
544
		boolean combineAccessRestrictions = !element.getAttribute(TAG_COMBINE_ACCESS_RULES).equals("false"); //$NON-NLS-1$
600
		boolean combineAccessRestrictions = !removeAttribute(TAG_COMBINE_ACCESS_RULES, attributes).equals("false"); //$NON-NLS-1$
545
		
601
		
546
		// extra attributes (optional)
602
		// extra attributes (optional)
547
		IClasspathAttribute[] extraAttributes = decodeExtraAttributes(element);
603
		attributeList = getChildAttributes(TAG_ATTRIBUTES, children, foundChildren);
604
		IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList);
548
		
605
		
549
		// custom output location
606
		// custom output location
550
		IPath outputLocation = element.hasAttribute(TAG_OUTPUT) ? projectPath.append(element.getAttribute(TAG_OUTPUT)) : null;
607
		IPath outputLocation = element.hasAttribute(TAG_OUTPUT) ? projectPath.append(removeAttribute(TAG_OUTPUT, attributes)) : null;
608
		
609
		String[] unknownAttributes = null;
610
		ArrayList unknownChildren = null;
611
612
		if (unknownElements != null) {
613
			// unknown attributes
614
			int unknownAttributeLength = attributes.getLength();
615
			if (unknownAttributeLength != 0) {
616
				unknownAttributes = new String[unknownAttributeLength*2];
617
				for (int i = 0; i < unknownAttributeLength; i++) {
618
					Node attribute = attributes.item(i);
619
					unknownAttributes[i*2] = attribute.getNodeName();
620
					unknownAttributes[i*2 + 1] = attribute.getNodeValue();
621
				}
622
			}
623
			
624
			// unknown children
625
			for (int i = 0, length = foundChildren.length; i < length; i++) {
626
				if (!foundChildren[i]) {
627
					Node node = children.item(i);
628
					if (node.getNodeType() != Node.ELEMENT_NODE) continue;
629
					if (unknownChildren == null)
630
						unknownChildren = new ArrayList();
631
					StringBuffer buffer = new StringBuffer();
632
					decodeUnknownChild(node, buffer);
633
					unknownChildren.add(buffer.toString());
634
				}
635
			}
636
		}
551
		
637
		
552
		// recreate the CP entry
638
		// recreate the CP entry
553
		IClasspathEntry entry = null;
639
		IClasspathEntry entry = null;
554
		switch (kind) {
640
		switch (kind) {
555
641
556
			case IClasspathEntry.CPE_PROJECT :
642
			case IClasspathEntry.CPE_PROJECT :
557
				entry = JavaCore.newProjectEntry(
643
				entry = new ClasspathEntry(
558
												path, 
644
				IPackageFragmentRoot.K_SOURCE,
559
												accessRules,
645
				IClasspathEntry.CPE_PROJECT,
560
												combineAccessRestrictions,
646
				path,
561
												extraAttributes,
647
				ClasspathEntry.INCLUDE_ALL, // inclusion patterns
562
												isExported);
648
				ClasspathEntry.EXCLUDE_NONE, // exclusion patterns
649
				null, // source attachment
650
				null, // source attachment root
651
				null, // specific output folder
652
				isExported,
653
				accessRules,
654
				combineAccessRestrictions,
655
				extraAttributes);
563
				break;				
656
				break;				
564
			case IClasspathEntry.CPE_LIBRARY :
657
			case IClasspathEntry.CPE_LIBRARY :
565
				entry = JavaCore.newLibraryEntry(
658
				entry = JavaCore.newLibraryEntry(
Lines 574-580 Link Here
574
				// must be an entry in this project or specify another project
667
				// must be an entry in this project or specify another project
575
				String projSegment = path.segment(0);
668
				String projSegment = path.segment(0);
576
				if (projSegment != null && projSegment.equals(project.getElementName())) { // this project
669
				if (projSegment != null && projSegment.equals(project.getElementName())) { // this project
577
					return JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
670
					entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
578
				} else { 
671
				} else { 
579
					if (path.segmentCount() == 1) {
672
					if (path.segmentCount() == 1) {
580
						// another project
673
						// another project
Lines 586-592 Link Here
586
												isExported);
679
												isExported);
587
					} else {
680
					} else {
588
						// an invalid source folder
681
						// an invalid source folder
589
						return JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
682
						entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes);
590
					}
683
					}
591
				}
684
				}
592
				break;
685
				break;
Lines 608-614 Link Here
608
				break;
701
				break;
609
			case ClasspathEntry.K_OUTPUT :
702
			case ClasspathEntry.K_OUTPUT :
610
				if (!path.isAbsolute()) return null;
703
				if (!path.isAbsolute()) return null;
611
				return new ClasspathEntry(
704
				entry = new ClasspathEntry(
612
						ClasspathEntry.K_OUTPUT,
705
						ClasspathEntry.K_OUTPUT,
613
						IClasspathEntry.CPE_LIBRARY,
706
						IClasspathEntry.CPE_LIBRARY,
614
						path,
707
						path,
Lines 621-631 Link Here
621
						null, // no access rules
714
						null, // no access rules
622
						false, // no accessible files to combine
715
						false, // no accessible files to combine
623
						NO_EXTRA_ATTRIBUTES);
716
						NO_EXTRA_ATTRIBUTES);
717
				break;
624
			default :
718
			default :
625
				throw new Assert.AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); 
719
				throw new Assert.AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); 
626
		}
720
		}
721
		
722
		if (unknownAttributes != null || unknownChildren != null) {
723
			UnknownXmlElements unknownXmlElements = new UnknownXmlElements();
724
			unknownXmlElements.attributes = unknownAttributes;
725
			unknownXmlElements.children = unknownChildren;
726
			unknownElements.put(path, unknownXmlElements);
727
		}
728
		
627
		return entry;
729
		return entry;
628
	}
730
	}
731
	
732
	public static NodeList getChildAttributes(String childName, NodeList children, boolean[] foundChildren) {
733
		for (int i = 0, length = foundChildren.length; i < length; i++) {
734
			Node node = children.item(i);
735
			if (childName.equals(node.getNodeName())) {
736
				foundChildren[i] = true;
737
				return node.getChildNodes();
738
			}
739
		}
740
		return null;
741
	}
742
743
	
744
	private static String removeAttribute(String nodeName, NamedNodeMap nodeMap) {
745
		Node node = removeNode(nodeName, nodeMap);
746
		if (node == null)
747
			return ""; // //$NON-NLS-1$
748
		return node.getNodeValue();
749
	}
750
	
751
	private static Node removeNode(String nodeName, NamedNodeMap nodeMap) {
752
		try {
753
			return nodeMap.removeNamedItem(nodeName);
754
		} catch (DOMException e) {
755
			if (e.code != DOMException.NOT_FOUND_ERR)
756
				throw e;
757
			return null;
758
		}
759
	}
629
760
630
	/**
761
	/**
631
	 * Encode some patterns into XML parameter tag
762
	 * Encode some patterns into XML parameter tag
(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (-1 / +2 lines)
Lines 2278-2284 Link Here
2278
							containerString = ((JavaProject)project).encodeClasspath(
2278
							containerString = ((JavaProject)project).encodeClasspath(
2279
									entries, 
2279
									entries, 
2280
									null, 
2280
									null, 
2281
									false);
2281
									false,
2282
									null/*not interested in unknown elements*/);
2282
						}
2283
						}
2283
					} catch(JavaModelException e){
2284
					} catch(JavaModelException e){
2284
						// could not encode entry: will not persist
2285
						// could not encode entry: will not persist
(-)model/org/eclipse/jdt/internal/core/JavaProject.java (-6 / +18 lines)
Lines 796-801 Link Here
796
	 * Reads and decode an XML classpath string
796
	 * Reads and decode an XML classpath string
797
	 */
797
	 */
798
	protected IClasspathEntry[] decodeClasspath(String xmlClasspath, boolean createMarker, boolean logProblems) {
798
	protected IClasspathEntry[] decodeClasspath(String xmlClasspath, boolean createMarker, boolean logProblems) {
799
		return decodeClasspath(xmlClasspath, createMarker, logProblems, null/*not interested in unknown elements*/);
800
	}
801
	
802
	/**
803
	 * Reads and decode an XML classpath string
804
	 */
805
	protected IClasspathEntry[] decodeClasspath(String xmlClasspath, boolean createMarker, boolean logProblems, Map unknownElements) {
799
806
800
		ArrayList paths = new ArrayList();
807
		ArrayList paths = new ArrayList();
801
		IClasspathEntry defaultOutput = null;
808
		IClasspathEntry defaultOutput = null;
Lines 825-831 Link Here
825
			for (int i = 0; i < length; ++i) {
832
			for (int i = 0; i < length; ++i) {
826
				Node node = list.item(i);
833
				Node node = list.item(i);
827
				if (node.getNodeType() == Node.ELEMENT_NODE) {
834
				if (node.getNodeType() == Node.ELEMENT_NODE) {
828
					IClasspathEntry entry = ClasspathEntry.elementDecode((Element)node, this);
835
					IClasspathEntry entry = ClasspathEntry.elementDecode((Element)node, this, unknownElements);
829
					if (entry != null){
836
					if (entry != null){
830
						if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { 
837
						if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) { 
831
							defaultOutput = entry; // separate output
838
							defaultOutput = entry; // separate output
Lines 901-907 Link Here
901
	/**
908
	/**
902
	 * Returns the XML String encoding of the class path.
909
	 * Returns the XML String encoding of the class path.
903
	 */
910
	 */
904
	protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean indent) throws JavaModelException {
911
	protected String encodeClasspath(IClasspathEntry[] classpath, IPath outputLocation, boolean indent, Map unknownElements) throws JavaModelException {
905
		try {
912
		try {
906
			ByteArrayOutputStream s = new ByteArrayOutputStream();
913
			ByteArrayOutputStream s = new ByteArrayOutputStream();
907
			OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
914
			OutputStreamWriter writer = new OutputStreamWriter(s, "UTF8"); //$NON-NLS-1$
Lines 909-915 Link Here
909
			
916
			
910
			xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent);
917
			xmlWriter.startTag(ClasspathEntry.TAG_CLASSPATH, indent);
911
			for (int i = 0; i < classpath.length; ++i) {
918
			for (int i = 0; i < classpath.length; ++i) {
912
				((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true);
919
				((ClasspathEntry)classpath[i]).elementEncode(xmlWriter, this.project.getFullPath(), indent, true, unknownElements);
913
			}
920
			}
914
	
921
	
915
			if (outputLocation != null) {
922
			if (outputLocation != null) {
Lines 2537-2542 Link Here
2537
	 * Returns INVALID_CLASSPATH if it has a format problem.
2544
	 * Returns INVALID_CLASSPATH if it has a format problem.
2538
	 */
2545
	 */
2539
	protected IClasspathEntry[] readClasspathFile(boolean createMarker, boolean logProblems) {
2546
	protected IClasspathEntry[] readClasspathFile(boolean createMarker, boolean logProblems) {
2547
		return readClasspathFile(createMarker, logProblems, null/*not interested in unknown elements*/);
2548
	}
2549
	
2550
	protected IClasspathEntry[] readClasspathFile(boolean createMarker, boolean logProblems, Map unknownElements) {
2540
2551
2541
		try {
2552
		try {
2542
			String xmlClasspath = getSharedProperty(CLASSPATH_FILENAME);
2553
			String xmlClasspath = getSharedProperty(CLASSPATH_FILENAME);
Lines 2548-2554 Link Here
2548
				}
2559
				}
2549
				return null;
2560
				return null;
2550
			}
2561
			}
2551
			return decodeClasspath(xmlClasspath, createMarker, logProblems);
2562
			return decodeClasspath(xmlClasspath, createMarker, logProblems, unknownElements);
2552
		} catch(CoreException e) {
2563
		} catch(CoreException e) {
2553
			// file does not exist (or not accessible)
2564
			// file does not exist (or not accessible)
2554
			if (createMarker && this.project.isAccessible()) {
2565
			if (createMarker && this.project.isAccessible()) {
Lines 2653-2659 Link Here
2653
2664
2654
		if (!this.project.isAccessible()) return false;
2665
		if (!this.project.isAccessible()) return false;
2655
2666
2656
		IClasspathEntry[] fileEntries = readClasspathFile(false /*don't create markers*/, false/*don't log problems*/);
2667
		Map unknownElements = new HashMap();
2668
		IClasspathEntry[] fileEntries = readClasspathFile(false /*don't create markers*/, false/*don't log problems*/, unknownElements);
2657
		if (fileEntries != null && isClasspathEqualsTo(newClasspath, newOutputLocation, fileEntries)) {
2669
		if (fileEntries != null && isClasspathEqualsTo(newClasspath, newOutputLocation, fileEntries)) {
2658
			// no need to save it, it is the same
2670
			// no need to save it, it is the same
2659
			return false;
2671
			return false;
Lines 2661-2667 Link Here
2661
2673
2662
		// actual file saving
2674
		// actual file saving
2663
		try {
2675
		try {
2664
			setSharedProperty(CLASSPATH_FILENAME, encodeClasspath(newClasspath, newOutputLocation, true));
2676
			setSharedProperty(CLASSPATH_FILENAME, encodeClasspath(newClasspath, newOutputLocation, true, unknownElements));
2665
			return true;
2677
			return true;
2666
		} catch (CoreException e) {
2678
		} catch (CoreException e) {
2667
			throw new JavaModelException(e);
2679
			throw new JavaModelException(e);
(-)model/org/eclipse/jdt/internal/core/UserLibrary.java (-2 / +6 lines)
Lines 177-184 Link Here
177
					String path = element.getAttribute(TAG_PATH);
177
					String path = element.getAttribute(TAG_PATH);
178
					IPath sourceAttach= element.hasAttribute(TAG_SOURCEATTACHMENT) ? new Path(element.getAttribute(TAG_SOURCEATTACHMENT)) : null;
178
					IPath sourceAttach= element.hasAttribute(TAG_SOURCEATTACHMENT) ? new Path(element.getAttribute(TAG_SOURCEATTACHMENT)) : null;
179
					IPath sourceAttachRoot= element.hasAttribute(TAG_SOURCEATTACHMENTROOT) ? new Path(element.getAttribute(TAG_SOURCEATTACHMENTROOT)) : null;
179
					IPath sourceAttachRoot= element.hasAttribute(TAG_SOURCEATTACHMENTROOT) ? new Path(element.getAttribute(TAG_SOURCEATTACHMENTROOT)) : null;
180
					IClasspathAttribute[] extraAttributes = ClasspathEntry.decodeExtraAttributes(element);
180
					NodeList children = element.getElementsByTagName("*"); //$NON-NLS-1$
181
					IAccessRule[] accessRules = ClasspathEntry.decodeAccessRules(element);
181
					boolean[] foundChildren = new boolean[children.getLength()];
182
					NodeList attributeList = ClasspathEntry.getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren);
183
					IClasspathAttribute[] extraAttributes = ClasspathEntry.decodeExtraAttributes(attributeList);
184
					attributeList = ClasspathEntry.getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren);
185
					IAccessRule[] accessRules = ClasspathEntry.decodeAccessRules(attributeList);
182
					IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(path), sourceAttach, sourceAttachRoot, accessRules, extraAttributes, false/*not exported*/);
186
					IClasspathEntry entry = JavaCore.newLibraryEntry(new Path(path), sourceAttach, sourceAttachRoot, accessRules, extraAttributes, false/*not exported*/);
183
					res.add(entry);
187
					res.add(entry);
184
				}
188
				}
(-)model/org/eclipse/jdt/internal/core/XMLWriter.java (-4 / +7 lines)
Lines 92-107 Link Here
92
		} else {
92
		} else {
93
			sb.append(">"); //$NON-NLS-1$
93
			sb.append(">"); //$NON-NLS-1$
94
		}
94
		}
95
		printString(sb.toString(), insertTab, insertNewLine);
96
		if (parameters != null && !closeTag)
97
			this.tab++;
98
99
	}
100
	public void printString(String string, boolean insertTab, boolean insertNewLine) {
95
		if (insertTab) {
101
		if (insertTab) {
96
			printTabulation();
102
			printTabulation();
97
		}
103
		}
98
		print(sb.toString());
104
		print(string);
99
		if (insertNewLine) {
105
		if (insertNewLine) {
100
			print(this.lineSeparator);
106
			print(this.lineSeparator);
101
		}
107
		}
102
		if (parameters != null && !closeTag)
103
			this.tab++;
104
105
	}
108
	}
106
	public void startTag(String name, boolean insertTab) {
109
	public void startTag(String name, boolean insertTab) {
107
		printTag(name, null/*no parameters*/, insertTab, true/*insert new line*/, false/*don't close tag*/);
110
		printTag(name, null/*no parameters*/, insertTab, true/*insert new line*/, false/*don't close tag*/);

Return to bug 101425