org.eclipse.jdt.core.IAccessRule Java Examples

The following examples show how to use org.eclipse.jdt.core.IAccessRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateAppEngineFlexWtpProject.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private static void addDependenciesToClasspath(IProject project, IFolder folder,
    IProgressMonitor monitor)  throws CoreException {
  List<IClasspathEntry> newEntries = new ArrayList<>();

  IClasspathAttribute[] nonDependencyAttribute =
      new IClasspathAttribute[] {UpdateClasspathAttributeUtil.createNonDependencyAttribute()};

  // Add all the jars under lib folder to the classpath
  File libFolder = folder.getLocation().toFile();
  for (File file : libFolder.listFiles()) {
    IPath path = Path.fromOSString(file.toPath().toString());
    newEntries.add(JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0],
        nonDependencyAttribute, false /* isExported */));
  }

  ClasspathUtil.addClasspathEntries(project, newEntries, monitor);
}
 
Example #2
Source File: MainProjectWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void putDefaultClasspathEntriesIn(Collection<IClasspathEntry> classpathEntries) {
	final IPath newPath = this.jreGroup.getJREContainerPath();
	if (newPath != null) {
		classpathEntries.add(JavaCore.newContainerEntry(newPath));
	} else {
		final IClasspathEntry[] entries = PreferenceConstants.getDefaultJRELibrary();
		classpathEntries.addAll(Arrays.asList(entries));
	}

	final IClasspathEntry sarlClasspathEntry = JavaCore.newContainerEntry(
			SARLClasspathContainerInitializer.CONTAINER_ID,
			new IAccessRule[0],
			new IClasspathAttribute[0],
			true);
	classpathEntries.add(sarlClasspathEntry);
}
 
Example #3
Source File: LibraryClasspathContainerSerializerTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private static IAccessRule newAccessRule(final String pattern, final boolean accessible) {
  return new IAccessRule() {

    @Override
    public boolean ignoreIfBetter() {
      return false;
    }

    @Override
    public IPath getPattern() {
      return new Path(pattern);
    }

    @Override
    public int getKind() {
      if (accessible) {
        return IAccessRule.K_ACCESSIBLE;
      } else {
        return IAccessRule.K_NON_ACCESSIBLE;
      }
    }
  };
}
 
Example #4
Source File: UserLibraryPreferencePage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean canEdit(List<Object> list) {
	if (list.size() != 1)
		return false;

	Object firstElement= list.get(0);
	if (firstElement instanceof IAccessRule)
		return false;
	if (firstElement instanceof CPListElementAttribute) {
		CPListElementAttribute attrib= (CPListElementAttribute) firstElement;
		if (!attrib.isBuiltIn()) {
			ClasspathAttributeConfiguration config= fAttributeDescriptors.get(attrib.getKey());
			return config != null && config.canEdit(attrib.getClasspathAttributeAccess());
		}
	}
	return true;
}
 
Example #5
Source File: ProjectsWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void removeEntry() {
	List<Object> selElements= fProjectsList.getSelectedElements();
	for (int i= selElements.size() - 1; i >= 0 ; i--) {
		Object elem= selElements.get(i);
		if (elem instanceof CPListElementAttribute) {
			CPListElementAttribute attrib= (CPListElementAttribute) elem;
			if (attrib.isBuiltIn()) {
				String key= attrib.getKey();
				Object value= null;
				if (key.equals(CPListElement.ACCESSRULES)) {
					value= new IAccessRule[0];
				}
				attrib.getParent().setAttribute(key, value);
			} else {
				removeCustomAttribute(attrib);
			}
			selElements.remove(i);
		}
	}
	if (selElements.isEmpty()) {
		fProjectsList.refresh();
		fClassPathList.dialogFieldChanged(); // validate
	} else {
		fProjectsList.removeElements(selElements);
	}
}
 
Example #6
Source File: CPListElementSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int category(Object obj) {
	if (obj instanceof CPListElement) {
		CPListElement element= (CPListElement) obj;
		if (element.getParentContainer() != null) {
			return CONTAINER_ENTRY;
		}
		switch (element.getEntryKind()) {
		case IClasspathEntry.CPE_LIBRARY:
			return LIBRARY;
		case IClasspathEntry.CPE_PROJECT:
			return PROJECT;
		case IClasspathEntry.CPE_SOURCE:
			return SOURCE;
		case IClasspathEntry.CPE_VARIABLE:
			return VARIABLE;
		case IClasspathEntry.CPE_CONTAINER:
			return CONTAINER;
		}
	} else if (obj instanceof CPListElementAttribute) {
		return ATTRIBUTE;
	} else if (obj instanceof IAccessRule) {
		return ATTRIBUTE;
	}
	return OTHER;
}
 
Example #7
Source File: CPListLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getText(Object element) {
	if (element instanceof CPListElement) {
		return getCPListElementText((CPListElement) element);
	} else if (element instanceof CPListElementAttribute) {
		CPListElementAttribute attribute= (CPListElementAttribute) element;
		String text= getCPListElementAttributeText(attribute);
		if (attribute.isNonModifiable()) {
			return Messages.format(NewWizardMessages.CPListLabelProvider_non_modifiable_attribute, text);
		}
		return text;
	} else if (element instanceof CPUserLibraryElement) {
		return getCPUserLibraryText((CPUserLibraryElement) element);
	} else if (element instanceof IAccessRule) {
		IAccessRule rule= (IAccessRule) element;
		return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_label, new String[] { AccessRulesLabelProvider.getResolutionLabel(rule.getKind()), BasicElementLabels.getPathLabel(rule.getPattern(), false)});
	}
	return super.getText(element);
}
 
Example #8
Source File: XtendClasspathContainer.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private void addEntry(final List<IClasspathEntry> cpEntries, final String bundleId) {
	Bundle bundle = Platform.getBundle(bundleId);
	if (bundle != null) {
		IPath bundlePath = bundlePath(bundle);
		IPath sourceBundlePath = calculateSourceBundlePath(bundle, bundlePath);
		IClasspathAttribute[] extraAttributes = null;
		if (XtendClasspathContainer.XTEXT_XBASE_LIB_BUNDLE_ID.equals(bundleId)
				|| XtendClasspathContainer.XTEND_LIB_BUNDLE_ID.equals(bundleId)
				|| XtendClasspathContainer.XTEND_LIB_MACRO_BUNDLE_ID.equals(bundleId)) {
			extraAttributes = new IClasspathAttribute[] { JavaCore.newClasspathAttribute(
					IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, calculateJavadocURL()) };
		}
		cpEntries.add(JavaCore.newLibraryEntry(bundlePath, sourceBundlePath, null, new IAccessRule[] {},
				extraAttributes, false));
	}
}
 
Example #9
Source File: TypeFilter.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean isFiltered(TypeNameMatch match) {
	boolean filteredByPattern= getDefault().filter(match.getFullyQualifiedName());
	if (filteredByPattern) {
		return true;
	}

	int accessibility= match.getAccessibility();
	switch (accessibility) {
		case IAccessRule.K_NON_ACCESSIBLE:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK));
		case IAccessRule.K_DISCOURAGED:
			return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK));
		default:
			return false;
	}
}
 
Example #10
Source File: AccessRulesDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ListDialogField<IAccessRule> createListContents(CPListElement entryToEdit) {
	String label= NewWizardMessages.AccessRulesDialog_rules_label;
	String[] buttonLabels= new String[] {
			NewWizardMessages.AccessRulesDialog_rules_add,
			NewWizardMessages.AccessRulesDialog_rules_edit,
			null,
			NewWizardMessages.AccessRulesDialog_rules_up,
			NewWizardMessages.AccessRulesDialog_rules_down,
			null,
			NewWizardMessages.AccessRulesDialog_rules_remove
	};

	TypeRestrictionAdapter adapter= new TypeRestrictionAdapter();
	AccessRulesLabelProvider labelProvider= new AccessRulesLabelProvider();

	ListDialogField<IAccessRule> patternList= new ListDialogField<IAccessRule>(adapter, buttonLabels, labelProvider);
	patternList.setDialogFieldListener(adapter);

	patternList.setLabelText(label);
	patternList.setRemoveButtonIndex(IDX_REMOVE);
	patternList.setUpButtonIndex(IDX_UP);
	patternList.setDownButtonIndex(IDX_DOWN);
	patternList.enableButton(IDX_EDIT, false);

	IAccessRule[] rules= (IAccessRule[]) entryToEdit.getAttribute(CPListElement.ACCESSRULES);
	ArrayList<IAccessRule> elements= new ArrayList<IAccessRule>(rules.length);
	for (int i= 0; i < rules.length; i++) {
		elements.add(rules[i]);
	}
	patternList.setElements(elements);
	patternList.selectFirstElement();
	return patternList;
}
 
Example #11
Source File: JavaClasspathParser.java    From sarl with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:innerassignment" })
private static IAccessRule[] decodeAccessRules(NodeList list) {
    if (list == null) {
        return null;
    }
    final int length = list.getLength();
    if (length == 0) {
        return null;
    }
    IAccessRule[] result = new IAccessRule[length];
    int index = 0;
    for (int i = 0; i < length; i++) {
        final Node accessRule = list.item(i);
        if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
            final Element elementAccessRule = (Element) accessRule;
            final String pattern = elementAccessRule.getAttribute(ClasspathEntry.TAG_PATTERN);
            if (pattern == null) {
                continue;
            }
            final String tagKind = elementAccessRule.getAttribute(ClasspathEntry.TAG_KIND);
            final int kind;
            if (ClasspathEntry.TAG_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_NON_ACCESSIBLE.equals(tagKind)) {
                kind = IAccessRule.K_NON_ACCESSIBLE;
            } else if (ClasspathEntry.TAG_DISCOURAGED.equals(tagKind)) {
                kind = IAccessRule.K_DISCOURAGED;
            } else {
                continue;
            }
            final boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(ClasspathEntry.TAG_IGNORE_IF_BETTER)); //$NON-NLS-1$
            result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
        }
    }
    if (index != length) {
        System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
    }
    return result;
}
 
Example #12
Source File: AccessRulesDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void doCustomButtonPressed(ListDialogField<IAccessRule> field, int index) {
	if (index == IDX_ADD) {
		addEntry(field);
	} else if (index == IDX_EDIT) {
		editEntry(field);
	}
}
 
Example #13
Source File: AccessRulesDialog.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void editEntry(ListDialogField<IAccessRule> field) {

		List<IAccessRule> selElements= field.getSelectedElements();
		if (selElements.size() != 1) {
			return;
		}
		IAccessRule rule= selElements.get(0);
		AccessRuleEntryDialog dialog= new AccessRuleEntryDialog(getShell(), rule, fCurrElement);
		if (dialog.open() == Window.OK) {
			field.replaceElement(rule, dialog.getRule());
		}
	}
 
Example #14
Source File: ProjectsWorkbookPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canRemove(List<?> selElements) {
	if (selElements.size() == 0) {
		return false;
	}

	for (int i= 0; i < selElements.size(); i++) {
		Object elem= selElements.get(i);
		if (elem instanceof CPListElementAttribute) {
			CPListElementAttribute attrib= (CPListElementAttribute) elem;
			if (attrib.isNonModifiable()) {
				return false;
			}
			if (attrib.isBuiltIn()) {
				if (CPListElement.ACCESSRULES.equals(attrib.getKey())) {
					if (((IAccessRule[]) attrib.getValue()).length == 0) {
						return false;
					}
				} else if (attrib.getValue() == null) {
					return false;
				}
			} else {
				if  (!canRemoveCustomAttribute(attrib)) {
					return false;
				}
			}
		}
	}
	return true;
}
 
Example #15
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public Image getColumnImage(Object element, int columnIndex) {
	if (element instanceof IAccessRule) {
		IAccessRule rule= (IAccessRule) element;
		if (columnIndex == 0) {
			return getResolutionImage(rule.getKind());
		}
	}
	return null;
}
 
Example #16
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getColumnText(Object element, int columnIndex) {
	if (element instanceof IAccessRule) {
		IAccessRule rule= (IAccessRule) element;
		if (columnIndex == 0) {
			return getResolutionLabel(rule.getKind());
		} else {
			return BasicElementLabels.getPathLabel(rule.getPattern(), false);
		}
	}
	return element.toString();
}
 
Example #17
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static Image getResolutionImage(int kind) {
	switch (kind) {
		case IAccessRule.K_ACCESSIBLE:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_NLS_TRANSLATE);
		case IAccessRule.K_DISCOURAGED:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_WARNING);
		case IAccessRule.K_NON_ACCESSIBLE:
			return JavaPluginImages.get(JavaPluginImages.IMG_OBJS_REFACTORING_ERROR);
	}
	return null;
}
 
Example #18
Source File: AccessRulesLabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String getResolutionLabel(int kind) {
	switch (kind) {
		case IAccessRule.K_ACCESSIBLE:
			return NewWizardMessages.AccessRulesLabelProvider_kind_accessible;
		case IAccessRule.K_DISCOURAGED:
			return NewWizardMessages.AccessRulesLabelProvider_kind_discouraged;
		case IAccessRule.K_NON_ACCESSIBLE:
			return NewWizardMessages.AccessRulesLabelProvider_kind_non_accessible;
	}
	return ""; //$NON-NLS-1$
}
 
Example #19
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static StringBuffer appendEncodedAccessRules(IAccessRule[] rules, StringBuffer buf) {
	if (rules != null) {
		buf.append('[').append(rules.length).append(']');
		for (int i= 0; i < rules.length; i++) {
			appendEncodePath(rules[i].getPattern(), buf).append(';');
			buf.append(rules[i].getKind()).append(';');
		}
	} else {
		buf.append('[').append(']');
	}
	return buf;
}
 
Example #20
Source File: CPListElement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public StringBuffer appendEncodedSettings(StringBuffer buf) {
	buf.append(fEntryKind).append(';');
	if (getLinkTarget() == null) {
		appendEncodePath(fPath, buf).append(';');
	} else {
		appendEncodePath(fPath, buf).append('-').append('>');
		appendEncodePath(getLinkTarget(), buf).append(';');
	}
	buf.append(Boolean.valueOf(fIsExported)).append(';');
	for (int i= 0; i < fChildren.size(); i++) {
		Object curr= fChildren.get(i);
		if (curr instanceof CPListElementAttribute) {
			CPListElementAttribute elem= (CPListElementAttribute) curr;
			if (elem.isBuiltIn()) {
				String key= elem.getKey();
				if (OUTPUT.equals(key) || SOURCEATTACHMENT.equals(key)) {
					appendEncodePath((IPath) elem.getValue(), buf).append(';');
				} else if (EXCLUSION.equals(key) || INCLUSION.equals(key)) {
					appendEncodedFilter((IPath[]) elem.getValue(), buf).append(';');
				} else if (ACCESSRULES.equals(key)) {
					appendEncodedAccessRules((IAccessRule[]) elem.getValue(), buf).append(';');
				} else if (COMBINE_ACCESSRULES.equals(key)) {
					buf.append(((Boolean) elem.getValue()).booleanValue()).append(';');
				}
			} else {
				appendEncodedString((String) elem.getValue(), buf);
			}
		}
	}
	return buf;
}
 
Example #21
Source File: ClasspathAccessRule.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static int toProblemId(int kind) {
	boolean ignoreIfBetter = (kind & IAccessRule.IGNORE_IF_BETTER) != 0;
	switch (kind & ~IAccessRule.IGNORE_IF_BETTER) {
		case K_NON_ACCESSIBLE:
			return ignoreIfBetter ? IProblem.ForbiddenReference | AccessRule.IgnoreIfBetter : IProblem.ForbiddenReference;
		case K_DISCOURAGED:
			return ignoreIfBetter ? IProblem.DiscouragedReference | AccessRule.IgnoreIfBetter : IProblem.DiscouragedReference;
		default:
			return ignoreIfBetter ? AccessRule.IgnoreIfBetter : 0;
	}
}
 
Example #22
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ClasspathEntry(
		int contentKind,
		int entryKind,
		IPath path,
		IPath[] inclusionPatterns,
		IPath[] exclusionPatterns,
		IPath sourceAttachmentPath,
		IPath sourceAttachmentRootPath,
		IPath specificOutputLocation,
		boolean isExported,
		IAccessRule[] accessRules,
		boolean combineAccessRules,
		IClasspathAttribute[] extraAttributes) {

	this(	contentKind, 
			entryKind, 
			path, 
			inclusionPatterns, 
			exclusionPatterns, 
			sourceAttachmentPath, 
			sourceAttachmentRootPath, 
			specificOutputLocation,
			null,
			isExported,
			accessRules,
			combineAccessRules,
			extraAttributes);
}
 
Example #23
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
static IAccessRule[] decodeAccessRules(NodeList list) {
	if (list == null) return null;
	int length = list.getLength();
	if (length == 0) return null;
	IAccessRule[] result = new IAccessRule[length];
	int index = 0;
	for (int i = 0; i < length; i++) {
		Node accessRule = list.item(i);
		if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
			Element elementAccessRule = (Element) accessRule;
			String pattern = elementAccessRule.getAttribute(TAG_PATTERN);
			if (pattern == null) continue;
			String tagKind =  elementAccessRule.getAttribute(TAG_KIND);
			int kind;
			if (TAG_ACCESSIBLE.equals(tagKind))
				kind = IAccessRule.K_ACCESSIBLE;
			else if (TAG_NON_ACCESSIBLE.equals(tagKind))
				kind = IAccessRule.K_NON_ACCESSIBLE;
			else if (TAG_DISCOURAGED.equals(tagKind))
				kind = IAccessRule.K_DISCOURAGED;
			else
				continue;
			boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER)); //$NON-NLS-1$
			result[index++] = new ClasspathAccessRule(new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind);
		}
	}
	if (index != length)
		System.arraycopy(result, 0, result = new IAccessRule[index], 0, index);
	return result;
}
 
Example #24
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IClasspathEntry#getAccessRules()
 */
public IAccessRule[] getAccessRules() {
	if (this.accessRuleSet == null) return NO_ACCESS_RULES;
	AccessRule[] rules = this.accessRuleSet.getAccessRules();
	int length = rules.length;
	if (length == 0) return NO_ACCESS_RULES;
	IAccessRule[] result = new IAccessRule[length];
	System.arraycopy(rules, 0, result, 0, length);
	return result;
}
 
Example #25
Source File: CreateAppEngineWtpProject.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static void addJunit4ToClasspath(IProject newProject, IProgressMonitor monitor)
    throws CoreException {
  IClasspathAttribute nonDependencyAttribute =
      UpdateClasspathAttributeUtil.createNonDependencyAttribute();
  IClasspathEntry junit4Container = JavaCore.newContainerEntry(
      JUnitCore.JUNIT4_CONTAINER_PATH,
      new IAccessRule[0],
      new IClasspathAttribute[] {nonDependencyAttribute},
      false);
  ClasspathUtil.addClasspathEntry(newProject, junit4Container, monitor);
}
 
Example #26
Source File: XbaseUIValidator.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected RestrictionKind computeRestriction(IJavaProject project, IType type) {
	try {
		IPackageFragmentRoot root = (IPackageFragmentRoot) type.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
		if (root == null) {
			return RestrictionKind.VALID;
		}
		IClasspathEntry entry = getResolvedClasspathEntry(project, root);
		if (entry == null) {
			return RestrictionKind.VALID;
		}
		IAccessRule[] rules = entry.getAccessRules();
		String typePath = type.getFullyQualifiedName().replace('.', '/');
		char[] typePathAsArray = typePath.toCharArray();
		for(IAccessRule rule: rules) {
			char[] patternArray = ((ClasspathAccessRule)rule).pattern;
			if (CharOperation.pathMatch(patternArray, typePathAsArray, true, '/')) {
				if (rule.getKind() == IAccessRule.K_DISCOURAGED) {
					return RestrictionKind.DISCOURAGED;
				} else if (rule.getKind() == IAccessRule.K_NON_ACCESSIBLE) {
					return RestrictionKind.FORBIDDEN;
				}
				return RestrictionKind.VALID;
			}
		}
	} catch(JavaModelException jme) {
		// ignore
	}
	return RestrictionKind.VALID;
}
 
Example #27
Source File: LibraryClasspathContainerSerializerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws IOException, CoreException {
  serializedContainer = loadFile("testdata/serializedContainer.json");
  
  List<IClasspathEntry> classpathEntries = Arrays.asList(
      newClasspathEntry(IClasspathEntry.CPE_LIBRARY, "/test/path/to/jar",
          "/test/path/to/src", new IClasspathAttribute[] {newAttribute("attrName", "attrValue")},
          new IAccessRule[] {newAccessRule("/com/example/accessible", true /* accessible */),
              newAccessRule("/com/example/nonaccessible", false /* accessible */)},
          true));

  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      IJavaProject project = invocation.getArgumentAt(0, IJavaProject.class);
      String fileId = invocation.getArgumentAt(1, String.class);
      IPath path = stateLocationProvider.getContainerStateFile(project, fileId, false);
      if (path != null && path.toFile() != null) {
        path.toFile().delete();
      }
      return null;
    }
  }).when(stateLocationProvider).removeContainerStateFile(any(IJavaProject.class), anyString());

  when(binaryBaseLocationProvider.getBaseLocation()).thenReturn(new Path("/test"));
  when(sourceBaseLocationProvider.getBaseLocation()).thenReturn(new Path("/test"));
  MavenCoordinates coordinates = new MavenCoordinates.Builder()
      .setGroupId("com.google").setArtifactId("jarartifact").build();
  LibraryFile libraryFile = new LibraryFile(coordinates);
  List<LibraryFile> libraryFiles = new ArrayList<>();
  libraryFiles.add(libraryFile);
  container = new LibraryClasspathContainer(new Path(CONTAINER_PATH), CONTAINER_DESCRIPTION,
      classpathEntries, libraryFiles);
}
 
Example #28
Source File: LibraryClasspathContainerSerializerTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static void compare(LibraryClasspathContainer expected,
    LibraryClasspathContainer actual) {
  assertEquals(expected.getPath(), actual.getPath());
  assertEquals(expected.getKind(), actual.getKind());
  assertEquals(expected.getDescription(), actual.getDescription());
  for (int i = 0; i < expected.getClasspathEntries().length; i++) {
    IClasspathEntry classpathEntry = expected.getClasspathEntries()[i];
    IClasspathEntry otherClasspathEntry = actual.getClasspathEntries()[i];
    assertEquals(classpathEntry.getPath(), otherClasspathEntry.getPath());
    assertEquals(classpathEntry.getEntryKind(), otherClasspathEntry.getEntryKind());
    assertEquals(classpathEntry.getSourceAttachmentPath(),
        otherClasspathEntry.getSourceAttachmentPath());
    assertEquals(classpathEntry.isExported(), otherClasspathEntry.isExported());
    for (int j = 0; j < classpathEntry.getAccessRules().length; j++) {
      IAccessRule accessRule = classpathEntry.getAccessRules()[j];
      IAccessRule otherAccessRule = otherClasspathEntry.getAccessRules()[j];
      assertEquals(accessRule.getKind(), otherAccessRule.getKind());
      assertEquals(accessRule.getPattern(), otherAccessRule.getPattern());
    }
    for (int k = 0; k < classpathEntry.getExtraAttributes().length; k++) {
      IClasspathAttribute classpathAttribute = classpathEntry.getExtraAttributes()[k];
      IClasspathAttribute otherClasspathAttribute = otherClasspathEntry.getExtraAttributes()[k];
      assertEquals(classpathAttribute.getName(), otherClasspathAttribute.getName());
      assertEquals(classpathAttribute.getValue(), otherClasspathAttribute.getValue());
    }
  }
  
  List<LibraryFile> libraryFiles = actual.getLibraryFiles();
  if (libraryFiles.size() != 0) {
    for (int i = 0; i < libraryFiles.size(); i++) {
      assertEquals(libraryFiles.get(i), actual.getLibraryFiles().get(i));
    }
  }
}
 
Example #29
Source File: BuildPath.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static IClasspathEntry makeClasspathEntry(Library library) throws CoreException {
  IClasspathAttribute[] classpathAttributes = new IClasspathAttribute[1];
  if (library.isExport()) {
    boolean isWebApp = true;
    classpathAttributes[0] = UpdateClasspathAttributeUtil.createDependencyAttribute(isWebApp);
  } else {
    classpathAttributes[0] = UpdateClasspathAttributeUtil.createNonDependencyAttribute();
  }
  // in practice, this method will only be called for the master library
  IPath containerPath = new Path(LibraryClasspathContainer.CONTAINER_PATH_PREFIX)
      .append(library.getId());
  return JavaCore.newContainerEntry(containerPath, new IAccessRule[0], classpathAttributes,
      false);
}
 
Example #30
Source File: SerializableClasspathEntry.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private void setAccessRules(IAccessRule[] accessRules) {
  this.accessRules = new SerializableAccessRules[accessRules.length];
  for (int i = 0; i < accessRules.length; i++) {
    IAccessRule rule = accessRules[i];
    this.accessRules[i] = new SerializableAccessRules(rule);
  }
}