Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
CLOSED - #325: Project setting to proceed building bundle when compile
Browse files Browse the repository at this point in the history
  • Loading branch information
njbartlett committed Dec 13, 2011
1 parent c2b9eee commit 068724d
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 25 deletions.
15 changes: 15 additions & 0 deletions bndtools.core/_plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -738,5 +738,20 @@
<extension point="bndtools.core.validators">
<validator name="BSN check" class="org.bndtools.core.build.validate.BsnValidator"/>
</extension>

<extension point="org.eclipse.ui.propertyPages">
<page
id="org.bndtools.core.propPages.project"
name="Bndtools"
adaptable="true"
objectClass="org.eclipse.core.resources.IProject"
class="bndtools.preferences.ui.BndProjectPropertyPage">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject">
<test property="org.eclipse.core.resources.projectNature" value="bndtools.core.bndnature"/>
</adapt>
</enabledWhen>
</page>
</extension>

</plugin>
85 changes: 60 additions & 25 deletions bndtools.core/src/bndtools/builder/NewBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.core.resources.IResourceDeltaVisitor;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
Expand All @@ -31,9 +32,9 @@
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaModelMarker;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import aQute.bnd.build.Project;
import aQute.bnd.build.Workspace;
Expand All @@ -43,6 +44,7 @@
import bndtools.Plugin;
import bndtools.api.IValidator;
import bndtools.classpath.BndContainerInitializer;
import bndtools.preferences.CompileErrorAction;

public class NewBuilder extends IncrementalProjectBuilder {

Expand All @@ -63,8 +65,6 @@ public class NewBuilder extends IncrementalProjectBuilder {

@Override
protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, "Building bundles", 0);

IPreferenceStore prefs = Plugin.getDefault().getPreferenceStore();
logLevel = prefs.getInt(Plugin.PREF_BUILD_LOGGING);

Expand Down Expand Up @@ -414,25 +414,47 @@ private static IPath calculateTargetDirPath(Project model) throws Exception {
return targetDirPath;
}

private enum Action { build, delete };

/**
* @param force Whether to force bnd to build
* @return Whether any files were built
*/
private boolean rebuild(boolean force) throws Exception {
clearBuildMarkers();

// Abort build if compilation errors exist
// Check if compilation errors exist, and if so check the project settings for what to do about that...
Action buildAction = Action.build;
if (hasBlockingErrors()) {
addBuildMarker(String.format("Will not build OSGi bundle(s) for project %s until compilation problems are fixed.", model.getName()), IMarker.SEVERITY_ERROR);
log(LOG_BASIC, "SKIPPING due to Java problem markers");
return false;
ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(getProject()), Plugin.PLUGIN_ID);
switch (CompileErrorAction.parse(store.getString(CompileErrorAction.PREFERENCE_KEY))) {
case skip:
addBuildMarker(String.format("Will not build OSGi bundle(s) for project %s until compilation problems are fixed.", model.getName()), IMarker.SEVERITY_ERROR);
log(LOG_BASIC, "SKIPPING due to Java problem markers");
return false;
case build:
buildAction = Action.build;
break;
case delete:
buildAction = Action.delete;
break;
}
} else if (!classpathErrors.isEmpty()) {
addBuildMarker("Will not build OSGi bundle(s) for project %s until classpath resolution problems are fixed.", IMarker.SEVERITY_ERROR);
log(LOG_BASIC, "SKIPPING due to classpath resolution problem markers");
return false;
ScopedPreferenceStore store = new ScopedPreferenceStore(new ProjectScope(getProject()), Plugin.PLUGIN_ID);
switch (CompileErrorAction.parse(store.getString(CompileErrorAction.PREFERENCE_KEY))) {
case skip:
addBuildMarker("Will not build OSGi bundle(s) for project %s until classpath resolution problems are fixed.", IMarker.SEVERITY_ERROR);
log(LOG_BASIC, "SKIPPING due to classpath resolution problem markers");
return false;
case build:
buildAction = Action.build;
break;
case delete:
buildAction = Action.delete;
break;
}
}

log(LOG_BASIC, "REBUILDING, force=%b", force);
log(LOG_BASIC, "REBUILDING, force=%b, action=%s", force, buildAction);

File[] built;

Expand All @@ -445,23 +467,36 @@ private boolean rebuild(boolean force) throws Exception {
}
}

// Build!
// Clear errors & warnings before build
model.clear();
model.setTrace(true);
if (force)
built = model.buildLocal(false);
else
built = model.build();
if (built == null) built = new File[0];

// Log rebuilt files
log(LOG_BASIC, "requested rebuild of %d files", built.length);
if (logLevel >= LOG_FULL) {
for (File builtFile : built) {
log(LOG_FULL, "target file %s has an age of %d ms", builtFile, System.currentTimeMillis() - builtFile.lastModified());

if (buildAction == Action.build) {
// Build!
model.setTrace(true);
if (force)
built = model.buildLocal(false);
else
built = model.build();
if (built == null) built = new File[0];

// Log rebuilt files
log(LOG_BASIC, "requested rebuild of %d files", built.length);
if (logLevel >= LOG_FULL) {
for (File builtFile : built) {
log(LOG_FULL, "target file %s has an age of %d ms", builtFile, System.currentTimeMillis() - builtFile.lastModified());
}
}
} else {
// Delete target files since the project has compile errors and the delete action was selected.
for (Builder builder : model.getSubBuilders()) {
File targetFile = new File(model.getTarget(), builder.getBsn() + ".jar");
boolean deleted = targetFile.delete();
log(LOG_FULL, "deleted target file %s (%b)", targetFile, deleted);
}
built = new File[0];
}


// Make sure Eclipse knows about the changed files (should already have been done?)
IFolder targetFolder = getProject().getFolder(calculateTargetDirPath(model));
targetFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
Expand Down
18 changes: 18 additions & 0 deletions bndtools.core/src/bndtools/preferences/CompileErrorAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package bndtools.preferences;

public enum CompileErrorAction {

delete, skip, build;

public static final String PREFERENCE_KEY = "compileErrorAction";
private static final CompileErrorAction DEFAULT = skip;

public static CompileErrorAction parse(String string) {
try {
return valueOf(string);
} catch (Exception e) {
return DEFAULT;
}
}

}
118 changes: 118 additions & 0 deletions bndtools.core/src/bndtools/preferences/ui/BndProjectPropertyPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package bndtools.preferences.ui;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.dialogs.PropertyPage;
import org.eclipse.ui.preferences.ScopedPreferenceStore;

import bndtools.Plugin;
import bndtools.preferences.CompileErrorAction;

public class BndProjectPropertyPage extends PropertyPage {

private CompileErrorAction action;

public BndProjectPropertyPage() {
setTitle("Bndtools");
}

/**
* Create contents of the property page.
* @param parent
*/
@Override
public Control createContents(Composite parent) {
// CREATE CONTROLS
Composite container = new Composite(parent, SWT.NULL);
container.setLayout(new GridLayout(1, false));

Group grpJavaCompilationErrors = new Group(container, SWT.NONE);
grpJavaCompilationErrors.setLayout(new GridLayout(1, false));
grpJavaCompilationErrors.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
grpJavaCompilationErrors.setText("Java Compilation Errors");

Label lblHowShouldBndtools = new Label(grpJavaCompilationErrors, SWT.WRAP);
lblHowShouldBndtools.setBounds(0, 0, 59, 14);
lblHowShouldBndtools.setText("How should Bndtools proceed when Java compilation errors exist?");

final Button btnDelete = new Button(grpJavaCompilationErrors, SWT.RADIO);
btnDelete.setText("Delete the output bundle");

final Button btnSkip = new Button(grpJavaCompilationErrors, SWT.RADIO);
btnSkip.setText("Skip building the output bundle (default)");

final Button btnContinue = new Button(grpJavaCompilationErrors, SWT.RADIO);
btnContinue.setText("Continue building the bundle");

// LOAD DATA
IPreferenceStore store = getPreferenceStore();
action = CompileErrorAction.parse(store.getString(CompileErrorAction.PREFERENCE_KEY));
switch (action) {
case delete:
btnDelete.setSelection(true); btnSkip.setSelection(false); btnContinue.setSelection(false);
break;
case skip:
btnDelete.setSelection(false); btnSkip.setSelection(true); btnContinue.setSelection(false);
break;
case build:
btnDelete.setSelection(false); btnSkip.setSelection(false); btnContinue.setSelection(true);
break;
}

// LISTENERS
SelectionAdapter listener = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (btnDelete.getSelection())
action = CompileErrorAction.delete;
else if (btnSkip.getSelection())
action = CompileErrorAction.skip;
else if (btnContinue.getSelection())
action = CompileErrorAction.build;
};
};
btnDelete.addSelectionListener(listener);
btnSkip.addSelectionListener(listener);
btnContinue.addSelectionListener(listener);


return container;
}

IProject getProject() {
IAdaptable elem = getElement();
if (elem instanceof IProject)
return (IProject) elem;

IProject project = (IProject) elem.getAdapter(IProject.class);
if (project != null)
return project;

throw new IllegalArgumentException("Target element does not adapt to IProject");
}

@Override
public boolean performOk() {
IPreferenceStore store = getPreferenceStore();
store.setValue(CompileErrorAction.PREFERENCE_KEY, action.name());

return true;
}

@Override
protected IPreferenceStore doGetPreferenceStore() {
return new ScopedPreferenceStore(new ProjectScope(getProject()), Plugin.PLUGIN_ID);
}
}

0 comments on commit 068724d

Please sign in to comment.