use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckstylePropertyPage method createContents.
/**
* {@inheritDoc}
*/
@Override
public Control createContents(Composite parent) {
Composite container = null;
try {
this.mPageController = new PageController();
// suppress default- & apply-buttons
noDefaultAndApplyButton();
mMainTab = new TabFolder(parent, SWT.TOP);
mMainTab.setLayoutData(new GridData(GridData.FILL_BOTH));
mMainTab.addSelectionListener(mPageController);
// create the main container
container = new Composite(mMainTab, SWT.NULL);
container.setLayout(new FormLayout());
container.setLayoutData(new GridData(GridData.FILL_BOTH));
// create the checkbox to enable/disable the simple configuration
this.mChkSimpleConfig = new Button(container, SWT.CHECK);
this.mChkSimpleConfig.setText(Messages.CheckstylePropertyPage_btnUseSimpleConfig);
this.mChkSimpleConfig.addSelectionListener(this.mPageController);
this.mChkSimpleConfig.setSelection(mProjectConfig.isUseSimpleConfig());
FormData fd = new FormData();
// fd.left = new FormAttachment(this.mChkEnable, 0, SWT.RIGHT);
fd.top = new FormAttachment(0, 3);
fd.right = new FormAttachment(100, -3);
this.mChkSimpleConfig.setLayoutData(fd);
// create the checkbox to enable/disable checkstyle
this.mChkEnable = new Button(container, SWT.CHECK);
this.mChkEnable.setText(Messages.CheckstylePropertyPage_btnActivateCheckstyle);
this.mChkEnable.addSelectionListener(this.mPageController);
this.mChkEnable.setSelection(mCheckstyleInitiallyActivated);
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(0, 3);
fd.right = new FormAttachment(this.mChkSimpleConfig, 3, SWT.LEFT);
this.mChkEnable.setLayoutData(fd);
// create the checkbox for formatter syncing
this.mChkSyncFormatter = new Button(container, SWT.CHECK);
this.mChkSyncFormatter.setText(Messages.CheckstylePropertyPage_btnSyncFormatter);
this.mChkSyncFormatter.addSelectionListener(this.mPageController);
this.mChkSyncFormatter.setSelection(mProjectConfig.isSyncFormatter());
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(this.mChkEnable, 3, SWT.BOTTOM);
this.mChkSyncFormatter.setLayoutData(fd);
// create the configuration area
mFileSetsContainer = new Composite(container, SWT.NULL);
final Control configArea = createFileSetsArea(mFileSetsContainer);
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(this.mChkSyncFormatter, 6, SWT.BOTTOM);
fd.right = new FormAttachment(100, -3);
fd.bottom = new FormAttachment(45);
configArea.setLayoutData(fd);
// create the filter area
final Control filterArea = createFilterArea(container);
fd = new FormData();
fd.left = new FormAttachment(0, 3);
fd.top = new FormAttachment(configArea, 3, SWT.BOTTOM);
fd.right = new FormAttachment(100, -3);
fd.bottom = new FormAttachment(100, -3);
fd.width = 500;
filterArea.setLayoutData(fd);
// create the local configurations area
Control localConfigArea = createLocalConfigArea(mMainTab);
TabItem mainItem = new TabItem(mMainTab, SWT.NULL);
mainItem.setControl(container);
mainItem.setText(Messages.CheckstylePropertyPage_tabMain);
TabItem localItem = new TabItem(mMainTab, SWT.NULL);
localItem.setControl(localConfigArea);
localItem.setText(Messages.CheckstylePropertyPage_tabCheckConfigs);
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), Messages.errorOpeningPropertiesPage, e, true);
}
return container;
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class FileMatchPatternEditDialog method okPressed.
/**
* @see org.eclipse.jface.dialogs.Dialog#okPressed()
*/
@Override
protected void okPressed() {
String pattern = mFileMatchPatternText.getText();
try {
//
// Try compiling the pattern using the regular expression compiler.
//
Pattern.compile(pattern);
if (mPattern == null) {
mPattern = new FileMatchPattern(pattern);
} else {
mPattern.setMatchPattern(pattern);
}
mPattern.setIsIncludePattern(mIncludeButton.getSelection());
} catch (PatternSyntaxException e) {
this.setErrorMessage(e.getLocalizedMessage());
return;
} catch (CheckstylePluginException e) {
this.setErrorMessage(e.getLocalizedMessage());
return;
}
super.okPressed();
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class ConfigurationWriter method write.
/**
* Writes the modules of the configuration to the output stream.
*
* @param out
* the ouput stream.
* @param modules
* the modules
* @param checkConfig
* the Check configuration object
* @throws CheckstylePluginException
* error writing the checkstyle configuration
*/
public static void write(OutputStream out, List<Module> modules, ICheckConfiguration checkConfig) throws CheckstylePluginException {
try {
// pass the configured modules through the save filters
SaveFilters.process(modules);
Document doc = DocumentHelper.createDocument();
doc.addDocType(XMLTags.MODULE_TAG, "-//Puppy Crawl//DTD Check Configuration 1.3//EN", "http://www.puppycrawl.com/dtds/configuration_1_3.dtd");
// $NON-NLS-1$
String lineSeperator = System.getProperty("line.separator");
String comment = lineSeperator + // $NON-NLS-1$
" This configuration file was written by the eclipse-cs plugin configuration editor" + lineSeperator;
doc.addComment(comment);
// write out name and description as comment
String description = // $NON-NLS-1$
lineSeperator + " Checkstyle-Configuration: " + checkConfig.getName() + lineSeperator + // $NON-NLS-1$
" Description: " + (Strings.emptyToNull(checkConfig.getDescription()) != null ? lineSeperator + checkConfig.getDescription() + lineSeperator : // $NON-NLS-1$
"none" + lineSeperator);
doc.addComment(description);
// find the root module (Checker)
// the root module is the only module that has no parent
List<Module> rootModules = getChildModules(null, modules);
if (rootModules.size() < 1) {
throw new CheckstylePluginException(Messages.errorNoRootModule);
}
if (rootModules.size() > 1) {
throw new CheckstylePluginException(Messages.errorMoreThanOneRootModule);
}
writeModule(rootModules.get(0), doc, null, modules);
out.write(XMLUtil.toByteArray(doc));
} catch (IOException e) {
CheckstylePluginException.rethrow(e);
}
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class RemoteConfigurationType method getBytesFromURLConnection.
@Override
protected byte[] getBytesFromURLConnection(URLConnection connection) throws IOException {
byte[] configurationFileData = null;
// set timeouts - bug 2941010
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
if (connection instanceof HttpURLConnection) {
if (!sFailedWith401URLs.contains(connection.getURL().toString())) {
HttpURLConnection httpConn = (HttpURLConnection) connection;
httpConn.setInstanceFollowRedirects(true);
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
try {
RemoteConfigAuthenticator.removeCachedAuthInfo(connection.getURL());
} catch (CheckstylePluginException e) {
CheckstyleLog.log(e);
}
// add to 401ed URLs
sFailedWith401URLs.add(connection.getURL().toString());
throw new IOException(Messages.RemoteConfigurationType_msgUnAuthorized);
}
} else {
// don't retry since we just get another 401
throw new IOException(Messages.RemoteConfigurationType_msgUnAuthorized);
}
}
try (InputStream in = connection.getInputStream()) {
configurationFileData = ByteStreams.toByteArray(in);
}
return configurationFileData;
}
use of net.sf.eclipsecs.core.util.CheckstylePluginException in project eclipse-cs by checkstyle.
the class CheckstyleBuilder method build.
/**
* {@inheritDoc}
*/
@Override
protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor) throws CoreException {
// get the associated project for this builder
IProject project = getProject();
// remove project level error markers
project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
if (CheckstyleNature.hasCorrectBuilderOrder(project)) {
//
// get the project configuration
//
IProjectConfiguration config = null;
try {
config = ProjectConfigurationFactory.getConfiguration(project);
} catch (CheckstylePluginException e) {
Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage() != null ? e.getMessage() : Messages.CheckstyleBuilder_msgErrorUnknown, e);
throw new CoreException(status);
}
Collection<IResource> resources = null;
// get the delta of the latest changes
IResourceDelta resourceDelta = getDelta(project);
IFilter[] filters = config.getFilters().toArray(new IFilter[config.getFilters().size()]);
// find the files for the build
if (resourceDelta != null) {
resources = getResources(resourceDelta, filters);
} else {
resources = getResources(project, filters);
}
handleBuildSelection(resources, config, monitor, project, kind);
} else {
// the builder order is wrong. Refuse to check and create a error
// marker.
// remove all existing Checkstyle markers
project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
Map<String, Object> markerAttributes = new HashMap<>();
markerAttributes.put(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
markerAttributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
markerAttributes.put(IMarker.MESSAGE, NLS.bind(Messages.CheckstyleBuilder_msgWrongBuilderOrder, project.getName()));
// enables own category under Java Problem Type
// setting for Problems view (RFE 1530366)
// $NON-NLS-1$
markerAttributes.put("categoryId", new Integer(999));
// create a marker for the actual resource
IMarker marker = project.createMarker(CheckstyleMarker.MARKER_ID);
marker.setAttributes(markerAttributes);
}
return new IProject[] { project };
}
Aggregations