use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class TransformFormatterRulesJob method runInWorkspace.
/**
* {@inheritDoc}
*/
@Override
public IStatus runInWorkspace(final IProgressMonitor arg0) throws CoreException {
// TODO this way of loading formatter profiles is very dubious, to say
// the least, refer to FormatterConfigWriter for a better API
final String workspace = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
final String configLocation = workspace + "/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs";
FormatterConfigParser parser = null;
try {
parser = new FormatterConfigParser(configLocation);
} catch (final FileNotFoundException e) {
return Status.CANCEL_STATUS;
}
final FormatterConfiguration rules = parser.parseRules();
if (rules == null) {
return Status.CANCEL_STATUS;
}
try {
FormatterTransformer transformer = new FormatterTransformer(rules);
transformer.transformRules(workspace + "/test-checkstyle.xml");
} catch (CheckstylePluginException e) {
Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
throw new CoreException(status);
}
return Status.OK_STATUS;
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ProjectConfigurationFactory method getProjectConfiguration.
private static IProjectConfiguration getProjectConfiguration(InputStream in, IProject project) throws DocumentException, CheckstylePluginException {
SAXReader reader = new SAXReader();
Document document = reader.read(in);
Element root = document.getRootElement();
String version = root.attributeValue(XMLTags.FORMAT_VERSION_TAG);
if (!SUPPORTED_VERSIONS.contains(version)) {
throw new CheckstylePluginException(NLS.bind(Messages.errorUnknownFileFormat, version));
}
boolean useSimpleConfig = Boolean.valueOf(root.attributeValue(XMLTags.SIMPLE_CONFIG_TAG)).booleanValue();
boolean syncFormatter = Boolean.valueOf(root.attributeValue(XMLTags.SYNC_FORMATTER_TAG)).booleanValue();
List<ICheckConfiguration> checkConfigs = getLocalCheckConfigs(root, project);
List<FileSet> fileSets = getFileSets(root, checkConfigs);
List<IFilter> filters = getFilters(root);
return new ProjectConfiguration(project, checkConfigs, fileSets, filters, useSimpleConfig, syncFormatter);
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class MetadataFactory method parseMetadata.
@SuppressWarnings("unchecked")
private static void parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle) throws DocumentException, CheckstylePluginException {
SAXReader reader = new SAXReader();
reader.setEntityResolver(new XMLUtil.InternalDtdEntityResolver(PUBLIC2INTERNAL_DTD_MAP));
Document document = reader.read(metadataStream);
List<Element> groupElements = document.getRootElement().elements(XMLTags.RULE_GROUP_METADATA_TAG);
for (Element groupEl : groupElements) {
String groupName = groupEl.attributeValue(XMLTags.NAME_TAG).trim();
groupName = localize(groupName, metadataBundle);
// process description
String groupDesc = groupEl.elementTextTrim(XMLTags.DESCRIPTION_TAG);
groupDesc = localize(groupDesc, metadataBundle);
RuleGroupMetadata group = getRuleGroupMetadata(groupName);
if (group == null) {
boolean hidden = Boolean.valueOf(groupEl.attributeValue(XMLTags.HIDDEN_TAG)).booleanValue();
int priority = 0;
try {
priority = Integer.parseInt(groupEl.attributeValue(XMLTags.PRIORITY_TAG));
} catch (Exception e) {
CheckstyleLog.log(e);
priority = Integer.MAX_VALUE;
}
group = new RuleGroupMetadata(groupName, groupDesc, hidden, priority);
sRuleGroupMetadata.put(groupName, group);
}
// process the modules
processModules(groupEl, group, metadataBundle);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ComplexFileSetsEditor method addFileSet.
private void addFileSet() {
try {
FileSetEditDialog dialog = new FileSetEditDialog(mComposite.getShell(), null, mProject, mPropertyPage);
if (Window.OK == dialog.open()) {
FileSet fileSet = dialog.getFileSet();
mFileSets.add(fileSet);
mViewer.refresh();
mViewer.setChecked(fileSet, fileSet.isEnabled());
mPropertyPage.getContainer().updateButtons();
}
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(mComposite.getShell(), NLS.bind(Messages.errorFailedAddFileset, e.getMessage()), e, true);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ProjectClassLoader method addToClassPath.
/**
* Adds the contents of a project to list of URLs.
*
* @param project
* the project
* @param cpURLs
* the resulting list
* @param isReferenced
* true if a referenced project is processed
*/
private static void addToClassPath(IProject project, List<URL> cpURLs, boolean isReferenced, Collection<IProject> processedProjects) {
try {
// this project has already been added
if (processedProjects.contains(project)) {
return;
} else {
processedProjects.add(project);
}
// get the java project
IJavaProject javaProject = JavaCore.create(project);
// get the resolved classpath of the project
IClasspathEntry[] cpEntries = javaProject.getResolvedClasspath(true);
// iterate over classpath to create classpath urls
int size = cpEntries.length;
for (int i = 0; i < size; i++) {
int entryKind = cpEntries[i].getEntryKind();
// handle a source path
if (IClasspathEntry.CPE_SOURCE == entryKind) {
handleSourcePath(project, cpURLs, cpEntries[i], javaProject);
} else if (IClasspathEntry.CPE_PROJECT == entryKind) {
// handle a project reference
handleRefProject(cpURLs, cpEntries[i], processedProjects);
} else if (IClasspathEntry.CPE_LIBRARY == entryKind) {
// handle a library entry
handleLibrary(project, cpURLs, cpEntries[i]);
} else {
// cannot happen since we use a resolved classpath
// log as exception
CheckstylePluginException ex = new CheckstylePluginException(NLS.bind(Messages.errorUnknownClasspathEntry, cpEntries[i].getPath()));
CheckstyleLog.log(ex);
}
}
} catch (JavaModelException jme) {
CheckstyleLog.log(jme);
}
}
Aggregations